Created
December 2, 2015 21:04
-
-
Save yogonza524/ce59c466c86bcbd61b5e to your computer and use it in GitHub Desktop.
Funcion para generar la siguiente fecha de emisión de cuota mensual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.get_fecha_emision() | |
RETURNS date AS | |
$BODY$ | |
DECLARE | |
dia_em integer; | |
today integer; | |
result date; | |
BEGIN | |
SELECT c.dia_emision INTO dia_em FROM config c LIMIT 1; | |
IF (dia_em IS NULL) THEN | |
RAISE EXCEPTION 'Error grave: no existe dia de emision en la tabla de configuración'; | |
END IF; | |
today = date_part('day',now()::date); | |
--Todavia no llegó el dia de emision | |
result = dia_em || '-' || date_part('month',now()) || '-' || date_part('year',now()); | |
IF (today > dia_em) THEN | |
result = result + '1 month'::interval; | |
END IF; | |
RETURN result; | |
END; | |
$BODY$ | |
LANGUAGE plpgsql VOLATILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Funcion encargada de devolver la fecha de emision de la siguiente factura a partir del dia de emision presente en la tabla "config".