diff --git a/db/routines/hedera/procedures/orderRow_updateOverstocking.sql b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql index 4bd1bb981..ff8362c65 100644 --- a/db/routines/hedera/procedures/orderRow_updateOverstocking.sql +++ b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql @@ -8,14 +8,14 @@ BEGIN * @param vOrderFk hedera.order.id */ DECLARE vCalcFk INT; - DECLARE vDated DATE; DECLARE vDone BOOL; DECLARE vWarehouseFk INT; DECLARE cWarehouses CURSOR FOR - SELECT DISTINCT warehouseFk, shipment - FROM orderRow r - WHERE r.orderFk = vOrderFk; + SELECT DISTINCT warehouseFk + FROM orderRow + WHERE orderFk = vOrderFk + AND shipped = util.VN_CURDATE(); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -29,24 +29,23 @@ BEGIN checking: LOOP SET vDone = FALSE; - FETCH cWarehouses INTO vWarehouseFk, vDated; + FETCH cWarehouses INTO vWarehouseFk; IF vDone THEN LEAVE checking; END IF; - CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated); + 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 + 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() + WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < util.VN_NOW() AND a.available <= 0 - AND r.shipment BETWEEN CURDATE() AND util.dayEnd(CURDATE()) - AND NOT o.confirmed - AND r.warehouseFk = vWarehouseFk; + AND r.warehouseFk = vWarehouseFk + AND r.orderFk = vOrderFk; END LOOP; CLOSE cWarehouses; END$$ diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 17adc74dd..b3aab522e 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -12,6 +12,7 @@ BEGIN * @param vUser The user identifier */ DECLARE vHasRows BOOL; + DECLARE vHas0Amount BOOL; DECLARE vDone BOOL; DECLARE vWarehouseFk INT; DECLARE vShipment DATE; @@ -113,6 +114,18 @@ BEGIN CALL util.throw('ORDER_EMPTY'); END IF; + -- Check if any product has a quantity of 0 + SELECT EXISTS ( + SELECT id + FROM orderRow + WHERE orderFk = vSelf + AND amount = 0 + ) INTO vHas0Amount; + + IF vHas0Amount THEN + CALL util.throw('Remove lines with quantity = 0 before confirming'); + END IF; + -- Crea los tickets del pedido OPEN vDates; lDates: LOOP