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

27 lines
760 B
MySQL
Raw Normal View History

2024-02-15 13:37:09 +00:00
DELIMITER $$
$$
2024-06-25 10:51:14 +00:00
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `floranet`.`deliveryDate_get`(vPostalCode VARCHAR(15))
2024-03-18 13:03:16 +00:00
READS SQL DATA
2024-02-15 13:37:09 +00:00
BEGIN
/**
2024-04-11 11:25:43 +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,
2024-05-14 07:03:49 +00:00
NOW() + INTERVAL apc.hoursInAdvance HOUR minDeliveryTime
2024-03-18 13:03:16 +00:00
FROM addressPostCode apc
WHERE apc.postCode = vPostalCode
HAVING nextDay > minDeliveryTime) sub;
2024-02-15 13:37:09 +00:00
END$$
DELIMITER ;