MZFICOM001

download MZFICOM001

If you can't read please download the document

description

Programa ABAP

Transcript of MZFICOM001

***INCLUDE ZFICOMI001 .*&---------------------------------------------------------------------**& Dados globais da z_fi_rfc_cria_pagamento*&---------------------------------------------------------------------**&type-pools: zfico, zfic2.ranges : s_belnr for bsis-belnr, s_augdt for bsad-augdt, s_augbl for bsad-augbl, s_stunr for konv-stunr, s_zaehk for konv-zaehk, s_buzei for bseg-buzei.constants c_mark2 type c value 'X'.* textos para o relatrio de representantesconstants: c_text_r01(50) type c value 'Comisso Representantes', c_text_r02(50) type c value 'Caramuru alimentos Ltda - Itumbiara', c_text_r03(50) type c value 'Programa:', c_text_r04(50) type c value 'Data:', c_text_r05(50) type c value 'Hora:', c_text_r06(50) type c value 'Pg:', c_text_r07(50) type c value 'Item', c_text_r08(50) type c value 'Nro Fatura', c_text_r09(50) type c value 'Par', c_text_r10(50) type c value 'Ordem', c_text_r11(50) type c value 'Descrio do cliente', c_text_r12(50) type c value 'Cidade', c_text_r13(50) type c value 'Vlr da comisso', c_text_r14(50) type c value 'Vlr amortizado', c_text_r15(50) type c value 'Vlr pagamento', c_text_r16(50) type c value 'Vlr desc & devol', c_text_r17(50) type c value 'Vlr das perdas', c_text_r18(50) type c value 'Saldo restante', c_text_r19(50) type c value 'Representante:', c_text_r20(50) type c value 'Totais dos lanamentos de comisses', c_text_r21(50) type c value 'Valor de comisso a pagar', c_text_r22(50) type c value 'Valor total da nota fiscal', c_text_r23(50) type c value 'Nota fiscal'.tables: zfitcom003, zfitcom004, zfiecom002.define grava_comissao. wa_item-vlreal = &1. wa_item-vlpgto = &2. wa_item-vldesc = &3. wa_item-vlperd = &4. wa_item-vlpdd = &5. if ( wa_item-wrbtr lt 0 ). wa_item-vlsald = wa_item-wrbtr + &3. else. wa_item-vlsald = wa_bsis-wrbtr - &1 - &2 - &3 - &4 - &5.* IF P_RESCISAO = '2'.* WA_ITEM-VLPGTO = WA_ITEM-VLPGTO + WA_ITEM-VLSALD.* CLEAR WA_ITEM-VLSALD.* ENDIF. endif. wa_item-buzei = wa_bsad-buzei. wa_item-gsber = wa_bsad-gsber. wa_item-budat = wa_bsad-budat. wa_item-buzcom = wa_bsis-buzei. append wa_item to t_zfitcom004.end-of-definition.define quebra. clear: v_vlreal, v_vldesc, v_vlpgto, v_vlperd, v_nroitem, v_vlsald, v_wrbtr.* format color col_heading intensified off. format reset. uline. read table t_auxlfa1 into wa_auxlfa1 with key vkbur = &1 binary search. if ( sy-subrc ne 0 ). clear wa_auxlfa1. endif. write: at /01(01) sy-vline no-gap, 03(14) c_text_r19 left-justified, 18 &1, 23 '-', 25(40) wa_auxlfa1-name1, 70(12) 'Pagamento:', 82(10) &2, 100(12) 'Criado em:', 112(10) &3, 130(16) 'Nro nota fiscal:', 147(06) &4, at sy-linsz sy-vline no-gap. uline.end-of-definition.define total_geral. uline.* format color col_total intensified on. format reset. v_comissao = v_vlpgto - v_vldesc - v_vlperd. v_vlsald = v_wrbtr - v_vlreal - v_vlpgto + v_vldiff. write: at /01(01) sy-vline no-gap, 03(45) c_text_r20, 130(01) sy-vline no-gap, 131(16) v_wrbtr, 148(1) sy-vline no-gap, 149(16) v_vlreal, 166(1) sy-vline no-gap, 167(16) v_vlpgto, 184(1) sy-vline no-gap, 185(16) v_vldesc, 202(1) sy-vline no-gap, 203(16) v_vlperd, 220(1) sy-vline no-gap, 221(16) v_vlsald, at sy-linsz sy-vline no-gap.* format color col_total intensified off. format reset. uline. clear v_imposto. loop at t_lfbw into wa_lfbw where ( vkbur eq wa_auxlfa1-vkbur ) and ( lifnr eq wa_auxlfa1-lifnr ) and ( nroseq eq wa_listaaux-nroseq ). write: at /01(01) sy-vline no-gap, 03(02) wa_lfbw-witht, 06(01) '-', 08(40) wa_lfbw-text40, 149(16) wa_lfbw-qsatz, 167(16) wa_lfbw-vlimp, at sy-linsz sy-vline no-gap. v_imposto = v_imposto + wa_lfbw-vlimp. endloop. uline.* format color col_total intensified on. format reset. v_comissao = v_vlpgto - v_vldesc - v_vlperd - v_imposto. write: at /01(01) sy-vline no-gap, 03(45) c_text_r21, 167(16) v_comissao, at sy-linsz sy-vline no-gap. if ( v_comissao le 0 ). clear v_vlpgto. endif. v_comissao = v_vlpgto - v_vldesc - v_vlperd. write: at /01(01) sy-vline no-gap, 03(45) c_text_r22, 167(16) v_comissao, at sy-linsz sy-vline no-gap. uline.end-of-definition.ranges: s_xref3 for bsis-xref3, s_hkon2 for bsis-hkont, s_param for bsis-hkont, s_bukrs for bsik-bukrs.data: p_newcom type c, p_concom type c, p_background type c, p_code100 like sy-ucomm, p_quinz like zfitcom003-quinzena, p_rescisao type c, v_wrbtr like zfitcom004-wrbtr, v_last_buzei like zfitcom004-buzei, v_vlreal like zfitcom004-vlreal, v_vlreal_ant like zfitcom004-vlreal, v_vlpgto like zfitcom004-vlpgto, v_acumpgt like zfitcom004-vlpgto, v_vldesc like zfitcom004-vldesc, v_vlperd like zfitcom004-vlperd, v_vlpdd like zfitcom004-vlpdd, v_vlcont like zfitcom004-vlpdd, v_vldiff like zfitcom004-vlpgto, v_imposto like vbap-netwr, v_buzei like zfitcom004-buzei, v_vlfat like vbrk-netwr, v_vlsald like zfitcom004-vlsald, v_taxcom type p decimals 6, v_nroitem type i, v_nroite like zfitcom011-nroite, v_datini like sy-datum, v_datfin like sy-datum, v_totvend like sy-tabix, v_print_mode like sy-callr, v_aux1 like vbrk-netwr, v_totproc(6) type n, v_text(60) type c, v_text2(60) type c, v_totpgt(6) type n, v_totdev like zfitcom004-vlpgto, v_pagnr like zfitcom003-pagnr, v_comissao like vbap-netwr, v_totcom like zfitcom004-wrbtr, v_linsz like sy-linsz, params like pri_params, arparams like arc_params, v_tabidx like sy-tabix, valid type c.data: begin of wa_zuonr, belnr(10) type n, buzei(03) type n, gjahr(04) type n, fill1(01) type c, end of wa_zuonr.data: begin of wa_ref, belnr like zfitcom004-belnr, bukrs like zfitcom004-bukrs, kunnr like zfitcom004-kunnr, zuonr like zfitcom004-belnr, vbeln like vbfa-vbelv, end of wa_ref.data: begin of wa_vbfa, vbeln like vbfa-vbeln, vbelv like vbfa-vbelv, end of wa_vbfa.data: begin of wa_lfbw_r9, witht like t059z-witht, wt_withcd like t059z-wt_withcd, qproz like t059z-qproz, qsatz like t059z-qsatz, text40 like t059u-text40, end of wa_lfbw_r9.data: begin of wa_data, mes(2) type n, fill(1) type c, ano(4) type n, rest(3) type c, end of wa_data.data: wa_bsis type zfic2_wa_bsis, wa_bsad type zfic2_wa_bsad, wa_bsadaux type zfic2_wa_bsad, wa_bsid type zfic2_wa_bsad, wa_parciais type zfic2_wa_parciais, wa_descontos type zfic2_wa_descontos, wa_descda type zfic2_wa_descontos, wa_parametros type zfic2_wa_parametros, wa_zfitcom003 type zfitcom003, wa_item type zfic2_wa_item,*> wa_bkpf type zfic2_wa_bkpf, wa_bsisaux type zfic2_wa_bsis, wa_compaux type zfic2_wa_compaux, wa_compdoc type zfic2_wa_descontos, wa_compda type zfic2_wa_descontos, wa_contda type zfic2_wa_descontos, wa_valida type zfic2_wa_valida, wa_vbrk type zfic2_wa_vbrk, wa_konv like konv, wa_fatori type zfic2_wa_bseg, wa_novos type zfic2_wa_novos, wa_base12 type zfic2_wa_historico, wa_auxbase type zfic2_wa_historico, wa_kna1 type zfic2_wa_kna1, wa_lista type zfic2_wa_lista, wa_partidas type zfic2_wa_partidas, wa_fatura type zfic2_wa_vbrk, wa_bseg1 type zfic2_wa_bseg, wa_bseg_all like bseg, wa_auxlfa1 type zfico_wa, wa_aux1 like zfitcom003, wa_lfbw like zfiecom001, wa_antigos like zfitcom010, wa_indices like zfitcom009, wa_tvbur1 like tvbur.data: t_antigos like standard table of zfitcom010, t_auxiliar type zfic2_zfitcom004, t_auxlfa1 type zfico_fornec, t_base12 type zfic2_historico, t_bsad type zfic2_bsad, t_bsad_full type zfic2_bsad, t_bsadaux type zfic2_bsad, t_bseg_all like standard table of bseg, t_bseg1 type zfic2_bseg, t_bsid type zfic2_bsad, t_bsis type zfic2_bsis, t_bsisaux type zfic2_bsis, t_compaux type zfic2_compaux, t_compda type zfic2_descontos, t_compdoc type zfic2_descontos, t_contda type zfic2_descontos, t_descontos type zfic2_descontos, t_descaux type zfic2_descontos, t_descda type zfic2_descontos, t_fatori type zfic2_bseg, t_fatura type zfic2_vbrk, t_indices like standard table of wa_indices, t_kna1 type zfic2_kna1, t_konv like standard table of konv, t_lista type zfic2_lista, t_lfbw like standard table of wa_lfbw, t_lfbwaux like standard table of wa_lfbw, t_novos type zfic2_novos, t_oldbase type zfic2_historico, t_parametros type zfic2_parametros, t_parciais type zfic2_parciais, t_partidas type zfic2_partidas, t_ref like standard table of wa_ref, t_refcto like standard table of wa_ref, t_refdev like standard table of wa_ref, t_tvbur1 like standard table of wa_tvbur1, t_valida type zfic2_valida, t_vbfa like standard table of wa_vbfa, t_vbrk type zfic2_vbrk, t_zfitcom003 type zfic2_zfitcom003, t_zfitcom004 type zfic2_zfitcom004, t_auxtcom004 type zfic2_zfitcom004.*> Alteraes para performancedata: wa_bkpf like bkpf, t_bkpf like standard table of wa_bkpf.*&---------------------------------------------------------------------**& Form f_selecao_de_criacao*&---------------------------------------------------------------------**& TELA 0100 - chamada para seleo de dados*& Rotina que seleciona os dados das comisses a serem pagas*&---------------------------------------------------------------------**&form f_selecao_de_criacao. data: v_xblnr like bsis-xblnr, v_vldesc like bsad-wrbtr. refresh: t_bsis, t_bsad, t_parciais, t_descontos, t_parametros, t_zfitcom003, t_zfitcom004, t_bsad_full. refresh s_hkon2. clear s_hkon2. s_hkon2-sign = 'I'. s_hkon2-option = 'EQ'. if ( p_newcom eq c_mark2 ). s_hkon2-low = '0002104009'. append s_hkon2. endif. if ( p_concom eq c_mark2 ). s_hkon2-low = '0002104010'. append s_hkon2. endif. call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 10 text = 'Lendo comisses em aberto ...'.*> Leitura das contas de comisses (s_hkon2) informadas como parmetro*> Buscando faturas e devolues e comisses da conta antiga select xref3 bukrs budat hkont zuonr gjahr belnr buzei blart wrbtr shkzg from bsis into table t_bsis where ( hkont in s_hkon2 ) and ( xref3 in s_xref3 ) and ( blart in ('RV', 'SN', 'DA' ) ) and ( budat le p_quinz ) and ( bukrs in s_bukrs ) order by hkont xref3 blart budat. delete t_bsis where not ( belnr in s_belnr ) or ( shkzg ne 'H' ). select xref3 bukrs budat hkont zuonr gjahr belnr buzei blart wrbtr shkzg from bsis into table t_bsisaux where ( hkont in s_hkon2 ) and ( xref3 in s_xref3 ) and ( blart in ('SN', 'DG' ) ) and ( budat le p_quinz ) and ( bukrs in s_bukrs ) order by hkont xref3 blart budat. delete t_bsisaux where not ( belnr in s_belnr ) or ( shkzg ne 'S' ). append lines of t_bsisaux to t_bsis. refresh t_bsisaux. check ( not t_bsis[] is initial ).*> Leitura dos clientes das faturas ref das comisses call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 20 text = 'Lendo pagamentos realizados ...'. sort t_bsis by bukrs belnr gjahr. loop at t_bsis into wa_bsis. wa_zuonr = wa_bsis-zuonr. if ( 'RVDGDA' cs wa_bsis-blart ). wa_bsis-belnz = wa_bsis-belnr. wa_bsis-gjahz = wa_bsis-gjahr. wa_bsis-buzez = wa_bsis-buzei.* Slvio em 06/03/2006 wa_bsis-beln2 = wa_bsis-belnr. wa_bsis-buze2 = wa_bsis-buzei. wa_bsis-gjah2 = wa_bsis-gjahr. else. wa_bsis-belnz = wa_zuonr-belnr. wa_bsis-buzez = wa_zuonr-buzei. wa_bsis-gjahz = wa_zuonr-gjahr. endif. if ( 'DASN' cs wa_bsis-blart ). wa_bsis-beln2 = wa_zuonr-belnr. wa_bsis-buze2 = wa_zuonr-buzei. wa_bsis-gjah2 = wa_zuonr-gjahr. endif. select * from bseg into table t_bseg_all where ( bukrs eq wa_bsis-bukrs ) and ( belnr eq wa_bsis-belnz ) and ( gjahr eq wa_bsis-gjahz ) and ( buzei eq 1 ) order by primary key. read table t_bseg_all into wa_bseg_all index 1. if ( sy-subrc eq 0 ). wa_bsis-kunnr = wa_bseg_all-kunnr. select * from bkpf into table t_bkpf where ( bukrs eq wa_bsis-bukrs ) and ( belnr eq wa_bsis-belnz ) and ( gjahr eq wa_bsis-gjahz ). read table t_bkpf into wa_bkpf index 1. if ( sy-subrc eq 0 ). wa_bsis-budat = wa_bkpf-budat. endif. endif. modify t_bsis from wa_bsis transporting belnz buzez gjahz beln2 buze2 gjah2 kunnr budat. endloop.*> Identificar os pagamentos realizados call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 30 text = 'Identificando pagamento de comisses ...'.*> Seleciona as partidas pagas pelo cliente com referncia a*> fatura .*> Separa a leitura das faturas por conta de contencioso e conta normal t_bsisaux[] = t_bsis[]. delete t_bsisaux where ( hkont ne '0002104010' ). if ( not t_bsisaux[] is initial ). select bukrs kunnr budat belnr buzei augbl wrbtr hkont gjahr gsber zuonr augdt vbeln from bsad into table t_bsad for all entries in t_bsisaux where ( bukrs eq t_bsisaux-bukrs ) and ( kunnr eq t_bsisaux-kunnr ) and ( belnr eq t_bsisaux-belnz ) and ( gjahr eq t_bsisaux-gjahz )*> and ( budat eq t_bsisaux-budat ) and ( umsks eq 'Y' ) and ( shkzg eq 'S' ). endif.* t_bsisaux[] = t_bsis[].* delete t_bsisaux where ( hkont ne '0002104010' )* or ( blart ne 'DA' ).** if ( not t_bsisaux[] is initial ).* select bukrs kunnr budat belnr buzei augbl wrbtr hkont gjahr gsber* zuonr augdt vbeln* from bsad* into table t_bsad* for all entries in t_bsisaux* where ( bukrs eq t_bsisaux-bukrs )* and ( kunnr eq t_bsisaux-kunnr )* and ( budat eq t_bsisaux-budat )* and ( zuonr eq t_bsisaux-zuonr )* and ( belnr eq t_bsisaux-belnz )* and ( gjahr eq t_bsisaux-gjahz )* and ( umsks eq 'Y' )* and ( shkzg eq 'S' ).** endif. t_bsisaux[] = t_bsis[]. delete t_bsisaux where ( hkont ne '0002104009' ). if ( not t_bsisaux[] is initial ). select bukrs kunnr budat belnr buzei augbl wrbtr hkont gjahr gsber zuonr augdt vbeln from bsad appending table t_bsad for all entries in t_bsisaux where ( bukrs eq t_bsisaux-bukrs ) and ( kunnr eq t_bsisaux-kunnr ) and ( belnr eq t_bsisaux-belnz ) and ( gjahr eq t_bsisaux-gjahz )*> and ( budat eq t_bsisaux-budat ) and ( umsks eq ' ' ) . endif. delete t_bsad where ( augdt gt p_quinz ). sort t_bsad by bukrs kunnr budat belnr.*> Leitura das partidas dos documentos de compensao realizados if ( not t_bsad[] is initial ). call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 40 text = 'Buscando contrapartidas de pagamentos...'.*> Identificar as faturas que j se encontram na programao p/ pagto*> ( GMSS - SPEC - 27.05.2005 ) - COMENTARIOS*> O objetivo da tabela t_valida identificar os lanamentos j reali-*> zados em outras quinzenas, para efeito de clculo do saldo.*> De outra forma, ela utilizada aqui neste ponto, para eliminar os*> pagamentos que esto vinculados em quinzenas j calculadas.*> Logo abaixo na rotina "f_elimina_registros" todos lanamentos de co-*> misso pendentes ( t_bsis ) sero eliminados caso no possuam nenhum*> registro de pagamento equivalente ( t_bsad ).*> select t1~belnr t1~buzcom t1~gjahr t1~buzei t1~bukrs t1~hkont t1~zuonr t2~pagnr t2~vkbur t1~wrbtr t1~vlreal t1~vlpgto t1~vlperd t1~vlpdd t1~vlsald t1~vldesc from zfitcom004 as t1 inner join zfitcom003 as t2 on t2~pagnr eq t1~pagnr and t2~status ne '4' into table t_valida for all entries in t_bsis where ( t1~belnr eq t_bsis-belnr ) and ( t1~buzcom eq t_bsis-buzei ) and ( t1~gjahr eq t_bsis-gjahr ). sort t_valida by belnr buzei gjahr. loop at t_bsad into wa_bsad. read table t_valida into wa_valida with key belnr = wa_bsad-belnr buzei = wa_bsad-buzei gjahr = wa_bsad-gjahr binary search. if ( sy-subrc eq 0 ). wa_bsad-mark = 'X'. modify t_bsad from wa_bsad transporting mark. endif. endloop. t_bsad_full[] = t_bsad[]. delete t_bsad where ( mark eq 'X' ). if ( not t_bsad[] is initial ). select bukrs kunnr augbl gjahr belnr buzei wrbtr hkont blart shkzg budat from bsad into table t_compdoc for all entries in t_bsad where ( kunnr eq t_bsad-kunnr ) and ( bukrs eq t_bsad-bukrs ) and ( augdt eq t_bsad-augdt ) and ( augbl eq t_bsad-augbl ) and ( budat le p_quinz ). sort t_compdoc by bukrs kunnr belnr. endif.*INICIO BDS - Retirado pois quando da compensao de um Debito e Crdito*no cliente e estes tem o mesmo valor no gerado na BSAD e BSEG o*documento de compensao mas este apenas informado no ZUONR e a*comisso no er liberada.* loop at t_bsad into wa_bsad.* read table t_compdoc into wa_compdoc* with key bukrs = wa_bsad-bukrs* kunnr = wa_bsad-kunnr* belnr = wa_bsad-augbl binary search.* if ( sy-subrc ne 0 ).* delete t_bsad.* endif.* endloop.*FIM BDS* Slvio em 09/03/06* T_BSAD_FULL[] = T_BSAD[]. endif.*> Busca partidas no pagas para pagamento de resciso if ( p_rescisao eq '2' ).* loop at t_bsis into wa_bsis.* move-corresponding wa_bsis to t_bsad_full.* append t_bsad_full.* endloop. perform f_busca_partidas_pagas. endif. sort t_valida by belnr buzcom gjahr. call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 50 text = 'Eliminando faturas estornadas ...'. perform f_elimina_registros. check ( not t_bsis[] is initial ). select t1~vbeln t1~netwr t1~mwsbk t1~xblnr t1~fksto t1~knumv from vbrk as t1 inner join vbrp as t2 on t2~vbeln eq t1~vbeln into table t_vbrk for all entries in t_bsis where ( t1~vbeln eq t_bsis-vbeln ). delete adjacent duplicates from t_vbrk comparing vbeln. sort t_vbrk by vbeln. refresh t_fatori. loop at t_bsis into wa_bsis.*> Eliminar comisses e devolues cujo a fatura tenha sido estornada read table t_vbrk into wa_vbrk with key vbeln = wa_bsis-vbeln binary search. if ( sy-subrc ne 0 ). if ( wa_bsis-hkont eq '0002104009' ). delete t_bsis. continue. endif. else. v_tabidx = sy-tabix. if ( wa_vbrk-fksto eq c_mark2 ). delete t_bsis. continue. else. select * from konv into table t_konv where ( knumv eq wa_vbrk-knumv ) and ( kschl eq 'ZCSS' ) order by primary key. loop at t_konv into wa_konv. at first. sum. wa_vbrk-wrbtr = wa_konv-kwert. endat. exit. endloop. modify t_vbrk from wa_vbrk index v_tabidx transporting wrbtr. endif. endif.*> Leitura dos valores das faturas para clculo taxa mdia comisso select * from bseg into table t_bseg_all where ( bukrs eq wa_bsis-bukrs ) and ( belnr eq wa_bsis-beln2 ) and ( gjahr eq wa_bsis-gjah2 ) and ( buzei eq wa_bsis-buze2 ) order by primary key. read table t_bseg_all into wa_bseg_all index 1. check ( sy-subrc eq 0 ). clear wa_fatori. move-corresponding wa_bseg_all to wa_fatori. append wa_fatori to t_fatori. endloop. sort t_fatori by belnr gjahr buzei. call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 60 text = 'Lendo descontos concedidos de contencioso...'. check: ( not t_bsad[] is initial ), ( not t_compdoc[] is initial ).*> Monta tabela com compensaes e descobre os descontos, perdas*> pdd e pagamentos realizados na conta cliente normal no momento*> da transferncia para o contencioso. perform f_descontos_contencioso. call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 65 text = 'Lendo descontos concedidos normais...'. perform f_descontos_normais. call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 70 text = 'Lendo descontos concedidos PDD ...'. perform f_descontos_adicionais. sort t_descontos by bukrs kunnr augbl belnr buzei gjahr. " hkont. loop at t_descaux into wa_descda. read table t_descontos into wa_descontos with key bukrs = wa_descda-bukrs kunnr = wa_descda-kunnr augbl = wa_descda-augbl belnr = wa_descda-belnr buzei = wa_descda-buzei gjahr = wa_descda-gjahr binary search.*> hkont = wa_descda-hkont binary search. if ( sy-subrc eq 0 ). delete t_descaux. endif. endloop. append lines of t_descaux to t_descontos. perform f_rateia_descontos tables t_descontos. perform f_rateia_descontos tables t_descda.endform. " f_selecao_de_criacao*&---------------------------------------------------------------------**& Form f_busca_partidas_pagas*&---------------------------------------------------------------------*form f_busca_partidas_pagas. refresh t_bsid. t_bsisaux[] = t_bsis[]. delete t_bsisaux where ( hkont ne '0002104010' ). if ( not t_bsisaux[] is initial ). select bukrs kunnr budat belnr buzei augbl wrbtr hkont gjahr gsber zuonr augdt vbeln from bsid into table t_bsid for all entries in t_bsisaux where ( bukrs eq t_bsisaux-bukrs ) and ( kunnr eq t_bsisaux-kunnr ) and ( budat eq t_bsisaux-budat ) and ( belnr eq t_bsisaux-belnz ) and ( gjahr eq t_bsisaux-gjahz ) and ( umsks eq 'Y' ) and ( shkzg eq 'S' ). endif. t_bsisaux[] = t_bsis[]. delete t_bsisaux where ( hkont ne '0002104009' ). if ( not t_bsisaux[] is initial ). select bukrs kunnr budat belnr buzei augbl wrbtr hkont gjahr gsber zuonr augdt vbeln from bsid appending table t_bsid for all entries in t_bsisaux where ( bukrs eq t_bsisaux-bukrs ) and ( kunnr eq t_bsisaux-kunnr ) and ( budat eq t_bsisaux-budat ) and ( belnr eq t_bsisaux-belnz ) and ( gjahr eq t_bsisaux-gjahz ) and ( umsks eq ' ' ) . endif.*> Busca contra partidas de crdito dos lanamentos selecionados check ( not t_bsid[] is initial ). sort t_bsid by bukrs kunnr budat belnr.*> Busca contra partidas de crdito dos lanamentos selecionados select bukrs kunnr belnr gjahr belnr buzei wrbtr hkont blart shkzg budat rebzg rebzz rebzj from bsid into table t_compaux for all entries in t_bsid where ( bukrs eq t_bsid-bukrs ) and ( gsber eq t_bsid-gsber ) and ( rebzg eq t_bsid-belnr ) and ( rebzz eq t_bsid-buzei ) and ( rebzj eq t_bsid-gjahr ) and ( shkzg eq 'H' ). sort t_compaux by rebzg rebzz rebzj. loop at t_bsid into wa_bsid. read table t_compaux into wa_compaux with key rebzg = wa_bsid-belnr rebzz = wa_bsid-buzei rebzj = wa_bsid-gjahr binary search. if ( sy-subrc eq 0 ). wa_bsid-augbl = wa_compaux-belnr. wa_bsid-augdt = wa_compaux-budat. modify t_bsid from wa_bsid transporting augbl augdt. endif. endloop. loop at t_compaux into wa_compaux. move-corresponding wa_compaux to wa_compdoc. append wa_compdoc to t_compdoc. endloop. append lines of t_bsid to t_bsad. append lines of t_bsid to t_bsad_full.* T_BSAD_FULL[] = T_BSAD[].endform. " f_busca_partidas_pagas*&---------------------------------------------------------------------**& Form f_elimina_registros*&---------------------------------------------------------------------*form f_elimina_registros. data v_flg type c.*> Elimina comisses que no possuem correspondncia com pagamentos*> feitos pelos clientes sort t_bsad by bukrs kunnr budat belnr. loop at t_bsis into wa_bsis. case wa_bsis-blart.*> Para cargas iniciais o check feito pelo campo zuonr. Com isso tb*> j se garante o pagameto indevido por outra parcela j compensada*> ( GMSS - SPEC ) when 'SN'. wa_zuonr = wa_bsis-zuonr. read table t_bsad into wa_bsad with key belnr = wa_zuonr-belnr buzei = wa_zuonr-buzei. when 'DA'. read table t_bsad into wa_bsad with key zuonr = wa_bsis-zuonr belnr = wa_bsis-belnr. when others. read table t_bsad into wa_bsad with key bukrs = wa_bsis-bukrs kunnr = wa_bsis-kunnr budat = wa_bsis-budat belnr = wa_bsis-belnr binary search. endcase.* Resciso entrar doctos em aberto - silvio 06/03/06 if ( sy-subrc ne 0 and p_rescisao ne '2' ). delete t_bsis. else. if ( wa_bsis-shkzg eq 'S' ). wa_bsis-vbeln = wa_bsad-vbeln. else. wa_bsis-vbeln = wa_bsad-belnr. endif.* ATENO! No ms 08/2006, devido a uma parametrizao errada,* foram geradas numero de doctos contbeis diferente do nro da* fatura de SD IF WA_BSIS-BELNR between '0090000000' AND '0090000084'. wa_bsis-vbeln = wa_bsad-vbeln. ENDIF. modify t_bsis from wa_bsis transporting vbeln. endif. endloop. check ( not t_bsis[] is initial ).*> Elimina pagamentos que no possuem correspondncia com comissoes*> feitos pelos clientes sort t_bsis by bukrs kunnr budat belnr. loop at t_bsad into wa_bsad. clear v_flg. loop at t_bsis into wa_bsis where ( bukrs eq wa_bsad-bukrs ) and ( kunnr eq wa_bsad-kunnr ) and ( budat ge wa_bsad-budat ). case wa_bsis-blart. when 'SN'. wa_zuonr = wa_bsis-zuonr. if ( wa_zuonr-belnr eq wa_bsad-belnr ) and ( wa_zuonr-buzei eq wa_bsad-buzei ). v_flg = c_mark2. endif. when 'DA'. if ( wa_bsis-zuonr eq wa_bsad-zuonr ) and ( wa_bsis-belnr eq wa_bsad-belnr ). v_flg = c_mark2. endif. when others. v_flg = c_mark2. endcase. check ( v_flg eq c_mark2 ). exit. endloop. if ( v_flg ne c_mark2 ). delete t_bsad. loop at t_compdoc into wa_compdoc where ( bukrs eq wa_bsad-bukrs ) and ( kunnr eq wa_bsad-kunnr ) and ( belnr eq wa_bsad-augbl ). delete t_compdoc. endloop. endif. endloop.endform. " f_elimina_registros*&---------------------------------------------------------------------**& Form f_descontos_contencioso*&---------------------------------------------------------------------*form f_descontos_contencioso.*> Monta tabela com compensaes e descobre os descontos, perdas*> pdd e pagamentos realizados na conta cliente normal no momento*> da transferncia para o contencioso. refresh t_compda. t_bsadaux[] = t_bsad[]. delete t_bsadaux where ( hkont ne '0001202002' ). check ( not t_bsadaux[] is initial ). select bukrs kunnr augbl gjahr belnr buzei wrbtr hkont blart shkzg budat from bsad into table t_compda for all entries in t_bsadaux where ( kunnr eq t_bsadaux-kunnr ) and ( bukrs eq t_bsadaux-bukrs ) and ( augbl eq t_bsadaux-belnr ). delete t_compda where ( budat gt p_quinz ).*> Identifica as partidas que so descontos concedidos check ( not t_compda[] is initial ). select bukrs kunnr augbl gjahr belnr buzei wrbtr hkont blart shkzg budat from bsad into table t_contda for all entries in t_compda where ( kunnr eq t_compda-kunnr ) and ( bukrs eq t_compda-bukrs ) and ( augdt eq t_compda-budat ) and ( augbl eq t_compda-belnr ) and ( gjahr eq t_compda-gjahr ) and ( umskz eq ' ' ). check ( sy-subrc eq 0 ). select hkori hkdes tipope from zfitcom001 into table t_parametros for all entries in t_bsadaux where ( hkori eq t_bsadaux-hkont ) and ( ( tipope like 'DP%' ) or ( tipope like 'PP%' ) or ( tipope like 'PD%' ) ). check ( sy-subrc eq 0 ). refresh s_param. loop at t_parametros into wa_parametros. clear s_param. s_param-sign = 'I'. s_param-option = 'EQ'. s_param-low = wa_parametros-hkdes. append s_param. endloop. refresh t_descda. loop at t_contda into wa_contda. select * from bseg into table t_bseg_all where ( bukrs eq wa_contda-bukrs ) and ( belnr eq wa_contda-belnr ) and ( gjahr eq wa_contda-gjahr ) and ( hkont in s_param ) order by primary key. loop at t_bseg_all into wa_bseg_all. clear wa_descda. move-corresponding wa_bseg_all to wa_descda. append wa_descda to t_descda. endloop. endloop. delete adjacent duplicates from t_descda. sort t_descda by bukrs kunnr augbl. sort t_contda by bukrs gjahr belnr. sort t_compda by bukrs kunnr belnr. sort t_bsadaux by bukrs kunnr belnr. loop at t_descda into wa_descda. read table t_contda into wa_contda with key bukrs = wa_descda-bukrs gjahr = wa_descda-gjahr belnr = wa_descda-belnr binary search. check ( sy-subrc eq 0 ). read table t_compda into wa_compda with key bukrs = wa_contda-bukrs kunnr = wa_contda-kunnr belnr = wa_contda-augbl binary search. check ( sy-subrc eq 0 ). read table t_bsadaux into wa_bsad with key bukrs = wa_compda-bukrs kunnr = wa_compda-kunnr belnr = wa_compda-augbl binary search. check ( sy-subrc eq 0 ). wa_descda-bukrs = wa_compda-bukrs. wa_descda-kunnr = wa_compda-kunnr. wa_descda-augbl = wa_bsad-augbl. wa_descda-mark = c_mark2. modify t_descda from wa_descda. endloop. delete t_descda where ( mark eq space ).endform. " f_descontos_contencioso*&---------------------------------------------------------------------**& Form f_descontos_normais*&---------------------------------------------------------------------*form f_descontos_normais.*> Identificar os descontos a serem aplicados sobre as comisses*> como descontos, provisionamento de PDD e perdas. select hkori hkdes tipope from zfitcom001 into table t_parametros for all entries in t_bsad where ( hkori eq t_bsad-hkont ) and ( ( tipope like 'DP%' ) or ( tipope like 'PP%' ) or ( tipope like 'PD%' ) or ( tipope like 'CT%' ) ). check ( sy-subrc eq 0 ). refresh s_param. loop at t_parametros into wa_parametros. clear s_param. s_param-sign = 'I'. s_param-option = 'EQ'. s_param-low = wa_parametros-hkdes. append s_param. endloop. sort t_compdoc by bukrs gjahr belnr.*> Identifica as partidas que so descontos concedidos refresh t_descontos. loop at t_compdoc into wa_compdoc. select * from bseg into table t_bseg_all where ( bukrs eq wa_compdoc-bukrs ) and ( belnr eq wa_compdoc-belnr ) and ( gjahr eq wa_compdoc-gjahr ) and ( hkont in s_param ) order by primary key. loop at t_bseg_all into wa_bseg_all. clear wa_descontos. move-corresponding wa_bseg_all to wa_descontos. append wa_descontos to t_descontos. endloop. endloop. delete adjacent duplicates from t_descontos.*> Ficam somente os descontos concedidos na tabela sort t_descontos by bukrs kunnr augbl. loop at t_descontos into wa_descontos. read table t_compdoc into wa_compdoc with key bukrs = wa_descontos-bukrs gjahr = wa_descontos-gjahr belnr = wa_descontos-belnr binary search. check ( sy-subrc eq 0 ). wa_descontos-bukrs = wa_compdoc-bukrs. wa_descontos-kunnr = wa_compdoc-kunnr. wa_descontos-augbl = wa_compdoc-augbl. wa_descontos-mark = c_mark2. modify t_descontos from wa_descontos. endloop. delete t_descontos where ( mark eq space ).endform. " f_descontos_normais*&---------------------------------------------------------------------**& Form f_descontos_adicionais*&---------------------------------------------------------------------*form f_descontos_adicionais.*> Monta tabela com compensaes e descobre os descontos, perdas*> pdd e pagamentos realizados na conta cliente normal no momento*> da transferncia para o contencioso. refresh t_compda. t_bsadaux[] = t_bsad[]. delete t_bsadaux where ( hkont eq '0001202002' ). check ( not t_bsadaux[] is initial ). select bukrs kunnr augbl gjahr belnr buzei wrbtr hkont blart shkzg budat from bsad into table t_compda for all entries in t_bsadaux where ( kunnr eq t_bsadaux-kunnr ) and ( bukrs eq t_bsadaux-bukrs ) and ( augbl eq t_bsadaux-augbl ). delete t_compda where ( budat gt p_quinz ).*> Identifica as partidas que so descontos concedidos check ( not t_compda[] is initial ). select bukrs kunnr augbl gjahr belnr buzei wrbtr hkont blart shkzg budat from bsad into table t_contda for all entries in t_compda where ( kunnr eq t_compda-kunnr ) and ( bukrs eq t_compda-bukrs ) and ( augdt eq t_compda-budat ) and ( augbl eq t_compda-belnr ) and ( gjahr eq t_compda-gjahr ) and ( umskz eq ' ' ). check ( sy-subrc eq 0 ). select hkori hkdes tipope from zfitcom001 into table t_parametros for all entries in t_bsadaux where ( hkori eq t_bsadaux-hkont ) and ( ( tipope like 'DP%' ) or ( tipope like 'PP%' ) or ( tipope like 'PD%' ) or ( tipope like 'CT%' ) ). check ( sy-subrc eq 0 ). refresh s_param. loop at t_parametros into wa_parametros. clear s_param. s_param-sign = 'I'. s_param-option = 'EQ'. s_param-low = wa_parametros-hkdes. append s_param. endloop. refresh t_descaux. loop at t_contda into wa_contda. select * from bseg into table t_bseg_all where ( bukrs eq wa_contda-bukrs ) and ( belnr eq wa_contda-belnr ) and ( gjahr eq wa_contda-gjahr ) and ( hkont in s_param ) order by primary key. loop at t_bseg_all into wa_bseg_all. clear wa_descda. move-corresponding wa_bseg_all to wa_descda. append wa_descda to t_descaux. endloop. endloop. delete adjacent duplicates from t_descaux. sort t_descaux by bukrs kunnr augbl. sort t_contda by bukrs gjahr belnr. sort t_compda by bukrs kunnr belnr. sort t_bsadaux by bukrs kunnr belnr. loop at t_descaux into wa_descda. read table t_contda into wa_contda with key bukrs = wa_descda-bukrs gjahr = wa_descda-gjahr belnr = wa_descda-belnr binary search. check ( sy-subrc eq 0 ). read table t_compda into wa_compda with key bukrs = wa_contda-bukrs kunnr = wa_contda-kunnr belnr = wa_contda-augbl binary search. check ( sy-subrc eq 0 ).* read table t_bsadaux into wa_bsad* with key bukrs = wa_compda-bukrs* kunnr = wa_compda-kunnr* belnr = wa_compda-augbl binary search.** check ( sy-subrc eq 0 ). wa_descda-bukrs = wa_compda-bukrs. wa_descda-kunnr = wa_compda-kunnr. wa_descda-augbl = wa_compda-augbl. wa_descda-mark = c_mark2. modify t_descaux from wa_descda. endloop. delete t_descaux where ( mark eq space ).endform. " f_descontos_contencioso*&---------------------------------------------------------------------**& Form f_rateia_descontos*&---------------------------------------------------------------------*form f_rateia_descontos tables t_desc structure wa_descontos. data: wa_desc like wa_descontos, v_perc type p decimals 3, v_vltotal like bsad-wrbtr.*> Rateia entre as parcelas da compensao o valor do desconto, perdas*> e PDD sort t_compdoc by bukrs kunnr augbl belnr shkzg. refresh t_descaux. loop at t_desc into wa_desc. clear v_vltotal. v_vldesc = wa_desc-wrbtr. loop at t_compdoc into wa_compdoc where ( bukrs eq wa_desc-bukrs ) and ( kunnr eq wa_desc-kunnr ) and ( augbl eq wa_desc-augbl ) and ( shkzg eq 'S' ) and ( blart eq 'RV' ). v_vltotal = v_vltotal + wa_compdoc-wrbtr. endloop. loop at t_compdoc into wa_compdoc where ( bukrs eq wa_desc-bukrs ) and ( kunnr eq wa_desc-kunnr ) and ( augbl eq wa_desc-augbl ) and ( shkzg eq 'S' ) and ( blart eq 'RV' ). v_perc = ( wa_compdoc-wrbtr / v_vltotal ). wa_desc-wrbtr = wa_desc-wrbtr * v_perc. v_vldesc = v_vldesc - wa_desc-wrbtr. wa_desc-belnr = wa_compdoc-belnr. wa_desc-buzei = wa_compdoc-buzei. clear wa_desc-mark. append wa_desc to t_descaux. endloop.*> Qualquer residual do desconto lanado na ltima partida if ( v_vldesc gt 0 ). wa_desc-wrbtr = v_vldesc. collect wa_desc into t_descaux. endif. endloop. t_desc[] = t_descaux[].endform. " f_rateia_descontos*&---------------------------------------------------------------------**& Form f_apura_pagamentos*&---------------------------------------------------------------------**& TELA 0200 - Prepara os dados selecionados para exibio*&---------------------------------------------------------------------**&form f_apura_pagamentos. sort t_bsis by xref3 belnr zuonr. sort t_valida by belnr buzei. sort t_vbrk by vbeln. sort t_bsad_full by bukrs kunnr budat belnr mark descending buzei. sort t_descontos by bukrs kunnr augbl belnr buzei. sort t_descda by bukrs kunnr augbl belnr buzei. sort t_parciais by hkont xref3 zuonr. sort t_parametros by hkdes.*> Leitura dos clientes das faturas ref das comisses call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 80 text = 'Apurando pagamentos a serem realizados ...'. select hkori hkdes tipope from zfitcom001 into table t_parametros for all entries in t_bsad where ( hkori eq t_bsad-hkont ) and ( ( tipope like 'DP%' ) or ( tipope like 'PP%' ) or ( tipope like 'PD%' ) or ( tipope like 'CT%' ) ). sort t_parametros by hkdes. clear v_pagnr. data: lc_bukrs like zfitcom003-bukrs. loop at t_bsis into wa_bsis. lc_bukrs = wa_bsis-bukrs. at new xref3. clear zfitcom003. v_pagnr = v_pagnr + 1. zfitcom003-pagnr = v_pagnr. if ( p_rescisao eq '2' ). zfitcom003-resctr = c_mark2. endif. zfitcom003-bukrs = lc_bukrs. zfitcom003-vkbur = wa_bsis-xref3. zfitcom003-quinzena = p_quinz. zfitcom003-nroseq = 1. append zfitcom003 to t_zfitcom003. endat. clear wa_item. wa_item-pagnr = v_pagnr. wa_item-gjahr = wa_bsis-gjahr. wa_item-belnr = wa_bsis-belnr. wa_item-buzcom = wa_bsis-buzei. wa_item-kunnr = wa_bsis-kunnr. wa_item-blart = wa_bsis-blart. wa_item-bukrs = wa_bsis-bukrs. wa_item-hkont = wa_bsis-hkont. wa_item-zuonr = wa_bsis-zuonr. wa_item-wrbtr = wa_bsis-wrbtr. wa_item-shkzg = wa_bsis-shkzg. clear: v_vlreal, v_vlpgto, v_last_buzei, v_wrbtr. wa_zuonr = wa_bsis-zuonr. if ( wa_bsis-blart eq 'SN' ). loop at t_bsad_full into wa_bsad where ( belnr eq wa_zuonr-belnr ) and ( buzei eq wa_zuonr-buzei ). perform f_grava_parcelas. endloop. elseif ( wa_bsis-blart eq 'DA' ). loop at t_bsad_full into wa_bsad where ( zuonr eq wa_bsis-zuonr ) and ( belnr eq wa_bsis-belnr ). perform f_grava_parcelas. endloop. else. loop at t_bsad_full into wa_bsad where ( bukrs eq wa_bsis-bukrs ) and ( kunnr eq wa_bsis-kunnr ) and ( budat eq wa_bsis-budat ) and ( belnr eq wa_bsis-belnr ). perform f_grava_parcelas. endloop. if sy-subrc ne 0 and p_rescisao eq 2. perform f_grava_parcelas. endif. endif. endloop.*> Calculo do 1/12 e 1/3 no pagamento de resciso if ( p_rescisao eq '2' ). call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 82 text = 'Calculando resciso de comisso ..'. perform f_calcula_rescisao. call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 85 text = 'Calculando resciso de comisso ..'. endif.*> Leitura dos clientes das faturas ref das comisses call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 90 text = 'Calculando impostos ...'. perform f_calcula_impostos. call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 100 text = 'Concluido ...'.endform. " f_apura_pagamentos*&---------------------------------------------------------------------**& Form f_grava_parcelas*&---------------------------------------------------------------------*form f_grava_parcelas. clear: v_vldesc, v_vlperd, v_vlpdd, v_buzei, v_vlcont, v_acumpgt.*> Comea apresentando o valor realizado da parcela at o momento loop at t_valida into wa_valida where ( belnr eq wa_bsad-belnr ) and ( buzei eq wa_bsad-buzei ).* Adicionei o desconto aqui - Slvio em 22.08.2005*> Acumula o valor de pagamento total realizado para o documento v_vlreal = v_vlreal + wa_valida-vlpgto + wa_valida-vldesc.*> Acumula o valor de pagamento total realizado p/ a parcela do docto v_acumpgt = v_acumpgt + wa_valida-vlpgto + wa_valida-vldesc. endloop. if sy-subrc ne 0. clear wa_valida. endif. perform f_apura_descontos tables t_descontos. perform f_apura_descontos tables t_descda. if ( 'DGSN' cs wa_bsis-blart ) and ( wa_bsis-shkzg eq 'S' ). v_vldesc = wa_bsis-wrbtr. wa_item-wrbtr = wa_item-wrbtr * -1. grava_comissao v_vlreal v_vlpgto v_vldesc v_vlperd v_vlpdd. elseif ( 'DASN' cs wa_bsis-blart ) and ( wa_bsis-hkont eq '0002104010' ). read table t_fatori into wa_fatori with key belnr = wa_zuonr-belnr gjahr = wa_zuonr-gjahr buzei = wa_zuonr-buzei binary search. if ( sy-subrc eq 0 ). v_vlfat = wa_fatori-wrbtr. else. v_vlfat = wa_bsad-wrbtr. endif. v_taxcom = wa_bsis-wrbtr / v_vlfat. v_vlpgto = wa_bsis-wrbtr.* Caso essa parcela tenha sido paga, diminui o valor pago v_vlpgto = v_vlpgto - v_acumpgt. v_vldesc = v_vldesc * v_taxcom. v_vlpdd = v_vlpdd * v_taxcom. v_vlperd = v_vlperd * v_taxcom. v_vlpgto = v_vlpgto - v_vldesc - v_vlperd - v_vlpdd. if ( v_vlpgto lt 0 ). clear v_vlpgto. endif. grava_comissao v_vlreal v_vlpgto v_vldesc v_vlperd v_vlpdd. else.* ATENO! No ms 08/2006, devido a uma parametrizao errada,* foram geradas numero de doctos contbeis diferente do nro da* fatura de SD IF WA_BSIS-BELNR between '0090000000' AND '0090000084'. read table t_vbrk into wa_vbrk with key vbeln = wa_bsad-vbeln binary search. if ( sy-subrc ne 0 ). clear t_vbrk. endif. else. read table t_vbrk into wa_vbrk with key vbeln = wa_bsad-belnr binary search. if ( sy-subrc ne 0 ). endif. ENDIF. v_vlfat = wa_vbrk-netwr + wa_vbrk-mwsbk. v_taxcom = wa_vbrk-wrbtr / v_vlfat. v_vlpgto = wa_bsad-wrbtr * v_taxcom.* Caso essa parcela tenha sido paga, diminui o valor pago v_vlpgto = v_vlpgto - v_acumpgt. v_vldesc = v_vldesc * v_taxcom. v_vlpdd = v_vlpdd * v_taxcom. v_vlperd = v_vlperd * v_taxcom. v_vlcont = v_vlcont * v_taxcom. if ( v_vlcont ne 0 ). v_vlcont = v_vlcont + v_vldesc + v_vlpdd + v_vlperd. clear: v_vldesc, v_vlpdd, v_vlperd. endif. v_vlreal = v_vlreal + v_vlcont.*> No deixar de deduzir o valor realizado pois este contem movimentos*> de pagamentos e transferencia para contencioso v_aux1 = wa_bsis-wrbtr - v_vlreal. if ( v_vlpgto gt v_aux1 ). v_vlpgto = v_aux1. else.*> Acrescenta diferena em centavos para a ltima parcela v_aux1 = wa_bsis-wrbtr - v_vlreal - v_vlpgto. if ( v_aux1 lt v_vlpgto ) and ( v_aux1 between 0 and 1 ). v_vlpgto = v_vlpgto + v_aux1. endif. endif. v_vlpgto = v_vlpgto - v_vldesc - v_vlperd - v_vlpdd - v_vlcont. if ( v_vlpgto lt 0 ). clear v_vlpgto. endif. grava_comissao v_vlreal v_vlpgto v_vldesc v_vlperd v_vlpdd. v_vlreal = v_vlreal + v_vlpgto + v_vldesc + v_vlperd + v_vlpdd.* V_VLREAL_ANT = V_VLREAL. endif.endform. " f_grava_parcelas*&---------------------------------------------------------------------**& Form f_apura_descontos*&---------------------------------------------------------------------*form f_apura_descontos tables t_desc structure wa_descontos. data wa_desc like wa_descontos. loop at t_desc into wa_desc where ( bukrs eq wa_bsad-bukrs ) and ( kunnr eq wa_bsad-kunnr ) and ( augbl eq wa_bsad-augbl ). if ( wa_bsis-blart eq 'RV' ) or ( wa_bsis-blart eq 'SN' and wa_bsis-hkont = '0002104009' ).*> Checa se o desconto proporcional a parcela check ( wa_desc-belnr eq wa_bsad-belnr ) and ( wa_desc-buzei eq wa_bsad-buzei ). endif. read table t_parametros into wa_parametros with key hkdes = wa_desc-hkont binary search. if ( sy-subrc ne 0 ). clear wa_parametros. endif. case wa_parametros-tipope(2). when 'DP'. v_vldesc = v_vldesc + wa_desc-wrbtr. when 'PP'. v_vlperd = v_vlperd + wa_desc-wrbtr. when 'PD'. v_vlpdd = v_vlpdd + wa_desc-wrbtr. when 'CT'. v_vlcont = v_vlcont + wa_desc-wrbtr. endcase. endloop.endform. " f_apura_descontos*&---------------------------------------------------------------------**& Form f_calcula_rescisao*&---------------------------------------------------------------------**& Rotina que calcula valores de 1/12 e 1/3 sobre o valor de todos*& os pagamentos realizados e ult. 3 meses respectivamente.*&---------------------------------------------------------------------**&form f_calcula_rescisao. data: v_nroseq like zfitcom003-nroseq, v_ini like zfitcom003-nroseq value 2, v_fim like zfitcom003-nroseq value 1. refresh: t_antigos, t_novos. refresh s_hkon2. clear s_hkon2. s_hkon2-sign = 'I'. s_hkon2-option = 'EQ'. s_hkon2-low = '0002104006'. append s_hkon2. s_hkon2-low = '0002104009'. append s_hkon2. s_hkon2-low = '0002104010'. append s_hkon2.* Se for COVL adiciona tambm a CAMI loop at s_bukrs. if s_bukrs-low = 'COVL'. refresh s_bukrs. clear s_bukrs. s_bukrs-sign = 'I'. s_bukrs-option = 'EQ'. s_bukrs-low = 'CAMI'. append s_bukrs. s_bukrs-sign = 'I'. s_bukrs-option = 'EQ'. s_bukrs-low = 'COVL'. append s_bukrs. ENDIF. endloop.*> Seleciona pagamentos realizados fora do R/3 select * from zfitcom010 into table t_antigos for all entries in t_tvbur1 where ( vkbur eq t_tvbur1-vkbur ).*> L todos os pagamentos a credito realizados ao representante no*> estornados. check ( not t_auxlfa1[] is initial ). select t1~bukrs t1~belnr t1~buzei t1~gjahr t1~gsber t1~blart t1~budat t1~skfbt t1~lifnr t1~xblnr from bsak as t1 inner join bkpf as t2 on t2~bukrs eq t1~bukrs and t2~belnr eq t1~belnr and t2~gjahr eq t1~gjahr into table t_novos for all entries in t_auxlfa1*BDS-02.09.04 Buscar tambm faturas representante da CAMI-PEDENCIA 1035* where ( t1~bukrs eq 'COVL' )* where ( t1~bukrs eq 'COVL' ) or ( t1~bukrs eq 'CAMI' ) where ( t1~bukrs in s_bukrs )*BDS-Fim - 02.09.04 and ( t1~lifnr eq t_auxlfa1-lifnr ) and ( t1~umsks eq ' ' ) and ( t1~shkzg eq 'H' ) and ( t2~stblg eq space ). " estornado if ( sy-subrc eq 0 ).*> Identifica quais pagamentos so referentes as contas de comisso select bukrs belnr gjahr from bseg into table t_bseg1 for all entries in t_novos where ( bukrs eq t_novos-bukrs ) and ( belnr eq t_novos-belnr ) and ( gjahr eq t_novos-gjahr ) and ( buzei ne t_novos-buzei ) and ( hkont in s_hkon2 ). sort t_bseg1 by bukrs belnr gjahr. loop at t_novos into wa_novos. read table t_bseg1 into wa_bseg1 with key bukrs = wa_novos-bukrs belnr = wa_novos-belnr gjahr = wa_novos-gjahr binary search. check ( sy-subrc ne 0 ). delete t_novos. endloop. endif.*> Aplica correo sobre as comisses do representante select * from zfitcom009 into table t_indices where ( indice eq 'CORR' ). sort t_indices by indice mes ano. call function 'CONVERT_DATE_BY_PERIOD_OUTPUT' EXPORTING i_idate = sy-datum i_iprkz = '2' IMPORTING o_edate = wa_data EXCEPTIONS invalid_period = 1 invalid_date = 2 others = 3. if ( sy-subrc eq 0 ). read table t_indices into wa_indices with key indice = 'CORR' mes = wa_data-mes ano = wa_data-ano binary search. if ( sy-subrc ne 0 ). message w999(zarm) with text-m34. endif. endif. refresh t_base12.*> Verifica representantes que ainda no possuem header*> Nova header para os itens de resciso (1/3) e (1/12) sort t_zfitcom003 by vkbur. loop at t_auxlfa1 into wa_auxlfa1. read table t_zfitcom003 into zfitcom003 with key vkbur = wa_auxlfa1-vkbur binary search. if ( sy-subrc ne 0 ). clear zfitcom003. endif. v_nroseq = zfitcom003-nroseq + 1. clear zfitcom003. v_pagnr = v_pagnr + 1. zfitcom003-pagnr = v_pagnr. zfitcom003-resctr = c_mark2. zfitcom003-vkbur = wa_auxlfa1-vkbur. ZFITCOM003-BUKRS = WA_AUXLFA1-BUKRS. zfitcom003-quinzena = p_quinz. zfitcom003-nroseq = v_nroseq. append zfitcom003 to t_zfitcom003. endloop. sort t_antigos by vkbur dtpgto. sort t_zfitcom003 by vkbur nroseq. loop at t_antigos into wa_antigos. at new vkbur.*> Identifica a sequencia correta para a resciso do 2 times varying v_nroseq from v_ini next v_fim. read table t_zfitcom003 into zfitcom003 with key vkbur = wa_antigos-vkbur nroseq = v_nroseq binary search. if ( sy-subrc eq 0 ). exit. else. clear zfitcom003. endif. enddo. endat. check ( wa_antigos-quinzena is initial ). clear wa_base12.*> wa_base12-mand = sy-mandt. wa_base12-pagnr = zfitcom003-pagnr. perform f_aplica_correcao using wa_antigos-dtpgto wa_antigos-vlpgto changing wa_base12-vlcorr. if ( wa_base12-vlcorr is initial ). wa_base12-vlcorr = wa_antigos-vlpgto. endif. wa_base12-xblnr = wa_antigos-nfnum. wa_base12-dtpgto = wa_antigos-dtpgto. wa_base12-vlpgto = wa_antigos-vlpgto. wa_base12-tipo = 'D'. append wa_base12 to t_base12. endloop. loop at t_novos into wa_novos. clear wa_base12.*> wa_base12-mand = sy-mandt. perform f_aplica_correcao using wa_novos-budat wa_novos-skfbt changing wa_base12-vlcorr. read table t_auxlfa1 into wa_auxlfa1 with key lifnr = wa_novos-lifnr. if ( sy-subrc ne 0 ). clear wa_auxlfa1. endif. do 2 times varying v_nroseq from v_ini next v_fim. read table t_zfitcom003 into zfitcom003 with key vkbur = wa_auxlfa1-vkbur nroseq = v_nroseq binary search. if ( sy-subrc eq 0 ). exit. else. clear zfitcom003. endif. enddo. wa_base12-pagnr = zfitcom003-pagnr. wa_base12-bukrs = wa_novos-bukrs. wa_base12-belnr = wa_novos-belnr. wa_base12-gjahr = wa_novos-gjahr. wa_base12-buzei = wa_novos-buzei. wa_base12-xblnr = wa_novos-xblnr. wa_base12-dtpgto = wa_novos-budat. wa_base12-vlpgto = wa_novos-skfbt. wa_base12-tipo = 'D'. append wa_base12 to t_base12. endloop.*> Calcula 1/12 sobre o valor total da base sort t_base12 by pagnr dtpgto descending. loop at t_base12 into wa_base12. at new pagnr. clear v_nroite. sum. clear wa_item.*> wa_item-mandt = sy-mandt. wa_item-pagnr = wa_base12-pagnr. wa_item-belnr = '9999999999'. wa_item-buzei = '001'. wa_item-blart = '12'. wa_item-wrbtr = wa_base12-vlcorr / 12. wa_item-vlpgto = wa_item-wrbtr. wa_item-bukrs = 'COVL'. wa_item-gsber = 'OV01'. append wa_item to t_zfitcom004. endat. v_nroite = v_nroite + 1. wa_base12-nroite = v_nroite. modify t_base12 from wa_base12. endloop. t_oldbase[] = t_base12[].*> Calcula 1/3 sobre o valor dos ltimos 3 meses de pagamento*> identifica os ltimos 3 meses call function 'RP_CALC_DATE_IN_INTERVAL' EXPORTING date = p_quinz days = 0 months = 3 signum = '-' years = 0 IMPORTING calc_date = v_datini. v_datini+06(2) = 1. call function 'RP_CALC_DATE_IN_INTERVAL' EXPORTING date = p_quinz days = 0 months = 1 signum = '-' years = 0 IMPORTING calc_date = v_datfin. call function 'RP_LAST_DAY_OF_MONTHS' EXPORTING day_in = v_datfin IMPORTING last_day_of_month = v_datfin. delete t_novos where ( budat lt v_datini ) or ( budat gt v_datfin ). loop at t_novos into wa_novos. read table t_auxlfa1 into wa_auxlfa1 with key lifnr = wa_novos-lifnr. if ( sy-subrc ne 0 ). clear wa_auxlfa1. endif. do 2 times varying v_nroseq from v_ini next v_fim. read table t_zfitcom003 into zfitcom003 with key vkbur = wa_auxlfa1-vkbur nroseq = v_nroseq binary search. if ( sy-subrc eq 0 ). exit. else. clear zfitcom003. endif. enddo. clear wa_item. perform f_aplica_correcao using wa_novos-budat wa_novos-skfbt changing wa_item-wrbtr. wa_item-pagnr = zfitcom003-pagnr. wa_item-belnr = '9999999999'. wa_item-buzei = '002'. wa_item-blart = '03'. wa_item-wrbtr = ( wa_item-wrbtr / 3 ). wa_item-vlpgto = wa_item-wrbtr. wa_item-bukrs = 'COVL'. wa_item-gsber = 'OV01'. collect wa_item into t_zfitcom004. endloop.endform. " f_calcula_rescisao*&---------------------------------------------------------------------**& Form f_aplica_correcao*&---------------------------------------------------------------------**& Rotina de calculo da correo*&---------------------------------------------------------------------**&form f_aplica_correcao using value(p_dtpgto) value(p_vlpgto) changing p_valor. p_valor = p_vlpgto. call function 'CONVERT_DATE_BY_PERIOD_OUTPUT' EXPORTING i_idate = p_dtpgto i_iprkz = '2' IMPORTING o_edate = wa_data EXCEPTIONS invalid_period = 1 invalid_date = 2 others = 3. check ( sy-subrc eq 0 ). read table t_indices into wa_indices with key indice = 'CORR' mes = wa_data-mes ano = wa_data-ano binary search. check ( sy-subrc eq 0 ). p_vlpgto = p_vlpgto / wa_indices-valind. call function 'CONVERT_DATE_BY_PERIOD_OUTPUT' EXPORTING i_idate = sy-datum i_iprkz = '2' IMPORTING o_edate = wa_data EXCEPTIONS invalid_period = 1 invalid_date = 2 others = 3. check ( sy-subrc eq 0 ). read table t_indices into wa_indices with key indice = 'CORR' mes = wa_data-mes ano = wa_data-ano binary search. check ( sy-subrc eq 0 ). p_valor = p_vlpgto * wa_indices-valind.endform. " f_aplica_correcao*&---------------------------------------------------------------------**& Form f_calcula_impostos*&---------------------------------------------------------------------**& Rotina de calculo para impostos*&---------------------------------------------------------------------**&form f_calcula_impostos. refresh: t_kna1, t_lfbw. t_auxtcom004[] = t_zfitcom004[]. sort t_auxtcom004 by kunnr. delete adjacent duplicates from t_auxtcom004 comparing kunnr. select kunnr name1 ort01 from kna1 into table t_kna1 for all entries in t_auxtcom004 where ( kunnr eq t_auxtcom004-kunnr ). sort t_zfitcom004 by pagnr belnr buzei. read table t_zfitcom004 into wa_item index 1. select t1~lifnr t1~witht t1~wt_withcd t3~qproz t3~qsatz t1~wt_subjct t4~text40 from lfbw as t1 inner join lfa1 as t2 on t2~lifnr eq t1~lifnr inner join t059z as t3 on t3~land1 eq t2~land1 and t3~witht eq t1~witht and t3~wt_withcd eq t1~wt_withcd inner join t059u as t4 on t4~spras eq sy-langu and t4~land1 eq t2~land1 and t4~witht eq t1~witht into corresponding fields of table t_lfbw for all entries in t_auxlfa1 where ( t1~lifnr eq t_auxlfa1-lifnr ) and ( t1~bukrs eq wa_item-bukrs ). sort t_lfbw by lifnr. refresh t_lfbwaux.*> Seleciona o valor do IR R9 para substituir qdo for rescisao. select single t1~witht t1~wt_withcd t1~qproz t1~qsatz t2~text40 from t059z as t1 inner join t059u as t2 on t2~spras eq sy-langu and t2~land1 eq t1~land1 and t2~witht eq t1~witht into wa_lfbw_r9 where ( t1~land1 eq 'BR' ) and ( t1~witht eq 'IR' ) and ( t1~wt_withcd eq 'R9' ). loop at t_auxlfa1 into wa_auxlfa1.* READ TABLE T_LFBW INTO WA_LFBW WITH KEY LIFNR = WA_AUXLFA1-LIFNR* BINARY SEARCH.* CHECK ( SY-SUBRC EQ 0 ). loop at t_lfbw into wa_lfbw where lifnr = wa_auxlfa1-lifnr.*> Identifica o nro de sequencias a gerar imposto e qdo estiver na*> sequencia que existir resciso imputar o imposto R9 ao invs do pr-*> existente. loop at t_zfitcom003 into zfitcom003 where ( vkbur eq wa_auxlfa1-vkbur ). if ( wa_lfbw-wt_subjct eq c_mark2 ) and ( wa_lfbw-witht eq 'IR' ). loop at t_zfitcom004 into wa_item where ( pagnr eq zfitcom003-pagnr ) and ( belnr eq '9999999999' ). endloop. if ( sy-subrc eq 0 ). move-corresponding wa_lfbw_r9 to wa_lfbw. endif. endif. wa_lfbw-vkbur = wa_auxlfa1-vkbur. wa_lfbw-nroseq = zfitcom003-nroseq. append wa_lfbw to t_lfbwaux. endloop. endloop. endloop. t_lfbw[] = t_lfbwaux[].* Slvio 04/07/2006 -* Estava calculando imposto em duplicidade para os pagamentos que j* existiam- Notei que a tabela abaixo vem com a mesma quantidade de* registros da tabela t_zfitcom003. delete adjacent duplicates from t_lfbw.* end loop at t_lfbw into wa_lfbw. check ( wa_lfbw-wt_subjct eq c_mark2 ). wa_lfbw-vlimp = ( wa_item-vlpgto * wa_lfbw-qproz ) / 100. wa_lfbw-vlimp = ( wa_lfbw-vlimp * wa_lfbw-qsatz ) / 100. if ( wa_lfbw-witht eq 'IR' and wa_lfbw-vlimp < 10 ). clear wa_lfbw-vlimp. endif. modify t_lfbw from wa_lfbw transporting vlimp. endloop. sort t_lfbw by vkbur lifnr.endform. " f_calcula_impostos*&---------------------------------------------------------------------**& Form f_gera_arquivo*&---------------------------------------------------------------------**& Rotina de impresso em spool para que o disparador envio para*& os vendedores a noite*&---------------------------------------------------------------------**&form f_gera_arquivo. clear v_totproc. if ( p_background eq c_mark2 ). wa_item-mark = c_mark2. modify t_zfitcom004 from wa_item transporting mark where ( mark ne c_mark2 ). v_print_mode = 'BATCH'. else. clear v_print_mode. endif. perform f_analisa_devolucao. delete t_zfitcom004 where ( mark ne c_mark2 ). delete t_base12 where ( mark ne c_mark2 ). describe table t_zfitcom003 lines v_totpgt. loop at t_zfitcom003 into zfitcom003. t_auxiliar[] = t_zfitcom004[]. delete t_auxiliar where ( pagnr ne zfitcom003-pagnr ). perform f_calcula_totais tables t_auxiliar t_lfbw t_auxlfa1 changing zfiecom002-totalnf zfiecom002-totcom zfiecom002-totimp. if ( zfiecom002-totalnf le 0 ). delete t_zfitcom003. delete t_zfitcom004 where ( pagnr eq zfitcom003-pagnr ). endif. endloop.* Previnir duplicidade de registros no spool sort t_zfitcom004. delete adjacent duplicates from t_zfitcom004. export t_zfitcom003 to memory id 'C001'. export t_zfitcom004 to memory id 'C002'. export t_lfbw to memory id 'C003'. export t_auxlfa1 to memory id 'C004'. export t_kna1 to memory id 'C005'. export v_totproc to memory id 'CTOT'. submit zficomr006 and return. import v_totproc from memory id 'CTOT'. zfitcom003-uscal = sy-uname. zfitcom003-dtcal = sy-datum. zfitcom003-hrcal = sy-uzeit. zfitcom003-status = '1'. modify t_zfitcom003 from zfitcom003 transporting uscal dtcal hrcal status where ( status ne '1' ). concatenate 'Foram processados' v_totpgt 'pagamentos,' into v_text separated by space. concatenate 'onde' v_totproc 'foram criados com sucesso!' into v_text2 separated by space. check ( p_background is initial ). message i999(zarm) with v_text v_text2.endform. " f_gera_arquivo*&---------------------------------------------------------------------**& Form f_analisa_devolucao*&---------------------------------------------------------------------** Analisar o total por divisao e identificar se o valor maior* ou igual ao das devoluoes.*----------------------------------------------------------------------*form f_analisa_devolucao. data: begin of wa_analise, pagnr like zfitcom004-pagnr, gsber like zfitcom004-gsber, vlpgto like zfitcom004-vlpgto, end of wa_analise, v_totmark(4) type n, v_textline(80), wa_auxitem like wa_item, t_analise like standard table of wa_analise. sort t_zfitcom004 by shkzg mark. loop at t_zfitcom004 into wa_auxitem where ( shkzg ne 'S' ) and ( mark eq c_mark2 ). clear wa_analise. wa_analise-pagnr = wa_auxitem-pagnr. wa_analise-gsber = wa_auxitem-gsber. wa_analise-vlpgto = wa_auxitem-vlpgto. collect wa_analise into t_analise. endloop. sort t_analise by pagnr gsber. sort t_zfitcom004 by shkzg mark vldesc descending. loop at t_zfitcom004 into wa_auxitem where ( shkzg eq 'S' ) and ( mark eq c_mark2 ). read table t_analise into wa_analise with key pagnr = wa_auxitem-pagnr gsber = wa_auxitem-gsber binary search. if ( sy-subrc eq 0 ). if ( wa_analise-vlpgto ge wa_auxitem-vldesc ). wa_analise-vlpgto = wa_analise-vlpgto - wa_auxitem-vldesc. modify t_analise from wa_analise index sy-tabix transporting vlpgto. else. clear wa_auxitem-mark. endif. else. clear wa_auxitem-mark. endif. if ( wa_auxitem-mark ne c_mark2 ). v_totmark = v_totmark + 1. modify t_zfitcom004 from wa_auxitem transporting mark. endif. endloop. concatenate v_totmark 'devolues foram desmarcadas devido a saldo' into v_textline separated by space. check ( p_background is initial ). call function 'POPUP_TO_DISPLAY_TEXT' EXPORTING titel = 'Devolues desmarcadas no pagamento' textline1 = v_textline textline2 = 'insuficiente em suas respectivas divises.'.endform. " f_analisa_devolucao*&---------------------------------------------------------------------**& Form f_calcula_totais*&---------------------------------------------------------------------**& Rotina que calcula valores dos impostos e totais finais*&---------------------------------------------------------------------**&form f_calcula_totais tables itens structure zfitcom004 impostos structure zfiecom001 lfa1 type zfico_fornec changing p_nota p_comissao p_imposto. data: v_basecalc like zfitcom004-vlpgto, wa_itens like zfitcom004, wa_impostos like zfiecom001, wa_auxlfa1 like lfa1. sort itens by pagnr. sort impostos by vkbur lifnr. clear: p_imposto, p_nota, p_comissao, v_totdev. loop at itens into wa_itens. if ( wa_itens-shkzg eq 'S' ). v_totdev = v_totdev + wa_itens-vldesc. endif. at end of pagnr. sum. p_nota = ( wa_itens-vlpgto - v_totdev ). clear v_totdev. read table t_zfitcom003 into zfitcom003 with key pagnr = wa_itens-pagnr binary search. if ( sy-subrc ne 0 ). clear zfitcom003. endif. read table lfa1 into wa_auxlfa1 with key vkbur = zfitcom003-vkbur. if ( sy-subrc ne 0 ). clear wa_auxlfa1. endif. if ( p_nota le 0 ). clear: wa_impostos-vlimp, p_imposto. modify impostos from wa_impostos transporting vlimp where ( vkbur eq wa_auxlfa1-vkbur ) and ( lifnr eq wa_auxlfa1-lifnr ) and ( nroseq eq zfitcom003-nroseq ) and ( wt_subjct eq 'X' ). else. loop at impostos into wa_impostos where ( vkbur eq wa_auxlfa1-vkbur ) and ( lifnr eq wa_auxlfa1-lifnr ) and ( nroseq eq zfitcom003-nroseq ) and ( wt_subjct eq 'X' ). wa_impostos-vlimp = ( p_nota * wa_impostos-qproz ) / 100. wa_impostos-vlimp = ( wa_impostos-vlimp * wa_impostos-qsatz ) / 100. if ( wa_impostos-witht eq 'IR' and wa_impostos-vlimp < 10 ). clear wa_impostos-vlimp. endif. modify impostos from wa_impostos transporting vlimp. p_imposto = p_imposto + wa_impostos-vlimp. endloop. endif. endat. endloop.* if ( p_imposto is initial ).* wa_impostos-vlimp = p_imposto.* modify impostos from wa_impostos transporting vlimp* where ( vlimp ne 0 ).* endif. p_comissao = p_nota - p_imposto.endform. " f_calcula_totais*&---------------------------------------------------------------------**& Form f_imprime*&---------------------------------------------------------------------**& Rotina de impresso de vendedores*&---------------------------------------------------------------------**&form f_imprime using value(p_tabix). data: wa_listaaux like wa_lista, wa_zfitcom004 like zfitcom004. sort t_auxlfa1 by vkbur. sort t_vbrk by vbeln. sort t_zfitcom003 by vkbur quinzena pagnr. sort t_zfitcom004 by pagnr belnr buzei. loop at t_zfitcom004 into wa_zfitcom004. clear wa_ref. wa_ref-belnr = wa_zfitcom004-belnr. wa_ref-bukrs = wa_zfitcom004-bukrs. wa_ref-kunnr = wa_zfitcom004-kunnr. if ( wa_zfitcom004-zuonr(2) eq '16' ). wa_ref-zuonr = wa_zfitcom004-zuonr(10). if ( wa_zfitcom004-hkont eq '0002104009' ). append wa_ref to t_refdev. else. append wa_ref to t_refcto. endif. else. wa_ref-vbeln = wa_zfitcom004-zuonr(10). append wa_ref to t_ref. endif. endloop. sort t_refcto by kunnr bukrs zuonr. sort t_refdev by kunnr bukrs zuonr. if ( not t_refcto[] is initial ). select bukrs kunnr augbl belnr vbeln from bsad into table t_partidas for all entries in t_refcto where ( kunnr eq t_refcto-kunnr ) and ( bukrs eq t_refcto-bukrs ) and ( augbl eq t_refcto-zuonr ) and ( blart eq 'RV' ). loop at t_partidas into wa_partidas. read table t_refcto into wa_ref with key kunnr = wa_partidas-kunnr bukrs = wa_partidas-bukrs zuonr = wa_partidas-augbl binary search. check ( sy-subrc eq 0 ). wa_ref-vbeln = wa_partidas-belnr. modify t_refcto from wa_ref index sy-tabix transporting vbeln. endloop. endif. if ( not t_refdev[] is initial ). select bukrs kunnr augbl belnr vbeln from bsad into table t_partidas for all entries in t_refdev where ( bukrs eq t_refdev-bukrs ) and ( kunnr eq t_refdev-kunnr ) and ( belnr eq t_refdev-zuonr ). select bukrs kunnr augbl belnr vbeln from bsid appending table t_partidas for all entries in t_refdev where ( kunnr eq t_refdev-kunnr ) and ( bukrs eq t_refdev-bukrs ) and ( belnr eq t_refdev-zuonr ). loop at t_partidas into wa_partidas. read table t_refdev into wa_ref with key kunnr = wa_partidas-kunnr bukrs = wa_partidas-bukrs zuonr = wa_partidas-belnr binary search. check ( sy-subrc eq 0 ). wa_ref-vbeln = wa_partidas-vbeln. modify t_refdev from wa_ref index sy-tabix transporting vbeln. endloop. if not t_refdev is initial. select vbeln vbelv from vbfa into table t_vbfa for all entries in t_refdev where ( vbeln eq t_refdev-vbeln ) and ( posnn ge 10 ) and ( vbtyp_n eq 'O' ) and ( vbtyp_v eq 'M' ). endif. delete adjacent duplicates from t_vbfa comparing vbeln. sort t_refdev by vbeln. loop at t_vbfa into wa_vbfa. read table t_refdev into wa_ref with key vbeln = wa_vbfa-vbeln binary search. check ( sy-subrc eq 0 ). wa_ref-vbeln = wa_vbfa-vbelv. modify t_refdev from wa_ref index sy-tabix transporting vbeln. endloop. endif. append lines of t_refcto to t_ref. append lines of t_refdev to t_ref. delete t_ref where ( vbeln eq 0 ). sort t_ref by belnr vbeln. if not t_ref[] is initial. select vbeln vbelv from vbfa into table t_vbfa for all entries in t_ref where ( vbeln eq t_ref-vbeln ) and ( posnn ge 10 ) and ( vbtyp_n eq 'M' or vbtyp_n eq 'O' ) and ( vbtyp_v eq 'C' or vbtyp_v eq 'E' or vbtyp_v eq 'H' ). endif. delete adjacent duplicates from t_vbfa comparing vbeln. select t1~vbeln t1~netwr t1~mwsbk t1~xblnr from vbrk as t1 inner join vbrp as t2 on t2~vbeln eq t1~vbeln into table t_fatura for all entries in t_ref where ( t1~vbeln eq t_ref-vbeln ). sort t_fatura by vbeln. sort t_vbfa by vbeln. if ( not p_tabix is initial ). read table t_zfitcom003 into zfitcom003 index p_tabix. move-corresponding zfitcom003 to wa_lista. wa_listaaux = wa_lista. quebra wa_lista-vkbur wa_lista-pagnr wa_lista-quinzena wa_lista-nfnum. perform f_imprime_itens. total_geral. else. refresh t_lista. loop at t_zfitcom003 into zfitcom003. move-corresponding zfitcom003 to wa_lista. append wa_lista to t_lista. endloop. sort t_lista by vkbur quinzena pagnr. loop at t_lista into wa_lista. wa_listaaux = wa_lista. at new pagnr. quebra wa_lista-vkbur wa_lista-pagnr wa_lista-quinzena wa_listaaux-nfnum. endat. perform f_imprime_itens. at end of pagnr. total_geral. endat. endloop. endif.endform. " f_imprime*&---------------------------------------------------------------------**& Form f_imprime_itens*&---------------------------------------------------------------------**& Rotina de impresso dos itens de comisso*&---------------------------------------------------------------------**&form f_imprime_itens. data: v_flag type c, v_text(40) type c, v_belnr like bsid-belnr, v_oldite like zfitcom004-belnr, v_auxreal like zfitcom004-vlreal, v_auxpgto like zfitcom004-vlpgto, v_ultpgto like zfitcom004-vlpgto. clear: v_totcom, v_vlreal, v_vldiff, v_oldite. loop at t_zfitcom004 into wa_item where ( pagnr eq wa_lista-pagnr ). check ( wa_item-mark eq c_mark2 ). at new belnr. clear: v_auxreal, v_auxpgto, v_ultpgto. endat. if ( v_flag is initial ).* format color col_normal intensified on. format reset. v_flag = c_mark2. else.* format color col_normal intensified off. format reset. clear v_flag. endif. read table t_kna1 into wa_kna1 with table key kunnr = wa_item-kunnr. if ( sy-subrc ne 0 ). clear wa_kna1. endif. read table t_ref into wa_ref with key belnr = wa_item-belnr binary search. if ( sy-subrc ne 0 ). clear wa_ref. endif. read table t_vbfa into wa_vbfa with key vbeln = wa_ref-vbeln binary search. if ( sy-subrc ne 0 ). clear wa_vbfa. endif. read table t_fatura into wa_fatura with key vbeln = wa_ref-vbeln binary search. if ( sy-subrc ne 0 ). clear wa_fatura. endif. concatenate wa_item-kunnr '-' wa_kna1-name1 into v_text separated by space. if ( wa_item-belnr eq '9999999999' ). if ( wa_item-buzei eq 1 ). v_text = 'Indenizao 1/12 sobre todos pagamentos'. else. v_text = 'Acerto 1/3 sobre 3 ltimos meses pgtos'. endif. endif. v_nroitem = v_nroitem + 1. if ( v_oldite ne wa_item-belnr ) or ( v_oldite eq wa_item-belnr and wa_item-blart ne 'RV' ). if ( wa_item-shkzg ne 'S' ). v_wrbtr = v_wrbtr + wa_item-wrbtr. endif. v_oldite = wa_item-belnr. endif. if ( wa_item-shkzg ne 'S' ). wa_item-vlpgto = wa_item-vlpgto + wa_item-vldesc + wa_item-vlperd + wa_item-vlpdd. v_vlpgto = v_vlpgto + wa_item-vlpgto. endif. v_vldesc = v_vldesc + wa_item-vldesc. wa_item-vlperd = wa_item-vlperd + wa_item-vlpdd. v_vlperd = v_vlperd + wa_item-vlperd. v_vlsald = v_vlsald + wa_item-vlsald. write: at /01(01) sy-vline no-gap, 03(04) v_nroitem, 08(1) sy-vline no-gap, 09(10) wa_item-belnr, 20(1) sy-vline no-gap, 22(03) wa_item-buzei, 26(1) sy-vline no-gap, 27(10) wa_vbfa-vbelv, 38(1) sy-vline no-gap, 39(16) wa_fatura-xblnr, 56(1) sy-vline no-gap, 57(40) v_text, 98(1) sy-vline no-gap, 99(30) wa_kna1-ort01, 130(1) sy-vline no-gap, 131(16) wa_item-wrbtr, 148(1) sy-vline no-gap, 149(16) wa_item-vlreal, 166(1) sy-vline no-gap, 167(16) wa_item-vlpgto, 184(1) sy-vline no-gap, 185(16) wa_item-vldesc, 202(1) sy-vline no-gap, 203(16) wa_item-vlperd, 220(1) sy-vline no-gap, 221(16) wa_item-vlsald, at sy-linsz sy-vline no-gap. if ( wa_item-blart eq 'RV' ). v_auxreal = wa_item-vlreal. v_auxpgto = v_auxpgto + wa_item-vlpgto. v_ultpgto = wa_item-vlpgto. else. v_auxreal = v_auxreal + wa_item-vlreal. endif. at end of belnr. v_vlreal = v_vlreal + v_auxreal. v_vldiff = v_vldiff + v_auxpgto - v_ultpgto. endat. endloop.endform. " f_imprime_itens*&---------------------------------------------------------------------**& Form f_grava_dados*&---------------------------------------------------------------------**& Rotina para gravar dados nas tabelas de pagamento*&---------------------------------------------------------------------**&form f_grava_dados. data: v_lintab1 type i, v_lintab2 type i, v_lintab3 type i, v_lintab4 type i. describe table t_zfitcom003 lines v_lintab1. sort t_zfitcom004. describe table t_base12 lines v_lintab3. delete adjacent duplicates from t_zfitcom004. describe table t_zfitcom004 lines v_lintab2. if ( p_code100 eq 'CRIA' ). perform f_ajusta_pagnr. insert zfitcom003 from table t_zfitcom003. if ( sy-dbcnt ne v_lintab1 ). rollback work. message w999(zarm) with text-m08. exit. endif. insert zfitcom004 from table t_zfitcom004. if ( sy-dbcnt ne v_lintab2 ). rollback work. message w999(zarm) with text-m09. exit. endif. insert zfitcom011 from table t_base12. if ( sy-dbcnt ne v_lintab3 ). rollback work. message w999(zarm) with text-m22. exit. endif. else. update zfitcom003 from table t_zfitcom003. if ( sy-dbcnt ne v_lintab1 ). rollback work. message w999(zarm) with text-m10. exit. endif. update zfitcom004 from table t_zfitcom004. if ( sy-dbcnt ne v_lintab2 ). rollback work. message w999(zarm) with text-m11. exit. endif. if ( p_code100 eq 'PAGA' ). select * from zfitcom010 into table t_antigos for all entries in t_zfitcom003 where ( vkbur eq t_zfitcom003-vkbur ). sort t_antigos by vkbur dtpgto. if ( sy-subrc eq 0 ). loop at t_zfitcom003 into wa_aux1 where ( resctr eq c_mark2 ). loop at t_base12 into wa_base12 where ( pagnr eq wa_aux1-pagnr ) and ( belnr eq space ). read table t_antigos into wa_antigos with key vkbur = wa_aux1-vkbur dtpgto = wa_base12-dtpgto binary search. check ( sy-subrc eq 0 ). wa_antigos-quinzena = wa_aux1-quinzena. modify t_antigos from wa_antigos index sy-tabix transporting quinzena. endloop. endloop. endif. delete t_antigos where ( quinzena eq space ). describe table t_antigos lines v_lintab4. update zfitcom010 from table t_antigos. if ( sy-dbcnt ne v_lintab4 ). rollback work. message w999(zarm) with text-m24. exit. endif. endif. endif. commit work.endform. " f_grava_dados*&---------------------------------------------------------------------**& Form f_ajusta_pagnr*&---------------------------------------------------------------------**& Rotina de ajuste do nro do pagamento*&---------------------------------------------------------------------**&form f_ajusta_pagnr. loop at t_zfitcom003 into zfitcom003. call function 'NUMBER_GET_NEXT' EXPORTING nr_range_nr = '01' object = 'ZFICOM002' IMPORTING number = v_pagnr EXCEPTIONS interval_not_found = 1 number_range_not_intern = 2 object_not_found = 3 quantity_is_0 = 4 quantity_is_not_1 = 5 interval_overflow = 6 buffer_overflow = 7 others = 8. if sy-subrc 0. message e999(zarm) with text-m25. endif. loop at t_zfitcom004 into zfitcom004 where ( pagnr eq zfitcom003-pagnr ). zfitcom004-pagnr = v_pagnr. modify t_zfitcom004 from zfitcom004. endloop. loop at t_base12 into wa_base12 where ( pagnr eq zfitcom003-pagnr ). wa_base12-pagnr = v_pagnr. modify t_base12 from wa_base12. endloop. zfitcom003-pagnr = v_pagnr. modify t_zfitcom003 from zfitcom003. endloop.endform. " f_ajusta_pagnr*&---------------------------------------------------------------------**& Form init_vars*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*form init_vars using value(p_quinzena) value(p_ucomm) value(p_comissao) value(p_contencioso) value(p_resc) value(p_execjob) p_lfa1 like t_auxlfa1[] p_tvbur like t_tvbur1[] p_xref3 like s_xref3[]. p_quinz = p_quinzena. p_code100 = p_ucomm. p_newcom = p_comissao. p_concom = p_contencioso. p_rescisao = p_resc. p_background = p_execjob. t_auxlfa1[] = p_lfa1[]. t_tvbur1[] = p_tvbur[]. s_xref3[] = p_xref3[].endform. " init_vars*&---------------------------------------------------------------------**& Event top-of-page*&---------------------------------------------------------------------**&top-of-page. format color col_heading intensified on. format reset. v_linsz = sy-linsz - 2. uline at /01(sy-linsz). write at: /01(01) sy-vline no-gap, 02(v_linsz) c_text_r01 centered, sy-linsz(01) sy-vline no-gap. write: at /01(01) sy-vline no-gap, 02(40) c_text_r02 left-justified, "Nome da empresa 65(20) c_text_r03 left-justified, "Texto do programa 76(30) sy-repid, "Programa 136(05) c_text_r04 left-justified, "Texto da data 142(10) sy-datum, "Data 170(05) c_text_r05, "Texto da hora 176(08) sy-uzeit, "hora 228(04) c_text_r06, "Texto da pgina 233(05) sy-pagno, "Pgina atual at sy-linsz(01) sy-vline no-gap. uline at /01(sy-linsz). write: at /01(01) sy-vline no-gap, 03(04) c_text_r07, 08(1) sy-vline no-gap, 09(10) c_text_r08, 20(1) sy-vline no-gap, 22(03) c_text_r09, 26(1) sy-vline no-gap, 27(10) c_text_r10, 38(1) sy-vline no-gap, 39(16) c_text_r23, 56(1) sy-vline no-gap, 57(40) c_text_r11, 98(1) sy-vline no-gap, 99(30) c_text_r12, 130(1) sy-vline no-gap, 131(16) c_text_r13, 148(1) sy-vline no-gap, 149(16) c_text_r14, 166(1) sy-vline no-gap, 167(16) c_text_r15, 184(1) sy-vline no-gap, 185(16) c_text_r16, 202(1) sy-vline no-gap, 203(16) c_text_r17, 220(1) sy-vline no-gap, 221(16) c_text_r18, at sy-linsz sy-vline no-gap.*&---------------------------------------------------------------------**& Event end-of-page*&---------------------------------------------------------------------**&end-of-page. uline at /01(sy-linsz).