From 578685e05e54017b2a74091960f65ecf533e5dba Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 18 Feb 2022 13:56:18 +0100 Subject: [PATCH 1/7] feat(client): add back route 'updatePortfolio' --- .../back/methods/client/updatePortfolio.js | 20 +++++++++++++++++++ modules/client/back/models/client.js | 1 + modules/client/front/basic-data/index.html | 3 ++- modules/client/front/basic-data/index.js | 7 +++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 modules/client/back/methods/client/updatePortfolio.js diff --git a/modules/client/back/methods/client/updatePortfolio.js b/modules/client/back/methods/client/updatePortfolio.js new file mode 100644 index 000000000..8224a8aa4 --- /dev/null +++ b/modules/client/back/methods/client/updatePortfolio.js @@ -0,0 +1,20 @@ +module.exports = function(Self) { + Self.remoteMethodCtx('updatePortfolio', { + description: 'Update salesPeson potfolio weight', + accessType: 'READ', + accepts: [], + returns: { + type: 'Object', + root: true + }, + http: { + path: `/updatePortfolio`, + verb: 'GET' + } + }); + + Self.updatePortfolio = async() => { + query = `CALL bs.vendedores_updatePortfolio()`; + return await Self.rawSql(query); + }; +}; diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e842c3ea1..9ec45f58d 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -29,6 +29,7 @@ module.exports = Self => { require('../methods/client/updateAddress')(Self); require('../methods/client/consumption')(Self); require('../methods/client/createReceipt')(Self); + require('../methods/client/updatePortfolio')(Self); // Validations diff --git a/modules/client/front/basic-data/index.html b/modules/client/front/basic-data/index.html index a76b448f2..72d09ab49 100644 --- a/modules/client/front/basic-data/index.html +++ b/modules/client/front/basic-data/index.html @@ -68,7 +68,8 @@ value-field="id" where="{role: 'salesPerson'}" label="Salesperson" - vn-acl="salesAssistant"> + vn-acl="salesAssistant" + on-change="$ctrl.updatePortfolio()"> Date: Wed, 23 Feb 2022 12:57:43 +0100 Subject: [PATCH 2/7] fix: execute updatePortfolio after submit changes --- modules/client/front/basic-data/index.html | 5 ++--- modules/client/front/basic-data/index.js | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/client/front/basic-data/index.html b/modules/client/front/basic-data/index.html index 72d09ab49..a5c866979 100644 --- a/modules/client/front/basic-data/index.html +++ b/modules/client/front/basic-data/index.html @@ -10,7 +10,7 @@ url="ContactChannels" data="contactChannels"> -
+ + vn-acl="salesAssistant"> { + const query = `Clients/updatePortfolio`; + this.$http.get(query); + }); } } From dedecb492e640d81c974261d12329b89a6839abd Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 23 Feb 2022 12:58:01 +0100 Subject: [PATCH 3/7] sql modify --- .../00-vendedores_updatePortfolio.sql | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql diff --git a/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql b/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql new file mode 100644 index 000000000..f4c8fd7e8 --- /dev/null +++ b/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql @@ -0,0 +1,30 @@ +DROP PROCEDURE IF EXISTS bs.vendedores_updatePortfolio; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `bs`.`vendedores_updatePortfolio`() +BEGIN + /** + * Actualiza el campo portfolioWeight que indica el peso de la cartera del comercial + * + */ + DECLARE vStarted DATE DEFAULT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -17 MONTH), '%Y-%m-01'); + + DELETE v + FROM vendedores v + JOIN vn.`time` t ON t.`year` = v.año AND t.`month` = v.mes + WHERE t.dated BETWEEN vStarted AND CURDATE(); + + INSERT INTO vendedores(Id_Trabajador, año, mes, portfolioWeight) + SELECT c.lastSalesPersonFk + , t.`year` + , t.`month` + , SUM(v.importe) + FROM vn.`time` t + STRAIGHT_JOIN bs.ventas v ON t.dated = v.fecha + JOIN vn.`client` c ON c.id = v.Id_Cliente + WHERE c.lastSalesPersonFk IS NOT NULL + AND v.fecha BETWEEN vStarted AND CURDATE() + GROUP BY c.lastSalesPersonFk, t.`month`, t.`year`; +END$$ +DELIMITER ; From b3263fb97e5803173f7ba586bfd25db5d9e48e62 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 23 Feb 2022 12:58:09 +0100 Subject: [PATCH 4/7] add fixtures --- db/dump/fixtures.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 07eaf23fd..f3b55a9dc 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2443,3 +2443,16 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (1103, 500, CURDATE(), CURDATE()), (1107, 500, CURDATE(), CURDATE()), (1109, 500, CURDATE(), CURDATE()); + +INSERT INTO `bs`.`vendedores` (`Id_Trabajador`, `año`, `mes`, `portfolioWeight`) + VALUES + (18, YEAR(CURDATE()), MONTH(CURDATE()), 807.23), + (19, YEAR(CURDATE()), MONTH(CURDATE()), 34.40); + +INSERT INTO `bs`.`ventas` (`Id_Movimiento`, `importe`, `fecha`, `tipo_id`, `Id_Cliente`) + VALUES + (1, 501.95, CURDATE(), 2, 1101), + (2, 70.7, CURDATE(), 2, 1101), + (3, 200.78, CURDATE(), 2, 1101), + (4, 33.8, CURDATE(), 1, 1101), + (30, 34.4, CURDATE(), 1, 1108); From ca40eee5ad7e8516a3d7e980af95d47d0a36522d Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 23 Feb 2022 14:53:49 +0100 Subject: [PATCH 5/7] feat: add backTest --- .../client/specs/updatePortfolio.spec.js | 30 +++++++++++++++++++ .../back/methods/order/specs/filter.spec.js | 6 ++-- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 modules/client/back/methods/client/specs/updatePortfolio.spec.js diff --git a/modules/client/back/methods/client/specs/updatePortfolio.spec.js b/modules/client/back/methods/client/specs/updatePortfolio.spec.js new file mode 100644 index 000000000..d2362cde9 --- /dev/null +++ b/modules/client/back/methods/client/specs/updatePortfolio.spec.js @@ -0,0 +1,30 @@ +const models = require('vn-loopback/server/server').models; + +describe('Client updatePortfolio', () => { + const salesPersonId = 18; + const clienId = 1108; + it('should update the portfolioWeight', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const expectedResult = 841.63; + + const client = await models.Client.findById(clienId, null, options); + // await client.updateAttribute('salesPersonFk', 18); + await models.Client.rawSql(`UPDATE vn.client SET salesPersonFk = ${salesPersonId} WHERE id = ${clienId}; `); + + await models.Client.updatePortfolio(); + + let [vendedores] = await models.Client.rawSql(`SELECT portfolioWeight FROM bs.vendedores WHERE Id_Trabajador = ${salesPersonId}; `, null, options); + + expect(vendedores.portfolioWeight).toEqual(expectedResult); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 53b666c10..68de7fe04 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -53,11 +53,11 @@ describe('order filter()', () => { try { const options = {transaction: tx}; - const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 18}}; + const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 9}}; const result = await models.Order.filter(myCtx, filter, options); - expect(result.length).toEqual(9); - expect(result[0].id).toEqual(7); + expect(result.length).toEqual(4); + expect(result[0].id).toEqual(19); await tx.rollback(); } catch (e) { From 5ea8c5b06c9d7692adc0223181930a1676a7de4b Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 3 Mar 2022 11:38:32 +0100 Subject: [PATCH 6/7] delete vendedores_updatePortfolio.sql --- .../00-vendedores_updatePortfolio.sql | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql diff --git a/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql b/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql deleted file mode 100644 index f4c8fd7e8..000000000 --- a/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql +++ /dev/null @@ -1,30 +0,0 @@ -DROP PROCEDURE IF EXISTS bs.vendedores_updatePortfolio; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `bs`.`vendedores_updatePortfolio`() -BEGIN - /** - * Actualiza el campo portfolioWeight que indica el peso de la cartera del comercial - * - */ - DECLARE vStarted DATE DEFAULT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -17 MONTH), '%Y-%m-01'); - - DELETE v - FROM vendedores v - JOIN vn.`time` t ON t.`year` = v.año AND t.`month` = v.mes - WHERE t.dated BETWEEN vStarted AND CURDATE(); - - INSERT INTO vendedores(Id_Trabajador, año, mes, portfolioWeight) - SELECT c.lastSalesPersonFk - , t.`year` - , t.`month` - , SUM(v.importe) - FROM vn.`time` t - STRAIGHT_JOIN bs.ventas v ON t.dated = v.fecha - JOIN vn.`client` c ON c.id = v.Id_Cliente - WHERE c.lastSalesPersonFk IS NOT NULL - AND v.fecha BETWEEN vStarted AND CURDATE() - GROUP BY c.lastSalesPersonFk, t.`month`, t.`year`; -END$$ -DELIMITER ; From 4e3fe180ca4d881efeecea4baedd9e91d21dfa60 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 13:25:55 +0100 Subject: [PATCH 7/7] feat(client_descriptor): add supplier quick-link --- front/salix/components/descriptor/index.js | 3 ++- front/salix/components/descriptor/style.scss | 2 +- modules/client/back/methods/client/getCard.js | 6 ++++++ modules/client/back/models/client.json | 8 +++++++- modules/client/front/descriptor/index.html | 8 ++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/front/salix/components/descriptor/index.js b/front/salix/components/descriptor/index.js index 85baa7f02..470f0409d 100644 --- a/front/salix/components/descriptor/index.js +++ b/front/salix/components/descriptor/index.js @@ -97,7 +97,8 @@ ngModule.vnComponent('vnDescriptor', { btnOne: '?btnOne', btnTwo: '?btnTwo', btnThree: '?btnThree', - btnFour: '?btnFour' + btnFour: '?btnFour', + btnFive: '?btnFive' } }); diff --git a/front/salix/components/descriptor/style.scss b/front/salix/components/descriptor/style.scss index d15c60938..a87b3f451 100644 --- a/front/salix/components/descriptor/style.scss +++ b/front/salix/components/descriptor/style.scss @@ -104,7 +104,7 @@ vn-descriptor-content { align-items: center; justify-content: center; padding: 0 $spacing-sm; - margin: 0 $spacing-sm; + margin: 0 $spacing-xs; & > vn-icon { font-size: 1.75rem; diff --git a/modules/client/back/methods/client/getCard.js b/modules/client/back/methods/client/getCard.js index c3ce00bf3..34fba0984 100644 --- a/modules/client/back/methods/client/getCard.js +++ b/modules/client/back/methods/client/getCard.js @@ -64,6 +64,12 @@ module.exports = function(Self) { scope: { fields: ['id', 'name', 'active'] } + }, + { + relation: 'supplier', + scope: { + fields: ['id', 'nif'] + } } ] }, myOptions); diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index d6a98d83c..6404cfba0 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -228,7 +228,13 @@ "type": "belongsTo", "model": "Client", "foreignKey": "transferorFk" - } + }, + "supplier": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "fi", + "primaryKey": "nif" + } }, "scopes": { "isActive": { diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index 6ae1f690e..e75246ebe 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -101,6 +101,14 @@ icon="face"> +
+ + +