2024-07-03 07:29:12 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`(
|
|
|
|
vItemFk INT
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-09-17 10:10:47 +00:00
|
|
|
* Update the volume of tickets containing the item.
|
2024-07-03 07:29:12 +00:00
|
|
|
*
|
2024-09-17 10:10:47 +00:00
|
|
|
* @param vItemFk Item id
|
2024-07-03 07:29:12 +00:00
|
|
|
*/
|
2024-09-17 10:10:47 +00:00
|
|
|
DECLARE vTicket INT;
|
|
|
|
DECLARE vDone BOOL;
|
|
|
|
|
|
|
|
DECLARE vTickets CURSOR FOR
|
|
|
|
SELECT DISTINCT t.id
|
2024-07-03 07:29:12 +00:00
|
|
|
FROM sale s
|
|
|
|
JOIN ticket t ON t.id = s.ticketFk
|
|
|
|
JOIN itemCost ic ON ic.itemFk = s.itemFk
|
|
|
|
AND ic.warehouseFk = t.warehouseFk
|
2024-08-20 09:43:08 +00:00
|
|
|
WHERE s.itemFk = vItemFk
|
|
|
|
AND t.shipped >= util.VN_CURDATE()
|
2024-09-17 10:10:47 +00:00
|
|
|
AND t.refFk IS NULL;
|
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
|
|
|
|
|
|
|
OPEN vTickets;
|
|
|
|
l: LOOP
|
|
|
|
FETCH vTickets INTO vTicket;
|
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE l;
|
|
|
|
END IF;
|
2024-07-03 07:29:12 +00:00
|
|
|
|
2024-09-17 10:10:47 +00:00
|
|
|
CALL ticket_setVolume(vTicket);
|
2024-08-20 09:43:08 +00:00
|
|
|
|
2024-09-17 10:10:47 +00:00
|
|
|
END LOOP l;
|
|
|
|
CLOSE vTickets;
|
2024-07-03 07:29:12 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|