2024-01-31 06:11:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`itemShelvingSale_doReserve`()
|
2024-01-31 06:11:03 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
DECLARE vSales CURSOR FOR
|
|
|
|
SELECT DISTINCT saleFk FROM tSale;
|
|
|
|
|
|
|
|
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-06-24 11:30:03 +00:00
|
|
|
SELECT id, saleFk FROM itemShelvingSaleReserve;
|
2024-01-31 06:11:03 +00:00
|
|
|
|
|
|
|
OPEN vSales;
|
|
|
|
|
|
|
|
myLoop: LOOP
|
|
|
|
SET vDone = FALSE;
|
|
|
|
FETCH vSales INTO vSaleFk;
|
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE myLoop;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CALL itemShelvingSale_addBySale (vSaleFk);
|
|
|
|
END LOOP;
|
|
|
|
|
|
|
|
CLOSE vSales;
|
|
|
|
|
2024-06-24 11:30:03 +00:00
|
|
|
DELETE iss FROM itemShelvingSaleReserve iss JOIN tSale s ON s.id = iss.id;
|
2024-01-31 06:11:03 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tSale;
|
|
|
|
|
|
|
|
DO RELEASE_LOCK('vn.itemShelvingSale_doReserve');
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|