2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setParking`(
|
2024-07-08 11:17:29 +00:00
|
|
|
vSelf INT,
|
|
|
|
vParkingFk INT
|
|
|
|
)
|
|
|
|
BEGIN
|
2024-01-15 11:31:03 +00:00
|
|
|
/**
|
2024-07-08 11:17:29 +00:00
|
|
|
* Aparca un ticket en un parking.
|
2024-01-15 11:31:03 +00:00
|
|
|
*
|
2024-07-08 11:17:29 +00:00
|
|
|
* @param vSelf Id ticket
|
|
|
|
* @param vParkingFk Id parking
|
2024-01-15 11:31:03 +00:00
|
|
|
*/
|
|
|
|
DECLARE vDone INT DEFAULT FALSE;
|
|
|
|
DECLARE vCollectionTicketFk INT;
|
|
|
|
DECLARE vCursor CURSOR FOR
|
|
|
|
SELECT IFNULL(tc2.ticketFk, t.id)
|
|
|
|
FROM ticket t
|
|
|
|
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
|
|
|
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
2024-07-08 11:17:29 +00:00
|
|
|
WHERE t.id = vSelf;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
|
|
|
|
|
|
|
INSERT INTO vn.ticketParking(ticketFk, parkingFk)
|
|
|
|
SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk
|
|
|
|
FROM ticket t
|
|
|
|
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
|
|
|
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
2024-07-08 11:17:29 +00:00
|
|
|
WHERE t.id = vSelf
|
2024-01-15 11:31:03 +00:00
|
|
|
ON DUPLICATE KEY UPDATE parkingFk = vParkingFk;
|
|
|
|
|
|
|
|
OPEN vCursor;
|
|
|
|
l: LOOP
|
|
|
|
FETCH vCursor INTO vCollectionTicketFk;
|
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE l;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CALL vn.ticket_setNextState(vCollectionTicketFk);
|
|
|
|
END LOOP;
|
|
|
|
|
|
|
|
CLOSE vCursor;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|