diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index aa50f0ed8..6625e89b8 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -48,6 +48,13 @@ proc: BEGIN RESIGNAL; END; + START TRANSACTION; + + SELECT id INTO vSaleFk + FROM sale + WHERE id = vSaleFk + FOR UPDATE; + SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity INTO vLastPickingOrder, vOutStanding, vSaleQuantity FROM sale s @@ -57,7 +64,8 @@ proc: BEGIN LEFT JOIN parking p ON p.id = sh.parkingFk WHERE s.id = vSaleFk; - IF vOutStanding <= 0 THEN + IF vOutStanding <= 0 THEN + COMMIT; LEAVE proc; END IF; @@ -84,10 +92,8 @@ proc: BEGIN END IF; LEAVE l; END IF; - - START TRANSACTION; - - SELECT id INTO vItemShelvingFk + + SELECT id INTO vItemShelvingFk FROM itemShelving WHERE id = vItemShelvingFk FOR UPDATE; @@ -115,9 +121,8 @@ proc: BEGIN WHERE id = vItemShelvingFk; END IF; - - COMMIT; END LOOP; CLOSE vItemShelvingAvailable; + COMMIT; END$$ DELIMITER ; \ No newline at end of file