fix: refs #7404 remove volume from ticket sold on holland #3169

Merged
pablone merged 5 commits from 7404-fix-remove-tickets-volume into test 2024-11-12 06:31:33 +00:00
1 changed files with 36 additions and 10 deletions
Showing only changes of commit f8c3d69c5d - Show all commits

View File

@ -13,7 +13,7 @@ proc: BEGIN
LEAVE proc; LEAVE proc;
END IF; END IF;
CREATE OR REPLACE TEMPORARY TABLE tStockBought CREATE OR REPLACE TEMPORARY TABLE tCurrentData
SELECT workerFk, reserve SELECT workerFk, reserve
FROM stockBought FROM stockBought
WHERE dated = vDated WHERE dated = vDated
@ -21,15 +21,28 @@ proc: BEGIN
DELETE FROM stockBought WHERE dated = vDated; DELETE FROM stockBought WHERE dated = vDated;
CREATE OR REPLACE TEMPORARY TABLE tStockSold
SELECT it.workerFk,
SUM(ic.cm3 * ito.quantity / vc.palletM3 / 1000000) sold
FROM itemTicketOut ito
JOIN item i ON i.id = ito.itemFk
JOIN itemType it ON it.id = i.typeFk
JOIN ticket t ON t.id = ito.ticketFk
JOIN warehouse wh ON wh.id = t.warehouseFk
JOIN itemCost ic ON ic.itemFk = ito.itemFk
AND ic.warehouseFk = t.warehouseFk
JOIN volumeConfig vc
WHERE ito.shipped BETWEEN vDated AND util.dayEnd(vDated)
AND wh.code = 'VNH'
GROUP BY it.workerFk;
CALL item_calculateStock(vDated); CALL item_calculateStock(vDated);
INSERT INTO stockBought(workerFk, bought, dated) CREATE OR REPLACE TEMPORARY TABLE tStockBought
SELECT it.workerFk, SELECT it.workerFk,
ROUND(SUM( SUM((ti.quantity / b.packing) *
(ti.quantity / b.packing) * buy_getVolume(b.id)
buy_getVolume(b.id) ) / vc.palletM3 / 1000000 bought
) / vc.palletM3 / 1000000, 1) bought,
vDated
FROM itemType it FROM itemType it
JOIN item i ON i.typeFk = it.id JOIN item i ON i.typeFk = it.id
LEFT JOIN tmp.item ti ON ti.itemFk = i.id LEFT JOIN tmp.item ti ON ti.itemFk = i.id
@ -43,20 +56,33 @@ proc: BEGIN
GROUP BY it.workerFk GROUP BY it.workerFk
HAVING bought; HAVING bought;
INSERT INTO stockBought(workerFk, bought, dated)
SELECT tb.workerFk,
ROUND(GREATEST(tb.bought - IFNULL(ts.sold, 0), 0), 1),
vDated
FROM tStockBought tb
LEFT JOIN tStockSold ts ON ts.workerFk = tb.workerFk;
UPDATE stockBought s UPDATE stockBought s
JOIN tStockBought ts ON ts.workerFk = s.workerFk JOIN tCurrentData ts ON ts.workerFk = s.workerFk
SET s.reserve = ts.reserve SET s.reserve = ts.reserve
WHERE s.dated = vDated; WHERE s.dated = vDated;
INSERT INTO stockBought (workerFk, reserve, dated) INSERT INTO stockBought (workerFk, reserve, dated)
SELECT ts.workerFk, ts.reserve, vDated SELECT ts.workerFk, ts.reserve, vDated
FROM tStockBought ts FROM tCurrentData ts
WHERE ts.workerFk NOT IN ( WHERE ts.workerFk NOT IN (
SELECT workerFk SELECT workerFk
FROM stockBought FROM stockBought
WHERE dated = vDated WHERE dated = vDated
); );
DROP TEMPORARY TABLE tStockBought, tmp.item, tmp.buyUltimate; UPDATE stockBought s
JOIN tStockSold ts ON ts.workerFk = s.workerFk
SET s.bought = IF(s.bought < ts.sold, ROUND(s.bought - ts.sold, 1), 0)
WHERE s.dated = vDated;
DROP TEMPORARY TABLE tCurrentData, tmp.item, tmp.buyUltimate, tStockSold;
END$$ END$$
DELIMITER ; DELIMITER ;