diff --git a/db/routines/vn/procedures/clearShelvingList.sql b/db/routines/vn/procedures/clearShelvingList.sql deleted file mode 100644 index 1ba726e85..000000000 --- a/db/routines/vn/procedures/clearShelvingList.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`clearShelvingList`(vShelvingFk VARCHAR(8)) -BEGIN - UPDATE vn.itemShelving - SET visible = 0 - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk COLLATE utf8_unicode_ci; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingMakeFromDate.sql b/db/routines/vn/procedures/itemShelvingMakeFromDate.sql deleted file mode 100644 index 4918d55e1..000000000 --- a/db/routines/vn/procedures/itemShelvingMakeFromDate.sql +++ /dev/null @@ -1,58 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, `vCreated` VARCHAR(22)) -BEGIN - - DECLARE vItemFk INT; - - SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - - SELECT itemFk INTO vItemFk - FROM vn.buy b - WHERE b.id = vItemFk; - - IF (SELECT COUNT(*) FROM vn.shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN - - INSERT IGNORE INTO vn.parking(`code`) VALUES(vShelvingFk); - INSERT INTO vn.shelving(`code`, parkingFk) - SELECT vShelvingFk, id - FROM vn.parking - WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; - - END IF; - - IF (SELECT COUNT(*) FROM vn.itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking) = 1 THEN - - UPDATE vn.itemShelving - SET visible = visible+vQuantity, - created = vCreated - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking; - - ELSE - CALL cache.last_buy_refresh(FALSE); - INSERT INTO itemShelving( itemFk, - shelvingFk, - visible, - created, - `grouping`, - packing, - packagingFk) - SELECT vItemFk, - vShelvingFk, - vQuantity, - vCreated, - IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) `grouping`, - IF(vPacking = 0, b.packing, vPacking) packing, - IF(vPackagingFk = '', b.packagingFk, vPackagingFk) packaging - FROM vn.item i - LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id - WHERE i.id = vItemFk; - END IF; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql b/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql deleted file mode 100644 index 085a3fe4b..000000000 --- a/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql +++ /dev/null @@ -1,20 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingPlacementSupplyAdd`(vItemShelvingFk INT, vItemPlacementSupplyFk INT, vQuantity INT) -BEGIN - - INSERT INTO vn.itemShelvingPlacementSupply( itemShelvingFk, - itemPlacementSupplyFk, - quantity, - userFk) - VALUES (vItemShelvingFk, - vItemPlacementSupplyFk, - vQuantity, - getUser()); - - UPDATE vn.itemShelving - SET visible = visible - vQuantity - WHERE id = vItemShelvingFk; - - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_Add.sql b/db/routines/vn/procedures/itemShelvingSale_Add.sql index 05b6b9d45..c00f25150 100644 --- a/db/routines/vn/procedures/itemShelvingSale_Add.sql +++ b/db/routines/vn/procedures/itemShelvingSale_Add.sql @@ -18,7 +18,8 @@ BEGIN getUser()); UPDATE itemShelving - SET visible = visible - vQuantity + SET visible = visible - vQuantity, + available = available - vQuantity WHERE id = vItemShelvingFk; UPDATE vn.saleTracking diff --git a/db/routines/vn/procedures/itemShelving_selfConsumption.sql b/db/routines/vn/procedures/itemShelving_selfConsumption.sql index 25ff2363c..083d8d74c 100644 --- a/db/routines/vn/procedures/itemShelving_selfConsumption.sql +++ b/db/routines/vn/procedures/itemShelving_selfConsumption.sql @@ -6,12 +6,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_selfCons ) BEGIN /** - * Leave the indicated amount on the shelf + * Leave the indicated amount on the shelve * and create a ticket with the difference. * - * @param vShelvingFk id of the shelf where the item is located. + * @param vShelvingFk id of the shelve where the item is located. * @param vItemFk article of which the self-consumption ticket is to be created. - * @param vQuantity amount that will stay on the shelf + * @param vQuantity amount that will stay on the shelve */ DECLARE vVisible INT; DECLARE vClientFk INT; @@ -80,7 +80,8 @@ BEGIN WHERE id = vItemFk; UPDATE itemShelving - SET visible = IF(id = vItemShelvingFk, vQuantity, 0) + SET visible = IF(id = vItemShelvingFk, vQuantity, 0), + available = IF(id = vItemShelvingFk, vQuantity, 0) WHERE shelvingFk = vShelvingFk AND itemFk = vItemFk; diff --git a/db/routines/vn/procedures/itemShelving_transfer.sql b/db/routines/vn/procedures/itemShelving_transfer.sql index 3597da7e1..95d70227f 100644 --- a/db/routines/vn/procedures/itemShelving_transfer.sql +++ b/db/routines/vn/procedures/itemShelving_transfer.sql @@ -31,7 +31,8 @@ BEGIN IF vNewItemShelvingFk THEN UPDATE itemShelving ish JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk - SET ish.visible = ish.visible + ish2.visible + SET ish.visible = ish.visible + ish2.visible, + ish.available = ish.available + ish2.available WHERE ish.id = vNewItemShelvingFk; DELETE FROM itemShelving diff --git a/db/routines/vn/procedures/item_devalueA2.sql b/db/routines/vn/procedures/item_devalueA2.sql index 44ae306ec..d0178f6a7 100644 --- a/db/routines/vn/procedures/item_devalueA2.sql +++ b/db/routines/vn/procedures/item_devalueA2.sql @@ -303,7 +303,8 @@ BEGIN WHERE id = vTargetItemShelvingFk; ELSE UPDATE itemShelving - SET visible = vCurrentVisible - vQuantity + SET visible = vCurrentVisible - vQuantity, + available = GREATEST(0, available - vQuantity) WHERE id = vTargetItemShelvingFk; END IF;