diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index 15be8c926..6488676d1 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -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 ;