salix/db/routines/floranet/procedures/deliveryDate_get.sql

29 lines
808 B
MySQL
Raw Normal View History

2024-02-15 13:37:09 +00:00
DROP PROCEDURE IF EXISTS floranet.deliveryDate_get;
DELIMITER $$
$$
2024-03-18 13:03:16 +00:00
CREATE DEFINER=`root`@`localhost` PROCEDURE `floranet`.`deliveryDate_get`(vPostalCode VARCHAR(15))
READS SQL DATA
2024-02-15 13:37:09 +00:00
BEGIN
/**
2024-03-18 13:03:16 +00:00
* Returns available dates for this postalCode, in the next seven days
2024-02-15 13:37:09 +00:00
*
* @param vPostalCode Delivery address postal code
*/
2024-03-18 13:03:16 +00:00
DECLARE vCurrentDayOfWeek INT;
2024-02-15 13:37:09 +00:00
2024-03-18 13:03:16 +00:00
SET vCurrentDayOfWeek = DAYOFWEEK(NOW());
2024-02-15 13:37:09 +00:00
2024-03-18 13:03:16 +00:00
SELECT DISTINCT nextDay
FROM (
SELECT CURDATE() + INTERVAL IF(
apc.dayOfWeek >= vCurrentDayOfWeek,
apc.dayOfWeek - vCurrentDayOfWeek,
7 - apc.dayOfWeek
) DAY nextDay,
NOW() + INTERVAL apc.hoursInAdvance - 12 HOUR minDeliveryTime
FROM addressPostCode apc
WHERE apc.postCode = vPostalCode
HAVING nextDay > minDeliveryTime) sub;
2024-02-15 13:37:09 +00:00
END$$
DELIMITER ;