From 6fbc5a1a544e3feff1e9a6feb05785db15eda975 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 30 Sep 2024 09:17:27 +0200 Subject: [PATCH 01/81] feat: refs #7202 added new field --- db/dump/fixtures.before.sql | 98 +++++++++---------- .../11269-wheatBirch/00-firstScript.sql | 9 ++ .../back/methods/invoiceOut/filter.js | 14 ++- .../invoiceOut/back/models/invoice-out.json | 5 + 4 files changed, 75 insertions(+), 51 deletions(-) create mode 100644 db/versions/11269-wheatBirch/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index ffbc6a864..33090d7a6 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -425,50 +425,50 @@ INSERT INTO `vn`.`clientConfig`(`id`, `riskTolerance`, `maxCreditRows`, `maxPric (1, 200, 10, 0.25, 2, 4, 5, 300.00, 1, 1, 2); -INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`, `isDefaultAddress`) +INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`, `isDefaultAddress`, `customsAgentFk`) VALUES - (1, 'Bruce Wayne', '1007 Mountain Drive, Gotham', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 1), - (2, 'Petter Parker', '20 Ingram Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 1), - (3, 'Clark Kent', '344 Clinton Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 1), - (4, 'Tony Stark', '10880 Malibu Point', 'Gotham', 46460, 1, 1111111111, 222222222, 1 , 1104, 2, NULL, NULL, 0, 1), - (5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1), - (6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1), - (7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1), - (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 5, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 1), - (9, 'Bruce Banner', 'Somewhere in New York', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 1), - (10, 'Jessica Jones', 'NYCC 2015 Poster', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 1), - (11, 'Missing', 'The space', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1111, 10, NULL, NULL, 0, 1), - (12, 'Trash', 'New York city', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1112, 10, NULL, NULL, 0, 1), - (101, 'Somewhere in Thailand', 'address 01', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (102, 'Somewhere in Poland', 'address 02', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (103, 'Somewhere in Japan', 'address 03', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (104, 'Somewhere in Spain', 'address 04', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (105, 'Somewhere in Potugal', 'address 05', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (106, 'Somewhere in UK', 'address 06', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (107, 'Somewhere in Valencia', 'address 07', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (108, 'Somewhere in Gotham', 'address 08', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (109, 'Somewhere in London', 'address 09', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (110, 'Somewhere in Algemesi', 'address 10', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (111, 'Somewhere in Carlet', 'address 11', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (112, 'Somewhere in Campanar', 'address 12', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (113, 'Somewhere in Malilla', 'address 13', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (114, 'Somewhere in France', 'address 14', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (115, 'Somewhere in Birmingham', 'address 15', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (116, 'Somewhere in Scotland', 'address 16', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (117, 'Somewhere in nowhere', 'address 17', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (118, 'Somewhere over the rainbow', 'address 18', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (119, 'Somewhere in Alberic', 'address 19', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (120, 'Somewhere in Montortal', 'address 20', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (121, 'the bat cave', 'address 21', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 0), - (122, 'NY roofs', 'address 22', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 0), - (123, 'The phone box', 'address 23', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 0), - (124, 'Stark tower Gotham', 'address 24', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1104, 2, NULL, NULL, 0, 0), - (125, 'The plastic cell', 'address 25', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 0), - (126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0), - (127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0), - (128, 'Cerebro', 'address 28', 'Gotham', 46460, 5, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0), - (129, 'Luke Cages Bar', 'address 29', 'Gotham', 'EC170150', 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0), - (130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0); + (1, 'Bruce Wayne', '1007 Mountain Drive, Gotham', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 1, 1), + (2, 'Petter Parker', '20 Ingram Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 1, NULL), + (3, 'Clark Kent', '344 Clinton Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 1, NULL), + (4, 'Tony Stark', '10880 Malibu Point', 'Gotham', 46460, 1, 1111111111, 222222222, 1 , 1104, 2, NULL, NULL, 0, 1, NULL), + (5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1, NULL), + (6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1, NULL), + (7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1, NULL), + (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 5, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 1, NULL), + (9, 'Bruce Banner', 'Somewhere in New York', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 1, NULL), + (10, 'Jessica Jones', 'NYCC 2015 Poster', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 1, NULL), + (11, 'Missing', 'The space', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1111, 10, NULL, NULL, 0, 1, NULL), + (12, 'Trash', 'New York city', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1112, 10, NULL, NULL, 0, 1, NULL), + (101, 'Somewhere in Thailand', 'address 01', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (102, 'Somewhere in Poland', 'address 02', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (103, 'Somewhere in Japan', 'address 03', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (104, 'Somewhere in Spain', 'address 04', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (105, 'Somewhere in Potugal', 'address 05', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (106, 'Somewhere in UK', 'address 06', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (107, 'Somewhere in Valencia', 'address 07', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (108, 'Somewhere in Gotham', 'address 08', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (109, 'Somewhere in London', 'address 09', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (110, 'Somewhere in Algemesi', 'address 10', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (111, 'Somewhere in Carlet', 'address 11', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (112, 'Somewhere in Campanar', 'address 12', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (113, 'Somewhere in Malilla', 'address 13', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (114, 'Somewhere in France', 'address 14', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (115, 'Somewhere in Birmingham', 'address 15', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (116, 'Somewhere in Scotland', 'address 16', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (117, 'Somewhere in nowhere', 'address 17', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (118, 'Somewhere over the rainbow', 'address 18', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (119, 'Somewhere in Alberic', 'address 19', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (120, 'Somewhere in Montortal', 'address 20', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0, NULL), + (121, 'the bat cave', 'address 21', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 0, NULL), + (122, 'NY roofs', 'address 22', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 0, NULL), + (123, 'The phone box', 'address 23', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 0, NULL), + (124, 'Stark tower Gotham', 'address 24', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1104, 2, NULL, NULL, 0, 0, NULL), + (125, 'The plastic cell', 'address 25', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 0, NULL), + (126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0, NULL), + (127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0, NULL), + (128, 'Cerebro', 'address 28', 'Gotham', 46460, 5, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0, NULL), + (129, 'Luke Cages Bar', 'address 29', 'Gotham', 'EC170150', 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0, NULL), + (130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0, NULL); INSERT INTO `vn`.`address`( `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `isActive`, `clientFk`, `agencyModeFk`, `isDefaultAddress`) SELECT name, CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, 1, id, 2, 1 @@ -639,13 +639,13 @@ INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaF ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); -INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) +INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`, `customsAgentFk`) VALUES - (1, 'T', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0); + (1, 'T', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, 1), + (2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL), + (3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL), + (4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL), + (5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0, NULL); UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1; UPDATE `vn`.`invoiceOut` SET ref = 'T2222222' WHERE id = 2; diff --git a/db/versions/11269-wheatBirch/00-firstScript.sql b/db/versions/11269-wheatBirch/00-firstScript.sql new file mode 100644 index 000000000..b2f113167 --- /dev/null +++ b/db/versions/11269-wheatBirch/00-firstScript.sql @@ -0,0 +1,9 @@ +ALTER TABLE vn.invoiceOut ADD COLUMN IF NOT EXISTS customsAgentFk INT(11) DEFAULT NULL AFTER siiTrascendencyInvoiceOutFk; + +ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_customsAgentFk FOREIGN KEY (customsAgentFk) + REFERENCES vn.customsAgent (id) ON DELETE RESTRICT ON UPDATE CASCADE; + +UPDATE vn.invoiceOut i + JOIN vn.client c ON c.id = io.clientFk + JOIN vn.address a ON a.id = c.defaultAddressFk + SET i.customsAgentFk = a.customsAgentFk; \ No newline at end of file diff --git a/modules/invoiceOut/back/methods/invoiceOut/filter.js b/modules/invoiceOut/back/methods/invoiceOut/filter.js index 99a80c169..3b6aa4d82 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/filter.js +++ b/modules/invoiceOut/back/methods/invoiceOut/filter.js @@ -73,6 +73,12 @@ module.exports = Self => { type: 'date', description: 'The due date filter', http: {source: 'query'} + }, + { + arg: 'customsAgentFk', + type: 'integer', + description: 'The customsAgent id', + http: {source: 'query'} } ], returns: { @@ -112,6 +118,7 @@ module.exports = Self => { case 'companyFk': case 'issued': case 'dued': + case 'customsAgentFk': param = `i.${param}`; return {[param]: value}; } @@ -131,11 +138,14 @@ module.exports = Self => { i.dued, i.clientFk, i.hasPdf, + i.customsAgentFk, c.socialName AS clientSocialName, - co.code AS companyCode + co.code AS companyCode, + ca.fiscalName AS customsAgentName FROM invoiceOut i LEFT JOIN client c ON c.id = i.clientFk - LEFT JOIN company co ON co.id = i.companyFk` + LEFT JOIN company co ON co.id = i.companyFk + LEFT JOIN customsAgent ca ON ca.id = i.customsAgentFk` ); stmt.merge(conn.makeSuffix(filter)); diff --git a/modules/invoiceOut/back/models/invoice-out.json b/modules/invoiceOut/back/models/invoice-out.json index 1ee36accb..2ad13fe3f 100644 --- a/modules/invoiceOut/back/models/invoice-out.json +++ b/modules/invoiceOut/back/models/invoice-out.json @@ -66,6 +66,11 @@ "model": "Ticket", "foreignKey": "refFk", "primaryKey": "ref" + }, + "customsAgentFk": { + "type": "belongsTo", + "model": "CustomsAgent", + "foreignKey": "customsAgentFk" } } } From da749a5dcbe9cbc648ec16281d80a96493acda4b Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 30 Sep 2024 09:21:05 +0200 Subject: [PATCH 02/81] fix: refs #7202 fixed sql --- db/versions/11269-wheatBirch/00-firstScript.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11269-wheatBirch/00-firstScript.sql b/db/versions/11269-wheatBirch/00-firstScript.sql index b2f113167..6a50e5232 100644 --- a/db/versions/11269-wheatBirch/00-firstScript.sql +++ b/db/versions/11269-wheatBirch/00-firstScript.sql @@ -3,7 +3,7 @@ ALTER TABLE vn.invoiceOut ADD COLUMN IF NOT EXISTS customsAgentFk INT(11) DEFAUL ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_customsAgentFk FOREIGN KEY (customsAgentFk) REFERENCES vn.customsAgent (id) ON DELETE RESTRICT ON UPDATE CASCADE; -UPDATE vn.invoiceOut i +UPDATE vn.invoiceOut io JOIN vn.client c ON c.id = io.clientFk JOIN vn.address a ON a.id = c.defaultAddressFk - SET i.customsAgentFk = a.customsAgentFk; \ No newline at end of file + SET io.customsAgentFk = a.customsAgentFk; \ No newline at end of file From 451e3bebefaad230d5eb30222aa07afff29d6e3b Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 30 Sep 2024 09:45:55 +0200 Subject: [PATCH 03/81] fix: refs #7202 fixed back test --- .../client/back/methods/client/specs/updateAddress.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index 68981f8b7..0453332d7 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('Address updateAddress', () => { - const clientId = 1101; - const addressId = 1; + const clientId = 1102; + const addressId = 2; const provinceId = 5; const incotermsId = 'FAS'; const customAgentOneId = 1; From a6799cba0ff74c1740220430b18ad38fea1f5a79 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 1 Oct 2024 10:39:57 +0200 Subject: [PATCH 04/81] refactor: refs #7202 modified procedure to include customsAgent field when creating an invoice --- db/routines/vn/procedures/invoiceOut_new.sql | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/invoiceOut_new.sql b/db/routines/vn/procedures/invoiceOut_new.sql index 723f33df5..6f2f7f8ff 100644 --- a/db/routines/vn/procedures/invoiceOut_new.sql +++ b/db/routines/vn/procedures/invoiceOut_new.sql @@ -105,7 +105,8 @@ BEGIN clientFk, dued, companyFk, - siiTypeInvoiceOutFk + siiTypeInvoiceOutFk, + customsAgentFk ) SELECT 1, @@ -118,9 +119,11 @@ BEGIN vCplusCorrectingInvoiceTypeFk, IF(vSerial = vSimplifiedSerial, vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClientFk; + vCplusStandardInvoiceTypeFk)), + a.customsAgentFk + FROM client c + JOIN address a ON a.id = c.defaultAddressFk + WHERE c.id = vClientFk; SET vNewInvoiceId = LAST_INSERT_ID(); From ca3ac64072f0480650b7f9dd623e99b1d75172a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 1 Oct 2024 16:37:12 +0200 Subject: [PATCH 05/81] feat: refs #4460 invoiceIn refund --- db/routines/sage/procedures/invoiceIn_add.sql | 18 +++---- .../sage/procedures/invoiceOut_add.sql | 5 +- .../00-firstScript.sql | 47 +++++++++++++++++++ 3 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 db/versions/11266-goldenChrysanthemum/00-firstScript.sql diff --git a/db/routines/sage/procedures/invoiceIn_add.sql b/db/routines/sage/procedures/invoiceIn_add.sql index 0898d6810..ba7a0c6c0 100644 --- a/db/routines/sage/procedures/invoiceIn_add.sql +++ b/db/routines/sage/procedures/invoiceIn_add.sql @@ -4,10 +4,10 @@ BEGIN /** * Traslada la info de contabilidad relacionada con las facturas recibidas * - * @vInvoiceInFk Factura recibida - * @vXDiarioFk Id tabla XDiario + * @param vInvoiceInFk Factura recibida + * @param vXDiarioFk Id tabla XDiario */ - DECLARE vInvoiceInOriginalFk INT; + DECLARE vInvoiceInOriginalFk INT; DECLARE vDone BOOL DEFAULT FALSE; DECLARE vBase DOUBLE; DECLARE vVat DOUBLE; @@ -204,9 +204,9 @@ BEGIN WHERE correctingFk = vInvoiceInFk; IF vInvoiceInOriginalFk THEN - UPDATE movContaIVA mci - JOIN vn.invoiceInRefund iir ON iir.invoiceInRefundFk = vInvoiceInFk + JOIN vn.invoiceInCorrection iic ON iic.correctingFk = vInvoiceInFk + JOIN vn.siiTypeInvoiceOut st ON st.id = iic.siiTypeInvoiceOutFk JOIN (SELECT issued, SUM(sub.taxableBase) taxableBase, SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat @@ -215,20 +215,20 @@ BEGIN ti.PorcentajeIva FROM vn.invoiceIn i JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id - JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk + JOIN TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk WHERE i.id = vInvoiceInOriginalFk GROUP BY ti.CodigoIva)sub )invoiceInOriginal JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa' - SET mci.TipoRectificativa = iir.refundCategoryFk, - mci.ClaseAbonoRectificativas = iir.refundType, + SET mci.TipoRectificativa = iic.cplusRectificationTypeFk, + mci.ClaseAbonoRectificativas = REGEXP_REPLACE(st.`code`, '[^0-9]', ''), mci.FechaFacturaOriginal = invoiceInOriginal.issued, mci.FechaOperacion = invoiceInOriginal.issued, mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase, mci.CuotaIvaOriginal = invoiceInOriginal.vat, mci.ClaveOperacionFactura = co.ClaveOperacionFactura_ WHERE mci.id = vXDiarioFk; - END IF; END$$ +$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/sage/procedures/invoiceOut_add.sql b/db/routines/sage/procedures/invoiceOut_add.sql index 95d6a56dd..f9c6f6b87 100644 --- a/db/routines/sage/procedures/invoiceOut_add.sql +++ b/db/routines/sage/procedures/invoiceOut_add.sql @@ -169,6 +169,7 @@ BEGIN UPDATE movContaIVA mci JOIN vn.invoiceOut i ON i.id = vInvoiceOutCorrectedFk JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk + JOIN vn.siiTypeInvoiceOut st ON st.id = ic.siiTypeInvoiceOutFk JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase, SUM(IF(IFNULL(e.vatFk, TRUE), iot.vat, 0)) vat, SUM(IF(IFNULL(e.vatFk, TRUE), 0, iot.vat)) equ @@ -177,8 +178,8 @@ BEGIN WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk ) tax JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa' - SET mci.TipoRectificativa = 2, - mci.ClaseAbonoRectificativas = 1, + SET mci.TipoRectificativa = ic.cplusRectificationTypeFk, + mci.ClaseAbonoRectificativas = REGEXP_REPLACE(st.`code`, '[^0-9]', ''), mci.FechaFacturaOriginal = i.issued, mci.FechaOperacion = i.issued, mci.BaseImponibleOriginal = tax.taxableBase, diff --git a/db/versions/11266-goldenChrysanthemum/00-firstScript.sql b/db/versions/11266-goldenChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..37143c99b --- /dev/null +++ b/db/versions/11266-goldenChrysanthemum/00-firstScript.sql @@ -0,0 +1,47 @@ + USE vn; + + DROP TRIGGER IF EXISTS invoiceIn_beforeUpdate; + + UPDATE vn.invoiceIn + SET cplusRectificationTypeFk = NULL + WHERE cplusRectificationTypeFk = 1; + + DELETE IGNORE FROM vn.cplusRectificationType WHERE id = 1; + + UPDATE vn.cplusRectificationType + SET id = 1 + WHERE id = 3; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`invoiceIn_beforeUpdate` + BEFORE UPDATE ON `invoiceIn` + FOR EACH ROW +BEGIN + DECLARE vWithholdingSageFk INT; + + IF NOT (NEW.supplierRef <=> OLD.supplierRef) AND NOT util.checkPrintableChars(NEW.supplierRef) THEN + CALL util.throw('The invoiceIn reference contains invalid characters'); + END IF; + + SET NEW.editorFk = account.myUser_getId(); + + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk + AND YEAR(issued) = YEAR(NEW.issued) + AND id <> NEW.id + ) THEN + CALL util.throw('reference duplicated'); + END IF; + + IF NEW.supplierFk != OLD.supplierFk THEN + CALL supplier_checkIsActive(NEW.supplierFk); + SELECT withholdingSageFk INTO vWithholdingSageFk + FROM vn.supplier + WHERE id = NEW.supplierFk; + SET NEW.withholdingSageFk = vWithholdingSageFk; + END IF; + +END$$ +DELIMITER ; + From 2a1fa8ca68d34e67767c954fa808c1f51d5e728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 1 Oct 2024 18:55:29 +0200 Subject: [PATCH 06/81] feat: refs #4466 invoiceIn refund --- db/routines/vn/procedures/invoiceIn_booking.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/invoiceIn_booking.sql b/db/routines/vn/procedures/invoiceIn_booking.sql index 36189afcc..3d1ca402a 100644 --- a/db/routines/vn/procedures/invoiceIn_booking.sql +++ b/db/routines/vn/procedures/invoiceIn_booking.sql @@ -43,7 +43,7 @@ BEGIN ii.cplusTaxBreakFk, ii.cplusSubjectOpFk, ii.siiTypeInvoiceInFk, - ii.cplusRectificationTypeFk, + ic.cplusRectificationTypeFk, ii.booked, IFNULL(a.isUeeMember, c.isUeeMember) isUeeMember, (c.id = cc.id) isSameCountry, @@ -66,6 +66,7 @@ BEGIN e.name expenseName FROM invoiceIn ii JOIN supplier s ON s.id = ii.supplierFk + LEFT JOIN invoiceInCorrection ic ON ic.correctingFk = ii.id LEFT JOIN province p ON p.id = s.provinceFk LEFT JOIN autonomy a ON a.id = p.autonomyFk JOIN country c ON c.id = s.countryFk From 2ec0d7f186526d774a79ca07f80da9d9f6efc793 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 23 Oct 2024 08:10:00 +0200 Subject: [PATCH 07/81] refactor: refs #7202 modified new invoice procedure and incoterms sql --- db/dump/fixtures.before.sql | 12 ++++----- db/routines/vn/procedures/invoiceOut_new.sql | 15 +++++++---- .../11269-wheatBirch/00-firstScript.sql | 12 ++++++--- .../invoice-incoterms/sql/incoterms.sql | 27 +++++++++++-------- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index e48fb36b0..a418876b0 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -639,13 +639,13 @@ INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaF ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); -INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`, `customsAgentFk`) +INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`, `customsAgentFk`, `incotermsFk`) VALUES - (1, 'T', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, 1), - (2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL), - (3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL), - (4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL), - (5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0, NULL); + (1, 'E', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, 1, 'FAS'), + (2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL, NULL), + (3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL, NULL), + (4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL, NULL), + (5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0, NULL, NULL); UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1; UPDATE `vn`.`invoiceOut` SET ref = 'T2222222' WHERE id = 2; diff --git a/db/routines/vn/procedures/invoiceOut_new.sql b/db/routines/vn/procedures/invoiceOut_new.sql index 6f2f7f8ff..1f20fb5fc 100644 --- a/db/routines/vn/procedures/invoiceOut_new.sql +++ b/db/routines/vn/procedures/invoiceOut_new.sql @@ -34,6 +34,7 @@ BEGIN DECLARE vMaxShipped DATE; DECLARE vDone BOOL; DECLARE vTicketFk INT; + DECLARE vAddressFk INT; DECLARE vCursor CURSOR FOR SELECT id FROM tmp.ticketToInvoice; @@ -48,11 +49,13 @@ BEGIN DATE(vInvoiceDate) >= invoiceOut_getMaxIssued( vSerial, t.companyFk, - YEAR(vInvoiceDate)) + YEAR(vInvoiceDate)), + t.addressFk INTO vClientFk, vCompanyFk, vMaxShipped, - vIsCorrectInvoiceDate + vIsCorrectInvoiceDate, + vAddressFk FROM tmp.ticketToInvoice tt JOIN ticket t ON t.id = tt.id; @@ -106,7 +109,8 @@ BEGIN dued, companyFk, siiTypeInvoiceOutFk, - customsAgentFk + customsAgentFk, + incotermsFk ) SELECT 1, @@ -120,9 +124,10 @@ BEGIN IF(vSerial = vSimplifiedSerial, vCplusSimplifiedInvoiceTypeFk, vCplusStandardInvoiceTypeFk)), - a.customsAgentFk + a.customsAgentFk, + a.incotermsFk FROM client c - JOIN address a ON a.id = c.defaultAddressFk + JOIN address a ON a.id = vAddressFk WHERE c.id = vClientFk; SET vNewInvoiceId = LAST_INSERT_ID(); diff --git a/db/versions/11269-wheatBirch/00-firstScript.sql b/db/versions/11269-wheatBirch/00-firstScript.sql index 6a50e5232..9432d131b 100644 --- a/db/versions/11269-wheatBirch/00-firstScript.sql +++ b/db/versions/11269-wheatBirch/00-firstScript.sql @@ -1,9 +1,15 @@ ALTER TABLE vn.invoiceOut ADD COLUMN IF NOT EXISTS customsAgentFk INT(11) DEFAULT NULL AFTER siiTrascendencyInvoiceOutFk; +ALTER TABLE vn.invoiceOut ADD COLUMN IF NOT EXISTS incotermsFk varchar(3) DEFAULT NULL AFTER customsAgentFk; ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_customsAgentFk FOREIGN KEY (customsAgentFk) REFERENCES vn.customsAgent (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_incotermsFk FOREIGN KEY (incotermsFk) + REFERENCES vn.incoterms (`code`) ON DELETE RESTRICT ON UPDATE CASCADE; + UPDATE vn.invoiceOut io - JOIN vn.client c ON c.id = io.clientFk - JOIN vn.address a ON a.id = c.defaultAddressFk - SET io.customsAgentFk = a.customsAgentFk; \ No newline at end of file + JOIN vn.client c ON c.id = io.clientFk + JOIN vn.ticket t ON t.clientFk = c.id + JOIN vn.address a ON a.id = t.addressFk + SET io.customsAgentFk = a.customsAgentFk, + io.incotermsFk = a.incotermsFk; \ No newline at end of file diff --git a/print/templates/reports/invoice-incoterms/sql/incoterms.sql b/print/templates/reports/invoice-incoterms/sql/incoterms.sql index 016a8342e..535451674 100644 --- a/print/templates/reports/invoice-incoterms/sql/incoterms.sql +++ b/print/templates/reports/invoice-incoterms/sql/incoterms.sql @@ -1,9 +1,9 @@ WITH tickets AS( -SELECT id, packages, addressFk, weight - FROM ticket - WHERE refFk= ? +SELECT id, addressFk, packages, refFk + FROM vn.ticket + WHERE refFk = ? ), volume AS( -SELECT SUM(volume) volume +SELECT SUM(volume) volume, MAX(weight)weight FROM tickets t JOIN vn.saleVolume sv ON sv.ticketFk = t.id ), intrastat AS( @@ -12,10 +12,14 @@ SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR ' JOIN vn.sale s ON t.id = s.ticketFk JOIN vn.item i ON i.id = s.itemFk JOIN vn.intrastat ir ON ir.id = i.intrastatFk -)SELECT SUM(t.packages) packages, - a.incotermsFk, +), totalPackages AS( +SELECT SUM(packages)packages + FROM tickets s +) +SELECT tp.packages, + io.incotermsFk, ic.name incotermsName, - MAX(t.weight) weight, + v.weight weight, ca.fiscalName customsAgentName, ca.street customsAgentStreet, ca.nif customsAgentNif, @@ -23,9 +27,10 @@ SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR ' ca.email customsAgentEmail, CAST(v.volume AS DECIMAL (10,2)) volume, i.intrastat - FROM tickets t - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.incoterms ic ON ic.code = a.incotermsFk - LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk + FROM vn.invoiceOut io + JOIN vn.incoterms ic ON ic.code = io.incotermsFk + LEFT JOIN vn.customsAgent ca ON ca.id = io.customsAgentFk JOIN volume v JOIN intrastat i + JOIN totalPackages tp + WHERE `ref` = (SELECT DISTINCT refFk FROM tickets) \ No newline at end of file From c593b95935302ef661dea268525a3546576541f0 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 23 Oct 2024 15:21:24 +0200 Subject: [PATCH 08/81] feat: refs #7880 error code and translations --- .../hedera/procedures/order_confirmWithUser.sql | 2 +- db/versions/11320-salmonRose/00-firstScript.sql | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/versions/11320-salmonRose/00-firstScript.sql diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 644d68a87..db83cba5c 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -107,7 +107,7 @@ BEGIN ) INTO vHas0Amount; IF vHas0Amount THEN - CALL util.throw('Hay líneas vacías. Por favor, elimínelas'); + CALL util.throw('orderLinesWithZero'); END IF; START TRANSACTION; diff --git a/db/versions/11320-salmonRose/00-firstScript.sql b/db/versions/11320-salmonRose/00-firstScript.sql new file mode 100644 index 000000000..cd3431fee --- /dev/null +++ b/db/versions/11320-salmonRose/00-firstScript.sql @@ -0,0 +1,11 @@ +INSERT INTO hedera.message (code, description) + VALUES ('orderLinesWithZero','There are empty lines. Please delete them'); + +INSERT INTO hedera.messageI18n (code, lang, description) + VALUES ('orderLinesWithZero','es','Hay líneas vacías. Por favor, elimínelas'); + +INSERT INTO hedera.messageI18n (code, lang, description) + VALUES ('orderLinesWithZero','fr','Il y a des lignes vides. Veuillez les supprimer'); + +INSERT INTO hedera.messageI18n (code, lang, description) + VALUES ('orderLinesWithZero','pt','Existem linhas vazias. Por favor, apague-os'); \ No newline at end of file From 679dd6929bfde285fe1a501f9199dbcd5fd26af2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 6 Nov 2024 13:42:36 +0100 Subject: [PATCH 09/81] feat: refs #6583 add new opt in where builder --- modules/ticket/back/methods/ticket/getTicketsAdvance.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 41f3ee79a..6abac455f 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -55,6 +55,11 @@ module.exports = Self => { type: 'number', description: 'Department identifier' }, + { + arg: 'onlyWithDestination', + type: 'Boolean', + description: 'True when only tickets with destination are returned' + }, { arg: 'filter', type: 'object', @@ -103,6 +108,9 @@ module.exports = Self => { return {'f.isFullMovable': value}; case 'departmentFk': return {'f.departmentFk': value}; + case 'onlyWithDestination': + if (!value) return; + return {'f.id': {neq: null}}; } }); From 611cd12392f80e6833c14f4763b956c044a27465 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 7 Nov 2024 16:16:40 +0100 Subject: [PATCH 10/81] feat: refs #6583 retrieve cloned sale --- db/routines/vn/procedures/ticket_canAdvance.sql | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index e8fc70bba..cee706e08 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -52,7 +52,8 @@ BEGIN IFNULL(dest.nickname, origin.nickname) nickname, dest.landed, dest.preparation, - origin.departmentFk + origin.departmentFk, + origin.saleClonedFk FROM ( SELECT s.ticketFk, c.salesPersonFk workerFk, @@ -73,11 +74,13 @@ BEGIN t.warehouseFk, t.companyFk, t.agencyModeFk, - wd.departmentFk + wd.departmentFk, + sc.saleClonedFk FROM ticket t JOIN client c ON c.id = t.clientFk JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.id JOIN saleVolume sv ON sv.saleFk = s.id JOIN item i ON i.id = s.itemFk JOIN ticketState ts ON ts.ticketFk = t.id From 41512a0516294d2709b3836585d5239c2b84c97e Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 11 Nov 2024 16:09:26 +0100 Subject: [PATCH 11/81] refactor: refs #6583 entry report table style --- .../reports/entry-order/assets/css/style.css | 5 +++ .../reports/entry-order/entry-order.html | 44 +++++++++---------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/print/templates/reports/entry-order/assets/css/style.css b/print/templates/reports/entry-order/assets/css/style.css index 767b1185a..1a5ea3eb6 100644 --- a/print/templates/reports/entry-order/assets/css/style.css +++ b/print/templates/reports/entry-order/assets/css/style.css @@ -17,4 +17,9 @@ h3 { .tags { font-size: 10px; margin: 0; +} + +.column-oriented th, +.column-oriented td{ + padding: 5px } \ No newline at end of file diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index e5d3bfb6d..77545ef9b 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -41,36 +41,36 @@ + - + - - - - - - - - + + + + + + + + - - - - - + + + - - - - - + + + + From 3db6ab07789540c213a2403c7223ea040c6841c6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 11 Nov 2024 16:10:49 +0100 Subject: [PATCH 12/81] feat: refs #6583 rollback --- .../reports/entry-order/assets/css/style.css | 5 +++ .../reports/entry-order/entry-order.html | 44 +++++++++---------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/print/templates/reports/entry-order/assets/css/style.css b/print/templates/reports/entry-order/assets/css/style.css index 767b1185a..1a5ea3eb6 100644 --- a/print/templates/reports/entry-order/assets/css/style.css +++ b/print/templates/reports/entry-order/assets/css/style.css @@ -17,4 +17,9 @@ h3 { .tags { font-size: 10px; margin: 0; +} + +.column-oriented th, +.column-oriented td{ + padding: 5px } \ No newline at end of file diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index e5d3bfb6d..77545ef9b 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -41,36 +41,36 @@
{{$t('reference')}} {{$t('boxes')}} {{$t('packing')}}{{$t('concept')}}{{$t('reference')}}{{$t('tags')}}{{$t('quantity')}}{{$t('price')}}{{$t('amount')}}{{$t('concept')}}{{$t('tags')}}{{$t('quantity')}}{{$t('price')}}{{$t('amount')}}
{{buy.comment}} {{buy.stickers}}x{{buy.packing}}{{buy.name}}{{buy.comment}} - {{buy.tag5}} → {{buy.value5}} - {{buy.tag6}} → {{buy.value6}} - {{buy.tag7}} → {{buy.value7}} + x{{buy.packing}}{{buy.name}} + {{buy.tag5}} → {{buy.value5}} + {{buy.tag6}} → {{buy.value6}} + {{buy.tag7}} → {{buy.value7}} {{buy.quantity | number($i18n.locale)}}x{{buy.buyingValue | currency('EUR', $i18n.locale)}}= + {{buy.quantity | number($i18n.locale)}}x{{buy.buyingValue | currency('EUR', $i18n.locale)}}= {{buy.buyingValue * buy.quantity | currency('EUR', $i18n.locale)}}
+ - + - - - - - - - - + + + + + + + + - - - - - + + + - - - - - + + + + From 2f3efa15ba8e2a832aff010ddc114c39192576b9 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 11 Nov 2024 16:13:25 +0100 Subject: [PATCH 13/81] feat: refs #6583 rollback --- .../reports/entry-order/assets/css/style.css | 5 --- .../reports/entry-order/entry-order.html | 44 +++++++++---------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/print/templates/reports/entry-order/assets/css/style.css b/print/templates/reports/entry-order/assets/css/style.css index 1a5ea3eb6..767b1185a 100644 --- a/print/templates/reports/entry-order/assets/css/style.css +++ b/print/templates/reports/entry-order/assets/css/style.css @@ -17,9 +17,4 @@ h3 { .tags { font-size: 10px; margin: 0; -} - -.column-oriented th, -.column-oriented td{ - padding: 5px } \ No newline at end of file diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index 77545ef9b..e5d3bfb6d 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -41,36 +41,36 @@
{{$t('reference')}} {{$t('boxes')}} {{$t('packing')}}{{$t('concept')}}{{$t('reference')}}{{$t('tags')}}{{$t('quantity')}}{{$t('price')}}{{$t('amount')}}{{$t('concept')}}{{$t('tags')}}{{$t('quantity')}}{{$t('price')}}{{$t('amount')}}
{{buy.comment}} {{buy.stickers}}x{{buy.packing}}{{buy.name}}{{buy.comment}} - {{buy.tag5}} → {{buy.value5}} - {{buy.tag6}} → {{buy.value6}} - {{buy.tag7}} → {{buy.value7}} + x{{buy.packing}}{{buy.name}} + {{buy.tag5}} → {{buy.value5}} + {{buy.tag6}} → {{buy.value6}} + {{buy.tag7}} → {{buy.value7}} {{buy.quantity | number($i18n.locale)}}x{{buy.buyingValue | currency('EUR', $i18n.locale)}}= + {{buy.quantity | number($i18n.locale)}}x{{buy.buyingValue | currency('EUR', $i18n.locale)}}= {{buy.buyingValue * buy.quantity | currency('EUR', $i18n.locale)}}
- - + - - - - - - - + + + + + + + + - - - - - + + + + - - - - - + + + + From 9a645c3288bb2db2bcb5604c0500d4c2a283a422 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 26 Nov 2024 16:56:39 +0100 Subject: [PATCH 14/81] fix: refs #7936 add IF NOT EXISTS to isRaid column in travel table --- db/versions/11332-tealErica/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11332-tealErica/00-firstScript.sql b/db/versions/11332-tealErica/00-firstScript.sql index 6358695b2..957aa57e2 100644 --- a/db/versions/11332-tealErica/00-firstScript.sql +++ b/db/versions/11332-tealErica/00-firstScript.sql @@ -1,4 +1,4 @@ -ALTER TABLE vn.travel ADD isRaid tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Redada'; +ALTER TABLE vn.travel ADD IF NOT EXISTS isRaid tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Redada'; ALTER TABLE vn.travel MODIFY COLUMN daysInForward int(10) unsigned DEFAULT NULL COMMENT 'Cuando es una redada, indica el número de días que se añadirán a la fecha de hoy para establecer el landed. NULL si no es una redada'; From a68e287b23cfc568574a215562a629562e2d0465 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 26 Nov 2024 17:01:50 +0100 Subject: [PATCH 15/81] refactor: refs #7936 remove old trigger and add isRaid column to travel table --- db/versions/11332-tealErica/00-firstScript.sql | 2 +- .../00-firstScript.sql | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) rename db/versions/{11266-goldenChrysanthemum => 11368-whiteAspidistra}/00-firstScript.sql (99%) diff --git a/db/versions/11332-tealErica/00-firstScript.sql b/db/versions/11332-tealErica/00-firstScript.sql index 957aa57e2..6358695b2 100644 --- a/db/versions/11332-tealErica/00-firstScript.sql +++ b/db/versions/11332-tealErica/00-firstScript.sql @@ -1,4 +1,4 @@ -ALTER TABLE vn.travel ADD IF NOT EXISTS isRaid tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Redada'; +ALTER TABLE vn.travel ADD isRaid tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Redada'; ALTER TABLE vn.travel MODIFY COLUMN daysInForward int(10) unsigned DEFAULT NULL COMMENT 'Cuando es una redada, indica el número de días que se añadirán a la fecha de hoy para establecer el landed. NULL si no es una redada'; diff --git a/db/versions/11266-goldenChrysanthemum/00-firstScript.sql b/db/versions/11368-whiteAspidistra/00-firstScript.sql similarity index 99% rename from db/versions/11266-goldenChrysanthemum/00-firstScript.sql rename to db/versions/11368-whiteAspidistra/00-firstScript.sql index 37143c99b..333fa1315 100644 --- a/db/versions/11266-goldenChrysanthemum/00-firstScript.sql +++ b/db/versions/11368-whiteAspidistra/00-firstScript.sql @@ -45,3 +45,4 @@ BEGIN END$$ DELIMITER ; + From 6ab25c2ff588c82db06cde389ccdc4fd73efff58 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 26 Nov 2024 17:06:45 +0100 Subject: [PATCH 16/81] fix: refs #7936 add IF NOT EXISTS to isRaid column in travel table --- db/versions/11332-tealErica/00-firstScript.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11332-tealErica/00-firstScript.sql b/db/versions/11332-tealErica/00-firstScript.sql index 6358695b2..a7870632f 100644 --- a/db/versions/11332-tealErica/00-firstScript.sql +++ b/db/versions/11332-tealErica/00-firstScript.sql @@ -1,4 +1,4 @@ -ALTER TABLE vn.travel ADD isRaid tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Redada'; +ALTER TABLE vn.travel ADD IF NOT EXISTS isRaid tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Redada'; ALTER TABLE vn.travel MODIFY COLUMN daysInForward int(10) unsigned DEFAULT NULL - COMMENT 'Cuando es una redada, indica el número de días que se añadirán a la fecha de hoy para establecer el landed. NULL si no es una redada'; + COMMENT 'Cuando es una redada, indica el número de días que se añadirán a la fecha de hoy para establecer el landed. NULL si no es una redada'; \ No newline at end of file From 5db1262e082d52d2f5333f7c452aa30a5d69d723 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 27 Nov 2024 10:24:13 +0100 Subject: [PATCH 17/81] feat: refs #7936 add company filter --- .../invoiceIn/back/methods/invoice-in/filter.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/filter.js b/modules/invoiceIn/back/methods/invoice-in/filter.js index 936f7bb6c..c549769ab 100644 --- a/modules/invoiceIn/back/methods/invoice-in/filter.js +++ b/modules/invoiceIn/back/methods/invoice-in/filter.js @@ -91,6 +91,10 @@ module.exports = Self => { { arg: 'supplierActivityFk', type: 'string', + }, + { + arg: 'companyFk', + type: 'number', } ], returns: { @@ -161,8 +165,8 @@ module.exports = Self => { : {'ii.id': {nin: correcteds.map(x => x.correctingFk)}}; case 'correctedFk': return {'ii.id': {inq: correctings.map(x => x.correctingFk)}}; - case 'supplierActivityFk': - return {'s.supplierActivityFk': value}; + case 'companyFk': + return {'ii.companyFk': value}; } }); @@ -184,7 +188,8 @@ module.exports = Self => { s.name supplierName, s.account, SUM(iid.amount) amount, - sub.code awbCode + sub.code awbCode, + c.code FROM invoiceIn ii JOIN supplier s ON s.id = ii.supplierFk LEFT JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id @@ -199,7 +204,8 @@ module.exports = Self => { GROUP BY de.duaFk ) sub ON sub.duaFk = d.id LEFT JOIN company co ON co.id = ii.companyFk - LEFT JOIN dms dm ON dm.id = ii.docFk` + LEFT JOIN dms dm ON dm.id = ii.docFk + JOIN company c ON c.id = ii.companyFk`, ); const sqlWhere = conn.makeWhere(filter.where); From ba51052d8836ab43df51f36baa21bc62392329fd Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 27 Nov 2024 17:52:45 +0100 Subject: [PATCH 18/81] feat: refs #7936 add SiiTypeInvoiceIn model and update invoice correction logic --- db/routines/sage/procedures/invoiceIn_add.sql | 2 +- db/versions/11368-whiteAspidistra/01-acls.sql | 23 +++++++++++++++++++ .../back/methods/invoice-in/corrective.js | 2 +- .../invoice-in/specs/corrective.spec.js | 2 +- .../back/models/invoice-in-correction.json | 7 +++--- modules/invoiceOut/back/model-config.json | 5 +++- .../back/models/sii-type-invoice-in.json | 22 ++++++++++++++++++ .../back/models/sii-type-invoice-out.json | 5 +--- 8 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 db/versions/11368-whiteAspidistra/01-acls.sql create mode 100644 modules/invoiceOut/back/models/sii-type-invoice-in.json diff --git a/db/routines/sage/procedures/invoiceIn_add.sql b/db/routines/sage/procedures/invoiceIn_add.sql index a3de50d6a..eeeb28143 100644 --- a/db/routines/sage/procedures/invoiceIn_add.sql +++ b/db/routines/sage/procedures/invoiceIn_add.sql @@ -207,7 +207,7 @@ BEGIN IF vInvoiceInOriginalFk THEN UPDATE movContaIVA mci JOIN vn.invoiceInCorrection iic ON iic.correctingFk = vInvoiceInFk - JOIN vn.siiTypeInvoiceOut st ON st.id = iic.siiTypeInvoiceOutFk + JOIN vn.siiTypeInvoiceIn st ON st.id = iic.siiTypeInvoiceInFk JOIN (SELECT issued, SUM(sub.taxableBase) taxableBase, SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat diff --git a/db/versions/11368-whiteAspidistra/01-acls.sql b/db/versions/11368-whiteAspidistra/01-acls.sql new file mode 100644 index 000000000..6ac98db43 --- /dev/null +++ b/db/versions/11368-whiteAspidistra/01-acls.sql @@ -0,0 +1,23 @@ +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES('SiiTypeInvoiceIn', 'find', 'READ', 'ALLOW', 'ROLE', 'salesPerson'); + +DROP TABLE IF EXISTS vn.invoiceInCorrection; + +CREATE TABLE `invoiceInCorrection` ( + `correctingFk` mediumint(8) unsigned NOT NULL COMMENT 'Factura rectificativa', + `correctedFk` mediumint(8) unsigned NOT NULL COMMENT 'Factura rectificada', + `cplusRectificationTypeFk` int(10) unsigned NOT NULL, + `siiTypeInvoiceInFk` int(10) unsigned NOT NULL, + `invoiceCorrectionTypeFk` int(11) NOT NULL DEFAULT 3, + PRIMARY KEY (`correctingFk`), + KEY `invoiceInCorrection_correctedFk` (`correctedFk`), + KEY `invoiceInCorrection_cplusRectificationTypeFk` (`cplusRectificationTypeFk`), + KEY `invoiceInCorrection_siiTypeInvoiceIn` (`siiTypeInvoiceInFk`), + KEY `invoiceInCorrection_invoiceCorrectionTypeFk` (`invoiceCorrectionTypeFk`), + CONSTRAINT `invoiceInCorrection_correctedFk` FOREIGN KEY (`correctedFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `invoiceInCorrection_correctingFk` FOREIGN KEY (`correctingFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `invoiceInCorrection_cplusRectificationTypeFk` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `cplusRectificationType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInCorrection_invoiceCorrectionTypeFk` FOREIGN KEY (`invoiceCorrectionTypeFk`) REFERENCES `invoiceCorrectionType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInCorrection_siiTypeInvoiceIn` FOREIGN KEY (`siiTypeInvoiceInFk`) REFERENCES `siiTypeInvoiceIn` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + diff --git a/modules/invoiceIn/back/methods/invoice-in/corrective.js b/modules/invoiceIn/back/methods/invoice-in/corrective.js index 05f632bcd..e7088d201 100644 --- a/modules/invoiceIn/back/methods/invoice-in/corrective.js +++ b/modules/invoiceIn/back/methods/invoice-in/corrective.js @@ -44,7 +44,7 @@ module.exports = Self => { correctingFk: clone.id, correctedFk: id, cplusRectificationTypeFk: invoiceType, - siiTypeInvoiceOutFk: invoiceClass, + siiTypeInvoiceInFk: invoiceClass, invoiceCorrectionTypeFk: invoiceReason }, myOptions); diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js index c63f02439..9f085694b 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js @@ -30,7 +30,7 @@ describe('invoiceIn corrective()', () => { }, options); expect(correction.cplusRectificationTypeFk).toEqual(invoiceType); - expect(correction.siiTypeInvoiceOutFk).toEqual(invoiceClass); + expect(correction.siiTypeInvoiceInFk).toEqual(invoiceClass); expect(correction.invoiceCorrectionTypeFk).toEqual(invoiceReason); }); }); diff --git a/modules/invoiceIn/back/models/invoice-in-correction.json b/modules/invoiceIn/back/models/invoice-in-correction.json index 52e16d420..d353f9e98 100644 --- a/modules/invoiceIn/back/models/invoice-in-correction.json +++ b/modules/invoiceIn/back/models/invoice-in-correction.json @@ -28,11 +28,10 @@ "model": "InvoiceCorrectionType", "foreignKey": "invoiceCorrectionTypeFk" }, - "siiTypeInvoiceOut": { + "siiTypeInvoiceIn": { "type": "belongsTo", - "model": "SiiTypeInvoiceOut", - "foreignKey": "siiTypeInvoiceOutFk" + "model": "SiiTypeInvoiceIn", + "foreignKey": "siiTypeInvoiceInFk" } - } } \ No newline at end of file diff --git a/modules/invoiceOut/back/model-config.json b/modules/invoiceOut/back/model-config.json index 9c7512429..710d824c3 100644 --- a/modules/invoiceOut/back/model-config.json +++ b/modules/invoiceOut/back/model-config.json @@ -43,5 +43,8 @@ }, "SiiTypeInvoiceOut": { "dataSource": "vn" + }, + "SiiTypeInvoiceIn": { + "dataSource": "vn" } -} +} \ No newline at end of file diff --git a/modules/invoiceOut/back/models/sii-type-invoice-in.json b/modules/invoiceOut/back/models/sii-type-invoice-in.json new file mode 100644 index 000000000..a191febb9 --- /dev/null +++ b/modules/invoiceOut/back/models/sii-type-invoice-in.json @@ -0,0 +1,22 @@ +{ + "name": "SiiTypeInvoiceIn", + "base": "VnModel", + "options": { + "mysql": { + "table": "siiTypeInvoiceIn" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "code": { + "type": "string" + }, + "description": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/modules/invoiceOut/back/models/sii-type-invoice-out.json b/modules/invoiceOut/back/models/sii-type-invoice-out.json index 37fd39c38..89f01bd74 100644 --- a/modules/invoiceOut/back/models/sii-type-invoice-out.json +++ b/modules/invoiceOut/back/models/sii-type-invoice-out.json @@ -17,9 +17,6 @@ }, "description": { "type": "string" - }, - "code": { - "type": "string" } } -} +} \ No newline at end of file From 7d5ae9dfbd4a0ba3a6ec4b34a46473ab475f4e1b Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 28 Nov 2024 14:52:41 +0100 Subject: [PATCH 19/81] feat: refs #7936 add reference rates for currency in fixtures --- db/dump/fixtures.before.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index e5d5f53dc..542d3dfe9 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4033,3 +4033,8 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); + +INSERT INTO vn.referenceRate (currencyFk, dated, value) + VALUES (2, '2000-12-01', 1.0495), + (2, '2001-01-01', 1.0531), + (2, '2001-02-01', 7.6347); \ No newline at end of file From 1f6e401e39c45fbb404b8c9434b0f9cb3d052169 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 11:53:07 +0100 Subject: [PATCH 20/81] feat: refs #7936 add save validation --- .../invoiceIn/back/methods/invoice-in/toUnbook.js | 3 ++- .../back/methods/invoice-in/updateInvoiceIn.js | 3 ++- modules/invoiceIn/back/models/invoice-in.js | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js index a697e9ddc..c27354d73 100644 --- a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js +++ b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js @@ -52,7 +52,8 @@ module.exports = Self => { accountingEntries = await models.Xdiario.count({ASIEN: asien}, myOptions); await models.Xdiario.destroyAll({ASIEN: asien}, myOptions); - await Self.updateAll({id: invoiceInId}, {isBooked: false}, myOptions); + const invoiceIn = await Self.findById(invoiceInId, myOptions); + await invoiceIn.updateAttribute('isBooked', false, myOptions); } else { const linkedBookEntry = await models.Xdiario.findOne({ fields: ['ASIEN'], diff --git a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js index 92a1ba8ee..2f1b4caca 100644 --- a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js +++ b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js @@ -82,7 +82,7 @@ module.exports = Self => { try { const invoiceIn = await Self.findById(id, null, myOptions); - invoiceIn.updateAttributes({supplierFk, + await invoiceIn.updateAttributes({supplierFk, supplierRef, issued, operated, @@ -94,6 +94,7 @@ module.exports = Self => { companyFk, withholdingSageFk }, myOptions); + if (tx) await tx.commit(); return invoiceIn; } catch (e) { diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index 1e69c0ef8..21aa230c5 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -19,4 +19,19 @@ module.exports = Self => { return new UserError(`This invoice has a linked vehicle.`); return err; }); + + Self.observe('before save', async function(ctx) { + if (ctx.newInstance) return; + + const changes = ctx.data || ctx.instance; + const orgData = ctx.currentInstance; + let isNotEditable = orgData.isBooked || (!orgData.isBooked && changes.isBooked); + + if (isNotEditable) { + for (const [key, value] of Object.entries(changes)) { + if (key !== 'isBooked' && value !== orgData[key]) + throw new UserError('InvoiceIn is already booked'); + } + } + }); }; From 332e1c62d9e1361df960d2a0e99033c4b5263e74 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 12:22:01 +0100 Subject: [PATCH 21/81] feat: refs #7936 add validation to InvoiceIn & InvoiceInTax --- .../invoiceIn/back/models/invoice-in-tax.js | 18 ++++++++++++++++++ modules/invoiceIn/back/models/invoice-in.js | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 modules/invoiceIn/back/models/invoice-in-tax.js diff --git a/modules/invoiceIn/back/models/invoice-in-tax.js b/modules/invoiceIn/back/models/invoice-in-tax.js new file mode 100644 index 000000000..a9d16ec42 --- /dev/null +++ b/modules/invoiceIn/back/models/invoice-in-tax.js @@ -0,0 +1,18 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.observe('before save', async function(ctx) { + if (ctx.newInstance) return; + + const models = Self.app.models; + const invoiceIn = await models.InvoiceIn.findById(ctx.currentInstance.invoiceInFk); + if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked'); + }); + + Self.observe('before delete', async function(ctx) { + const models = Self.app.models; + const invoiceInTax = await models.InvoiceInTax.findById(ctx.where.id); + const invoiceIn = await models.InvoiceIn.findById(invoiceInTax.invoiceInFk); + if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked'); + }); +}; diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index 21aa230c5..ff5d1ba86 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -34,4 +34,10 @@ module.exports = Self => { } } }); + + Self.observe('before delete', async function(ctx) { + const invoiceIn = await Self.findById(ctx.where.id); + if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked'); + }); }; + From 9ece52c5cecf15fa6d7350999f27cc3dd68d1b71 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 12:42:15 +0100 Subject: [PATCH 22/81] feat: refs #7936 add currency check to updateInvoiceIn --- .../back/methods/invoice-in/updateInvoiceIn.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js index 2f1b4caca..2b059f07b 100644 --- a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js +++ b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js @@ -72,6 +72,7 @@ module.exports = Self => { ) => { let tx; const myOptions = {userId: ctx.req.accessToken.userId}; + const models = Self.app.models; if (typeof options == 'object') Object.assign(myOptions, options); @@ -95,6 +96,17 @@ module.exports = Self => { withholdingSageFk }, myOptions); + if (currencyFk) { + const currency = await models.Currency.findById(currencyFk, null, myOptions); + if (currency.code === 'EUR') { + const invoiceInTaxes = await models.InvoiceInTax.find( + {where: {invoiceInFk: id}}, myOptions); + + for (const invoiceInTax of invoiceInTaxes) + await invoiceInTax.updateAttribute('foreignValue', null, myOptions); + } + } + if (tx) await tx.commit(); return invoiceIn; } catch (e) { From 163c6ddd20b2846cff8a01d2415aa0fb317facf0 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 13:44:42 +0100 Subject: [PATCH 23/81] feat: refs #7936 add currency handling in invoiceIn trigger --- .../vn/triggers/invoiceIn_afterUpdate.sql | 18 ++++++++++++------ .../back/methods/invoice-in/updateInvoiceIn.js | 11 ----------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/db/routines/vn/triggers/invoiceIn_afterUpdate.sql b/db/routines/vn/triggers/invoiceIn_afterUpdate.sql index 95b1d98a9..8f0a63465 100644 --- a/db/routines/vn/triggers/invoiceIn_afterUpdate.sql +++ b/db/routines/vn/triggers/invoiceIn_afterUpdate.sql @@ -3,24 +3,30 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`invoiceIn_afterUpdate` AFTER UPDATE ON `invoiceIn` FOR EACH ROW BEGIN - IF NEW.issued != OLD.issued - OR NEW.currencyFk != OLD.currencyFk THEN + DECLARE vIsEuro BOOL; + + SELECT if(`code` = 'EUR', TRUE, FALSE) INTO vIsEuro + FROM currency + WHERE id = NEW.currencyFk; + + IF (NOT NEW.issued <=> OLD.issued + OR NEW.currencyFk <> OLD.currencyFk) THEN UPDATE invoiceInTax iit JOIN invoiceIn ii ON ii.id = iit.invoiceInFk LEFT JOIN referenceRate rr ON rr.dated = ii.issued AND rr.currencyFk = ii.currencyFk - SET iit.taxableBase = IF(iit.foreignValue IS NULL, iit.taxableBase, iit.foreignValue / rr.value) + SET iit.taxableBase = IF(vIsEuro, iit.taxableBase, iit.foreignValue / rr.value), + iit.foreignValue = IF(vIsEuro, NULL, iit.foreignValue) WHERE ii.id = NEW.id; UPDATE invoiceInDueDay iidd JOIN invoiceIn ii ON ii.id = iidd.invoiceInFk LEFT JOIN referenceRate rr ON rr.dated = ii.issued AND rr.currencyFk = ii.currencyFk - SET iidd.amount = IF(iidd.foreignValue IS NULL, iidd.amount, iidd.foreignValue / rr.value) + SET iidd.amount = IF(vIsEuro, iidd.amount, iidd.foreignValue / rr.value), + iidd.foreignValue = IF(vIsEuro, NULL, iidd.foreignValue) WHERE ii.id = NEW.id; - END IF; - END$$ DELIMITER ; diff --git a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js index 2b059f07b..6006b1b14 100644 --- a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js +++ b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js @@ -96,17 +96,6 @@ module.exports = Self => { withholdingSageFk }, myOptions); - if (currencyFk) { - const currency = await models.Currency.findById(currencyFk, null, myOptions); - if (currency.code === 'EUR') { - const invoiceInTaxes = await models.InvoiceInTax.find( - {where: {invoiceInFk: id}}, myOptions); - - for (const invoiceInTax of invoiceInTaxes) - await invoiceInTax.updateAttribute('foreignValue', null, myOptions); - } - } - if (tx) await tx.commit(); return invoiceIn; } catch (e) { From c9cf96676b15f0d2d45469a3fbda417422008b8d Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 14:32:12 +0100 Subject: [PATCH 24/81] fix: refs #7936 check if insert in hook & change test description --- .../back/methods/invoice-in/specs/corrective.spec.js | 4 ++-- modules/invoiceIn/back/models/invoice-in-tax.js | 2 +- modules/invoiceIn/back/models/invoice-in.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js index 9f085694b..aee8d3f2c 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js @@ -15,11 +15,11 @@ describe('invoiceIn corrective()', () => { await tx.rollback(); }); - it('La función corrective debería devolver un id cuando se ejecuta correctamente', async() => { + it('should return an id when executed correctly', async() => { const originalId = 1; const invoiceReason = 3; const invoiceType = 2; - const invoiceClass = 1; + const invoiceClass = 8; const cloneId = await models.InvoiceIn.corrective(ctx, originalId, invoiceReason, invoiceType, invoiceClass, options); diff --git a/modules/invoiceIn/back/models/invoice-in-tax.js b/modules/invoiceIn/back/models/invoice-in-tax.js index a9d16ec42..0449d7719 100644 --- a/modules/invoiceIn/back/models/invoice-in-tax.js +++ b/modules/invoiceIn/back/models/invoice-in-tax.js @@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.observe('before save', async function(ctx) { - if (ctx.newInstance) return; + if (ctx.isNewInstance) return; const models = Self.app.models; const invoiceIn = await models.InvoiceIn.findById(ctx.currentInstance.invoiceInFk); diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index ff5d1ba86..ac197e904 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -21,7 +21,7 @@ module.exports = Self => { }); Self.observe('before save', async function(ctx) { - if (ctx.newInstance) return; + if (ctx.isNewInstance) return; const changes = ctx.data || ctx.instance; const orgData = ctx.currentInstance; From ac87905351ef6dbebaaee042f3c78132c44706d8 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 15:49:14 +0100 Subject: [PATCH 25/81] feat: refs #7936 add back test for updateInvoiceIn --- .../invoice-in/specs/updateInvoiceIn.spec.js | 59 +++++++++++++++++++ .../methods/invoice-in/updateInvoiceIn.js | 1 - 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 modules/invoiceIn/back/methods/invoice-in/specs/updateInvoiceIn.spec.js diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/updateInvoiceIn.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/updateInvoiceIn.spec.js new file mode 100644 index 000000000..4e856ec71 --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/specs/updateInvoiceIn.spec.js @@ -0,0 +1,59 @@ +const models = require('vn-loopback/server/server').models; + +const invoiceInId = 1; +const supplierId = 791; +fdescribe('invoiceIn updateInvoiceIn()', () => { + const ctx = beforeAll.getCtx(); + let options; + let tx; + + beforeEach(async() => { + options = {transaction: tx}; + tx = await models.Sale.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should update the invoice', async() => { + const invoiceBefore = await models.InvoiceIn.findById(invoiceInId, null, options); + await update(ctx, options); + const invoiceAfter = await models.InvoiceIn.findById(invoiceInId, null, options); + + expect(invoiceAfter.supplierFk).not.toBe(invoiceBefore.supplierFk); + expect(invoiceAfter.supplierFk).toBe(supplierId); + }); + + it('should not update the invoice if is booked', async() => { + let error; + try { + await models.InvoiceIn.toBook(ctx, invoiceInId, options); + await update(ctx, options); + } catch (e) { + error = e; + } + + expect(error.message).toBe('InvoiceIn is already booked'); + }); +}); + +async function update(ctx, opts) { + const supplierRef = 'mockRef'; + const currencyId = 1; + await models.InvoiceIn.updateInvoiceIn(ctx, + invoiceInId, + supplierId, + supplierRef, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + currencyId, + undefined, + undefined, + opts); +} diff --git a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js index 6006b1b14..2f1b4caca 100644 --- a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js +++ b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js @@ -72,7 +72,6 @@ module.exports = Self => { ) => { let tx; const myOptions = {userId: ctx.req.accessToken.userId}; - const models = Self.app.models; if (typeof options == 'object') Object.assign(myOptions, options); From 59b5dd5a3627c08c8e1a5d0be468d00833cf68af Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 16:25:47 +0100 Subject: [PATCH 26/81] feat: refs #7936 add tests for invoiceIn --- .../invoice-in/specs/invoiceIn.spec.js | 66 +++++++++++++++++++ .../invoice-in/specs/updateInvoiceIn.spec.js | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js new file mode 100644 index 000000000..4e2ee36d5 --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js @@ -0,0 +1,66 @@ +const models = require('vn-loopback/server/server').models; + +fdescribe('invoiceIn', () => { + let options; + let tx; + const invoiceId = 1; + const supplierId = 791; + const currencyId = 1; + const companyId = 442; + + beforeEach(async() => { + options = {transaction: tx}; + tx = await models.InvoiceIn.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should allow insert for new instance', async() => { + const newInvoice = { + supplierFk: supplierId, + issued: Date.vnNew(), + operated: Date.vnNew(), + currencyFk: currencyId, + companyFk: companyId, + isBooked: false + }; + + const createdInvoice = await models.InvoiceIn.create(newInvoice, options); + + expect(createdInvoice).toBeDefined(); + expect(createdInvoice.id).toBeDefined(); + }); + + it('should throw an error if trying to update a booked invoice', async() => { + const invoice = await models.InvoiceIn.findById(invoiceId, null, options); + await invoice.updateAttribute('isBooked', true, options); + + let error; + try { + await invoice.updateAttribute('supplierFk', supplierId, options); + } catch (err) { + error = err; + } + + expect(error).toBeDefined(); + expect(error.message).toBe('InvoiceIn is already booked'); + }); + + it('should throw an error if trying to delete a booked invoice', async() => { + const invoice = await models.InvoiceIn.findById(invoiceId, null, options); + await invoice.updateAttribute('isBooked', true, options); + + let error; + try { + await models.InvoiceIn.deleteById(invoiceId, options); + } catch (err) { + error = err; + } + + expect(error).toBeDefined(); + expect(error.sqlMessage).toBe('InvoiceIn is already booked'); + }); +}); diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/updateInvoiceIn.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/updateInvoiceIn.spec.js index 4e856ec71..773e2ac2f 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/updateInvoiceIn.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/updateInvoiceIn.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; const invoiceInId = 1; const supplierId = 791; -fdescribe('invoiceIn updateInvoiceIn()', () => { +describe('invoiceIn updateInvoiceIn()', () => { const ctx = beforeAll.getCtx(); let options; let tx; From 00085f2b99d61086908ee29975cd731cbcf5b2c9 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 17:05:13 +0100 Subject: [PATCH 27/81] feat: refs #7936 add tests for invoiceIn filter --- .../methods/invoice-in/specs/filter.spec.js | 17 +++++++++++++++++ .../methods/invoice-in/specs/invoiceIn.spec.js | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js index 48310b32a..beaa608e6 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js @@ -166,4 +166,21 @@ describe('InvoiceIn filter()', () => { throw e; } }); + + it('should return the invoice in matching companyFk', async() => { + const tx = await models.InvoiceIn.beginTransaction({}); + const options = {transaction: tx}; + + try { + const company = await models.Company.findOne({}, options); + const invoicesByCompany = await models.InvoiceIn.find({where: {companyFk: company.id}}, options); + const filteredInvoices = await models.InvoiceIn.filter({args: {companyFk: company.id}}, {}, options); + + expect(filteredInvoices.length).toEqual(invoicesByCompany.length); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js index 4e2ee36d5..69038d9fd 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('invoiceIn', () => { +describe('invoiceIn', () => { let options; let tx; const invoiceId = 1; From 5b04debfb157b6240e4e1ba2f6bf32814930b91b Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 2 Dec 2024 17:48:40 +0100 Subject: [PATCH 28/81] refactor: refs #7936 add transaction & tests --- .../invoice-in/specs/invoiceIn.spec.js | 7 +- .../invoice-in/specs/invoiceInTax.spec.js | 74 +++++++++++++++++++ .../invoiceIn/back/models/invoice-in-tax.js | 6 +- modules/invoiceIn/back/models/invoice-in.js | 2 +- 4 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 modules/invoiceIn/back/methods/invoice-in/specs/invoiceInTax.spec.js diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js index 69038d9fd..a83aad3b2 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/invoiceIn.spec.js @@ -9,9 +9,8 @@ describe('invoiceIn', () => { const companyId = 442; beforeEach(async() => { - options = {transaction: tx}; tx = await models.InvoiceIn.beginTransaction({}); - options.transaction = tx; + options = {transaction: tx}; }); afterEach(async() => { @@ -45,7 +44,6 @@ describe('invoiceIn', () => { error = err; } - expect(error).toBeDefined(); expect(error.message).toBe('InvoiceIn is already booked'); }); @@ -60,7 +58,6 @@ describe('invoiceIn', () => { error = err; } - expect(error).toBeDefined(); - expect(error.sqlMessage).toBe('InvoiceIn is already booked'); + expect(error.message).toBe('InvoiceIn is already booked'); }); }); diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/invoiceInTax.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/invoiceInTax.spec.js new file mode 100644 index 000000000..e822189bd --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/specs/invoiceInTax.spec.js @@ -0,0 +1,74 @@ +const models = require('vn-loopback/server/server').models; + +describe('invoiceInTax', () => { + let options; + let tx; + const invoiceInId = 1; + const invoiceInTaxId = 1; + beforeEach(async() => { + tx = await models.InvoiceInTax.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should throw an error if trying to save a tax from a booked invoice', async() => { + const invoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options); + await invoiceIn.updateAttributes({isBooked: true}, options); + const invoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options); + let error; + try { + await invoiceInTax.updateAttribute('taxableBase', 100, options); + } catch (err) { + error = err; + } + + expect(error.message).toBe('InvoiceIn is already booked'); + }); + + it('should allow save if the invoice is not booked', async() => { + const invoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options); + await invoiceIn.updateAttribute('isBooked', false, options); + + const invoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options); + await invoiceInTax.updateAttribute('taxableBase', 100, options); + + const updatedInvoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options); + + expect(updatedInvoiceInTax.taxableBase).toBe(100); + }); + + it('should throw an error if trying to delete a tax from a booked invoice', async() => { + const invoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options); + await invoiceIn.updateAttribute('isBooked', true, options); + + let error; + try { + await models.InvoiceInTax.destroyById(invoiceInTaxId, options); + } catch (err) { + error = err; + } + + expect(error).toBeDefined(); + expect(error.message).toBe('InvoiceIn is already booked'); + }); + + it('should allow delete if the invoice is not booked', async() => { + const invoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options); + await invoiceIn.updateAttribute('isBooked', false, options); + + let error; + try { + await models.InvoiceInTax.destroyById(invoiceInTaxId, options); + } catch (err) { + error = err; + } + + const deletedInvoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options); + + expect(error).toBeUndefined(); + expect(deletedInvoiceInTax).toBeNull(); + }); +}); diff --git a/modules/invoiceIn/back/models/invoice-in-tax.js b/modules/invoiceIn/back/models/invoice-in-tax.js index 0449d7719..ce33fe18f 100644 --- a/modules/invoiceIn/back/models/invoice-in-tax.js +++ b/modules/invoiceIn/back/models/invoice-in-tax.js @@ -5,14 +5,14 @@ module.exports = Self => { if (ctx.isNewInstance) return; const models = Self.app.models; - const invoiceIn = await models.InvoiceIn.findById(ctx.currentInstance.invoiceInFk); + const invoiceIn = await models.InvoiceIn.findById(ctx.currentInstance.invoiceInFk, null, ctx.options); if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked'); }); Self.observe('before delete', async function(ctx) { const models = Self.app.models; - const invoiceInTax = await models.InvoiceInTax.findById(ctx.where.id); - const invoiceIn = await models.InvoiceIn.findById(invoiceInTax.invoiceInFk); + const invoiceInTax = await Self.findById(ctx.where.id, null, ctx.options); + const invoiceIn = await models.InvoiceIn.findById(invoiceInTax.invoiceInFk, null, ctx.options); if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked'); }); }; diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index ac197e904..ca506b54d 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -36,7 +36,7 @@ module.exports = Self => { }); Self.observe('before delete', async function(ctx) { - const invoiceIn = await Self.findById(ctx.where.id); + const invoiceIn = await Self.findById(ctx.where.id, null, ctx.options); if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked'); }); }; From f69dfbd5aa89463c52e315f9a6c35e8c863524d3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 9 Dec 2024 14:03:45 +0100 Subject: [PATCH 29/81] refactor: refs #7936 remove schema --- db/routines/vn/triggers/invoiceIn_afterUpdate.sql | 2 +- db/versions/11368-whiteAspidistra/00-firstScript.sql | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/triggers/invoiceIn_afterUpdate.sql b/db/routines/vn/triggers/invoiceIn_afterUpdate.sql index 8f0a63465..8c2785e38 100644 --- a/db/routines/vn/triggers/invoiceIn_afterUpdate.sql +++ b/db/routines/vn/triggers/invoiceIn_afterUpdate.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`invoiceIn_afterUpdate` BEGIN DECLARE vIsEuro BOOL; - SELECT if(`code` = 'EUR', TRUE, FALSE) INTO vIsEuro + SELECT `code` = 'EUR' INTO vIsEuro FROM currency WHERE id = NEW.currencyFk; diff --git a/db/versions/11368-whiteAspidistra/00-firstScript.sql b/db/versions/11368-whiteAspidistra/00-firstScript.sql index 333fa1315..f36832805 100644 --- a/db/versions/11368-whiteAspidistra/00-firstScript.sql +++ b/db/versions/11368-whiteAspidistra/00-firstScript.sql @@ -2,13 +2,13 @@ DROP TRIGGER IF EXISTS invoiceIn_beforeUpdate; - UPDATE vn.invoiceIn + UPDATE invoiceIn SET cplusRectificationTypeFk = NULL WHERE cplusRectificationTypeFk = 1; - DELETE IGNORE FROM vn.cplusRectificationType WHERE id = 1; + DELETE IGNORE FROM cplusRectificationType WHERE id = 1; - UPDATE vn.cplusRectificationType + UPDATE cplusRectificationType SET id = 1 WHERE id = 3; @@ -25,7 +25,7 @@ BEGIN SET NEW.editorFk = account.myUser_getId(); - IF (SELECT COUNT(*) FROM vn.invoiceIn + IF (SELECT COUNT(*) FROM invoiceIn WHERE supplierRef = NEW.supplierRef AND supplierFk = NEW.supplierFk AND YEAR(issued) = YEAR(NEW.issued) @@ -37,7 +37,7 @@ BEGIN IF NEW.supplierFk != OLD.supplierFk THEN CALL supplier_checkIsActive(NEW.supplierFk); SELECT withholdingSageFk INTO vWithholdingSageFk - FROM vn.supplier + FROM supplier WHERE id = NEW.supplierFk; SET NEW.withholdingSageFk = vWithholdingSageFk; END IF; From 46448d5fc20d5346c1cd0a70888b00f91f5d3172 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 10 Dec 2024 10:27:35 +0100 Subject: [PATCH 30/81] fix: refs #7936 change type --- modules/invoiceIn/back/models/invoice-in-tax.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/invoiceIn/back/models/invoice-in-tax.json b/modules/invoiceIn/back/models/invoice-in-tax.json index 53b5548b6..256ee0553 100644 --- a/modules/invoiceIn/back/models/invoice-in-tax.json +++ b/modules/invoiceIn/back/models/invoice-in-tax.json @@ -22,12 +22,11 @@ "type": "number" }, "expenseFk": { - "type": "number" + "type": "string" }, "created": { "type": "date" } - }, "relations": { "invoiceIn": { @@ -51,4 +50,4 @@ "foreignKey": "transactionTypeSageFk" } } -} +} \ No newline at end of file From addb093b6b37a76c19bce6b299cd0eb25c65b589 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 11 Dec 2024 17:42:03 +0100 Subject: [PATCH 31/81] feat: refs #7936 add minimum due date --- modules/invoiceIn/back/methods/invoice-in/filter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/filter.js b/modules/invoiceIn/back/methods/invoice-in/filter.js index c549769ab..f081368e4 100644 --- a/modules/invoiceIn/back/methods/invoice-in/filter.js +++ b/modules/invoiceIn/back/methods/invoice-in/filter.js @@ -189,7 +189,8 @@ module.exports = Self => { s.account, SUM(iid.amount) amount, sub.code awbCode, - c.code + c.code, + MIN(iid.dueDated) dueDated FROM invoiceIn ii JOIN supplier s ON s.id = ii.supplierFk LEFT JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id From c83f34859a02228e273b267e0e8717c5cc87df9e Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 12 Dec 2024 11:20:23 +0100 Subject: [PATCH 32/81] feat: refs #7936 return country code & is vies fields --- modules/invoiceIn/back/methods/invoice-in/summary.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/summary.js b/modules/invoiceIn/back/methods/invoice-in/summary.js index fe198b2b4..b3fd9ee97 100644 --- a/modules/invoiceIn/back/methods/invoice-in/summary.js +++ b/modules/invoiceIn/back/methods/invoice-in/summary.js @@ -37,7 +37,13 @@ module.exports = Self => { { relation: 'supplier', scope: { - fields: ['id', 'name'] + fields: ['id', 'name', 'isVies', 'countryFk'], + include: [{ + relation: 'country', + scope: { + fields: ['id', 'code'] + } + }] } }, { From e748e9a0127bb25bb62ecdcc9a0390b4281d2d7e Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 13 Dec 2024 08:30:23 +0100 Subject: [PATCH 33/81] feat: refs #7235 add serialType parameter to getInvoiceDate and implement corresponding tests --- modules/account/back/methods/account/sync.js | 4 +- .../back/methods/invoiceOut/getInvoiceDate.js | 15 ++++--- .../invoiceOut/specs/getInvoiceDate.spec.js | 39 +++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 modules/invoiceOut/back/methods/invoiceOut/specs/getInvoiceDate.spec.js diff --git a/modules/account/back/methods/account/sync.js b/modules/account/back/methods/account/sync.js index 1026c5020..b38e4dd37 100644 --- a/modules/account/back/methods/account/sync.js +++ b/modules/account/back/methods/account/sync.js @@ -29,14 +29,14 @@ module.exports = Self => { const models = Self.app.models; const myOptions = {}; let tx; - + if (typeof options == 'object') Object.assign(myOptions, options); if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; - }; + } try { const user = await models.VnUser.findOne({ diff --git a/modules/invoiceOut/back/methods/invoiceOut/getInvoiceDate.js b/modules/invoiceOut/back/methods/invoiceOut/getInvoiceDate.js index dcc1fa6e8..493f19aa7 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/getInvoiceDate.js +++ b/modules/invoiceOut/back/methods/invoiceOut/getInvoiceDate.js @@ -7,7 +7,12 @@ module.exports = Self => { arg: 'companyFk', type: 'number', required: true - } + }, + { + arg: 'serialType', + type: 'string', + required: true + }, ], returns: { type: ['object'], @@ -19,16 +24,16 @@ module.exports = Self => { } }); - Self.getInvoiceDate = async companyFk => { + Self.getInvoiceDate = async(companyFk, serialType) => { const models = Self.app.models; const [invoiceDate] = await models.InvoiceOut.rawSql( `SELECT MAX(io.issued) issued FROM invoiceOut io JOIN invoiceOutSerial ios ON ios.code = io.serial - WHERE ios.type = 'global' - AND io.issued + WHERE ios.type = ? + AND io.issued AND io.companyFk = ?`, - [companyFk] + [serialType, companyFk] ); return invoiceDate; }; diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/getInvoiceDate.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/getInvoiceDate.spec.js new file mode 100644 index 000000000..830402250 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/getInvoiceDate.spec.js @@ -0,0 +1,39 @@ +const models = require('vn-loopback/server/server').models; +const moment = require('moment'); + +describe('getInvoiceDate()', () => { + const companyFk = 442; + let tx; + let options; + + beforeEach(async() => { + tx = await models.InvoiceOut.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should return a correct date for serialType "global"', async() => { + const serialType = 'global'; + const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options); + + expect(moment(result.issued).format('YYYY-MM-DD')).toEqual('2000-12-01'); + }); + + it('should return null for serialType "multiple"', async() => { + const serialType = 'multiple'; + const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options); + + expect(result.issued).toBeNull(); + }); + + it('should return correct date for serialType "quick"', async() => { + const serialType = 'quick'; + const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options); + + expect(moment(result.issued).format('YYYY-MM-DD')).toEqual('2001-01-01'); + }); +}); + From 9c32dc5707630b5c67a183409465015946348e61 Mon Sep 17 00:00:00 2001 From: Jtubau Date: Mon, 16 Dec 2024 08:34:53 +0100 Subject: [PATCH 34/81] feat: refs #8293 include zone data --- modules/claim/back/methods/claim/filter.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/claim/back/methods/claim/filter.js b/modules/claim/back/methods/claim/filter.js index f60b6572e..bacdd4021 100644 --- a/modules/claim/back/methods/claim/filter.js +++ b/modules/claim/back/methods/claim/filter.js @@ -80,6 +80,12 @@ module.exports = Self => { description: 'The claimResponsible id', http: {source: 'query'} }, + { + arg: 'zoneFk', + type: 'string', + description: 'The zone name', + http: {source: 'query'} + }, { arg: 'myTeam', type: 'boolean', @@ -174,6 +180,8 @@ module.exports = Self => { to.setHours(23, 59, 59, 999); return {'cl.created': {between: [value, to]}}; + case 'zoneFk': + return {'t.zoneFk': value}; case 'myTeam': if (value) return {'cl.workerFk': {inq: teamMembersId}}; @@ -195,11 +203,15 @@ module.exports = Self => { u.name AS workerName, cs.code stateCode, cs.description stateDescription, - cl.created + cl.created, + z.name zoneName, + z.id zoneId FROM claim cl LEFT JOIN client c ON c.id = cl.clientFk LEFT JOIN account.user u ON u.id = cl.workerFk - LEFT JOIN claimState cs ON cs.id = cl.claimStateFk` + LEFT JOIN claimState cs ON cs.id = cl.claimStateFk + LEFT JOIN ticket t ON t.id = cl.ticketFk + LEFT JOIN zone z ON z.id = t.zoneFk` ); stmt.merge(conn.makeSuffix(filter)); From d9eab361600ab1eddcd1f02576bebef0932146b3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 16 Dec 2024 09:35:41 +0100 Subject: [PATCH 35/81] fix: refs #7936 conflicts --- db/routines/sage/procedures/invoiceIn_add.sql | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/db/routines/sage/procedures/invoiceIn_add.sql b/db/routines/sage/procedures/invoiceIn_add.sql index eeeb28143..8fdbb9ce3 100644 --- a/db/routines/sage/procedures/invoiceIn_add.sql +++ b/db/routines/sage/procedures/invoiceIn_add.sql @@ -25,7 +25,7 @@ BEGIN DECLARE vIsInformativeExportation BOOL DEFAULT FALSE; DECLARE vCursor CURSOR FOR - SELECT it.taxableBase, + SELECT SUM(it.taxableBase), CAST(SUM((( it.taxableBase / 100) * t.PorcentajeIva)) AS DECIMAL (10,2)), t.PorcentajeIva, it.transactionTypeSageFk, @@ -204,25 +204,25 @@ BEGIN FROM vn.invoiceInCorrection WHERE correctingFk = vInvoiceInFk; - IF vInvoiceInOriginalFk THEN + IF vInvoiceInOriginalFk THEN UPDATE movContaIVA mci JOIN vn.invoiceInCorrection iic ON iic.correctingFk = vInvoiceInFk JOIN vn.siiTypeInvoiceIn st ON st.id = iic.siiTypeInvoiceInFk JOIN (SELECT issued, - SUM(sub.taxableBase) taxableBase, + SUM(sub.taxableBase) taxableBase, SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat FROM(SELECT issued, - SUM(iit.taxableBase) taxableBase, + SUM(iit.taxableBase) taxableBase, ti.PorcentajeIva - FROM vn.invoiceIn i + FROM vn.invoiceIn i JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id JOIN TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk WHERE i.id = vInvoiceInOriginalFk GROUP BY ti.CodigoIva)sub )invoiceInOriginal JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa' - SET mci.TipoRectificativa = iic.cplusRectificationTypeFk, - mci.ClaseAbonoRectificativas = REGEXP_REPLACE(st.`code`, '[^0-9]', ''), + SET mci.TipoRectificativa = iir.refundCategoryFk, + mci.ClaseAbonoRectificativas = iir.refundType, mci.FechaFacturaOriginal = invoiceInOriginal.issued, mci.FechaOperacion = invoiceInOriginal.issued, mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase, @@ -231,5 +231,4 @@ BEGIN WHERE mci.id = vXDiarioFk; END IF; END$$ -$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; From acccb4abc3bd548af0f3e9ce524b818f75f8191f Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 17 Dec 2024 12:19:46 +0100 Subject: [PATCH 36/81] fix: hotfix mix --- modules/travel/back/methods/travel/filter.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index b96873925..30c1a45fa 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -83,6 +83,14 @@ module.exports = Self => { arg: 'daysOnward', type: 'number', description: 'The days onward' + }, { + arg: 'shipped', + type: 'date', + description: 'The shipped date' + }, { + arg: 'landed', + type: 'date', + description: 'The landed date' } ], returns: { @@ -108,6 +116,10 @@ module.exports = Self => { : {'t.ref': {like: `%${value}%`}}; case 'ref': return {'t.ref': {like: `%${value}%`}}; + case 'shipped': + return {'t.shipped': value}; + case 'landed': + return {'t.landed': value}; case 'shippedFrom': return {'t.shipped': {gte: value}}; case 'shippedTo': From f965f7aa52d2bd394ecd89d2bd7b1538c84f81e0 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 17 Dec 2024 12:46:48 +0100 Subject: [PATCH 37/81] fix: refs #6583 update onlyWithDestination logic to handle null values correctly --- modules/ticket/back/methods/ticket/getTicketsAdvance.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 6abac455f..58d46173c 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -109,8 +109,7 @@ module.exports = Self => { case 'departmentFk': return {'f.departmentFk': value}; case 'onlyWithDestination': - if (!value) return; - return {'f.id': {neq: null}}; + return {'f.id': value ? {neq: null} : null}; } }); From b935878dd6ec75820bf1d4159c20d029f4b6b0a1 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 17 Dec 2024 12:58:25 +0100 Subject: [PATCH 38/81] feat: refs #6583 add tests --- .../ticket/specs/getTicketsAdvance.spec.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index a941013cd..bb7f230ee 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -167,4 +167,56 @@ describe('TicketFuture getTicketsAdvance()', () => { throw e; } }); + + it('should return the tickets with only destination', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const args = { + dateFuture: today, + dateToAdvance: today.setHours(23, 59, 59, 999), + warehouseFk: 1, + }; + ctx.args = args; + + const allTickets = await models.Ticket.getTicketsAdvance(ctx, options); + ctx.args.onlyWithDestination = true; + const withDestinationTickets = await models.Ticket.getTicketsAdvance(ctx, options); + + expect(allTickets.filter(ticket => ticket.id).length).toBe(withDestinationTickets.length); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + fit('should return the tickets without only destination', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const args = { + dateFuture: today, + dateToAdvance: today.setHours(23, 59, 59, 999), + warehouseFk: 1, + }; + ctx.args = args; + + const allTickets = await models.Ticket.getTicketsAdvance(ctx, options); + ctx.args.onlyWithDestination = false; + const withoutDestinationTickets = await models.Ticket.getTicketsAdvance(ctx, options); + + expect(allTickets.filter(ticket => !ticket.id).length).toBe(withoutDestinationTickets.length); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 9ac8e60f0cb31de688f8d385d16afab5f603f525 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 17 Dec 2024 12:58:57 +0100 Subject: [PATCH 39/81] fix: refs #6583 drop focus --- .../ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index bb7f230ee..e71942341 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -194,7 +194,7 @@ describe('TicketFuture getTicketsAdvance()', () => { } }); - fit('should return the tickets without only destination', async() => { + it('should return the tickets without only destination', async() => { const tx = await models.Ticket.beginTransaction({}); try { From 31952725aa23b50171f42f27b914d1656dc130d6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 17 Dec 2024 13:33:29 +0100 Subject: [PATCH 40/81] refactor: refs #6583 use warehouseId var --- .../ticket/specs/getTicketsAdvance.spec.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index e71942341..157cdb1ff 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -8,6 +8,7 @@ describe('TicketFuture getTicketsAdvance()', () => { tomorrow.setDate(today.getDate() + 1); const salesDeptId = 43; const spain1DeptId = 95; + const warehouseId = 1; beforeAll.mockLoopBackContext(); it('should return the tickets passing the required data', async() => { @@ -19,7 +20,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, }; ctx.args = args; @@ -42,7 +43,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, isFullMovable: true }; @@ -67,7 +68,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, isFullMovable: false }; @@ -92,7 +93,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, ipt: 'V' }; @@ -117,7 +118,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, tfIpt: 'V' }; @@ -141,7 +142,7 @@ describe('TicketFuture getTicketsAdvance()', () => { ctx.args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, }; await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options); @@ -177,7 +178,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: today, dateToAdvance: today.setHours(23, 59, 59, 999), - warehouseFk: 1, + warehouseFk: warehouseId, }; ctx.args = args; @@ -203,7 +204,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: today, dateToAdvance: today.setHours(23, 59, 59, 999), - warehouseFk: 1, + warehouseFk: warehouseId, }; ctx.args = args; From 1a8b05c46bb782a2fd46e1b05329be25744fac2b Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 Dec 2024 07:08:23 +0100 Subject: [PATCH 41/81] fix: refs #8315 fixture claimDevelopment --- db/dump/fixtures.before.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 57a9f9ca8..c2afbb7b4 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1922,7 +1922,7 @@ INSERT INTO `vn`.`claimDestination`(`id`, `description`, `addressFk`) INSERT INTO `vn`.`claimDevelopment`(`id`, `claimFk`, `claimResponsibleFk`, `workerFk`, `claimReasonFk`, `claimResultFk`, `claimRedeliveryFk`, `claimDestinationFk`) VALUES - (1, 1, 1, 21, 1, 1, 2, 5), + (1, 1, 1, 21, 7, 1, 2, 5), (2, 1, 2, 21, 7, 2, 2, 5), (3, 2, 7, 21, 9, 3, 2, 5), (4, 3, 7, 21, 15, 8, 2, 5), From 42c3cdae5d76d8da0420c8aff7fee07ba1f2f35c Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 Dec 2024 11:33:48 +0100 Subject: [PATCH 42/81] build: init version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e823eaad..a843ac9c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.52.0", + "version": "25.02.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From c0893f8684e4d6cdbe1f2af731d5c2c81c09076a Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 18 Dec 2024 13:06:01 +0100 Subject: [PATCH 43/81] feat: refs #7936 add locale --- modules/invoiceIn/back/locale/invoiceIn/en.yml | 7 ++++++- modules/invoiceIn/back/locale/invoiceIn/es.yml | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/invoiceIn/back/locale/invoiceIn/en.yml b/modules/invoiceIn/back/locale/invoiceIn/en.yml index 9e94eba0d..6940b6f77 100644 --- a/modules/invoiceIn/back/locale/invoiceIn/en.yml +++ b/modules/invoiceIn/back/locale/invoiceIn/en.yml @@ -17,4 +17,9 @@ columns: isVatDeductible: is VAT deductible withholdingSageFk: withholding expenseFkDeductible: expense deductible - editorFk: editor \ No newline at end of file + editorFk: editor + cplusRectificationTypeFk: cplus rectification type + cplusSubjectOpFk: cplus subject op + cplusTaxBreakFk: cplus tax break + siiTrasCendencyInvoiceInFk: sii tras cendency invoice in + siiTypeInvoiceInFk: sii type invoice in \ No newline at end of file diff --git a/modules/invoiceIn/back/locale/invoiceIn/es.yml b/modules/invoiceIn/back/locale/invoiceIn/es.yml index bd64c4327..9599c0535 100644 --- a/modules/invoiceIn/back/locale/invoiceIn/es.yml +++ b/modules/invoiceIn/back/locale/invoiceIn/es.yml @@ -5,7 +5,7 @@ columns: serial: serie supplierFk: proveedor issued: fecha emisión - supplierRef: referéncia proveedor + supplierRef: referencia proveedor isBooked: facturado currencyFk: moneda created: creado @@ -17,4 +17,9 @@ columns: isVatDeductible: impuesto deducible withholdingSageFk: código de retención expenseFkDeductible: gasto deducible - editorFk: editor \ No newline at end of file + editorFk: editor + cplusRectificationTypeFk: tipo de rectificación cplus + cplusSubjectOpFk: sujeto op cplus + cplusTaxBreakFk: exención fiscal cplus + siiTrasCendencyInvoiceInFk: trascendencia sii factura recibida + siiTypeInvoiceInFk: tipo sii factura recibida \ No newline at end of file From 94136d35ff284cd5a07bbbc909616450419f8fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 18 Dec 2024 12:22:59 +0000 Subject: [PATCH 44/81] Actualizar db/routines/vn/triggers/route_afterUpdate.sql --- db/routines/vn/triggers/route_afterUpdate.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/routines/vn/triggers/route_afterUpdate.sql b/db/routines/vn/triggers/route_afterUpdate.sql index 447608acc..a15c1a4b7 100644 --- a/db/routines/vn/triggers/route_afterUpdate.sql +++ b/db/routines/vn/triggers/route_afterUpdate.sql @@ -22,6 +22,7 @@ BEGIN OR !(NEW.workerFk <=> OLD.workerFk) OR !(NEW.m3 <=> OLD.m3) OR !(NEW.agencyModeFk <=> OLD.agencyModeFk) + OR !(NEW.dated <=> OLD.dated) OR !(NEW.vehicleFk <=> OLD.vehicleFk)THEN CALL route_calcCommission(NEW.id); END IF; From 1ba23ad45057893a6612a62e1844025c0b353657 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 18 Dec 2024 13:27:43 +0100 Subject: [PATCH 45/81] feat: refs #8073 #refs 8073 create vn.productionCountryVolume --- db/versions/11387-whiteDendro/00-firstScript.sql | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 db/versions/11387-whiteDendro/00-firstScript.sql diff --git a/db/versions/11387-whiteDendro/00-firstScript.sql b/db/versions/11387-whiteDendro/00-firstScript.sql new file mode 100644 index 000000000..4461b945d --- /dev/null +++ b/db/versions/11387-whiteDendro/00-firstScript.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS vn.productionCountryVolume( + id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + countryFk MEDIUMINT(8) UNSIGNED NOT NULL, + estimate DECIMAL(6, 2), + PRIMARY KEY (id), + CONSTRAINT productionCountryVolume_countryFK + FOREIGN KEY (countryFk) REFERENCES vn.country (id) + ON DELETE RESTRICT ON UPDATE CASCADE +) COMMENT = 'Estimación del crecimiento por país' \ No newline at end of file From 148ab57b1a1cf0bc4d42f999a039951ace7c41a8 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 18 Dec 2024 15:06:49 +0100 Subject: [PATCH 46/81] feat: refs #8073 change names and primary key --- db/versions/11387-whiteDendro/00-firstScript.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/versions/11387-whiteDendro/00-firstScript.sql b/db/versions/11387-whiteDendro/00-firstScript.sql index 4461b945d..3226dfc42 100644 --- a/db/versions/11387-whiteDendro/00-firstScript.sql +++ b/db/versions/11387-whiteDendro/00-firstScript.sql @@ -1,8 +1,7 @@ -CREATE TABLE IF NOT EXISTS vn.productionCountryVolume( - id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, +CREATE TABLE IF NOT EXISTS vn.productionCountry( countryFk MEDIUMINT(8) UNSIGNED NOT NULL, - estimate DECIMAL(6, 2), - PRIMARY KEY (id), + volumeGrowthEstimatePercent DECIMAL(6, 2), + PRIMARY KEY (countryFk), CONSTRAINT productionCountryVolume_countryFK FOREIGN KEY (countryFk) REFERENCES vn.country (id) ON DELETE RESTRICT ON UPDATE CASCADE From 83d46d0a281d9b9fbbda13a798c52aee79e67174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 18 Dec 2024 17:58:30 +0100 Subject: [PATCH 47/81] feat: refs #8324 country unique --- db/versions/11390-goldenPalmetto/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/versions/11390-goldenPalmetto/00-firstScript.sql diff --git a/db/versions/11390-goldenPalmetto/00-firstScript.sql b/db/versions/11390-goldenPalmetto/00-firstScript.sql new file mode 100644 index 000000000..adcc76e4f --- /dev/null +++ b/db/versions/11390-goldenPalmetto/00-firstScript.sql @@ -0,0 +1,3 @@ + +ALTER TABLE vn.country + ADD CONSTRAINT country_unique_name UNIQUE KEY (name); From 9ae27e104e006a964f7feb2cf8aa51a16f12a3a7 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 19 Dec 2024 07:07:56 +0100 Subject: [PATCH 48/81] feat: refs #8167 update canBeInvoiced method to include active status check and improve test cases --- .../back/methods/client/canBeInvoiced.js | 9 +-- .../client/specs/canBeInvoiced.spec.js | 67 ++++++++----------- 2 files changed, 30 insertions(+), 46 deletions(-) diff --git a/modules/client/back/methods/client/canBeInvoiced.js b/modules/client/back/methods/client/canBeInvoiced.js index cdb865500..536606b0b 100644 --- a/modules/client/back/methods/client/canBeInvoiced.js +++ b/modules/client/back/methods/client/canBeInvoiced.js @@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = function(Self) { Self.remoteMethod('canBeInvoiced', { - description: 'Change property isEqualizated in all client addresses', + description: 'Check if a client can be invoiced', accessType: 'READ', accepts: [ { @@ -38,7 +38,7 @@ module.exports = function(Self) { Object.assign(myOptions, options); const client = await models.Client.findById(id, { - fields: ['id', 'isTaxDataChecked', 'hasToInvoice', 'payMethodFk'], + fields: ['id', 'isTaxDataChecked', 'hasToInvoice', 'payMethodFk', 'isActive'], include: { relation: 'payMethod', @@ -53,9 +53,6 @@ module.exports = function(Self) { if (client.payMethod().code === 'wireTransfer' && !company.supplierAccountFk) throw new UserError('The company has not informed the supplier account for bank transfers'); - if (client.isTaxDataChecked && client.hasToInvoice) - return true; - - return false; + return client.isTaxDataChecked && client.hasToInvoice && client.isActive; }; }; diff --git a/modules/client/back/methods/client/specs/canBeInvoiced.spec.js b/modules/client/back/methods/client/specs/canBeInvoiced.spec.js index 397be3c92..4012b7409 100644 --- a/modules/client/back/methods/client/specs/canBeInvoiced.spec.js +++ b/modules/client/back/methods/client/specs/canBeInvoiced.spec.js @@ -8,6 +8,8 @@ describe('client canBeInvoiced()', () => { const activeCtx = { accessToken: {userId: userId} }; + let tx; + let options; beforeAll(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ @@ -15,60 +17,45 @@ describe('client canBeInvoiced()', () => { }); }); + beforeEach(async() => { + tx = await models.Client.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => { + await tx.rollback(); + }); + it('should return falsy for a client without the data checked', async() => { - const tx = await models.Client.beginTransaction({}); + const client = await models.Client.findById(clientId, null, options); + await client.updateAttribute('isTaxDataChecked', false, options); - try { - const options = {transaction: tx}; + const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); - const client = await models.Client.findById(clientId, null, options); - await client.updateAttribute('isTaxDataChecked', false, options); + expect(canBeInvoiced).toEqual(false); + }); - const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); + it('should return falsy for a client not active', async() => { + const client = await models.Client.findById(clientId, null, options); + await client.updateAttribute('isActive', false, options); - expect(canBeInvoiced).toEqual(false); + const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(canBeInvoiced).toEqual(false); }); it('should return falsy for a client with invoicing disabled', async() => { - const tx = await models.Client.beginTransaction({}); + const client = await models.Client.findById(clientId, null, options); + await client.updateAttribute('hasToInvoice', false, options); - try { - const options = {transaction: tx}; + const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); - const client = await models.Client.findById(clientId, null, options); - await client.updateAttribute('hasToInvoice', false, options); - - const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); - - expect(canBeInvoiced).toEqual(false); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(canBeInvoiced).toEqual(false); }); it('should return truthy for an invoiceable client', async() => { - const tx = await models.Client.beginTransaction({}); + const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); - try { - const options = {transaction: tx}; - - const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); - - expect(canBeInvoiced).toEqual(true); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(canBeInvoiced).toEqual(true); }); }); From 49c30890e5c6487ecf8ad41e27fff13693fbfb66 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 19 Dec 2024 08:31:51 +0100 Subject: [PATCH 49/81] fix: refs #7301 update SQL fixtures and improve lastEntriesFilter logic --- db/dump/fixtures.before.sql | 11 ++++--- .../back/methods/item/lastEntriesFilter.js | 30 ++++++++++++------- .../item/specs/lastEntriesFilter.spec.js | 16 +++++----- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 57a9f9ca8..41ed69d53 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1516,7 +1516,8 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10, FALSE, NULL), (10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10, TRUE, 2), (11, util.VN_CURDATE() - INTERVAL 1 DAY , util.VN_CURDATE(), 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, FALSE, NULL), - (12, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, FALSE, NULL); + (12, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, FALSE, NULL), + (13, util.VN_CURDATE() - INTERVAL 1 MONTH - INTERVAL 1 DAY, util.VN_CURDATE() - INTERVAL 1 MONTH, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, FALSE, NULL); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `evaNotes`, `typeFk`) VALUES @@ -1529,8 +1530,9 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 'observation seven', 'product'), (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, '', 'product'), (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, '', 'product'), - (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10',1, '', 'product'), - (11, 4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 11',0, '', 'product'), + (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2010', 'Movement 10',1, '', 'product'), + (11, 4, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 1, 442, 'IN2011', 'Movement 11',0, '', 'product'), + (12, 4, util.VN_CURDATE() - INTERVAL 1 MONTH, 13, 1, 442, 'IN2012', 'Movement 12',0, '', 'product'), (99, 69, util.VN_CURDATE() - INTERVAL 1 MONTH, 11, 0, 442, 'IN2009', 'Movement 99',0, '', 'product'); INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`) @@ -1572,7 +1574,8 @@ INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `sal (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()), (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), (16, 99,1,50.0000, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.60, 99.40, 0, 1, 0, 1.00, '2024-07-30 08:13:51.000'), - (17, 11, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH); + (17, 11, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH), + (18, 12, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'grouping', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH); INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`) VALUES diff --git a/modules/item/back/methods/item/lastEntriesFilter.js b/modules/item/back/methods/item/lastEntriesFilter.js index 06c60162f..dd2e638e4 100644 --- a/modules/item/back/methods/item/lastEntriesFilter.js +++ b/modules/item/back/methods/item/lastEntriesFilter.js @@ -29,10 +29,11 @@ module.exports = Self => { Object.assign(myOptions, options); const stmt = new ParameterizedSQL( - `SELECT w.id AS warehouseFk, - w.name AS warehouse, - tr.landed, - b.id AS buyFk, + `SELECT i.id itemFk, + w.id warehouseFk, + w.name warehouse, + CAST(tr.landed AS CHAR) landed, + b.id buyFk, b.entryFk, b.isIgnored, b.price2, @@ -47,15 +48,18 @@ module.exports = Self => { b.buyingValue + b.freightValue + b.comissionValue + - b.packageValue AS cost, + b.packageValue cost, b.buyingValue, b.freightValue, b.comissionValue, b.packageValue, b.packagingFk , - s.id AS supplierFk, - s.name AS supplier, - b.printedStickers + s.id supplierFk, + s.name supplier, + b.printedStickers, + c.inventoried, + ic.supplierFk inventorySupplierFk, + s.id = ic.supplierFk isInventorySupplier FROM itemType it RIGHT JOIN (entry e LEFT JOIN supplier s ON s.id = e.supplierFk @@ -66,10 +70,16 @@ module.exports = Self => { LEFT JOIN warehouse w ON w.id = tr.warehouseInFk LEFT JOIN origin o ON o.id = i.originFk ) ON it.id = i.typeFk - LEFT JOIN edi.ekt ek ON b.ektFk = ek.id` + LEFT JOIN edi.ekt ek ON b.ektFk = ek.id + JOIN config c + JOIN inventoryConfig ic` ); - stmt.merge(conn.makeSuffix(filter)); + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge('AND IF(s.id = ic.supplierFk, tr.landed = DATE(c.inventoried), TRUE)'); + stmt.merge(conn.makePagination(filter)); + + console.log('stmt: ', stmt); return conn.executeStmt(stmt, myOptions); }; }; diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index d4429e158..3182f3a35 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -1,16 +1,17 @@ const {models} = require('vn-loopback/server/server'); +const itemFk = 1; describe('item lastEntriesFilter()', () => { - it('should return two entry for the given item', async() => { + fit('should return two entry for the given item', async() => { const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); const maxDate = Date.vnNew(); - maxDate.setHours(23, 59, 59, 59); + maxDate.setHours(23, 59, 59, 999); const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; + const filter = {where: {itemFk, landed: {between: [minDate, maxDate]}}}; const result = await models.Item.lastEntriesFilter(filter, options); expect(result.length).toEqual(2); @@ -22,7 +23,7 @@ describe('item lastEntriesFilter()', () => { } }); - it('should return six entries for the given item', async() => { + fit('should return six entries for the given item', async() => { const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); minDate.setMonth(minDate.getMonth() - 2, 1); @@ -34,11 +35,10 @@ describe('item lastEntriesFilter()', () => { const options = {transaction: tx}; try { - const itemFk = 1; const filter = {where: {itemFk, landed: {between: [minDate, maxDate]}}}; const result = await models.Item.lastEntriesFilter(filter, options); - const minDateUtc = new Date(minDate).getTime(); - const maxDateUtc = new Date(maxDate).getTime(); + const minDateUtc = minDate.getTime(); + const maxDateUtc = maxDate.getTime(); const resultMatch = ( await Promise.all( @@ -50,7 +50,7 @@ describe('item lastEntriesFilter()', () => { }); const isItemFkValid = itemRecord?.id === itemFk; - const landedDate = new Date(item.landed).getTime(); + const landedDate = Date.vnNew(item.landed).getTime(); const isLandedValid = landedDate >= minDateUtc && landedDate <= maxDateUtc; return isItemFkValid && isLandedValid; From b838e988e0e6262cf81d2b186b51e7ce160fff1d Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 19 Dec 2024 08:39:47 +0100 Subject: [PATCH 50/81] fix: refs #7301 remove debug console log and update test cases in lastEntriesFilter --- modules/item/back/methods/item/lastEntriesFilter.js | 1 - .../item/back/methods/item/specs/lastEntriesFilter.spec.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/item/back/methods/item/lastEntriesFilter.js b/modules/item/back/methods/item/lastEntriesFilter.js index dd2e638e4..7a98eabd9 100644 --- a/modules/item/back/methods/item/lastEntriesFilter.js +++ b/modules/item/back/methods/item/lastEntriesFilter.js @@ -79,7 +79,6 @@ module.exports = Self => { stmt.merge('AND IF(s.id = ic.supplierFk, tr.landed = DATE(c.inventoried), TRUE)'); stmt.merge(conn.makePagination(filter)); - console.log('stmt: ', stmt); return conn.executeStmt(stmt, myOptions); }; }; diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index 3182f3a35..a32225af7 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); const itemFk = 1; describe('item lastEntriesFilter()', () => { - fit('should return two entry for the given item', async() => { + it('should return two entry for the given item', async() => { const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); const maxDate = Date.vnNew(); @@ -23,7 +23,7 @@ describe('item lastEntriesFilter()', () => { } }); - fit('should return six entries for the given item', async() => { + it('should return six entries for the given item', async() => { const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); minDate.setMonth(minDate.getMonth() - 2, 1); From a99d7adfe88c36e4356a3dd685dbf2d1e9ffd5d7 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 19 Dec 2024 10:11:33 +0100 Subject: [PATCH 51/81] feat: refs #7924 add isCustomInspectionRequired field to item and update related logic --- db/dump/fixtures.before.sql | 46 ++++++++++--------- .../11391-redPalmetto/00-itemAlter.sql | 2 + modules/item/back/models/item.json | 5 +- .../methods/travel/extraCommunityFilter.js | 19 ++++---- .../travel/specs/extraCommunityFilter.spec.js | 13 ++++++ 5 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 db/versions/11391-redPalmetto/00-itemAlter.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 97ed0ae47..181b34e5a 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -974,26 +974,30 @@ INSERT INTO `vn`.`itemFamily`(`code`, `description`) ('SER', 'Services'), ('VT', 'Sales'); -INSERT INTO `vn`.`item`(`id`, `typeFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `expenseFk`, - `comment`, `relevancy`, `image`, `subName`, `minPrice`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`, `weightByPiece`) - VALUES - (1, 2, 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 'EMB', 0, NULL, 'V', 0, 3), - (2, 2, 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 'VT', 0, NULL, 'H', 0, 2), - (3, 1, 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 'VT', 0, NULL, NULL, 0, 5), - (4, 1, 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL), - (5, 3, 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL), - (6, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL), - (7, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL), - (8, 2, 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL), - (9, 2, 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL), - (10, 1, 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL), - (11, 1, 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL), - (12, 3, 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL), - (13, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 'VT', 1, NULL, NULL, 1, NULL), - (14, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL), - (15, 4, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL), - (16, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL), - (71, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL); +INSERT INTO `vn`.`item`( + `id`, `typeFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `expenseFk`, + `comment`, `relevancy`, `image`, `subName`, `minPrice`, `family`, `isFloramondo`, `genericFk`, + `itemPackingTypeFk`, `hasMinPrice`, `weightByPiece`, `isCustomInspectionRequired` +) +VALUES + (1, 2, 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 'EMB', 0, NULL, 'V', 0, 3, 1), + (2, 2, 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 'VT', 0, NULL, 'H', 0, 2, 1), + (3, 1, 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 'VT', 0, NULL, NULL, 0, 5, 0), + (4, 1, 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0), + (5, 3, 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0), + (6, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0), + (7, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0), + (8, 2, 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0), + (9, 2, 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL, 0), + (10, 1, 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0), + (11, 1, 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0), + (12, 3, 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0), + (13, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 'VT', 1, NULL, NULL, 1, NULL, 0), + (14, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL, 0), + (15, 4, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL, 0), + (16, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL, 0), + (71, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0); + -- Update the taxClass after insert of the items UPDATE `vn`.`itemTaxCountry` SET `taxClassFk` = 2 @@ -4038,7 +4042,7 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); -INSERT INTO vn.referenceRate (currencyFk, dated, value) +INSERT INTO vn.referenceRate (currencyFk, dated, value) VALUES (2, '2000-12-01', 1.0495), (2, '2001-01-01', 1.0531), (2, '2001-02-01', 7.6347); diff --git a/db/versions/11391-redPalmetto/00-itemAlter.sql b/db/versions/11391-redPalmetto/00-itemAlter.sql new file mode 100644 index 000000000..1eaef1a1b --- /dev/null +++ b/db/versions/11391-redPalmetto/00-itemAlter.sql @@ -0,0 +1,2 @@ +ALTER TABLE `item` +ADD COLUMN `isCustomInspectionRequired` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indicates if the item requires physical inspection at customs'; diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index eda56e938..159883455 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -154,6 +154,9 @@ }, "photoMotivation": { "type": "string" + }, + "isCustomInspectionRequired": { + "type": "boolean" } }, "relations": { @@ -222,4 +225,4 @@ } } } -} \ No newline at end of file +} diff --git a/modules/travel/back/methods/travel/extraCommunityFilter.js b/modules/travel/back/methods/travel/extraCommunityFilter.js index f1586f804..2f3f998d6 100644 --- a/modules/travel/back/methods/travel/extraCommunityFilter.js +++ b/modules/travel/back/methods/travel/extraCommunityFilter.js @@ -132,18 +132,18 @@ module.exports = Self => { CAST(SUM(b.weight * b.stickers) AS DECIMAL(10,0)) loadedKg, CAST( SUM( - vc.aerealVolumetricDensity * - b.stickers * + vc.aerealVolumetricDensity * + b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) AS DECIMAL(10,0) ) volumeKg, CAST( GREATEST( SUM(b.weight * b.stickers) , - SUM(vc.aerealVolumetricDensity * - b.stickers * - IF(pkg.volume, - pkg.volume, + SUM(vc.aerealVolumetricDensity * + b.stickers * + IF(pkg.volume, + pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000) ) / t.kg * 100 AS INT ) percentageKg @@ -185,11 +185,12 @@ module.exports = Self => { CAST(SUM(b.weight * b.stickers) AS DECIMAL(10,0)) as loadedkg, CAST( SUM( - vc.aerealVolumetricDensity * - b.stickers * + vc.aerealVolumetricDensity * + b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) AS DECIMAL(10,0) - ) as volumeKg + ) as volumeKg, + MAX(i.isCustomInspectionRequired) isCustomInspectionRequired FROM tmp.travel tr JOIN entry e ON e.travelFk = tr.id JOIN buy b ON b.entryFk = e.id diff --git a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js index 7e90c7681..8fa013fe4 100644 --- a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js +++ b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js @@ -112,4 +112,17 @@ describe('Travel extraCommunityFilter()', () => { expect(result.length).toEqual(2); }); + + it('should return field isCustomInspectionRequired true', async() => { + const ctx = { + args: { + id: 2 + } + }; + + const result = await app.models.Travel.extraCommunityFilter(ctx, filter); + + expect(result[0].entries[0].isCustomInspectionRequired).toBeTruthy(); + expect(result[0].entries[1].isCustomInspectionRequired).toBeFalsy(); + }); }); From ea4b11801516e7abca32781501dcd31731177402 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 19 Dec 2024 10:26:53 +0100 Subject: [PATCH 52/81] feat: refs #7301 update lastEntriesFilter to include landedDate and enhance test cases --- .../back/methods/item/lastEntriesFilter.js | 1 + .../item/specs/lastEntriesFilter.spec.js | 53 ++++++++++++++----- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/modules/item/back/methods/item/lastEntriesFilter.js b/modules/item/back/methods/item/lastEntriesFilter.js index 7a98eabd9..b038bb155 100644 --- a/modules/item/back/methods/item/lastEntriesFilter.js +++ b/modules/item/back/methods/item/lastEntriesFilter.js @@ -33,6 +33,7 @@ module.exports = Self => { w.id warehouseFk, w.name warehouse, CAST(tr.landed AS CHAR) landed, + tr.landed landedDate, b.id buyFk, b.entryFk, b.isIgnored, diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index a32225af7..b2bfdf59c 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -1,17 +1,22 @@ const {models} = require('vn-loopback/server/server'); const itemFk = 1; + +const today = Date.vnNew(); +today.setHours(23, 59, 59, 999); + +const twoMonthsAgo = Date.vnNew(); +twoMonthsAgo.setHours(0, 0, 0, 0); +twoMonthsAgo.setMonth(twoMonthsAgo.getMonth() - 2, 1); describe('item lastEntriesFilter()', () => { it('should return two entry for the given item', async() => { const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); - const maxDate = Date.vnNew(); - maxDate.setHours(23, 59, 59, 999); const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const filter = {where: {itemFk, landed: {between: [minDate, maxDate]}}}; + const filter = {where: {itemFk, landed: {between: [minDate, today]}}}; const result = await models.Item.lastEntriesFilter(filter, options); expect(result.length).toEqual(2); @@ -24,21 +29,14 @@ describe('item lastEntriesFilter()', () => { }); it('should return six entries for the given item', async() => { - const minDate = Date.vnNew(); - minDate.setHours(0, 0, 0, 0); - minDate.setMonth(minDate.getMonth() - 2, 1); - - const maxDate = Date.vnNew(); - maxDate.setHours(23, 59, 59, 59); - const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const filter = {where: {itemFk, landed: {between: [minDate, maxDate]}}}; + const filter = {where: {itemFk, landed: {between: [twoMonthsAgo, today]}}}; const result = await models.Item.lastEntriesFilter(filter, options); - const minDateUtc = minDate.getTime(); - const maxDateUtc = maxDate.getTime(); + const twoMonthsAgoUtc = twoMonthsAgo.getTime(); + const todayUtc = today.getTime(); const resultMatch = ( await Promise.all( @@ -51,7 +49,7 @@ describe('item lastEntriesFilter()', () => { const isItemFkValid = itemRecord?.id === itemFk; const landedDate = Date.vnNew(item.landed).getTime(); - const isLandedValid = landedDate >= minDateUtc && landedDate <= maxDateUtc; + const isLandedValid = landedDate >= twoMonthsAgoUtc && landedDate <= todayUtc; return isItemFkValid && isLandedValid; }) @@ -66,4 +64,31 @@ describe('item lastEntriesFilter()', () => { throw e; } }); + + it('should return just the inventoried inventory', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {where: {itemFk, landed: {between: [twoMonthsAgo, today]}}}; + const result = await models.Item.lastEntriesFilter(filter, options); + + const {supplierFk} = await models.InventoryConfig.findOne(options); + const {inventoried} = await models.Config.findOne(options); + + let hasInventoriedDate = false; + result.forEach(entry => { + if (entry.supplierFk === supplierFk && + entry.landedDate.getTime() === inventoried.getTime() + )hasInventoriedDate = true; + }); + + expect(hasInventoriedDate).toEqual(true); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 1f7dae2514a238ec9d49ef8c9e076b109735a649 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 19 Dec 2024 10:34:46 +0100 Subject: [PATCH 53/81] fix: refs #7936 locale --- modules/invoiceIn/back/locale/invoiceIn/en.yml | 7 ++----- modules/invoiceIn/back/locale/invoiceIn/es.yml | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/modules/invoiceIn/back/locale/invoiceIn/en.yml b/modules/invoiceIn/back/locale/invoiceIn/en.yml index 6940b6f77..f590f9656 100644 --- a/modules/invoiceIn/back/locale/invoiceIn/en.yml +++ b/modules/invoiceIn/back/locale/invoiceIn/en.yml @@ -18,8 +18,5 @@ columns: withholdingSageFk: withholding expenseFkDeductible: expense deductible editorFk: editor - cplusRectificationTypeFk: cplus rectification type - cplusSubjectOpFk: cplus subject op - cplusTaxBreakFk: cplus tax break - siiTrasCendencyInvoiceInFk: sii tras cendency invoice in - siiTypeInvoiceInFk: sii type invoice in \ No newline at end of file + siiTrasCendencyInvoiceInFk: SII tax regime + siiTypeInvoiceInFk: SII Type \ No newline at end of file diff --git a/modules/invoiceIn/back/locale/invoiceIn/es.yml b/modules/invoiceIn/back/locale/invoiceIn/es.yml index 9599c0535..494764d07 100644 --- a/modules/invoiceIn/back/locale/invoiceIn/es.yml +++ b/modules/invoiceIn/back/locale/invoiceIn/es.yml @@ -18,8 +18,5 @@ columns: withholdingSageFk: código de retención expenseFkDeductible: gasto deducible editorFk: editor - cplusRectificationTypeFk: tipo de rectificación cplus - cplusSubjectOpFk: sujeto op cplus - cplusTaxBreakFk: exención fiscal cplus - siiTrasCendencyInvoiceInFk: trascendencia sii factura recibida - siiTypeInvoiceInFk: tipo sii factura recibida \ No newline at end of file + siiTrasCendencyInvoiceInFk: Régimen fiscal SII + siiTypeInvoiceInFk: Tipo SII \ No newline at end of file From 6abbf3ec1d5ddcf7b55191a82db99f00c0af82cd Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 19 Dec 2024 13:01:34 +0100 Subject: [PATCH 54/81] fix: refs #7936 update Spanish locale for SII terms --- modules/invoiceIn/back/locale/invoiceIn/es.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/invoiceIn/back/locale/invoiceIn/es.yml b/modules/invoiceIn/back/locale/invoiceIn/es.yml index 494764d07..64ded6aca 100644 --- a/modules/invoiceIn/back/locale/invoiceIn/es.yml +++ b/modules/invoiceIn/back/locale/invoiceIn/es.yml @@ -18,5 +18,5 @@ columns: withholdingSageFk: código de retención expenseFkDeductible: gasto deducible editorFk: editor - siiTrasCendencyInvoiceInFk: Régimen fiscal SII - siiTypeInvoiceInFk: Tipo SII \ No newline at end of file + siiTrasCendencyInvoiceInFk: régimen fiscal SII + siiTypeInvoiceInFk: tipo SII \ No newline at end of file From c59cae9f74fbe65d14badde2fc40e82660573a1c Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 19 Dec 2024 14:38:28 +0100 Subject: [PATCH 55/81] feat: refs #8073 new comment message --- db/versions/11387-whiteDendro/00-firstScript.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11387-whiteDendro/00-firstScript.sql b/db/versions/11387-whiteDendro/00-firstScript.sql index 3226dfc42..4e9f1d217 100644 --- a/db/versions/11387-whiteDendro/00-firstScript.sql +++ b/db/versions/11387-whiteDendro/00-firstScript.sql @@ -1,8 +1,8 @@ CREATE TABLE IF NOT EXISTS vn.productionCountry( countryFk MEDIUMINT(8) UNSIGNED NOT NULL, - volumeGrowthEstimatePercent DECIMAL(6, 2), + volumeGrowthEstimatePercent DECIMAL(6, 2) COMMENT 'Porcentaje estimado de crecimiento del volumen', PRIMARY KEY (countryFk), CONSTRAINT productionCountryVolume_countryFK FOREIGN KEY (countryFk) REFERENCES vn.country (id) ON DELETE RESTRICT ON UPDATE CASCADE -) COMMENT = 'Estimación del crecimiento por país' \ No newline at end of file +) COMMENT = 'Datos de producción por país' \ No newline at end of file From a2218b41f8b5192b060ca2ad1944dd25ec221dfb Mon Sep 17 00:00:00 2001 From: jtubau Date: Mon, 23 Dec 2024 14:49:44 +0100 Subject: [PATCH 56/81] feat: refs #8266 added itemFk and needed fixtures --- db/dump/fixtures.before.sql | 2 +- modules/ticket/back/methods/expedition/filter.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 663705ff5..8dbaac2c2 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3963,7 +3963,7 @@ VALUES(1, ''); INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) -VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); +VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, 'Ranged Reinforced weapon sniper rifle 700mm' , 'NCC', NULL); INSERT INTO vn.accountDetail (id, value, accountDetailTypeFk, supplierAccountFk) diff --git a/modules/ticket/back/methods/expedition/filter.js b/modules/ticket/back/methods/expedition/filter.js index bd2012668..801d00a9b 100644 --- a/modules/ticket/back/methods/expedition/filter.js +++ b/modules/ticket/back/methods/expedition/filter.js @@ -50,7 +50,8 @@ module.exports = Self => { su.name scannerUserName, es.scanned, est.description state, - de.longName + de.longName, + de.itemFk FROM vn.expedition e LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk INNER JOIN vn.item i1 ON i1.id = e.freightItemFk From 98e2483565754146a05fe7dd3f2a2773b13ceba3 Mon Sep 17 00:00:00 2001 From: jgallego Date: Sun, 29 Dec 2024 09:38:51 +0100 Subject: [PATCH 57/81] feat: refs #8167 update locale and improve invoicing logic with error handling --- loopback/locale/en.json | 9 +++++---- .../back/methods/invoiceOut/clientsToInvoice.js | 12 ++++++++---- .../invoiceOut/specs/clientsToInvoice.spec.js | 4 ++-- .../back/methods/ticket/specs/makeInvoice.spec.js | 4 +++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index e6ec52d63..80da13ae5 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -246,8 +246,9 @@ "ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}", "The raid information is not correct": "The raid information is not correct", "Payment method is required": "Payment method is required", - "Sales already moved": "Sales already moved", - "Holidays to past days not available": "Holidays to past days not available", + "Sales already moved": "Sales already moved", + "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "There are tickets to be invoiced" -} + "There are tickets to be invoiced": "There are tickets to be invoiced", + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" +} \ No newline at end of file diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js index 5526d214a..7befdcbeb 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { Self.remoteMethodCtx('clientsToInvoice', { description: 'Get the clients to make global invoicing', @@ -47,7 +49,12 @@ module.exports = Self => { } try { - // Packaging liquidation + const clientCanBeInvoiced = + await Self.app.models.Client.canBeInvoiced(clientId, companyFk, myOptions); + + if (!clientCanBeInvoiced) + throw new UserError(`This client can't be invoiced`); + const vIsAllInvoiceable = false; await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [ clientId, @@ -71,9 +78,6 @@ module.exports = Self => { AND t.shipped BETWEEN ? AND util.dayEnd(?) AND (t.clientFk = ? OR ? IS NULL ) AND t.companyFk = ? - AND c.hasToInvoice - AND c.isTaxDataChecked - AND c.isActive AND NOT t.isDeleted GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id) HAVING SUM(t.totalWithVat) > 0;`; diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js index 470690c5a..df0566c54 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js @@ -4,11 +4,11 @@ describe('InvoiceOut clientsToInvoice()', () => { const userId = 1; const clientId = 1101; const companyFk = 442; - const maxShipped = new Date(); + const maxShipped = Date.vnNew(); maxShipped.setMonth(11); maxShipped.setDate(31); maxShipped.setHours(23, 59, 59, 999); - const invoiceDate = new Date(); + const invoiceDate = Date.vnNew(); const activeCtx = { getLocale: () => { return 'en'; diff --git a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js index 88812dc92..f9e4bcac0 100644 --- a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js +++ b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js @@ -77,6 +77,8 @@ describe('ticket makeInvoice()', () => { await tx.rollback(); } - expect(error.message).toEqual(`The address of the customer must have information about Incoterms and Customs Agent`); + expect(error.message).toEqual( + `The address of the customer must have information about Incoterms and Customs Agent` + ); }); }); From 8ca5808554dc01b28f5a88eb7f8e412b58644397 Mon Sep 17 00:00:00 2001 From: jgallego Date: Sun, 29 Dec 2024 10:16:38 +0100 Subject: [PATCH 58/81] fix: add isCustomInspectionRequired column to item table for customs inspection indication --- db/versions/11391-redPalmetto/00-itemAlter.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11391-redPalmetto/00-itemAlter.sql b/db/versions/11391-redPalmetto/00-itemAlter.sql index 1eaef1a1b..fc47d5fc0 100644 --- a/db/versions/11391-redPalmetto/00-itemAlter.sql +++ b/db/versions/11391-redPalmetto/00-itemAlter.sql @@ -1,2 +1,2 @@ -ALTER TABLE `item` +ALTER TABLE `vn`.`item` ADD COLUMN `isCustomInspectionRequired` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indicates if the item requires physical inspection at customs'; From 879ffcad64a8e3867b8e1b76afe3df47c0ee4545 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 30 Dec 2024 15:51:11 +0100 Subject: [PATCH 59/81] fix: refs #6598 update ACL property assignment --- back/methods/vn-user/acls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/vn-user/acls.js b/back/methods/vn-user/acls.js index 7da75ed2c..347cfa426 100644 --- a/back/methods/vn-user/acls.js +++ b/back/methods/vn-user/acls.js @@ -19,7 +19,7 @@ module.exports = Self => { if (acl.principalType == 'ROLE' && acl.permission == 'ALLOW') { const staticAcl = { model: model.name, - property: '*', + property: acl.property, accessType: acl.accessType, permission: acl.permission, principalType: acl.principalType, From 1f23ebf6d5a3d5528acb535dac45c87a783c352b Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 31 Dec 2024 11:46:32 +0100 Subject: [PATCH 60/81] feat: refs #7832 implement refund ticket restrictions and add unit tests for ticket service updates --- .../back/models/specs/ticket-service.spec.js | 65 +++++++++++++++++++ modules/ticket/back/models/ticket-service.js | 11 +++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 modules/ticket/back/models/specs/ticket-service.spec.js diff --git a/modules/ticket/back/models/specs/ticket-service.spec.js b/modules/ticket/back/models/specs/ticket-service.spec.js new file mode 100644 index 000000000..0edd296c6 --- /dev/null +++ b/modules/ticket/back/models/specs/ticket-service.spec.js @@ -0,0 +1,65 @@ +/* eslint max-len: ["error", { "code": 150 }]*/ +const {models} = require('vn-loopback/server/server'); + +fdescribe('ticketService model ', () => { + const originalTicketFk = 1; + const refundTicketFk = 11; + + let tx; + let opts; + let ticketService; + + beforeEach(async() => { + tx = await models.Sale.beginTransaction({}); + opts = {transaction: tx}; + + ticketService = await models.TicketService.create({ + ticketFk: refundTicketFk, + description: 'test', + quantity: 1, + price: 100, + taxClassFk: 1, + ticketServiceTypeFk: 1 + }, opts); + }); + + afterEach(async() => { + await tx.rollback(); + }); + + describe('TicketService', () => { + it('should allow updating description and quantity for non-refund tickets', async() => { + await ticketService.updateAttributes({ + ticketServiceTypeFk: 2, + quantity: 5 + }, opts); + + const updated = await models.TicketService.findById(ticketService.id, null, opts); + + expect(updated.description).not.toBe('test'); + expect(updated.quantity).toBe(5); + }); + + it('should only allow updating description for refund tickets', async() => { + await models.TicketRefund.create({ + refundTicketFk, + originalTicketFk + }, opts); + + await ticketService.updateAttributes({ + ticketServiceTypeFk: 2 + }, opts); + + try { + await ticketService.updateAttributes({ + ticketServiceTypeFk: 3, + quantity: 5 + }, opts); + + fail('Should have thrown error'); + } catch (e) { + expect(e.message).toBe('Only description can be modified in refund tickets'); + } + }); + }); +}); diff --git a/modules/ticket/back/models/ticket-service.js b/modules/ticket/back/models/ticket-service.js index 209727ee4..77479498a 100644 --- a/modules/ticket/back/models/ticket-service.js +++ b/modules/ticket/back/models/ticket-service.js @@ -10,9 +10,18 @@ module.exports = Self => { const isLocked = await models.Ticket.isLocked(ticketId); if (isLocked) throw new UserError(`The current ticket can't be modified`); + + const isRefund = await models.TicketRefund.findOne({ + where: {refundTicketFk: ticketId} + }, { + transaction: ctx.options.transaction + }); + + if (isRefund && ctx.data && Object.keys(ctx.data).some(field => field !== 'ticketServiceTypeFk')) + throw new UserError('Only description can be modified in refund tickets'); } - if (changes && changes.ticketServiceTypeFk) { + if (changes?.ticketServiceTypeFk) { const ticketServiceType = await models.TicketServiceType.findById(changes.ticketServiceTypeFk); changes.description = ticketServiceType.name; } From 0ad26b336d7a08a4a885b1d0b04947c968684a56 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 31 Dec 2024 11:48:05 +0100 Subject: [PATCH 61/81] fix: refs #7832 update ticketService model test suite to correct describe block --- modules/ticket/back/models/specs/ticket-service.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ticket/back/models/specs/ticket-service.spec.js b/modules/ticket/back/models/specs/ticket-service.spec.js index 0edd296c6..2691123eb 100644 --- a/modules/ticket/back/models/specs/ticket-service.spec.js +++ b/modules/ticket/back/models/specs/ticket-service.spec.js @@ -1,7 +1,6 @@ -/* eslint max-len: ["error", { "code": 150 }]*/ const {models} = require('vn-loopback/server/server'); -fdescribe('ticketService model ', () => { +describe('ticketService model ', () => { const originalTicketFk = 1; const refundTicketFk = 11; From 8822fde7fb194c93f284db3b9e5b7b38374a4c4a Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 2 Jan 2025 18:04:53 +0100 Subject: [PATCH 62/81] feat: refs #7343 delete sending to user --- .../back/methods/route/driverRouteEmail.js | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/modules/route/back/methods/route/driverRouteEmail.js b/modules/route/back/methods/route/driverRouteEmail.js index bbac2b0e8..78069683d 100644 --- a/modules/route/back/methods/route/driverRouteEmail.js +++ b/modules/route/back/methods/route/driverRouteEmail.js @@ -8,7 +8,7 @@ module.exports = Self => { arg: 'id', type: 'number', required: true, - description: 'The client id', + description: 'The route id', http: {source: 'path'} }, { arg: 'replyTo', @@ -31,26 +31,13 @@ module.exports = Self => { }); Self.driverRouteEmail = async(ctx, id) => { - const models = Self.app.models; - const {workerFk, agencyMode} = await Self.findById(id, { - fields: ['workerFk', 'agencyModeFk'], + const {agencyMode} = await Self.findById(id, { + fields: ['agencyModeFk'], include: {relation: 'agencyMode'} }); const {reportMail} = agencyMode(); - let user; - let account; - - if (workerFk) { - user = await models.VnUser.findById(workerFk, { - fields: ['active', 'id'], - include: {relation: 'emailUser'} - }); - account = await models.Account.findById(workerFk); - } - - if (user?.active && account) ctx.args.recipient = user.emailUser().email; - else ctx.args.recipient = reportMail; + ctx.args.recipient = reportMail; if (!ctx.args.recipient) throw new UserError('An email is necessary'); return Self.sendTemplate(ctx, 'driver-route'); }; From 67c484cd876ab4472e3c1b6e7754d6292a4d51f7 Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 3 Jan 2025 09:39:49 +0100 Subject: [PATCH 63/81] feat: refs #7301 update SQL fixtures and enhance lastEntriesFilter logic --- db/dump/fixtures.before.sql | 11 ++-- .../back/methods/item/lastEntriesFilter.js | 30 ++++++---- .../item/specs/lastEntriesFilter.spec.js | 57 +++++++++++++------ 3 files changed, 68 insertions(+), 30 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 97ed0ae47..ff24fa2a6 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1516,7 +1516,8 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10, FALSE, NULL), (10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10, TRUE, 2), (11, util.VN_CURDATE() - INTERVAL 1 DAY , util.VN_CURDATE(), 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, FALSE, NULL), - (12, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, FALSE, NULL); + (12, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, FALSE, NULL), + (13, util.VN_CURDATE() - INTERVAL 1 MONTH - INTERVAL 1 DAY, util.VN_CURDATE() - INTERVAL 1 MONTH, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, FALSE, NULL); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `evaNotes`, `typeFk`) VALUES @@ -1529,8 +1530,9 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 'observation seven', 'product'), (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, '', 'product'), (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, '', 'product'), - (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10',1, '', 'product'), - (11, 4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 11',0, '', 'product'), + (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2010', 'Movement 10',1, '', 'product'), + (11, 4, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 1, 442, 'IN2011', 'Movement 11',0, '', 'product'), + (12, 4, util.VN_CURDATE() - INTERVAL 1 MONTH, 13, 1, 442, 'IN2012', 'Movement 12',0, '', 'product'), (99, 69, util.VN_CURDATE() - INTERVAL 1 MONTH, 11, 0, 442, 'IN2009', 'Movement 99',0, '', 'product'); INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`) @@ -1572,7 +1574,8 @@ INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `sal (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()), (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), (16, 99,1,50.0000, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.60, 99.40, 0, 1, 0, 1.00, '2024-07-30 08:13:51.000'), - (17, 11, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH); + (17, 11, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH), + (18, 12, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'grouping', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH); INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`) VALUES diff --git a/modules/item/back/methods/item/lastEntriesFilter.js b/modules/item/back/methods/item/lastEntriesFilter.js index 06c60162f..b038bb155 100644 --- a/modules/item/back/methods/item/lastEntriesFilter.js +++ b/modules/item/back/methods/item/lastEntriesFilter.js @@ -29,10 +29,12 @@ module.exports = Self => { Object.assign(myOptions, options); const stmt = new ParameterizedSQL( - `SELECT w.id AS warehouseFk, - w.name AS warehouse, - tr.landed, - b.id AS buyFk, + `SELECT i.id itemFk, + w.id warehouseFk, + w.name warehouse, + CAST(tr.landed AS CHAR) landed, + tr.landed landedDate, + b.id buyFk, b.entryFk, b.isIgnored, b.price2, @@ -47,15 +49,18 @@ module.exports = Self => { b.buyingValue + b.freightValue + b.comissionValue + - b.packageValue AS cost, + b.packageValue cost, b.buyingValue, b.freightValue, b.comissionValue, b.packageValue, b.packagingFk , - s.id AS supplierFk, - s.name AS supplier, - b.printedStickers + s.id supplierFk, + s.name supplier, + b.printedStickers, + c.inventoried, + ic.supplierFk inventorySupplierFk, + s.id = ic.supplierFk isInventorySupplier FROM itemType it RIGHT JOIN (entry e LEFT JOIN supplier s ON s.id = e.supplierFk @@ -66,9 +71,14 @@ module.exports = Self => { LEFT JOIN warehouse w ON w.id = tr.warehouseInFk LEFT JOIN origin o ON o.id = i.originFk ) ON it.id = i.typeFk - LEFT JOIN edi.ekt ek ON b.ektFk = ek.id` + LEFT JOIN edi.ekt ek ON b.ektFk = ek.id + JOIN config c + JOIN inventoryConfig ic` ); - stmt.merge(conn.makeSuffix(filter)); + + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge('AND IF(s.id = ic.supplierFk, tr.landed = DATE(c.inventoried), TRUE)'); + stmt.merge(conn.makePagination(filter)); return conn.executeStmt(stmt, myOptions); }; diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index d4429e158..b2bfdf59c 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -1,16 +1,22 @@ const {models} = require('vn-loopback/server/server'); +const itemFk = 1; + +const today = Date.vnNew(); +today.setHours(23, 59, 59, 999); + +const twoMonthsAgo = Date.vnNew(); +twoMonthsAgo.setHours(0, 0, 0, 0); +twoMonthsAgo.setMonth(twoMonthsAgo.getMonth() - 2, 1); describe('item lastEntriesFilter()', () => { it('should return two entry for the given item', async() => { const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); - const maxDate = Date.vnNew(); - maxDate.setHours(23, 59, 59, 59); const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; + const filter = {where: {itemFk, landed: {between: [minDate, today]}}}; const result = await models.Item.lastEntriesFilter(filter, options); expect(result.length).toEqual(2); @@ -23,22 +29,14 @@ describe('item lastEntriesFilter()', () => { }); it('should return six entries for the given item', async() => { - const minDate = Date.vnNew(); - minDate.setHours(0, 0, 0, 0); - minDate.setMonth(minDate.getMonth() - 2, 1); - - const maxDate = Date.vnNew(); - maxDate.setHours(23, 59, 59, 59); - const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const itemFk = 1; - const filter = {where: {itemFk, landed: {between: [minDate, maxDate]}}}; + const filter = {where: {itemFk, landed: {between: [twoMonthsAgo, today]}}}; const result = await models.Item.lastEntriesFilter(filter, options); - const minDateUtc = new Date(minDate).getTime(); - const maxDateUtc = new Date(maxDate).getTime(); + const twoMonthsAgoUtc = twoMonthsAgo.getTime(); + const todayUtc = today.getTime(); const resultMatch = ( await Promise.all( @@ -50,8 +48,8 @@ describe('item lastEntriesFilter()', () => { }); const isItemFkValid = itemRecord?.id === itemFk; - const landedDate = new Date(item.landed).getTime(); - const isLandedValid = landedDate >= minDateUtc && landedDate <= maxDateUtc; + const landedDate = Date.vnNew(item.landed).getTime(); + const isLandedValid = landedDate >= twoMonthsAgoUtc && landedDate <= todayUtc; return isItemFkValid && isLandedValid; }) @@ -66,4 +64,31 @@ describe('item lastEntriesFilter()', () => { throw e; } }); + + it('should return just the inventoried inventory', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {where: {itemFk, landed: {between: [twoMonthsAgo, today]}}}; + const result = await models.Item.lastEntriesFilter(filter, options); + + const {supplierFk} = await models.InventoryConfig.findOne(options); + const {inventoried} = await models.Config.findOne(options); + + let hasInventoriedDate = false; + result.forEach(entry => { + if (entry.supplierFk === supplierFk && + entry.landedDate.getTime() === inventoried.getTime() + )hasInventoriedDate = true; + }); + + expect(hasInventoriedDate).toEqual(true); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From dc52c08c150b5cbb638193af2b018f045c15cec7 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 6 Jan 2025 19:30:06 +0100 Subject: [PATCH 64/81] build: refs #8355 add changelog --- CHANGELOG.md | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73ebecabc..c4eb7d29a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,106 @@ +# Version 24.52 - 2024-01-07 + +### Added 🆕 + +- chore: pullinfo by:alexm +- chore: refs #8002 drop comments by:jorgep +- chore: refs #8002 drop useless code by:jorgep +- feat: added translations and show error in item-type by:Jon +- feat: modified data to be equal as the updated back by:Jon +- feat: refs #4460 invoiceIn refund by:Carlos Andrés +- feat: refs #4466 invoiceIn refund by:Carlos Andrés +- feat: refs #6583 add new opt in where builder by:jorgep +- feat: refs #6583 add tests by:jorgep +- feat: refs #6583 retrieve cloned sale by:jorgep +- feat: refs #6583 rollback by:jorgep +- feat: refs #7301 add inventory-config and acl by:pablone +- feat: refs #7301 update SQL fixtures and enhance lastEntriesFilter logic by:pablone +- feat: refs #7882 Added locationiq service by:guillermo +- feat: refs #7882 Added osrm service by:guillermo +- feat: refs #7882 Added tests by:guillermo +- feat: refs #7882 Fixed problems osrm service by:guillermo +- feat: refs #7882 Osrm service by:guillermo +- feat: refs #7882 Reequested changes by:guillermo +- feat: refs #7882 Requested changes by:guillermo +- feat: refs #7936 add back test for updateInvoiceIn by:jorgep +- feat: refs #7936 add company filter by:jorgep +- feat: refs #7936 add currency check to updateInvoiceIn by:jorgep +- feat: refs #7936 add currency handling in invoiceIn trigger by:jorgep +- feat: refs #7936 add locale by:jorgep +- feat: refs #7936 add minimum due date by:jorgep +- feat: refs #7936 add reference rates for currency in fixtures by:jorgep +- feat: refs #7936 add save validation by:jorgep +- feat: refs #7936 add SiiTypeInvoiceIn model and update invoice correction logic by:jorgep +- feat: refs #7936 add tests for invoiceIn by:jorgep +- feat: refs #7936 add tests for invoiceIn filter by:jorgep +- feat: refs #7936 add validation to InvoiceIn & InvoiceInTax by:jorgep +- feat: refs #7936 return country code & is vies fields by:jorgep +- feat: refs #8002 adjust to lilium by:jorgep +- feat: refs #8002 drop support btn by:jorgep +- feat: refs #8174 Changed datatype incompatibility access by:guillermo +- feat: refs #8174 Created table sim by:guillermo +- feat: refs #8174 create table simsupplier by:Jbreso +- feat: refs #8174 fix by:Jbreso +- feat: refs#8174 simSupplier by:Jbreso +- feat: refs #8190 entry_getCommission by:robert +- feat: refs #8190 entry_getCommission change request by:robert +- feat: refs #8218 Added time and code in mistakeType by:guillermo +- feat: refs #8293 include zone data by:Jtubau +- refactor: refs #6583 entry report table style by:jorgep + +### Changed 📦 + +- refactor: refs #6583 entry report table style by:jorgep +- refactor: refs #6583 use warehouseId var by:jorgep +- refactor: refs #7301 update entry and item filter tests to validate results against specific criteria by:pablone +- refactor: refs #7882 Added ACL's by:guillermo +- refactor: refs #7882 Deleted quadminds files by:guillermo +- refactor: refs #7936 add transaction & tests by:jorgep +- refactor: refs #7936 remove old trigger and add isRaid column to travel table by:jorgep +- refactor: refs #7936 remove schema by:jorgep +- refactor: refs #8002 use loop wip by:jorgep +- refactor: refs #8004 simplify SQL query by removing redundant aliases by:pablone +- refactor: refs #8262 Deprecated inventoryFailure by:guillermo +- refactor: refs #8266 changed expedition item name by:Jtubau +- refactor: refs #8272 delete bi.rotacion by:ivanm + +### Fixed 🛠️ + +- feat: refs #7301 update SQL fixtures and enhance lastEntriesFilter logic by:pablone +- feat: refs #7936 add reference rates for currency in fixtures by:jorgep +- feat: refs #8174 fix by:Jbreso +- fix: 8174 pasar PIN a CHAR by:Jbreso +- fix: monitorPayMethodFilter by:carlossa +- fix: refs #6389 back by:carlossa +- fix: refs #6389 filter by:carlossa +- fix: refs #6389 packing by:carlossa +- fix: refs #6389 saleMonitor filter by:carlossa +- fix: refs #6389 salesFilter by:carlossa +- fix: refs #6583 drop focus by:jorgep +- fix: refs #6583 update onlyWithDestination logic to handle null values correctly by:jorgep +- fix: refs #7028 fix confirm deny by:carlossa +- fix: refs #7028 fix pr by:carlossa +- fix: refs #7028 fix tback findById by:carlossa +- fix: refs #7028 fix userError by:carlossa +- fix: refs #7028 remove ifs by:carlossa +- fix: refs #7028 requesterId fix by:carlossa +- fix: refs #7028 requesterId fix salesPerson by:carlossa +- fix: refs #7031 fix vnPrice by:carlossa +- fix: refs #7031 remove check by:carlossa +- fix: refs #7301 update ACL insertion to use INSERT IGNORE and refine property value by:pablone +- fix: refs #7936 add IF NOT EXISTS to isRaid column in travel table by:jorgep +- fix: refs #7936 change type by:jorgep +- fix: refs #7936 check if insert in hook & change test description by:jorgep +- fix: refs #7936 conflicts by:jorgep +- fix: refs #7936 locale by:jorgep +- fix: refs #7936 update Spanish locale for SII terms by:jorgep +- fix: refs #8174 fix by:Jbreso +- fix: refs#8174 fix by:Jbreso +- fix: refs8174 pasar a char el PIN by:Jbreso +- fix: refs #8174 Version by:guillermo +- fix: refs #8251 add eng template by:carlossa +- fix: refs #8315 fixture claimDevelopment by:alexm + # Version 24.48 - 2024-11-25 ### Added 🆕 From ad0c1eb4c5e8b493066cf8302863df0515ecb633 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 7 Jan 2025 07:12:33 +0100 Subject: [PATCH 65/81] feat: refs #8246 added relation for the front's new field --- modules/client/back/models/address.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/client/back/models/address.json b/modules/client/back/models/address.json index e8bf8d8a0..2d11b7745 100644 --- a/modules/client/back/models/address.json +++ b/modules/client/back/models/address.json @@ -84,6 +84,11 @@ "type": "belongsTo", "model": "CustomsAgent", "foreignKey": "customsAgentFk" + }, + "postcode": { + "type": "belongsTo", + "model": "Postcode", + "foreignKey": "postalCode" } } } From 48d4bab7062eb9d8c3b04976801ad93b1acdf26d Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 7 Jan 2025 08:01:44 +0100 Subject: [PATCH 66/81] build: refs #8355 dump db --- db/dump/.dump/data.sql | 25 ++- db/dump/.dump/privileges.sql | 11 +- db/dump/.dump/structure.sql | 351 ++++++++++++++--------------------- db/dump/.dump/triggers.sql | 29 ++- 4 files changed, 191 insertions(+), 225 deletions(-) diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index cd978e4a8..a2df34218 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -4,7 +4,7 @@ USE `util`; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -INSERT INTO `version` VALUES ('vn-database','11377','d3fe5098277c3935c434838b53facb271f84ebec','2024-12-10 07:22:33','11379'); +INSERT INTO `version` VALUES ('vn-database','11385','72bf27f08d3ddf646ec0bb6594fc79cecd4b72f2','2025-01-07 07:46:33','11395'); INSERT INTO `versionLog` VALUES ('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL); @@ -1083,6 +1083,7 @@ INSERT INTO `versionLog` VALUES ('vn-database','11322','00-entryAcl.sql','jenkin INSERT INTO `versionLog` VALUES ('vn-database','11324','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-13 10:49:47',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11325','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-26 07:05:30',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11326','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-26 07:05:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11327','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:24',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11330','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-26 07:05:30',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11331','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-26 07:05:30',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11332','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:04',NULL,NULL); @@ -1110,6 +1111,7 @@ INSERT INTO `versionLog` VALUES ('vn-database','11348','00-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','11349','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-26 07:28:14',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11350','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-26 07:28:14',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11351','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:04',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11352','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:24',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11353','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-26 07:28:14',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11354','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:04',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11355','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-11-26 07:28:14',NULL,NULL); @@ -1120,6 +1122,8 @@ INSERT INTO `versionLog` VALUES ('vn-database','11362','00-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','11363','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:04',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11366','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:04',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11367','00-deprecate.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:04',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11368','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11368','01-acls.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:32',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11369','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:05',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11371','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:05',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11371','01-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:20:47',NULL,NULL); @@ -1128,7 +1132,13 @@ INSERT INTO `versionLog` VALUES ('vn-database','11371','03-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','11372','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-09 13:30:30',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11373','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-02 16:09:01',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11375','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-03 08:58:20',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11376','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:32',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11377','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-12-10 07:22:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11378','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11379','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11379','01-secScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11384','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11385','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2025-01-07 07:46:33',NULL,NULL); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; @@ -2128,7 +2138,7 @@ INSERT INTO `ACL` VALUES (746,'Claim','getSummary','READ','ALLOW','ROLE','claimV INSERT INTO `ACL` VALUES (747,'CplusRectificationType','*','READ','ALLOW','ROLE','administrative',NULL); INSERT INTO `ACL` VALUES (748,'SiiTypeInvoiceOut','*','READ','ALLOW','ROLE','salesPerson',NULL); INSERT INTO `ACL` VALUES (749,'InvoiceCorrectionType','*','READ','ALLOW','ROLE','salesPerson',NULL); -INSERT INTO `ACL` VALUES (750,'InvoiceOut','transfer','WRITE','ALLOW','ROLE','administrative',NULL); +INSERT INTO `ACL` VALUES (750,'InvoiceOut','transfer','WRITE','ALLOW','ROLE','administrative',13657); INSERT INTO `ACL` VALUES (751,'Application','executeProc','*','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (752,'Application','executeFunc','*','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (753,'NotificationSubscription','getList','READ','ALLOW','ROLE','employee',NULL); @@ -2369,6 +2379,10 @@ INSERT INTO `ACL` VALUES (1006,'Entry','latestBuysFilter','READ','ALLOW','ROLE', INSERT INTO `ACL` VALUES (1007,'ItemShelving','getItemsByReviewOrder','READ','ALLOW','ROLE','production',19294); INSERT INTO `ACL` VALUES (1008,'Entry','buyLabelSupplier','READ','ALLOW','ROLE','employee',19295); INSERT INTO `ACL` VALUES (1009,'Entry','buyLabel','READ','ALLOW','ROLE','supplier',19295); +INSERT INTO `ACL` VALUES (1010,'InventoryConfig','find','READ','ALLOW','ROLE','buyer',10578); +INSERT INTO `ACL` VALUES (1011,'SiiTypeInvoiceIn','find','READ','ALLOW','ROLE','salesPerson',10578); +INSERT INTO `ACL` VALUES (1012,'OsrmConfig','optimize','READ','ALLOW','ROLE','employee',10578); +INSERT INTO `ACL` VALUES (1013,'Route','optimizePriority','*','ALLOW','ROLE','employee',10578); INSERT INTO `fieldAcl` VALUES (1,'Client','name','update','employee'); INSERT INTO `fieldAcl` VALUES (2,'Client','contact','update','employee'); @@ -2525,9 +2539,8 @@ INSERT INTO `companyI18n` VALUES (442,'en','In compliance with the provisions of INSERT INTO `companyI18n` VALUES (442,'fr','Conformément aux dispositions de la loi organique 15/1999 sur la protection des données personnelles, nous vous informons que les données personnelles que vous fournissez seront incluses dans des dossiers. VERDNATURA LEVANTE S.L., vous pouvez à tout moment, exercer les droits d``accès, de rectification, d``annulation et d``opposition, en communiquant par écrit au siège social de la société. Le dossier a pour objet la gestion administrative, la comptabilité et la facturation.'); INSERT INTO `companyI18n` VALUES (442,'pt','Em cumprimento do disposto na lei Orgânica 15/1999, de Protecção de Dados de Carácter Pessoal, comunicamos que os dados pessoais que facilite se incluirão nos ficheiros automatizados de VERDNATURA LEVANTE S.L., podendo em todo momento exercer os direitos de acesso, rectificação, cancelação e oposição, comunicando por escrito ao domicílio social da entidade. A finalidade do ficheiro é a gestão administrativa, contabilidade e facturação.'); -INSERT INTO `cplusRectificationType` VALUES (1,'Campo vacio'); +INSERT INTO `cplusRectificationType` VALUES (1,'S – Por sustitución'); INSERT INTO `cplusRectificationType` VALUES (2,'I – Por diferencias'); -INSERT INTO `cplusRectificationType` VALUES (3,'S – Por sustitución'); INSERT INTO `cplusSubjectOp` VALUES (1,'Campo vacio'); INSERT INTO `cplusSubjectOp` VALUES (2,'S1 – Sujeta – No exenta'); @@ -2619,6 +2632,8 @@ INSERT INTO `claimResult` VALUES (26,'Decepcion/Esperaba mas'); INSERT INTO `claimResult` VALUES (27,'Otros'); INSERT INTO `claimResult` VALUES (28,'Baboso/Cocido'); INSERT INTO `claimResult` VALUES (29,'Videocámaras'); +INSERT INTO `claimResult` VALUES (30,'Manipulado'); +INSERT INTO `claimResult` VALUES (31,'ReclamReclamado PR/AG'); INSERT INTO `component` VALUES (10,'Precios Especiales',4,NULL,NULL,1,'specialPrices',0); INSERT INTO `component` VALUES (14,'porte extra por dia semana',6,NULL,NULL,1,'extraCostPerWeekDay',0); @@ -2725,7 +2740,7 @@ INSERT INTO `department` VALUES (146,NULL,'VERDNACOLOMBIA',3,4,NULL,72,0,0,2,0,2 INSERT INTO `department` VALUES (147,'spainTeamAsia','EQUIPO ESPAÑA ASIA',71,72,40214,0,0,0,2,0,43,'/1/43/','esA_equipo',1,'esA@verdnatura.es',0,0,0,0,NULL,NULL,'5500',NULL); INSERT INTO `department` VALUES (148,'franceTeamCatchment','EQUIPO CAPTACIÓN FRANCIA',73,74,25178,0,0,0,2,0,43,'/1/43/',NULL,1,NULL,0,0,0,0,NULL,NULL,'6000',NULL); INSERT INTO `department` VALUES (149,'spainTeamCatchment','EQUIPO ESPAÑA CAPTACIÓN',75,76,1203,0,0,0,2,0,43,'/1/43/','es_captacion_equipo',1,'es_captacion@verdnatura.es',0,0,0,0,NULL,NULL,'5700',NULL); -INSERT INTO `department` VALUES (150,'spainTeamLevanteIslands','EQUIPO ESPAÑA LEVANTE/ISLAS',77,78,1118,0,0,0,2,0,43,'/1/43/','es_levanteislas_equipo',1,'levanteislas.verdnatura@gmail.com',0,0,0,0,NULL,NULL,'5000',NULL); +INSERT INTO `department` VALUES (150,'spainTeamLevanteIslands','EQUIPO ESPAÑA LEVANTE',77,78,1118,0,0,0,2,0,43,'/1/43/','es_levante_equipo',1,'levanteislas.verdnatura@gmail.com',0,0,0,0,NULL,NULL,'5000',NULL); INSERT INTO `department` VALUES (151,'spainTeamNorthwest','EQUIPO ESPAÑA NOROESTE',79,80,7102,0,0,0,2,0,43,'/1/43/','es_noroeste_equipo',1,'noroeste.verdnatura@gmail.com',0,0,0,0,NULL,NULL,'5300',NULL); INSERT INTO `department` VALUES (152,'spainTeamNortheast','EQUIPO ESPAÑA NORESTE',81,82,1118,0,0,0,2,0,43,'/1/43/','es_noreste_equipo',1,'noreste.verdnatura@gmail.com',0,0,0,0,NULL,NULL,'5200',NULL); INSERT INTO `department` VALUES (153,'spainTeamSouth','EQUIPO ESPAÑA SUR',83,84,36578,0,0,0,2,0,43,'/1/43/','es_sur_equipo',1,'sur.verdnatura@gmail.com',0,0,0,0,NULL,NULL,'5400',NULL); diff --git a/db/dump/.dump/privileges.sql b/db/dump/.dump/privileges.sql index f608d0e8a..460256b56 100644 --- a/db/dump/.dump/privileges.sql +++ b/db/dump/.dump/privileges.sql @@ -979,7 +979,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','bi','officeBoss','Greuge_Evolution' INSERT IGNORE INTO `tables_priv` VALUES ('','bi','claimManager','rotacion','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','sale','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','zonePromo__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','accountingConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','accountingConfig','carlosap@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Update',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','accountingType','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','agencyMode','alexm@%','0000-00-00 00:00:00','Insert,Update',''); INSERT IGNORE INTO `tables_priv` VALUES ('','cache','employee','visible','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); @@ -1417,9 +1417,11 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','accountDetail', INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBoss','project','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBoss','machineDetail','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','workerActivityType','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerSalesAssistant','route','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','delivery','zoneConfig','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerSalesAssistant','route','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','workCenter','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerSalesAssistant','Rutas','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','marketingBoss','specialPrice','alexm@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','genericAllocation','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','businessReasonEnd','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','buy_edi','alexm@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); @@ -1488,6 +1490,10 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logisticAssist','itemBaseTag', INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logisticAssist','itemBreederTag','jenkins@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemShelvingLog','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logisticAssist','itemTextureTag','jenkins@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','travelThermograph','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','thermograph','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerSalesAssistant','Tickets','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','sim','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); /*!40000 ALTER TABLE `tables_priv` ENABLE KEYS */; /*!40000 ALTER TABLE `columns_priv` DISABLE KEYS */; @@ -1873,6 +1879,7 @@ INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','subordinateget INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','buy_afterUpsert','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','util','grafana','dayend','FUNCTION','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','srt','production','buffer_settypebyname','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','grafana','clientGetMana','FUNCTION','guillermo@db-proxy2.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','barcodeToItem','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticket_splititempackingtype','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','entry_getCommission','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); diff --git a/db/dump/.dump/structure.sql b/db/dump/.dump/structure.sql index a4ae460b1..e52ed2a51 100644 --- a/db/dump/.dump/structure.sql +++ b/db/dump/.dump/structure.sql @@ -2569,28 +2569,6 @@ SET character_set_client = utf8; 1 AS `Consumo` */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `rotacion` --- - -DROP TABLE IF EXISTS `rotacion`; -/*!50001 DROP VIEW IF EXISTS `rotacion`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `rotacion` AS SELECT - 1 AS `Id_Article`, - 1 AS `warehouse_id`, - 1 AS `total`, - 1 AS `rotacion`, - 1 AS `cm3`, - 1 AS `almacenaje`, - 1 AS `manipulacion`, - 1 AS `auxiliar`, - 1 AS `mermas`, - 1 AS `cm3reparto`, - 1 AS `grams` */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `rutasBoard` -- @@ -17481,10 +17459,10 @@ BEGIN /** * Traslada la info de contabilidad relacionada con las facturas recibidas * - * @vInvoiceInFk Factura recibida - * @vXDiarioFk Id tabla XDiario + * @param vInvoiceInFk Factura recibida + * @param vXDiarioFk Id tabla XDiario */ - DECLARE vInvoiceInOriginalFk INT; + DECLARE vInvoiceInOriginalFk INT; DECLARE vDone BOOL DEFAULT FALSE; DECLARE vBase DOUBLE; DECLARE vVat DOUBLE; @@ -17502,7 +17480,7 @@ BEGIN DECLARE vIsInformativeExportation BOOL DEFAULT FALSE; DECLARE vCursor CURSOR FOR - SELECT it.taxableBase, + SELECT SUM(it.taxableBase), CAST(SUM((( it.taxableBase / 100) * t.PorcentajeIva)) AS DECIMAL (10,2)), t.PorcentajeIva, it.transactionTypeSageFk, @@ -17681,32 +17659,31 @@ BEGIN FROM vn.invoiceInCorrection WHERE correctingFk = vInvoiceInFk; - IF vInvoiceInOriginalFk THEN - + IF vInvoiceInOriginalFk THEN UPDATE movContaIVA mci - JOIN vn.invoiceInRefund iir ON iir.invoiceInRefundFk = vInvoiceInFk + JOIN vn.invoiceInCorrection iic ON iic.correctingFk = vInvoiceInFk + JOIN vn.siiTypeInvoiceIn st ON st.id = iic.siiTypeInvoiceInFk JOIN (SELECT issued, - SUM(sub.taxableBase) taxableBase, + SUM(sub.taxableBase) taxableBase, SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat FROM(SELECT issued, - SUM(iit.taxableBase) taxableBase, + SUM(iit.taxableBase) taxableBase, ti.PorcentajeIva - FROM vn.invoiceIn i + FROM vn.invoiceIn i JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id - JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk + JOIN TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk WHERE i.id = vInvoiceInOriginalFk GROUP BY ti.CodigoIva)sub )invoiceInOriginal JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa' SET mci.TipoRectificativa = iir.refundCategoryFk, - mci.ClaseAbonoRectificativas = iir.refundType, + mci.ClaseAbonoRectificativas = iir.refundType, mci.FechaFacturaOriginal = invoiceInOriginal.issued, mci.FechaOperacion = invoiceInOriginal.issued, mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase, mci.CuotaIvaOriginal = invoiceInOriginal.vat, mci.ClaveOperacionFactura = co.ClaveOperacionFactura_ WHERE mci.id = vXDiarioFk; - END IF; END ;; DELIMITER ; @@ -18178,6 +18155,7 @@ BEGIN UPDATE movContaIVA mci JOIN vn.invoiceOut i ON i.id = vInvoiceOutCorrectedFk JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk + JOIN vn.siiTypeInvoiceOut st ON st.id = ic.siiTypeInvoiceOutFk JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase, SUM(IF(IFNULL(e.vatFk, TRUE), iot.vat, 0)) vat, SUM(IF(IFNULL(e.vatFk, TRUE), 0, iot.vat)) equ @@ -18186,8 +18164,8 @@ BEGIN WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk ) tax JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa' - SET mci.TipoRectificativa = 2, - mci.ClaseAbonoRectificativas = 1, + SET mci.TipoRectificativa = ic.cplusRectificationTypeFk, + mci.ClaseAbonoRectificativas = REGEXP_REPLACE(st.`code`, '[^0-9]', ''), mci.FechaFacturaOriginal = i.issued, mci.FechaOperacion = i.issued, mci.BaseImponibleOriginal = tax.taxableBase, @@ -29528,14 +29506,16 @@ CREATE TABLE `deviceProductionUser` ( `userFk` int(10) unsigned NOT NULL, `created` timestamp NULL DEFAULT current_timestamp(), `editorFk` int(10) unsigned DEFAULT NULL, - `simSerialNumber` text DEFAULT NULL, + `simFk` varchar(25) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `deviceProductionUser_unique` (`deviceProductionFk`), KEY `userFgn_idx` (`userFk`), KEY `deviceProductionUser_fk_editor` (`editorFk`), + KEY `deviceProductionUser_sim_FK` (`simFk`), CONSTRAINT `deviceProductionUser_PK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `deviceProductionUser_deviceProduction_FK` FOREIGN KEY (`deviceProductionFk`) REFERENCES `deviceProduction` (`id`), - CONSTRAINT `deviceProductionUser_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) + CONSTRAINT `deviceProductionUser_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), + CONSTRAINT `deviceProductionUser_sim_FK` FOREIGN KEY (`simFk`) REFERENCES `sim` (`code`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -31354,13 +31334,27 @@ CREATE TABLE `inventoryConfig` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `inventoryFailure` +-- Table structure for table `inventoryFailureCause__` -- -DROP TABLE IF EXISTS `inventoryFailure`; +DROP TABLE IF EXISTS `inventoryFailureCause__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `inventoryFailure` ( +CREATE TABLE `inventoryFailureCause__` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='@deprecated 2024-12-16'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `inventoryFailure__` +-- + +DROP TABLE IF EXISTS `inventoryFailure__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `inventoryFailure__` ( `id` int(11) NOT NULL AUTO_INCREMENT, `dated` date NOT NULL, `itemFk` int(11) NOT NULL, @@ -31381,22 +31375,8 @@ CREATE TABLE `inventoryFailure` ( CONSTRAINT `inventoryFailure_fk2` FOREIGN KEY (`throwerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk3` FOREIGN KEY (`guiltyFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk4` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `inventoryFailure_fk5` FOREIGN KEY (`causeFk`) REFERENCES `inventoryFailureCause` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `inventoryFailureCause` --- - -DROP TABLE IF EXISTS `inventoryFailureCause`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `inventoryFailureCause` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `description` varchar(100) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + CONSTRAINT `inventoryFailure_fk5` FOREIGN KEY (`causeFk`) REFERENCES `inventoryFailureCause__` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='@deprecated 2024-12-16'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31554,18 +31534,18 @@ CREATE TABLE `invoiceInCorrection` ( `correctingFk` mediumint(8) unsigned NOT NULL COMMENT 'Factura rectificativa', `correctedFk` mediumint(8) unsigned NOT NULL COMMENT 'Factura rectificada', `cplusRectificationTypeFk` int(10) unsigned NOT NULL, - `siiTypeInvoiceOutFk` int(10) unsigned NOT NULL, + `siiTypeInvoiceInFk` int(10) unsigned NOT NULL, `invoiceCorrectionTypeFk` int(11) NOT NULL DEFAULT 3, PRIMARY KEY (`correctingFk`), KEY `invoiceInCorrection_correctedFk` (`correctedFk`), KEY `invoiceInCorrection_cplusRectificationTypeFk` (`cplusRectificationTypeFk`), - KEY `invoiceInCorrection_siiTypeInvoiceOut` (`siiTypeInvoiceOutFk`), + KEY `invoiceInCorrection_siiTypeInvoiceIn` (`siiTypeInvoiceInFk`), KEY `invoiceInCorrection_invoiceCorrectionTypeFk` (`invoiceCorrectionTypeFk`), CONSTRAINT `invoiceInCorrection_correctedFk` FOREIGN KEY (`correctedFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceInCorrection_correctingFk` FOREIGN KEY (`correctingFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceInCorrection_cplusRectificationTypeFk` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `cplusRectificationType` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceInCorrection_invoiceCorrectionTypeFk` FOREIGN KEY (`invoiceCorrectionTypeFk`) REFERENCES `invoiceCorrectionType` (`id`) ON UPDATE CASCADE, - CONSTRAINT `invoiceInCorrection_siiTypeInvoiceOut` FOREIGN KEY (`siiTypeInvoiceOutFk`) REFERENCES `siiTypeInvoiceOut` (`id`) ON UPDATE CASCADE + CONSTRAINT `invoiceInCorrection_siiTypeInvoiceIn` FOREIGN KEY (`siiTypeInvoiceInFk`) REFERENCES `siiTypeInvoiceIn` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -33837,7 +33817,9 @@ DROP TABLE IF EXISTS `mistakeType`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mistakeType` ( `id` int(11) NOT NULL AUTO_INCREMENT, + `code` varchar(50) DEFAULT NULL, `description` varchar(45) NOT NULL, + `time` int(10) DEFAULT NULL COMMENT 'Segundos que se suelen tardar en arreglar el fallo', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -34204,6 +34186,22 @@ CREATE TABLE `osTicketConfig` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `osrmConfig` +-- + +DROP TABLE IF EXISTS `osrmConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `osrmConfig` ( + `id` int(10) unsigned NOT NULL, + `url` varchar(100) NOT NULL COMMENT 'Dirección base de la API', + `tolerance` decimal(6,6) NOT NULL DEFAULT 0.000000 COMMENT 'Tolerancia entre las coordenadas enviadas y las retornadas', + PRIMARY KEY (`id`), + CONSTRAINT `osrmConfig_check` CHECK (`id` = 1) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `outgoingInvoiceVat` -- @@ -35763,26 +35761,6 @@ CREATE TABLE `punchState` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Table for storing punches that have cars with errors'; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `quadmindsApiConfig` --- - -DROP TABLE IF EXISTS `quadmindsApiConfig`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `quadmindsApiConfig` ( - `id` int(10) unsigned NOT NULL, - `url` varchar(255) DEFAULT NULL, - `key` varchar(255) DEFAULT NULL, - `maxObjects` int(11) DEFAULT NULL COMMENT 'Número máximo de objetos en el array por petición', - `limit` int(11) DEFAULT NULL COMMENT 'Limite de objetos solicitados por petición', - `orderTimeFrom` varchar(5) DEFAULT NULL COMMENT 'Inicio de ventana horaria de pedido', - `orderTimeTo` varchar(5) DEFAULT NULL COMMENT 'Fin de ventana horaria de pedido', - PRIMARY KEY (`id`), - CONSTRAINT `quadMindsConfig_check` CHECK (`id` = 1) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `quality` -- @@ -37542,6 +37520,23 @@ CREATE TABLE `siiTypeInvoiceOut` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tipo de Factura Emitidas en el suministro de inmediato'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `sim` +-- + +DROP TABLE IF EXISTS `sim`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `sim` ( + `code` varchar(25) NOT NULL COMMENT 'No se ha puesto BIGINT por incompatibilidad con Access', + `line` varchar(15) NOT NULL CHECK (`line` regexp '^[0-9]+$'), + `ext` int(4) NOT NULL, + `pin` varchar(4) NOT NULL CHECK (`pin` regexp '^[0-9]+$'), + `puk` varchar(15) NOT NULL CHECK (`pin` regexp '^[0-9]+$'), + PRIMARY KEY (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `sinister` -- @@ -41255,7 +41250,7 @@ CREATE TABLE `zone` ( `hour` datetime NOT NULL, `agencyModeFk` int(11) NOT NULL, `travelingDays` int(11) NOT NULL DEFAULT 1, - `price` double NOT NULL DEFAULT 0 CHECK (`price` > 0), + `price` decimal(10,2) DEFAULT NULL, `bonus` double NOT NULL DEFAULT 0, `isVolumetric` tinyint(1) NOT NULL DEFAULT 0, `inflation` decimal(5,2) NOT NULL DEFAULT 1.00, @@ -41264,11 +41259,14 @@ CREATE TABLE `zone` ( `code` varchar(45) DEFAULT NULL, `editorFk` int(10) unsigned DEFAULT NULL, `itemMaxLength` int(11) DEFAULT NULL COMMENT 'Longitud maxima para articulos acostados que esa agencia puede transportar', + `addressFk` int(11) DEFAULT NULL COMMENT 'Punto de distribución de donde salen para repartir', PRIMARY KEY (`id`), KEY `fk_zone_2_idx` (`agencyModeFk`), KEY `zone_name_idx` (`name`), KEY `zone_fk_editor` (`editorFk`), + KEY `zone_address_FK` (`addressFk`), CONSTRAINT `fk_zone_2` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `zone_address_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE, CONSTRAINT `zone_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -41318,7 +41316,10 @@ CREATE TABLE `zoneConfig` ( `id` int(10) unsigned NOT NULL, `scope` int(10) unsigned NOT NULL, `forwardDays` int(10) NOT NULL DEFAULT 7 COMMENT 'days forward to show zone_upcomingDeliveries', + `defaultAddressFk` int(11) DEFAULT NULL COMMENT 'Punto de distribución por defecto', PRIMARY KEY (`id`), + KEY `zoneConfig_address_FK` (`defaultAddressFk`), + CONSTRAINT `zoneConfig_address_FK` FOREIGN KEY (`defaultAddressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE, CONSTRAINT `zoneConfig_check` CHECK (`id` = 1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -43244,6 +43245,7 @@ BEGIN DECLARE vCurrentCommission INT; DECLARE vIsNotEUR INT; DECLARE vLastEntryFk INT; + DECLARE vLanded INT; SELECT count(*) INTO vIsNotEUR FROM currency c @@ -43259,23 +43261,25 @@ BEGIN RETURN IFNULL(vCommission, 0); ELSE + SELECT landed INTO vLanded + FROM travel + WHERE id = vTravelFk; + SELECT e.id INTO vLastEntryFk FROM `entry` e JOIN travel tr ON tr.id = e.travelFk - WHERE e.supplierFk = vSupplierFk - ORDER BY tr.landed DESC - LIMIT 1; + WHERE e.supplierFk = vSupplierFk + ORDER BY (vLanded <= tr.landed), tr.landed DESC + LIMIT 1; IF vLastEntryFk THEN SELECT commission INTO vCurrentCommission FROM `entry` WHERE id = vLastEntryFk; - ELSE SELECT commission INTO vCurrentCommission FROM supplier s WHERE s.id = vSupplierFk; - END IF; RETURN vCurrentCommission; @@ -49455,7 +49459,7 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - WHERE cd.description NOT IN ('Bueno', 'Corregido') + WHERE cd.code NOT IN ('good', 'corrected', 'supplierClaim') AND NOT ce.isGreuge AND cs.code = 'resolved'; @@ -49480,7 +49484,7 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - WHERE cd.description NOT IN ('Bueno', 'Corregido') + WHERE cd.code NOT IN ('good', 'corrected', 'supplierClaim') AND NOT ce.isGreuge AND cs.code = 'resolved' AND c.isChargedToMana; @@ -49491,7 +49495,7 @@ BEGIN JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk SET ce.isGreuge = TRUE - WHERE cd.description NOT IN ('Bueno', 'Corregido') + WHERE cd.code NOT IN ('good', 'corrected', 'supplierClaim') AND NOT ce.isGreuge AND cs.code = 'resolved'; @@ -49570,7 +49574,7 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - WHERE cd.description NOT IN ('Bueno', 'Corregido') + WHERE cd.code NOT IN ('good', 'corrected', 'supplierClaim') AND cs.code = 'resolved' AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR GROUP BY c.clientFk @@ -56857,67 +56861,6 @@ BEGIN UPDATE greugeConfig SET lastNotifyCheck = vTimeEnd; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `inventoryFailureAdd` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; -DELIMITER ;; -CREATE DEFINER=`vn`@`localhost` PROCEDURE `inventoryFailureAdd`() -BEGIN - -DECLARE done BOOL DEFAULT FALSE; -DECLARE vTicketFk INT; - -DECLARE rs CURSOR FOR - SELECT id FROM vn.ticket - WHERE shipped = util.yesterday() - AND clientFk = 400 - AND warehouseFk IN (1,44); - -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - -OPEN rs; - -FETCH rs INTO vTicketFk; - -WHILE NOT done DO - - INSERT INTO vn.inventoryFailure(dated, itemFk, quantity, value, warehouseFk, throwerFk) - SELECT t.shipped, - s.itemFk, - s.quantity, - b.buyingValue + b.freightValue + b.packageValue + b.comissionValue, - t.warehouseFk, - w.id - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - LEFT JOIN cache.last_buy lb ON lb.warehouse_id = t.warehouseFk AND item_id = s.itemFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN vn.worker w ON w.code = LEFT(s.concept, 3) - WHERE t.id = vTicketFk - AND s.quantity > 0; - - FETCH rs INTO vTicketFk; - -END WHILE; - - -CLOSE rs; - - - - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -57927,7 +57870,7 @@ BEGIN ii.cplusTaxBreakFk, ii.cplusSubjectOpFk, ii.siiTypeInvoiceInFk, - ii.cplusRectificationTypeFk, + ic.cplusRectificationTypeFk, ii.booked, IFNULL(a.isUeeMember, c.isUeeMember) isUeeMember, (c.id = cc.id) isSameCountry, @@ -57950,6 +57893,7 @@ BEGIN e.name expenseName FROM invoiceIn ii JOIN supplier s ON s.id = ii.supplierFk + LEFT JOIN invoiceInCorrection ic ON ic.correctingFk = ii.id LEFT JOIN province p ON p.id = s.provinceFk LEFT JOIN autonomy a ON a.id = p.autonomyFk JOIN country c ON c.id = s.countryFk @@ -62647,10 +62591,6 @@ BEGIN SET itemFk = vItemNew WHERE itemFk = vItemOld; - UPDATE inventoryFailure - SET itemFk = vItemNew - WHERE itemFk = vItemOld; - UPDATE genericAllocation SET itemFk = vItemNew WHERE itemFk = vItemOld; @@ -73325,7 +73265,8 @@ BEGIN IFNULL(dest.nickname, origin.nickname) nickname, dest.landed, dest.preparation, - origin.departmentFk + origin.departmentFk, + origin.saleClonedFk FROM ( SELECT s.ticketFk, c.salesPersonFk workerFk, @@ -73346,11 +73287,13 @@ BEGIN t.warehouseFk, t.companyFk, t.agencyModeFk, - wd.departmentFk + wd.departmentFk, + sc.saleClonedFk FROM ticket t JOIN client c ON c.id = t.clientFk JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.id JOIN saleVolume sv ON sv.saleFk = s.id JOIN item i ON i.id = s.itemFk JOIN ticketState ts ON ts.ticketFk = t.id @@ -77747,8 +77690,8 @@ BEGIN * @param vIsRaid idRaid value * @param vDaysInForward daysInForward value */ - IF (NOT vIsRaid AND vDaysInForward IS NOT NULL) OR (vIsRaid AND vDaysInForward IS NULL) THEN - CALL util.throw('The raid information is not correct'); + IF NOT vIsRaid AND vDaysInForward THEN + CALL util.throw('If daysInForward has a value, the raid cannot be unchecked'); END IF; END ;; DELIMITER ; @@ -78115,22 +78058,15 @@ BEGIN DECLARE vDone BOOL DEFAULT FALSE; DECLARE vBuyerEmail VARCHAR(40); DECLARE vTravelLink TEXT; - DECLARE vMailBody TEXT DEFAULT ''; + DECLARE vMailBody TEXT; + DECLARE vDaysBetweenDates INT; + DECLARE vSubject VARCHAR(30); - DECLARE vCur CURSOR FOR - SELECT GROUP_CONCAT(DISTINCT - CONCAT('https://salix.verdnatura.es/#!/travel/', - ttm.travelFk, - '/summary ') - ORDER BY ttm.travelFk SEPARATOR '\n\r') travelLink, - CONCAT(u.name, '@verdnatura.es') buyerEmail - FROM tTravelToMove ttm - JOIN entry e ON e.travelFk = ttm.travelFk - JOIN buy b ON b.entryFk = e.id - JOIN item i ON i.id = b.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN account.user u ON u.id = it.workerFk - GROUP BY u.name; + DECLARE vTravels CURSOR FOR + SELECT GROUP_CONCAT(DISTINCT travelLink ORDER BY id SEPARATOR '\n\r'), + buyerEmail + FROM tTravelToMove + GROUP BY buyerEmail; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -78141,35 +78077,50 @@ BEGIN END; CREATE OR REPLACE TEMPORARY TABLE tTravelToMove - SELECT id travelFk, - util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded - FROM travel + WITH travels AS ( + SELECT id, + CONCAT('https://salix.verdnatura.es/#!/travel/', id,'/summary') travelLink, + util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded, + util.VN_CURDATE() - INTERVAL DATEDIFF(landed, shipped) + daysInForward DAY newShipped + FROM vn.travel WHERE isRaid - AND daysInForward; + AND daysInForward + )SELECT t.id, + t.travelLink, + t.newLanded, + t.newShipped, + CONCAT(u.name, '@verdnatura.es') buyerEmail + FROM travels t + STRAIGHT_JOIN vn.entry e ON e.travelFk = t.id + JOIN vn.buy b ON b.entryFk = e.id + JOIN vn.item i ON i.id = b.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN account.user u ON u.id = it.workerFk + GROUP BY t.id; START TRANSACTION; UPDATE travel tr - JOIN tTravelToMove ttm ON ttm.travelFk = tr.id - SET tr.landed = ttm.newLanded; + JOIN tTravelToMove ttm ON ttm.id = tr.id + SET tr.landed = ttm.newLanded, + tr.shipped = ttm.newShipped; - OPEN vCur; + OPEN vTravels; l: LOOP SET vDone = FALSE; - FETCH vCur INTO vTravelLink, vBuyerEmail; + FETCH vTravels INTO vTravelLink, vBuyerEmail; IF vDone THEN LEAVE l; END IF; - CALL `vn`.`mail_insert`( - vBuyerEmail, - 'noreply@verdnatura.es', - 'Cambio de fecha en Redadas', - CONCAT('Se ha movido los siguientes travels: \n\r ', vTravelLink)); + SET vSubject = 'Cambio de fecha en Redadas', + vMailBody = CONCAT('Se ha movido los siguientes travels: \n\r ', vTravelLink); + + CALL mail_insert(vBuyerEmail, 'noreply@verdnatura.es', vSubject, vMailBody); END LOOP; - CLOSE vCur; + CLOSE vTravels; COMMIT; DROP TEMPORARY TABLE tTravelToMove; END ;; @@ -85618,24 +85569,6 @@ USE `bi`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; --- --- Final view structure for view `rotacion` --- - -/*!50001 DROP VIEW IF EXISTS `rotacion`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `rotacion` AS select `ic`.`itemFk` AS `Id_Article`,`ic`.`warehouseFk` AS `warehouse_id`,`ic`.`quantity` AS `total`,`ic`.`rotation` AS `rotacion`,`ic`.`cm3` AS `cm3`,`ic`.`storage` AS `almacenaje`,`ic`.`handling` AS `manipulacion`,`ic`.`extraCharge` AS `auxiliar`,`ic`.`wasted` AS `mermas`,`ic`.`cm3delivery` AS `cm3reparto`,`ic`.`grams` AS `grams` from `vn`.`itemCost` `ic` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - -- -- Final view structure for view `tarifa_componentes` -- @@ -90949,4 +90882,4 @@ USE `vn2008`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-12-10 8:17:51 +-- Dump completed on 2025-01-07 6:51:38 diff --git a/db/dump/.dump/triggers.sql b/db/dump/.dump/triggers.sql index 3299aea37..039dbb2a8 100644 --- a/db/dump/.dump/triggers.sql +++ b/db/dump/.dump/triggers.sql @@ -5701,7 +5701,7 @@ BEGIN SET NEW.editorFk = account.myUser_getId(); - IF (SELECT COUNT(*) FROM vn.invoiceIn + IF (SELECT COUNT(*) FROM invoiceIn WHERE supplierRef = NEW.supplierRef AND supplierFk = NEW.supplierFk AND YEAR(issued) = YEAR(NEW.issued) @@ -5713,7 +5713,7 @@ BEGIN IF NEW.supplierFk != OLD.supplierFk THEN CALL supplier_checkIsActive(NEW.supplierFk); SELECT withholdingSageFk INTO vWithholdingSageFk - FROM vn.supplier + FROM supplier WHERE id = NEW.supplierFk; SET NEW.withholdingSageFk = vWithholdingSageFk; END IF; @@ -5737,25 +5737,31 @@ DELIMITER ;; AFTER UPDATE ON `invoiceIn` FOR EACH ROW BEGIN - IF NEW.issued != OLD.issued - OR NEW.currencyFk != OLD.currencyFk THEN + DECLARE vIsEuro BOOL; + + SELECT `code` = 'EUR' INTO vIsEuro + FROM currency + WHERE id = NEW.currencyFk; + + IF (NOT NEW.issued <=> OLD.issued + OR NEW.currencyFk <> OLD.currencyFk) THEN UPDATE invoiceInTax iit JOIN invoiceIn ii ON ii.id = iit.invoiceInFk LEFT JOIN referenceRate rr ON rr.dated = ii.issued AND rr.currencyFk = ii.currencyFk - SET iit.taxableBase = IF(iit.foreignValue IS NULL, iit.taxableBase, iit.foreignValue / rr.value) + SET iit.taxableBase = IF(vIsEuro, iit.taxableBase, iit.foreignValue / rr.value), + iit.foreignValue = IF(vIsEuro, NULL, iit.foreignValue) WHERE ii.id = NEW.id; UPDATE invoiceInDueDay iidd JOIN invoiceIn ii ON ii.id = iidd.invoiceInFk LEFT JOIN referenceRate rr ON rr.dated = ii.issued AND rr.currencyFk = ii.currencyFk - SET iidd.amount = IF(iidd.foreignValue IS NULL, iidd.amount, iidd.foreignValue / rr.value) + SET iidd.amount = IF(vIsEuro, iidd.amount, iidd.foreignValue / rr.value), + iidd.foreignValue = IF(vIsEuro, NULL, iidd.foreignValue) WHERE ii.id = NEW.id; - END IF; - END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -8161,6 +8167,7 @@ BEGIN OR !(NEW.workerFk <=> OLD.workerFk) OR !(NEW.m3 <=> OLD.m3) OR !(NEW.agencyModeFk <=> OLD.agencyModeFk) + OR !(NEW.dated <=> OLD.dated) OR !(NEW.vehicleFk <=> OLD.vehicleFk)THEN CALL route_calcCommission(NEW.id); END IF; @@ -10582,6 +10589,10 @@ BEGIN CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); END IF; + IF NOT (NEW.isRaid <=> OLD.isRaid) OR NOT (NEW.daysInForward <=> OLD.daysInForward) THEN + CALL travel_checkRaid(NEW.isRaid, NEW.daysInForward); + END IF; + IF NOT (NEW.awbFk <=> OLD.awbFk)THEN SELECT COUNT(*) INTO vHasAnyInvoiceBooked FROM travel t @@ -11488,4 +11499,4 @@ USE `vn2008`; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-12-10 8:18:11 +-- Dump completed on 2025-01-07 6:51:57 From 1d8dcdf63f70534afc1c3529ef85244d9e08a608 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 7 Jan 2025 09:44:50 +0100 Subject: [PATCH 67/81] build: add new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a843ac9c5..e4cbf1406 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "25.02.0", + "version": "25.04.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 065f13557b9265d1e0903560c05be40d91b18039 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 7 Jan 2025 11:58:36 +0100 Subject: [PATCH 68/81] feat: refs #8357 Agregados triggers para manejar exclusiones de trabajadores en la tabla workerMana --- .../vn/triggers/workerManaExcluded_beforeInsert.sql | 9 +++++++++ .../vn/triggers/workerManaExcluded_beforeUpdate.sql | 9 +++++++++ db/routines/vn/triggers/workerMana_beforeInsert.sql | 10 ++++++++++ db/routines/vn/triggers/workerMana_beforeUpdate.sql | 10 ++++++++++ db/versions/11396-blueErica/00-firstScript.sql | 5 +++++ 5 files changed, 43 insertions(+) create mode 100644 db/routines/vn/triggers/workerManaExcluded_beforeInsert.sql create mode 100644 db/routines/vn/triggers/workerManaExcluded_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/workerMana_beforeInsert.sql create mode 100644 db/routines/vn/triggers/workerMana_beforeUpdate.sql create mode 100644 db/versions/11396-blueErica/00-firstScript.sql diff --git a/db/routines/vn/triggers/workerManaExcluded_beforeInsert.sql b/db/routines/vn/triggers/workerManaExcluded_beforeInsert.sql new file mode 100644 index 000000000..824f0982b --- /dev/null +++ b/db/routines/vn/triggers/workerManaExcluded_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerManaExcluded_beforeInsert` + BEFORE INSERT ON `workerManaExcluded` + FOR EACH ROW +BEGIN + DELETE FROM workerMana + WHERE workerFk = NEW.workerFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerManaExcluded_beforeUpdate.sql b/db/routines/vn/triggers/workerManaExcluded_beforeUpdate.sql new file mode 100644 index 000000000..83d73e131 --- /dev/null +++ b/db/routines/vn/triggers/workerManaExcluded_beforeUpdate.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerManaExcluded_beforeUpdate` + BEFORE UPDATE ON `workerManaExcluded` + FOR EACH ROW +BEGIN + DELETE FROM workerMana + WHERE workerFk = NEW.workerFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerMana_beforeInsert.sql b/db/routines/vn/triggers/workerMana_beforeInsert.sql new file mode 100644 index 000000000..2d27004e3 --- /dev/null +++ b/db/routines/vn/triggers/workerMana_beforeInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerMana_beforeInsert` + BEFORE INSERT ON `workerMana` + FOR EACH ROW +BEGIN + IF (SELECT EXISTS(SELECT TRUE FROM workerManaExcluded WHERE workerFk = NEW.workerFk)) THEN + CALL util.throw('Worker is excluded from mana'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerMana_beforeUpdate.sql b/db/routines/vn/triggers/workerMana_beforeUpdate.sql new file mode 100644 index 000000000..6916733cb --- /dev/null +++ b/db/routines/vn/triggers/workerMana_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerMana_beforeUpdate` + BEFORE UPDATE ON `workerMana` + FOR EACH ROW +BEGIN + IF (SELECT EXISTS(SELECT TRUE FROM workerManaExcluded WHERE workerFk = NEW.workerFk)) THEN + CALL util.throw('Worker is excluded from mana'); + END IF; +END$$ +DELIMITER ; diff --git a/db/versions/11396-blueErica/00-firstScript.sql b/db/versions/11396-blueErica/00-firstScript.sql new file mode 100644 index 000000000..b21965fe8 --- /dev/null +++ b/db/versions/11396-blueErica/00-firstScript.sql @@ -0,0 +1,5 @@ +DELETE FROM vn.workerMana + WHERE workerFk IN ( + SELECT workerFk + FROM vn.workerManaExcluded + ); From 5ab06ef6e46d5b5771a75f6ed080c502d5e71395 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 8 Jan 2025 09:39:55 +0100 Subject: [PATCH 69/81] fix: hotFix getStartDateOfWeekNumber --- .../methods/worker-time-control/sendMail.js | 16 ++------------ .../weeklyHourRecordEmail.js | 21 +------------------ .../worker/back/models/worker-time-control.js | 11 ++++++++++ 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 2e1e00d83..229e4d323 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -45,7 +45,7 @@ module.exports = Self => { const from = Date.vnNew(); const to = Date.vnNew(); - const time = await models.Time.findOne({ + const [time] = await models.Time.find({ where: { dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]} }, @@ -55,8 +55,7 @@ module.exports = Self => { args.week = time.week; args.year = time.year; } - - const started = getStartDateOfWeekNumber(args.week, args.year); + const started = Self.getStartDateOfWeekNumber(args.week, args.year); started.setHours(0, 0, 0, 0); const ended = new Date(started); @@ -388,17 +387,6 @@ module.exports = Self => { return true; }; - function getStartDateOfWeekNumber(week, year) { - const simple = new Date(year, 0, 1 + (week - 1) * 7); - const dow = simple.getDay(); - const weekStart = simple; - if (dow <= 4) - weekStart.setDate(simple.getDate() - simple.getDay() + 1); - else - weekStart.setDate(simple.getDate() + 8 - simple.getDay()); - return weekStart; - } - function getTime(timeString) { const [hours, minutes, seconds] = timeString.split(':'); return [parseInt(hours), parseInt(minutes), parseInt(seconds)]; diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index e352eb3cb..51573c1d6 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -55,7 +55,7 @@ module.exports = Self => { } }, myOptions); - const dated = getMondayDateFromYearWeek(args.year, args.week); + const dated = Self.getStartDateOfWeekNumber(args.week, args.year); const timestamp = dated.getTime() / 1000; const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; @@ -64,23 +64,4 @@ module.exports = Self => { await models.WorkerTimeControl.updateMailState(ctx, ctx.args.workerId, myOptions); return Self.sendTemplate(ctx, 'weekly-hour-record'); }; - - function getMondayDateFromYearWeek(yearNumber, weekNumber) { - const yearStart = new Date(yearNumber, 0, 1); - const firstMonday = new Date(yearStart.getTime() + ((7 - yearStart.getDay() + 1) % 7) * 86400000); - const firstMondayWeekNumber = getWeekNumber(firstMonday); - - if (firstMondayWeekNumber > 1) - firstMonday.setDate(firstMonday.getDate() + 7); - - firstMonday.setDate(firstMonday.getDate() + (weekNumber - 1) * 7); - - return firstMonday; - } - - function getWeekNumber(date) { - const firstDayOfYear = new Date(date.getFullYear(), 0, 1); - const daysPassed = (date - firstDayOfYear) / 86400000; - return Math.ceil((daysPassed + firstDayOfYear.getDay() + 1) / 7); - } }; diff --git a/modules/worker/back/models/worker-time-control.js b/modules/worker/back/models/worker-time-control.js index 92f1bacf0..eab061b0e 100644 --- a/modules/worker/back/models/worker-time-control.js +++ b/modules/worker/back/models/worker-time-control.js @@ -19,4 +19,15 @@ module.exports = Self => { return new UserError(`The introduced hour already exists`); return err; }); + + Self.getStartDateOfWeekNumber = (week, year) => { + const simple = new Date(year, 0, 1 + (week - 1) * 7); + const dow = simple.getDay(); + const weekStart = simple; + if (dow <= 4) + weekStart.setDate(simple.getDate() - simple.getDay() + 1); + else + weekStart.setDate(simple.getDate() + 8 - simple.getDay()); + return weekStart; + }; }; From 70ad6e26249d9a47603b8e5a318c45d4563e97bf Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 8 Jan 2025 10:25:08 +0100 Subject: [PATCH 70/81] =?UTF-8?q?fix:=20refs=20#6861=20refs=C2=B76861=20ti?= =?UTF-8?q?cketOrderReserve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/methods/collection/getTickets.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index 677c9e444..85d1111df 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -40,6 +40,7 @@ module.exports = Self => { const sales = await Self.rawSql(` SELECT s.ticketFk, + NULL ticketOrder, sgd.saleGroupFk, s.id saleFk, s.itemFk, @@ -83,6 +84,7 @@ module.exports = Self => { GROUP BY s.id, ish.id, p.code, p2.code UNION ALL SELECT s.ticketFk, + DENSE_RANK() OVER (ORDER BY ss.id), sgd.saleGroupFk, s.id saleFk, s.itemFk, From 9842f70becf95430fa0f5e7de3a90454a5fb831c Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 8 Jan 2025 11:25:07 +0100 Subject: [PATCH 71/81] fix: hotFix getMondayWeekYear --- .../methods/worker-time-control/sendMail.js | 17 +++-------------- .../weeklyHourRecordEmail.js | 4 ++-- .../worker/back/models/worker-time-control.js | 19 ++++++++++--------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 229e4d323..5fd5f65ff 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -41,21 +41,10 @@ module.exports = Self => { const stmts = []; let stmt; - if (!args.week || !args.year) { - const from = Date.vnNew(); - const to = Date.vnNew(); + const {date: started, week, year} = Self.getMondayWeekYear(args.week, args.year); + args.week = week; + args.year = year; - const [time] = await models.Time.find({ - where: { - dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]} - }, - order: 'week ASC' - }, myOptions); - - args.week = time.week; - args.year = time.year; - } - const started = Self.getStartDateOfWeekNumber(args.week, args.year); started.setHours(0, 0, 0, 0); const ended = new Date(started); diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index 51573c1d6..eadbecb00 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -55,8 +55,8 @@ module.exports = Self => { } }, myOptions); - const dated = Self.getStartDateOfWeekNumber(args.week, args.year); - const timestamp = dated.getTime() / 1000; + const {date} = Self.getMondayWeekYear(args.week, args.year); + const timestamp = date.getTime() / 1000; const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; ctx.args.url = url; diff --git a/modules/worker/back/models/worker-time-control.js b/modules/worker/back/models/worker-time-control.js index eab061b0e..cdf51b712 100644 --- a/modules/worker/back/models/worker-time-control.js +++ b/modules/worker/back/models/worker-time-control.js @@ -1,4 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); +const moment = require('moment'); module.exports = Self => { require('../methods/worker-time-control/filter')(Self); @@ -20,14 +21,14 @@ module.exports = Self => { return err; }); - Self.getStartDateOfWeekNumber = (week, year) => { - const simple = new Date(year, 0, 1 + (week - 1) * 7); - const dow = simple.getDay(); - const weekStart = simple; - if (dow <= 4) - weekStart.setDate(simple.getDate() - simple.getDay() + 1); - else - weekStart.setDate(simple.getDate() + 8 - simple.getDay()); - return weekStart; + Self.getMondayWeekYear = (week, year) => { + if (!week || !year) { + const today = Date.vnNew(); + today.setDate(today.getDate() - 7); + week = moment(today).isoWeek(); + year = moment(today).isoWeekYear(); + } + const date = moment(year, 'YYYY').week(week).startOf('isoweek').toDate(); + return {date, year, week}; }; }; From 60933216f788fcd4037b45895cac1f2dd6fcc072 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 8 Jan 2025 11:25:07 +0100 Subject: [PATCH 72/81] fix: hotFix getMondayWeekYear --- .../methods/worker-time-control/sendMail.js | 17 +++-------------- .../weeklyHourRecordEmail.js | 4 ++-- .../worker/back/models/worker-time-control.js | 19 ++++++++++--------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 229e4d323..5fd5f65ff 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -41,21 +41,10 @@ module.exports = Self => { const stmts = []; let stmt; - if (!args.week || !args.year) { - const from = Date.vnNew(); - const to = Date.vnNew(); + const {date: started, week, year} = Self.getMondayWeekYear(args.week, args.year); + args.week = week; + args.year = year; - const [time] = await models.Time.find({ - where: { - dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]} - }, - order: 'week ASC' - }, myOptions); - - args.week = time.week; - args.year = time.year; - } - const started = Self.getStartDateOfWeekNumber(args.week, args.year); started.setHours(0, 0, 0, 0); const ended = new Date(started); diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index 51573c1d6..eadbecb00 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -55,8 +55,8 @@ module.exports = Self => { } }, myOptions); - const dated = Self.getStartDateOfWeekNumber(args.week, args.year); - const timestamp = dated.getTime() / 1000; + const {date} = Self.getMondayWeekYear(args.week, args.year); + const timestamp = date.getTime() / 1000; const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; ctx.args.url = url; diff --git a/modules/worker/back/models/worker-time-control.js b/modules/worker/back/models/worker-time-control.js index eab061b0e..cdf51b712 100644 --- a/modules/worker/back/models/worker-time-control.js +++ b/modules/worker/back/models/worker-time-control.js @@ -1,4 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); +const moment = require('moment'); module.exports = Self => { require('../methods/worker-time-control/filter')(Self); @@ -20,14 +21,14 @@ module.exports = Self => { return err; }); - Self.getStartDateOfWeekNumber = (week, year) => { - const simple = new Date(year, 0, 1 + (week - 1) * 7); - const dow = simple.getDay(); - const weekStart = simple; - if (dow <= 4) - weekStart.setDate(simple.getDate() - simple.getDay() + 1); - else - weekStart.setDate(simple.getDate() + 8 - simple.getDay()); - return weekStart; + Self.getMondayWeekYear = (week, year) => { + if (!week || !year) { + const today = Date.vnNew(); + today.setDate(today.getDate() - 7); + week = moment(today).isoWeek(); + year = moment(today).isoWeekYear(); + } + const date = moment(year, 'YYYY').week(week).startOf('isoweek').toDate(); + return {date, year, week}; }; }; From c07e30a89c691e11e2bace073b0c587e54d15d9d Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 8 Jan 2025 12:48:28 +0100 Subject: [PATCH 73/81] fix: prevent deleting absences for past dates --- db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql | 2 ++ modules/worker/back/methods/worker/deleteAbsence.js | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql diff --git a/db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql b/db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..8ab24cb0d --- /dev/null +++ b/db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql @@ -0,0 +1,2 @@ +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Worker','canDeleteAbsenceInPast','WRITE','ALLOW','ROLE','hr'); \ No newline at end of file diff --git a/modules/worker/back/methods/worker/deleteAbsence.js b/modules/worker/back/methods/worker/deleteAbsence.js index b71d077a4..a7c6efc21 100644 --- a/modules/worker/back/methods/worker/deleteAbsence.js +++ b/modules/worker/back/methods/worker/deleteAbsence.js @@ -53,6 +53,12 @@ module.exports = Self => { } } }, myOptions); + const canDeleteAbsenceInPast = + await models.ACL.checkAccessAcl(ctx, 'Worker', 'canDeleteAbsenceInPast', 'WRITE'); + + if (!canDeleteAbsenceInPast && Date.vnNow() > absence.dated.getTime()) + throw new UserError(`Holidays to past days not available`); + const result = await absence.destroy(myOptions); const labour = absence.labour(); const department = labour && labour.department(); From f557b41feb782d1f1eb9788ec3d8fd413f2d3284 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 8 Jan 2025 13:52:50 +0100 Subject: [PATCH 74/81] fix: tests --- .../worker/specs/deleteAbsence.spec.js | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js index 0f3f913dc..c0d05e4a2 100644 --- a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js @@ -4,6 +4,8 @@ const LoopBackContext = require('loopback-context'); describe('Worker deleteAbsence()', () => { const businessId = 18; const workerId = 18; + const hrId = 37; + const salesBossId = 19; const activeCtx = { accessToken: {userId: 1106}, headers: {origin: 'http://localhost'} @@ -50,16 +52,16 @@ describe('Worker deleteAbsence()', () => { }); it('should successfully delete an absence', async() => { - activeCtx.accessToken.userId = 19; + activeCtx.accessToken.userId = salesBossId; const tx = await app.models.Calendar.beginTransaction({}); - + const pastDate = new Date(Date.vnNow() + 24 * 60 * 60 * 1000); try { const options = {transaction: tx}; const createdAbsence = await app.models.Calendar.create({ businessFk: businessId, dayOffTypeFk: 1, - dated: Date.vnNew() + dated: pastDate }, options); ctx.args = {absenceId: createdAbsence.id}; @@ -76,4 +78,61 @@ describe('Worker deleteAbsence()', () => { throw e; } }); + + it('should successfully delete an absence if the user is HR even if the date is in the past', async() => { + activeCtx.accessToken.userId = hrId; + const tx = await app.models.Calendar.beginTransaction({}); + + try { + const options = {transaction: tx}; + const pastDate = new Date(Date.vnNow() - 24 * 60 * 60 * 1000); // Restar un día + const createdAbsence = await app.models.Calendar.create({ + businessFk: businessId, + dayOffTypeFk: 1, + dated: pastDate + }, options); + + ctx.args = {absenceId: createdAbsence.id}; + await app.models.Worker.deleteAbsence(ctx, workerId, options); + + const deletedAbsence = await app.models.Calendar.findById(createdAbsence.id, null, options); + + expect(deletedAbsence).toBeNull(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should throw an error if the date is in the past', async() => { + activeCtx.accessToken.userId = salesBossId; + const tx = await app.models.Calendar.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + const pastDate = new Date(Date.vnNow() - 24 * 60 * 60 * 1000); + const createdAbsence = await app.models.Calendar.create({ + businessFk: businessId, + dayOffTypeFk: 1, + dated: pastDate + }, options); + + ctx.args = {absenceId: createdAbsence.id}; + await app.models.Worker.deleteAbsence(ctx, workerId, options); + + const deletedAbsence = await app.models.Calendar.findById(createdAbsence.id, null, options); + + expect(deletedAbsence).toBeNull(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toBe('Holidays to past days not available'); + }); }); From 838617e3f667fdb9ad14d454cdaa1854eca7d6d5 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 8 Jan 2025 15:47:53 +0100 Subject: [PATCH 75/81] fix: update access control for modifying absences in the past --- db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql | 4 +++- modules/worker/back/methods/worker/createAbsence.js | 6 +++--- modules/worker/back/methods/worker/deleteAbsence.js | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql b/db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql index 8ab24cb0d..f3e0355a8 100644 --- a/db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql +++ b/db/versions/11400-turquoiseChrysanthemum/00-firstScript.sql @@ -1,2 +1,4 @@ +DELETE FROM salix.ACL WHERE property = 'canCreateAbsenceInPast'; + INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('Worker','canDeleteAbsenceInPast','WRITE','ALLOW','ROLE','hr'); \ No newline at end of file + VALUES ('Worker','canModifyAbsenceInPast','WRITE','ALLOW','ROLE','hr'); diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 93ca7fd89..36781bc3f 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -58,12 +58,12 @@ module.exports = Self => { if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); - const canCreateAbsenceInPast = - await models.ACL.checkAccessAcl(ctx, 'Worker', 'canCreateAbsenceInPast', 'WRITE'); + const canModifyAbsenceInPast = + await models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE'); const now = Date.vnNew(); const newDate = new Date(args.dated).getTime(); - if ((now.getTime() > newDate) && !canCreateAbsenceInPast) + if ((now.getTime() > newDate) && !canModifyAbsenceInPast) throw new UserError(`Holidays to past days not available`); const labour = await models.WorkerLabour.findById(args.businessFk, diff --git a/modules/worker/back/methods/worker/deleteAbsence.js b/modules/worker/back/methods/worker/deleteAbsence.js index a7c6efc21..11a8cb0c1 100644 --- a/modules/worker/back/methods/worker/deleteAbsence.js +++ b/modules/worker/back/methods/worker/deleteAbsence.js @@ -53,10 +53,10 @@ module.exports = Self => { } } }, myOptions); - const canDeleteAbsenceInPast = - await models.ACL.checkAccessAcl(ctx, 'Worker', 'canDeleteAbsenceInPast', 'WRITE'); + const canModifyAbsenceInPast = + await models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE'); - if (!canDeleteAbsenceInPast && Date.vnNow() > absence.dated.getTime()) + if (!canModifyAbsenceInPast && Date.vnNow() > absence.dated.getTime()) throw new UserError(`Holidays to past days not available`); const result = await absence.destroy(myOptions); From 412638d59000f04fbe10aa45c4429230e57f1a41 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 8 Jan 2025 18:27:23 +0100 Subject: [PATCH 76/81] fix: refactor access control for modifying past absences --- modules/worker/back/methods/worker/createAbsence.js | 4 +--- modules/worker/back/methods/worker/deleteAbsence.js | 4 +--- .../worker/back/methods/worker/specs/createAbsence.spec.js | 2 +- .../worker/back/methods/worker/specs/deleteAbsence.spec.js | 2 +- modules/worker/back/models/worker.js | 7 +++++++ 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 36781bc3f..dc716c95d 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -58,12 +58,10 @@ module.exports = Self => { if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); - const canModifyAbsenceInPast = - await models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE'); const now = Date.vnNew(); const newDate = new Date(args.dated).getTime(); - if ((now.getTime() > newDate) && !canModifyAbsenceInPast) + if (!await Self.canModifyAbsenceInPast(ctx, newDate)) throw new UserError(`Holidays to past days not available`); const labour = await models.WorkerLabour.findById(args.businessFk, diff --git a/modules/worker/back/methods/worker/deleteAbsence.js b/modules/worker/back/methods/worker/deleteAbsence.js index 11a8cb0c1..596f8f28d 100644 --- a/modules/worker/back/methods/worker/deleteAbsence.js +++ b/modules/worker/back/methods/worker/deleteAbsence.js @@ -53,10 +53,8 @@ module.exports = Self => { } } }, myOptions); - const canModifyAbsenceInPast = - await models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE'); - if (!canModifyAbsenceInPast && Date.vnNow() > absence.dated.getTime()) + if (!await Self.canModifyAbsenceInPast(ctx, absence.dated.getTime())) throw new UserError(`Holidays to past days not available`); const result = await absence.destroy(myOptions); diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index 1c7efcd28..b6600048f 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -describe('Worker createAbsence()', () => { +fdescribe('Worker createAbsence()', () => { const workerId = 18; it('should return an error for a user without enough privileges', async() => { diff --git a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js index c0d05e4a2..dfbcd9835 100644 --- a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -describe('Worker deleteAbsence()', () => { +fdescribe('Worker deleteAbsence()', () => { const businessId = 18; const workerId = 18; const hrId = 37; diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 3351c348c..e1adca77e 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -26,6 +26,13 @@ module.exports = Self => { message: 'Invalid TIN' }); + Self.canModifyAbsenceInPast = async(ctx, time) => { + const hasPrivs = await Self.app.models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE'); + const now = Date.vnNew(); + now.setHours(0, 0, 0, 0); + return hasPrivs || now.getTime() < time; + }; + async function tinIsValid(err, done) { const country = await Self.app.models.Country.findOne({ fields: ['code'], From b12c3bb72f8d182983bfd89d64c55237bf20f834 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 8 Jan 2025 18:28:00 +0100 Subject: [PATCH 77/81] fix: enable tests for createAbsence and deleteAbsence methods --- modules/worker/back/methods/worker/specs/createAbsence.spec.js | 2 +- modules/worker/back/methods/worker/specs/deleteAbsence.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index b6600048f..1c7efcd28 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -fdescribe('Worker createAbsence()', () => { +describe('Worker createAbsence()', () => { const workerId = 18; it('should return an error for a user without enough privileges', async() => { diff --git a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js index dfbcd9835..c0d05e4a2 100644 --- a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -fdescribe('Worker deleteAbsence()', () => { +describe('Worker deleteAbsence()', () => { const businessId = 18; const workerId = 18; const hrId = 37; From 50a95ed3c4bdb1396d1d1c1ad12b81ed301e1561 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 8 Jan 2025 18:30:33 +0100 Subject: [PATCH 78/81] fix: correct variable name in canModifyAbsenceInPast method --- modules/worker/back/models/worker.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index e1adca77e..2e45b78da 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -28,9 +28,9 @@ module.exports = Self => { Self.canModifyAbsenceInPast = async(ctx, time) => { const hasPrivs = await Self.app.models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE'); - const now = Date.vnNew(); - now.setHours(0, 0, 0, 0); - return hasPrivs || now.getTime() < time; + const today = Date.vnNew(); + today.setHours(0, 0, 0, 0); + return hasPrivs || today.getTime() < time; }; async function tinIsValid(err, done) { From d0d1950e7554d970159cbb4233242e5c6d9c0107 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 9 Jan 2025 07:28:14 +0100 Subject: [PATCH 79/81] fix: refs #7912 Changed week num param to to be similar vn.time --- db/routines/bs/procedures/waste_addSales.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/bs/procedures/waste_addSales.sql b/db/routines/bs/procedures/waste_addSales.sql index ea4adbc27..9ce67b19d 100644 --- a/db/routines/bs/procedures/waste_addSales.sql +++ b/db/routines/bs/procedures/waste_addSales.sql @@ -22,7 +22,7 @@ BEGIN REPLACE bs.waste SELECT YEAR(t.shipped), - WEEK(t.shipped, 4), + WEEK(t.shipped, 6), it.workerFk, it.id, s.itemFk, @@ -70,6 +70,6 @@ BEGIN JOIN vn.buy b ON b.id = lb.buy_id WHERE t.shipped BETWEEN vDateFrom AND vDateTo AND w.isManaged - GROUP BY YEAR(t.shipped), WEEK(t.shipped, 4), i.id; + GROUP BY YEAR(t.shipped), WEEK(t.shipped, 6), i.id; END$$ DELIMITER ; From d258de1194deb54a730a39d59484e0aa83dac77b Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 9 Jan 2025 07:58:59 +0100 Subject: [PATCH 80/81] fix: lang any --- back/methods/vn-user/update-user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/vn-user/update-user.js b/back/methods/vn-user/update-user.js index 2bb390cf9..32bad0f17 100644 --- a/back/methods/vn-user/update-user.js +++ b/back/methods/vn-user/update-user.js @@ -22,7 +22,7 @@ module.exports = Self => { description: 'The user email' }, { arg: 'lang', - type: 'string', + type: 'any', description: 'The user lang' }, { arg: 'twoFactor', From 2141d7d95dc6273e2cc44b12629686b69cd959b8 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 9 Jan 2025 11:29:07 +0100 Subject: [PATCH 81/81] fix: refs #7912 Major corrections waste_addSales --- db/routines/bs/procedures/waste_addSales.sql | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/db/routines/bs/procedures/waste_addSales.sql b/db/routines/bs/procedures/waste_addSales.sql index 9ce67b19d..4a34d74b3 100644 --- a/db/routines/bs/procedures/waste_addSales.sql +++ b/db/routines/bs/procedures/waste_addSales.sql @@ -10,18 +10,26 @@ BEGIN * @param vDateFrom Fecha desde * @param vDateTo Fecha hasta */ - IF vDateFrom IS NULL THEN - SET vDateFrom = util.VN_CURDATE() - INTERVAL WEEKDAY(util.VN_CURDATE()) DAY; + DECLARE vDaysInYear INT; + SET vDaysInYear = DATEDIFF(util.lastDayOfYear(CURDATE()), util.firstDayOfYear(CURDATE())); + + SET vDateFrom = COALESCE(vDateFrom, util.VN_CURDATE()); + SET vDateTo = COALESCE(vDateTo, util.VN_CURDATE()); + + IF DATEDIFF(vDateTo, vDateFrom) > vDaysInYear THEN + CALL util.throw('The period cannot be longer than one year'); END IF; - IF vDateTo IS NULL THEN - SET vDateTo = vDateFrom + INTERVAL 6 DAY; - END IF; + -- Obtiene el primer día de la semana de esa fecha + SET vDateFrom = DATE_SUB(vDateFrom, INTERVAL ((WEEKDAY(vDateFrom) + 1) % 7) DAY); + + -- Obtiene el último día de la semana de esa fecha + SET vDateTo = DATE_ADD(vDateTo, INTERVAL (6 - ((WEEKDAY(vDateTo) + 1) % 7)) DAY); CALL cache.last_buy_refresh(FALSE); REPLACE bs.waste - SELECT YEAR(t.shipped), + SELECT YEARWEEK(t.shipped, 6) DIV 100, WEEK(t.shipped, 6), it.workerFk, it.id, @@ -68,8 +76,8 @@ BEGIN JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = w.id JOIN vn.buy b ON b.id = lb.buy_id - WHERE t.shipped BETWEEN vDateFrom AND vDateTo + WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDateTo) AND w.isManaged - GROUP BY YEAR(t.shipped), WEEK(t.shipped, 6), i.id; + GROUP BY YEARWEEK(t.shipped, 6) DIV 100, WEEK(t.shipped, 6), i.id; END$$ DELIMITER ;
{{$t('reference')}} {{$t('boxes')}} {{$t('packing')}}{{$t('concept')}}{{$t('tags')}}{{$t('quantity')}}{{$t('price')}}{{$t('amount')}}{{$t('concept')}}{{$t('reference')}}{{$t('tags')}}{{$t('quantity')}}{{$t('price')}}{{$t('amount')}}
{{buy.comment}} {{buy.stickers}}x{{buy.packing}}{{buy.name}} - {{buy.tag5}} → {{buy.value5}} - {{buy.tag6}} → {{buy.value6}} - {{buy.tag7}} → {{buy.value7}} + x{{buy.packing}}{{buy.name}}{{buy.comment}} + {{buy.tag5}} → {{buy.value5}} + {{buy.tag6}} → {{buy.value6}} + {{buy.tag7}} → {{buy.value7}} {{buy.quantity | number($i18n.locale)}}x{{buy.buyingValue | currency('EUR', $i18n.locale)}}= + {{buy.quantity | number($i18n.locale)}}x{{buy.buyingValue | currency('EUR', $i18n.locale)}}= {{buy.buyingValue * buy.quantity | currency('EUR', $i18n.locale)}}