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

37 lines
946 B
MySQL
Raw Permalink 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-26 08:36:43 +00:00
ls.lotFk,
r.warehouseFk,
r.shipment dated,
r.itemFk,
r.amount quantity,
r.created,
FALSE isPicked
FROM tLotStatus ls
JOIN hedera.orderRow r ON r.lotFk = ls.lotFk
JOIN hedera.`order` o ON o.id = r.orderFk
WHERE ls.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 ;