Buscar

Cartao exclusao caixa

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

SET TERM ^ ;
CREATE OR ALTER procedure CXA_LANCA_CARTAO (
 EMPRESA integer,
 CCSEQ integer,
 CARTAO integer,
 CCNRO varchar(40),
 CXGER integer,
 CCNRCF integer,
 VALOR_REF numeric(15,2),
 OPERACAO char(1))
as
declare variable DATA timestamp;
declare variable LANCAMENTO integer;
declare variable CONTA integer;
declare variable CONTA_TAXA integer;
declare variable PERC_TAXA numeric(15,4);
declare variable VALOR numeric(15,2);
declare variable ENTRADA_SAIDA char(1);
declare variable VALOR_TAXA numeric(15,2);
declare variable HISTORICO varchar(60);
declare variable QUITACAO_ENTRADA char(1);
declare variable QUITACAO_SAIDA char(1);
declare variable ESTORNO_ENTRADA char(1);
declare variable ESTORNO_SAIDA char(1);
declare variable TRANSF_ENTRADA char(1);
declare variable TRANSF_SAIDA char(1);
declare variable DELETAR_TAXA char(1);
declare variable CONTA_A_RECEBER integer;
begin
 conta_a_receber = (select PARCTACARTAO from sisapar where parcod =:empresa);
 quitacao_entrada = 'N';
 if ((:operacao = 'Q') and (:valor_ref > 0)) then
 quitacao_entrada = 'S';
 quitacao_saida = 'N';
 if ((:operacao = 'Q') and (:valor_ref < 0)) then
 quitacao_saida = 'S';
 estorno_entrada = 'N';
 if ((:operacao = 'E') and (:valor_ref > 0)) then
 estorno_entrada = 'S';
 estorno_saida = 'N';
 if ((:operacao = 'E') and (:valor_ref < 0)) then
 estorno_saida = 'S';
 transf_entrada = 'N';
 if ((:operacao = 'T') and (:valor_ref > 0)) then
 transf_entrada = 'S';
 transf_saida = 'N';
 if ((:operacao = 'T') and (:valor_ref < 0)) then
 transf_saida = 'S';
 if (:operacao = 'I') then
 historico = substring(('Inclusão de Cartão ' || :CCNRO) from 1 for 60);
 else
 if (:operacao = 'D') then
 historico = substring(('Exclusão de Cartão ' || :CCNRO) from 1 for 60);
 else
 if (:operacao = 'Q') then
 historico = substring(('Quitação de Cartão ' || :CCNRO) from 1 for 60);
 else
 if (:operacao = 'E') then
 historico = substring(('Estorno de Quitação de Cartão ' || :CCNRO) from 1 for 60);
 else
 if (:operacao = 'T') then
 historico = substring(('Alteração de Conta de Cartão ' || :CCNRO) from 1 for 60);
 if ((:estorno_saida = 'S') or (:transf_saida = 'S') or (:operacao = 'D')) then
 begin
 select first 1 dicta, coalesce(divlr, 0) from a02adiar
 left join a02aplan p on (p.ctcta = dicta)
 left join a02actsg s on (s.sgsgru = p.ctsgru)
 left join a02actbg g on (g.gcgru = s.sggru)
 where dies = 'E' and g.gcrd = 'D' and dicartao =:ccseq
 order by dinrlan desc
 into :conta_taxa, :valor_taxa;
 end
 deletar_taxa = 'N';
 if ((:operacao = 'D') or (:operacao = 'E') or (:operacao = 'T')) then
 begin
 select first 1 dicta, didata, divlr from a02adiar
 left join a02aplan p on (p.ctcta = dicta)
 left join a02actsg s on (s.sgsgru = p.ctsgru)
 left join a02actbg g on (g.gcgru = s.sggru)
 where dies = 'E' and g.gcrd <> 'D' and dicartao =:ccseq
 order by dinrlan desc
 into :conta, :data, :valor;
 
 if (:conta <> :conta_a_receber) then
 deletar_taxa = 'S';
 if ((:conta = :conta_a_receber) and (:operacao = 'T')) then
 exit;
 end
 if (:operacao = 'Q') then
 begin
 select cgdata from a02acxg g
 where g.cgemp =:empresa and g.cgnrcx=:cxger
 into :data;
 if (data is not null) then
 data = cast((cast(:data as date) || ' 23:59:59') as timestamp);
 end
 if ((:operacao = 'I') or (:data is null)) then
 begin
 select cxdata from a02acxa c
 where c.cxemp =:empresa and c.cxcaixa =:ccnrcf
 into :data;
 if ((:data is null) or (:data = current_date)) then
 data = current_timestamp;
 else
 data = cast((cast(:data as date) || ' 23:59:59') as timestamp);
 end
 if ((:quitacao_entrada = 'S') or (:transf_entrada = 'S')) then
 begin
 select coalesce(ec.creempctbco, x.crctbco),
 coalesce(ec.creemptaxa, x.crtaxa,0),
 coalesce(ec.creempcrctdesp, x.crctdesp)
 from a02acre x
 left join a02acre_config cf on (cf.creconfcod = x.crconfig)
 left join a02acre_emp_config ec on (ec.creempconf = cf.creconfcod and ec.creempemp = :empresa)
 where x.crcod = :cartao
 into :conta, :perc_taxa, :conta_taxa;
 
 valor_taxa = (:valor_ref * perc_taxa) / 100;
 valor = :valor_ref - :valor_taxa;
 end
 if ((:operacao = 'I') or (:estorno_entrada = 'S') or (:quitacao_saida = 'S')) then
 begin
 conta = :conta_a_receber;
 valor = :valor_ref;
 end
 
 if ((:operacao = 'D') and (:conta is null)) then
 begin
 conta = :conta_a_receber;
 data = current_timestamp;
 valor = :valor_ref;
 end
 if (:valor_ref > 0) then
 entrada_saida = 'E';
 else
 entrada_saida = 'S';
 valor = abs(:valor);
 valor_taxa = abs(:valor_taxa);
 if (:conta is not null) then
 execute procedure Diar_lancar(:empresa, null, :data,
 :historico, :conta, null, :valor, :entrada_saida, null, 'X',
 :cxger, null, 29, :data, null, null, null, :ccseq)
 returning_values :lancamento;
 if ((:conta_taxa is not null) and (:valor_taxa > 0) and ((:estorno_saida = 'S') or (:quitacao_entrada = 'S') or (:deletar_taxa = 'S')) ) then
 begin
 historico = substring(('Taxa Adm. ' || :historico) from 1 for 60);
 execute procedure Diar_lancar(:empresa, null, :data,
 :historico, :conta_taxa, null, :valor_taxa, :entrada_saida, null, 'Z',
 :cxger, null, 31, :data, null, null, null, :ccseq)
 returning_values :lancamento;
 end
END^
SET TERM ; ^

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Outros materiais