From 14a3a815da11e780009fce9e635aece4a0413221 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 2 Dec 2022 12:05:25 +0100 Subject: [PATCH] =?UTF-8?q?fix(invoiceOut):=20pdf=20adjunto=20correcto.=20?= =?UTF-8?q?Corregido=20valor=20NaN=20en=20intrastat.=20S=C3=B3lo=20muestra?= =?UTF-8?q?=20intrstar=20en=20fact=20CEE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/invoiceOut/invoiceClient.js | 2 +- print/templates/reports/invoice/invoice.js | 2 +- .../reports/invoice/sql/intrastat.sql | 71 ++++++++++--------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js index b04747d16..95c51a96d 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js +++ b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js @@ -138,7 +138,7 @@ module.exports = Self => { recipient: invoiceOut.client().email }; try { - await models.InvoiceOut.invoiceEmail(ctx); + await models.InvoiceOut.invoiceEmail(ctx, invoiceOut.ref); } catch (err) {} return invoiceId; diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js index eebbde8ef..48848c079 100755 --- a/print/templates/reports/invoice/invoice.js +++ b/print/templates/reports/invoice/invoice.js @@ -82,7 +82,7 @@ module.exports = { return this.rawSqlFromDef(`taxes`, [reference]); }, fetchIntrastat(reference) { - return this.rawSqlFromDef(`intrastat`, [reference, reference, reference, reference]); + return this.rawSqlFromDef(`intrastat`, [reference, reference, reference, reference, reference]); }, fetchRectified(reference) { return this.rawSqlFromDef(`rectified`, [reference]); diff --git a/print/templates/reports/invoice/sql/intrastat.sql b/print/templates/reports/invoice/sql/intrastat.sql index 5cc3ebd7f..7f5fbdf39 100644 --- a/print/templates/reports/invoice/sql/intrastat.sql +++ b/print/templates/reports/invoice/sql/intrastat.sql @@ -1,32 +1,39 @@ -(SELECT - ir.id code, - ir.description description, - CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL(10,2)) stems, - CAST(SUM(CAST(IFNULL(i.stems, 1) * s.quantity * IF(ic.grams, ic.grams, i.density * ic.cm3delivery / 1000) / 1000 AS DECIMAL(10,2)) * - IF(sub.weight, sub.weight / vn.invoiceOut_getWeight(?), 1)) AS DECIMAL(10,2)) netKg, - CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) subtotal - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk - JOIN vn.intrastat ir ON ir.id = i.intrastatFk - LEFT JOIN ( - SELECT t2.weight - FROM vn.ticket t2 - WHERE refFk = ? AND weight - LIMIT 1 - ) sub ON TRUE - WHERE t.refFk = ? - AND i.intrastatFk - GROUP BY i.intrastatFk - ORDER BY i.intrastatFk) -UNION ALL -(SELECT - NULL AS code, - NULL AS description, - 0 AS stems, - 0 AS netKg, - CAST(SUM((ts.quantity * ts.price)) AS DECIMAL(10,2)) AS subtotal - FROM vn.ticketService ts - JOIN vn.ticket t ON ts.ticketFk = t.id - WHERE t.refFk = ?); \ No newline at end of file +SELECT * + FROM invoiceOut io + JOIN invoiceOutSerial ios ON io.serial = ios.code + JOIN + (SELECT + t.refFk, + ir.id code, + ir.description description, + CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL(10,2)) stems, + CAST(SUM(CAST(IFNULL(i.stems, 1) * s.quantity * IF(ic.grams, ic.grams, i.density * ic.cm3delivery / 1000) / 1000 AS DECIMAL(10,2)) * + IF(sub.weight, sub.weight / vn.invoiceOut_getWeight(?), 1)) AS DECIMAL(10,2)) netKg, + CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) subtotal + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk + JOIN vn.intrastat ir ON ir.id = i.intrastatFk + LEFT JOIN ( + SELECT t2.weight + FROM vn.ticket t2 + WHERE refFk = ? AND weight + LIMIT 1 + ) sub ON TRUE + WHERE t.refFk = ? + AND i.intrastatFk + GROUP BY i.intrastatFk + UNION ALL + SELECT + NULL AS refFk, + NULL AS code, + NULL AS description, + 0 AS stems, + 0 AS netKg, + IF(CAST(SUM((ts.quantity * ts.price)) AS DECIMAL(10,2)), CAST(SUM((ts.quantity * ts.price)) AS DECIMAL(10,2)), 0) AS 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;