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

25 lines
508 B
MySQL
Raw Normal View History

2024-07-02 07:36:23 +00:00
DELIMITER $$
2024-10-01 06:51:03 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setVolume`(
2024-07-02 07:36:23 +00:00
vSelf INT
)
BEGIN
/**
* Update the volume ticket.
2024-07-02 07:36:23 +00:00
*
* @param vSelf Ticket id
*/
DECLARE vVolume DECIMAL(10,6);
SELECT SUM(s.quantity * ic.cm3delivery / 1000000) INTO vVolume
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN itemCost ic ON ic.itemFk = s.itemFk
AND ic.warehouseFk = t.warehouseFk
WHERE t.id = vSelf;
UPDATE ticket
SET volume = vVolume
WHERE id = vSelf;
END$$
DELIMITER ;