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 01/35] 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 02/35] 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 679dd6929bfde285fe1a501f9199dbcd5fd26af2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 6 Nov 2024 13:42:36 +0100 Subject: [PATCH 03/35] 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 04/35] 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 05/35] 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 06/35] 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 07/35] 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 08/35] 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 09/35] 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 10/35] 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 11/35] 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 12/35] 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 13/35] 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 14/35] 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 15/35] 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 16/35] 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 17/35] 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 18/35] 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 19/35] 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 20/35] 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 21/35] 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 22/35] 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 23/35] 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 24/35] 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 25/35] 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 26/35] 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 9c32dc5707630b5c67a183409465015946348e61 Mon Sep 17 00:00:00 2001 From: Jtubau Date: Mon, 16 Dec 2024 08:34:53 +0100 Subject: [PATCH 27/35] 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 28/35] 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 29/35] 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 30/35] 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 31/35] 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 32/35] 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 33/35] 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 34/35] 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 35/35] 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",
{{$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)}}