salix/print/templates/reports/collection-label/sql/labelsData.sql

43 lines
1.7 KiB
MySQL
Raw Normal View History

2022-11-30 07:18:37 +00:00
SELECT c.itemPackingTypeFk code,
2023-01-13 07:44:58 +00:00
tc.collectionFk,
SUBSTRING('ABCDEFGH', tc.wagon, 1) wagon,
tc.`level`,
t.id ticketFk,
COALESCE(rs.description, zo.name, am.name) agencyDescription,
2023-01-13 07:44:58 +00:00
cc.code color,
t.clientFk,
CAST(SUM(sv.volume) AS DECIMAL(5, 2)) volume,
MAX(
2024-01-15 09:03:05 +00:00
IF(sgd.id, IFNULL(pc.itemPreviousDefaultSize, i.`size`), i.`size`)
) `size`,
2023-01-13 07:44:58 +00:00
w.code workerCode,
w.id workerFk,
2023-01-13 07:44:58 +00:00
TIME_FORMAT(t.shipped, '%H:%i') shippedHour,
TIME_FORMAT(zo.`hour`, '%H:%i') zoneHour,
DATE_FORMAT(t.shipped, '%d/%m/%y') shipped,
tt.labelCount,
t.nickName,
SUM(IF(sgd.id IS NULL, 1, 0)) + IF(sgd.id , 1, 0) lineCount,
2023-01-13 07:44:58 +00:00
rm.routeFk
FROM vn.ticket t
JOIN vn.ticketCollection tc ON tc.ticketFk = t.id
JOIN vn.collection c ON c.id = tc.collectionFk
LEFT JOIN vn.collectionColors cc ON cc.shelve = tc.`level`
AND cc.wagon = tc.wagon
AND cc.trainFk = c.trainFk
JOIN vn.sale s ON s.ticketFk = t.id
LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
2023-01-13 07:44:58 +00:00
JOIN vn.item i ON i.id = s.itemFk
JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
JOIN vn.worker w ON w.id = c.workerFk
JOIN vn.agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN vn.ticketTrolley tt ON tt.ticket = t.id
LEFT JOIN vn.`zone` zo ON t.zoneFk = zo.id
LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk
LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk
LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
JOIN vn.productionConfig pc
2023-01-13 07:44:58 +00:00
WHERE t.id IN (?)
GROUP BY t.id
ORDER BY cc.`code`