Merge pull request 'MASTER_hotfix_invoiceOut' (!1197) from MASTER_hotfix_invoiceOut into master
gitea/salix/pipeline/head There was a failure building this commit Details

Reviewed-on: #1197
This commit is contained in:
Vicent Llopis 2022-12-02 12:25:33 +00:00
commit f7178f4e32
3 changed files with 41 additions and 34 deletions

View File

@ -138,7 +138,7 @@ module.exports = Self => {
recipient: invoiceOut.client().email recipient: invoiceOut.client().email
}; };
try { try {
await models.InvoiceOut.invoiceEmail(ctx); await models.InvoiceOut.invoiceEmail(ctx, invoiceOut.ref);
} catch (err) {} } catch (err) {}
return invoiceId; return invoiceId;

View File

@ -82,7 +82,7 @@ module.exports = {
return this.rawSqlFromDef(`taxes`, [reference]); return this.rawSqlFromDef(`taxes`, [reference]);
}, },
fetchIntrastat(reference) { fetchIntrastat(reference) {
return this.rawSqlFromDef(`intrastat`, [reference, reference, reference, reference]); return this.rawSqlFromDef(`intrastat`, [reference, reference, reference, reference, reference]);
}, },
fetchRectified(reference) { fetchRectified(reference) {
return this.rawSqlFromDef(`rectified`, [reference]); return this.rawSqlFromDef(`rectified`, [reference]);

View File

@ -1,32 +1,39 @@
(SELECT SELECT *
ir.id code, FROM invoiceOut io
ir.description description, JOIN invoiceOutSerial ios ON io.serial = ios.code
CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL(10,2)) stems, JOIN
CAST(SUM(CAST(IFNULL(i.stems, 1) * s.quantity * IF(ic.grams, ic.grams, i.density * ic.cm3delivery / 1000) / 1000 AS DECIMAL(10,2)) * (SELECT
IF(sub.weight, sub.weight / vn.invoiceOut_getWeight(?), 1)) AS DECIMAL(10,2)) netKg, t.refFk,
CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) subtotal ir.id code,
FROM vn.ticket t ir.description description,
JOIN vn.sale s ON s.ticketFk = t.id CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL(10,2)) stems,
JOIN vn.item i ON i.id = s.itemFk CAST(SUM(CAST(IFNULL(i.stems, 1) * s.quantity * IF(ic.grams, ic.grams, i.density * ic.cm3delivery / 1000) / 1000 AS DECIMAL(10,2)) *
JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk IF(sub.weight, sub.weight / vn.invoiceOut_getWeight(?), 1)) AS DECIMAL(10,2)) netKg,
JOIN vn.intrastat ir ON ir.id = i.intrastatFk CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) subtotal
LEFT JOIN ( FROM vn.ticket t
SELECT t2.weight JOIN vn.sale s ON s.ticketFk = t.id
FROM vn.ticket t2 JOIN vn.item i ON i.id = s.itemFk
WHERE refFk = ? AND weight JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk
LIMIT 1 JOIN vn.intrastat ir ON ir.id = i.intrastatFk
) sub ON TRUE LEFT JOIN (
WHERE t.refFk = ? SELECT t2.weight
AND i.intrastatFk FROM vn.ticket t2
GROUP BY i.intrastatFk WHERE refFk = ? AND weight
ORDER BY i.intrastatFk) LIMIT 1
UNION ALL ) sub ON TRUE
(SELECT WHERE t.refFk = ?
NULL AS code, AND i.intrastatFk
NULL AS description, GROUP BY i.intrastatFk
0 AS stems, UNION ALL
0 AS netKg, SELECT
CAST(SUM((ts.quantity * ts.price)) AS DECIMAL(10,2)) AS subtotal NULL AS refFk,
FROM vn.ticketService ts NULL AS code,
JOIN vn.ticket t ON ts.ticketFk = t.id NULL AS description,
WHERE t.refFk = ?); 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;