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

40 lines
776 B
MySQL
Raw Normal View History

DELIMITER $$
2024-10-01 06:51:03 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`(
vItemFk INT
)
BEGIN
/**
* Update the volume of tickets containing the item.
*
* @param vItemFk Item id
*/
DECLARE vTicket INT;
DECLARE vDone BOOL;
DECLARE vTickets CURSOR FOR
SELECT DISTINCT t.id
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()
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;
CALL ticket_setVolume(vTicket);
2024-08-20 09:43:08 +00:00
END LOOP l;
CLOSE vTickets;
END$$
DELIMITER ;