From a9aa47fef1aa194145cbe93260a2618ec365702b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 23 Jul 2024 14:17:01 +0200 Subject: [PATCH] fix: refs #7505 visible_refresh support warehouse null and added isComparative --- db/routines/cache/procedures/visible_refresh.sql | 10 ++++++---- db/routines/vn/procedures/item_calcVisible.sql | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 053da1d14..d7c5c3738 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -20,10 +20,12 @@ proc:BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, SUM(amount) stock, SUM(amount) visible - FROM cache.stock - WHERE (v_warehouse IS NULL OR warehouse_id = v_warehouse) - GROUP BY item_id; + SELECT s.item_id, SUM(s.amount) stock, SUM(s.amount) visible + FROM cache.stock s + JOIN warehouse w ON w.id = s.warehouse_id + WHERE (v_warehouse IS NULL OR s.warehouse_id = v_warehouse) + AND w.isComparative + GROUP BY s.item_id; -- Calculamos los movimientos confirmados de hoy CALL vn.item_calcVisible(NULL, v_warehouse); diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index 2ce663d80..32adfdfa3 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -22,7 +22,6 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk JOIN `state` s ON s.id = ts.stateFk JOIN warehouse w ON w.id = i.warehouseFk - AND w.isComparative LEFT JOIN ( SELECT DISTINCT st.saleFk FROM saleTracking st @@ -34,26 +33,27 @@ BEGIN AND (vSelf IS NULL OR i.itemFk = vSelf) AND (s.isPicked OR i.reserved OR stPrevious.saleFk) AND i.shipped >= vDated AND i.shipped < vTomorrow + AND w.isComparative UNION ALL SELECT iei.itemFk, iei.quantity FROM itemEntryIn iei JOIN warehouse w ON w.id = iei.warehouseInFk - AND w.isComparative WHERE iei.isReceived AND iei.landed >= vDated AND iei.landed < vTomorrow AND (vWarehouseFk IS NULL OR iei.warehouseInFk = vWarehouseFk) AND (vSelf IS NULL OR iei.itemFk = vSelf) AND NOT iei.isVirtualStock + AND w.isComparative UNION ALL SELECT ieo.itemFk, ieo.quantity FROM itemEntryOut ieo JOIN warehouse w ON w.id = ieo.warehouseOutFk - AND w.isComparative WHERE ieo.isDelivered AND ieo.shipped >= vDated AND ieo.shipped < vTomorrow AND (vWarehouseFk IS NULL OR ieo.warehouseOutFk = vWarehouseFk) AND (vSelf IS NULL OR ieo.itemFk = vSelf) + AND w.isComparative ) t GROUP BY itemFk ON DUPLICATE KEY UPDATE