br_nfe 2.0.0 → 2.1.0

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.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/br_nfe/active_model_base.rb +0 -5
  4. data/lib/br_nfe/base.rb +116 -7
  5. data/lib/br_nfe/helper/values_ts/service_v1.rb +15 -11
  6. data/lib/br_nfe/response/service/build_response.rb +230 -53
  7. data/lib/br_nfe/response/service/nota_fiscal.rb +9 -0
  8. data/lib/br_nfe/response/service/paths/base.rb +93 -59
  9. data/lib/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta.rb +2 -2
  10. data/lib/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta.rb +2 -2
  11. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta.rb +2 -2
  12. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta.rb +2 -2
  13. data/lib/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta.rb +4 -4
  14. data/lib/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta.rb +8 -8
  15. data/lib/br_nfe/response/service/paths/v1/tc_nfse.rb +201 -57
  16. data/lib/br_nfe/service/base.rb +104 -5
  17. data/lib/br_nfe/service/betha/base.rb +5 -0
  18. data/lib/br_nfe/service/betha/v1/cancelamento_nfs.rb +1 -4
  19. data/lib/br_nfe/service/betha/v1/consulta_lote_rps.rb +1 -4
  20. data/lib/br_nfe/service/betha/v1/consulta_nfs_por_rps.rb +1 -4
  21. data/lib/br_nfe/service/betha/v1/consulta_nfse.rb +1 -4
  22. data/lib/br_nfe/service/betha/v1/consulta_situacao_lote_rps.rb +1 -3
  23. data/lib/br_nfe/service/betha/v1/gateway.rb +1 -1
  24. data/lib/br_nfe/service/betha/v1/recepcao_lote_rps.rb +1 -3
  25. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta.rb +5 -1
  26. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta.rb +5 -1
  27. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +5 -1
  28. data/lib/br_nfe/service/concerns/rules/cancelamento_nfs.rb +5 -0
  29. data/lib/br_nfe/service/rps.rb +13 -4
  30. data/lib/br_nfe/service/simpliss/v1/base.rb +79 -0
  31. data/lib/br_nfe/service/simpliss/v1/cancela_nfse.rb +30 -0
  32. data/lib/br_nfe/service/simpliss/v1/consulta_lote_rps.rb +38 -0
  33. data/lib/br_nfe/service/simpliss/v1/consulta_nfs_por_rps.rb +31 -0
  34. data/lib/br_nfe/service/simpliss/v1/consulta_nfse.rb +30 -0
  35. data/lib/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps.rb +29 -0
  36. data/lib/br_nfe/service/simpliss/v1/recepcao_lote_rps.rb +35 -0
  37. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_cancelar_nfse_resposta.rb +22 -0
  38. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_lote_rps_resposta.rb +25 -0
  39. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_resposta.rb +25 -0
  40. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +25 -0
  41. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_situacao_lote_rps_resposta.rb +31 -0
  42. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_enviar_lote_rps_resposta.rb +36 -0
  43. data/lib/br_nfe/service/simpliss/v1/xml/_login.xml.slim +3 -0
  44. data/lib/br_nfe/service/simpliss/v1/xml/_tc_dados_servico.xml.slim +18 -0
  45. data/lib/br_nfe/service/simpliss/v1/xml/_tc_item_servico.xml.slim +3 -0
  46. data/lib/br_nfe/service/simpliss/v1/xml/servico_cancelar_nfse_envio.xml.slim +11 -0
  47. data/lib/br_nfe/service/simpliss/v1/xml/servico_consultar_lote_rps_envio.xml.slim +7 -0
  48. data/lib/br_nfe/service/simpliss/v1/xml/servico_consultar_nfse_envio.xml.slim +22 -0
  49. data/lib/br_nfe/service/simpliss/v1/xml/servico_consultar_nfse_rps_envio.xml.slim +8 -0
  50. data/lib/br_nfe/service/simpliss/v1/xml/servico_consultar_situacao_lote_rps_envio.xml.slim +7 -0
  51. data/lib/br_nfe/service/simpliss/v1/xml/servico_enviar_lote_rps_envio.xml.slim +11 -0
  52. data/lib/br_nfe/service/thema/v1/base.rb +48 -2
  53. data/lib/br_nfe/service/thema/v1/cancela_nfse.rb +14 -5
  54. data/lib/br_nfe/service/thema/v1/consulta_lote_rps.rb +5 -4
  55. data/lib/br_nfe/service/thema/v1/consulta_nfs_por_rps.rb +5 -4
  56. data/lib/br_nfe/service/thema/v1/consulta_nfse.rb +5 -4
  57. data/lib/br_nfe/service/thema/v1/consulta_situacao_lote_rps.rb +1 -4
  58. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps.rb +19 -5
  59. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps_limitado.rb +1 -1
  60. data/lib/br_nfe/service/thema/v1/response_paths/servico_cancelar_nfse_resposta.rb +17 -0
  61. data/lib/br_nfe/service/thema/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +19 -0
  62. data/lib/br_nfe/service/xml/v1/_tc_contato.xml.slim +2 -2
  63. data/lib/br_nfe/service/xml/v1/_tc_cpf_cnpj.xml.slim +2 -2
  64. data/lib/br_nfe/service/xml/v1/_tc_dados_construcao_civil.xml.slim +2 -2
  65. data/lib/br_nfe/service/xml/v1/_tc_dados_prestador.xml.slim +5 -5
  66. data/lib/br_nfe/service/xml/v1/_tc_dados_servico.xml.slim +6 -6
  67. data/lib/br_nfe/service/xml/v1/_tc_dados_tomador.xml.slim +4 -4
  68. data/lib/br_nfe/service/xml/v1/_tc_endereco.xml.slim +7 -7
  69. data/lib/br_nfe/service/xml/v1/_tc_identificacao_intermediario_servico.xml.slim +3 -3
  70. data/lib/br_nfe/service/xml/v1/_tc_identificacao_nfse.xml.slim +4 -4
  71. data/lib/br_nfe/service/xml/v1/_tc_identificacao_orgao_gerador.xml.slim +2 -2
  72. data/lib/br_nfe/service/xml/v1/_tc_identificacao_prestador.xml.slim +2 -2
  73. data/lib/br_nfe/service/xml/v1/_tc_identificacao_rps.xml.slim +3 -3
  74. data/lib/br_nfe/service/xml/v1/_tc_identificacao_tomador.xml.slim +2 -2
  75. data/lib/br_nfe/service/xml/v1/_tc_inf_pedido_cancelamento.xml.slim +2 -2
  76. data/lib/br_nfe/service/xml/v1/_tc_inf_rps.xml.slim +13 -13
  77. data/lib/br_nfe/service/xml/v1/_tc_lote_rps.xml.slim +6 -6
  78. data/lib/br_nfe/service/xml/v1/_tc_pedido_cancelamento.xml.slim +1 -1
  79. data/lib/br_nfe/service/xml/v1/_tc_rps.xml.slim +2 -2
  80. data/lib/br_nfe/service/xml/v1/_tc_valores.xml.slim +16 -17
  81. data/lib/br_nfe/service/xml/v1/servico_cancelar_nfse_envio.xml.slim +3 -4
  82. data/lib/br_nfe/service/xml/v1/servico_consultar_lote_rps_envio.xml.slim +3 -3
  83. data/lib/br_nfe/service/xml/v1/servico_consultar_nfse_envio.xml.slim +8 -8
  84. data/lib/br_nfe/service/xml/v1/servico_consultar_nfse_rps_envio.xml.slim +3 -3
  85. data/lib/br_nfe/service/xml/v1/servico_consultar_situacao_lote_rps_envio.xml.slim +3 -3
  86. data/lib/br_nfe/service/xml/v1/servico_enviar_lote_rps_envio.xml.slim +3 -3
  87. data/lib/br_nfe/version.rb +1 -1
  88. data/lib/br_nfe/xml/_signed_info_sh1.xml.slim +9 -9
  89. data/lib/br_nfe/xml/signature_sh1.xml.slim +5 -5
  90. data/lib/br_nfe.rb +26 -10
  91. data/test/br_nfe/base_test.rb +5 -5
  92. data/test/br_nfe/helper/values_ts/service_v1_test.rb +376 -0
  93. data/test/br_nfe/response/service/build_response_test.rb +1 -173
  94. data/test/br_nfe/response/service/paths/base_test.rb +61 -64
  95. data/test/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta_test.rb +2 -2
  96. data/test/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta_test.rb +2 -2
  97. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta_test.rb +2 -2
  98. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta_test.rb +2 -2
  99. data/test/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta_test.rb +3 -3
  100. data/test/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta_test.rb +4 -4
  101. data/test/br_nfe/response/service/paths/v1/tc_nfse_test.rb +27 -31
  102. data/test/br_nfe/service/base_test.rb +206 -11
  103. data/test/br_nfe/service/betha/base_test.rb +9 -0
  104. data/test/br_nfe/service/betha/v1/cancelamento_nfs_test.rb +0 -6
  105. data/test/br_nfe/service/betha/v1/consulta_lote_rps_test.rb +0 -6
  106. data/test/br_nfe/service/betha/v1/consulta_nfs_por_rps_test.rb +0 -4
  107. data/test/br_nfe/service/betha/v1/consulta_nfse_test.rb +0 -4
  108. data/test/br_nfe/service/betha/v1/consulta_situacao_lote_rps_test.rb +1 -5
  109. data/test/br_nfe/service/betha/v1/gateway_test.rb +4 -2
  110. data/test/br_nfe/service/betha/v1/recepcao_lote_rps_test.rb +0 -4
  111. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta_test.rb +1 -1
  112. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta_test.rb +1 -1
  113. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta_test.rb +1 -1
  114. data/test/br_nfe/service/rps_test.rb +39 -6
  115. data/test/br_nfe/service/simpliss/v1/base_test.rb +102 -0
  116. data/test/br_nfe/service/simpliss/v1/cancela_nfse_test.rb +97 -0
  117. data/test/br_nfe/service/simpliss/v1/consulta_lote_rps_test.rb +241 -0
  118. data/test/br_nfe/service/simpliss/v1/consulta_nfs_por_rps_test.rb +239 -0
  119. data/test/br_nfe/service/simpliss/v1/consulta_nfse_test.rb +226 -0
  120. data/test/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps_test.rb +122 -0
  121. data/test/br_nfe/service/simpliss/v1/recepcao_lote_rps_test.rb +105 -0
  122. data/test/br_nfe/service/simpliss/v1/xsd/nfse_3.xsd +735 -0
  123. data/test/br_nfe/service/simpliss/v1/xsd/xmldsig-core-schema20020212.xsd +318 -0
  124. data/test/br_nfe/service/thema/v1/base_test.rb +23 -2
  125. data/test/br_nfe/service/thema/v1/cancela_nfse_test.rb +69 -3
  126. data/test/br_nfe/service/thema/v1/consulta_lote_rps_test.rb +134 -4
  127. data/test/br_nfe/service/thema/v1/consulta_nfs_por_rps_test.rb +131 -4
  128. data/test/br_nfe/service/thema/v1/consulta_nfse_test.rb +214 -4
  129. data/test/br_nfe/service/thema/v1/consulta_situacao_lote_rps_test.rb +97 -4
  130. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_limitado_test.rb +109 -0
  131. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test.rb +72 -4
  132. data/test/factories/service/rps.rb +17 -16
  133. data/test/factories/service/{sc/gaspar/recepcao_lote_rps_limitado.rb → simpliss/v1/base.rb} +1 -3
  134. data/test/factories/service/{sc/gaspar → simpliss/v1}/cancela_nfse.rb +2 -2
  135. data/test/factories/service/simpliss/v1/consulta_lote_rps.rb +7 -0
  136. data/test/factories/service/{sc/gaspar → simpliss/v1}/consulta_nfs_por_rps.rb +1 -1
  137. data/test/factories/service/{sc/gaspar → simpliss/v1}/consulta_nfse.rb +1 -1
  138. data/test/factories/service/simpliss/v1/consulta_situacao_lote_rps.rb +6 -0
  139. data/test/factories/service/{sc/gaspar → simpliss/v1}/recepcao_lote_rps.rb +1 -1
  140. data/test/fixtures/service/response/simpliss/v1/cancela_nfse/fault.xml +21 -0
  141. data/test/fixtures/service/response/simpliss/v1/cancela_nfse/success.xml +26 -0
  142. data/test/fixtures/service/response/simpliss/v1/consulta_lote_rps/fault.xml +21 -0
  143. data/test/fixtures/service/response/simpliss/v1/consulta_lote_rps/nfse_complete.xml +134 -0
  144. data/test/fixtures/service/response/simpliss/v1/consulta_lote_rps/nfse_simple.xml +100 -0
  145. data/test/fixtures/service/response/simpliss/v1/consulta_nfse/fault.xml +16 -0
  146. data/test/fixtures/service/response/simpliss/v1/consulta_nfse/nfs_empty.xml +10 -0
  147. data/test/fixtures/service/response/simpliss/v1/consulta_nfse/nfse_complete.xml +134 -0
  148. data/test/fixtures/service/response/simpliss/v1/consulta_nfse/nfse_simple.xml +100 -0
  149. data/test/fixtures/service/response/simpliss/v1/consulta_nfse_por_rps/fault.xml +16 -0
  150. data/test/fixtures/service/response/simpliss/v1/consulta_nfse_por_rps/nfse_complete.xml +132 -0
  151. data/test/fixtures/service/response/simpliss/v1/consulta_nfse_por_rps/nfse_simple.xml +98 -0
  152. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/error.xml +11 -0
  153. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/fault.xml +16 -0
  154. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/success.xml +11 -0
  155. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/unprocessed.xml +11 -0
  156. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/unreceived.xml +11 -0
  157. data/test/fixtures/service/response/simpliss/v1/recepcao_lote_rps/error.xml +16 -0
  158. data/test/fixtures/service/response/simpliss/v1/recepcao_lote_rps/success.xml +12 -0
  159. data/test/fixtures/service/response/thema/v1/cancela_nfse/fault.xml +33 -0
  160. data/test/fixtures/service/response/thema/v1/cancela_nfse/success.xml +30 -0
  161. data/test/fixtures/service/response/thema/v1/consulta_lote_rps/fault.xml +19 -0
  162. data/test/fixtures/service/response/thema/v1/consulta_lote_rps/nfse_complete.xml +109 -0
  163. data/test/fixtures/service/response/thema/v1/consulta_nfse/fault.xml +20 -0
  164. data/test/fixtures/service/response/thema/v1/consulta_nfse/nfs_empty.xml +14 -0
  165. data/test/fixtures/service/response/thema/v1/consulta_nfse/nfse_complete.xml +111 -0
  166. data/test/fixtures/service/response/thema/v1/consulta_nfse/nfse_simple.xml +111 -0
  167. data/test/fixtures/service/response/thema/v1/consulta_nfse_por_rps/fault.xml +23 -0
  168. data/test/fixtures/service/response/thema/v1/consulta_nfse_por_rps/nfse_complete.xml +110 -0
  169. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/error.xml +14 -0
  170. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/fault.xml +15 -0
  171. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/success.xml +14 -0
  172. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/unprocessed.xml +14 -0
  173. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/unreceived.xml +19 -0
  174. data/test/fixtures/service/response/thema/v1/recepcao_lote_rps/error.xml +17 -0
  175. data/test/fixtures/service/response/thema/v1/recepcao_lote_rps/success.xml +15 -0
  176. data/test/fixtures/service/response/thema/v1/recepcao_lote_rps_limitado/error.xml +19 -0
  177. data/test/fixtures/service/response/thema/v1/recepcao_lote_rps_limitado/success.xml +15 -0
  178. data/test/fixtures/service/thema/v1/cancelar_nfse_envio.xml +1 -0
  179. data/test/fixtures/service/thema/v1/cancelar_nfse_envio_signed.xml +2 -0
  180. data/test/fixtures/service/thema/v1/enviar_lote_rps.xml +1 -0
  181. data/test/fixtures/service/thema/v1/enviar_lote_rps_signed.xml +2 -0
  182. data/test/test_helper.rb +5 -0
  183. metadata +146 -37
  184. data/lib/br_nfe/service/sc/gaspar/cancela_nfse.rb +0 -13
  185. data/lib/br_nfe/service/sc/gaspar/consulta_lote_rps.rb +0 -13
  186. data/lib/br_nfe/service/sc/gaspar/consulta_nfs_por_rps.rb +0 -13
  187. data/lib/br_nfe/service/sc/gaspar/consulta_nfse.rb +0 -17
  188. data/lib/br_nfe/service/sc/gaspar/consulta_situacao_lote_rps.rb +0 -13
  189. data/lib/br_nfe/service/sc/gaspar/recepcao_lote_rps.rb +0 -13
  190. data/lib/br_nfe/service/sc/gaspar/recepcao_lote_rps_limitado.rb +0 -13
  191. data/test/br_nfe/service/sc/gaspar/cancela_nfse_test.rb +0 -21
  192. data/test/br_nfe/service/sc/gaspar/consulta_nfs_por_rps_test.rb +0 -21
  193. data/test/br_nfe/service/sc/gaspar/consulta_nfse_test.rb +0 -21
  194. data/test/br_nfe/service/sc/gaspar/consulta_situacao_lote_rps_test.rb +0 -21
  195. data/test/br_nfe/service/sc/gaspar/recepcao_lote_rps_limitado_test.rb +0 -22
  196. data/test/br_nfe/service/sc/gaspar/recepcao_lote_rps_test.rb +0 -22
  197. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test_limitado.rb +0 -50
  198. data/test/factories/service/sc/gaspar/consulta_lote_rps.rb +0 -7
  199. data/test/factories/service/sc/gaspar/consulta_situacao_lote_rps.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcf8317971e11086557fdb6a9041f0e870acaeaa
4
- data.tar.gz: c5ef4f3c19e466e9fb4d1ffa62478075355c9d97
3
+ metadata.gz: ea6a1eaa1f98eb411c09920514df79554940ad0d
4
+ data.tar.gz: 8b05a7fd858d2e170dfb265ed3fb24cce070897b
5
5
  SHA512:
6
- metadata.gz: d553904a62f2c4aa1c52d8d6a6c963477462da19f2938baa27c51ec282f97a8ab04ed04c11678efee48a40134016b84353792d035f66024b746c941154c50441
7
- data.tar.gz: ced46055c7c90db5905f233794d096317ee3a8d74be72cc4346c4f1a308f47544ee0ddb077c5313fa78a416b53b7bfbbab4a1bbf2da36583b2fa3f47d071fd6c
6
+ metadata.gz: 0472708c6a76b15978beb4ea13eed887839e5fc6375fe862a64f10f8820bb1a5214e55a33ae42291357bbf9ffd0b8b1748b54d4bad4588e24c63a58a18529985
7
+ data.tar.gz: 0fb2ab18fd1a9e2068d14be52572e1f2bec77390a654abc9ebdef6cba583d977935562a4b5e245aee7beb8bc27392fb5ed2ddea51628ad11cafd8a4b33dee618
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_nfe (2.0.0)
4
+ br_nfe (2.1.0)
5
5
  activemodel (~> 4)
6
6
  activesupport (~> 4)
7
7
  nokogiri (~> 1.6)
@@ -40,11 +40,6 @@ module BrNfe
40
40
  return ''
41
41
  end
42
42
 
43
- # Irá retornar 1(true) e 2(false)
44
- def value_true_false(value)
45
- BrNfe.true_values.include?(value) ? '1' : '2'
46
- end
47
-
48
43
  # Deve receber um valor do tipo float
49
44
  # Irá retornar o valor com a precisão
50
45
  # Alguns WS convertem os valores para String com separador de milhar uma vírgula
data/lib/br_nfe/base.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module BrNfe
2
2
  class Base < BrNfe::ActiveModelBase
3
-
4
3
  include BrNfe::Helper::HaveEmitente
5
4
 
6
5
  attr_accessor :certificate_pkcs12_password
@@ -73,17 +72,35 @@ module BrNfe
73
72
  # o namespace utilizado para identificar o namespace da mensagem.
74
73
  #
75
74
  # Exemplo: se o método message_namespaces for {xmlns:ns1="http...."} então
76
- # o namespace_identifier deveria ser :ns1.
75
+ # o namespace_identifier deveria ser 'ns1:'.
77
76
  # E com isso irá adicionar o namespace na tag principal da requsição.
78
77
  # Exemplo com a requisição EnviarLoteRps:
79
78
  # COM namespace_identifier => ns1:EnviarLoteRpsEnvio
80
79
  # SEM namespace_identifier => EnviarLoteRpsEnvio
81
80
  #
82
- # <b>Tipo de retorno: </b> _Hash_ OR _Nil_
81
+ # <b>Tipo de retorno: </b> _String_ OR _Nil_
83
82
  #
84
83
  def namespace_identifier
85
84
  end
86
85
 
86
+ # Utilizado para colocar o namespace nas tags de valores
87
+ # Exemplo:
88
+ # <ns1:LoteRps id="123">
89
+ # <ns1:NumeroLote>3311</ns1:NumeroLote>
90
+ # <ns1:Cnpj>23020443000140</ns1:Cnpj>
91
+ def namespace_for_tags
92
+ end
93
+
94
+ # Utilizado para colocar o namespace nas tags da assiantura
95
+ # Exemplo:
96
+ # <ns2:Signature Id="?">
97
+ # <ns2:SignedInfo Id="?">
98
+ # <ns2:CanonicalizationMethod Algorithm="?">?</ns2:CanonicalizationMethod>
99
+ # .....
100
+ #
101
+ def namespace_for_signature
102
+ end
103
+
87
104
  def message_namespaces
88
105
  {}
89
106
  end
@@ -101,6 +118,10 @@ module BrNfe
101
118
  "UTF-8"
102
119
  end
103
120
 
121
+ def response_encoding
122
+ "UTF-8"
123
+ end
124
+
104
125
  # Tag XML que vai na requisição SOAP
105
126
  #
106
127
  # <b>Tipo de retorno: </b> _String_
@@ -161,8 +182,17 @@ module BrNfe
161
182
  def certificate_pkcs12
162
183
  return @certificate_pkcs12 if @certificate_pkcs12
163
184
  @certificate_pkcs12 = nil
164
- # Correção bug http://stackoverflow.com/questions/33112155/pgconnectionbad-pqconsumeinput-ssl-error-key-values-mismatch/36283315#36283315
165
- Thread.new { @certificate_pkcs12 = OpenSSL::PKCS12.new(certificate_pkcs12_value, certificate_pkcs12_password) }.join
185
+
186
+ # É utilizado uma Thread e limpado os errors do OpenSSL para evitar perda de
187
+ # conexão com o banco de dados PostgreSQL.
188
+ # Veja: http://stackoverflow.com/questions/33112155/pgconnectionbad-pqconsumeinput-ssl-error-key-values-mismatch/36283315#36283315
189
+ # Veja: https://github.com/tedconf/front_end_builds/pull/66
190
+ Thread.new do
191
+ @certificate_pkcs12 = OpenSSL::PKCS12.new(certificate_pkcs12_value, certificate_pkcs12_password)
192
+ OpenSSL.errors.clear
193
+ end.join
194
+ OpenSSL.errors.clear
195
+
166
196
  @certificate_pkcs12
167
197
  rescue
168
198
  end
@@ -185,7 +215,7 @@ module BrNfe
185
215
 
186
216
  def certificate_key=(value)
187
217
  @certificate_key = value
188
- end
218
+ end
189
219
 
190
220
  # Renderiza o xml a partir do nome de um arquivo
191
221
  # Irá procurar o arquivo a partir dos seguintes diretórios>
@@ -245,13 +275,92 @@ module BrNfe
245
275
  "#{BrNfe.root}/lib/br_nfe/xml"
246
276
  end
247
277
 
278
+ # Existem 2 tipos de assinatura da NFS-e
279
+ # * [+:default+]
280
+ # Assina o XML no momento em que está sendo montado. Funciona normalmente para a
281
+ # maiora das prefeituras.
282
+ # Primeiro assina cada RPS individualmente e adiciona a tag da assinatura e depois
283
+ # Assina o LOTE RPS com todas os RPSs assinados
284
+ #
285
+ # * [+:method_sign+]
286
+ # Assina o XML após a montagem do mesmo. Utiliza a gem 'signer' para assinar os nós do XML.
287
+ # Adiciona toda a assinatura no final do XML, diferente do que é descrito nas documentações.
288
+ # Porém em algumas cidades só consegui validar a assinatura utilizando esse método
289
+ # Estava dando o erro: E515 - Erro ao validar assinatura. - Remessa adulterada após a assinatura.
290
+ #
291
+ def signature_type
292
+ :default
293
+ end
294
+ def signature_type?(type)
295
+ signature_type == type
296
+ end
297
+
298
+ # USE EXAMPLE
299
+ # @xml = <?xml version="1.0" encoding="ISO-8859-1"?>
300
+ # <EnviarLoteRpsEnvio xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd">
301
+ # <LoteRps id="L2">
302
+ # ...
303
+ # <ListaRps>
304
+ # <Rps>
305
+ # <InfRps id="R2">
306
+ # ...
307
+ # </>InfRps
308
+ # </Rps>
309
+ # <Rps>
310
+ # <InfRps id="R3">
311
+ # ...
312
+ # </>InfRps
313
+ # </Rps>
314
+ # </ListaRps>
315
+ # </LoteRps>
316
+ # </EnviarLoteRpsEnvio>
317
+ # sign_nodes = [
318
+ # {
319
+ # node_path: "//nf:EnviarLoteRpsEnvio/nf:LoteRps/nf:ListaRps/nf:Rps/nf:InfRps",
320
+ # node_namespaces: {nf: 'http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd'},
321
+ # node_ids: ['R2','R3']
322
+ # },
323
+ # {
324
+ # node_path: "//nf:EnviarLoteRpsEnvio/nf:LoteRps",
325
+ # node_namespaces: {nf: 'http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd'},
326
+ # node_ids: ['L2']
327
+ # },
328
+ # ]
329
+ #
330
+ # Call Method:
331
+ # sign_xml(@xml, sign_nodes)
332
+ #
333
+ def sign_xml(xml, sign_nodes=[])
334
+ return xml unless certificate
335
+ signer = Signer.new(xml)
336
+ signer.cert = certificate
337
+ signer.private_key = certificate_key
338
+
339
+ # Como o documento não é um envelope SOAP preciso setar o security_node e o security_token_id
340
+ signer.security_node = signer.document.root
341
+ signer.security_token_id = ""
342
+
343
+ sign_nodes.each do |options|
344
+ node_ids = [options[:node_ids]].flatten
345
+ signer.document.xpath(options[:node_path], options[:node_namespaces]).each_with_index do |node, i|
346
+ # digo quais tags devem ser assinadas
347
+ signer.digest!(node, id: "#{node_ids[i]}", enveloped: true)
348
+ end
349
+ end
350
+
351
+ # Assina o XML
352
+ signer.sign!(security_token: false, issuer_serial: true)
353
+
354
+ signer.to_xml
355
+ end
356
+
248
357
  private
249
358
 
250
359
  def tag_cpf_cnpj(xml, cpf_cnpj)
251
360
  cpf_cnpj = BrNfe::Helper::CpfCnpj.new(cpf_cnpj)
252
361
  if cpf_cnpj.cnpj?
253
362
  xml.Cnpj cpf_cnpj.sem_formatacao
254
- elsif cpf_cnpj.cpf?
363
+ elsif cpf_cnpj.cpf?
255
364
  xml.Cpf cpf_cnpj.sem_formatacao
256
365
  end
257
366
  end
@@ -61,7 +61,7 @@ module BrNfe
61
61
  # 2 - Não
62
62
  #
63
63
  def ts_sim_nao value
64
- value_true_false(value)
64
+ BrNfe.true_values.include?(value) ? '1' : '2'
65
65
  end
66
66
 
67
67
  # Quantidade de RPS do Lote
@@ -104,15 +104,19 @@ module BrNfe
104
104
  # 1.000,00 = 1000
105
105
  #
106
106
  def ts_valor value
107
- "#{value_monetary(value, 2)}".max_size(17)
107
+ value.to_f.round(2) if value.present?
108
108
  end
109
109
 
110
110
  # Código de item da lista de serviço
111
+ # Se um serviço for por exemplo: 107 deve ser enviado no formato
112
+ # 1.07
111
113
  #
112
114
  def ts_item_lista_servico value
113
- BrNfe::Helper.only_number(value).max_size(5).rjust(4, '0')
115
+ return if value.blank?
116
+ number_only = BrNfe::Helper.only_number(value).max_size(4).to_i.to_s
117
+ number_only.reverse.scan(/.{1,2}/).join('.').reverse
114
118
  end
115
-
119
+
116
120
  # Código CNAE
117
121
  #
118
122
  def ts_codigo_cnae value
@@ -127,12 +131,12 @@ module BrNfe
127
131
 
128
132
  # Alíquota. Valor percentual.
129
133
  # Formato: 0.0000
130
- # Ex: 1% = 0.01
131
- # 25,5% = 0.255
132
- # 100% = 1.0000 ou 1
134
+ # Ex: 1% = 1.00
135
+ # 25,5% = 25.5
136
+ # 100% = 100.0000 ou 100
133
137
  #
134
138
  def ts_aliquota value
135
- "#{value_monetary(value, 4)}".max_size(9)
139
+ value_monetary(value, 4)
136
140
  end
137
141
 
138
142
  # Discriminação do conteúdo da NFS-e
@@ -204,7 +208,7 @@ module BrNfe
204
208
  # Número do CEP
205
209
  #
206
210
  def ts_cep value
207
- BrNfe::Helper.only_number(value).max_size(8)
211
+ BrNfe::Helper.only_number(value).max_size(8).ljust(8, '0') if value.present?
208
212
  end
209
213
 
210
214
  # E-mail
@@ -216,7 +220,7 @@ module BrNfe
216
220
  # Telefone
217
221
  #
218
222
  def ts_telefone value
219
- "#{value}".max_size(11)
223
+ BrNfe::Helper.only_number(value).max_size(11)
220
224
  end
221
225
 
222
226
  # Número CPF
@@ -230,7 +234,7 @@ module BrNfe
230
234
  # 2 – CNPJ
231
235
  # 3 – Não Informado
232
236
  #
233
- def ts_indicacao_cpf_cnpj
237
+ def ts_indicacao_cpf_cnpj value
234
238
  BrNfe::Helper.only_number(value).max_size(1)
235
239
  end
236
240
 
@@ -6,33 +6,127 @@ module BrNfe
6
6
  # 1: A resposta da requisição soap
7
7
  attr_accessor :savon_response
8
8
 
9
- # 2: O module que será incluido contendo os métodos com os
10
- # caminhos das chaves para encontrar cada valor
11
- attr_accessor :module_methods
12
-
13
- # 3: Um array com o caminho inicial padrão da requisição de retorno
9
+ # 2: Um array com o caminho inicial padrão da requisição de retorno
14
10
  attr_accessor :keys_root_path
15
11
 
16
- # 4: Caminho para encontrar o XML da NF-e
12
+ # 3: Caminho para encontrar o XML da NF-e
17
13
  attr_accessor :nfe_xml_path
18
14
 
19
- # 5: Alguns Webservices trazem dentro do body da resposta SOAp
15
+ # 4: Alguns Webservices trazem dentro do body da resposta SOAp
20
16
  # outro XML com as informações necessárias.
21
17
  # Quando isso aocntece é preciso converter esse XML para um HASH
22
18
  # para que possamos encontrar os valores necessários.
23
19
  attr_accessor :body_xml_path
24
-
25
- def initialize(attributes = {})
26
- super(attributes)
27
- include_module!
28
- end
29
20
 
30
- # Método utilizado para incluir módules dinâmicos
31
- #
32
- def include_module!
33
- self.class.send(:include, module_methods) if module_methods
34
- end
21
+ # 5: Codificação original do XML de resposta para que seja convertido
22
+ # para UTF-8
23
+ attr_accessor :xml_encode
35
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
+
36
130
  def response
37
131
  @response ||= BrNfe::Response::Service::Default.new({
38
132
  error_messages: get_message_for_path(message_errors_path),
@@ -55,13 +149,22 @@ module BrNfe
55
149
  return @savon_body if @savon_body.present?
56
150
  if body_xml_path.present?
57
151
  @savon_body = Nori.new.parse(
58
- find_value_for_keys(savon_response.try(:body), body_xml_path)
152
+ body_converted_to_xml
59
153
  ).deep_transform_keys!{|k| k.to_s.underscore.to_sym}
60
154
  else
61
155
  @savon_body = savon_response.try(:body) || {}
62
156
  end
63
157
  end
64
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
+
65
168
  # Método utilizado para encontrar valores em um Hash
66
169
  # passando o caminho do valor em um array onde contém as chaves
67
170
  # ordenadas.
@@ -122,11 +225,11 @@ module BrNfe
122
225
  if _messages.is_a?(Hash)
123
226
  messages << get_message_for_hash(_messages)
124
227
  elsif _messages.is_a?(Array)
125
- _messages.map{|msg| messages << get_message_for_hash(msg) }
228
+ _messages.map{|msg| messages << get_message_for_hash(msg) if msg.present? }
126
229
  elsif _messages.present?
127
230
  messages << _messages
128
231
  end
129
- messages
232
+ messages.uniq
130
233
  end
131
234
 
132
235
  # Método utilizado para quando encontrar uam mensagem que seja um HAsh,
@@ -155,11 +258,11 @@ module BrNfe
155
258
  #
156
259
  def get_invoices
157
260
  invoices = []
158
- _inoices = find_value_for_keys(savon_body, path_with_root(invoices_path))
159
- if _inoices.is_a?(Hash)
160
- invoices << instance_invoice(_inoices)
161
- elsif _inoices.is_a?(Array)
162
- _inoices.map{|inv| invoices << instance_invoice(inv) }
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) }
163
266
  end
164
267
  invoices
165
268
  end
@@ -208,7 +311,11 @@ module BrNfe
208
311
  # <b>Tipo de retorno: </b> _String_
209
312
  #
210
313
  def get_xml_nf
211
- canonicalize(Nokogiri::XML.parse(canonicalize(savon_response.doc.to_s), nil, 'UTF-8').xpath(nfe_xml_path).to_xml)
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
212
319
  rescue
213
320
  savon_response.xml
214
321
  end
@@ -227,56 +334,126 @@ module BrNfe
227
334
  # O parâmetro recebido deve ser o Hash representado pelo tipo de dados tcCompNfse(do manual NFS-e v1)
228
335
  #
229
336
  def instance_invoice(invoice_hash)
230
- BrNfe::Response::Service::NotaFiscal.new({
337
+ nfe = BrNfe::Response::Service::NotaFiscal.new({
231
338
  xml_nf: get_xml_nf.force_encoding('UTF-8'),
232
339
  numero_nf: find_value_for_keys(invoice_hash, invoice_numero_nf_path ),
233
340
  codigo_verificacao: find_value_for_keys(invoice_hash, invoice_codigo_verificacao_path ),
234
341
  data_emissao: find_value_for_keys(invoice_hash, invoice_data_emissao_path ),
235
342
  url_nf: find_value_for_keys(invoice_hash, invoice_url_nf_path ),
236
- rps_numero: find_value_for_keys(invoice_hash, invoice_rps_numero_path ),
237
- rps_serie: find_value_for_keys(invoice_hash, invoice_rps_serie_path ),
238
- rps_tipo: find_value_for_keys(invoice_hash, invoice_rps_tipo_path ),
239
- rps_situacao: find_value_for_keys(invoice_hash, invoice_rps_situacao_path ),
240
- rps_substituido_numero: find_value_for_keys(invoice_hash, invoice_rps_substituido_numero_path ),
241
- rps_substituido_serie: find_value_for_keys(invoice_hash, invoice_rps_substituido_serie_path ),
242
- rps_substituido_tipo: find_value_for_keys(invoice_hash, invoice_rps_substituido_tipo_path ),
243
- data_emissao_rps: find_value_for_keys(invoice_hash, invoice_data_emissao_rps_path ),
244
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 ),
245
348
  outras_informacoes: find_value_for_keys(invoice_hash, invoice_outras_informacoes_path ),
246
349
  item_lista_servico: find_value_for_keys(invoice_hash, invoice_item_lista_servico_path ),
247
350
  cnae_code: find_value_for_keys(invoice_hash, invoice_cnae_code_path ),
248
351
  description: find_value_for_keys(invoice_hash, invoice_description_path ),
249
352
  codigo_municipio: find_value_for_keys(invoice_hash, invoice_codigo_municipio_path ),
250
- total_services: find_value_for_keys(invoice_hash, invoice_total_services_path ),
251
- deductions: find_value_for_keys(invoice_hash, invoice_deductions_path ),
252
- valor_pis: find_value_for_keys(invoice_hash, invoice_valor_pis_path ),
253
- valor_cofins: find_value_for_keys(invoice_hash, invoice_valor_cofins_path ),
254
- valor_inss: find_value_for_keys(invoice_hash, invoice_valor_inss_path ),
255
- valor_ir: find_value_for_keys(invoice_hash, invoice_valor_ir_path ),
256
- valor_csll: find_value_for_keys(invoice_hash, invoice_valor_csll_path ),
257
- iss_retained: find_value_for_keys(invoice_hash, invoice_iss_retained_path ),
258
- outras_retencoes: find_value_for_keys(invoice_hash, invoice_outras_retencoes_path ),
259
- total_iss: find_value_for_keys(invoice_hash, invoice_total_iss_path ),
260
- base_calculation: find_value_for_keys(invoice_hash, invoice_base_calculation_path ),
261
- iss_tax_rate: find_value_for_keys(invoice_hash, invoice_iss_tax_rate_path ),
262
- valor_liquido: find_value_for_keys(invoice_hash, invoice_valor_liquido_path ),
263
- desconto_condicionado: find_value_for_keys(invoice_hash, invoice_desconto_condicionado_path ),
264
- desconto_incondicionado: find_value_for_keys(invoice_hash, invoice_desconto_incondicionado_path ),
265
353
  responsavel_retencao: find_value_for_keys(invoice_hash, invoice_responsavel_retencao_path ),
266
354
  numero_processo: find_value_for_keys(invoice_hash, invoice_numero_processo_path ),
267
355
  municipio_incidencia: find_value_for_keys(invoice_hash, invoice_municipio_incidencia_path ),
268
356
  orgao_gerador_municipio: find_value_for_keys(invoice_hash, invoice_orgao_gerador_municipio_path ),
269
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({
270
385
  cancelamento_codigo: find_value_for_keys(invoice_hash, invoice_cancelamento_codigo_path ),
271
386
  cancelamento_numero_nf: find_value_for_keys(invoice_hash, invoice_cancelamento_numero_nf_path ),
272
387
  cancelamento_cnpj: find_value_for_keys(invoice_hash, invoice_cancelamento_cnpj_path ),
273
388
  cancelamento_inscricao_municipal: find_value_for_keys(invoice_hash, invoice_cancelamento_inscricao_municipal_path),
274
389
  cancelamento_municipio: find_value_for_keys(invoice_hash, invoice_cancelamento_municipio_path ),
275
- cancelamento_sucesso: find_value_for_keys(invoice_hash, invoice_cancelamento_sucesso_path ),
276
390
  cancelamento_data_hora: find_value_for_keys(invoice_hash, invoice_cancelamento_data_hora_path ),
277
391
  nfe_substituidora: find_value_for_keys(invoice_hash, invoice_nfe_substituidora_path ),
278
- codigo_obra: find_value_for_keys(invoice_hash, invoice_codigo_obra_path ),
279
- codigo_art: find_value_for_keys(invoice_hash, invoice_codigo_art_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
+ }
280
457
  })
281
458
  end
282
459