2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`itemShelvingProblem`(vSectorFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
DECLARE vVisibleCache INT;
|
|
|
|
DECLARE vWarehouseFk INT;
|
|
|
|
|
|
|
|
SELECT warehouseFk INTO vWarehouseFk
|
|
|
|
FROM vn.sector
|
|
|
|
WHERE id = vSectorFk;
|
|
|
|
|
|
|
|
CALL cache.visible_refresh (vVisibleCache, FALSE, vWarehouseFk);
|
|
|
|
|
|
|
|
SELECT t.id as ticketFk,
|
|
|
|
CAST(s.quantity AS DECIMAL(10,0)) as Cantidad,
|
|
|
|
s.itemFk,
|
|
|
|
s.concept,
|
|
|
|
v.visible - GREATEST(0,iss.visible) + IFNULL(sub3.transit,0) as Nicho,
|
|
|
|
i.subName,
|
|
|
|
GREATEST(0,iss.visible - IFNULL(sub3.transit,0)) as Altillo,
|
|
|
|
s.id as saleFk,
|
|
|
|
IFNULL(sub3.transit,0) transit,
|
2024-04-24 07:53:31 +00:00
|
|
|
v.visible, s.isPicked, s.reserved, t.shipped, tst.productionOrder, st.saleFk
|
|
|
|
FROM ticket t
|
|
|
|
JOIN ticketState tst ON tst.ticketFk = t.id
|
|
|
|
JOIN sale s ON s.ticketFk = t.id
|
|
|
|
JOIN item i ON i.id = s.itemFk
|
2024-01-15 11:31:03 +00:00
|
|
|
JOIN cache.visible v ON s.itemFk = v.item_id AND v.calc_id = vVisibleCache
|
2024-04-24 07:53:31 +00:00
|
|
|
LEFT JOIN saleTracking st ON st.saleFk = s.id AND st.stateFk = 26
|
|
|
|
JOIN itemShelvingStock iss ON iss.itemFk = v.item_id
|
2024-01-15 11:31:03 +00:00
|
|
|
LEFT JOIN
|
|
|
|
(SELECT itemFk, sum(saldo) as transit
|
2024-04-24 07:53:31 +00:00
|
|
|
FROM itemPlacementSupplyList
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE saldo > 0
|
|
|
|
AND sectorFk = vSectorFk
|
|
|
|
GROUP BY itemFk) sub3 ON sub3.itemFk = i.id
|
|
|
|
WHERE v.visible + IFNULL(sub3.transit,0) - GREATEST(0,iss.visible) < s.quantity
|
|
|
|
AND IFNULL(sub3.transit,0) < s.quantity
|
|
|
|
AND s.isPicked = FALSE
|
|
|
|
AND s.reserved = FALSE
|
|
|
|
AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE())
|
|
|
|
AND tst.isPreviousPreparable = TRUE
|
|
|
|
AND t.warehouseFk = vWarehouseFk
|
|
|
|
AND iss.sectorFk = vSectorFk
|
2024-04-24 07:53:31 +00:00
|
|
|
AND st.saleFk IS NULL
|
2024-01-15 11:31:03 +00:00
|
|
|
ORDER BY itemFk;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|