2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT)
|
2024-07-09 12:24:35 +00:00
|
|
|
proc:BEGIN
|
2024-01-15 11:31:03 +00:00
|
|
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
|
|
|
BEGIN
|
|
|
|
CALL cache_calc_unlock (v_calc);
|
|
|
|
RESIGNAL;
|
|
|
|
END;
|
|
|
|
|
2024-07-09 12:24:17 +00:00
|
|
|
CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
IF !v_refresh THEN
|
|
|
|
LEAVE proc;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
-- Calculamos el stock hasta ayer
|
|
|
|
|
2024-07-09 12:24:17 +00:00
|
|
|
CALL cache.stock_refresh(false);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible
|
|
|
|
(PRIMARY KEY (item_id))
|
|
|
|
ENGINE = MEMORY
|
2024-07-23 12:17:01 +00:00
|
|
|
SELECT s.item_id, SUM(s.amount) stock, SUM(s.amount) visible
|
|
|
|
FROM cache.stock s
|
|
|
|
JOIN warehouse w ON w.id = s.warehouse_id
|
|
|
|
WHERE (v_warehouse IS NULL OR s.warehouse_id = v_warehouse)
|
|
|
|
AND w.isComparative
|
|
|
|
GROUP BY s.item_id;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
-- Calculamos los movimientos confirmados de hoy
|
2024-07-09 12:22:32 +00:00
|
|
|
CALL vn.item_calcVisible(NULL, v_warehouse);
|
2024-01-15 11:31:03 +00:00
|
|
|
DELETE FROM visible WHERE calc_id = v_calc;
|
|
|
|
|
|
|
|
INSERT INTO visible (calc_id, item_id,visible)
|
|
|
|
SELECT v_calc, item_id, visible FROM tmp.itemVisible;
|
|
|
|
|
2024-07-09 12:24:17 +00:00
|
|
|
CALL cache_calc_end (v_calc);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.itemVisible;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|