2024-05-15 15:03:33 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_getItemDetails`(
|
2024-05-17 10:48:16 +00:00
|
|
|
vBarcodeItem INT,
|
|
|
|
vShelvingFK VARCHAR(10)
|
|
|
|
)
|
2024-05-15 15:03:33 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Obtiene el precio y visible de un item
|
|
|
|
*
|
|
|
|
* @param vBarcodeItem barcode de artículo
|
2024-05-17 09:20:26 +00:00
|
|
|
* @param vShelvingFK Ubicación actual del artículo
|
2024-05-15 15:03:33 +00:00
|
|
|
*/
|
|
|
|
DECLARE vIsItem BOOL;
|
2024-05-17 10:48:16 +00:00
|
|
|
DECLARE vBuyFk INT;
|
2024-05-15 15:03:33 +00:00
|
|
|
DECLARE vWarehouseFk INT;
|
|
|
|
|
2024-05-17 10:48:16 +00:00
|
|
|
SELECT COUNT(*) > 0 INTO vIsItem
|
|
|
|
FROM item
|
2024-05-15 15:03:33 +00:00
|
|
|
WHERE id = vBarcodeItem;
|
|
|
|
|
2024-05-17 10:48:16 +00:00
|
|
|
IF vIsItem THEN
|
2024-05-15 15:03:33 +00:00
|
|
|
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());
|
2024-05-15 15:03:33 +00:00
|
|
|
|
2024-05-17 10:48:16 +00:00
|
|
|
SELECT buyFk INTO vBuyFk
|
|
|
|
FROM tmp.buyUltimate
|
|
|
|
WHERE itemFk = vBarcodeItem
|
|
|
|
AND warehouseFk = vWarehouseFk;
|
2024-05-15 15:03:33 +00:00
|
|
|
|
2024-05-17 10:48:16 +00:00
|
|
|
DELETE FROM tmp.buyUltimate;
|
|
|
|
ELSE
|
|
|
|
SELECT vBarcodeItem INTO vBuyFk;
|
2024-05-15 15:03:33 +00:00
|
|
|
END IF;
|
2024-05-17 10:48:16 +00:00
|
|
|
|
|
|
|
WITH visible AS(
|
|
|
|
SELECT itemFk,
|
|
|
|
IFNULL(buyingValue, 0) +
|
|
|
|
IFNULL(freightValue, 0) +
|
|
|
|
IFNULL(comissionValue, 0) +
|
|
|
|
IFNULL(packageValue, 0) itemCost
|
|
|
|
FROM vn.buy b
|
|
|
|
WHERE b.id = vBuyFk
|
|
|
|
) SELECT v.itemFk,
|
|
|
|
vShelvingFK,
|
|
|
|
v.itemCost,
|
|
|
|
SUM(ish.visible) visible
|
|
|
|
FROM vn.itemShelving ish
|
|
|
|
JOIN visible v
|
2024-05-17 14:38:11 +00:00
|
|
|
WHERE ish.shelvingFK = vShelvingFK COLLATE utf8mb3_general_ci
|
2024-05-17 10:48:16 +00:00
|
|
|
AND ish.itemFk = v.itemFk;
|
2024-05-15 15:03:33 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|