feat: refs #8069 new proc

This commit is contained in:
Pako Natek 2024-10-01 15:02:24 +02:00
parent fd262e32c1
commit 03ea7580d8
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `hedera`.`orderRow_updateOverstocking`(
vWarehouseFk INT
)
BEGIN
/**
* Set amount = 0 to avoid overbooking sales
*
* @param vWarehouseFk vn.warehouse.id
*/
DECLARE vCalcFk INT;
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, CURDATE());
UPDATE orderRow r
JOIN `order` o ON o.id = r.orderFk
JOIN orderConfig oc
JOIN cache.available a ON a.calc_id = vCalcFk AND a.item_id = r.itemFk
SET r.amount = 0
WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < NOW()
AND a.available <= 0
AND r.shipment BETWEEN CURDATE() AND util.dayEnd(CURDATE())
AND NOT o.confirmed
AND r.warehouseFk = vWarehouseFk;
END$$
DELIMITER ;