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

72 lines
2.2 KiB
MySQL
Raw Normal View History

2021-02-24 06:51:05 +00:00
SELECT
2021-05-27 08:49:19 +00:00
io.ref,
c.socialName,
sa.iban,
pm.name AS payMethod,
t.clientFk,
t.shipped,
t.nickname,
2021-02-24 06:51:05 +00:00
s.ticketFk,
s.itemFk,
s.concept,
s.quantity,
s.price,
s.discount,
i.tag5,
i.value5,
i.tag6,
i.value6,
i.tag7,
i.value7,
tc.code AS vatType,
ib.ediBotanic botanical
2021-05-27 08:49:19 +00:00
FROM vn.invoiceOut io
JOIN vn.ticket t ON t.refFk = io.ref
JOIN vn.supplier su ON su.id = io.companyFk
JOIN vn.client c ON c.id = t.clientFk
JOIN vn.payMethod pm ON pm.id = c.payMethodFk
JOIN vn.company co ON co.id = io.companyFk
JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk
JOIN vn.sale s ON s.ticketFk = t.id
JOIN item i ON i.id = s.itemFk
LEFT JOIN itemType it ON it.id = i.typeFk
LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id
AND ic.code = 'plant'
AND ib.ediBotanic IS NOT NULL
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk
AND itc.itemFk = s.itemFk
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
2022-07-21 08:05:37 +00:00
WHERE t.refFk = ?
2021-05-27 08:49:19 +00:00
UNION ALL
2021-02-24 06:51:05 +00:00
SELECT
2021-05-27 08:49:19 +00:00
io.ref,
c.socialName,
sa.iban,
pm.name AS payMethod,
t.clientFk,
t.shipped,
t.nickname,
t.id AS ticketFk,
2021-02-24 06:51:05 +00:00
'',
ts.description concept,
ts.quantity,
ts.price,
0 discount,
NULL AS tag5,
NULL AS value5,
NULL AS tag6,
NULL AS value6,
NULL AS tag7,
NULL AS value7,
tc.code AS vatType,
NULL AS botanical
2021-05-27 08:49:19 +00:00
FROM vn.invoiceOut io
JOIN vn.ticket t ON t.refFk = io.ref
JOIN vn.ticketService ts ON ts.ticketFk = t.id
JOIN vn.client c ON c.id = t.clientFk
JOIN vn.payMethod pm ON pm.id = c.payMethodFk
JOIN vn.company co ON co.id = io.companyFk
JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk
JOIN vn.taxClass tc ON tc.id = ts.taxClassFk
2022-07-21 08:05:37 +00:00
WHERE t.refFk = ?