*&---------------------------------------------------------------------*
*& Report /XEGR/RWS_EASY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report /xegr/rws_easy.
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
type-pools : slis.
types: begin of ty_ylog,
taxjurcode type /xegr/tegrprefp-taxjurcode,
stcd1 type stcd1,
status type char4,
nf type char15,
message type string,
xstring_header type xstring,
xstring_body type xstring,
xstring_return type xstring,
xml_header type char4,
xml_body type char4,
xml_return type char4,
end of ty_ylog.
data: gt_ylog type standard table of ty_ylog,
gw_ylog type ty_ylog.
data: g_bedat type sy-datum.
data: gt_fieldcatalog type slis_t_fieldcat_alv with header line,
gd_layout type slis_layout_alv,
gd_repid like sy-repid,
g_exit type c.
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
class /xegr/clws_easy_local definition.
public section.
methods execute
importing
!io_bundle type ref to /xegr/clegr_bundle .
types:
begin of ty_yelements,
name type string,
ancestral type string,
elemnt type ref to if_ixml_element,
end of ty_yelements .
data: mo_request_builder type ref to /xegr/clegr_ws_nfse_req_build,
mw_nfse_process type /xegr/tegrprefp,
mw_tegrmdcfg type /xegr/tegrmdcfg,
mt_yelements type standard table of ty_yelements,
mo_ixml type ref to if_ixml,
m_xstring_body type xstring,
m_xstring_header type xstring,
m_xstring_return type xstring,
mo_document type ref to if_ixml_document,
m_xstring type xstring,
mo_xml type ref to cl_xml_document.
class-methods: read_node importing i_key type string
io_xml type ref to cl_xml_document
returning value(r_value) type string.
methods: select_some_data.
methods sign_with_certificate .
methods send_request .
methods add_new_node
importing
!i_nam type any
!i_val type any
!i_anc type any
!i_att type any .
methods get_webservice_request .
methods handle_return .
methods get_certificate
returning
value(ro_certificate) type ref to /xegr/clegr_ws_certificate .
methods get_standard
returning
value(ro_xml) type ref to cl_xml_document .
methods standardise_xml
changing
!co_xml type ref to cl_xml_document .
methods input_to_egr
importing
!io_input type ref to /xegr/ifegr_input_xml
returning
value(rw_txmlk) type /xegr/txmlk .
private section.
data mw_ws_setup type /xegr/tegrwspre .
data mo_bundle type ref to /xegr/clegr_bundle .
methods generate_output_xml
importing
!io_document type ref to if_ixml_document
returning
value(r_xstring) type xstring .
methods sign_request .
endclass.
data: lo_ws_easy type ref to /xegr/clws_easy_local.
selection-screen begin of block b1 with frame title g_b1.
selection-screen begin of line.
selection-screen comment 1(20) g_com1 for field p_txcjd.
parameters: p_txcjd type /xegr/tegrprefp-taxjurcode.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(17) g_dats for field s_date.
select-options s_date for g_bedat.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(20) g_rep for field p_rep.
parameters: p_rep as checkbox.
selection-screen end of line.
selection-screen end of block b1.
initialization.
g_b1 = 'Restrições'.
g_com1 = 'CodDomFiscal'.
g_dats = 'Data de Busca'.
g_rep = 'Gerar Report'.
at line-selection.
break-point.
start-of-selection.
perform start_ws.
end-of-selection.
if p_rep = 'X'.
perform show_report.
endif.
*&---------------------------------------------------------------------*
*& Form SHOW_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form show_report.
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
data: lo_xml type ref to cl_xml_document,
l_string type string.
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
check p_rep = 'X'.
loop at gt_ylog into gw_ylog.
case gw_ylog-status.
when 'E'.
gw_ylog-status = '@02@'.
when others.
gw_ylog-status = '@01@'.
endcase.
if gw_ylog-xstring_body is not initial.
gw_ylog-xml_body = '@R4@'.
endif.
if gw_ylog-xstring_header is not initial.
gw_ylog-xml_header = '@R4@'.
endif.
if gw_ylog-xstring_return is not initial.
gw_ylog-xml_return = '@R4@'.
endif.
"-->Caso sucesso, ler a tag NF
create object lo_xml.
lo_xml->parse_xstring( stream = gw_ylog-xstring_return ).
case gw_ylog-taxjurcode(2).
when 'SP'.
call method /xegr/clws_easy_local=>read_node
exporting
i_key = 'ChaveNFe.NumeroNFe'
io_xml = lo_xml
receiving
r_value = l_string.
when others.
call method /xegr/clws_easy_local=>read_node
exporting
i_key = 'Numero'
io_xml = lo_xml
receiving
r_value = l_string.
endcase.
gw_ylog-nf = l_string.
modify gt_ylog from gw_ylog.
endloop.
perform build_gt_fieldcatalog.
perform display_alv_report.
endform.
form build_gt_fieldcatalog .
clear gt_fieldcatalog.
gt_fieldcatalog-fieldname = 'TAXJURCODE'.
gt_fieldcatalog-seltext_m = 'taxjurcode'.
gt_fieldcatalog-col_pos = 0.
append gt_fieldcatalog to gt_fieldcatalog.
clear gt_fieldcatalog.
clear gt_fieldcatalog.
gt_fieldcatalog-fieldname = 'STCD1'.
gt_fieldcatalog-seltext_m = 'stcd1'.
gt_fieldcatalog-col_pos = 0.
append gt_fieldcatalog to gt_fieldcatalog.
clear gt_fieldcatalog.
clear gt_fieldcatalog.
gt_fieldcatalog-fieldname = 'STATUS'.
gt_fieldcatalog-seltext_m = 'Status'.
gt_fieldcatalog-col_pos = 0.
append gt_fieldcatalog to gt_fieldcatalog.
clear gt_fieldcatalog.
gt_fieldcatalog-fieldname = 'MESSAGE'.
gt_fieldcatalog-seltext_m = 'Message'.
gt_fieldcatalog-col_pos = 1.
append gt_fieldcatalog to gt_fieldcatalog.
clear gt_fieldcatalog.
gt_fieldcatalog-fieldname = 'XML_HEADER'.
gt_fieldcatalog-seltext_m = 'XML Header'.
gt_fieldcatalog-col_pos = 2.
gt_fieldcatalog-outputlen = 4.
append gt_fieldcatalog to gt_fieldcatalog.
clear gt_fieldcatalog.
gt_fieldcatalog-fieldname = 'XML_BODY'.
gt_fieldcatalog-seltext_m = 'XML Body'.
gt_fieldcatalog-col_pos = 3.
gt_fieldcatalog-outputlen = 4.
append gt_fieldcatalog to gt_fieldcatalog.
clear gt_fieldcatalog.
gt_fieldcatalog-fieldname = 'XML_RETURN'.
gt_fieldcatalog-seltext_m = 'XML Return'.
gt_fieldcatalog-col_pos = 3.
gt_fieldcatalog-outputlen = 4.
append gt_fieldcatalog to gt_fieldcatalog.
clear gt_fieldcatalog.
gt_fieldcatalog-fieldname = 'NF'.
gt_fieldcatalog-seltext_m = 'Nf'.
gt_fieldcatalog-col_pos = 4.
gt_fieldcatalog-outputlen = 15.
append gt_fieldcatalog to gt_fieldcatalog.
clear gt_fieldcatalog.
endform. " BUILD_GT_fieldcatalog
form display_alv_report .
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = gt_fieldcatalog[]
i_save = 'X'
tables
t_outtab = gt_ylog
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
endif.
endform. "DISPLAY_ALV_REPORT
form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'Log de Processamento do WS'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
concatenate sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) into wa_header-info.
append wa_header to t_header.
clear: wa_header.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
endform. "top-of-page
form user_command using r_ucomm
ls_selfield type slis_selfield.
clear gw_ylog.
read table gt_ylog into gw_ylog index ls_selfield-tabindex.
case ls_selfield-fieldname.
when 'XML_BODY'.
if gw_ylog-xstring_body is initial.
message 'XML vazio' type 'S'.
return.
endif.
call function 'DISPLAY_XML_STRING'
exporting
xml_string = gw_ylog-xstring_body
title = 'Body XML'
starting_x = 5
starting_y = 5
exceptions
no_xml_document = 1
others = 2.
when 'XML_HEADER'.
if gw_ylog-xstring_header is initial.
message 'XML vazio' type 'S'.
return.
endif.
call function 'DISPLAY_XML_STRING'
exporting
xml_string = gw_ylog-xstring_header
title = 'Header XML'
starting_x = 5
starting_y = 5
exceptions
no_xml_document = 1
others = 2.
when 'XML_RETURN'.
if gw_ylog-xstring_return is initial.
message 'XML vazio' type 'S'.
return.
endif.
call function 'DISPLAY_XML_STRING'
exporting
xml_string = gw_ylog-xstring_return
title = 'Return XML'
starting_x = 5
starting_y = 5
exceptions
no_xml_document = 1
others = 2.
endcase.
endform.
*&---------------------------------------------------------------------*
*& Form START_WS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form start_ws.
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
data: lt_tegrmdcfg type table of /xegr/tegrmdcfg,
lw_tegrmdcfg like line of lt_tegrmdcfg,
lt_nfse_process type table of /xegr/tegrprefp,
lw_nfse_process like line of lt_nfse_process,
lo_process type ref to /xegr/ifegr_process,
lo_city_process type ref to /xegr/clegr_city_process,
lo_root type ref to cx_root,
l_stcd1 type lfa1-stcd1,
l_prestador type lfa1-stcd3,
w_ws_setup type /xegr/tegrwspre,
t_t001w type standard table of t001w,
w_t001w type t001w,
lo_bundle type ref to /xegr/clegr_bundle.
types: begin of ty_yprestadores,
stcd1 type lfa1-stcd1,
lifnr type lfa1-lifnr,
end of ty_yprestadores.
types: begin of ty_ypedidos,
ebeln type ekko-ebeln,
ebelp type ekpo-ebelp,
lifnr type ekko-lifnr,
loekz type ekpo-loekz,
elikz type ekpo-elikz,
end of ty_ypedidos.
data: t_yprestadores type standard table of ty_yprestadores,
w_yprestadores type ty_yprestadores.
data: t_ypedidos type standard table of ty_ypedidos,
w_ypedidos type ty_ypedidos.
data: mw_ws_setup type /xegr/tegrwspre.
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
call method /xegr/cltracer=>start_trace( 'Iniciando DOWNLOAD_XMLS' ).
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
* Select All NFSE Inbound Process available
* Select all companies registered at EGR
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
select * from /xegr/tegrmdcfg into table lt_tegrmdcfg.
select * from /xegr/tegrprefp into table lt_nfse_process.
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
* For each NFSE Inbound Process, execute it for each branch
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
"-->Modificação Inicio Bertani 04.04.2017 15:35:49 EGR-1035
if lt_nfse_process[] is initial or lt_tegrmdcfg[] is initial.
call method /xegr/cltracer=>set_trace
exporting
i_text = `Configuração Vazia!`
i_msgtp = 'E'
io_obj1 = lt_tegrmdcfg
io_obj2 = lt_nfse_process.
endif.
"-->Modificação FIM Bertani
create object lo_city_process.
loop at lt_nfse_process into lw_nfse_process.
if p_txcjd is not initial.
check p_txcjd = lw_nfse_process-taxjurcode.
endif.
free lo_process.
try .
lo_process = lo_city_process->find_process(
i_country = lw_nfse_process-country
i_taxjurcode = lw_nfse_process-taxjurcode
i_origin = 'J' "JOB
).
catch /xegr/cx_egr_city_process.
call method /xegr/cltracer=>set_trace
exporting
i_text = `/xegr/cx_egr_city_process`
i_msgtp = 'E'
io_obj1 = lw_nfse_process.
continue.
endtry.
check lo_process is not initial.
loop at lt_tegrmdcfg into lw_tegrmdcfg.
"-->Verificação para saber se é necessário passar por todos os Prestadores
clear l_stcd1.
/xegr/clgr_tools=>get_branch_fiscal_data(
exporting
i_bukrs = lw_tegrmdcfg-bukrs
i_branch = lw_tegrmdcfg-branc
importing
e_stcd1 = l_stcd1 ).
select single *
from /xegr/tegrwspre
into w_ws_setup
where country = lw_nfse_process-country
and taxjurcode = lw_nfse_process-taxjurcode.
if w_ws_setup-loop_prestador = 'X'.
refresh t_yprestadores[].
select lfa1~stcd1 lfa1~lifnr
from lfbw
inner join lfa1
on lfa1~lifnr = lfbw~lifnr
into corresponding fields of table t_yprestadores
where lfa1~txjcd = lw_nfse_process-taxjurcode.
if sy-subrc <> 0.
continue.
endif.
sort t_yprestadores by stcd1.
delete adjacent duplicates from t_yprestadores comparing stcd1.
if not t_yprestadores[] is initial.
g_bedat = sy-datum - 300.
select * from ekko inner join ekpo
on ekko~ebeln = ekpo~ebeln
into corresponding fields of table t_ypedidos
for all entries in t_yprestadores
where ekko~lifnr = t_yprestadores-lifnr
and ekko~bedat >= g_bedat.
delete t_ypedidos where ( loekz <> space or elikz <> space ).
sort t_ypedidos by lifnr ascending.
delete adjacent duplicates from t_ypedidos comparing lifnr.
loop at t_yprestadores into w_yprestadores.
read table t_ypedidos with key lifnr = w_yprestadores-lifnr
transporting no fields binary search.
if sy-subrc <> 0.
delete t_yprestadores.
endif.
endloop.
endif.
else.
append l_stcd1 to t_yprestadores. "-->Neste caso ele apenas irá dar o loop
endif.
select single *
from /xegr/tegrwspre
into mw_ws_setup
where country = lw_nfse_process-country
and taxjurcode = lw_nfse_process-taxjurcode.
loop at t_yprestadores into w_yprestadores.
create object lo_bundle.
lo_bundle->add(
exporting
i_varname = 'tegrmdcfg'
i_data = lw_tegrmdcfg
).
lo_bundle->add(
exporting
i_varname = 'tegrprefp'
i_data = lw_nfse_process
).
lo_bundle->add(
exporting
i_varname = 'prestador'
i_data = w_yprestadores-stcd1
).
create object lo_ws_easy.
try .
clear gw_ylog.
gw_ylog-stcd1 = w_yprestadores-stcd1.
gw_ylog-taxjurcode = lw_nfse_process-taxjurcode.
call method lo_ws_easy->execute( lo_bundle ).
catch cx_root into lo_root.
gw_ylog-status = 'E'.
gw_ylog-message = `Exception no WS NFSe`.
call method /xegr/cltracer=>set_trace
exporting
i_text = `Exception no WS NFSe`
i_msgtp = 'E'
io_obj1 = lo_root.
endtry.
if p_rep = 'X'.
gw_ylog-xstring_header = lo_ws_easy->m_xstring_header.
gw_ylog-xstring_body = lo_ws_easy->m_xstring_body.
gw_ylog-xstring_return = lo_ws_easy->m_xstring_return.
append gw_ylog to gt_ylog.
endif.
free lo_ws_easy.
clear lo_ws_easy.
endloop.
endloop.
endloop.
endform.
class /xegr/clws_easy_local implementation.
method add_new_node.
"-->POOL-------------------------------------------------------ʕ•ᴥ•ʔ"
data: w_yelements type ty_yelements,
l_value type string.
field-symbols