33 lines
728 B
MySQL
33 lines
728 B
MySQL
|
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 ;
|