2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketParking_findSkipped`(vTicketFk INT, vItemPackingTypeFk VARCHAR(1))
|
|
|
|
BEGIN
|
2024-06-05 06:05:46 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
/**
|
|
|
|
* Averigua los tickets que se han saltado por un error en el proceso encajado
|
|
|
|
* @param vTicketFk Ticket
|
|
|
|
* @param vItemPackingTypeFk Modo de encajado
|
|
|
|
* @return un select con los tickets afectados
|
2024-06-05 06:05:46 +00:00
|
|
|
*/
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DECLARE vParkingFk INT;
|
|
|
|
DECLARE vParked DATETIME;
|
|
|
|
DECLARE vLevel INT;
|
|
|
|
DECLARE vWagon INT;
|
|
|
|
DECLARE vCollectionFk INT;
|
2024-06-05 06:05:46 +00:00
|
|
|
|
|
|
|
SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0)
|
2024-01-15 11:31:03 +00:00
|
|
|
INTO vLevel, vWagon, vCollectionFk
|
|
|
|
FROM vn.ticketCollection tc
|
|
|
|
JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk
|
|
|
|
WHERE ticketFk = vTicketFk
|
|
|
|
ORDER BY c.id DESC
|
|
|
|
LIMIT 1;
|
2024-06-05 06:05:46 +00:00
|
|
|
|
|
|
|
SELECT created, parkingFk
|
2024-01-15 11:31:03 +00:00
|
|
|
INTO vParked, vParkingFk
|
|
|
|
FROM vn.ticketParking tp
|
2024-06-05 06:05:46 +00:00
|
|
|
JOIN vn.parking p ON p.id = tp.parkingFk
|
|
|
|
JOIN vn.sector s ON s.id = p.sectorFk
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE ticketFk = vTicketFk
|
|
|
|
AND s.itemPackingTypeFk = vItemPackingTypeFk
|
|
|
|
AND s.isPackagingArea ;
|
2024-06-05 06:05:46 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia
|
|
|
|
FROM vn.ticketParking tp
|
2024-06-05 10:42:55 +00:00
|
|
|
JOIN vn.parking p ON p.id = tp.parkingFk
|
|
|
|
JOIN vn.sector sc ON sc.id = p.sectorFk
|
|
|
|
LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk
|
|
|
|
JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk
|
|
|
|
JOIN vn.ticket t ON t.id = tp.ticketFk
|
|
|
|
JOIN vn.zone z ON z.id = t.zoneFk
|
|
|
|
JOIN vn.agencyMode am ON am.id = z.agencyModeFk
|
|
|
|
JOIN vn.state s ON s.id = tst.state
|
|
|
|
JOIN vn.alertLevel alPacked ON alPacked.code = 'PACKED'
|
|
|
|
JOIN vn.alertLevel alOnPreparation ON alOnPreparation.code = 'ON_PREPARATION'
|
2024-06-05 06:05:46 +00:00
|
|
|
WHERE (s.alertLevel < alPacked.id
|
2024-01-15 11:31:03 +00:00
|
|
|
AND tp.parkingFk = vParkingFk
|
|
|
|
AND sc.isPackagingArea
|
|
|
|
AND (
|
|
|
|
( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked )
|
|
|
|
OR
|
2024-06-05 06:05:46 +00:00
|
|
|
( tc.collectionFk = vCollectionFk
|
2024-01-15 11:31:03 +00:00
|
|
|
AND (LEFT(tc.wagon,1) < LEFT(vWagon,1)
|
2024-06-05 06:05:46 +00:00
|
|
|
OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1)))
|
2024-01-15 11:31:03 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
) -- Etiquetas que no se han escaneado y ya estamos con una posterior
|
|
|
|
OR
|
2024-06-05 06:05:46 +00:00
|
|
|
(s.alertLevel > alOnPreparation.id
|
2024-01-15 11:31:03 +00:00
|
|
|
AND tp.parkingFk = vParkingFk
|
|
|
|
AND sc.isPackagingArea
|
2024-06-05 06:05:46 +00:00
|
|
|
AND tp.created < vParked
|
2024-01-15 11:31:03 +00:00
|
|
|
AND t.packages <=> 0);
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|