2019-11-14 13:37:18 +00:00
|
|
|
USE `vn`;
|
|
|
|
DROP procedure IF EXISTS `zone_getEvents`;
|
2019-09-26 08:08:37 +00:00
|
|
|
|
|
|
|
DELIMITER $$
|
2019-11-14 13:37:18 +00:00
|
|
|
USE `vn`$$
|
|
|
|
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents`(
|
2019-09-26 08:08:37 +00:00
|
|
|
vProvinceFk INT,
|
2019-11-14 13:37:18 +00:00
|
|
|
vPostCode VARCHAR(255),
|
|
|
|
vAgencyModeFk INT)
|
2019-09-26 08:08:37 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Returns available events for the passed province/postcode and agency.
|
|
|
|
*
|
|
|
|
* @param vAgencyModeFk The agency mode id
|
|
|
|
* @param vProvinceFk The province id
|
|
|
|
* @param vPostCode The postcode or %NULL to use the province
|
|
|
|
*/
|
2019-11-14 13:37:18 +00:00
|
|
|
DECLARE vGeoFk INT;
|
2019-11-19 12:49:10 +00:00
|
|
|
|
2019-11-14 13:37:18 +00:00
|
|
|
IF vPostCode IS NOT NULL THEN
|
2019-09-26 08:08:37 +00:00
|
|
|
SELECT p.geoFk INTO vGeoFk
|
|
|
|
FROM postCode p
|
|
|
|
JOIN town t ON t.id = p.townFk
|
|
|
|
WHERE p.`code` = vPostCode
|
|
|
|
AND t.provinceFk = vProvinceFk;
|
|
|
|
ELSE
|
|
|
|
SELECT geoFk INTO vGeoFk
|
|
|
|
FROM province
|
2019-11-14 13:37:18 +00:00
|
|
|
WHERE id = vProvinceFk;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CALL zone_getFromGeo(vGeoFk);
|
|
|
|
|
|
|
|
IF vAgencyModeFk IS NOT NULL THEN
|
|
|
|
DELETE t FROM tmp.zone t
|
|
|
|
JOIN zone z ON z.id = t.id
|
|
|
|
WHERE z.agencyModeFk != vAgencyModeFk;
|
|
|
|
END IF;
|
|
|
|
|
2019-11-19 12:49:10 +00:00
|
|
|
SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays
|
2019-09-26 08:08:37 +00:00
|
|
|
FROM tmp.zone t
|
|
|
|
JOIN zoneEvent e ON e.zoneFk = t.id;
|
2019-11-14 13:37:18 +00:00
|
|
|
|
2019-11-19 12:49:10 +00:00
|
|
|
SELECT e.zoneFk, e.dated
|
2019-09-26 08:08:37 +00:00
|
|
|
FROM tmp.zone t
|
|
|
|
JOIN zoneExclusion e ON e.zoneFk = t.id;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.zone;
|
|
|
|
END$$
|
2019-11-14 13:37:18 +00:00
|
|
|
|
2019-09-26 08:08:37 +00:00
|
|
|
DELIMITER ;
|
|
|
|
|