fix: refs #7564 Ticket volume item cost

This commit is contained in:
Guillermo Bonet 2024-09-17 12:10:47 +02:00
parent 55df919076
commit 4a102d315d
2 changed files with 22 additions and 12 deletions

View File

@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolume`(
) )
BEGIN BEGIN
/** /**
* Update the volume ticket * Update the volume ticket.
* *
* @param vSelf Ticket id * @param vSelf Ticket id
*/ */

View File

@ -4,26 +4,36 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolumeIte
) )
BEGIN BEGIN
/** /**
* Update the volume tickets of item * Update the volume of tickets containing the item.
* *
* @param vSelf Ticket id * @param vItemFk Item id
*/ */
CREATE OR REPLACE TEMPORARY TABLE tTicket DECLARE vTicket INT;
(PRIMARY KEY (id)) DECLARE vDone BOOL;
ENGINE = MEMORY
SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume DECLARE vTickets CURSOR FOR
SELECT DISTINCT t.id
FROM sale s FROM sale s
JOIN ticket t ON t.id = s.ticketFk JOIN ticket t ON t.id = s.ticketFk
JOIN itemCost ic ON ic.itemFk = s.itemFk JOIN itemCost ic ON ic.itemFk = s.itemFk
AND ic.warehouseFk = t.warehouseFk AND ic.warehouseFk = t.warehouseFk
WHERE s.itemFk = vItemFk WHERE s.itemFk = vItemFk
AND t.shipped >= util.VN_CURDATE() AND t.shipped >= util.VN_CURDATE()
GROUP BY t.id; AND t.refFk IS NULL;
UPDATE ticket t DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
JOIN tTicket tt ON tt.id = t.id
SET t.volume = tt.volume;
DROP TEMPORARY TABLE tTicket; OPEN vTickets;
l: LOOP
FETCH vTickets INTO vTicket;
IF vDone THEN
LEAVE l;
END IF;
CALL ticket_setVolume(vTicket);
END LOOP l;
CLOSE vTickets;
END$$ END$$
DELIMITER ; DELIMITER ;