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,
|
2024-11-13 08:03:44 +00:00
|
|
|
vShelvingCode VARCHAR(10)
|
2024-05-17 10:48:16 +00:00
|
|
|
)
|
2024-05-15 15:03:33 +00:00
|
|
|
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
|
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) +
|
2024-11-13 08:03:44 +00:00
|
|
|
IFNULL(freightValue, 0) +
|
|
|
|
IFNULL(comissionValue, 0) +
|
|
|
|
IFNULL(packageValue, 0) itemCost
|
|
|
|
FROM vn.buy b
|
2024-05-17 10:48:16 +00:00
|
|
|
WHERE b.id = vBuyFk
|
|
|
|
) SELECT v.itemFk,
|
2024-11-13 08:03:44 +00:00
|
|
|
vShelvingCode,
|
2024-05-17 10:48:16 +00:00
|
|
|
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
|
2024-05-17 10:48:16 +00:00
|
|
|
JOIN visible v
|
2024-11-13 08:03:44 +00:00
|
|
|
WHERE sh.code = vShelvingCode COLLATE utf8mb3_general_ci
|
|
|
|
AND ish.itemFk = v.itemFk;
|
2024-05-15 15:03:33 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|