From 93abfdd8a1e8d2bd2508300918518d38e4b1d984 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 16 Apr 2024 08:44:50 +0200 Subject: [PATCH] feat: refs #7173 Added restrictions in invoiceIn structure --- db/dump/fixtures.before.sql | 16 ++++++++++------ .../vn/procedures/invoiceInTax_afterUpsert.sql | 2 ++ ...eckIsBooked.sql => invoiceIn_checkBooked.sql} | 2 +- .../invoiceInCorrection_beforeDelete.sql | 2 +- .../vn/triggers/invoiceInDueDay_beforeDelete.sql | 4 ++-- .../vn/triggers/invoiceInDueDay_beforeInsert.sql | 2 ++ .../triggers/invoiceInIntrastat_beforeDelete.sql | 2 +- .../triggers/invoiceInIntrastat_beforeInsert.sql | 8 ++++++++ ...tesql => invoiceInIntrastat_beforeUpdate.sql} | 0 .../vn/triggers/invoiceInTax_beforeDelete.sql | 2 +- .../vn/triggers/invoiceInTax_beforeUpdate.sql | 2 +- .../vn/triggers/invoiceIn_afterDelete.sql | 2 -- .../vn/triggers/invoiceIn_afterUpdate.sql | 2 -- .../vn/triggers/invoiceIn_beforeDelete.sql | 8 ++++++++ .../vn/triggers/invoiceIn_beforeUpdate.sql | 4 +++- .../methods/invoice-in-due-day/specs/new.spec.js | 3 +-- .../back/methods/invoice-in/specs/filter.spec.js | 2 +- 17 files changed, 42 insertions(+), 21 deletions(-) rename db/routines/vn/procedures/{invoiceIn_checkIsBooked.sql => invoiceIn_checkBooked.sql} (94%) create mode 100644 db/routines/vn/triggers/invoiceInIntrastat_beforeInsert.sql rename db/routines/vn/triggers/{invoiceInIntrastat_beforeUpdatesql => invoiceInIntrastat_beforeUpdate.sql} (100%) create mode 100644 db/routines/vn/triggers/invoiceIn_beforeDelete.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 1dad68b2c..cca080e45 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2542,15 +2542,15 @@ INSERT INTO `vn`.`duaEntry` (`duaFk`, `entryFk`, `value`, `customsValue`, `euroV REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issued`, `created`, `supplierRef`, `isBooked`, `companyFk`, `docFk`) VALUES (1, 1001, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1234, 0, 442, 1), - (2, 1002, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1235, 1, 442, 1), + (2, 1002, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1235, 0, 442, 1), (3, 1003, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1236, 0, 442, 1), (4, 1004, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1237, 0, 442, 1), - (5, 1005, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1238, 1, 442, 1), + (5, 1005, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1238, 0, 442, 1), (6, 1006, 'R', 2, util.VN_CURDATE(), util.VN_CURDATE(), 1239, 0, 442, 1), - (7, 1007, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1240, 1, 442, 1), - (8, 1008, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1241, 1, 442, 1), - (9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 1, 442, 1), - (10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 1, 442, 1); + (7, 1007, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1240, 0, 442, 1), + (8, 1008, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1241, 0, 442, 1), + (9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 0, 442, 1), + (10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 0, 442, 1); INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageWithholdingFk`, `daysAgo`) VALUES @@ -2605,6 +2605,10 @@ INSERT INTO `vn`.`invoiceInIntrastat` (`invoiceInFk`, `net`, `intrastatFk`, `amo (2, 13.20, 5080000, 15.00, 580, 5), (2, 16.10, 6021010, 25.00, 80, 5); +UPDATE `vn`.`invoiceIn` + SET isBooked = TRUE + WHERE id IN (2, 5, 7, 8, 9, 10); + INSERT INTO `vn`.`ticketRecalc`(`ticketFk`) SELECT t.id FROM vn.ticket t diff --git a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql index 60ec34696..43d54c28c 100644 --- a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql +++ b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql @@ -10,6 +10,8 @@ BEGIN DECLARE vLines INT; DECLARE vHasDistinctTransactions INT; + CALL invoiceIn_checkBooked(vInvoiceInFk); + SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; SELECT COUNT(*) INTO vLines diff --git a/db/routines/vn/procedures/invoiceIn_checkIsBooked.sql b/db/routines/vn/procedures/invoiceIn_checkBooked.sql similarity index 94% rename from db/routines/vn/procedures/invoiceIn_checkIsBooked.sql rename to db/routines/vn/procedures/invoiceIn_checkBooked.sql index 35008fcd5..862870eb4 100644 --- a/db/routines/vn/procedures/invoiceIn_checkIsBooked.sql +++ b/db/routines/vn/procedures/invoiceIn_checkBooked.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_checkIsBooked`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_checkBooked`( vSelf INT ) BEGIN diff --git a/db/routines/vn/triggers/invoiceInCorrection_beforeDelete.sql b/db/routines/vn/triggers/invoiceInCorrection_beforeDelete.sql index 309d53af2..f4df48dcd 100644 --- a/db/routines/vn/triggers/invoiceInCorrection_beforeDelete.sql +++ b/db/routines/vn/triggers/invoiceInCorrection_beforeDelete.sql @@ -3,6 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInCorrection_b BEFORE DELETE ON `invoiceInCorrection` FOR EACH ROW BEGIN - CALL invoiceIn_checkIsBooked(OLD.correctingFk); + CALL invoiceIn_checkBooked(OLD.correctingFk); END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInDueDay_beforeDelete.sql b/db/routines/vn/triggers/invoiceInDueDay_beforeDelete.sql index eed070950..10c9d0b52 100644 --- a/db/routines/vn/triggers/invoiceInDueDay_beforeDelete.sql +++ b/db/routines/vn/triggers/invoiceInDueDay_beforeDelete.sql @@ -3,6 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_befor BEFORE DELETE ON `invoiceInDueDay` FOR EACH ROW BEGIN - CALL invoiceIn_checkIsBooked(OLD.id); + CALL invoiceIn_checkBooked(OLD.invoiceInFk); END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql b/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql index f7e4265a7..95b227616 100644 --- a/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql +++ b/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql @@ -5,6 +5,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_befor BEGIN DECLARE vIsNotified BOOLEAN; + CALL invoiceIn_checkBooked(NEW.invoiceInFk); + SET NEW.editorFk = account.myUser_getId(); SELECT isNotified INTO vIsNotified diff --git a/db/routines/vn/triggers/invoiceInIntrastat_beforeDelete.sql b/db/routines/vn/triggers/invoiceInIntrastat_beforeDelete.sql index e3dfc769c..412b091f4 100644 --- a/db/routines/vn/triggers/invoiceInIntrastat_beforeDelete.sql +++ b/db/routines/vn/triggers/invoiceInIntrastat_beforeDelete.sql @@ -3,6 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInIntrastat_be BEFORE DELETE ON `invoiceInIntrastat` FOR EACH ROW BEGIN - CALL invoiceIn_checkIsBooked(OLD.invoiceInFk); + CALL invoiceIn_checkBooked(OLD.invoiceInFk); END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInIntrastat_beforeInsert.sql b/db/routines/vn/triggers/invoiceInIntrastat_beforeInsert.sql new file mode 100644 index 000000000..d6c25c505 --- /dev/null +++ b/db/routines/vn/triggers/invoiceInIntrastat_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInIntrastat_beforeInsert` + BEFORE INSERT ON `invoiceInIntrastat` + FOR EACH ROW +BEGIN + CALL invoiceIn_checkBooked(NEW.invoiceInFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInIntrastat_beforeUpdatesql b/db/routines/vn/triggers/invoiceInIntrastat_beforeUpdate.sql similarity index 100% rename from db/routines/vn/triggers/invoiceInIntrastat_beforeUpdatesql rename to db/routines/vn/triggers/invoiceInIntrastat_beforeUpdate.sql diff --git a/db/routines/vn/triggers/invoiceInTax_beforeDelete.sql b/db/routines/vn/triggers/invoiceInTax_beforeDelete.sql index c48e7a227..a43f602b4 100644 --- a/db/routines/vn/triggers/invoiceInTax_beforeDelete.sql +++ b/db/routines/vn/triggers/invoiceInTax_beforeDelete.sql @@ -3,6 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_beforeDe BEFORE DELETE ON `invoiceInTax` FOR EACH ROW BEGIN - CALL invoiceIn_checkIsBooked(OLD.invoiceInFk); + CALL invoiceIn_checkBooked(OLD.invoiceInFk); END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql b/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql index 99ccd2c1d..3e5ecf030 100644 --- a/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql +++ b/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_beforeUp BEFORE UPDATE ON `invoiceInTax` FOR EACH ROW BEGIN - CALL invoiceIn_checkIsBooked(OLD.invoiceInFk); + CALL invoiceIn_checkBooked(OLD.invoiceInFk); IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); diff --git a/db/routines/vn/triggers/invoiceIn_afterDelete.sql b/db/routines/vn/triggers/invoiceIn_afterDelete.sql index 62a01ebc2..c088f6492 100644 --- a/db/routines/vn/triggers/invoiceIn_afterDelete.sql +++ b/db/routines/vn/triggers/invoiceIn_afterDelete.sql @@ -3,8 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_afterDelete AFTER DELETE ON `invoiceIn` FOR EACH ROW BEGIN - CALL invoiceIn_checkIsBooked(OLD.id); - INSERT INTO invoiceInLog SET `action` = 'delete', `changedModel` = 'InvoiceIn', diff --git a/db/routines/vn/triggers/invoiceIn_afterUpdate.sql b/db/routines/vn/triggers/invoiceIn_afterUpdate.sql index 8d3df4ed5..1a9105c9e 100644 --- a/db/routines/vn/triggers/invoiceIn_afterUpdate.sql +++ b/db/routines/vn/triggers/invoiceIn_afterUpdate.sql @@ -3,8 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_afterUpdate AFTER UPDATE ON `invoiceIn` FOR EACH ROW BEGIN - CALL invoiceIn_checkIsBooked(OLD.id); - IF NEW.issued != OLD.issued OR NEW.currencyFk != OLD.currencyFk THEN diff --git a/db/routines/vn/triggers/invoiceIn_beforeDelete.sql b/db/routines/vn/triggers/invoiceIn_beforeDelete.sql new file mode 100644 index 000000000..2ffff923a --- /dev/null +++ b/db/routines/vn/triggers/invoiceIn_beforeDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_beforeDelete` + BEFORE DELETE ON `invoiceIn` + FOR EACH ROW +BEGIN + CALL invoiceIn_checkBooked(OLD.id); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql b/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql index 688a3af92..d0762de96 100644 --- a/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql +++ b/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql @@ -5,7 +5,9 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_beforeUpdat BEGIN DECLARE vWithholdingSageFk INT; - CALL invoiceIn_checkBooked(OLD.id); + IF NEW.isBooked = OLD.isBooked THEN + CALL invoiceIn_checkBooked(OLD.id); + END IF; IF NOT (NEW.supplierRef <=> OLD.supplierRef) AND NOT util.checkPrintableChars(NEW.supplierRef) THEN CALL util.throw('The invoiceIn reference contains invalid characters'); diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js index c188a511d..f21dad9f2 100644 --- a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js @@ -13,11 +13,10 @@ describe('invoiceInDueDay new()', () => { it('should correctly create a new due day', async() => { const userId = 9; - const invoiceInFk = 6; + const invoiceInFk = 3; const ctx = { req: { - accessToken: {userId: userId}, } }; 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 9834989fc..3ff5a92f3 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js @@ -158,7 +158,7 @@ describe('InvoiceIn filter()', () => { const result = await models.InvoiceIn.filter(ctx, {}, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(4); await tx.rollback(); } catch (e) {