salix/print/templates/reports/item-label-qr/sql/item.sql

42 lines
1.2 KiB
SQL

WITH RECURSIVE numbers AS (
SELECT 1 n
UNION ALL
SELECT n + 1
FROM numbers
WHERE n < ?
)
SELECT ROW_NUMBER() OVER() labelNum,
b.id buyFk,
b.itemFk,
b.quantity,
b.packing,
b.isPickedOff,
b.entryFk,
e.sub,
o.code origin,
COALESCE(p.`name`, p.id, '') producer,
i.name item,
i.`size`,
i.category,
i.stems,
i.inkFk,
IFNULL(CONCAT(ig.longName, ' ', ig.`size`, ' ', ig.subName), i.comment) comment,
i.typeFk,
i.isLaid,
w.code buyerName,
w.code,
s.company_name companyName,
t.shipped
FROM vn.buy b
JOIN vn.item i ON i.id = b.itemFk
LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk
LEFT JOIN edi.ekt e ON e.id = b.ektFk
JOIN vn.origin o ON o.id = i.originFk
LEFT JOIN vn.producer p ON p.id = i.producerFk
JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.worker w ON w.id = it.workerFk
LEFT JOIN edi.supplier s ON s.supplier_id = e.pro
JOIN vn.entry e2 ON e2.id = b.entryFk
JOIN vn.travel t ON t.id = e2.travelFk
JOIN numbers num
WHERE b.id = ?