{{$t('deliveryNote')}}
diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js
index bd85a812c..c5abfad7e 100755
--- a/print/templates/reports/invoice/invoice.js
+++ b/print/templates/reports/invoice/invoice.js
@@ -27,7 +27,8 @@ module.exports = {
for (let sale of sales) {
const ticket = map.get(sale.ticketFk);
- ticket.sales.push(sale);
+
+ if (ticket) ticket.sales.push(sale);
}
this.tickets = tickets;
diff --git a/print/templates/reports/invoice/sql/intrastat.sql b/print/templates/reports/invoice/sql/intrastat.sql
index e391056ec..6bf72c158 100644
--- a/print/templates/reports/invoice/sql/intrastat.sql
+++ b/print/templates/reports/invoice/sql/intrastat.sql
@@ -2,9 +2,13 @@ SELECT
ir.id AS code,
ir.description AS description,
CAST(SUM(IFNULL(i.stems,1) * s.quantity) AS DECIMAL(10,2)) as stems,
- CAST(SUM( weight) AS DECIMAL(10,2)) as netKg,
+ CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) netKg,
CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) AS subtotal
- FROM vn.sale s
+ FROM vn.sale s
+ LEFT JOIN (SELECT ic.itemFk, ic.cm3, ic.cm3delivery
+ FROM vn.itemCost ic
+ WHERE ic.cm3
+ GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk
LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
LEFT JOIN vn.ticket t ON t.id = s.ticketFk
LEFT JOIN vn.invoiceOut io ON io.ref = t.refFk