2024-01-31 06:11:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_doReserve`()
|
|
|
|
proc: BEGIN
|
|
|
|
/**
|
2024-06-24 11:30:03 +00:00
|
|
|
* Genera reservas de la tabla vn.itemShelvingSaleReserve
|
2024-01-31 06:11:03 +00:00
|
|
|
*/
|
|
|
|
DECLARE vDone BOOL;
|
|
|
|
DECLARE vSaleFk INT;
|
2024-07-17 14:09:09 +00:00
|
|
|
DECLARE vSectorFk INT;
|
2024-01-31 06:11:03 +00:00
|
|
|
|
|
|
|
DECLARE vSales CURSOR FOR
|
2024-07-17 16:24:27 +00:00
|
|
|
SELECT DISTINCT saleFk, sectorFk FROM tSale;
|
2024-01-31 06:11:03 +00:00
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
|
|
|
SET vDone = TRUE;
|
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
|
|
|
|
BEGIN
|
|
|
|
DO RELEASE_LOCK('vn.itemShelvingSale_doReserve');
|
|
|
|
ROLLBACK;
|
|
|
|
RESIGNAL;
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF !GET_LOCK('vn.itemShelvingSale_doReserve', 0) THEN
|
|
|
|
LEAVE proc;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tSale
|
|
|
|
ENGINE = MEMORY
|
2024-07-17 14:09:09 +00:00
|
|
|
SELECT id, saleFk, sectorFk FROM itemShelvingSaleReserve;
|
2024-01-31 06:11:03 +00:00
|
|
|
|
|
|
|
OPEN vSales;
|
|
|
|
|
|
|
|
myLoop: LOOP
|
|
|
|
SET vDone = FALSE;
|
2024-07-17 14:09:09 +00:00
|
|
|
FETCH vSales INTO vSaleFk, vSectorFk;
|
2024-01-31 06:11:03 +00:00
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE myLoop;
|
|
|
|
END IF;
|
|
|
|
|
2024-07-17 14:09:09 +00:00
|
|
|
CALL itemShelvingSale_addBySale (vSaleFk, vSectorFk);
|
2024-01-31 06:11:03 +00:00
|
|
|
END LOOP;
|
|
|
|
|
|
|
|
CLOSE vSales;
|
|
|
|
|
2024-07-17 14:09:09 +00:00
|
|
|
DELETE iss FROM itemShelvingSaleReserve iss
|
|
|
|
JOIN tSale s ON s.id = iss.id AND s.sectorFk = iss.sectorFk;
|
2024-01-31 06:11:03 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tSale;
|
|
|
|
|
|
|
|
DO RELEASE_LOCK('vn.itemShelvingSale_doReserve');
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|