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