refactor: refs #7640 Refactor multipleInventory
This commit is contained in:
parent
0d1573973e
commit
8ac26c7281
|
@ -76,52 +76,52 @@ proc: BEGIN
|
||||||
GROUP BY itemFk;
|
GROUP BY itemFk;
|
||||||
|
|
||||||
-- Cálculo del visible
|
-- Cálculo del visible
|
||||||
UPDATE tItemInventoryCalc iic
|
CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
|
||||||
JOIN (
|
(PRIMARY KEY (itemFk))
|
||||||
SELECT itemFk, SUM(quantity) visible
|
ENGINE = MEMORY
|
||||||
FROM (
|
SELECT itemFk, SUM(quantity) visible
|
||||||
SELECT s.itemFk, s.quantity
|
FROM (
|
||||||
FROM sale s
|
SELECT s.itemFk, s.quantity
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
FROM sale s
|
||||||
JOIN warehouse w ON w.id = t.warehouseFk
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
WHERE t.shipped >= vDate
|
JOIN warehouse w ON w.id = t.warehouseFk
|
||||||
AND t.shipped < vDateTomorrow
|
WHERE t.shipped >= vDate
|
||||||
AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
|
AND t.shipped < vDateTomorrow
|
||||||
AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
|
AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
|
||||||
AND w.isComparative
|
AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
|
||||||
UNION ALL
|
AND w.isComparative
|
||||||
SELECT b.itemFk, - b.quantity
|
UNION ALL
|
||||||
FROM buy b
|
SELECT b.itemFk, - b.quantity
|
||||||
JOIN entry e ON e.id = b.entryFk
|
FROM buy b
|
||||||
JOIN travel t ON t.id = e.travelFk
|
JOIN entry e ON e.id = b.entryFk
|
||||||
JOIN warehouse w ON w.id = t.warehouseInFk
|
JOIN travel t ON t.id = e.travelFk
|
||||||
WHERE t.landed = vDate
|
JOIN warehouse w ON w.id = t.warehouseInFk
|
||||||
AND NOT t.isReceived
|
WHERE t.landed = vDate
|
||||||
AND NOT e.isExcludedFromAvailable
|
AND NOT t.isReceived
|
||||||
AND NOT e.isRaid
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
|
AND NOT e.isRaid
|
||||||
AND w.isComparative
|
AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
|
||||||
UNION ALL
|
AND w.isComparative
|
||||||
SELECT b.itemFk, b.quantity
|
UNION ALL
|
||||||
FROM buy b
|
SELECT b.itemFk, b.quantity
|
||||||
JOIN entry e ON e.id = b.entryFk
|
FROM buy b
|
||||||
JOIN travel t ON t.id = e.travelFk
|
JOIN entry e ON e.id = b.entryFk
|
||||||
JOIN warehouse w ON w.id = t.warehouseOutFk
|
JOIN travel t ON t.id = e.travelFk
|
||||||
WHERE t.shipped = vDate
|
JOIN warehouse w ON w.id = t.warehouseOutFk
|
||||||
AND NOT t.isReceived
|
WHERE t.shipped = vDate
|
||||||
AND NOT e.isExcludedFromAvailable
|
AND NOT t.isReceived
|
||||||
AND NOT e.isRaid
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
|
AND NOT e.isRaid
|
||||||
AND w.isComparative
|
AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
|
||||||
) sub2
|
AND w.isComparative
|
||||||
GROUP BY itemFk
|
) sub2
|
||||||
) sub ON sub.itemFk = iic.itemFk
|
GROUP BY itemFk;
|
||||||
SET iic.visible = iic.visible + sub.visible;
|
|
||||||
|
|
||||||
UPDATE tmp.itemInventory ai
|
UPDATE tmp.itemInventory ai
|
||||||
JOIN tItemInventoryCalc iic ON iic.itemFk = ai.id
|
JOIN tItemInventoryCalc iic ON iic.itemFk = ai.id
|
||||||
|
JOIN tItemVisibleCalc ivc ON ivc.itemFk = ai.id
|
||||||
SET ai.inventory = iic.quantity,
|
SET ai.inventory = iic.quantity,
|
||||||
ai.visible = iic.visible,
|
ai.visible = iic.quantity + ivc.visible,
|
||||||
ai.avalaible = iic.quantity,
|
ai.avalaible = iic.quantity,
|
||||||
ai.sd = iic.quantity;
|
ai.sd = iic.quantity;
|
||||||
|
|
||||||
|
@ -195,6 +195,7 @@ proc: BEGIN
|
||||||
tmp.itemTravel,
|
tmp.itemTravel,
|
||||||
tmp.itemCalc,
|
tmp.itemCalc,
|
||||||
tItemInventoryCalc,
|
tItemInventoryCalc,
|
||||||
|
tItemVisibleCalc,
|
||||||
tmp.itemAtp;
|
tmp.itemAtp;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue