2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_getLack`(IN vForce BOOLEAN, IN vDays INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Calcula una tabla con el máximo negativo visible para cada producto y almacen
|
|
|
|
*
|
|
|
|
* @param vForce Fuerza el recalculo del stock
|
|
|
|
* @param vDays Numero de dias a considerar
|
|
|
|
**/
|
|
|
|
|
|
|
|
CALL `cache`.stock_refresh(vForce);
|
|
|
|
CALL item_getMinacum(NULL, util.VN_CURDATE(), vDays, NULL);
|
|
|
|
CALL item_getMinETD();
|
|
|
|
CALL item_zoneClosure();
|
|
|
|
|
|
|
|
SELECT i.id itemFk,
|
|
|
|
i.longName,
|
|
|
|
w.id warehouseFk,
|
|
|
|
p.`name` producer,
|
|
|
|
i.`size`,
|
|
|
|
i.category,
|
|
|
|
w.name warehouse,
|
|
|
|
SUM(IFNULL(sub.amount,0)) lack,
|
|
|
|
i.inkFk,
|
|
|
|
IFNULL(im.timed, util.midnight()) timed,
|
2024-02-09 08:22:24 +00:00
|
|
|
IFNULL(izc.timed, util.midnight()) minTimed,
|
|
|
|
o.name originFk
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM (SELECT item_id,
|
|
|
|
warehouse_id,
|
|
|
|
amount
|
|
|
|
FROM cache.stock
|
|
|
|
WHERE amount > 0
|
|
|
|
UNION ALL
|
|
|
|
SELECT itemFk,
|
|
|
|
warehouseFk,
|
|
|
|
amount
|
|
|
|
FROM tmp.itemMinacum
|
|
|
|
) sub
|
|
|
|
JOIN warehouse w ON w.id = sub.warehouse_id
|
|
|
|
JOIN item i ON i.id = sub.item_id
|
|
|
|
LEFT JOIN producer p ON p.id = i.producerFk
|
|
|
|
JOIN itemType it ON it.id = i.typeFk
|
|
|
|
JOIN itemCategory ic ON ic.id = it.categoryFk
|
|
|
|
LEFT JOIN tmp.itemMinETD im ON im.itemFk = i.id
|
|
|
|
LEFT JOIN tmp.itemZoneClosure izc ON izc.itemFk = i.id
|
2024-02-09 08:22:24 +00:00
|
|
|
JOIN origin o ON o.id = i.originFk
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE w.isForTicket
|
|
|
|
AND ic.display
|
|
|
|
AND it.code != 'GEN'
|
|
|
|
GROUP BY i.id, w.id
|
|
|
|
HAVING lack < 0;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.itemMinacum;
|
|
|
|
DROP TEMPORARY TABLE tmp.itemMinETD;
|
|
|
|
DROP TEMPORARY TABLE tmp.itemZoneClosure;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|