2024-10-07 12:21:18 +00:00
|
|
|
DELIMITER $$
|
2024-10-08 10:19:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
2024-10-07 12:21:18 +00:00
|
|
|
PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT)
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Set amount = 0 to avoid overbooking sales
|
2024-10-08 10:19:10 +00:00
|
|
|
*
|
2024-10-07 12:21:18 +00:00
|
|
|
* @param vOrderFk hedera.order.id
|
|
|
|
*/
|
|
|
|
DECLARE vCalcFk INT;
|
|
|
|
DECLARE vDone BOOL;
|
|
|
|
DECLARE vWarehouseFk INT;
|
|
|
|
|
|
|
|
DECLARE cWarehouses CURSOR FOR
|
|
|
|
SELECT DISTINCT warehouseFk
|
|
|
|
FROM orderRow
|
|
|
|
WHERE orderFk = vOrderFk
|
|
|
|
AND shipment = util.VN_CURDATE();
|
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
|
|
|
|
|
|
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
|
|
|
BEGIN
|
|
|
|
ROLLBACK;
|
|
|
|
RESIGNAL;
|
|
|
|
END;
|
|
|
|
|
|
|
|
OPEN cWarehouses;
|
|
|
|
checking: LOOP
|
|
|
|
SET vDone = FALSE;
|
|
|
|
|
|
|
|
FETCH cWarehouses INTO vWarehouseFk;
|
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE checking;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, util.VN_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) < util.VN_NOW()
|
|
|
|
AND a.available <= 0
|
|
|
|
AND r.warehouseFk = vWarehouseFk
|
|
|
|
AND r.orderFk = vOrderFk;
|
|
|
|
END LOOP;
|
|
|
|
CLOSE cWarehouses;
|
|
|
|
END$$
|
2024-10-08 10:19:10 +00:00
|
|
|
DELIMITER ;
|