3626-client_basic-data #883
|
@ -2453,10 +2453,22 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced`
|
||||||
(1107, 500, CURDATE(), CURDATE()),
|
(1107, 500, CURDATE(), CURDATE()),
|
||||||
(1109, 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`)
|
INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`)
|
||||||
VALUES
|
VALUES
|
||||||
('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word');
|
('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word');
|
||||||
|
|
||||||
INSERT INTO `vn`.`docuwareConfig` (`url`)
|
INSERT INTO `vn`.`docuwareConfig` (`url`)
|
||||||
VALUES
|
VALUES
|
||||||
('https://verdnatura.docuware.cloud/docuware/platform');
|
('https://verdnatura.docuware.cloud/docuware/platform');
|
||||||
|
|
|
@ -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}; `);
|
||||||
|
|
||||||
vicent marked this conversation as resolved
carlosjr
commented
Review
*
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -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);
|
||||||
|
};
|
||||||
|
};
|
|
@ -29,6 +29,7 @@ module.exports = Self => {
|
||||||
require('../methods/client/updateAddress')(Self);
|
require('../methods/client/updateAddress')(Self);
|
||||||
require('../methods/client/consumption')(Self);
|
require('../methods/client/consumption')(Self);
|
||||||
require('../methods/client/createReceipt')(Self);
|
require('../methods/client/createReceipt')(Self);
|
||||||
|
require('../methods/client/updatePortfolio')(Self);
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
url="ContactChannels"
|
url="ContactChannels"
|
||||||
data="contactChannels">
|
data="contactChannels">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<form name="form" vn-http-submit="watcher.submit()" class="vn-w-md">
|
<form name="form" vn-http-submit="$ctrl.onSubmit()" class="vn-w-md">
|
||||||
<vn-card class="vn-pa-lg">
|
<vn-card class="vn-pa-lg">
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
|
|
|
@ -7,6 +7,13 @@ export default class Controller extends Section {
|
||||||
? {id: $search}
|
? {id: $search}
|
||||||
: {name: {like: '%' + $search + '%'}};
|
: {name: {like: '%' + $search + '%'}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSubmit() {
|
||||||
|
return this.$.watcher.submit().then(() => {
|
||||||
|
const query = `Clients/updatePortfolio`;
|
||||||
|
this.$http.get(query);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnClientBasicData', {
|
ngModule.vnComponent('vnClientBasicData', {
|
||||||
|
|
|
@ -53,11 +53,11 @@ describe('order filter()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
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);
|
const result = await models.Order.filter(myCtx, filter, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(9);
|
expect(result.length).toEqual(4);
|
||||||
expect(result[0].id).toEqual(7);
|
expect(result[0].id).toEqual(19);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue