salix/db/routines/vn/functions/getDueDate.sql

18 lines
370 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`getDueDate`(vDated DATE, vDayToPay INT)
RETURNS date
NOT DETERMINISTIC
NO SQL
BEGIN
DECLARE vDued DATE;
IF vDayToPay = 0 THEN
RETURN vDated;
END IF;
SET vDued = TIMESTAMPADD(DAY,vDayToPay MOD 30, LAST_DAY(TIMESTAMPADD(MONTH, vDayToPay DIV 30, vDated)));
RETURN vDued;
END$$
DELIMITER ;