Merge pull request 'feat: #6749 se mira la vida para buscar dias en el pasado' (!1978) from 6749-disponible-sin-dar-vida into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1978
Reviewed-by: Pako Natek <pako@verdnatura.es>
This commit is contained in:
Javi Gallego 2024-02-06 06:32:08 +00:00
commit ebf80a4eb9
1 changed files with 27 additions and 27 deletions

View File

@ -5,7 +5,8 @@ proc: BEGIN
DECLARE vReserveDate DATETIME; DECLARE vReserveDate DATETIME;
DECLARE vParams CHAR(100); DECLARE vParams CHAR(100);
DECLARE vInventoryDate DATE; DECLARE vInventoryDate DATE;
DECLARE vIsLogifloraDay BOOLEAN; DECLARE vLifeScope DATE;
DECLARE vWarehouseFkInventory INT;
DECLARE EXIT HANDLER FOR SQLEXCEPTION DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN BEGIN
@ -26,43 +27,42 @@ proc: BEGIN
LEAVE proc; LEAVE proc;
END IF; END IF;
-- Invoca al procedimiento que genera el stock virtual de Logiflora, si coincide con la peticion de refresco del disponible
IF vn.isLogifloraDay(vDated, vWarehouse) THEN
-- CALL edi.floramondo_offerRefresh;
SET vIsLogifloraDay = TRUE;
ELSE
SET vIsLogifloraDay = FALSE;
END IF;
-- Calcula algunos parámetros necesarios -- Calcula algunos parámetros necesarios
SET vStartDate = TIMESTAMP(vDated, '00:00:00'); SET vStartDate = TIMESTAMP(vDated, '00:00:00');
SELECT inventoried INTO vInventoryDate FROM vn.config; SELECT inventoried INTO vInventoryDate FROM vn.config;
SELECT DATE_SUB(vStartDate, INTERVAL MAX(life) DAY) INTO vLifeScope FROM vn.itemType;
SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vReserveDate SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vReserveDate
FROM hedera.orderConfig; FROM hedera.orderConfig;
SELECT w.id INTO vWarehouseFkInventory
FROM vn.warehouse w
WHERE w.code = 'inv';
-- Calcula el ultimo dia de vida para cada producto -- Calcula el ultimo dia de vida para cada producto
DROP TEMPORARY TABLE IF EXISTS itemRange; DROP TEMPORARY TABLE IF EXISTS itemRange;
CREATE TEMPORARY TABLE itemRange CREATE TEMPORARY TABLE itemRange
(PRIMARY KEY (itemFk)) (PRIMARY KEY (itemFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT c.itemFk, SELECT i.id itemFk,
IF(it.life IS NULL, util.dayEnd(DATE_ADD(c.maxLanded, INTERVAL it.life DAY)) ended, it.life
NULL, FROM vn.item i
TIMESTAMP(TIMESTAMPADD(DAY, it.life, c.landing), '23:59:59')) ended LEFT JOIN (
FROM ( SELECT b.itemFk, MAX(t.landed) maxLanded
SELECT b.itemFk, MAX(t.landed) landing FROM vn.buy b
FROM vn.buy b JOIN vn.entry e ON b.entryFk = e.id
JOIN vn.entry e ON b.entryFk = e.id JOIN vn.travel t ON t.id = e.travelFk
JOIN vn.travel t ON t.id = e.travelFk JOIN vn.warehouse w ON w.id = t.warehouseInFk
JOIN vn.warehouse w ON w.id = t.warehouseInFk JOIN vn.item i ON i.id = b.itemFk
WHERE t.landed BETWEEN vInventoryDate AND vStartDate JOIN vn.itemType it ON it.id = i.typeFk
AND t.warehouseInFk = vWarehouse WHERE t.landed BETWEEN vLifeScope AND vStartDate
AND NOT e.isExcludedFromAvailable AND t.warehouseInFk = vWarehouse
GROUP BY b.itemFk AND t.warehouseOutFk <> vWarehouseFkInventory
) c AND it.life
JOIN vn.item i ON i.id = c.itemFk AND NOT e.isExcludedFromAvailable
GROUP BY b.itemFk
) c ON i.id = c.itemFk
JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemType it ON it.id = i.typeFk
HAVING ended >= vStartDate OR ended IS NULL; HAVING ended >= vStartDate OR life IS NULL;
-- Calcula el ATP -- Calcula el ATP
DELETE FROM available WHERE calc_id = vCalc; DELETE FROM available WHERE calc_id = vCalc;
@ -86,7 +86,7 @@ proc: BEGIN
WHERE i.landed >= vStartDate WHERE i.landed >= vStartDate
AND (ir.ended IS NULL OR i.landed <= ir.ended) AND (ir.ended IS NULL OR i.landed <= ir.ended)
AND i.warehouseInFk = vWarehouse AND i.warehouseInFk = vWarehouse
AND (ISNULL(wf.entryFk) OR vIsLogifloraDay) AND ISNULL(wf.entryFk)
UNION ALL UNION ALL
SELECT i.itemFk, i.shipped, i.quantity SELECT i.itemFk, i.shipped, i.quantity
FROM vn.itemEntryOut i FROM vn.itemEntryOut i