51 lines
1.3 KiB
SQL
51 lines
1.3 KiB
SQL
USE `cache`;
|
|
DROP procedure IF EXISTS `last_buy_refresh`;
|
|
|
|
DELIMITER $$
|
|
USE `cache`$$
|
|
CREATE DEFINER=`root`@`%` PROCEDURE `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 vn2008.item_last_buy_().
|
|
*
|
|
* @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?
|
|
SET started = vn2008.date_inv();-- TIMESTAMPADD(DAY, -90, CURDATE());
|
|
SET ended = CURDATE(); -- TIMESTAMPADD(DAY, -1, CURDATE());
|
|
|
|
CALL vn.buyUltimateFromInterval(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 ;
|
|
|