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

42 lines
1.1 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockTraslation`(
vDated DATE
)
BEGIN
/**
* Calcula el stock del almacén de subasta desde FechaInventario hasta vDated
* sin tener en cuenta las salidas del mismo dia vDated
* para ver el transporte a reservar
*
* @param vDated Fecha hasta la cual calcula el stock
* @return tmp.item
*/
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 ;