2024-03-18 16:51:35 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE
|
|
|
|
`vn`.`itemShelvingSale_reserveBySectorCollection`(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-08 08:59:19 +00:00
|
|
|
DECLARE vHasSales BOOL;
|
|
|
|
|
2024-03-18 16:51:35 +00:00
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
|
|
|
(INDEX(saleFk))
|
|
|
|
ENGINE = MEMORY
|
2024-04-11 11:45:43 +00:00
|
|
|
SELECT s.id saleFk, str.workerFk userFK
|
2024-03-18 16:51:35 +00:00
|
|
|
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'
|
2024-05-08 08:59:19 +00:00
|
|
|
LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
|
2024-03-18 16:51:35 +00:00
|
|
|
WHERE sc.sectorCollectionFk = vSectorCollectionFk
|
2024-05-08 08:59:19 +00:00
|
|
|
AND str.workerFk = account.myUser_getId()
|
|
|
|
AND iss.id IS NULL;
|
|
|
|
|
|
|
|
SELECT COUNT(*)INTO vHasSales
|
|
|
|
FROM tmp.sale;
|
2024-03-18 16:51:35 +00:00
|
|
|
|
2024-05-08 08:59:19 +00:00
|
|
|
IF vHasSales THEN
|
|
|
|
CALL itemShelvingSale_reserve();
|
|
|
|
ELSE
|
|
|
|
CALL util.throw ('There are not sales to reserve');
|
|
|
|
END IF;
|
2024-03-18 16:51:35 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|