fix: refs #7505 visible_refresh support warehouse null and added isComparative
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-07-23 13:59:36 +02:00
parent 88724d6d8c
commit 5d2e9c6210
2 changed files with 24 additions and 17 deletions

View File

@ -20,9 +20,10 @@ proc:BEGIN
CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible
(PRIMARY KEY (item_id))
ENGINE = MEMORY
SELECT item_id, amount stock, amount visible
SELECT item_id, SUM(amount) stock, SUM(amount) visible
FROM cache.stock
WHERE (warehouse_id IS NULL OR warehouse_id = v_warehouse);
WHERE (v_warehouse IS NULL OR warehouse_id = v_warehouse)
GROUP BY item_id;
-- Calculamos los movimientos confirmados de hoy
CALL vn.item_calcVisible(NULL, v_warehouse);

View File

@ -21,6 +21,8 @@ BEGIN
FROM itemTicketOut i
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
@ -28,26 +30,30 @@ BEGIN
WHERE st.created > vDated
AND (s.isPicked OR st.isChecked)
) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
WHERE IFNULL(vWarehouseFk, i.warehouseFk) = i.warehouseFk
WHERE (vWarehouseFk IS NULL OR i.warehouseFk = vWarehouseFk)
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
UNION ALL
SELECT itemFk, quantity
FROM itemEntryIn
WHERE isReceived
AND landed >= vDated AND landed < vTomorrow
AND IFNULL(vWarehouseFk, warehouseInFk) = warehouseInFk
AND (vSelf IS NULL OR itemFk = vSelf)
AND NOT isVirtualStock
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
UNION ALL
SELECT itemFk, quantity
FROM itemEntryOut
WHERE isDelivered
AND shipped >= vDated
AND shipped < vTomorrow
AND IFNULL(vWarehouseFk, warehouseOutFk) = warehouseOutFk
AND (vSelf IS NULL OR itemFk = vSelf)
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)
) t
GROUP BY itemFk
ON DUPLICATE KEY UPDATE