feat: refs #8069 orderRow_updateOverstocking
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
03ea7580d8
commit
9d84c39fce
|
@ -1,26 +1,53 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `hedera`.`orderRow_updateOverstocking`(
|
||||
vWarehouseFk INT
|
||||
)
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
||||
PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Set amount = 0 to avoid overbooking sales
|
||||
*
|
||||
* @param vWarehouseFk vn.warehouse.id
|
||||
* @param vOrderFk hedera.order.id
|
||||
*/
|
||||
DECLARE vCalcFk INT;
|
||||
DECLARE vDated DATE;
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vWarehouseFk INT;
|
||||
|
||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, CURDATE());
|
||||
DECLARE cWarehouses CURSOR FOR
|
||||
SELECT DISTINCT warehouseFk, shipment
|
||||
FROM orderRow r
|
||||
WHERE r.orderFk = vOrderFk;
|
||||
|
||||
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;
|
||||
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, vDated;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE checking;
|
||||
END IF;
|
||||
|
||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated);
|
||||
|
||||
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 LOOP;
|
||||
CLOSE cWarehouses;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -101,6 +101,8 @@ BEGIN
|
|||
|
||||
CALL order_checkEditable(vSelf);
|
||||
|
||||
CALL orderRow_updateOverstocking(vSelf);
|
||||
|
||||
-- Check order is not empty
|
||||
SELECT COUNT(*) > 0 INTO vHasRows
|
||||
FROM orderRow
|
||||
|
|
Loading…
Reference in New Issue