From d2729e67e93ed0153d3c45d66b0da10760e551ff Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 22 Nov 2021 08:27:14 +0100 Subject: [PATCH 1/4] feat(item and latest-buys: add supplier filter --- .../entry/back/methods/entry/latestBuysFilter.js | 11 ++++++++++- .../entry/front/latest-buys-search-panel/index.html | 11 +++++++++++ modules/item/back/methods/item/filter.js | 11 ++++++++++- modules/item/front/search-panel/index.html | 13 ++++++++++++- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 7711bc0f1..3b6da1acd 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -39,6 +39,11 @@ module.exports = Self => { type: 'integer', description: 'The buyer of the item', }, + { + arg: 'supplierFk', + type: 'integer', + description: 'The supplier of the item', + }, { arg: 'active', type: 'boolean', @@ -99,6 +104,8 @@ module.exports = Self => { return {'ic.id': value}; case 'salesPersonFk': return {'it.workerFk': value}; + case 'supplierFk': + return {'s.id': value}; case 'code': return {'it.code': value}; case 'active': @@ -172,7 +179,9 @@ module.exports = Self => { LEFT JOIN itemCategory ic ON ic.id = it.categoryFk LEFT JOIN itemType t ON t.id = i.typeFk LEFT JOIN intrastat intr ON intr.id = i.intrastatFk - LEFT JOIN origin ori ON ori.id = i.originFk` + LEFT JOIN origin ori ON ori.id = i.originFk + LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN supplier s ON s.id = e.supplierFk` ); if (ctx.args.tags) { diff --git a/modules/entry/front/latest-buys-search-panel/index.html b/modules/entry/front/latest-buys-search-panel/index.html index 4693141f8..7d570f798 100644 --- a/modules/entry/front/latest-buys-search-panel/index.html +++ b/modules/entry/front/latest-buys-search-panel/index.html @@ -46,6 +46,17 @@ where="{role: {inq: ['logistic', 'buyer']}}" label="Buyer"> + + {{name}}: {{nickname}} + { type: 'integer', description: 'The buyer of the item', }, + { + arg: 'supplierFk', + type: 'integer', + description: 'The supplier of the item', + }, { arg: 'description', type: 'string', @@ -120,6 +125,8 @@ module.exports = Self => { return {'ic.id': value}; case 'buyerFk': return {'it.workerFk': value}; + case 'supplierFk': + return {'s.id': value}; case 'origin': return {'ori.code': value}; case 'intrastat': @@ -170,7 +177,9 @@ module.exports = Self => { LEFT JOIN producer pr ON pr.id = i.producerFk LEFT JOIN origin ori ON ori.id = i.originFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = it.warehouseFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id` + LEFT JOIN buy b ON b.id = lb.buy_id + LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN supplier s ON s.id = e.supplierFk` ); if (ctx.args.tags) { diff --git a/modules/item/front/search-panel/index.html b/modules/item/front/search-panel/index.html index 57f05bb54..7cbe9c56d 100644 --- a/modules/item/front/search-panel/index.html +++ b/modules/item/front/search-panel/index.html @@ -43,10 +43,21 @@ ng-model="filter.buyerFk" url="Items/activeBuyers" show-field="nickname" - search-function="{firstName: $search}" + search-function="{nickname: {like: '%'+ $search +'%'}}" value-field="workerFk" label="Buyer"> + + {{name}}: {{nickname}} + From 1e6805a1614ca860a53cdba621c7602ccdbbbbcf Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 22 Nov 2021 08:30:28 +0100 Subject: [PATCH 2/4] remove unnecessary tabulation --- modules/entry/back/methods/entry/latestBuysFilter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 3b6da1acd..c877612e1 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -181,7 +181,7 @@ module.exports = Self => { LEFT JOIN intrastat intr ON intr.id = i.intrastatFk LEFT JOIN origin ori ON ori.id = i.originFk LEFT JOIN entry e ON e.id = b.entryFk - LEFT JOIN supplier s ON s.id = e.supplierFk` + LEFT JOIN supplier s ON s.id = e.supplierFk` ); if (ctx.args.tags) { From 97a66754a7518238566d86d961582cb0afbef8c8 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 22 Nov 2021 08:58:54 +0100 Subject: [PATCH 3/4] feat(item and entry): add back test --- .../entry/specs/latestBuysFilter.spec.js | 12 ++++++ .../back/methods/item/specs/filter.spec.js | 40 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js index f386894dd..bdd302adb 100644 --- a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js +++ b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js @@ -136,5 +136,17 @@ describe('Buy latests buys filter()', () => { expect(results.length).toBe(1); }); + + it('should return results matching "supplierFk"', async() => { + let ctx = { + args: { + supplierFk: 1 + } + }; + + let results = await app.models.Buy.latestBuysFilter(ctx); + + expect(results.length).toBe(2); + }); }); diff --git a/modules/item/back/methods/item/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index 7b1fac9ac..30bdcec32 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -79,4 +79,44 @@ describe('item filter()', () => { throw e; } }); + + it('should return 2 result filtering by buyerFk', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {}; + const ctx = {args: {filter: filter, buyerFk: 16}}; + const result = await models.Item.filter(ctx, filter, options); + + expect(result.length).toEqual(2); + expect(result[0].id).toEqual(16); + expect(result[1].id).toEqual(71); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return 2 result filtering by supplierFk', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {}; + const ctx = {args: {filter: filter, supplierFk: 1}}; + const result = await models.Item.filter(ctx, filter, options); + + expect(result.length).toEqual(2); + expect(result[0].id).toEqual(1); + expect(result[1].id).toEqual(3); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 80f651f37d0757551a7db7f8ca664d16f39f4dee Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 22 Nov 2021 12:34:20 +0100 Subject: [PATCH 4/4] add entries less than a year ago --- modules/entry/back/methods/entry/latestBuysFilter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index c877612e1..0c8ce3f99 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -180,7 +180,7 @@ module.exports = Self => { LEFT JOIN itemType t ON t.id = i.typeFk LEFT JOIN intrastat intr ON intr.id = i.intrastatFk LEFT JOIN origin ori ON ori.id = i.originFk - LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN entry e ON e.id = b.entryFk AND e.created >= DATE_SUB(CURDATE(),INTERVAL 1 YEAR) LEFT JOIN supplier s ON s.id = e.supplierFk` );