salix/db/routines/vn/procedures/item_calculateStock.sql

40 lines
1.0 KiB
MySQL
Raw Normal View History

DELIMITER $$
2024-09-20 09:06:38 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_calculateStock`(
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-09-20 09:06:38 +00:00
* @param vDated Date to calculate the stock.
* @return tmp.item, tmp.buyUltimate
*/
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);
END$$
DELIMITER ;