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))
|
(PRIMARY KEY (itemFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT itemFk,
|
SELECT itemFk,
|
||||||
SUM(quantity) quantity,
|
SUM(quantity) quantity
|
||||||
SUM(quantity) visible
|
|
||||||
FROM (
|
FROM (
|
||||||
SELECT s.itemFk, - s.quantity quantity
|
SELECT s.itemFk, - s.quantity quantity
|
||||||
FROM sale s
|
FROM sale s
|
||||||
|
@ -75,56 +74,59 @@ proc: BEGIN
|
||||||
) sub
|
) sub
|
||||||
GROUP BY itemFk;
|
GROUP BY itemFk;
|
||||||
|
|
||||||
-- Cálculo del visible
|
|
||||||
UPDATE tItemInventoryCalc iic
|
|
||||||
JOIN (
|
|
||||||
SELECT itemFk, SUM(quantity) visible
|
|
||||||
FROM (
|
|
||||||
SELECT s.itemFk, s.quantity
|
|
||||||
FROM sale s
|
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
|
||||||
JOIN warehouse w ON w.id = t.warehouseFk
|
|
||||||
WHERE t.shipped >= vDate
|
|
||||||
AND t.shipped < vDateTomorrow
|
|
||||||
AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
|
|
||||||
AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
|
|
||||||
AND w.isComparative
|
|
||||||
UNION ALL
|
|
||||||
SELECT b.itemFk, - b.quantity
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
JOIN warehouse w ON w.id = t.warehouseInFk
|
|
||||||
WHERE t.landed = vDate
|
|
||||||
AND NOT t.isReceived
|
|
||||||
AND NOT e.isExcludedFromAvailable
|
|
||||||
AND NOT e.isRaid
|
|
||||||
AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
|
|
||||||
AND w.isComparative
|
|
||||||
UNION ALL
|
|
||||||
SELECT b.itemFk, b.quantity
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
JOIN warehouse w ON w.id = t.warehouseOutFk
|
|
||||||
WHERE t.shipped = vDate
|
|
||||||
AND NOT t.isReceived
|
|
||||||
AND NOT e.isExcludedFromAvailable
|
|
||||||
AND NOT e.isRaid
|
|
||||||
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;
|
|
||||||
|
|
||||||
UPDATE tmp.itemInventory ai
|
UPDATE tmp.itemInventory ai
|
||||||
JOIN tItemInventoryCalc iic ON iic.itemFk = ai.id
|
JOIN tItemInventoryCalc iic ON iic.itemFk = ai.id
|
||||||
SET ai.inventory = iic.quantity,
|
SET ai.inventory = iic.quantity,
|
||||||
ai.visible = iic.visible,
|
ai.visible = iic.quantity,
|
||||||
ai.avalaible = iic.quantity,
|
ai.avalaible = iic.quantity,
|
||||||
ai.sd = iic.quantity;
|
ai.sd = iic.quantity;
|
||||||
|
|
||||||
|
-- Cálculo del visible
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
|
||||||
|
(PRIMARY KEY (itemFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT itemFk, SUM(quantity) visible
|
||||||
|
FROM (
|
||||||
|
SELECT s.itemFk, s.quantity
|
||||||
|
FROM sale s
|
||||||
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
|
JOIN warehouse w ON w.id = t.warehouseFk
|
||||||
|
WHERE t.shipped >= vDate
|
||||||
|
AND t.shipped < vDateTomorrow
|
||||||
|
AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
|
||||||
|
AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
|
||||||
|
AND w.isComparative
|
||||||
|
UNION ALL
|
||||||
|
SELECT b.itemFk, - b.quantity
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
JOIN warehouse w ON w.id = t.warehouseInFk
|
||||||
|
WHERE t.landed = vDate
|
||||||
|
AND NOT t.isReceived
|
||||||
|
AND NOT e.isExcludedFromAvailable
|
||||||
|
AND NOT e.isRaid
|
||||||
|
AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
|
||||||
|
AND w.isComparative
|
||||||
|
UNION ALL
|
||||||
|
SELECT b.itemFk, b.quantity
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
JOIN warehouse w ON w.id = t.warehouseOutFk
|
||||||
|
WHERE t.shipped = vDate
|
||||||
|
AND NOT t.isReceived
|
||||||
|
AND NOT e.isExcludedFromAvailable
|
||||||
|
AND NOT e.isRaid
|
||||||
|
AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
|
||||||
|
AND w.isComparative
|
||||||
|
) sub2
|
||||||
|
GROUP BY itemFk;
|
||||||
|
|
||||||
|
UPDATE tmp.itemInventory ai
|
||||||
|
JOIN tItemVisibleCalc ivc ON ivc.itemFk = ai.id
|
||||||
|
SET ai.visible = ai.visible + ivc.visible;
|
||||||
|
|
||||||
-- Calculo del disponible
|
-- Calculo del disponible
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
|
||||||
(INDEX (itemFk, warehouseFk))
|
(INDEX (itemFk, warehouseFk))
|
||||||
|
@ -195,6 +197,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