1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Estorno de Titulo ACR

Discussão em 'EMS , HCM e Totvs 11' iniciado por rosapamp, Julho 30, 2015.

  1. rosapamp

    rosapamp Sem Pontuação

    Bom Dia!

    Estou precisando estornar um titulo no contas a receber, alguém sabe qual API posso utilizar?
  2. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    Só lembrando que se vc tem algum movimento alem de implantação, vc tem que estornar esse movimento primeiro e depois estornar o titulo.

    Código:
    /*  ------------------------------------------------------------
        Programa .: imesul.ems5.contasReceber.Titulo.Estorno.cls
        Autor ....: Richard Edgar - Imesul
        Data .....: 20/01/2015
        Descricao : Estornar titulo contas a receber
        ------------------------------------------------------------ */
        {grid2/error.i}
    
        class imesul.ems5.contasReceber.Titulo.Estorno:
            define variable error as ExceptionControl no-undo.
    
            def temp-table tt_input_estorno no-undo
                field ttv_cod_label                    as character
                field ttv_des_conteudo                 as character
                field ttv_num_seq                      as integer
                index tt_primario                      is primary
                      ttv_num_seq                      ascending.
       
            def temp-table tt_log_erros_estorn_cancel no-undo
                field tta_cod_estab                    as character
                field tta_num_id_tit_acr               as integer
                field tta_num_id_movto_tit_acr         as integer
                field ttv_num_mensagem                 as integer
                field ttv_des_msg_erro                 as character
                field ttv_des_msg_ajuda                as character
                index tt_relac_tit_acr               
                      tta_cod_estab                    ascending
                      tta_num_id_tit_acr               ascending
                      tta_num_id_movto_tit_acr         ascending
                      ttv_num_mensagem                 ascending.
    
            define variable dataCancelamento     as date      no-undo.
            define variable motivoCancelamento   as character no-undo.
            define variable idNumMovtoLiquidacao as integer   no-undo.
            define variable situacao             as character no-undo.
    
            constructor public Estorno():
                assign error                = ExceptionControl:getInstance()
                       dataCancelamento     = today
                       motivoCancelamento   = ''
                       idNumMovtoLiquidacao = 0.
            end constructor.
    
            method public void findTitulo(cod_estab as character, cod_espec_docto as character, cod_ser_docto as character, cod_tit_acr as character, cod_parcela as character):
                find first tit_acr no-lock
                     where tit_acr.cod_estab       = cod_estab
                       and tit_acr.cod_espec_docto = cod_espec_docto
                       and tit_acr.cod_ser_docto   = cod_ser_docto
                       and tit_acr.cod_tit_acr     = cod_tit_acr
                       and tit_acr.cod_parcela     = cod_parcela
                           no-error.
    
                if not avail tit_acr then error:throwException('Estorno','Erro titulo',substitute('Titulo &1 &2 &3 &4 &5 nÆo encontrado',cod_estab, cod_espec_docto, cod_ser_docto, cod_tit_acr, cod_parcela)).
                verificaSituacao().
            end method.
    
            method private void verificaSituacao():
                assign idNumMovtoLiquidacao = 0.
                       situacao             = 'Aberto'.
    
                for each movto_tit_acr of tit_acr no-lock
                    where movto_tit_acr.log_movto_estordo = no:
                    assign idNumMovtoLiquidacao = movto_tit_acr.num_id_movto_tit_acr.
                    case movto_tit_acr.ind_trans_acr:
                        when 'Estorno de Titulo' then do:
                            assign situacao = 'Estornado'.
                            leave.
                        end.
                        when 'Liquida‡Æo'        then do:
                            assign situacao = 'Liquidado'.
                            leave.
                        end.
                    end case.
                end.
            end method.
    
            method public character getSituacao():
                return situacao.
            end method.
    
            method public void setData(campo as date):
                assign dataCancelamento = campo.
            end method.
    
            method public void setMotivo(campo as character):
                assign motivoCancelamento = campo.
            end method.
    
            method public void executar():
                if getSituacao() = 'Estornado' then return.
    
                if getSituacao() = 'Liquidado' then do:
                    empty temp-table tt_input_estorno.
                    empty temp-table tt_log_erros_estorn_cancel.
    
                    create tt_input_estorno.
                    assign tt_input_estorno.ttv_cod_label    = "N¡vel"
                           tt_input_estorno.ttv_des_conteudo = "Movimentos"
                           tt_input_estorno.ttv_num_seq      = 1.
    
                    create tt_input_estorno.
                    assign tt_input_estorno.ttv_cod_label    = "Opera‡Æo"
                           tt_input_estorno.ttv_des_conteudo = "Estorno"
                           tt_input_estorno.ttv_num_seq      = 1.
    
                    create tt_input_estorno.
                    assign tt_input_estorno.ttv_cod_label    = "Estabelecimento"
                           tt_input_estorno.ttv_des_conteudo = string(tit_acr.cod_estab)
                           tt_input_estorno.ttv_num_seq      = 1.
    
                    create tt_input_estorno.
                    assign tt_input_estorno.ttv_cod_label    = "Data"
                           tt_input_estorno.ttv_des_conteudo = string(dataCancelamento)
                           tt_input_estorno.ttv_num_seq      = 1.
    
                    create tt_input_estorno.
                    assign tt_input_estorno.ttv_cod_label    = "Referˆncia"
                           tt_input_estorno.ttv_des_conteudo = geraReferencia(tit_acr.cod_estab)
                           tt_input_estorno.ttv_num_seq      = 1.
    
                    create tt_input_estorno.
                    assign tt_input_estorno.ttv_cod_label    = "Hist¢rico"
                           tt_input_estorno.ttv_des_conteudo = motivoCancelamento
                           tt_input_estorno.ttv_num_seq      = 1.
    
                    create tt_input_estorno.
                    assign tt_input_estorno.ttv_cod_label    = "ID Titulo"
                           tt_input_estorno.ttv_des_conteudo = string(tit_acr.num_id_tit_acr).
                           tt_input_estorno.ttv_num_seq      = 1.
    
                    create tt_input_estorno.
                    assign tt_input_estorno.ttv_cod_label    = "ID Movimento"
                           tt_input_estorno.ttv_des_conteudo = string(idNumMovtoLiquidacao)
                           tt_input_estorno.ttv_num_seq      = 1.
    
                    run prgfin/acr/acr715zb.py (input 1,
                                                input  table tt_input_estorno,
                                                output table tt_log_erros_estorn_cancel).
    
                    if can-find(first tt_log_erros_estorn_cancel) then do:
                        for each tt_log_erros_estorn_cancel:
                            error:addException('acr715zb',
                                               'Erro estorno titulo',
                                               substitute('&1 &2 &3 - Erro &4 - &5 - &6',
                                                          tit_acr.cod_estab,
                                                          tit_acr.cod_tit_acr,
                                                          tit_acr.cod_parcela,
                                                          tt_log_erros_estorn_cancel.ttv_num_mensagem,
                                                          tt_log_erros_estorn_cancel.ttv_des_msg_erro,
                                                          tt_log_erros_estorn_cancel.ttv_des_msg_ajuda)
                                               ).
                        end.
                        error:throwException().
                    end.
                end.
    
                empty temp-table tt_input_estorno.
                empty temp-table tt_log_erros_estorn_cancel.
    
                create tt_input_estorno.
                assign tt_input_estorno.ttv_cod_label    = "N¡vel"
                       tt_input_estorno.ttv_des_conteudo = "Titulo"
                       tt_input_estorno.ttv_num_seq      = 1.
    
                create tt_input_estorno.
                assign tt_input_estorno.ttv_cod_label    = "Opera‡Æo"
                       tt_input_estorno.ttv_des_conteudo = "Estorno"
                       tt_input_estorno.ttv_num_seq      = 1.
    
                create tt_input_estorno.
                assign tt_input_estorno.ttv_cod_label    = "Estabelecimento"
                       tt_input_estorno.ttv_des_conteudo = string(tit_acr.cod_estab)
                       tt_input_estorno.ttv_num_seq      = 1.
    
                create tt_input_estorno.
                assign tt_input_estorno.ttv_cod_label    = "Data"
                       tt_input_estorno.ttv_des_conteudo = string(dataCancelamento)
                       tt_input_estorno.ttv_num_seq      = 1.
    
                create tt_input_estorno.
                assign tt_input_estorno.ttv_cod_label    = "Referˆncia"
                       tt_input_estorno.ttv_des_conteudo = geraReferencia(tit_acr.cod_estab)
                       tt_input_estorno.ttv_num_seq      = 1.
    
                create tt_input_estorno.
                assign tt_input_estorno.ttv_cod_label    = "Hist¢rico"
                       tt_input_estorno.ttv_des_conteudo = motivoCancelamento
                       tt_input_estorno.ttv_num_seq      = 1.
    
                create tt_input_estorno.
                assign tt_input_estorno.ttv_cod_label    = "ID Titulo"
                       tt_input_estorno.ttv_des_conteudo = string(tit_acr.num_id_tit_acr).
                       tt_input_estorno.ttv_num_seq      = 1.
    
                run prgfin/acr/acr715zb.py (input 1,
                                            input  table tt_input_estorno,
                                            output table tt_log_erros_estorn_cancel).
    
                if can-find(first tt_log_erros_estorn_cancel) then do:
                    for each tt_log_erros_estorn_cancel:
                        error:addException('acr715zb',
                                           'Erro estorno titulo',
                                           substitute('&1 &2 &3 - Erro &4 - &5 - &6',
                                                      tit_acr.cod_estab,
                                                      tit_acr.cod_tit_acr,
                                                      tit_acr.cod_parcela,
                                                      tt_log_erros_estorn_cancel.ttv_num_mensagem,
                                                      tt_log_erros_estorn_cancel.ttv_des_msg_erro,
                                                      tt_log_erros_estorn_cancel.ttv_des_msg_ajuda)
                                           ).
                    end.
                    error:throwException().
                end.
            end method.
    
            method private character geraReferencia(input codEstabel as character):
                define variable c-ref          as character no-undo.
                define variable i-sequencia-no as integer   no-undo.
       
                define buffer bTitAcr      for tit_acr.
                define buffer bMovtoTitAcr for movto_tit_acr.
       
                assign i-sequencia-no = 0.
                do while true:
                   assign c-ref = "ES" + string(TODAY,"999999") + string(i-sequencia-no).
       
                   find first bMovtoTitAcr no-lock
                        where bMovtoTitAcr.cod_estab = codEstabel
                          and bMovtoTitAcr.cod_refer = c-ref
                              no-error.
       
                   find first bTitAcr no-lock
                        where bTitAcr.cod_estab = codEstabel
                          and bTitAcr.cod_refer = c-ref
                              no-error.
       
                   find first lote_impl_tit_acr no-lock
                        where lote_impl_tit_acr.cod_estab = codEstabel
                          and lote_impl_tit_acr.cod_refer = c-ref
                              no-error.
       
                   find first lote_liquidac_acr no-lock
                        where lote_liquidac_acr.cod_estab = codEstabel
                          and lote_liquidac_acr.cod_refer = c-ref
                              no-error.
       
                   if  not avail bMovtoTitAcr      and
                       not avail bTitAcr           and
                       not avail lote_impl_tit_acr and
                       not avail lote_liquidac_acr then
                       leave.
    
                   assign i-sequencia-no = i-sequencia-no + 1.
                end.
       
                release bMovtoTitAcr.
                release bTitAcr.
                release lote_impl_tit_acr.
                release lote_liquidac_acr.
       
                return c-ref.
                   
            end method.
    
        end class.
    
  3. rosapamp

    rosapamp Sem Pontuação

    Obrigada, nesse caso tenho somente a implantação.
  4. cintiasottelli

    cintiasottelli Membro Participativo

    @bootstrapmaster Bom dia!

    Meu título está apenas com o movimento de implantação, está contabilizado mas não estou conseguindo estornar... Tinha uma ocorrência bancária mas consegui alterar o movimento escritural.... Você sabe me dizer porque não está estoranando?
  5. cintiasottelli

    cintiasottelli Membro Participativo

    Para dizer que não tem apenas implantação, tem uma alteração não contábil, não contabilizada... Eu teria que cancelar essa? como eu faço isso?
    @bootstrapmaster
  6. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    pra estornar um titulo, tem que estornar todos os movimentos existentes no titulo.
    cintiasottelli curtiu isso.

Compartilhe esta Página