salix/db/routines/vn/procedures/collection_getTickets.sql

105 lines
3.8 KiB
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`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
*/
DECLARE vItemPackingTypeFk VARCHAR(1);
DECLARE vYesterday DATE;
-- Si los sacadores son los de pruebas, pinta los colores
2024-04-11 10:16:00 +00:00
SELECT itemPackingTypeFk
INTO vItemPackingTypeFk
FROM collection
WHERE id = vParamFk;
2024-04-11 10:16:00 +00:00
SET vYesterday = util.yesterday();
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
2024-10-04 08:42:33 +00:00
JOIN vn.observationType ot ON ot.id = tob.observationTypeFk AND ot.`code` = 'itemPicker'
WHERE tc.collectionFk = vParamFk OR tc.ticketFk = vParamFk
2024-04-11 10:16:00 +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`,
am.name agencyName,
t.warehouseFk,
w.id salesPersonFk,
2024-05-27 09:33:04 +00:00
IFNULL(ob.description,'') observaciones,
2024-11-05 15:42:51 +00:00
cc.rgb,
p.code parkingCode,
IF (ps.ticketFk, TRUE, FALSE) isAdvanced
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
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-11-05 15:42:51 +00:00
LEFT JOIN observation ob ON ob.ticketFk = t.id
LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
LEFT JOIN vn.parking p ON tp.parkingFk = p.id
LEFT JOIN vn.packingSiteAdvanced ps ON ps.ticketFk = t.id
WHERE t.id = vParamFk
AND t.shipped >= vYesterday
UNION
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`,
am.name agencyName,
t.warehouseFk,
2024-04-11 10:16:00 +00:00
w.id salesPersonFk,
ob.description,
2024-11-05 15:42:51 +00:00
IF(NOT (vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb`,
p.code parkingCode,
IF (ps.ticketFk, TRUE, FALSE) isAdvanced
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
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-11-05 15:42:51 +00:00
LEFT JOIN observation ob ON ob.ticketFk = t.id
LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
LEFT JOIN vn.parking p ON tp.parkingFk = p.id
LEFT JOIN vn.packingSiteAdvanced ps ON ps.ticketFk = t.id
2024-04-11 10:16:00 +00:00
WHERE tc.collectionFk = vParamFk
UNION
2024-04-11 10:16:00 +00:00
SELECT sg.ticketFk,
NULL `level`,
am.name agencyName,
t.warehouseFk,
c.salesPersonFk,
ob.description,
2024-11-05 15:42:51 +00:00
NULL `rgb`,
p.code parkingCode,
IF (ps.ticketFk, TRUE, FALSE) isAdvanced
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-11-05 15:42:51 +00:00
LEFT JOIN vn.client c ON c.id = t.clientFk
LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
LEFT JOIN vn.parking p ON tp.parkingFk = p.id
LEFT JOIN vn.packingSiteAdvanced ps ON ps.ticketFk = t.id
2024-04-11 10:16:00 +00:00
WHERE sc.id = vParamFk
AND t.shipped >= vYesterday
GROUP BY ticketFk;
END$$
DELIMITER ;