feat: refs #7564 Added ticket_setVolumeItemCost
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-07-03 09:29:12 +02:00
parent 1e5fd8002c
commit 2f8df96ba7
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`(
vItemFk INT
)
BEGIN
/**
* Update the volume tickets of item
*
* @param vSelf Ticket id
*/
CREATE OR REPLACE TEMPORARY TABLE tTicket
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume
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 IN (
SELECT DISTINCT ticketFk
FROM sale
WHERE itemFk = vItemFk
)
GROUP BY t.id;
UPDATE ticket t
JOIN tTicket tt ON tt.id = t.id
SET t.volume = tt.volume;
DROP TEMPORARY TABLE tTicket;
END$$
DELIMITER ;