From 03ea7580d8d3474a2b4d8aa40cffabdf45ebcc27 Mon Sep 17 00:00:00 2001 From: Pako Date: Tue, 1 Oct 2024 15:02:24 +0200 Subject: [PATCH] feat: refs #8069 new proc --- .../orderRow_updateOverstocking.sql | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/db/routines/hedera/procedures/orderRow_updateOverstocking.sql b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql index e69de29bb..21cdb07ac 100644 --- a/db/routines/hedera/procedures/orderRow_updateOverstocking.sql +++ b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql @@ -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 ; \ No newline at end of file