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

Programa de Reporte Por operação Customizado utilizando a SFAPI009

Discussão em 'EMS , HCM e Totvs 11' iniciado por thiagoladeira, Junho 29, 2022.

  1. thiagoladeira

    thiagoladeira Sem Pontuação

    Prezados,

    Alguém possui um exemplo de programa de reporte por operação customizado no Datasul. Sei que existe uma api para isso SFAPI009. Gostaria de uma tela de reporte com somente as informações abaixo

    Alguém tem algum exemplo do Código que possa compartilhar?

    Achei a documentação um pouco complexa, de difícil entendimento.
  2. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    Tipo essa ?
    Alem do api de chão de fabrica, ainda processo co-produto, controle de qualidade e mais algumas coisinhas.


    upload_2022-6-30_15-34-23.png
  3. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    Existe uma tela de criação do plano de reporte, onde o usuario indica qual materia prima pegar e quais itens serão produzidos, depois ele entra nessa tela e faz os reporteres, enquanto o usuario não digitar tudo que precisa, o programa não faz nada em termos de datasul, depois que termina tudo, que faz as validações, existem umas regras de percentual que criamos por maquina, tipo limite maximo de sucata em relação ao requisitado e outras coisinhas, quando o usuario clica no botão pra reportar, eu crio a ordem de produção, requisita, reporta, sucateia e encerra a ordem, preenche os exames de controle de qualidade, e os exames dando OK, já transfere o item reportado do deposito CQ para o deposito onde deve ficar esperando ou pra vender ou pra ser requisitado para outro acabado.
  4. thiagoladeira

    thiagoladeira Sem Pontuação

    Ficou ótimo. Preciso mesmo de uma tela bem simples mesmo digitar a hora inicia, hora final, quantidade, operador. Como não conheço a API a fundo estou batendo cabeça.
  5. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    Um exemplo de uso ...
    Código:
    /*  ------------------------------------------------------
        Programa .: cstp/cssf0309rp.p
        Autor ....: Richard Edgar - Imesul
        Data .....: 01/02-2012
        Descricao : Efetuar reporte chÆo de f brica
                    est  em um programa aparte para conseguir
                    efetuar varios reporteres em sequencia.
        ------------------------------------------------------ */
        {grid2/error.i}
    
        using imesul.ems2.producao.gerenciador2.*.
    
        define variable error           as ExceptionControl no-undo.
        define variable requisicaoOrdem as RequisicaoOrdem  no-undo.
    
    {sfc/sfapi009.i}
    {cdp/cd0666.i}
    
    define temp-table tt-import-rep-oper
        field tipo-rep            as integer
        field nr-ord-produ        as integer
        field num-operac-sfc      as integer
        field num-split-operac    as integer
        field cod-roteiro         as character
        field op-codigo           as integer
        field cod-ctrab           as character
        field it-codigo           as character
        field cod-refer           as character
        field lote-serie          as character
        field dat-valid-lote      as date
        field per-ppm             as decimal
        field qtd-produzida       as decimal
        field cod-motiv-refugo    as character
        field qtd-refugada        as decimal
        field qtd-refugada-un-ref as decimal
        field qtd-retrabalho      as decimal
        field ct-refugo           as character
        field sc-refugo           as character
        field dat-inic-rep        as date
        field hr-inic-rep         as character
        field dat-fim-rep         as date
        field hr-fim-rep          as character
        field dat-inic-setup      as date
        field hr-inic-setup       as decimal
        field dat-fim-setup       as date
        field hr-fim-setup        as decimal
        field cod-equipe          as character
        field cod-operador        as character
        field cod-ferramenta      as character
        field num-contador-ini    as integer
        field num-contador-fim    as integer
        field finaliza            as logical
        field linha               as integer
        field erro                as logical
        field item-pai            as character.
    /*     index split is primary tipo-rep it-codigo */
    /*     index num-linha linha.                    */
    
    define input parameter codUnidnegoc as character no-undo.
    define input parameter numeroPlano  as integer   no-undo.
    define input parameter table for tt-import-rep-oper.
    define input parameter table for tt-reservas.
    define input parameter table for tt-ref.
    
    define variable sfapi009 as handle    no-undo.
    define variable retorno  as character no-undo.
    
    define variable campo1    as character no-undo.
    define variable campo2    as integer   no-undo.
    define variable campo3    as decimal   no-undo.
    define variable campo4    as date      no-undo.
    define variable sequencia as integer   no-undo.
    
    define temp-table tt-reservas-api no-undo like tt-reservas.
    
    do:
        assign error           = ExceptionControl:getInstance()
               requisicaoOrdem = new RequisicaoOrdem().
    
        empty temp-table tt-import-rep-oper-tt.
        empty temp-table tt-param-reporte.
        empty temp-table tt-reporte.
        empty temp-table tt-erro.
        empty temp-table tt-apont-mob.
        empty temp-table tt-aloca.
        empty temp-table tt-mat-reciclado.
        empty temp-table tt-raw-transfere.
        empty temp-table RowErrors.
        empty temp-table tt-saldo-dispatch.
        empty temp-table tt-reservas-api.
    
        run sfc/sfapi009.p persistent set sfapi009 (input 205, input table tt-import-rep-oper-tt, output table tt-erro).
    
        if can-find(first tt-erro) then do:
            run cdp/cd0666.w (input table tt-erro).
            return 'NOK'.
        end.
        if codUnidNegoc = 'SCP' then run gerarRequisicao. 
        run processaReporte.
        assign retorno = return-value.
    
        run finalizaAPI in sfapi009.
    
        return retorno.
    
    end.
    
    procedure gerarRequisicao:
        define variable totalREQ  as decimal no-undo.
        define variable totalROP  as decimal no-undo.
        define variable totalSOB  as decimal no-undo.
        define variable totalACA  as decimal no-undo.
        define variable totalAREQ as decimal no-undo.
        define variable qtdREQ    as decimal no-undo.
    
        find first tt-import-rep-oper no-lock no-error.
    
        assign totalREQ  = 0
               totalROP  = 0
               totalSOB  = 0
               totalACA  = 0
               totalAREQ = 0.
    
        for each movto-estoq no-lock
            where movto-estoq.nr-ord-produ = tt-import-rep-oper.nr-ord-produ:
            case {ininc/i03in218.i 4 movto-estoq.esp-docto}:
                when 'REQ' then assign totalREQ = totalREQ + movto-estoq.quantidade.
                when 'RRQ' then assign totalREQ = totalREQ - movto-estoq.quantidade.
                when 'ACA' then assign totalACA = totalACA + movto-estoq.quantidade.
                when 'EAC' then assign totalACA = totalACA - movto-estoq.quantidade.
                when 'ROP' then do:
                    if movto-estoq.tipo-trans = 1 then assign totalROP = totalROP + movto-estoq.quantidade.
                    if movto-estoq.tipo-trans = 2 then assign totalROP = totalROP - movto-estoq.quantidade.
                end.
                when 'SOB' then do:
                    if movto-estoq.tipo-trans = 1 then assign totalSOB = totalSOB + movto-estoq.quantidade.
                    if movto-estoq.tipo-trans = 2 then assign totalSOB = totalSOB - movto-estoq.quantidade.
                end.
            end case.
        end.
    
        for each tt-ref no-lock:
            assign totalROP = totalROP + tt-ref.qtd-operac-refgda.
        end.
    
        for each tt-reservas no-lock
            where tt-reservas.quant-requis <> 0:
            assign totalSOB = totalSOB + tt-reservas.quant-requis.
        end.
    
        assign totalACA = totalACA + tt-import-rep-oper.qtd-produzida.
    
        assign totalAREQ = (totalACA + totalROP + totalSOB) - totalREQ.
        if totalAREQ > 0 then do:
            for each cst_ger_plano_ra no-lock
                where cst_ger_plano_ra.cod-unid-negoc = codUnidNegoc
                  and cst_ger_plano_ra.numero         = numeroPlano
                ,
                first cst_ger_plano of cst_ger_plano_ra no-lock:
    
                for each saldo-estoq no-lock
                    where saldo-estoq.it-codigo   = cst_ger_plano.it-codigo
                      and saldo-estoq.cod-estabel = cst_ger_plano_ra.cod-estabel
                      and saldo-estoq.lote        = cst_ger_plano_ra.lote
                      and saldo-estoq.qtidade-atu > 0:
    
                    assign qtdREQ = totalAREQ.
                    if saldo-estoq.qtidade-atu < totalAREQ then assign qtdREQ = saldo-estoq.qtidade-atu.
    
                    do {&try}:
                        requisicaoOrdem:new(cst_ger_plano.cod-unid-negoc, cst_ger_plano.numero, tt-import-rep-oper.nr-ord-produ, today).
                        requisicaoOrdem:setReserva(no).
                        requisicaoOrdem:setItem(saldo-estoq.cod-depos, saldo-estoq.cod-estabel, saldo-estoq.cod-localiz, saldo-estoq.lote, saldo-estoq.it-codigo).
                        requisicaoOrdem:requisitar(qtdREQ).
                        assign totalAREQ = totalAREQ - qtdREQ.
                    {&catch}
    
                    if totalAREQ <= 0 then leave.
                end.
            end.
        end.
    end procedure.
    
    procedure processaReporte:
        define variable totalRefugo as decimal no-undo.
    
        find first tt-import-rep-oper no-error.
        for first ord-prod no-lock
            where ord-prod.nr-ord-produ = tt-import-rep-oper.nr-ord-produ:
            assign tt-import-rep-oper.item-pai = ord-prod.it-codigo.
        end.
        find first tt-import-rep-oper no-lock no-error.
    
        if not avail tt-import-rep-oper then do:
            run utp/ut-msgs.p('show',17006,'Sem itens para reportar').
            return 'NOK'.
        end.
    
        assign totalRefugo = 0.
        for each tt-ref
            where tt-ref.qtd-operac-refgda = 0
               or tt-ref.qtd-operac-refgda = ?:
            delete tt-ref no-error.
        end.
    
        for each tt-ref no-lock:
            assign totalRefugo = totalRefugo + tt-ref.qtd-operac-refgda.
        end.
    
        do transaction:
            run retornaParametrosDefault in sfapi009(output table tt-param-reporte).
    
            for each tt-param-reporte:
                case tt-param-reporte.cod-param:
                    when 'l-on-line'                        then assign tt-param-reporte.log-result-param = no.
                    when 'l-msg-parada-sobrep-continua'     then assign tt-param-reporte.log-result-param = no.
                    when 'l-msg-reservas-n-requis-continua' then assign tt-param-reporte.log-result-param = no.
                    when 'l-msg-requisita-saldo-disponivel' then assign tt-param-reporte.log-result-param = no.
                    when 'l-msg-nao-req-sem-saldo-sific'    then assign tt-param-reporte.log-result-param = no.
                    when 'l-msg-qtd-menor-rep-ant'          then assign tt-param-reporte.log-result-param = yes.
                    when 'l-msg-sem-reporte-ggf'            then assign tt-param-reporte.log-result-param = yes.
                    when 'l-msg-sem-reporte-mob'            then assign tt-param-reporte.log-result-param = yes.
                    when 'l-informa-deposito'               then assign tt-param-reporte.log-result-param = no.
                    when 'l-msg-termina-com-operac-incompl' then assign tt-param-reporte.log-result-param = no.
                    when 'l-msg-termina-ordem'              then assign tt-param-reporte.log-result-param = no.
                    when 'l-msg-reporta-tempo-dif-real'     then assign tt-param-reporte.log-result-param = yes.
                end case.
            end.
    
            run recebeParametros in sfapi009(input table tt-param-reporte).
    
            find first split-operac no-lock
                 where split-operac.nr-ord-produ     = tt-import-rep-oper.nr-ord-produ
                   and split-operac.num-operac-sfc   = tt-import-rep-oper.num-operac-sfc
                   and split-operac.num-split-operac = tt-import-rep-oper.num-split-operac
                       no-error.
    
            find first ctrab no-lock
                 where ctrab.cod-ctrab = split-operac.cod-ctrab
                       no-error.
    
            session:set-wait-state('general').
            run setaRowSplitCtrab in sfapi009(rowid(split-operac), rowid(ctrab)).
            session:set-wait-state('').
    
            if return-value = 'NOK' then do:
                run utp/ut-msgs.p('show',17006,'NÆo foi possivel posicionar SPLIT / Centro de trabalho').
                return 'NOK'.
            end.
    
            run recebeValorCampos in sfapi009('equipe'           ,tt-import-rep-oper.cod-equipe                 ,?,?                                ,?).
            run recebeValorCampos in sfapi009('operador'         ,tt-import-rep-oper.cod-operador               ,?,?                                ,?).
            run recebeValorCampos in sfapi009('dat-inic-reporte' ,?                                             ,?,?                                ,tt-import-rep-oper.dat-inic-rep).
            run recebeValorCampos in sfapi009('hra-inic-rep'     ,replace(tt-import-rep-oper.hr-inic-rep,':',''),?,?                                ,?).
            run recebeValorCampos in sfapi009('dat-fim-reporte'  ,?                                             ,?,?                                ,tt-import-rep-oper.dat-fim-rep).
            run recebeValorCampos in sfapi009('hra-fim-rep'      ,replace(tt-import-rep-oper.hr-fim-rep,':','') ,?,?                                ,?).
            run recebeValorCampos in sfapi009('qtd-aprov'        ,?                                             ,?,tt-import-rep-oper.qtd-produzida ,?).
            run recebeValorCampos in sfapi009('qtd-refgda'       ,?                                             ,?,totalRefugo                      ,?).
            run recebeValorCampos in sfapi009('lote-acab'        ,tt-import-rep-oper.lote-serie                 ,?,?                                ,?).
            run recebeValorCampos in sfapi009('dt-valid-lote'    ,?                                             ,?,?                                ,tt-import-rep-oper.dat-valid-lote).
    
            if totalRefugo <> 0 then
                run recebeValorCampos in sfapi009('dep-refugo'   ,'SUT'                                         ,?,?                                ,?).
    
            session:set-wait-state('general').
    
            run pi-cria-tt-reservas-alocacoes in sfapi009.
            run pi-retorna-tt-reservas        in sfapi009(output table tt-reservas-api).
    
            if userid('emsfnd') = 'datasul' then do:
                for each tt-reservas no-lock:
                    message tt-reservas.it-codigo ' ' tt-reservas.quant-requis
                        view-as alert-box info buttons ok.
                end.
            end.
    
            assign sequencia = 0.
            for each tt-reservas-api no-lock
                break
                   by tt-reservas-api.sequencia:
                assign sequencia = tt-reservas-api.sequencia.
            end.
    
            for each tt-reservas no-lock
                where tt-reservas.quant-requis <> 0:
                create tt-reservas-api.
                assign sequencia = sequencia + 1.
                buffer-copy tt-reservas to tt-reservas-api.
                assign tt-reservas-api.quant-orig   = tt-reservas.quant-requis * (-1)
                       tt-reservas-api.quant-requis = tt-reservas.quant-requis * (-1)
                       tt-reservas-api.lote-serie   = 'UNICO SOB'
                       tt-reservas-api.op-codigo    = tt-import-rep-oper.num-operac-sfc
                       tt-reservas-api.cod-roteiro  = tt-import-rep-oper.cod-roteiro
                       tt-reservas-api.sequencia    = sequencia.
            end.
    
            find first ord-prod where ord-prod.nr-ord-produ = tt-import-rep-oper.nr-ord-produ no-lock no-error.
    
            find first cst_ord_prod_lote
                 where cst_ord_prod_lote.nr-ord-produ = ord-prod.nr-ord-produ
                   and cst_ord_prod_lote.it-codigo    = ord-prod.it-codigo
                   and cst_ord_prod_lote.lote         = tt-import-rep-oper.lote-serie
                       no-error.
            if not avail cst_ord_prod_lote then do:
                create cst_ord_prod_lote.
                assign cst_ord_prod_lote.nr-ord-produ  = ord-prod.nr-ord-produ
                       cst_ord_prod_lote.it-codigo     = ord-prod.it-codigo
                       cst_ord_prod_lote.lote          = tt-import-rep-oper.lote-serie
                       cst_ord_prod_lote.qt-reporte    = 0
                       cst_ord_prod_lote.qt-reporte-uc = 0.
            end.
            assign cst_ord_prod_lote.qt-reporte-uc = tt-import-rep-oper.qtd-retrabalho
                   cst_ord_prod_lote.qt-reporte    = tt-import-rep-oper.qtd-produzida.
    
            run pi-recebe-tt-reservas         in sfapi009(input  table tt-reservas-api).
            run pi-recebe-tt-ref              in sfapi009(input  table tt-ref).
            run processaReporte               in sfapi009.
            assign retorno = return-value.
            run retornaTTErro                 in sfapi009(output table tt-erro).
    
            session:set-wait-state('').
    
            if retorno = 'NOK' then do:
                find first cst_ord_prod_lote
                     where cst_ord_prod_lote.nr-ord-produ = ord-prod.nr-ord-produ
                       and cst_ord_prod_lote.it-codigo    = ord-prod.it-codigo
                       and cst_ord_prod_lote.lote         = tt-import-rep-oper.lote-serie
                           no-error.
                if avail cst_ord_prod_lote then do:
                    delete cst_ord_prod_lote no-error.
                end.
    
                run cdp/cd0666.w (input table tt-erro).
                return 'NOK'.
            end.
    
            if can-find(first tt-erro) then do:
                find first cst_ord_prod_lote
                     where cst_ord_prod_lote.nr-ord-produ = ord-prod.nr-ord-produ
                       and cst_ord_prod_lote.it-codigo    = ord-prod.it-codigo
                       and cst_ord_prod_lote.lote         = tt-import-rep-oper.lote-serie
                           no-error.
                if avail cst_ord_prod_lote then do:
                    delete cst_ord_prod_lote no-error.
                end.
                run cdp/cd0666.w (input table tt-erro).
                return 'NOK'.
            end.
    
            if tt-import-rep-oper.qtd-retrabalho <> 0 then do:
                for first ord-prod no-lock
                    where ord-prod.nr-ord-produ = tt-import-rep-oper.nr-ord-produ:
                    find first cst_saldo_estoq_qtd
                         where cst_saldo_estoq_qtd.it-codigo   = tt-import-rep-oper.it-codigo
                           and cst_saldo_estoq_qtd.cod-estabel = ord-prod.cod-estabel
                               no-error.
                    if avail cst_saldo_estoq_qtd then do:
                        assign cst_saldo_estoq_qtd.saldo = cst_saldo_estoq_qtd.saldo + tt-import-rep-oper.qtd-retrabalho.
                    end.
                    else do:
                        find first cst_saldo_estoq_qtd
                             where cst_saldo_estoq_qtd.it-codigo   = tt-import-rep-oper.it-codigo
                               and cst_saldo_estoq_qtd.cod-estabel = ord-prod.cod-estabel
                                   no-error.
    
                        find first esp_compl_lote exclusive-lock
                             where esp_compl_lote.it_codigo = tt-import-rep-oper.it-codigo
                               and esp_compl_lote.lote      = tt-import-rep-oper.lote-serie
                                   no-error.
    
                        if not avail esp_compl_lote then do:
                            create esp_compl_lote.
                            assign esp_compl_lote.lote            = tt-import-rep-oper.lote-serie
                                   esp_compl_lote.it_codigo       = tt-import-rep-oper.it-codigo
                                   esp_compl_lote.Qt_Unid_do_Lote = 0
                                   esp_compl_lote.Peso_Lote       = 0.
                        end.
    
                        assign esp_compl_lote.qt_unid_do_lote = esp_compl_lote.qt_unid_do_lote + tt-import-rep-oper.qtd-retrabalho
                               esp_compl_lote.peso_lote       = esp_compl_lote.peso_lote       + tt-import-rep-oper.qtd-produzida.
                    end.
                end.
            end.
        end.
    
        return 'ok'.
    end procedure.
    
    

Compartilhe esta Página