salix/db/routines/stock/procedures/buyOut_refreshOrder.sql

38 lines
946 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `stock`.`buyOut_refreshOrder`(
`vTable` VARCHAR(255),
`vId` INT)
BEGIN
2025-02-24 17:05:21 +00:00
CREATE OR REPLACE TEMPORARY TABLE tLotStatus
ENGINE = MEMORY
2025-02-24 17:05:21 +00:00
SELECT lotFk,
@isExcluded := o.confirmed OR NOT isReserved OR r.amount <= 0 isExcluded,
NOT @isExcluded isIncluded
2025-02-24 17:05:21 +00:00
FROM hedera.orderRow r
JOIN hedera.`order` o ON o.id = r.orderFk
WHERE
2025-02-24 17:05:21 +00:00
(vTable = 'lot' AND r.lotFk = vId)
OR (vTable = 'order' AND o.id = vId);
2025-02-24 17:05:21 +00:00
CREATE OR REPLACE TEMPORARY TABLE tLotAlive
ENGINE = MEMORY
SELECT
2025-02-24 17:05:21 +00:00
oo.lotFk,
r.warehouseFk,
r.shipment dated,
r.itemFk,
r.amount quantity,
r.created,
FALSE isPicked
2025-02-24 17:05:21 +00:00
FROM tLotStatus oo
JOIN hedera.orderRow r ON r.lotFk = oo.lotFk
JOIN hedera.`order` o ON o.id = r.orderFk
WHERE oo.isIncluded;
2025-02-24 17:05:21 +00:00
CALL buyOut_refresh(vTable, vId, 'orderRow');
2025-02-24 17:05:21 +00:00
DROP TEMPORARY TABLE tLotStatus, tLotAlive;
END$$
DELIMITER ;