refactor: refs #7640 multipleInventoryFix #2689

Merged
guillermo merged 4 commits from 7640-multipleInventoryFix into master 2024-07-08 05:52:52 +00:00
1 changed files with 49 additions and 46 deletions

View File

@ -40,8 +40,7 @@ proc: BEGIN
(PRIMARY KEY (itemFk))
ENGINE = MEMORY
SELECT itemFk,
SUM(quantity) quantity,
SUM(quantity) visible
SUM(quantity) quantity
FROM (
SELECT s.itemFk, - s.quantity quantity
FROM sale s
@ -75,9 +74,17 @@ proc: BEGIN
) sub
GROUP BY itemFk;
UPDATE tmp.itemInventory ai
JOIN tItemInventoryCalc iic ON iic.itemFk = ai.id
SET ai.inventory = iic.quantity,
ai.visible = iic.quantity,
ai.avalaible = iic.quantity,
ai.sd = iic.quantity;
-- Cálculo del visible
UPDATE tItemInventoryCalc iic
JOIN (
CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
(PRIMARY KEY (itemFk))
ENGINE = MEMORY
SELECT itemFk, SUM(quantity) visible
FROM (
SELECT s.itemFk, s.quantity
@ -114,16 +121,11 @@ proc: BEGIN
AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
AND w.isComparative
) sub2
GROUP BY itemFk
) sub ON sub.itemFk = iic.itemFk
SET iic.visible = iic.visible + sub.visible;
GROUP BY itemFk;
UPDATE tmp.itemInventory ai
JOIN tItemInventoryCalc iic ON iic.itemFk = ai.id
SET ai.inventory = iic.quantity,
ai.visible = iic.visible,
ai.avalaible = iic.quantity,
ai.sd = iic.quantity;
JOIN tItemVisibleCalc ivc ON ivc.itemFk = ai.id
SET ai.visible = ai.visible + ivc.visible;
-- Calculo del disponible
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
@ -195,6 +197,7 @@ proc: BEGIN
tmp.itemTravel,
tmp.itemCalc,
tItemInventoryCalc,
tItemVisibleCalc,
tmp.itemAtp;
END$$
DELIMITER ;