salix/db/routines/vn/procedures/itemShelving_getItemDetails...

56 lines
1.3 KiB
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_getItemDetails`(
vBarcodeItem INT,
2024-11-13 08:03:44 +00:00
vShelvingCode VARCHAR(10)
)
BEGIN
/**
* Obtiene el precio y visible de un item
*
* @param vBarcodeItem barcode de artículo
2024-11-13 08:03:44 +00:00
* @param vShelvingCode Ubicación actual del artículo
*/
DECLARE vIsItem BOOL;
DECLARE vBuyFk INT;
DECLARE vWarehouseFk INT;
SELECT COUNT(*) > 0 INTO vIsItem
FROM item
WHERE id = vBarcodeItem;
IF vIsItem THEN
SELECT warehouseFk INTO vWarehouseFk
FROM operator
WHERE workerFk = account.myUser_getId();
2024-07-16 16:44:24 +00:00
CALL buy_getUltimate(vBarcodeItem, vWarehouseFk, util.VN_CURDATE());
SELECT buyFk INTO vBuyFk
FROM tmp.buyUltimate
WHERE itemFk = vBarcodeItem
AND warehouseFk = vWarehouseFk;
DELETE FROM tmp.buyUltimate;
ELSE
SELECT vBarcodeItem INTO vBuyFk;
END IF;
WITH visible AS(
SELECT itemFk,
IFNULL(buyingValue, 0) +
2024-11-13 08:03:44 +00:00
IFNULL(freightValue, 0) +
IFNULL(comissionValue, 0) +
IFNULL(packageValue, 0) itemCost
FROM vn.buy b
WHERE b.id = vBuyFk
) SELECT v.itemFk,
2024-11-13 08:03:44 +00:00
vShelvingCode,
v.itemCost,
SUM(ish.visible) visible
FROM vn.itemShelving ish
2024-11-13 08:03:44 +00:00
JOIN vn.shelving sh ON sh.id = ish.shelvingFK
JOIN visible v
2024-11-13 08:03:44 +00:00
WHERE sh.code = vShelvingCode COLLATE utf8mb3_general_ci
AND ish.itemFk = v.itemFk;
END$$
DELIMITER ;