salix/db/routines/vn/procedures/itemShelvingSale_addBySecto...

41 lines
1.2 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE
2024-05-23 14:35:36 +00:00
`vn`.`itemShelvingSale_addBySectorCollection`(vSectorCollectionFk INT(11))
BEGIN
/**
* Reserva cantidades con ubicaciones para el contenido de una preparación previa
* de la cual ya tiene generada la asociación del saleGroup con sectorCollection
*
* @param vSectorCollectionFk Identificador de sectorCollection
*/
2024-05-23 14:35:36 +00:00
DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vSaleFk INT;
DECLARE vSales CURSOR FOR
SELECT s.id
FROM sectorCollectionSaleGroup sc
JOIN saleGroupDetail sg ON sg.saleGroupFk = sc.saleGroupFk
JOIN sale s ON sg.saleFk = s.id
JOIN saleTracking str ON str.saleFk = s.id
JOIN `state` st ON st.id = str.stateFk
AND st.code = 'PREVIOUS_PREPARATION'
LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
WHERE sc.sectorCollectionFk = vSectorCollectionFk
AND str.workerFk = account.myUser_getId()
AND iss.id IS NULL;
2024-05-23 14:35:36 +00:00
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
OPEN vSales;
l: LOOP
SET vDone = FALSE;
FETCH vSales INTO vSaleFk;
IF vDone THEN
LEAVE l;
END IF;
2024-05-23 14:35:36 +00:00
CALL itemShelvingSale_addBySale(vSaleFk);
END LOOP;
CLOSE vSales;
END$$
2024-05-23 14:35:36 +00:00
DELIMITER ;