salix/db/routines/vn/procedures/sectorCollection_hasSalesRe...

26 lines
769 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION vn.sectorCollection_hasSalesReserved(vSelf INT) RETURNS tinyint(1)
DETERMINISTIC
BEGIN
/**
* Devuelve si sectorCollection tiene reservas
* @param vSelf Id de sectorCollection
*
* returns BOOLEAN
*/
DECLARE vHasSalesReserved BOOLEAN;
SELECT DISTINCT COUNT(*) INTO vHasSalesReserved
FROM sectorCollection sc
JOIN sectorCollectionSaleGroup scsg ON sc.id = scsg.sectorCollectionFk
JOIN saleGroup sg ON sg.id = scsg.saleGroupFk
JOIN saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
JOIN sale s ON s.id = sgd.saleFk
JOIN itemShelvingSale iss ON iss.saleFk = s.id
JOIN saleTracking st ON st.saleFk = s.id
WHERE sc.id = vSelf;
RETURN vHasSalesReserved;
END$$
DELIMITER ;