55 lines
1.3 KiB
SQL
55 lines
1.3 KiB
SQL
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 vShelvingFK 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();
|
|
|
|
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) +
|
|
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
|
|
WHERE ish.shelvingFK = vShelvingFK COLLATE utf8mb3_general_ci
|
|
AND ish.itemFk = v.itemFk;
|
|
END$$
|
|
DELIMITER ; |