Merge pull request 'refactor: refs #7640 multipleInventoryFix' (!2689) from 7640-multipleInventoryFix into master
Reviewed-on: #2689 Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
commit
6eef7876d9
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue