8144-devToTest_2448 #3216

Merged
alexm merged 256 commits from 8144-devToTest_2448 into test 2024-11-19 07:36:04 +00:00
1 changed files with 37 additions and 11 deletions
Showing only changes of commit 82bcb48101 - Show all commits

View File

@ -7,13 +7,13 @@ proc: BEGIN
* Calculate the stock of the auction warehouse from the inventory date to vDated * Calculate the stock of the auction warehouse from the inventory date to vDated
* without taking into account the outputs of the same day vDated * without taking into account the outputs of the same day vDated
* *
* @param vDated Date to calculate the stock. * @param vDated Date to calculate the stock
*/ */
IF vDated < util.VN_CURDATE() THEN IF vDated < util.VN_CURDATE() THEN
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 ;