46 lines
1.2 KiB
SQL
46 lines
1.2 KiB
SQL
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.buy_getUltimate().
|
|
*
|
|
* @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());
|
|
|
|
CALL vn.buy_getUltimateFromInterval(NULL, NULL, started, ended);
|
|
|
|
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 ;
|