From 9b73cdfa6ffe0edfa39a228b0e9d40fc241a868b Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 15 May 2024 17:03:33 +0200 Subject: [PATCH] refs #4979 feat:getInfoDetails && item_devalueA2 --- .../itemShelving_getItemDetails.sql | 90 +++++++++++++++++++ db/routines/vn/procedures/item_devalueA2.sql | 14 ++- 2 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 db/routines/vn/procedures/itemShelving_getItemDetails.sql diff --git a/db/routines/vn/procedures/itemShelving_getItemDetails.sql b/db/routines/vn/procedures/itemShelving_getItemDetails.sql new file mode 100644 index 000000000..2134f00c4 --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_getItemDetails.sql @@ -0,0 +1,90 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_getItemDetails`(vBarcodeItem INT, vShelvingFK VARCHAR(10) ) +BEGIN + +/** + * Obtiene el precio y visible de un item + * + * @param vBarcodeItem barcode de artículo + * @param vBarcodeItem Ubicación actual del artículo + */ + DECLARE vIsItem BOOL; + DECLARE vItemFk INT; + DECLARE vItemCost DECIMAL(10,4); + DECLARE vCacheVisibleFk INT; + DECLARE vWarehouseFk INT; + DECLARE vVisible INT; + + + SELECT COUNT(*)>0 INTO vIsItem + FROM vn.item + WHERE id = vBarcodeItem; + + IF NOT vIsItem THEN + + SELECT IFNULL(b.buyingValue, 0) + + IFNULL(b.freightValue, 0) + + IFNULL(b.comissionValue, 0) + + IFNULL(b.packageValue, 0), + SUM(is2.visible) , + b.itemFk + INTO vItemCost, vVisible, vItemFk + FROM itemShelving is2 + JOIN buy b ON b.itemFk = is2.itemFk AND b.id = vBarcodeItem + WHERE is2.shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci + GROUP BY shelvingFK; + + SELECT vItemFk itemFk, + vShelvingFK shelvingFk, + vItemCost itemCost, + vVisible quantity; + + END IF; + + IF vItemCost IS NULL THEN + + SELECT warehouseFk INTO vWarehouseFk + FROM operator + WHERE workerFk = account.myUser_getId(); + + SELECT barcodeToItem(vBarcodeItem) INTO vItemFk; + + IF vItemFk IS NULL THEN + CALL util.throw ('Item not valid'); + ELSE + CALL buyUltimate(vWarehouseFk, util.VN_CURDATE()); + + SELECT IFNULL(b.buyingValue, 0) + + IFNULL(b.freightValue, 0) + + IFNULL(b.comissionValue, 0) + + IFNULL(b.packageValue, 0) itemCost, + SUM(is2.visible) visible, + is2.itemFk + INTO vItemCost, vVisible, vItemFk + FROM itemShelving is2 + JOIN tmp.buyUltimate bu ON bu.itemFk = is2.itemFk + JOIN buy b ON b.id = bu.buyFk + WHERE is2.itemFk = vBarcodeItem AND + is2.shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci; + + IF vItemFk IS NULL THEN + CALL util.throw ('Item not valid'); + ELSE + SELECT vItemFk itemFk, + vShelvingFK shelvingFk, + vItemCost itemCost, + vVisible quantity; + END IF; + + DELETE FROM tmp.buyUltimate; + + END IF; + + END IF; + + IF vItemCost IS NULL THEN + CALL util.throw ('Item not valid'); + END IF; + +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/item_devalueA2.sql b/db/routines/vn/procedures/item_devalueA2.sql index 276c5b508..f331c7230 100644 --- a/db/routines/vn/procedures/item_devalueA2.sql +++ b/db/routines/vn/procedures/item_devalueA2.sql @@ -14,6 +14,7 @@ BEGIN * @param vSelf Id de artículo a devaluar * @param vShelvingFK Ubicación actual del artículo * @param vBuyingValue Nuevo precio de coste + * @param vQuantity Cantidad del ítem a pasar a A2 */ DECLARE vItemA2Fk INT; DECLARE vLastBuyFk BIGINT; @@ -28,6 +29,7 @@ BEGIN DECLARE vCurrentVisible INT; DECLARE vDevalueTravelFk INT; DECLARE vCurdate DATE; + DECLARE vBuyingValueOriginal DECIMAL(10,4); DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN @@ -86,19 +88,23 @@ BEGIN SELECT id, DATE(dated) INTO vTargetEntryFk, vTargetEntryDate FROM `entry` e WHERE DATE(dated) = vCurdate - AND typeFk ='devaluation' + AND typeFk = 'devaluation' AND travelFk = vDevalueTravelFk ORDER BY created DESC LIMIT 1; CALL buyUltimate(vWarehouseFk, vCurdate); - SELECT b.entryFk, bu.buyFk INTO vLastEntryFk,vLastBuyFk + SELECT b.entryFk, bu.buyFk,IFNULL(b.buyingValue, 0) INTO vLastEntryFk, vLastBuyFk, vBuyingValueOriginal FROM tmp.buyUltimate bu - JOIN vn.buy b ON b.id =bu.buyFk + JOIN vn.buy b ON b.id = bu.buyFk WHERE bu.itemFk = vSelf AND bu.warehouseFk = vWarehouseFk; - + + IF vBuyingValue > vBuyingValueOriginal THEN + CALL util.throw ('Price not valid'); + END IF; + IF vLastEntryFk IS NULL OR vLastBuyFk IS NULL THEN CALL util.throw ('The item has not a buy'); END IF;