feat: refs #6769 itemDiary #2683

Merged
guillermo merged 10 commits from 6769-itemDiary into dev 2024-07-12 08:13:29 +00:00
1 changed files with 1 additions and 34 deletions
Showing only changes of commit dab386326f - Show all commits

View File

@ -33,35 +33,6 @@ BEGIN
CALL util.throw('Config variables are not set');
END IF;
-- Calcula el ultimo dia de vida para cada producto
-- Tiene tmp a propósito, porque si no falla al utilizarlo en el WITH
CREATE OR REPLACE TEMPORARY TABLE tmp.itemRange
(PRIMARY KEY (itemFk))
ENGINE = MEMORY
SELECT i.id itemFk,
util.dayEnd(c.maxLanded + INTERVAL it.life DAY) ended,
it.life
FROM item i
LEFT JOIN (
SELECT b.itemFk, MAX(t.landed) maxLanded
FROM buy b
JOIN entry e ON b.entryFk = e.id
JOIN travel t ON t.id = e.travelFk
JOIN warehouse w ON w.id = t.warehouseInFk
JOIN item i ON i.id = b.itemFk
JOIN itemType it ON it.id = i.typeFk
WHERE t.landed BETWEEN vLifeScope AND vDateInventory
AND t.warehouseInFk = vWarehouseFk
AND t.warehouseOutFk <> vWarehouseInventoryFk
AND it.life
AND i.id = vItemFk
AND NOT e.isExcludedFromAvailable
GROUP BY b.itemFk
) c ON i.id = c.itemFk
JOIN itemType it ON it.id = i.typeFk
WHERE i.id = vItemFk
HAVING ended >= vDateInventory OR life IS NULL;
CREATE OR REPLACE TEMPORARY TABLE tItemDiary
ENGINE = MEMORY
WITH entriesIn AS (
@ -210,10 +181,8 @@ BEGIN
NULL
FROM hedera.orderRow r
JOIN hedera.`order` o ON o.id = r.orderFk
JOIN tmp.itemRange ir ON ir.itemFk = r.itemFk
JOIN vn.client c ON c.id = o.customer_id
WHERE r.shipment >= vDateInventory
AND (ir.ended IS NULL OR r.shipment <= ir.ended)
AND r.warehouseFk = vWarehouseFk
AND r.created >= (
SELECT SUBTIME(util.VN_NOW(), reserveTime)
@ -315,8 +284,6 @@ BEGIN
WHERE shipped >= vDated;
END IF;
DROP TEMPORARY TABLE
tItemDiary,
tmp.itemRange;
DROP TEMPORARY TABLE tItemDiary;
END$$
DELIMITER ;