diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 17f90bb26..edb937e5f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2453,10 +2453,22 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (1107, 500, CURDATE(), CURDATE()), (1109, 500, CURDATE(), CURDATE()); +INSERT INTO `bs`.`salesPerson` (`workerFk`, `year`, `month`, `portfolioWeight`) + VALUES + (18, YEAR(CURDATE()), MONTH(CURDATE()), 807.23), + (19, YEAR(CURDATE()), MONTH(CURDATE()), 34.40); + +INSERT INTO `bs`.`sale` (`saleFk`, `amount`, `dated`, `typeFk`, `clientFk`) + 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); INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`) VALUES ('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word'); INSERT INTO `vn`.`docuwareConfig` (`url`) VALUES - ('https://verdnatura.docuware.cloud/docuware/platform'); \ No newline at end of file + ('https://verdnatura.docuware.cloud/docuware/platform'); 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/methods/client/specs/updatePortfolio.spec.js b/modules/client/back/methods/client/specs/updatePortfolio.spec.js new file mode 100644 index 000000000..0794fbf92 --- /dev/null +++ b/modules/client/back/methods/client/specs/updatePortfolio.spec.js @@ -0,0 +1,28 @@ +const models = require('vn-loopback/server/server').models; + +xdescribe('Client updatePortfolio', () => { + const salesPersonId = 18; + const clientId = 1108; + it('should update the portfolioWeight', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const expectedResult = 841.63; + + await models.Client.rawSql(`UPDATE vn.client SET salesPersonFk = ${salesPersonId} WHERE id = ${clientId}; `); + + 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/client/back/methods/client/updatePortfolio.js b/modules/client/back/methods/client/updatePortfolio.js new file mode 100644 index 000000000..3d522f6c8 --- /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.salesPerson_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/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/basic-data/index.html b/modules/client/front/basic-data/index.html index a76b448f2..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"> -