br_nfe 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +0 -1
- data/Gemfile.lock +1 -1
- data/README.markdown +264 -106
- data/lib/br_nfe/{helper → association}/have_address.rb +1 -1
- data/lib/br_nfe/{helper → association}/have_condicao_pagamento.rb +1 -1
- data/lib/br_nfe/association/have_destinatario.rb +22 -0
- data/lib/br_nfe/association/have_emitente.rb +24 -0
- data/lib/br_nfe/base.rb +37 -27
- data/lib/br_nfe/condicao_pagamento.rb +2 -0
- data/lib/br_nfe/constants.rb +33 -0
- data/lib/br_nfe/endereco.rb +10 -0
- data/lib/br_nfe/helper/string_methods.rb +4 -0
- data/lib/br_nfe/{emitente.rb → person.rb} +11 -7
- data/lib/br_nfe/product/base.rb +82 -0
- data/lib/br_nfe/product/consulta_status_servico.rb +35 -0
- data/lib/br_nfe/product/emitente.rb +8 -0
- data/lib/br_nfe/product/gateway/base.rb +62 -0
- data/lib/br_nfe/product/gateway/web_service_svrs.rb +39 -0
- data/lib/br_nfe/product/value_nf.rb +9 -0
- data/lib/br_nfe/product/xml/soap_env.xml.slim +8 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/consReciNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/consSitNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/consStatServ_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/enviNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/inutNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/leiauteConsSitNFe_v3.10.xsd +502 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/leiauteConsStatServ_v3.10.xsd +98 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/leiauteInutNFe_v3.10.xsd +193 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/leiauteNFe_v3.10.xsd +6060 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/nfe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/procInutNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/procNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/retConsReciNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/retConsSitNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/retConsStatServ_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/retEnviNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/retInutNFe_v3.10.xsd +9 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/tiposBasico_v3.10.xsd +571 -0
- data/lib/br_nfe/product/xml/v3_10/XSD/xmldsig-core-schema_v1.01.xsd +98 -0
- data/lib/br_nfe/product/xml/v3_10/consulta_status_servico.xml.slim +4 -0
- data/lib/br_nfe/service/association/have_intermediario.rb +26 -0
- data/lib/br_nfe/service/association/have_rps.rb +36 -0
- data/lib/br_nfe/service/base.rb +24 -20
- data/lib/br_nfe/service/betha/v1/cancela_nfse.rb +43 -0
- data/lib/br_nfe/service/betha/v1/consulta_lote_rps.rb +20 -6
- data/lib/br_nfe/service/betha/v1/consulta_nfs_por_rps.rb +17 -6
- data/lib/br_nfe/service/betha/v1/consulta_nfse.rb +16 -5
- data/lib/br_nfe/service/betha/v1/consulta_situacao_lote_rps.rb +15 -6
- data/lib/br_nfe/service/betha/v1/gateway.rb +4 -0
- data/lib/br_nfe/service/betha/v1/recepcao_lote_rps.rb +13 -5
- data/lib/br_nfe/service/betha/v1/xml/_tc_identificacao_prestador.xml.slim +3 -0
- data/lib/br_nfe/service/betha/v1/xml/_tc_pedido_cancelamento.xml.slim +4 -0
- data/lib/br_nfe/service/concerns/rules/cancelamento_nfs.rb +8 -0
- data/lib/br_nfe/service/concerns/rules/consulta_nfs_por_rps.rb +1 -1
- data/lib/br_nfe/service/concerns/rules/consulta_nfse.rb +5 -2
- data/lib/br_nfe/service/concerns/values_ts/service_v1.rb +319 -0
- data/lib/br_nfe/service/destinatario.rb +7 -0
- data/lib/br_nfe/service/emitente.rb +8 -0
- data/lib/br_nfe/service/intermediario.rb +1 -12
- data/lib/br_nfe/service/item.rb +7 -7
- data/lib/br_nfe/service/response/build/base.rb +166 -0
- data/lib/br_nfe/service/response/build/cancelamento.rb +62 -0
- data/lib/br_nfe/service/response/build/consulta_lote_rps.rb +25 -0
- data/lib/br_nfe/service/response/build/consulta_nfs_por_rps.rb +25 -0
- data/lib/br_nfe/service/response/build/consulta_nfse.rb +24 -0
- data/lib/br_nfe/service/response/build/consulta_situacao_lote_rps.rb +56 -0
- data/lib/br_nfe/service/response/build/invoice_build.rb +359 -0
- data/lib/br_nfe/service/response/build/recepcao_lote_rps.rb +69 -0
- data/lib/br_nfe/service/response/cancelamento.rb +22 -0
- data/lib/br_nfe/service/response/consulta_lote_rps.rb +18 -0
- data/lib/br_nfe/service/response/consulta_nfs_por_rps.rb +10 -0
- data/lib/br_nfe/service/response/consulta_nfse.rb +10 -0
- data/lib/br_nfe/service/response/consulta_situacao_lote_rps.rb +74 -0
- data/lib/br_nfe/service/response/default.rb +93 -0
- data/lib/br_nfe/{response/service → service/response}/nota_fiscal.rb +19 -12
- data/lib/br_nfe/service/response/paths/v1/tc_nfse.rb +275 -0
- data/lib/br_nfe/service/response/recepcao_lote_rps.rb +35 -0
- data/lib/br_nfe/service/rps.rb +30 -27
- data/lib/br_nfe/service/sc/florianopolis/xml/_service_item.xml.slim +4 -4
- data/lib/br_nfe/service/sc/florianopolis/xml/inf_requisicao.xml.slim +4 -4
- data/lib/br_nfe/service/simpliss/v1/cancela_nfse.rb +16 -6
- data/lib/br_nfe/service/simpliss/v1/consulta_lote_rps.rb +20 -12
- data/lib/br_nfe/service/simpliss/v1/consulta_nfs_por_rps.rb +21 -6
- data/lib/br_nfe/service/simpliss/v1/consulta_nfse.rb +20 -6
- data/lib/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps.rb +17 -6
- data/lib/br_nfe/service/simpliss/v1/recepcao_lote_rps.rb +16 -4
- data/lib/br_nfe/service/simpliss/v1/xml/_tc_item_servico.xml.slim +2 -2
- data/lib/br_nfe/service/thema/v1/cancela_nfse.rb +21 -19
- data/lib/br_nfe/service/thema/v1/consulta_lote_rps.rb +21 -19
- data/lib/br_nfe/service/thema/v1/consulta_nfs_por_rps.rb +25 -18
- data/lib/br_nfe/service/thema/v1/consulta_nfse.rb +20 -20
- data/lib/br_nfe/service/thema/v1/consulta_situacao_lote_rps.rb +14 -20
- data/lib/br_nfe/service/thema/v1/recepcao_lote_rps.rb +11 -16
- data/lib/br_nfe/service/thema/v1/recepcao_lote_rps_limitado.rb +8 -6
- data/lib/br_nfe/service/xml/v1/_tc_identificacao_nfse.xml.slim +1 -1
- data/lib/br_nfe/service/xml/v1/_tc_pedido_cancelamento.xml.slim +1 -1
- data/lib/br_nfe/service/xml/v1/_tc_valores.xml.slim +11 -11
- data/lib/br_nfe/version.rb +1 -1
- data/lib/br_nfe.rb +62 -62
- data/test/br_nfe/association/have_address_test.rb +64 -0
- data/test/br_nfe/association/have_condicao_pagamento_test.rb +75 -0
- data/test/br_nfe/association/have_destinatario_test.rb +76 -0
- data/test/br_nfe/association/have_emitente_test.rb +80 -0
- data/test/br_nfe/base_test.rb +96 -61
- data/test/br_nfe/endereco_test.rb +21 -0
- data/test/br_nfe/person_test.rb +55 -0
- data/test/br_nfe/product/base_test.rb +150 -0
- data/test/br_nfe/product/consulta_status_servico_test.rb +59 -0
- data/test/br_nfe/product/emitente_test.rb +29 -0
- data/test/br_nfe/product/gateway/base_test.rb +16 -0
- data/test/br_nfe/product/gateway/web_service_svrs_test.rb +36 -0
- data/test/br_nfe/service/association/have_intermediario_test.rb +80 -0
- data/test/br_nfe/service/association/have_rps_test.rb +62 -0
- data/test/br_nfe/service/base_test.rb +42 -42
- data/test/br_nfe/service/betha/v1/cancela_nfse_test.rb +90 -0
- data/test/br_nfe/service/betha/v1/consulta_lote_rps_test.rb +105 -5
- data/test/br_nfe/service/betha/v1/consulta_nfs_por_rps_test.rb +103 -5
- data/test/br_nfe/service/betha/v1/consulta_nfse_test.rb +114 -5
- data/test/br_nfe/service/betha/v1/consulta_situacao_lote_rps_test.rb +118 -5
- data/test/br_nfe/service/betha/v1/gateway_test.rb +1 -1
- data/test/br_nfe/service/betha/v1/recepcao_lote_rps_test.rb +51 -5
- data/test/br_nfe/service/concerns/rules/cancelamento_nfs_test.rb +2 -2
- data/test/br_nfe/service/concerns/rules/consulta_nfs_por_rps_test.rb +2 -7
- data/test/br_nfe/service/concerns/rules/consulta_nfse_test.rb +24 -3
- data/test/br_nfe/service/concerns/rules/recepcao_lote_rps_test.rb +1 -1
- data/test/br_nfe/{helper → service/concerns}/values_ts/service_v1_test.rb +2 -2
- data/test/br_nfe/{destinatario_test.rb → service/destinatario_test.rb} +3 -4
- data/test/br_nfe/service/emitente_test.rb +29 -0
- data/test/br_nfe/service/item_test.rb +14 -14
- data/test/br_nfe/service/response/build/base_test.rb +80 -0
- data/test/br_nfe/{response/service → service/response}/default_test.rb +1 -82
- data/test/br_nfe/service/response/nota_fiscal_test.rb +59 -0
- data/test/br_nfe/{response/service → service/response}/paths/v1/tc_nfse_test.rb +10 -10
- data/test/br_nfe/service/rps_test.rb +107 -138
- data/test/br_nfe/service/sc/florianopolis/emission_rps_test.rb +9 -9
- data/test/br_nfe/service/simpliss/v1/base_test.rb +1 -1
- data/test/br_nfe/service/simpliss/v1/cancela_nfse_test.rb +7 -10
- data/test/br_nfe/service/simpliss/v1/consulta_lote_rps_test.rb +11 -18
- data/test/br_nfe/service/simpliss/v1/consulta_nfs_por_rps_test.rb +11 -18
- data/test/br_nfe/service/simpliss/v1/consulta_nfse_test.rb +11 -18
- data/test/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps_test.rb +7 -11
- data/test/br_nfe/service/simpliss/v1/recepcao_lote_rps_test.rb +3 -9
- data/test/br_nfe/service/thema/v1/base_test.rb +1 -1
- data/test/br_nfe/service/thema/v1/cancela_nfse_test.rb +7 -14
- data/test/br_nfe/service/thema/v1/consulta_lote_rps_test.rb +6 -17
- data/test/br_nfe/service/thema/v1/consulta_nfs_por_rps_test.rb +6 -13
- data/test/br_nfe/service/thema/v1/consulta_nfse_test.rb +11 -18
- data/test/br_nfe/service/thema/v1/consulta_situacao_lote_rps_test.rb +7 -11
- data/test/br_nfe/service/thema/v1/recepcao_lote_rps_limitado_test.rb +1 -5
- data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test.rb +3 -9
- data/test/factories/base.rb +0 -1
- data/test/factories/{emitente.rb → person.rb} +1 -1
- data/test/factories/product/base.rb +12 -0
- data/test/factories/product/consulta_status_servico.rb +12 -0
- data/test/factories/product/emitente.rb +15 -0
- data/test/factories/product/gateway/base.rb +5 -0
- data/test/factories/product/gateway/web_service_svrs.rb +5 -0
- data/test/factories/service/betha/v1/{cancelamento_nfs.rb → cancela_nfse.rb} +2 -1
- data/test/factories/service/betha/v1/consulta_lote_rps.rb +1 -1
- data/test/factories/service/betha/v1/consulta_nfs_por_rps.rb +1 -1
- data/test/factories/service/betha/v1/consulta_nfse.rb +1 -1
- data/test/factories/service/betha/v1/consulta_situacao_lote_rps.rb +1 -1
- data/test/factories/{destinatario.rb → service/destinatario.rb} +1 -1
- data/test/factories/service/emitente.rb +15 -0
- data/test/factories/service/item.rb +4 -4
- data/test/factories/service/response/build_response.rb +5 -0
- data/test/factories/service/response/default.rb +6 -0
- data/test/factories/{response/service → service/response}/nota_fiscal.rb +8 -8
- data/test/factories/service/rps.rb +11 -11
- data/test/factories/service/sc/florianopolis/base.rb +1 -1
- data/test/factories/service/sc/florianopolis/cancellation.rb +1 -1
- data/test/factories/service/sc/florianopolis/emission_rps.rb +1 -1
- data/test/factories/service/simpliss/v1/base.rb +1 -1
- data/test/factories/service/simpliss/v1/cancela_nfse.rb +1 -1
- data/test/factories/service/simpliss/v1/consulta_lote_rps.rb +1 -1
- data/test/factories/service/simpliss/v1/consulta_nfs_por_rps.rb +1 -1
- data/test/factories/service/simpliss/v1/consulta_nfse.rb +1 -1
- data/test/factories/service/simpliss/v1/consulta_situacao_lote_rps.rb +1 -1
- data/test/factories/service/simpliss/v1/recepcao_lote_rps.rb +1 -1
- data/test/factories/service/thema/v1/base.rb +1 -1
- data/test/factories/service/thema/v1/cancela_nfse.rb +1 -1
- data/test/factories/service/thema/v1/consulta_lote_rps.rb +1 -1
- data/test/factories/service/thema/v1/consulta_nfs_por_rps.rb +1 -1
- data/test/factories/service/thema/v1/consulta_nfse.rb +1 -1
- data/test/factories/service/thema/v1/consulta_situacao_lote_rps.rb +1 -1
- data/test/factories/service/thema/v1/recepcao_lote_rps.rb +1 -1
- data/test/fixtures/service/response/betha/v1/cancela_nfse/fault.xml +17 -0
- data/test/fixtures/service/response/betha/v1/cancela_nfse/success.xml +48 -0
- data/test/fixtures/service/response/betha/v1/consulta_lote_rps/fault.xml +18 -0
- data/test/fixtures/service/response/betha/v1/consulta_lote_rps/success.xml +108 -0
- data/test/fixtures/service/response/betha/v1/consulta_nfse/fault.xml +18 -0
- data/test/fixtures/service/response/betha/v1/consulta_nfse/nfs_empty.xml +12 -0
- data/test/fixtures/service/response/betha/v1/consulta_nfse/success.xml +115 -0
- data/test/fixtures/service/response/betha/v1/consulta_nfse_por_rps/fault.xml +18 -0
- data/test/fixtures/service/response/betha/v1/consulta_nfse_por_rps/success.xml +103 -0
- data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/error.xml +13 -0
- data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/fault.xml +17 -0
- data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/success.xml +13 -0
- data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unprocessed.xml +13 -0
- data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unprocessed_by_code_error.xml +17 -0
- data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unreceived.xml +13 -0
- data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unreceived_by_code_error.xml +17 -0
- data/test/fixtures/service/response/betha/v1/recepcao_lote_rps/error.xml +17 -0
- data/test/fixtures/service/response/betha/v1/recepcao_lote_rps/success.xml +14 -0
- metadata +160 -94
- data/lib/br_nfe/destinatario.rb +0 -26
- data/lib/br_nfe/helper/have_destinatario.rb +0 -18
- data/lib/br_nfe/helper/have_emitente.rb +0 -20
- data/lib/br_nfe/helper/have_intermediario.rb +0 -24
- data/lib/br_nfe/helper/have_rps.rb +0 -34
- data/lib/br_nfe/helper/values_ts/service_v1.rb +0 -317
- data/lib/br_nfe/response/service/build_response.rb +0 -463
- data/lib/br_nfe/response/service/default.rb +0 -185
- data/lib/br_nfe/response/service/paths/base.rb +0 -127
- data/lib/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta.rb +0 -22
- data/lib/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta.rb +0 -25
- data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta.rb +0 -25
- data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta.rb +0 -25
- data/lib/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta.rb +0 -31
- data/lib/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta.rb +0 -36
- data/lib/br_nfe/response/service/paths/v1/tc_nfse.rb +0 -271
- data/lib/br_nfe/service/betha/v1/cancelamento_nfs.rb +0 -36
- data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta.rb +0 -23
- data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta.rb +0 -21
- data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -21
- data/lib/br_nfe/service/simpliss/v1/response_paths/servico_cancelar_nfse_resposta.rb +0 -22
- data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_lote_rps_resposta.rb +0 -25
- data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_resposta.rb +0 -25
- data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -25
- data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_situacao_lote_rps_resposta.rb +0 -31
- data/lib/br_nfe/service/simpliss/v1/response_paths/servico_enviar_lote_rps_resposta.rb +0 -36
- data/lib/br_nfe/service/thema/v1/response_paths/servico_cancelar_nfse_resposta.rb +0 -17
- data/lib/br_nfe/service/thema/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -19
- data/test/br_nfe/emitente_test.rb +0 -46
- data/test/br_nfe/helper/have_address_test.rb +0 -62
- data/test/br_nfe/helper/have_condicao_pagamento_test.rb +0 -71
- data/test/br_nfe/helper/have_destinatario_test.rb +0 -64
- data/test/br_nfe/helper/have_emitente_test.rb +0 -63
- data/test/br_nfe/helper/have_intermediario_test.rb +0 -77
- data/test/br_nfe/helper/have_rps_test.rb +0 -59
- data/test/br_nfe/response/service/build_response_test.rb +0 -205
- data/test/br_nfe/response/service/nota_fiscal_test.rb +0 -41
- data/test/br_nfe/response/service/paths/base_test.rb +0 -196
- data/test/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta_test.rb +0 -25
- data/test/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta_test.rb +0 -30
- data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta_test.rb +0 -30
- data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta_test.rb +0 -30
- data/test/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta_test.rb +0 -30
- data/test/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta_test.rb +0 -34
- data/test/br_nfe/service/betha/v1/cancelamento_nfs_test.rb +0 -54
- data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta_test.rb +0 -16
- data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta_test.rb +0 -16
- data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta_test.rb +0 -16
- data/test/factories/response/service/build_response.rb +0 -5
- data/test/factories/response/service/default.rb +0 -10
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
#encoding UTF-8
|
|
2
|
-
module BrNfe
|
|
3
|
-
module Response
|
|
4
|
-
module Service
|
|
5
|
-
class BuildResponse < BrNfe::ActiveModelBase
|
|
6
|
-
# 1: A resposta da requisição soap
|
|
7
|
-
attr_accessor :savon_response
|
|
8
|
-
|
|
9
|
-
# 2: Um array com o caminho inicial padrão da requisição de retorno
|
|
10
|
-
attr_accessor :keys_root_path
|
|
11
|
-
|
|
12
|
-
# 3: Caminho para encontrar o XML da NF-e
|
|
13
|
-
attr_accessor :nfe_xml_path
|
|
14
|
-
|
|
15
|
-
# 4: Alguns Webservices trazem dentro do body da resposta SOAp
|
|
16
|
-
# outro XML com as informações necessárias.
|
|
17
|
-
# Quando isso aocntece é preciso converter esse XML para um HASH
|
|
18
|
-
# para que possamos encontrar os valores necessários.
|
|
19
|
-
attr_accessor :body_xml_path
|
|
20
|
-
|
|
21
|
-
# 5: Codificação original do XML de resposta para que seja convertido
|
|
22
|
-
# para UTF-8
|
|
23
|
-
attr_accessor :xml_encode
|
|
24
|
-
|
|
25
|
-
##############################################################################################################
|
|
26
|
-
####################### CAMINHOS PARA ENCONTRAR OS VALORES NA RESPOSTA DA REQUISIÇÃO #####################
|
|
27
|
-
# Caminho para encontrar
|
|
28
|
-
attr_accessor :lot_number_path # o numero do lote
|
|
29
|
-
attr_accessor :protocol_path # o protocolo
|
|
30
|
-
attr_accessor :received_date_path # a data de recebimento do xml
|
|
31
|
-
attr_accessor :situation_path # a situação do lote rps
|
|
32
|
-
attr_accessor :situation_key_values #
|
|
33
|
-
def situation_key_values
|
|
34
|
-
@situation_key_values.is_a?(Hash) ? @situation_key_values : {
|
|
35
|
-
'1' => :unreceived, # Não Recebido
|
|
36
|
-
'2' => :unprocessed,# Não Processado
|
|
37
|
-
'3' => :error, # Processado com Erro
|
|
38
|
-
'4' => :success, # Processado com Sucesso
|
|
39
|
-
}
|
|
40
|
-
end
|
|
41
|
-
attr_accessor :cancelation_date_time_path # data e hora do cancelamento da nf
|
|
42
|
-
attr_accessor :message_errors_path # local para encontrar as mensagens de erro
|
|
43
|
-
attr_accessor :message_code_key # chave que representa o codigo do erro
|
|
44
|
-
attr_accessor :message_msg_key # chave que representa a mensagem do erro
|
|
45
|
-
attr_accessor :message_solution_key # chave que representa a solução do erro
|
|
46
|
-
attr_accessor :invoices_path # o caminho para listar as notas fiscais
|
|
47
|
-
attr_accessor :invoice_numero_nf_path # numero da nota fiscal
|
|
48
|
-
attr_accessor :invoice_codigo_verificacao_path # código de verificação
|
|
49
|
-
attr_accessor :invoice_data_emissao_path # Data de emissão da NF
|
|
50
|
-
attr_accessor :invoice_url_nf_path # URL para visualizar a DANFE (apenas alguns emissores disponibilizam isso)
|
|
51
|
-
attr_accessor :invoice_rps_numero_path # Número do RPS da nota
|
|
52
|
-
attr_accessor :invoice_rps_serie_path # Número da série do RPS da nota
|
|
53
|
-
attr_accessor :invoice_rps_tipo_path # Tipo do RPS
|
|
54
|
-
attr_accessor :invoice_rps_situacao_path # Situação da NF
|
|
55
|
-
attr_accessor :invoice_rps_substituido_numero_path # Número do RPS da nota substituido
|
|
56
|
-
attr_accessor :invoice_rps_substituido_serie_path # Número da série do RPS da nota substituido
|
|
57
|
-
attr_accessor :invoice_rps_substituido_tipo_path # Tipo do RPS substituido
|
|
58
|
-
attr_accessor :invoice_data_emissao_rps_path # Data de emissão do RPS
|
|
59
|
-
attr_accessor :invoice_competencia_path # Competência da nf
|
|
60
|
-
attr_accessor :invoice_natureza_operacao_path # natureza de operação
|
|
61
|
-
attr_accessor :invoice_regime_especial_tributacao_path # Regime especial de tributação
|
|
62
|
-
attr_accessor :invoice_optante_simples_nacional_path # Se é optante do simples
|
|
63
|
-
attr_accessor :invoice_incentivador_cultural_path # Incentivo cultural
|
|
64
|
-
attr_accessor :invoice_outras_informacoes_path # Outras informações da nf
|
|
65
|
-
attr_accessor :invoice_item_lista_servico_path # Código do serviço prestado
|
|
66
|
-
attr_accessor :invoice_cnae_code_path # CNAE utilizado na nf
|
|
67
|
-
attr_accessor :invoice_description_path # Descrição da nf
|
|
68
|
-
attr_accessor :invoice_codigo_municipio_path # Código do municipio prestador do serviço
|
|
69
|
-
attr_accessor :invoice_total_services_path # Valor total dos serviços
|
|
70
|
-
attr_accessor :invoice_deductions_path # Valor das deduções
|
|
71
|
-
attr_accessor :invoice_valor_pis_path # Valor do PIS
|
|
72
|
-
attr_accessor :invoice_valor_cofins_path # Valor do COFINS
|
|
73
|
-
attr_accessor :invoice_valor_inss_path # Valor do INSS
|
|
74
|
-
attr_accessor :invoice_valor_ir_path # Valor do IR
|
|
75
|
-
attr_accessor :invoice_valor_csll_path # Valor da CSLL
|
|
76
|
-
attr_accessor :invoice_iss_retained_path # Se o ISS está retido
|
|
77
|
-
attr_accessor :invoice_outras_retencoes_path # Valor Outras retenções
|
|
78
|
-
attr_accessor :invoice_total_iss_path # Valor total de ISS
|
|
79
|
-
attr_accessor :invoice_base_calculation_path # Valor da base de cálculo
|
|
80
|
-
attr_accessor :invoice_iss_tax_rate_path # Percentual do imposto de ISS
|
|
81
|
-
attr_accessor :invoice_valor_liquido_path # Valor liquido da NFS
|
|
82
|
-
attr_accessor :invoice_desconto_condicionado_path # Valor do desconto condicionado
|
|
83
|
-
attr_accessor :invoice_desconto_incondicionado_path # Valor do desconto incondicionado
|
|
84
|
-
attr_accessor :invoice_responsavel_retencao_path # Responsável pela retenção
|
|
85
|
-
attr_accessor :invoice_numero_processo_path # Número do processo da NF
|
|
86
|
-
attr_accessor :invoice_municipio_incidencia_path # Código do municipio em que o serviço foi prestado
|
|
87
|
-
attr_accessor :invoice_orgao_gerador_municipio_path # Órgão gerador municipal da NFS
|
|
88
|
-
attr_accessor :invoice_orgao_gerador_uf_path # Órgão gerador estadual da NFS
|
|
89
|
-
attr_accessor :invoice_cancelamento_codigo_path # Código do cancelamento da NFS
|
|
90
|
-
attr_accessor :invoice_cancelamento_numero_nf_path # Número da NFS cancelada
|
|
91
|
-
attr_accessor :invoice_cancelamento_cnpj_path # CNPJ da NF cancelada
|
|
92
|
-
attr_accessor :invoice_cancelamento_municipio_path # Municipo da nota cancelada
|
|
93
|
-
attr_accessor :invoice_cancelamento_data_hora_path # Data e hora do cancelamento
|
|
94
|
-
attr_accessor :invoice_cancelamento_inscricao_municipal_path # Inscrição municipal da nota cancelada
|
|
95
|
-
attr_accessor :invoice_nfe_substituidora_path # Número da NFS substituidora
|
|
96
|
-
attr_accessor :invoice_codigo_obra_path # Código obra
|
|
97
|
-
attr_accessor :invoice_codigo_art_path # Código art
|
|
98
|
-
attr_accessor :invoice_emitente_cnpj_path # Cnpj do emitente da NFS
|
|
99
|
-
attr_accessor :invoice_emitente_inscricao_municipal_path # Inscricao municipal do emitente da NFS
|
|
100
|
-
attr_accessor :invoice_emitente_razao_social_path # Razao social do emitente da NFS
|
|
101
|
-
attr_accessor :invoice_emitente_nome_fantasia_path # Nome fantasia do emitente da NFS
|
|
102
|
-
attr_accessor :invoice_emitente_telefone_path # Telefone do emitente da NFS
|
|
103
|
-
attr_accessor :invoice_emitente_email_path # Email do emitente da NFS
|
|
104
|
-
attr_accessor :invoice_emitente_endereco_logradouro_path # Logradouro do emitente da NFS
|
|
105
|
-
attr_accessor :invoice_emitente_endereco_numero_path # Numero do emitente da NFS
|
|
106
|
-
attr_accessor :invoice_emitente_endereco_complemento_path # Complemento do emitente da NFS
|
|
107
|
-
attr_accessor :invoice_emitente_endereco_bairro_path # Bairro do emitente da NFS
|
|
108
|
-
attr_accessor :invoice_emitente_endereco_codigo_municipio_path # Codigo_municipio do emitente da NFS
|
|
109
|
-
attr_accessor :invoice_emitente_endereco_uf_path # Uf do emitente da NFS
|
|
110
|
-
attr_accessor :invoice_emitente_endereco_cep_path # Cep do emitente da NFS
|
|
111
|
-
attr_accessor :invoice_destinatario_cpf_path # Cpf do destinatário da NFS
|
|
112
|
-
attr_accessor :invoice_destinatario_cnpj_path # Cnpj do destinatário da NFS
|
|
113
|
-
attr_accessor :invoice_destinatario_inscricao_municipal_path # Inscricao municipal do destinatário da NFS
|
|
114
|
-
attr_accessor :invoice_destinatario_inscricao_estadual_path # Inscricao estadual do destinatário da NFS
|
|
115
|
-
attr_accessor :invoice_destinatario_inscricao_suframa_path # Inscricao suframa do destinatário da NFS
|
|
116
|
-
attr_accessor :invoice_destinatario_razao_social_path # Razao social do destinatário da NFS
|
|
117
|
-
attr_accessor :invoice_destinatario_telefone_path # Telefone do destinatário da NFS
|
|
118
|
-
attr_accessor :invoice_destinatario_email_path # Email do destinatário da NFS
|
|
119
|
-
attr_accessor :invoice_destinatario_endereco_logradouro_path # Logradouro do destinatário da NFS
|
|
120
|
-
attr_accessor :invoice_destinatario_endereco_numero_path # Numero do destinatário da NFS
|
|
121
|
-
attr_accessor :invoice_destinatario_endereco_complemento_path # Complemento do destinatário da NFS
|
|
122
|
-
attr_accessor :invoice_destinatario_endereco_bairro_path # Bairro do destinatário da NFS
|
|
123
|
-
attr_accessor :invoice_destinatario_endereco_codigo_municipio_path # Codigo_municipio do destinatário da NFS
|
|
124
|
-
attr_accessor :invoice_destinatario_endereco_uf_path # Uf do destinatário da NFS
|
|
125
|
-
attr_accessor :invoice_destinatario_endereco_cep_path # Cep do destinatário da NFS
|
|
126
|
-
|
|
127
|
-
####################### FIM DA DEFINIÇÃO DOS CAMINHOS ############################
|
|
128
|
-
######################################################################################
|
|
129
|
-
|
|
130
|
-
def response
|
|
131
|
-
@response ||= BrNfe::Response::Service::Default.new({
|
|
132
|
-
error_messages: get_message_for_path(message_errors_path),
|
|
133
|
-
notas_fiscais: get_invoices,
|
|
134
|
-
protocolo: get_protocol,
|
|
135
|
-
data_recebimento: get_received_date,
|
|
136
|
-
numero_lote: get_lot_number,
|
|
137
|
-
situation: get_situation,
|
|
138
|
-
original_xml: savon_response.xml.force_encoding('UTF-8'),
|
|
139
|
-
cancelation_date_time: get_cancelation_date_time
|
|
140
|
-
})
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# Retorna o valor encontrado no body da resposta Savon
|
|
144
|
-
# em formato de hash
|
|
145
|
-
#
|
|
146
|
-
# <b>Tipo de retorno: </b> _Hash_
|
|
147
|
-
#
|
|
148
|
-
def savon_body
|
|
149
|
-
return @savon_body if @savon_body.present?
|
|
150
|
-
if body_xml_path.present?
|
|
151
|
-
@savon_body = Nori.new.parse(
|
|
152
|
-
body_converted_to_xml
|
|
153
|
-
).deep_transform_keys!{|k| k.to_s.underscore.to_sym}
|
|
154
|
-
else
|
|
155
|
-
@savon_body = savon_response.try(:body) || {}
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# Converte o body da requisição em XML (String)
|
|
160
|
-
# Isso é necessário quando dentro do body vem a resposta com outro XML
|
|
161
|
-
#
|
|
162
|
-
# <b>Tipo de retorno: </b> _String_
|
|
163
|
-
#
|
|
164
|
-
def body_converted_to_xml
|
|
165
|
-
@body_converted_to_xml ||= canonicalize("#{find_value_for_keys(savon_response.try(:body), body_xml_path)}".encode(xml_encode).force_encoding('UTF-8'))
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
# Método utilizado para encontrar valores em um Hash
|
|
169
|
-
# passando o caminho do valor em um array onde contém as chaves
|
|
170
|
-
# ordenadas.
|
|
171
|
-
# Recebe 2 parêmntros:
|
|
172
|
-
# 1º um o hash onde contém o valor a ser encontrado
|
|
173
|
-
# 2º um array com as chaves em sequencia formando o caminho para encontrar o valor.
|
|
174
|
-
#
|
|
175
|
-
# A funcionalidade desse método funciona parecido com o `.dig` da classe Hash do
|
|
176
|
-
# Ruby 2.3.0.
|
|
177
|
-
# A diferença é que no caso de exmeplo a seguir não apresenta uma excessão par ao usuário
|
|
178
|
-
# hash = {v1: {v2: 'valor string'}}
|
|
179
|
-
# hash.dig(:v1, :v2, :v3) <- Dá erro
|
|
180
|
-
# find_value_for_keys(hash, [:v1, :v2, :v3] <- Retorna nil e não da erro
|
|
181
|
-
#
|
|
182
|
-
# <b>Tipo de retorno: </b> _Anything_
|
|
183
|
-
#
|
|
184
|
-
def find_value_for_keys(hash, keys)
|
|
185
|
-
return if keys.blank?
|
|
186
|
-
keys = [keys] unless keys.is_a?(Array)
|
|
187
|
-
|
|
188
|
-
result = hash
|
|
189
|
-
keys.each do |key|
|
|
190
|
-
if result.is_a?(Hash)
|
|
191
|
-
result = result[key]
|
|
192
|
-
else
|
|
193
|
-
result = nil
|
|
194
|
-
break
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
result
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
# Quando para encontrar o valor de uma determinada chave
|
|
201
|
-
# é necessaŕio percorer o hash de retorno dês do inicio do mesmo.
|
|
202
|
-
# Como a mensagem tem uma chave 'root' padrão e pode ser diferente
|
|
203
|
-
# para cada orgaao emissor, é setado uma valor na variavel keys_root_path
|
|
204
|
-
# para que não seja necessário ficar setando a mesma chave em todos os
|
|
205
|
-
# métodos utilizados para encontrar determinado valor
|
|
206
|
-
#
|
|
207
|
-
# <b>Tipo de retorno: </b> _Array_
|
|
208
|
-
#
|
|
209
|
-
def path_with_root(path)
|
|
210
|
-
return if path.blank?
|
|
211
|
-
keys_root_path + [path].flatten
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
# Método que retorna as mensagens de retorno da requisição
|
|
215
|
-
# Quando procurar a mensagem a mesma pode retornar em 3 formatos:
|
|
216
|
-
# Hash: Onde encontrou apenas 1 mensagem com Codigo, Mensagem e Solução
|
|
217
|
-
# Array: Onde encontrou mais de uma mensagem com Codigo, Mensagem e Solução
|
|
218
|
-
# String: Onde encontrou uma unica mensagem de texto
|
|
219
|
-
#
|
|
220
|
-
# <b>Tipo de retorno: </b> _Array_
|
|
221
|
-
#
|
|
222
|
-
def get_message_for_path(msg_path)
|
|
223
|
-
messages = []
|
|
224
|
-
_messages = find_value_for_keys(savon_body, path_with_root(msg_path) )
|
|
225
|
-
if _messages.is_a?(Hash)
|
|
226
|
-
messages << get_message_for_hash(_messages)
|
|
227
|
-
elsif _messages.is_a?(Array)
|
|
228
|
-
_messages.map{|msg| messages << get_message_for_hash(msg) if msg.present? }
|
|
229
|
-
elsif _messages.present?
|
|
230
|
-
messages << _messages
|
|
231
|
-
end
|
|
232
|
-
messages.uniq
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
# Método utilizado para quando encontrar uam mensagem que seja um HAsh,
|
|
236
|
-
# onde nesse caso a mensagem terá um codigo de erro, uma mensagem, e uma
|
|
237
|
-
# mensagem de solução
|
|
238
|
-
#
|
|
239
|
-
# <b>Tipo de retorno: </b> _hash_
|
|
240
|
-
#
|
|
241
|
-
def get_message_for_hash(msg_hash)
|
|
242
|
-
{
|
|
243
|
-
code: find_value_for_keys(msg_hash, message_code_key),
|
|
244
|
-
message: find_value_for_keys(msg_hash, message_msg_key),
|
|
245
|
-
solution: find_value_for_keys(msg_hash, message_solution_key)
|
|
246
|
-
}
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
# Método que retorna as notas fiscais emitidas.
|
|
250
|
-
# Como pode ser que retorne mais de uma NF, a busca pela NF
|
|
251
|
-
# pode retornar um Array ou um Hash.
|
|
252
|
-
# Se retornar um array é porque existe mais de uma NFE, então é necessario
|
|
253
|
-
# percorer com um loop e instanciar cada nota com seus valores.
|
|
254
|
-
# Se retornar um Hash é porque tem apenas uma NFe, e nesse caso
|
|
255
|
-
# irá instanciar apenas a nfe encontrada.
|
|
256
|
-
#
|
|
257
|
-
# <b>Tipo de retorno: </b> _Array_
|
|
258
|
-
#
|
|
259
|
-
def get_invoices
|
|
260
|
-
invoices = []
|
|
261
|
-
_invoices = find_value_for_keys(savon_body, path_with_root(invoices_path))
|
|
262
|
-
if _invoices.is_a?(Hash)
|
|
263
|
-
invoices << instance_invoice(_invoices)
|
|
264
|
-
elsif _invoices.is_a?(Array)
|
|
265
|
-
_invoices.map{|inv| invoices << instance_invoice(inv) }
|
|
266
|
-
end
|
|
267
|
-
invoices
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
# Método utilizado para pegar protocolo de solicitação de
|
|
271
|
-
# processamento do RPS.
|
|
272
|
-
# Esse protocolo é utilizado posteriormente para consultar se
|
|
273
|
-
# o RPS já foi processado
|
|
274
|
-
#
|
|
275
|
-
# <b>Tipo de retorno: </b> _String_
|
|
276
|
-
#
|
|
277
|
-
def get_protocol
|
|
278
|
-
find_value_for_keys(savon_body, path_with_root(protocol_path))
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
# Método utilizado para pegar a situação do RPS
|
|
282
|
-
#
|
|
283
|
-
# <b>Tipo de retorno: </b> _Symbol_
|
|
284
|
-
#
|
|
285
|
-
def get_situation
|
|
286
|
-
situation_value = find_value_for_keys(savon_body, path_with_root(situation_path))
|
|
287
|
-
situation_value = situation_key_values[situation_value.to_s.strip] if situation_value.present?
|
|
288
|
-
situation_value
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
# Método utilizado para pegar a data de recebimento do lote
|
|
292
|
-
#
|
|
293
|
-
# <b>Tipo de retorno: </b> _String_
|
|
294
|
-
#
|
|
295
|
-
def get_received_date
|
|
296
|
-
find_value_for_keys(savon_body, path_with_root(received_date_path))
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
# Método utilizado para pegar o número do lote RPS
|
|
300
|
-
#
|
|
301
|
-
# <b>Tipo de retorno: </b> _String_
|
|
302
|
-
#
|
|
303
|
-
def get_lot_number
|
|
304
|
-
find_value_for_keys(savon_body, path_with_root(lot_number_path))
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
# Método utilizado para pegar o XML da NF
|
|
308
|
-
# É necessário canonicalizar o document para que seja colocado os
|
|
309
|
-
# namespaces nas tags corretas. Caso contrário o XML não irá abrir.
|
|
310
|
-
#
|
|
311
|
-
# <b>Tipo de retorno: </b> _String_
|
|
312
|
-
#
|
|
313
|
-
def get_xml_nf
|
|
314
|
-
if body_xml_path.present?
|
|
315
|
-
canonicalize(Nokogiri::XML.parse( body_converted_to_xml , nil, 'UTF-8').xpath(nfe_xml_path).to_xml)
|
|
316
|
-
else
|
|
317
|
-
canonicalize(Nokogiri::XML.parse(canonicalize(savon_response.doc.to_s), nil, 'UTF-8').xpath(nfe_xml_path).to_xml)
|
|
318
|
-
end
|
|
319
|
-
rescue
|
|
320
|
-
savon_response.xml
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
# Método utilizado para pegar o valor da data e hora de cancelmaento
|
|
324
|
-
# Só é utilizado para cancelar a NF-e
|
|
325
|
-
#
|
|
326
|
-
# <b>Tipo de retorno: </b> _DateTime_ OU _Nil_ OU _String_
|
|
327
|
-
#
|
|
328
|
-
def get_cancelation_date_time
|
|
329
|
-
find_value_for_keys(savon_body, path_with_root(cancelation_date_time_path)) if cancelation_date_time_path.present?
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
# Método responsável por instanciar a nota fiscal de acordo com o hash
|
|
333
|
-
# passado por parêmetro
|
|
334
|
-
# O parâmetro recebido deve ser o Hash representado pelo tipo de dados tcCompNfse(do manual NFS-e v1)
|
|
335
|
-
#
|
|
336
|
-
def instance_invoice(invoice_hash)
|
|
337
|
-
nfe = BrNfe::Response::Service::NotaFiscal.new({
|
|
338
|
-
xml_nf: get_xml_nf.force_encoding('UTF-8'),
|
|
339
|
-
numero_nf: find_value_for_keys(invoice_hash, invoice_numero_nf_path ),
|
|
340
|
-
codigo_verificacao: find_value_for_keys(invoice_hash, invoice_codigo_verificacao_path ),
|
|
341
|
-
data_emissao: find_value_for_keys(invoice_hash, invoice_data_emissao_path ),
|
|
342
|
-
url_nf: find_value_for_keys(invoice_hash, invoice_url_nf_path ),
|
|
343
|
-
competencia: find_value_for_keys(invoice_hash, invoice_competencia_path ),
|
|
344
|
-
natureza_operacao: find_value_for_keys(invoice_hash, invoice_natureza_operacao_path ),
|
|
345
|
-
regime_especial_tributacao: find_value_for_keys(invoice_hash, invoice_regime_especial_tributacao_path ),
|
|
346
|
-
optante_simples_nacional: find_value_for_keys(invoice_hash, invoice_optante_simples_nacional_path ),
|
|
347
|
-
incentivador_cultural: find_value_for_keys(invoice_hash, invoice_incentivador_cultural_path ),
|
|
348
|
-
outras_informacoes: find_value_for_keys(invoice_hash, invoice_outras_informacoes_path ),
|
|
349
|
-
item_lista_servico: find_value_for_keys(invoice_hash, invoice_item_lista_servico_path ),
|
|
350
|
-
cnae_code: find_value_for_keys(invoice_hash, invoice_cnae_code_path ),
|
|
351
|
-
description: find_value_for_keys(invoice_hash, invoice_description_path ),
|
|
352
|
-
codigo_municipio: find_value_for_keys(invoice_hash, invoice_codigo_municipio_path ),
|
|
353
|
-
responsavel_retencao: find_value_for_keys(invoice_hash, invoice_responsavel_retencao_path ),
|
|
354
|
-
numero_processo: find_value_for_keys(invoice_hash, invoice_numero_processo_path ),
|
|
355
|
-
municipio_incidencia: find_value_for_keys(invoice_hash, invoice_municipio_incidencia_path ),
|
|
356
|
-
orgao_gerador_municipio: find_value_for_keys(invoice_hash, invoice_orgao_gerador_municipio_path ),
|
|
357
|
-
orgao_gerador_uf: find_value_for_keys(invoice_hash, invoice_orgao_gerador_uf_path ),
|
|
358
|
-
codigo_obra: find_value_for_keys(invoice_hash, invoice_codigo_obra_path ),
|
|
359
|
-
codigo_art: find_value_for_keys(invoice_hash, invoice_codigo_art_path ),
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
build_rps_fields_nfe(nfe, invoice_hash)
|
|
363
|
-
build_cancelation_fields_nfe(nfe, invoice_hash)
|
|
364
|
-
build_values_nfe(nfe, invoice_hash)
|
|
365
|
-
build_emitente_nfe(nfe, invoice_hash)
|
|
366
|
-
build_destinatario_nfe(nfe, invoice_hash)
|
|
367
|
-
nfe
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
def build_rps_fields_nfe(nfe, invoice_hash)
|
|
371
|
-
nfe.assign_attributes({
|
|
372
|
-
rps_numero: find_value_for_keys(invoice_hash, invoice_rps_numero_path ),
|
|
373
|
-
rps_serie: find_value_for_keys(invoice_hash, invoice_rps_serie_path ),
|
|
374
|
-
rps_tipo: find_value_for_keys(invoice_hash, invoice_rps_tipo_path ),
|
|
375
|
-
rps_situacao: find_value_for_keys(invoice_hash, invoice_rps_situacao_path ),
|
|
376
|
-
rps_substituido_numero: find_value_for_keys(invoice_hash, invoice_rps_substituido_numero_path ),
|
|
377
|
-
rps_substituido_serie: find_value_for_keys(invoice_hash, invoice_rps_substituido_serie_path ),
|
|
378
|
-
rps_substituido_tipo: find_value_for_keys(invoice_hash, invoice_rps_substituido_tipo_path ),
|
|
379
|
-
data_emissao_rps: find_value_for_keys(invoice_hash, invoice_data_emissao_rps_path ),
|
|
380
|
-
})
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
def build_cancelation_fields_nfe(nfe, invoice_hash)
|
|
384
|
-
nfe.assign_attributes({
|
|
385
|
-
cancelamento_codigo: find_value_for_keys(invoice_hash, invoice_cancelamento_codigo_path ),
|
|
386
|
-
cancelamento_numero_nf: find_value_for_keys(invoice_hash, invoice_cancelamento_numero_nf_path ),
|
|
387
|
-
cancelamento_cnpj: find_value_for_keys(invoice_hash, invoice_cancelamento_cnpj_path ),
|
|
388
|
-
cancelamento_inscricao_municipal: find_value_for_keys(invoice_hash, invoice_cancelamento_inscricao_municipal_path),
|
|
389
|
-
cancelamento_municipio: find_value_for_keys(invoice_hash, invoice_cancelamento_municipio_path ),
|
|
390
|
-
cancelamento_data_hora: find_value_for_keys(invoice_hash, invoice_cancelamento_data_hora_path ),
|
|
391
|
-
nfe_substituidora: find_value_for_keys(invoice_hash, invoice_nfe_substituidora_path ),
|
|
392
|
-
})
|
|
393
|
-
end
|
|
394
|
-
|
|
395
|
-
def build_values_nfe(nfe, invoice_hash)
|
|
396
|
-
nfe.assign_attributes({
|
|
397
|
-
total_services: find_value_for_keys(invoice_hash, invoice_total_services_path ),
|
|
398
|
-
deductions: find_value_for_keys(invoice_hash, invoice_deductions_path ),
|
|
399
|
-
valor_pis: find_value_for_keys(invoice_hash, invoice_valor_pis_path ),
|
|
400
|
-
valor_cofins: find_value_for_keys(invoice_hash, invoice_valor_cofins_path ),
|
|
401
|
-
valor_inss: find_value_for_keys(invoice_hash, invoice_valor_inss_path ),
|
|
402
|
-
valor_ir: find_value_for_keys(invoice_hash, invoice_valor_ir_path ),
|
|
403
|
-
valor_csll: find_value_for_keys(invoice_hash, invoice_valor_csll_path ),
|
|
404
|
-
iss_retained: find_value_for_keys(invoice_hash, invoice_iss_retained_path ),
|
|
405
|
-
outras_retencoes: find_value_for_keys(invoice_hash, invoice_outras_retencoes_path ),
|
|
406
|
-
total_iss: find_value_for_keys(invoice_hash, invoice_total_iss_path ),
|
|
407
|
-
base_calculation: find_value_for_keys(invoice_hash, invoice_base_calculation_path ),
|
|
408
|
-
iss_tax_rate: find_value_for_keys(invoice_hash, invoice_iss_tax_rate_path ),
|
|
409
|
-
valor_liquido: find_value_for_keys(invoice_hash, invoice_valor_liquido_path ),
|
|
410
|
-
desconto_condicionado: find_value_for_keys(invoice_hash, invoice_desconto_condicionado_path ),
|
|
411
|
-
desconto_incondicionado: find_value_for_keys(invoice_hash, invoice_desconto_incondicionado_path ),
|
|
412
|
-
})
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
def build_emitente_nfe(nfe, invoice_hash)
|
|
416
|
-
nfe.assign_attributes({
|
|
417
|
-
emitente: {
|
|
418
|
-
cnpj: find_value_for_keys(invoice_hash, invoice_emitente_cnpj_path ),
|
|
419
|
-
inscricao_municipal: find_value_for_keys(invoice_hash, invoice_emitente_inscricao_municipal_path ),
|
|
420
|
-
razao_social: find_value_for_keys(invoice_hash, invoice_emitente_razao_social_path ),
|
|
421
|
-
nome_fantasia: find_value_for_keys(invoice_hash, invoice_emitente_nome_fantasia_path ),
|
|
422
|
-
telefone: find_value_for_keys(invoice_hash, invoice_emitente_telefone_path ),
|
|
423
|
-
email: find_value_for_keys(invoice_hash, invoice_emitente_email_path ),
|
|
424
|
-
endereco: {
|
|
425
|
-
logradouro: find_value_for_keys(invoice_hash, invoice_emitente_endereco_logradouro_path ),
|
|
426
|
-
numero: find_value_for_keys(invoice_hash, invoice_emitente_endereco_numero_path ),
|
|
427
|
-
complemento: find_value_for_keys(invoice_hash, invoice_emitente_endereco_complemento_path ),
|
|
428
|
-
bairro: find_value_for_keys(invoice_hash, invoice_emitente_endereco_bairro_path ),
|
|
429
|
-
codigo_municipio: find_value_for_keys(invoice_hash, invoice_emitente_endereco_codigo_municipio_path ),
|
|
430
|
-
uf: find_value_for_keys(invoice_hash, invoice_emitente_endereco_uf_path ),
|
|
431
|
-
cep: find_value_for_keys(invoice_hash, invoice_emitente_endereco_cep_path ),
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
})
|
|
435
|
-
end
|
|
436
|
-
|
|
437
|
-
def build_destinatario_nfe(nfe, invoice_hash)
|
|
438
|
-
nfe.assign_attributes({
|
|
439
|
-
destinatario: {
|
|
440
|
-
cpf_cnpj: (find_value_for_keys(invoice_hash, invoice_destinatario_cpf_path) || find_value_for_keys(invoice_hash, invoice_destinatario_cnpj_path)),
|
|
441
|
-
inscricao_municipal: find_value_for_keys(invoice_hash, invoice_destinatario_inscricao_municipal_path),
|
|
442
|
-
inscricao_estadual: find_value_for_keys(invoice_hash, invoice_destinatario_inscricao_estadual_path),
|
|
443
|
-
inscricao_suframa: find_value_for_keys(invoice_hash, invoice_destinatario_inscricao_suframa_path),
|
|
444
|
-
razao_social: find_value_for_keys(invoice_hash, invoice_destinatario_razao_social_path),
|
|
445
|
-
telefone: find_value_for_keys(invoice_hash, invoice_destinatario_telefone_path),
|
|
446
|
-
email: find_value_for_keys(invoice_hash, invoice_destinatario_email_path),
|
|
447
|
-
endereco: {
|
|
448
|
-
logradouro: find_value_for_keys(invoice_hash, invoice_destinatario_endereco_logradouro_path),
|
|
449
|
-
numero: find_value_for_keys(invoice_hash, invoice_destinatario_endereco_numero_path),
|
|
450
|
-
complemento: find_value_for_keys(invoice_hash, invoice_destinatario_endereco_complemento_path),
|
|
451
|
-
bairro: find_value_for_keys(invoice_hash, invoice_destinatario_endereco_bairro_path),
|
|
452
|
-
codigo_municipio: find_value_for_keys(invoice_hash, invoice_destinatario_endereco_codigo_municipio_path),
|
|
453
|
-
uf: find_value_for_keys(invoice_hash, invoice_destinatario_endereco_uf_path),
|
|
454
|
-
cep: find_value_for_keys(invoice_hash, invoice_destinatario_endereco_cep_path),
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
})
|
|
458
|
-
end
|
|
459
|
-
|
|
460
|
-
end
|
|
461
|
-
end
|
|
462
|
-
end
|
|
463
|
-
end
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
module BrNfe
|
|
2
|
-
module Response
|
|
3
|
-
module Service
|
|
4
|
-
class Default < BrNfe::ActiveModelBase
|
|
5
|
-
|
|
6
|
-
# Array contendo as mensagens de erros
|
|
7
|
-
# No array pode conter Hash (com :codigo, :mensagem e :correcao)
|
|
8
|
-
# mas também pode conter mensagens de texto puro
|
|
9
|
-
#
|
|
10
|
-
# <b>Tipo de retorno: </b> _Array_
|
|
11
|
-
#
|
|
12
|
-
attr_accessor :error_messages
|
|
13
|
-
|
|
14
|
-
# Array contendo as notas fiscais encontradas no xml de retorno.
|
|
15
|
-
# Utillizado em algumas requisições onde pode ser que retorne algum XML de NFe
|
|
16
|
-
# É um Array contendo objetos da classe BrNfe::Response::Service::NotaFiscal
|
|
17
|
-
#
|
|
18
|
-
# <b>Tipo de retorno: </b> _Array_
|
|
19
|
-
#
|
|
20
|
-
attr_accessor :notas_fiscais
|
|
21
|
-
|
|
22
|
-
# Número do protocolo de recebimento do XML
|
|
23
|
-
# Setado normalmente quando é enviado um lote RPS
|
|
24
|
-
# para processamento.
|
|
25
|
-
# O valor desse atributo é utilizado para posteriormente
|
|
26
|
-
# fazer a consulta para saber se o RPS já foi processado
|
|
27
|
-
#
|
|
28
|
-
# <b>Tipo de retorno: </b> _Integer_ ou _String_
|
|
29
|
-
#
|
|
30
|
-
attr_accessor :protocolo
|
|
31
|
-
|
|
32
|
-
# Data/Data hora do recebimento do XML pelo orgão emissor
|
|
33
|
-
# Nesse atrubuto pe setado a data/hora na qual o orgão emissor
|
|
34
|
-
# recebeu o XML que foi enviado.
|
|
35
|
-
# também é nesse atributo que é setado a data/hora do processamento
|
|
36
|
-
# da NF-e (nos casos de consulta)
|
|
37
|
-
#
|
|
38
|
-
# <b>Tipo de retorno: </b> _DateTime_
|
|
39
|
-
#
|
|
40
|
-
attr_accessor :data_recebimento
|
|
41
|
-
|
|
42
|
-
# Número do lote RPS
|
|
43
|
-
# Nesse atributo é setado o número do lote RPS
|
|
44
|
-
# quando o mesmo for retornado na resposta
|
|
45
|
-
#
|
|
46
|
-
# <b>Tipo de retorno: </b> _Integer_
|
|
47
|
-
#
|
|
48
|
-
attr_accessor :numero_lote
|
|
49
|
-
|
|
50
|
-
# XML original da resposta
|
|
51
|
-
# Contém todo o XML Envelope da resposta SOAP
|
|
52
|
-
#
|
|
53
|
-
# <b>Tipo de retorno: </b> _String_ XML
|
|
54
|
-
#
|
|
55
|
-
attr_accessor :original_xml
|
|
56
|
-
|
|
57
|
-
# Data e hora do cancelamento da NF-e
|
|
58
|
-
# utilizado apenas para o Cancelamento da NF
|
|
59
|
-
#
|
|
60
|
-
# <b>Tipo de retorno: </b> _DateTime_
|
|
61
|
-
#
|
|
62
|
-
attr_accessor :cancelation_date_time
|
|
63
|
-
|
|
64
|
-
# Status possíveis
|
|
65
|
-
# [:success, :falied, :soap_error, :http_error, :unknown_error]
|
|
66
|
-
#
|
|
67
|
-
# <b>Tipo de retorno: </b> _Hash_
|
|
68
|
-
#
|
|
69
|
-
attr_accessor :status
|
|
70
|
-
|
|
71
|
-
# Código da situação do lote RPS
|
|
72
|
-
# Utilizado para saber se o Lote RPS já foi processado
|
|
73
|
-
# e se foi processado com sucesso ou teve algum erro
|
|
74
|
-
#
|
|
75
|
-
# <b>Tipo de retorno: </b> _Integer_ ou _String_
|
|
76
|
-
#
|
|
77
|
-
attr_accessor :situation
|
|
78
|
-
def situation
|
|
79
|
-
@situation ||= get_situation_by_message_codes if error_messages.present?
|
|
80
|
-
@situation
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def situation_unreceived_code_errors
|
|
84
|
-
@situation_unreceived_code_errors ||= []
|
|
85
|
-
@situation_unreceived_code_errors+['E4']
|
|
86
|
-
end
|
|
87
|
-
def situation_unreceived_code_errors=(value)
|
|
88
|
-
@situation_unreceived_code_errors = [value].flatten
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def situation_unprocessed_code_errors
|
|
92
|
-
@situation_unprocessed_code_errors ||= []
|
|
93
|
-
@situation_unprocessed_code_errors+['E92']
|
|
94
|
-
end
|
|
95
|
-
def situation_unprocessed_code_errors=(value)
|
|
96
|
-
@situation_unprocessed_code_errors = [value].flatten
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def situation_success_code_errors
|
|
100
|
-
@situation_success_code_errors ||= []
|
|
101
|
-
@situation_success_code_errors#+[]
|
|
102
|
-
end
|
|
103
|
-
def situation_success_code_errors=(value)
|
|
104
|
-
@situation_success_code_errors = [value].flatten
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Como alguns orgãos emissores (como a Betha) não tem a capacidade
|
|
108
|
-
# de programar para colocar o codigo da situação em determinados momentos
|
|
109
|
-
# e simplesmente colocam uma mensagem de erro na resposta sem setar a situação
|
|
110
|
-
# foi necessário construir esse método para que a partir dos códigos das mensagens
|
|
111
|
-
# seja possível distinguir qual a situação atual do lote enviado.
|
|
112
|
-
# Por exemplo: Quando retornar o erro com código 'E92' quer dizer que a situação
|
|
113
|
-
# do lote é :unprocessed. Equivalente ao código de situação 2
|
|
114
|
-
#
|
|
115
|
-
# <b>Tipo de retorno: </b> _Symbol_
|
|
116
|
-
#
|
|
117
|
-
def get_situation_by_message_codes
|
|
118
|
-
if (situation_unprocessed_code_errors & message_codes).any?
|
|
119
|
-
:unprocessed
|
|
120
|
-
elsif (situation_unreceived_code_errors & message_codes).any?
|
|
121
|
-
:unreceived
|
|
122
|
-
elsif (situation_success_code_errors & message_codes).any?
|
|
123
|
-
:success
|
|
124
|
-
elsif message_codes.any?
|
|
125
|
-
:error
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def initialize(attributes = {})
|
|
130
|
-
self.notas_fiscais = [] # Para poder utilizar o <<
|
|
131
|
-
self.error_messages = [] # Para poder utilizar o <<
|
|
132
|
-
super
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def notas_fiscais
|
|
136
|
-
@notas_fiscais = [@notas_fiscais].flatten # Para retornar sempre um vetor
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def error_messages
|
|
140
|
-
@error_messages = [@error_messages].flatten
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# Método para saber se a conexão com a prefeitura foi mal-sucedida.
|
|
144
|
-
# Caso ocorra algum erro na requisição irá retornar true.
|
|
145
|
-
#
|
|
146
|
-
# <b>Tipo de retorno: </b> _Boolean_
|
|
147
|
-
#
|
|
148
|
-
def unsuccessful_request?
|
|
149
|
-
status.in?([:soap_error, :http_error, :unknown_error])
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# Método para saber se a conexão com a prefeitura foi bem-sucedida.
|
|
153
|
-
# Caso a requisição ocorra certo e não apresente nenhuma exception
|
|
154
|
-
# irá retornar true.
|
|
155
|
-
#
|
|
156
|
-
# <b>Tipo de retorno: </b> _Boolean_
|
|
157
|
-
#
|
|
158
|
-
def successful_request?
|
|
159
|
-
!unsuccessful_request?
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def success?
|
|
163
|
-
status == :success
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def status
|
|
167
|
-
@status ||= get_status
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def get_status
|
|
171
|
-
error_messages.blank? ? :success : :falied
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# Retorna um array apenas com os códigos das mensagens de erro.
|
|
175
|
-
# Sempre retornar o código no formato de String.
|
|
176
|
-
#
|
|
177
|
-
# <b>Tipo de retorno: </b> _Array_
|
|
178
|
-
#
|
|
179
|
-
def message_codes
|
|
180
|
-
@message_codes ||= error_messages.select{|msg| msg.is_a?(Hash)}.map{|msg| msg[:code].try(:to_s) }
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
end
|