2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-09-20 09:06:38 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_calculateStock`(
|
2024-01-15 11:31:03 +00:00
|
|
|
vDated DATE
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-09-20 09:06:38 +00:00
|
|
|
* Calculate the stock of the auction warehouse from the inventory date to vDated
|
2024-01-15 11:31:03 +00:00
|
|
|
*
|
2024-09-20 09:06:38 +00:00
|
|
|
* @param vDated Date to calculate the stock.
|
|
|
|
* @return tmp.item, tmp.buyUltimate
|
2024-01-15 11:31:03 +00:00
|
|
|
*/
|
|
|
|
DECLARE vAuctionWarehouseFk INT;
|
|
|
|
|
|
|
|
SELECT warehouseFk INTO vAuctionWarehouseFk
|
|
|
|
FROM auctionConfig;
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.item
|
|
|
|
(UNIQUE INDEX i USING HASH (itemFk))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT itemFk, SUM(quantity) quantity
|
|
|
|
FROM itemEntryIn
|
|
|
|
WHERE landed = vDated
|
|
|
|
AND vDated >= util.VN_CURDATE()
|
|
|
|
AND warehouseInFk = vAuctionWarehouseFk
|
|
|
|
AND NOT isVirtualStock
|
|
|
|
GROUP BY itemFk
|
|
|
|
HAVING quantity;
|
|
|
|
|
|
|
|
CALL `cache`.stock_refresh(FALSE);
|
|
|
|
|
|
|
|
INSERT INTO tmp.item (itemFk, quantity)
|
|
|
|
SELECT item_id, amount
|
|
|
|
FROM `cache`.stock
|
|
|
|
WHERE warehouse_id = vAuctionWarehouseFk
|
|
|
|
ON DUPLICATE KEY UPDATE quantity = tmp.item.quantity + VALUES(quantity);
|
|
|
|
|
2024-07-16 16:44:24 +00:00
|
|
|
CALL buy_getUltimate(NULL, vAuctionWarehouseFk, vDated);
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|