2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getTickets`(vParamFk INT)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-04-11 10:16:00 +00:00
|
|
|
* Selecciona los tickets de una colección/ticket/sectorCollection
|
|
|
|
* @param vParamFk ticketFk/collectionFk/sectorCollection
|
|
|
|
* @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observation
|
2024-01-15 11:31:03 +00:00
|
|
|
*/
|
|
|
|
DECLARE vItemPackingTypeFk VARCHAR(1);
|
2024-06-11 16:43:26 +00:00
|
|
|
DECLARE vYesterday DATE;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
-- Si los sacadores son los de pruebas, pinta los colores
|
2024-04-11 10:16:00 +00:00
|
|
|
SELECT itemPackingTypeFk
|
|
|
|
INTO vItemPackingTypeFk
|
|
|
|
FROM collection
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE id = vParamFk;
|
2024-04-11 10:16:00 +00:00
|
|
|
|
2024-06-11 16:43:26 +00:00
|
|
|
SET vYesterday = util.yesterday();
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-04-11 10:16:00 +00:00
|
|
|
WITH observation AS (
|
|
|
|
SELECT tob.ticketFk, tob.description
|
2024-05-27 09:33:04 +00:00
|
|
|
FROM vn.ticketObservation tob
|
|
|
|
JOIN vn.ticketCollection tc ON tc.ticketFk = tob.ticketFk
|
|
|
|
LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk
|
2024-04-11 10:16:00 +00:00
|
|
|
WHERE ot.`code` = 'itemPicker'
|
|
|
|
AND tc.collectionFk = vParamFk
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT t.id ticketFk,
|
2024-04-11 10:16:00 +00:00
|
|
|
IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
2024-01-15 11:31:03 +00:00
|
|
|
am.name agencyName,
|
|
|
|
t.warehouseFk,
|
|
|
|
w.id salesPersonFk,
|
2024-05-27 09:33:04 +00:00
|
|
|
IFNULL(ob.description,'') observaciones,
|
2024-01-15 11:31:03 +00:00
|
|
|
cc.rgb
|
2024-05-27 09:33:04 +00:00
|
|
|
FROM vn.ticket t
|
|
|
|
LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk
|
|
|
|
LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk
|
|
|
|
LEFT JOIN vn.collectionColors cc
|
2024-01-15 11:31:03 +00:00
|
|
|
ON cc.wagon = tc.wagon
|
|
|
|
AND cc.shelve = tc.`level`
|
2024-04-11 10:16:00 +00:00
|
|
|
AND cc.trainFk = c2.trainFk
|
2024-05-27 09:33:04 +00:00
|
|
|
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
|
|
|
LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk
|
|
|
|
LEFT JOIN vn.client c ON c.id = t.clientFk
|
|
|
|
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
2024-04-11 10:16:00 +00:00
|
|
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE t.id = vParamFk
|
2024-06-11 16:43:26 +00:00
|
|
|
AND t.shipped >= vYesterday
|
2024-01-15 11:31:03 +00:00
|
|
|
UNION ALL
|
|
|
|
SELECT t.id ticketFk,
|
2024-04-11 10:16:00 +00:00
|
|
|
IF(NOT(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
2024-01-15 11:31:03 +00:00
|
|
|
am.name agencyName,
|
|
|
|
t.warehouseFk,
|
2024-04-11 10:16:00 +00:00
|
|
|
w.id salesPersonFk,
|
|
|
|
ob.description,
|
|
|
|
IF(NOT (vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb`
|
2024-05-27 09:33:04 +00:00
|
|
|
FROM vn.ticket t
|
|
|
|
JOIN vn.ticketCollection tc ON t.id = tc.ticketFk
|
|
|
|
LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk
|
|
|
|
LEFT JOIN vn.collectionColors cc
|
2024-01-15 11:31:03 +00:00
|
|
|
ON cc.wagon = tc.wagon
|
|
|
|
AND cc.shelve = tc.`level`
|
2024-04-11 10:16:00 +00:00
|
|
|
AND cc.trainFk = c2.trainFk
|
2024-05-27 09:33:04 +00:00
|
|
|
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
|
|
|
LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk
|
|
|
|
LEFT JOIN vn.client c ON c.id = t.clientFk
|
|
|
|
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
2024-04-11 10:16:00 +00:00
|
|
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
|
|
|
WHERE tc.collectionFk = vParamFk
|
|
|
|
UNION ALL
|
|
|
|
SELECT sg.ticketFk,
|
|
|
|
NULL `level`,
|
|
|
|
am.name agencyName,
|
|
|
|
t.warehouseFk,
|
|
|
|
c.salesPersonFk,
|
|
|
|
ob.description,
|
|
|
|
NULL `rgb`
|
2024-05-27 09:33:04 +00:00
|
|
|
FROM vn.sectorCollection sc
|
|
|
|
JOIN vn.sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id
|
|
|
|
JOIN vn.saleGroup sg ON sg.id = ss.saleGroupFk
|
|
|
|
JOIN vn.ticket t ON t.id = sg.ticketFk
|
|
|
|
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
|
|
|
LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk
|
2024-04-11 10:16:00 +00:00
|
|
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
2024-05-27 09:33:04 +00:00
|
|
|
LEFT JOIN vn.client c ON c.id = t.clientFk
|
2024-04-11 10:16:00 +00:00
|
|
|
WHERE sc.id = vParamFk
|
2024-06-11 16:43:26 +00:00
|
|
|
AND t.shipped >= vYesterday;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|