2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`visible_getMisfit`(vSectorFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
/* Devuelve una tabla temporal con los descuadres entre el visible teórico y lo ubicado en la práctica
|
|
|
|
*
|
|
|
|
* @param vSectorFk Identificador de vn.sector
|
|
|
|
*
|
|
|
|
* @return tmp.stockMisfit(itemFk, visible, parked)
|
|
|
|
*/
|
|
|
|
|
|
|
|
DECLARE vCalcVisibleFk INT;
|
|
|
|
DECLARE vWarehouseFk INT;
|
|
|
|
|
|
|
|
SELECT warehouseFk INTO vWarehouseFk
|
|
|
|
FROM vn.sector s
|
|
|
|
WHERE s.id = vSectorFk;
|
|
|
|
|
|
|
|
CALL cache.visible_refresh(vCalcVisibleFk, FALSE, vWarehouseFk);
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.stockMisfit;
|
|
|
|
|
|
|
|
CREATE TEMPORARY TABLE tmp.stockMisfit(
|
|
|
|
itemFk INT PRIMARY KEY,
|
|
|
|
visible INT NOT NULL DEFAULT 0,
|
|
|
|
parked INT NOT NULL DEFAULT 0)
|
|
|
|
ENGINE = MEMORY;
|
|
|
|
|
|
|
|
INSERT INTO tmp.stockMisfit(itemFk, parked)
|
|
|
|
SELECT iss.itemFk , sum(iss.visible )
|
|
|
|
FROM vn.itemShelvingStock iss
|
|
|
|
JOIN vn.sector s ON s.id = iss.sectorFk
|
|
|
|
WHERE vSectorFk IN (s.id, s.sonFk)
|
|
|
|
GROUP BY iss.itemFk;
|
|
|
|
|
|
|
|
INSERT INTO tmp.stockMisfit(itemFk, visible)
|
|
|
|
SELECT v.item_id , v.visible
|
|
|
|
FROM cache.visible v
|
|
|
|
WHERE v.calc_id = vCalcVisibleFk
|
|
|
|
ON DUPLICATE KEY UPDATE visible = v.visible;
|
|
|
|
|
|
|
|
DELETE FROM tmp.stockMisfit
|
|
|
|
WHERE visible = parked;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|