2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`reportLabelCollection_get`(
|
2024-01-15 11:31:03 +00:00
|
|
|
vParam INT,
|
|
|
|
vLabelCount INT
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Obtains tag data from a ticket or collection.
|
|
|
|
*
|
|
|
|
* @param vParam Ticket/Collection from which data is to be taken.
|
|
|
|
* @param vLabelCount number of times the collection has been printed.
|
|
|
|
*/
|
|
|
|
DECLARE vIsCollection BOOL;
|
|
|
|
|
|
|
|
SELECT IF(id, TRUE, FALSE) INTO vIsCollection
|
|
|
|
FROM vn.collection c
|
|
|
|
WHERE id = vParam;
|
|
|
|
|
|
|
|
SELECT c.itemPackingTypeFk,
|
|
|
|
CONCAT(tc.collectionFk, ' ', LEFT(cc.code, 4)) color,
|
|
|
|
CONCAT(tc.collectionFk, ' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.level) levelV,
|
|
|
|
tc.ticketFk,
|
2024-04-30 09:48:18 +00:00
|
|
|
LEFT(COALESCE(rs.description, zo.name, am.name),12) agencyDescription,
|
2024-01-15 11:31:03 +00:00
|
|
|
am.name,
|
|
|
|
t.clientFk,
|
|
|
|
CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5, 2)), 'm³') m3 ,
|
|
|
|
CAST(IF(ic.code = 'plant', CONCAT(MAX(i.size), ' cm'), COUNT(*)) AS CHAR) size,
|
|
|
|
w.code workerCode,
|
|
|
|
IF(vLabelCount IS NULL, tt.labelCount, vLabelCount) labelCount,
|
|
|
|
IF(HOUR(t.shipped), TIME(t.shipped), TIME(zo.hour)) agencyHour,
|
|
|
|
t.shipped,
|
|
|
|
COUNT(*) lineCount,
|
|
|
|
t.nickName
|
|
|
|
FROM ticket t
|
|
|
|
JOIN ticketCollection tc ON tc.ticketFk = t.id
|
|
|
|
JOIN collection c ON c.id = tc.collectionFk
|
|
|
|
LEFT JOIN collectionColors cc ON cc.shelve = tc.level
|
|
|
|
AND cc.wagon = tc.wagon
|
|
|
|
AND cc.trainFk = c.trainFk
|
|
|
|
JOIN sale s ON s.ticketFk = t.id
|
|
|
|
LEFT JOIN saleVolume sv ON sv.saleFk = s.id
|
|
|
|
JOIN item i ON i.id = s.itemFk
|
|
|
|
JOIN itemType it ON it.id = i.typeFk
|
|
|
|
JOIN itemCategory ic ON ic.id = it.categoryFk
|
|
|
|
JOIN worker w ON w.id = c.workerFk
|
|
|
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
|
|
|
LEFT JOIN ticketTrolley tt ON tt.ticket = t.id
|
|
|
|
LEFT JOIN zone zo ON t.zoneFk = zo.id
|
|
|
|
LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk
|
2024-05-27 07:07:23 +00:00
|
|
|
LEFT JOIN roadmapStop rs ON rs.id = rm.roadmapStopFk
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE IF(vIsCollection, tc.collectionFk = vParam, tc.ticketFk = vParam)
|
|
|
|
GROUP BY t.id
|
|
|
|
ORDER BY cc.code;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|