Procedure para Gerar Parcelas
Boa noite!
Obtive a seguinte procedure de um fórum externo, porém ao tentar implementar a mesma não incrementa a data de vencimento conforme descrito, alguém poderia analisar e me dar um retorno?
Necessário declarar a função externa weekday da udf tbudf ou outra udf que possua a função
Declarei usando esse comando
declare external function udf_WeekDay
timestamp
returns smallint by value
entry_point 'udf_WeekDay' module_name 'tbudf';
SET TERM ^ ;
CREATE PROCEDURE GERA_PARCELAS (
DATA_INICIAL DATE,
NUMERO_PARCELAS INTEGER,
PRAZO_DIAS INTEGER,
APENAS_UTEIS SMALLINT)
RETURNS (
DATAVENCIMENTO DATE)
AS
DECLARE VARIABLE CTPARCELAS INTEGER;
begin
ctParcelas=0;
dataVencimento = :data_inicial;
suspend;
dataVencimento = :dataVencimento + :PRAZO_DIAS;
while (ctParcelas < :NUMERO_PARCELAS-1) do
begin
if (:apenas_uteis = 1) then --se forem apenas dias úteis...
begin
achouDiaUtil=0;
if ( (udf_weekday(:dataVencimento) = 0) or
(udf_weekday(:dataVencimento) = 6)) then
begin
achouDiaUtil=0;
dataVencimento=:dataVencimento + 1;
end
else
begin
suspend;
dataVencimento=:dataVencimento + :PRAZO_DIAS;
ctParcelas = :ctParcelas+1;
end
end
else /* se não for dias úteis */
begin
suspend;
dataVencimento=:dataVencimento + :PRAZO_DIAS;
ctParcelas = :ctParcelas +1;
end
end
end
^
SET TERM ; ^
Obtive a seguinte procedure de um fórum externo, porém ao tentar implementar a mesma não incrementa a data de vencimento conforme descrito, alguém poderia analisar e me dar um retorno?
Necessário declarar a função externa weekday da udf tbudf ou outra udf que possua a função
Declarei usando esse comando
declare external function udf_WeekDay
timestamp
returns smallint by value
entry_point 'udf_WeekDay' module_name 'tbudf';
SET TERM ^ ;
CREATE PROCEDURE GERA_PARCELAS (
DATA_INICIAL DATE,
NUMERO_PARCELAS INTEGER,
PRAZO_DIAS INTEGER,
APENAS_UTEIS SMALLINT)
RETURNS (
DATAVENCIMENTO DATE)
AS
DECLARE VARIABLE CTPARCELAS INTEGER;
begin
ctParcelas=0;
dataVencimento = :data_inicial;
suspend;
dataVencimento = :dataVencimento + :PRAZO_DIAS;
while (ctParcelas < :NUMERO_PARCELAS-1) do
begin
if (:apenas_uteis = 1) then --se forem apenas dias úteis...
begin
achouDiaUtil=0;
if ( (udf_weekday(:dataVencimento) = 0) or
(udf_weekday(:dataVencimento) = 6)) then
begin
achouDiaUtil=0;
dataVencimento=:dataVencimento + 1;
end
else
begin
suspend;
dataVencimento=:dataVencimento + :PRAZO_DIAS;
ctParcelas = :ctParcelas+1;
end
end
else /* se não for dias úteis */
begin
suspend;
dataVencimento=:dataVencimento + :PRAZO_DIAS;
ctParcelas = :ctParcelas +1;
end
end
end
^
SET TERM ; ^
Rutinaldo Sena
Curtidas 0