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

30 lines
793 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`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(*)>0 INTO vHasSalesReserved
FROM vn.sectorCollection sc
JOIN vn.sectorCollectionSaleGroup scsg ON sc.id = scsg.sectorCollectionFk
JOIN vn.saleGroup sg ON sg.id = scsg.saleGroupFk
JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
JOIN vn.sale s ON s.id = sgd.saleFk
JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id
JOIN vn.saleTracking st ON st.saleFk = s.id
WHERE sc.id = vSelf;
RETURN vHasSalesReserved;
END$$
DELIMITER ;