2024-07-03 07:29:12 +00:00
|
|
|
DELIMITER $$
|
2024-10-01 06:51:03 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`(
|
2024-07-03 07:29:12 +00:00
|
|
|
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 ;
|