salix/print/templates/reports/invoice/sql/intrastat.sql

18 lines
920 B
MySQL
Raw Normal View History

2021-02-24 06:51:05 +00:00
SELECT
ir.id AS code,
ir.description AS description,
CAST(SUM(IFNULL(i.stems,1) * s.quantity) AS DECIMAL(10,2)) as stems,
2022-02-17 09:18:47 +00:00
CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) netKg,
2021-02-24 06:51:05 +00:00
CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) AS subtotal
2022-02-17 09:18:47 +00:00
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
2021-02-24 06:51:05 +00:00
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
LEFT JOIN vn.item i ON i.id = s.itemFk
JOIN vn.intrastat ir ON ir.id = i.intrastatFk
WHERE io.id = ?
2021-03-16 12:37:59 +00:00
GROUP BY i.intrastatFk;