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

54 lines
1.7 KiB
MySQL
Raw Permalink Normal View History

2023-07-18 12:15:56 +00:00
SELECT
2021-05-27 08:49:19 +00:00
io.ref,
2021-02-24 06:51:05 +00:00
s.ticketFk,
2023-07-18 12:15:56 +00:00
ib.ediBotanic botanical,
s.quantity,
s.price,
2021-02-24 06:51:05 +00:00
s.discount,
2023-07-18 12:15:56 +00:00
s.itemFk,
s.concept,
2024-02-22 09:39:34 +00:00
tc.code vatType,
2024-07-08 09:05:11 +00:00
it.isPackaging,
i.subName
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
2023-07-18 12:15:56 +00:00
JOIN vn.client c ON c.id = t.clientFk
2021-05-27 08:49:19 +00:00
JOIN vn.payMethod pm ON pm.id = c.payMethodFk
2023-07-18 12:15:56 +00:00
JOIN vn.company co ON co.id = io.companyFk
2021-05-27 08:49:19 +00:00
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 = ?
2023-07-18 12:15:56 +00:00
UNION ALL
SELECT
2021-05-27 08:49:19 +00:00
io.ref,
2023-07-18 12:15:56 +00:00
t.id ticketFk,
NULL botanical,
ts.quantity,
ts.price,
0 discount,
2024-02-22 09:39:34 +00:00
NULL,
ts.description,
tc.code,
2024-07-08 09:05:11 +00:00
NULL,
2024-02-22 09:39:34 +00:00
NULL
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
2023-07-18 12:15:56 +00:00
JOIN vn.client c ON c.id = t.clientFk
2021-05-27 08:49:19 +00:00
JOIN vn.payMethod pm ON pm.id = c.payMethodFk
2023-07-18 12:15:56 +00:00
JOIN vn.company co ON co.id = io.companyFk
2021-05-27 08:49:19 +00:00
JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk
JOIN vn.taxClass tc ON tc.id = ts.taxClassFk
2023-07-18 12:15:56 +00:00
WHERE t.refFk = ?
2024-02-22 09:39:34 +00:00
ORDER BY (isPackaging), concept, itemFk