From d8acf45e0d9f2545062a055fa738dba7a5f970d9 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 10 Feb 2023 09:34:42 +0100 Subject: [PATCH 1/2] fix(client-debt-statment): typo --- .../reports/client-debt-statement/client-debt-statement.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/print/templates/reports/client-debt-statement/client-debt-statement.html b/print/templates/reports/client-debt-statement/client-debt-statement.html index fb7bfd625..30fbbe003 100644 --- a/print/templates/reports/client-debt-statement/client-debt-statement.html +++ b/print/templates/reports/client-debt-statement/client-debt-statement.html @@ -13,7 +13,7 @@ {{$t('date')}} - {{formatDate(new Date(), '%d-%m-%Y');}} + {{formatDate(new Date(), '%d-%m-%Y')}} @@ -44,7 +44,7 @@ - {{formatDate(sale.issued, '%d-%m-%Y');}} + {{formatDate(sale.issued, '%d-%m-%Y')}} {{sale.ref}} {{sale.debtOut}} {{sale.debtIn}} From ac3faddac166da4974fb8ade4a50ee0390341653 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 10 Feb 2023 12:09:51 +0100 Subject: [PATCH 2/2] fix: actulizada sql intrastat y se muestra solamente cuando toca --- db/changes/230402/00-invoiceOut_getWeight.sql | 30 ++++++++++ print/templates/reports/invoice/invoice.html | 2 +- print/templates/reports/invoice/invoice.js | 3 +- .../reports/invoice/sql/hasIntrastat.sql | 4 ++ .../reports/invoice/sql/intrastat.sql | 60 +++++++++++-------- 5 files changed, 72 insertions(+), 27 deletions(-) create mode 100644 db/changes/230402/00-invoiceOut_getWeight.sql create mode 100644 print/templates/reports/invoice/sql/hasIntrastat.sql diff --git a/db/changes/230402/00-invoiceOut_getWeight.sql b/db/changes/230402/00-invoiceOut_getWeight.sql new file mode 100644 index 000000000..4ca284857 --- /dev/null +++ b/db/changes/230402/00-invoiceOut_getWeight.sql @@ -0,0 +1,30 @@ +DROP FUNCTION IF EXISTS `vn`.`invoiceOut_getWeight`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceOut_getWeight`(vInvoice VARCHAR(15)) RETURNS decimal(10,2) + READS SQL DATA +BEGIN +/** + * Calcula el peso de una factura emitida + * + * @param vInvoice Id de la factura + * @return vTotalWeight peso de la factura + */ + DECLARE vTotalWeight DECIMAL(10,2); + + SELECT SUM(CAST(IFNULL(i.stems, 1) + * s.quantity + * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000 AS DECIMAL(10,2))) + INTO vTotalWeight + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemCost ic ON ic.itemFk = i.id + AND ic.warehouseFk = t.warehouseFk + WHERE t.refFk = vInvoice + AND i.intrastatFk; + + RETURN vTotalWeight; +END$$ +DELIMITER ; diff --git a/print/templates/reports/invoice/invoice.html b/print/templates/reports/invoice/invoice.html index 60d06d528..ffa03af45 100644 --- a/print/templates/reports/invoice/invoice.html +++ b/print/templates/reports/invoice/invoice.html @@ -203,7 +203,7 @@ -
+

{{$t('intrastat')}}

diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js index 7b572d970..eaf17527d 100755 --- a/print/templates/reports/invoice/invoice.js +++ b/print/templates/reports/invoice/invoice.js @@ -10,7 +10,8 @@ module.exports = { this.checkMainEntity(this.invoice); this.client = await this.findOneFromDef('client', [this.reference]); this.taxes = await this.rawSqlFromDef(`taxes`, [this.reference]); - this.intrastat = await this.rawSqlFromDef(`intrastat`, [this.reference, this.reference, this.reference]); + this.hasIntrastat = await this.findValueFromDef(`hasIntrastat`, [this.reference]); + this.intrastat = await this.rawSqlFromDef(`intrastat`, [this.reference, this.reference, this.reference, this.reference]); this.rectified = await this.rawSqlFromDef(`rectified`, [this.reference]); this.hasIncoterms = await this.findValueFromDef(`hasIncoterms`, [this.reference]); diff --git a/print/templates/reports/invoice/sql/hasIntrastat.sql b/print/templates/reports/invoice/sql/hasIntrastat.sql new file mode 100644 index 000000000..09eda94c2 --- /dev/null +++ b/print/templates/reports/invoice/sql/hasIntrastat.sql @@ -0,0 +1,4 @@ +SELECT taxAreaFk != 'NATIONAL' + FROM vn.invoiceOutSerial ios + JOIN vn.invoiceOut io ON io.serial = ios.code + WHERE io.ref = ?; diff --git a/print/templates/reports/invoice/sql/intrastat.sql b/print/templates/reports/invoice/sql/intrastat.sql index f986a9564..211ebfe71 100644 --- a/print/templates/reports/invoice/sql/intrastat.sql +++ b/print/templates/reports/invoice/sql/intrastat.sql @@ -1,26 +1,36 @@ SELECT * - FROM invoiceOut io - JOIN invoiceOutSerial ios ON io.serial = ios.code - JOIN( - SELECT ir.id code, - ir.description, - iii.stems, - iii.net netKg, - iii.amount subtotal - FROM vn.invoiceInIntrastat iii - LEFT JOIN vn.invoiceIn ii ON ii.id = iii.invoiceInFk - LEFT JOIN vn.invoiceOut io ON io.ref = ii.supplierRef - LEFT JOIN vn.intrastat ir ON ir.id = iii.intrastatFk - WHERE io.`ref` = ? - UNION ALL - SELECT NULL code, - 'Servicios' description, - 0 stems, - 0 netKg, - IF(CAST(SUM((ts.quantity * ts.price)) AS DECIMAL(10,2)), CAST(SUM((ts.quantity * ts.price)) AS DECIMAL(10,2)), 0) subtotal - FROM vn.ticketService ts - JOIN vn.ticket t ON ts.ticketFk = t.id - WHERE t.refFk = ? - ) sub - WHERE io.ref = ? AND ios.isCEE - ORDER BY sub.code; + FROM ( + SELECT i.intrastatFk code, + it.description, + CAST(SUM(ROUND((s.quantity * s.price * (100 - s.discount) / 100 ) , 2))AS DECIMAL(10, 2)) subtotal, + SUM(IFNULL(i.stems, 1) * s.quantity) stems, + CAST(SUM(IFNULL(i.stems, 1) + * s.quantity + * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) + * IF(sub.totalWeight, sub.totalWeight / vn.invoiceOut_getWeight(?), 1) + AS DECIMAL(10,2)) netKg + FROM sale s + JOIN ticket t ON s.ticketFk = t.id + JOIN supplier su ON su.id = t.companyFk + JOIN item i ON i.id = s.itemFk + JOIN intrastat it ON it.id = i.intrastatFk + LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk + LEFT JOIN ( + SELECT SUM(weight)totalWeight + FROM vn.ticket + WHERE refFk = ? + AND weight + ) sub ON TRUE + WHERE t.refFk =? + GROUP BY i.intrastatFk + UNION ALL + SELECT NULL , + IF((SUM((ts.quantity * ts.price))), 'Servicios', NULL), + IFNULL(CAST(SUM((ts.quantity * ts.price)) AS DECIMAL(10,2)), 0), + 0 , + 0 + FROM vn.ticketService ts + JOIN vn.ticket t ON ts.ticketFk = t.id + WHERE t.refFk = ? + ) sub2 + WHERE `description` IS NOT NULL;