Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6389-changesMonitor
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
bdec144b17
|
@ -1,132 +0,0 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
|
||||||
|
|
||||||
describe('machineWorker updateInTime()', () => {
|
|
||||||
const itBoss = 104;
|
|
||||||
const davidCharles = 1106;
|
|
||||||
|
|
||||||
beforeAll(async() => {
|
|
||||||
ctx = {
|
|
||||||
req: {
|
|
||||||
accessToken: {},
|
|
||||||
headers: {origin: 'http://localhost'},
|
|
||||||
__: value => value
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if the plate does not exist', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const plate = 'RE-123';
|
|
||||||
ctx.req.accessToken.userId = 1106;
|
|
||||||
try {
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
const error = e;
|
|
||||||
|
|
||||||
expect(error.message).toContain('the plate does not exist');
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should grab a machine where is not in use', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const plate = 'RE-003';
|
|
||||||
ctx.req.accessToken.userId = 1107;
|
|
||||||
try {
|
|
||||||
const totalBefore = await models.MachineWorker.find(null, options);
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
const totalAfter = await models.MachineWorker.find(null, options);
|
|
||||||
|
|
||||||
expect(totalAfter.length).toEqual(totalBefore.length + 1);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('less than 12h', () => {
|
|
||||||
const plate = 'RE-001';
|
|
||||||
it('should trow an error if it is not himself', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
ctx.req.accessToken.userId = davidCharles;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
const error = e;
|
|
||||||
|
|
||||||
expect(error.message).toContain('This machine is already in use');
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if it is himself with a different machine', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
ctx.req.accessToken.userId = itBoss;
|
|
||||||
const plate = 'RE-003';
|
|
||||||
try {
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
const error = e;
|
|
||||||
|
|
||||||
expect(error.message).toEqual('You are already using a machine');
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set the out time if it is himself', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
ctx.req.accessToken.userId = itBoss;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const isNotParked = await models.MachineWorker.findOne({
|
|
||||||
where: {workerFk: itBoss}
|
|
||||||
}, options);
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
const isParked = await models.MachineWorker.findOne({
|
|
||||||
where: {workerFk: itBoss}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(isNotParked.outTime).toBeNull();
|
|
||||||
expect(isParked.outTime).toBeDefined();
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('equal or more than 12h', () => {
|
|
||||||
const plate = 'RE-002';
|
|
||||||
it('should set the out time and grab the machine', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
ctx.req.accessToken.userId = davidCharles;
|
|
||||||
const filter = {
|
|
||||||
where: {workerFk: davidCharles, machineFk: 2}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const isNotParked = await models.MachineWorker.findOne(filter, options);
|
|
||||||
const totalBefore = await models.MachineWorker.find(null, options);
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
const isParked = await models.MachineWorker.findOne(filter, options);
|
|
||||||
const totalAfter = await models.MachineWorker.find(null, options);
|
|
||||||
|
|
||||||
expect(isNotParked.outTime).toBeNull();
|
|
||||||
expect(isParked.outTime).toBeDefined();
|
|
||||||
expect(totalAfter.length).toEqual(totalBefore.length + 1);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,77 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethodCtx('updateInTime', {
|
|
||||||
description: 'Updates the corresponding registry if the worker has been registered in the last few hours',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [
|
|
||||||
{
|
|
||||||
arg: 'plate',
|
|
||||||
type: 'string',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
http: {
|
|
||||||
path: `/updateInTime`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.updateInTime = async(ctx, plate, options) => {
|
|
||||||
const models = Self.app.models;
|
|
||||||
const userId = ctx.req.accessToken.userId;
|
|
||||||
const $t = ctx.req.__;
|
|
||||||
|
|
||||||
let tx;
|
|
||||||
const myOptions = {};
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await Self.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const machine = await models.Machine.findOne({
|
|
||||||
fields: ['id', 'plate'],
|
|
||||||
where: {plate}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
if (!machine)
|
|
||||||
throw new UserError($t('the plate does not exist', {plate}));
|
|
||||||
|
|
||||||
const machineWorker = await Self.findOne({
|
|
||||||
where: {
|
|
||||||
or: [{machineFk: machine.id}, {workerFk: userId}],
|
|
||||||
outTime: null,
|
|
||||||
}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
|
||||||
const hoursDifference = (Date.vnNow() - machineWorker?.inTime?.getTime() ?? 0) / (60 * 60 * 1000);
|
|
||||||
|
|
||||||
if (machineWorker) {
|
|
||||||
const isHimself = userId == machineWorker.workerFk;
|
|
||||||
const isSameMachine = machine.id == machineWorker.machineFk;
|
|
||||||
|
|
||||||
if (hoursDifference < maxHours && !isHimself)
|
|
||||||
throw new UserError($t('This machine is already in use.'));
|
|
||||||
|
|
||||||
if (hoursDifference < maxHours && isHimself && !isSameMachine)
|
|
||||||
throw new UserError($t('You are already using a machine'));
|
|
||||||
|
|
||||||
await machineWorker.updateAttributes({
|
|
||||||
outTime: Date.vnNew()
|
|
||||||
}, myOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!machineWorker || hoursDifference >= maxHours)
|
|
||||||
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
} catch (e) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -88,12 +88,6 @@
|
||||||
"Machine": {
|
"Machine": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"MachineWorker": {
|
|
||||||
"dataSource": "vn"
|
|
||||||
},
|
|
||||||
"MachineWorkerConfig": {
|
|
||||||
"dataSource": "vn"
|
|
||||||
},
|
|
||||||
"MobileAppVersionControl": {
|
"MobileAppVersionControl": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"name": "MachineWorkerConfig",
|
|
||||||
"base": "VnModel",
|
|
||||||
"options": {
|
|
||||||
"mysql": {
|
|
||||||
"table": "vn.machineWorkerConfig"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "number",
|
|
||||||
"id": true
|
|
||||||
},
|
|
||||||
"maxHours": {
|
|
||||||
"type": "number"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = Self => {
|
|
||||||
require('../methods/machine-worker/updateInTime')(Self);
|
|
||||||
};
|
|
|
@ -1,33 +0,0 @@
|
||||||
{
|
|
||||||
"name": "MachineWorker",
|
|
||||||
"base": "VnModel",
|
|
||||||
"options": {
|
|
||||||
"mysql": {
|
|
||||||
"table": "vn.machineWorker"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "number",
|
|
||||||
"id": true
|
|
||||||
},
|
|
||||||
"workerFk": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"machineFk": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"inTime": {
|
|
||||||
"type": "date",
|
|
||||||
"mysql": {
|
|
||||||
"columnName": "inTimed"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outTime": {
|
|
||||||
"type": "date",
|
|
||||||
"mysql": {
|
|
||||||
"columnName": "outTimed"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -404,7 +404,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city
|
||||||
(1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses');
|
(1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses');
|
||||||
|
|
||||||
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
|
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
|
||||||
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1
|
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), UPPER(CONCAT(name, 'Street')), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1
|
||||||
FROM `account`.`role` `r`
|
FROM `account`.`role` `r`
|
||||||
WHERE `r`.`hasLogin` = 1;
|
WHERE `r`.`hasLogin` = 1;
|
||||||
|
|
||||||
|
@ -2842,12 +2842,6 @@ INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmen
|
||||||
('RE-001', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442),
|
('RE-001', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442),
|
||||||
('RE-002', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442);
|
('RE-002', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442);
|
||||||
|
|
||||||
INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed`)
|
|
||||||
VALUES
|
|
||||||
(1106, 1, util.VN_CURDATE(), util.VN_CURDATE()),
|
|
||||||
(1106, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)),
|
|
||||||
(1106, 2, util.VN_CURDATE(), NULL),
|
|
||||||
(1106, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY));
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`zoneExclusion` (`id`, `zoneFk`, `dated`, `created`, `userFk`)
|
INSERT INTO `vn`.`zoneExclusion` (`id`, `zoneFk`, `dated`, `created`, `userFk`)
|
||||||
VALUES
|
VALUES
|
||||||
|
@ -3831,8 +3825,6 @@ UPDATE vn.collection
|
||||||
UPDATE vn.sale
|
UPDATE vn.sale
|
||||||
SET isPicked =FALSE;
|
SET isPicked =FALSE;
|
||||||
|
|
||||||
INSERT INTO vn.machineWorkerConfig(id, maxHours)
|
|
||||||
VALUES(1, 12);
|
|
||||||
|
|
||||||
INSERT INTO vn.workerAppTester(workerFk) VALUES(66);
|
INSERT INTO vn.workerAppTester(workerFk) VALUES(66);
|
||||||
|
|
||||||
|
@ -3840,9 +3832,6 @@ INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmen
|
||||||
VALUES
|
VALUES
|
||||||
('RE-003', 'IRON', 'JPH-24', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442);
|
('RE-003', 'IRON', 'JPH-24', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442);
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO vn.machineWorker(workerFk,machineFk,inTimed) VALUES (104,1,'2001-01-01 10:00:00.00.000');
|
|
||||||
|
|
||||||
UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1;
|
UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1;
|
||||||
|
|
||||||
UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5;
|
UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5;
|
||||||
|
|
|
@ -4,5 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `salix`.`ACL_beforeInsert`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
IF NEW.`property` = '*' THEN
|
||||||
|
CALL util.throw('The property field cannot be *');
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaig_add`
|
||||||
|
ON SCHEDULE EVERY 1 DAY
|
||||||
|
STARTS '2024-10-18 03:00:00.000'
|
||||||
|
ON COMPLETION PRESERVE
|
||||||
|
ENABLE
|
||||||
|
DO CALL itemCampaign_add()$$
|
||||||
|
DELIMITER ;
|
|
@ -1,23 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`workerMachinery_isRegistered`(vWorkerFk VARCHAR(10))
|
|
||||||
RETURNS tinyint(1)
|
|
||||||
NOT DETERMINISTIC
|
|
||||||
READS SQL DATA
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Comprueba si existen registros en las últimas horas (maxHours de machineWorkerConfig) del trabajador vWorkerFk y si tiene a nulo la hora outTimed (indica la hora que deja el vehículo)
|
|
||||||
*
|
|
||||||
* @param vWorkerFk id del trabajador
|
|
||||||
* @return Devuelve TRUE/FALSE en caso de que haya o no registros
|
|
||||||
*/
|
|
||||||
IF (SELECT COUNT(*)
|
|
||||||
FROM machineWorker m
|
|
||||||
WHERE m.workerFk = vWorkerFk
|
|
||||||
AND m.inTimed >= TIMESTAMPADD(HOUR , -(SELECT maxHours from machineWorkerConfig), util.VN_NOW()) AND ISNULL(m.outTimed))
|
|
||||||
THEN
|
|
||||||
RETURN TRUE;
|
|
||||||
ELSE
|
|
||||||
RETURN FALSE;
|
|
||||||
END IF;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaign_add`()
|
||||||
|
proc: BEGIN
|
||||||
|
/**
|
||||||
|
* Añade registros a tabla itemCampaign.
|
||||||
|
*
|
||||||
|
* @param vDateFrom Fecha desde
|
||||||
|
* @param vDateTo Fecha hasta
|
||||||
|
* @param vCampaign Código de la campaña
|
||||||
|
*/
|
||||||
|
DECLARE vYesterday DATE;
|
||||||
|
DECLARE vCampaign VARCHAR(100);
|
||||||
|
DECLARE vScopeDays INT;
|
||||||
|
DECLARE vPreviousDays INT;
|
||||||
|
DECLARE vDateSumFrom DATE;
|
||||||
|
DECLARE vDateSumTo DATE;
|
||||||
|
|
||||||
|
SET vYesterday = util.yesterday();
|
||||||
|
|
||||||
|
SELECT dated, code, scopeDays, previousDays
|
||||||
|
INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays
|
||||||
|
FROM campaign
|
||||||
|
WHERE dated >= vYesterday
|
||||||
|
ORDER BY dated
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
IF vCampaign IS NULL THEN
|
||||||
|
CALL util.throw('Missing data in campaign table');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT vYesterday BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY
|
||||||
|
AND vDateSumTo THEN
|
||||||
|
LEAVE proc;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY;
|
||||||
|
SET vDateSumTo = vDateSumTo - INTERVAL 1 DAY;
|
||||||
|
|
||||||
|
INSERT INTO itemCampaign(dated, itemFk, quantity, total, campaign)
|
||||||
|
SELECT vYesterday,
|
||||||
|
s.itemFk,
|
||||||
|
SUM(s.quantity) quantity,
|
||||||
|
SUM((s.quantity * s.price) * (100 - s.discount) / 100) total,
|
||||||
|
vCampaign
|
||||||
|
FROM sale s
|
||||||
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
|
JOIN client c ON c.id = t.clientFk
|
||||||
|
WHERE t.shipped BETWEEN vDateSumFrom AND util.dayEnd(vDateSumTo)
|
||||||
|
AND c.typeFk = 'normal'
|
||||||
|
AND NOT t.isDeleted
|
||||||
|
GROUP BY s.itemFk
|
||||||
|
HAVING quantity;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -20,6 +20,7 @@ proc: BEGIN
|
||||||
DECLARE vUserFk INT;
|
DECLARE vUserFk INT;
|
||||||
DECLARE vTotalReservedQuantity INT;
|
DECLARE vTotalReservedQuantity INT;
|
||||||
DECLARE vSaleQuantity INT;
|
DECLARE vSaleQuantity INT;
|
||||||
|
DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction;
|
||||||
|
|
||||||
DECLARE vItemShelvingAvailable CURSOR FOR
|
DECLARE vItemShelvingAvailable CURSOR FOR
|
||||||
SELECT ish.id itemShelvingFk,
|
SELECT ish.id itemShelvingFk,
|
||||||
|
@ -44,11 +45,11 @@ proc: BEGIN
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
BEGIN
|
BEGIN
|
||||||
ROLLBACK;
|
CALL util.tx_rollback(vIsRequiredTx);
|
||||||
RESIGNAL;
|
RESIGNAL;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
START TRANSACTION;
|
CALL util.tx_start(vIsRequiredTx);
|
||||||
|
|
||||||
SELECT id INTO vSaleFk
|
SELECT id INTO vSaleFk
|
||||||
FROM sale
|
FROM sale
|
||||||
|
@ -65,7 +66,7 @@ proc: BEGIN
|
||||||
WHERE s.id = vSaleFk;
|
WHERE s.id = vSaleFk;
|
||||||
|
|
||||||
IF vOutStanding <= 0 THEN
|
IF vOutStanding <= 0 THEN
|
||||||
COMMIT;
|
CALL util.tx_commit(vIsRequiredTx);
|
||||||
LEAVE proc;
|
LEAVE proc;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ proc: BEGIN
|
||||||
LEAVE l;
|
LEAVE l;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SELECT id INTO vItemShelvingFk
|
SELECT id INTO vItemShelvingFk
|
||||||
FROM itemShelving
|
FROM itemShelving
|
||||||
WHERE id = vItemShelvingFk
|
WHERE id = vItemShelvingFk
|
||||||
FOR UPDATE;
|
FOR UPDATE;
|
||||||
|
@ -102,19 +103,19 @@ proc: BEGIN
|
||||||
SET vOutStanding = vOutStanding - vReservedQuantity;
|
SET vOutStanding = vOutStanding - vReservedQuantity;
|
||||||
|
|
||||||
IF vReservedQuantity > 0 THEN
|
IF vReservedQuantity > 0 THEN
|
||||||
CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity',
|
CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity',
|
||||||
CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId()));
|
CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId()));
|
||||||
INSERT INTO itemShelvingSale(
|
INSERT INTO itemShelvingSale(
|
||||||
itemShelvingFk,
|
itemShelvingFk,
|
||||||
saleFk,
|
saleFk,
|
||||||
quantity,
|
quantity,
|
||||||
userFk,
|
userFk,
|
||||||
isPicked)
|
isPicked)
|
||||||
SELECT vItemShelvingFk,
|
SELECT vItemShelvingFk,
|
||||||
vSaleFk,
|
vSaleFk,
|
||||||
vReservedQuantity,
|
vReservedQuantity,
|
||||||
vUserFk,
|
vUserFk,
|
||||||
FALSE;
|
FALSE;
|
||||||
|
|
||||||
UPDATE itemShelving
|
UPDATE itemShelving
|
||||||
SET available = available - vReservedQuantity
|
SET available = available - vReservedQuantity
|
||||||
|
@ -123,6 +124,6 @@ proc: BEGIN
|
||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
CLOSE vItemShelvingAvailable;
|
CLOSE vItemShelvingAvailable;
|
||||||
COMMIT;
|
CALL util.tx_commit(vIsRequiredTx);
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -1,22 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machineWorker_add`(vPlate VARCHAR(10), vWorkerFk INT)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inserta registro si el vWorkerFk no ha registrado nada en las últimas 12 horas
|
|
||||||
* @param vPlate número de matrícula
|
|
||||||
* @param vWorkerFk id del worker
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
UPDATE vn.machineWorker mw
|
|
||||||
JOIN vn.machine m ON m.id = mw.machineFk
|
|
||||||
SET mw.outTimed = util.VN_NOW()
|
|
||||||
WHERE (mw.workerFk = vWorkerFk OR m.plate = vPlate)
|
|
||||||
AND ISNULL(mw.outTimed);
|
|
||||||
|
|
||||||
INSERT INTO machineWorker (machineFk, workerFk)
|
|
||||||
SELECT m.id, vWorkerFk
|
|
||||||
FROM machine m
|
|
||||||
WHERE m.plate= vPlate;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,21 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machineWorker_getHistorical`(vPlate VARCHAR(20), vWorkerFk INT)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Obtiene historial de la matrícula vPlate que el trabajador vWorkerFk escanea,
|
|
||||||
* si es jefe de producción muestra el historial completo.
|
|
||||||
*
|
|
||||||
* @param vPlate número de matrícula
|
|
||||||
* @param vWorkerFk id del trabajador
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vWorkerFk);
|
|
||||||
|
|
||||||
SELECT mw.inTimed,account.user_getNameFromId(mw.workerFk) as workerName, mw.outTimed
|
|
||||||
FROM machineWorker mw
|
|
||||||
JOIN machine m ON m.plate = vPlate
|
|
||||||
WHERE mw.machineFk = m.id
|
|
||||||
AND mw.workerFk = IF(account.user_hasRole(vWorkerName, 'coolerAssist'), mw.workerFk, vWorkerFk)
|
|
||||||
ORDER BY mw.inTimed DESC;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,38 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machineWorker_update`(vPlate VARCHAR(10), vWorkerFk INT)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Actualiza el registro correspondiente si el vWorkerFk se ha registrado en las últimas horas (campo maxHours de machineWorkerConfig) con vPlate,
|
|
||||||
*
|
|
||||||
* @param vPlate número de matrícula
|
|
||||||
* @param vWorkerFk id del trabajador
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
DECLARE vMachineFk INT(10);
|
|
||||||
DECLARE vMaxHours INT(10);
|
|
||||||
|
|
||||||
SELECT m.id INTO vMachineFk
|
|
||||||
FROM machine m
|
|
||||||
WHERE m.plate = vPlate;
|
|
||||||
|
|
||||||
SELECT maxHours INTO vMaxHours
|
|
||||||
FROM machineWorkerConfig;
|
|
||||||
|
|
||||||
IF (SELECT COUNT(*)
|
|
||||||
FROM machineWorker m
|
|
||||||
WHERE m.workerFk = vWorkerFk
|
|
||||||
AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN
|
|
||||||
|
|
||||||
UPDATE machineWorker m
|
|
||||||
SET m.outTimed = CURRENT_TIMESTAMP()
|
|
||||||
WHERE m.workerFk = vWorkerFk
|
|
||||||
AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW())
|
|
||||||
AND ISNULL(m.outTimed)
|
|
||||||
AND m.machineFk = vMachineFk;
|
|
||||||
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,16 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machine_getWorkerPlate`(vWorkerFk INT)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Selecciona la matrícula del vehículo del workerfk
|
|
||||||
*
|
|
||||||
* @param vWorkerFk el id del trabajador
|
|
||||||
*/
|
|
||||||
SELECT m.plate
|
|
||||||
FROM machine m
|
|
||||||
JOIN machineWorker mw ON mw.machineFk = m.id
|
|
||||||
WHERE mw.inTimed >= TIMESTAMPADD(HOUR , -12,util.VN_NOW())
|
|
||||||
AND ISNULL(mw.outTimed)
|
|
||||||
AND mw.workerFk = vWorkerFk;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -51,7 +51,8 @@ BEGIN
|
||||||
origin.companyFk futureCompanyFk,
|
origin.companyFk futureCompanyFk,
|
||||||
IFNULL(dest.nickname, origin.nickname) nickname,
|
IFNULL(dest.nickname, origin.nickname) nickname,
|
||||||
dest.landed,
|
dest.landed,
|
||||||
dest.preparation
|
dest.preparation,
|
||||||
|
origin.departmentFk
|
||||||
FROM (
|
FROM (
|
||||||
SELECT s.ticketFk,
|
SELECT s.ticketFk,
|
||||||
c.salesPersonFk workerFk,
|
c.salesPersonFk workerFk,
|
||||||
|
@ -71,9 +72,11 @@ BEGIN
|
||||||
t.addressFk,
|
t.addressFk,
|
||||||
t.warehouseFk,
|
t.warehouseFk,
|
||||||
t.companyFk,
|
t.companyFk,
|
||||||
t.agencyModeFk
|
t.agencyModeFk,
|
||||||
|
wd.departmentFk
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
|
JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN saleVolume sv ON sv.saleFk = s.id
|
JOIN saleVolume sv ON sv.saleFk = s.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
|
|
@ -10,11 +10,10 @@ FROM (
|
||||||
`vn`.`collection` `c`
|
`vn`.`collection` `c`
|
||||||
JOIN `vn`.`client` `cl` ON(`cl`.`id` = `c`.`workerFk`)
|
JOIN `vn`.`client` `cl` ON(`cl`.`id` = `c`.`workerFk`)
|
||||||
)
|
)
|
||||||
LEFT JOIN `vn`.`machineWorker` `mw` ON(
|
JOIN `vn`.`operator` `o` ON(
|
||||||
`mw`.`workerFk` = `c`.`workerFk`
|
`o`.`workerFk` = `c`.`workerFk`
|
||||||
AND `mw`.`inTimed` > `util`.`VN_CURDATE`()
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
WHERE `c`.`created` > `util`.`VN_CURDATE`()
|
WHERE `c`.`created` > `util`.`VN_CURDATE`()
|
||||||
AND `mw`.`workerFk` IS NULL
|
AND `o`.`machineFk` IS NULL
|
||||||
GROUP BY `c`.`workerFk`
|
GROUP BY `c`.`workerFk`
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS `vn`.`itemCampaign` (
|
||||||
|
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
dated date NOT NULL,
|
||||||
|
itemFk int(11) NOT NULL,
|
||||||
|
quantity decimal(10,2) NOT NULL,
|
||||||
|
total decimal(10,2) NOT NULL,
|
||||||
|
campaign varchar(100) NOT NULL,
|
||||||
|
UNIQUE KEY `itemCampaign_UNIQUE` (`dated`,`itemFk`),
|
||||||
|
CONSTRAINT itemCampaign_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
)
|
||||||
|
ENGINE=InnoDB
|
||||||
|
DEFAULT CHARSET=utf8mb3
|
||||||
|
COLLATE=utf8mb3_unicode_ci
|
||||||
|
COMMENT='Tallos confirmados por día en los días de más producción de una campaña. La tabla está pensada para que sea una foto.';
|
||||||
|
|
||||||
|
ALTER TABLE vn.campaign
|
||||||
|
ADD previousDays int(10) unsigned DEFAULT 30 NOT NULL COMMENT 'Días previos para calcular e insertar en la tabla itemCampaign';
|
||||||
|
|
||||||
|
UPDATE vn.campaign
|
||||||
|
SET previousDays = 90
|
||||||
|
WHERE code = 'allSaints';
|
||||||
|
|
||||||
|
UPDATE vn.campaign
|
||||||
|
SET previousDays = 60
|
||||||
|
WHERE code IN ('valentinesDay', 'mothersDay');
|
|
@ -0,0 +1,3 @@
|
||||||
|
DELETE FROM `salix`.`ACL`
|
||||||
|
WHERE `model` = 'Worker'
|
||||||
|
AND `property` IN ('find', 'findById', 'findOne');
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
USE vn;
|
||||||
|
RENAME TABLE machineWorker TO machineWorker__;
|
||||||
|
ALTER TABLE machineWorker__ COMMENT = '@deprecated 2024-10-23 not used';
|
||||||
|
|
||||||
|
RENAME TABLE machineWorkerConfig TO machineWorkerConfig__;
|
||||||
|
ALTER TABLE machineWorkerConfig__ COMMENT = '@deprecated 2024-10-23 not used';
|
||||||
|
|
||||||
|
DELETE FROM salix.ACL WHERE model = 'MachineWorker';
|
|
@ -24,8 +24,8 @@
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
label="Worker"
|
label="Worker"
|
||||||
ng-model="$ctrl.itemType.workerFk"
|
ng-model="$ctrl.itemType.workerFk"
|
||||||
url="Workers"
|
url="Workers/search"
|
||||||
show-field="firstName"
|
show-field="nickname"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
rule>
|
rule>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
label="Worker"
|
label="Worker"
|
||||||
ng-model="$ctrl.itemType.workerFk"
|
ng-model="$ctrl.itemType.workerFk"
|
||||||
url="Workers"
|
url="Workers/search"
|
||||||
show-field="firstName"
|
show-field="nickname"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
rule>
|
rule>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
|
|
@ -29,7 +29,7 @@ module.exports = Self => {
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const stmt = new ParameterizedSQL(
|
const stmt = new ParameterizedSQL(
|
||||||
`SELECT es.created, u.name, u.id workerFk, est.description state
|
`SELECT es.created, u.name, u.id workerFk, est.description state, es.isScanned
|
||||||
FROM vn.expeditionState es
|
FROM vn.expeditionState es
|
||||||
JOIN vn.expeditionStateType est ON est.id = es.typeFk
|
JOIN vn.expeditionStateType est ON est.id = es.typeFk
|
||||||
JOIN account.user u ON u.id = es.userFk
|
JOIN account.user u ON u.id = es.userFk
|
||||||
|
|
|
@ -50,6 +50,11 @@ module.exports = Self => {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: 'True when lines and stock of origin are equal'
|
description: 'True when lines and stock of origin are equal'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'departmentFk',
|
||||||
|
type: 'number',
|
||||||
|
description: 'Department identifier'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -96,6 +101,8 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
case 'isFullMovable':
|
case 'isFullMovable':
|
||||||
return {'f.isFullMovable': value};
|
return {'f.isFullMovable': value};
|
||||||
|
case 'departmentFk':
|
||||||
|
return {'f.departmentFk': value};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@ describe('TicketFuture getTicketsAdvance()', () => {
|
||||||
today.setHours(0, 0, 0, 0);
|
today.setHours(0, 0, 0, 0);
|
||||||
let tomorrow = Date.vnNew();
|
let tomorrow = Date.vnNew();
|
||||||
tomorrow.setDate(today.getDate() + 1);
|
tomorrow.setDate(today.getDate() + 1);
|
||||||
|
const salesDeptId = 43;
|
||||||
|
const spain1DeptId = 95;
|
||||||
|
beforeAll.mockLoopBackContext();
|
||||||
|
|
||||||
it('should return the tickets passing the required data', async() => {
|
it('should return the tickets passing the required data', async() => {
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
@ -129,4 +132,39 @@ describe('TicketFuture getTicketsAdvance()', () => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return the tickets matching the right department', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
ctx.args = {
|
||||||
|
dateFuture: tomorrow,
|
||||||
|
dateToAdvance: today,
|
||||||
|
warehouseFk: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options);
|
||||||
|
const client = await models.Client.findById(1, null, options);
|
||||||
|
await client.updateAttribute('salesPersonFk', 1, options);
|
||||||
|
const business = await models.Business.findById(1, null, options);
|
||||||
|
await business.updateAttributes({departmentFk: spain1DeptId}, options);
|
||||||
|
|
||||||
|
const saleTickets = await models.Ticket.getTicketsAdvance(ctx, options);
|
||||||
|
const filteredSaleTickets = await models.Ticket.getTicketsAdvance(
|
||||||
|
{args: {...ctx.args, departmentFk: spain1DeptId}},
|
||||||
|
options);
|
||||||
|
|
||||||
|
expect(saleTickets.length).toBeGreaterThan(filteredSaleTickets.length);
|
||||||
|
expect(saleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeTrue();
|
||||||
|
expect(saleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue();
|
||||||
|
|
||||||
|
expect(filteredSaleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeFalse();
|
||||||
|
expect(filteredSaleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue();
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue