From ba51052d8836ab43df51f36baa21bc62392329fd Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 27 Nov 2024 17:52:45 +0100 Subject: [PATCH] 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