2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`last_buy_refresh`(vRefresh BOOL)
|
|
|
|
proc: BEGIN
|
|
|
|
/**
|
|
|
|
* Crea o actualiza la cache con la última compra y fecha de cada
|
|
|
|
* artículo hasta ayer. Para obtener la última compra hasta una fecha
|
|
|
|
* determinada utilizar el procedimiento vn.buyUltimate().
|
|
|
|
*
|
|
|
|
* @param vRefresh %TRUE para forzar el recálculo de la cache
|
|
|
|
*/
|
|
|
|
DECLARE vCalc INT;
|
|
|
|
DECLARE started DATE;
|
|
|
|
DECLARE ended DATE;
|
|
|
|
DECLARE vLastRefresh DATE;
|
|
|
|
|
|
|
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
|
|
|
BEGIN
|
|
|
|
CALL cache_calc_unlock (vCalc);
|
|
|
|
RESIGNAL;
|
|
|
|
END;
|
|
|
|
|
|
|
|
CALL cache_calc_start (vCalc, vRefresh, 'last_buy', NULL);
|
|
|
|
|
|
|
|
IF !vRefresh
|
|
|
|
THEN
|
|
|
|
LEAVE proc;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
-- TODO: ¿Se puede usar la fecha del ultimo inventario?
|
|
|
|
SELECT inventoried INTO started FROM vn.config LIMIT 1;
|
|
|
|
SET ended = util.VN_CURDATE(); -- TIMESTAMPADD(DAY, -1, util.VN_CURDATE());
|
|
|
|
|
2024-07-16 16:55:58 +00:00
|
|
|
CALL vn.buy_getUltimateFromInterval(NULL, NULL, started, ended);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DELETE FROM last_buy;
|
|
|
|
|
|
|
|
INSERT INTO last_buy (item_id, warehouse_id, buy_id, landing)
|
|
|
|
SELECT itemFk, warehouseFk, buyFk, landed
|
|
|
|
FROM tmp.buyUltimateFromInterval;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.buyUltimateFromInterval;
|
|
|
|
|
|
|
|
CALL cache_calc_end (vCalc);
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|