salix/print/templates/reports/delivery-note/sql/sales.sql

45 lines
1.2 KiB
MySQL
Raw Normal View History

2024-06-25 10:00:49 +00:00
SELECT
2020-09-25 12:45:00 +00:00
s.id,
s.itemFk,
s.concept,
s.quantity,
s.price,
s.price - SUM(IF(ctr.id = 6, sc.value, 0)) netPrice,
s.discount,
i.size,
i.stems,
i.category,
it.id itemTypeId,
o.code AS origin,
i.inkFk,
s.ticketFk,
tcl.code vatType,
ib.ediBotanic botanical,
2024-06-25 10:00:49 +00:00
i.tag5,
2020-09-25 12:45:00 +00:00
i.value5,
2024-06-25 10:00:49 +00:00
i.tag6,
i.value6,
i.tag7,
i.value7,
i.subName
2020-09-25 12:45:00 +00:00
FROM vn.sale s
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
LEFT JOIN component cr ON cr.id = sc.componentFk
LEFT JOIN componentType ctr ON ctr.id = cr.typeFk
LEFT JOIN item i ON i.id = s.itemFk
LEFT JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN origin o ON o.id = i.originFk
LEFT JOIN country c ON c.id = o.countryFk
LEFT JOIN supplier sp ON sp.id = t.companyFk
LEFT JOIN itemType it ON it.id = i.typeFk
2020-12-16 08:24:11 +00:00
LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
2024-06-25 10:00:49 +00:00
LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id
AND itc.countryFk = sp.countryFk
2020-09-25 12:45:00 +00:00
LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk
LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id
2020-12-16 08:24:11 +00:00
AND ic.code = 'plant'
2021-02-24 06:51:05 +00:00
AND ib.ediBotanic IS NOT NULL
2020-09-25 12:45:00 +00:00
WHERE s.ticketFk = ?
GROUP BY s.id
2024-06-25 10:00:49 +00:00
ORDER BY (it.isPackaging), s.concept, s.itemFk