4270-route.create #1023
|
@ -0,0 +1,10 @@
|
||||||
|
UPDATE `vn`.`route` r
|
||||||
|
JOIN(SELECT r.id, wl.workcenterFk
|
||||||
|
FROM `vn`.`route` r
|
||||||
|
JOIN `vn`.`routeLog` rl ON rl.originFk = r.id
|
||||||
|
JOIN `vn`.`workerLabour` wl ON wl.workerFk = rl.userFk
|
||||||
|
AND r.created BETWEEN wl.started AND IFNULL(wl.ended, r.created)
|
||||||
|
WHERE r.created BETWEEN '2021-12-01' AND CURDATE()
|
||||||
|
AND rl.action = 'insert'
|
||||||
|
)sub ON sub.id = r.id
|
||||||
|
SET r.commissionWorkCenterFk = sub.workcenterFk;
|
|
@ -2620,3 +2620,7 @@ INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk
|
||||||
INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`)
|
INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 43200, 32400, 129600, 259200, 604800, '', '', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.33, 0.33, 40, '22:00:00', '06:00:00', 57600, 1200, 18000, 57600, 6, 13);
|
(1, 43200, 32400, 129600, 259200, 604800, '', '', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.33, 0.33, 40, '22:00:00', '06:00:00', 57600, 1200, 18000, 57600, 6, 13);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
|
||||||
|
VALUES
|
||||||
|
(1, 9);
|
||||||
|
|
|
@ -34349,6 +34349,7 @@ CREATE TABLE `route` (
|
||||||
`priority` int(11) NOT NULL DEFAULT '0',
|
`priority` int(11) NOT NULL DEFAULT '0',
|
||||||
`invoiceInFk` mediumint(8) unsigned DEFAULT NULL,
|
`invoiceInFk` mediumint(8) unsigned DEFAULT NULL,
|
||||||
`beachFk` int(11) DEFAULT NULL,
|
`beachFk` int(11) DEFAULT NULL,
|
||||||
|
`commissionWorkCenterFk` int(11) DEFAULT NULL COMMENT 'WorkerCenter que gestiona la ruta',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `Id_Agencia` (`agencyModeFk`),
|
KEY `Id_Agencia` (`agencyModeFk`),
|
||||||
KEY `Fecha` (`created`),
|
KEY `Fecha` (`created`),
|
||||||
|
@ -34357,7 +34358,9 @@ CREATE TABLE `route` (
|
||||||
KEY `fk_route_1_idx` (`zoneFk`),
|
KEY `fk_route_1_idx` (`zoneFk`),
|
||||||
KEY `asdfasdf_idx` (`invoiceInFk`),
|
KEY `asdfasdf_idx` (`invoiceInFk`),
|
||||||
KEY `route_idxIsOk` (`isOk`),
|
KEY `route_idxIsOk` (`isOk`),
|
||||||
|
KEY `route_WorkCenterFk_idx` (`commissionWorkCenterFk`),
|
||||||
CONSTRAINT `fk_route_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
CONSTRAINT `fk_route_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `route_WorkCenterFk` FOREIGN KEY (`commissionWorkCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE,
|
||||||
CONSTRAINT `route_fk5` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
CONSTRAINT `route_fk5` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
CONSTRAINT `route_ibfk_1` FOREIGN KEY (`gestdocFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
CONSTRAINT `route_ibfk_1` FOREIGN KEY (`gestdocFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
CONSTRAINT `route_ibfk_2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE,
|
CONSTRAINT `route_ibfk_2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE,
|
||||||
|
@ -34514,6 +34517,7 @@ CREATE TABLE `routeConfig` (
|
||||||
`plusCategory1Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
`plusCategory1Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
`plusCategory2Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
`plusCategory2Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
`defaultCompanyFk` smallint(5) unsigned DEFAULT '442',
|
`defaultCompanyFk` smallint(5) unsigned DEFAULT '442',
|
||||||
|
`defaultWorkCenterFk` int(11) DEFAULT 9 COMMENT 'Para el cálculo de las comisiones, en caso de el creador de la ruta no tenga workCenter',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `routeConfig_FK` (`defaultCompanyFk`),
|
KEY `routeConfig_FK` (`defaultCompanyFk`),
|
||||||
CONSTRAINT `routeConfig_FK` FOREIGN KEY (`defaultCompanyFk`) REFERENCES `company` (`id`)
|
CONSTRAINT `routeConfig_FK` FOREIGN KEY (`defaultCompanyFk`) REFERENCES `company` (`id`)
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('route updateWorkCenter()', () => {
|
||||||
|
const routeId = 1;
|
||||||
|
|
||||||
|
it('should set the commission work center if the worker has workCenter', async() => {
|
||||||
|
const tx = await models.Route.beginTransaction({});
|
||||||
|
try {
|
||||||
|
const developerId = 9;
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: developerId}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const expectedResult = 1;
|
||||||
|
const updatedRoute = await models.Route.updateWorkCenter(ctx, routeId, options);
|
||||||
|
|
||||||
|
expect(updatedRoute.commissionWorkCenterFk).toEqual(expectedResult);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`shoul set the default commision work center if that worker didn't have one yet`, async() => {
|
||||||
|
const tx = await models.Route.beginTransaction({});
|
||||||
|
try {
|
||||||
|
const userWithoutWorkCenter = 2;
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: userWithoutWorkCenter}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const expectedResult = 9;
|
||||||
|
const updatedRoute = await models.Route.updateWorkCenter(ctx, routeId, options);
|
||||||
|
|
||||||
|
expect(updatedRoute.commissionWorkCenterFk).toEqual(expectedResult);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,54 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('updateWorkCenter', {
|
||||||
|
description: 'Update the commission work center through user salix connected',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: {
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
description: 'Route Id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/:id/updateWorkCenter`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.updateWorkCenter = async(ctx, id, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [result] = await Self.rawSql(`
|
||||||
|
SELECT IFNULL(wl.workCenterFk, r.defaultWorkCenterFk) AS commissionWorkCenter
|
||||||
|
FROM vn.routeConfig r
|
||||||
|
LEFT JOIN vn.workerLabour wl ON wl.workerFk = ?
|
||||||
|
AND CURDATE() BETWEEN wl.started AND IFNULL(wl.ended, CURDATE());
|
||||||
|
`, [userId], myOptions);
|
||||||
|
|
||||||
|
const route = await models.Route.findById(id, null, myOptions);
|
||||||
|
await route.updateAttribute('commissionWorkCenterFk', result.commissionWorkCenter, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return route;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -9,6 +9,7 @@ module.exports = Self => {
|
||||||
require('../methods/route/clone')(Self);
|
require('../methods/route/clone')(Self);
|
||||||
require('../methods/route/getSuggestedTickets')(Self);
|
require('../methods/route/getSuggestedTickets')(Self);
|
||||||
require('../methods/route/unlink')(Self);
|
require('../methods/route/unlink')(Self);
|
||||||
|
require('../methods/route/updateWorkCenter')(Self);
|
||||||
|
|
||||||
Self.validate('kmStart', validateDistance, {
|
Self.validate('kmStart', validateDistance, {
|
||||||
message: 'Distance must be lesser than 1000'
|
message: 'Distance must be lesser than 1000'
|
||||||
|
|
|
@ -47,6 +47,9 @@
|
||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"commissionWorkCenterFk": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -4,7 +4,12 @@ import Section from 'salix/components/section';
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.$.watcher.submit().then(
|
this.$.watcher.submit().then(
|
||||||
res => this.$state.go('route.card.summary', {id: res.data.id})
|
res => {
|
||||||
|
this.$http.post(`Routes/${res.data.id}/updateWorkCenter`, null)
|
||||||
|
.then(() => {
|
||||||
|
this.$state.go('route.card.summary', {id: res.data.id});
|
||||||
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue