br_nfe 2.3.2 → 3.0.0.beta.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.markdown +1 -1
  4. data/br_nfe.gemspec +0 -0
  5. data/lib/br_nfe/constants.rb +2 -2
  6. data/lib/br_nfe/product/nf_xml_value.rb +6 -11
  7. data/lib/br_nfe/product/nfe/cobranca/pagamento.rb +39 -12
  8. data/lib/br_nfe/product/nfe/item.rb +83 -36
  9. data/lib/br_nfe/product/nfe/item_tax/icms.rb +182 -46
  10. data/lib/br_nfe/product/nfe/item_tax/icms_uf_destino.rb +33 -22
  11. data/lib/br_nfe/product/nfe/item_tax/ipi.rb +18 -18
  12. data/lib/br_nfe/product/nfe/transporte/base.rb +17 -15
  13. data/lib/br_nfe/product/nota_fiscal.rb +72 -6
  14. data/lib/br_nfe/product/operation/base.rb +14 -13
  15. data/lib/br_nfe/product/reader/item.rb +19 -2
  16. data/lib/br_nfe/product/reader/nfe.rb +28 -9
  17. data/lib/br_nfe/product/xml/v3_10/infNFe/det/_tc_prod.xml.slim +2 -2
  18. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/_tc_ICMSUFDest.xml.slim +1 -1
  19. data/lib/br_nfe/product/xml/v4_00/_tc_infNFe.xml.slim +45 -0
  20. data/lib/br_nfe/product/xml/v4_00/infNFe/_tc_ide.xml.slim +30 -0
  21. data/lib/br_nfe/product/xml/v4_00/infNFe/_tc_total.xml.slim +84 -0
  22. data/lib/br_nfe/product/xml/v4_00/infNFe/det/_tc_prod.xml.slim +62 -0
  23. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS00.xml.slim +11 -0
  24. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS10.xml.slim +28 -0
  25. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS20.xml.slim +18 -0
  26. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS201.xml.slim +21 -0
  27. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS202.xml.slim +20 -0
  28. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS30.xml.slim +23 -0
  29. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS500.xml.slim +13 -0
  30. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS51.xml.slim +25 -0
  31. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS60.xml.slim +12 -0
  32. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS70.xml.slim +35 -0
  33. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS90.xml.slim +38 -0
  34. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/ICMS/_tc_ICMS900.xml.slim +31 -0
  35. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/_tc_ICMSUFDest.xml.slim +15 -0
  36. data/lib/br_nfe/product/xml/v4_00/infNFe/det/imposto/_tc_IPI.xml.slim +27 -0
  37. data/lib/br_nfe/product/xml/v4_00/infNFe/pag/_tc_detPag.xml.slim +17 -0
  38. data/lib/br_nfe/version.rb +4 -4
  39. data/lib/config/settings/nfe/reader_xml_paths.yml +40 -9
  40. data/lib/config/settings/nfe/v4_00/operation.yml +843 -0
  41. data/lib/config/settings/nfe/v4_00/soap_client.yml +807 -0
  42. data/lib/config/settings/nfe/v4_00/xml_paths.yml +577 -0
  43. data/test/br_nfe/product/nfe/item_tax/icms_uf_destino_test.rb +9 -8
  44. data/test/br_nfe/product/nota_fiscal_test.rb +28 -36
  45. data/test/br_nfe/product/reader/nfe_test.rb +31 -31
  46. data/test/factories/product/nfe/item_tax/icms_uf_destino.rb +1 -1
  47. data/test/factories/product/operation/nfe_autorizacao.rb +3 -3
  48. metadata +26 -4
@@ -24,7 +24,7 @@ module BrNfe
24
24
  # <b>Example: </b> _00_
25
25
  # <b>Length: </b> _2_
26
26
  # <b>tag: </b> CST
27
- #
27
+ #
28
28
  attr_accessor :codigo_cst
29
29
  def codigo_cst
30
30
  "#{@codigo_cst}".rjust(2, '0') if @codigo_cst.present?
@@ -40,11 +40,11 @@ module BrNfe
40
40
  # <b>Example: </b> _C1324_
41
41
  # <b>Length: </b> _max: 5_
42
42
  # <b>tag: </b> clEnq
43
- #
43
+ #
44
44
  attr_accessor :classe_enquadramento
45
45
  alias_attribute :clEnq, :classe_enquadramento
46
46
 
47
- # CNPJ DO PRODUTOR DA MERCADORIA, QUANDO DIFERENTE DO EMITENTE.
47
+ # CNPJ DO PRODUTOR DA MERCADORIA, QUANDO DIFERENTE DO EMITENTE.
48
48
  # SOMENTE PARA OS CASOS DE EXPORTAÇÃO DIRETA OU INDIRETA.
49
49
  # Informar os zeros não significativos
50
50
  #
@@ -53,7 +53,7 @@ module BrNfe
53
53
  # <b>Example: </b> _00.000.000/0001-00 OU 01234567890123_
54
54
  # <b>Length: </b> _14_
55
55
  # <b>tag: </b> CNPJProd
56
- #
56
+ #
57
57
  attr_accessor :cnpj_produtor
58
58
  def cnpj_produtor
59
59
  "#{@cnpj_produtor}".gsub(/[^\d]/,'')
@@ -69,7 +69,7 @@ module BrNfe
69
69
  # <b>Example: </b> _SELO12345654_
70
70
  # <b>Length: </b> _max: 60_
71
71
  # <b>tag: </b> cSelo
72
- #
72
+ #
73
73
  attr_accessor :codigo_selo
74
74
  alias_attribute :cSelo, :codigo_selo
75
75
 
@@ -80,24 +80,24 @@ module BrNfe
80
80
  # <b>Example: </b> _50_
81
81
  # <b>Length: </b> _max: 12_
82
82
  # <b>tag: </b> qSelo
83
- #
83
+ #
84
84
  attr_accessor :quantidade_selo
85
85
  def quantidade_selo
86
86
  "#{@quantidade_selo}".gsub(/[^\d]/,'')
87
87
  end
88
88
  alias_attribute :qSelo, :quantidade_selo
89
-
89
+
90
90
  # CÓDIGO DE ENQUADRAMENTO LEGAL DO IPI
91
- # Tabela a ser criada pela RFB, informar 999 enquanto a tabela
92
- # não for criada
91
+ # Preenchimento conforme Anexo XIV da Nota Técnica 2015.002.
92
+ # http://www.nfe.fazenda.gov.br/portal/exibirArquivo.aspx?conteudo=hDS5co/qWOc=
93
93
  #
94
94
  # <b>Type: </b> _String_
95
95
  # <b>Required: </b> _Yes_
96
- # <b>Example: </b> _999_
96
+ # <b>Example: </b> _265_
97
97
  # <b>Default: </b> _999_
98
98
  # <b>Length: </b> _max: 3_
99
99
  # <b>tag: </b> cEnq
100
- #
100
+ #
101
101
  attr_accessor :codigo_enquadramento
102
102
  alias_attribute :cEnq, :codigo_enquadramento
103
103
 
@@ -108,7 +108,7 @@ module BrNfe
108
108
  # <b>Required: </b> _No_
109
109
  # <b>Example: </b> _152.38_
110
110
  # <b>tag: </b> vBC
111
- #
111
+ #
112
112
  attr_accessor :base_calculo
113
113
  alias_attribute :vBC, :base_calculo
114
114
 
@@ -118,18 +118,18 @@ module BrNfe
118
118
  # <b>Required: </b> _No_
119
119
  # <b>Example: </b> _12.00_
120
120
  # <b>tag: </b> pIPI
121
- #
121
+ #
122
122
  attr_accessor :aliquota
123
123
  alias_attribute :pIPI, :aliquota
124
124
 
125
- # QUANTIDADE TOTAL NA UNIDADE PADRÃO PARA TRIBUTAÇÃO
125
+ # QUANTIDADE TOTAL NA UNIDADE PADRÃO PARA TRIBUTAÇÃO
126
126
  # (SOMENTE PARA OS PRODUTOS TRIBUTADOS POR UNIDADE)
127
127
  #
128
128
  # <b>Type: </b> _Float_
129
129
  # <b>Required: </b> _No_
130
130
  # <b>Example: </b> _12.00_
131
131
  # <b>tag: </b> qUnid
132
- #
132
+ #
133
133
  attr_accessor :quantidade_unidade
134
134
  alias_attribute :qUnid, :quantidade_unidade
135
135
 
@@ -139,7 +139,7 @@ module BrNfe
139
139
  # <b>Required: </b> _No_
140
140
  # <b>Example: </b> _12.00_
141
141
  # <b>tag: </b> vUnid
142
- #
142
+ #
143
143
  attr_accessor :total_unidade
144
144
  alias_attribute :vUnid, :total_unidade
145
145
 
@@ -149,13 +149,13 @@ module BrNfe
149
149
  # <b>Required: </b> _No_ (Yes if CST [00 49 50 99])
150
150
  # <b>Example: </b> _12.00_
151
151
  # <b>tag: </b> vIPI
152
- #
152
+ #
153
153
  attr_accessor :total
154
154
  alias_attribute :vIPI, :total
155
155
 
156
156
  def default_values
157
157
  {
158
- codigo_enquadramento: '999',
158
+ codigo_enquadramento: '999',
159
159
  }
160
160
  end
161
161
 
@@ -3,13 +3,15 @@ module BrNfe
3
3
  module Nfe
4
4
  module Transporte
5
5
  class Base < BrNfe::ActiveModelBase
6
-
6
+
7
7
  # Modalidade do frete
8
- # 0- Por conta do emitente;
9
- # 1- Por conta do destinatário/remetente;
10
- # 2- Por conta de terceiros;
11
- # 9- Sem frete
12
- #
8
+ # 0=Contratação do Frete por conta do Remetente (CIF);
9
+ # 1=Contratação do Frete por conta do Destinatário (FOB);
10
+ # 2=Contratação do Frete por conta de Terceiros;
11
+ # 3=Transporte Próprio por conta do Remetente;
12
+ # 4=Transporte Próprio por conta do Destinatário;
13
+ # 9=Sem Ocorrência de Transporte.
14
+ #
13
15
  # <b>Type: </b> _Number_
14
16
  # <b>Required: </b> _Yes_
15
17
  # <b>Default: </b> _9_
@@ -22,7 +24,7 @@ module BrNfe
22
24
 
23
25
  ##############################################################################
24
26
  #################### Dados da retenção ICMS do Transporte ####################
25
-
27
+
26
28
  # Método para saber se há retenção de ICMS, e se houver,
27
29
  # aplica as validações e adiciona a tag no XML
28
30
  #
@@ -54,7 +56,7 @@ module BrNfe
54
56
  alias_attribute :vBCRet, :retencao_base_calculo_icms
55
57
 
56
58
  # Percentual de aliquota da retenção do ICMS
57
- # Exemplo:
59
+ # Exemplo:
58
60
  # Se a aliquota for de 2,56% então deve setar o valor para
59
61
  # o atrubuto assim: self.retencao_aliquota = 2.56
60
62
  #
@@ -91,7 +93,7 @@ module BrNfe
91
93
  attr_accessor :retencao_cfop
92
94
  alias_attribute :CFOP, :retencao_cfop
93
95
 
94
- # Código do município de ocorrência do fato gerador
96
+ # Código do município de ocorrência do fato gerador
95
97
  # do ICMS do transporte
96
98
  #
97
99
  # <b>Type: </b> _Number_
@@ -102,7 +104,7 @@ module BrNfe
102
104
  attr_accessor :retencao_codigo_municipio
103
105
  alias_attribute :cMunFG, :retencao_codigo_municipio
104
106
 
105
- # Attr utilizado para saber como será validado os dados do
107
+ # Attr utilizado para saber como será validado os dados do
106
108
  # 'veiculo' utilizado para transportar a carga.
107
109
  #
108
110
  # <b>Type: </b> _Symbol_
@@ -111,7 +113,7 @@ module BrNfe
111
113
  # <b>Default: </b> _:veiculo_
112
114
  #
113
115
  attr_accessor :forma_transporte
114
-
116
+
115
117
  # Veículo de transporte
116
118
  # Utilizado quando a forma de transporte for com :veiculo
117
119
  #
@@ -198,8 +200,8 @@ module BrNfe
198
200
  #
199
201
  has_one :transportador, 'BrNfe.transportador_product_class'
200
202
  alias_attribute :transporta, :transportador
201
-
202
-
203
+
204
+
203
205
  def default_values
204
206
  {
205
207
  modalidade_frete: 9, # 9 = Sem frete
@@ -207,11 +209,11 @@ module BrNfe
207
209
  }
208
210
  end
209
211
 
210
- validates :modalidade_frete, inclusion: [0, '0', 1, '1', 2, '2', 9, '9']
212
+ validates :modalidade_frete, inclusion: [0, 1, 2, 3, 4, 9, '0', '1', '2', '3', '4', '9']
211
213
  validates :forma_transporte, presence: true
212
214
  validates :forma_transporte, inclusion: [:veiculo, :balsa, :vagao]
213
215
  validate_has_one :transportador
214
-
216
+
215
217
  validate_has_many :volumes, message: :invalid_volume
216
218
  validate_has_many :reboques, message: :invalid_reboque
217
219
  validates :reboques, length: {maximum: 5}
@@ -120,6 +120,9 @@ module BrNfe
120
120
  # 1=Pagamento a prazo;
121
121
  # 2=Outros.
122
122
  #
123
+ # NA VERSÃO 4.0 essa informação está em cada pagamento (tag: indPag, id: YA01b).
124
+ #
125
+ #
123
126
  # <b>Type: </b> _Number_ OR _String_
124
127
  # <b>Required: </b> _Yes_
125
128
  # <b>Default: </b> _0_
@@ -237,6 +240,7 @@ module BrNfe
237
240
  # 2=Operação não presencial, pela Internet;
238
241
  # 3=Operação não presencial, Teleatendimento;
239
242
  # 4=NFC-e em operação com entrega a domicílio;
243
+ # 5=Operação presencial, fora do estabelecimento;
240
244
  # 9=Operação não presencial, outros. (Default)
241
245
  #
242
246
  # <b>Required: </b> _Yes_
@@ -380,7 +384,6 @@ module BrNfe
380
384
  alias_attribute :cobr, :fatura
381
385
 
382
386
  # Array com as informações dos pagamentos
383
- # IMPORTANTE: Utilizado apenas para NFC-e
384
387
  #
385
388
  # Pode ser adicionado os dados dos pagamentos em forma de `Hash`
386
389
  # ou o próprio objeto da classe BrNfe.pagamento_product_class.
@@ -398,7 +401,7 @@ module BrNfe
398
401
  # Sempre vai retornar um Array de objetos da class configurada em `BrNfe.pagamento_product_class`
399
402
  #
400
403
  # <b>Tipo: </b> _BrNfe.pagamento_product_class (BrNfe::Product::Nfe::Cobranca::Pagamento)_
401
- # <b>Min: </b> _0_
404
+ # <b>Min: </b> _1_
402
405
  # <b>Max: </b> _100_
403
406
  # <b>Default: </b> _[]_
404
407
  # <b>tag: </b> pag
@@ -406,6 +409,19 @@ module BrNfe
406
409
  has_many :pagamentos, 'BrNfe.pagamento_product_class'
407
410
  alias_attribute :pag, :pagamentos
408
411
 
412
+ # VALOR DO TROCO
413
+ # O valor do Troco na NFe deve ser informado quando o valor da NFe (campo vNF)
414
+ # for diferente dos valores dos Pagamentos (campos vPag).
415
+ #
416
+ # <b>Type: </b> _Float_
417
+ # <b>Required: </b> _No_
418
+ # <b>Example: </b> _108.46_
419
+ # <b>Length: </b> _13v2_
420
+ # <b>tag: </b> vTroco
421
+ #
422
+ attr_accessor :pagamento_troco
423
+ alias_attribute :vTroco, :pagamento_troco
424
+
409
425
  # DETALHAMENTO DE PRODUTOS E SERVIÇOS
410
426
  #
411
427
  # <b>Type: </b> _BrNfe.item_product_class (BrNfe::Product::Nfe::Item)_
@@ -654,6 +670,59 @@ module BrNfe
654
670
  attr_accessor :total_tributos
655
671
  alias_attribute :ICMSTot_vTotTrib, :total_tributos
656
672
  validates :total_tributos, numericality: {greater_than_or_equal_to: 0.0}, allow_blank: true
673
+
674
+ # VALOR TOTAL DO FCP (FUNDO DE COMBATE À POBREZA)
675
+ # Corresponde ao total da soma dos campos id: N17c
676
+ #
677
+ # <b>Type: </b> _Float_
678
+ # <b>Required: </b> _Yes_
679
+ # <b>Example: </b> _178.46_
680
+ # <b>Length: </b> _13v2_
681
+ # <b>tag: </b> vFCP
682
+ #
683
+ attr_accessor :total_fcp
684
+ alias_attribute :vFCP, :total_fcp
685
+
686
+ # VALOR TOTAL DO FCP (FUNDO DE COMBATE À POBREZA) RETIDO POR SUBSTITUIÇÃO TRIBUTÁRIA
687
+ # Corresponde ao total da soma dos campos id: N23d
688
+ #
689
+ # <b>Type: </b> _Float_
690
+ # <b>Required: </b> _Yes_
691
+ # <b>Example: </b> _178.46_
692
+ # <b>Length: </b> _13v2_
693
+ # <b>tag: </b> vFCPST
694
+ #
695
+ attr_accessor :total_fcp_st
696
+ alias_attribute :vFCPST, :total_fcp_st
697
+
698
+ # VALOR TOTAL DO FCP RETIDO ANTERIORMENTE POR SUBSTITUIÇÃO TRIBUTÁRIA
699
+ # Corresponde ao total da soma dos campos id: N27d
700
+ #
701
+ # <b>Type: </b> _Float_
702
+ # <b>Required: </b> _Yes_
703
+ # <b>Example: </b> _178.46_
704
+ # <b>Length: </b> _13v2_
705
+ # <b>tag: </b> vFCPSTRet
706
+ #
707
+ attr_accessor :total_fcp_st_retido
708
+ alias_attribute :vFCPSTRet, :total_fcp_st_retido
709
+
710
+ # VALOR TOTAL DO IPI DEVOLVIDO
711
+ # Deve ser informado quando preenchido o Grupo Tributos
712
+ # Devolvidos na emissão de nota finNFe=4 (devolução) nas
713
+ # operações com não contribuintes do IPI. Corresponde ao
714
+ # total da soma dos campos id:UA04.
715
+ # Deve ser preenchido no XML mesmo que zerado
716
+ #
717
+ # <b>Type: </b> _Float_
718
+ # <b>Required: </b> _Yes_
719
+ # <b>Example: </b> _178.46_
720
+ # <b>Length: </b> _13v2_
721
+ # <b>tag: </b> vIPIDevol
722
+ #
723
+ attr_accessor :total_ipi_devolvido
724
+ alias_attribute :vIPIDevol, :total_ipi_devolvido
725
+
657
726
  ##########################################################################
658
727
  ######################### TOTAIS PARA SERVIÇOS #########################
659
728
  # VALOR TOTAL DOS SERVIÇOS SOB NÃO-INCIDÊNCIA OU NÃO TRIBUTADOS PELO ICMS
@@ -1099,9 +1168,6 @@ module BrNfe
1099
1168
 
1100
1169
  validates :natureza_operacao, presence: true
1101
1170
 
1102
- validates :forma_pagamento, presence: true
1103
- validates :forma_pagamento, inclusion: [0, 1, 2, '0', '1', '2']
1104
-
1105
1171
  validates :modelo_nf, presence: true
1106
1172
  validates :modelo_nf, inclusion: [55, 65, '55', '65']
1107
1173
 
@@ -1115,7 +1181,7 @@ module BrNfe
1115
1181
  validates :tipo_impressao, inclusion: [0, 1, 2, 3, 4, 5, '0', '1', '2', '3', '4', '5']
1116
1182
 
1117
1183
  validates :presenca_comprador, presence: true
1118
- validates :presenca_comprador, inclusion: [0, 1, 2, 3, 4, 9, '0', '1', '2', '3', '4', '9']
1184
+ validates :presenca_comprador, inclusion: [0, 1, 2, 3, 4, 5, 9, '0', '1', '2', '3', '4', '5', '9']
1119
1185
 
1120
1186
  validates :processo_emissao, presence: true
1121
1187
  validates :processo_emissao, inclusion: [0, 1, 2, 3, '0', '1', '2', '3']
@@ -17,7 +17,7 @@ module BrNfe
17
17
  attr_accessor :tipo_emissao
18
18
  def tipo_emissao= value
19
19
  if "#{value}" == '1'
20
- @tipo_emissao = :normal
20
+ @tipo_emissao = :normal
21
21
  elsif "#{value}" == '9'
22
22
  @tipo_emissao = :offline_nfce
23
23
  elsif "#{value}".in?(%w[6 7])
@@ -45,9 +45,9 @@ module BrNfe
45
45
  #
46
46
  # <b>Required: </b> _No_
47
47
  # <b>Type: </b> _String_ XML
48
- #
48
+ #
49
49
  attr_accessor :original_xml
50
-
50
+
51
51
  validates :tipo_emissao, inclusion: {in: [:normal, :svc]}
52
52
  validates :inicio_contingencia, presence: true, if: :contingencia?
53
53
  validates :motivo_contingencia, length: { minimum: 15, maximum: 256 }, if: :contingencia?
@@ -90,7 +90,7 @@ module BrNfe
90
90
  # - :soap_client => Contém as configurações para instanciar o client Soap com o Savon.
91
91
  # - :xml_paths => Contém os caminhos com namespace para encontrar os valores dentro dos XMLS
92
92
  #
93
- # <b>Tipo de retorno: </b> _Symbol_
93
+ # <b>Tipo de retorno: </b> _Symbol_
94
94
  #
95
95
  def gateway_settings
96
96
  nfe_settings[:gateway][gateway]
@@ -109,7 +109,7 @@ module BrNfe
109
109
  # 'AM', 'BA', 'CE', 'GO', 'MA', 'MS', 'MT', 'PA', 'PE', 'PI', 'PR'
110
110
  when '13', '29', '23', '52', '21', '50', '51', '15', '26', '22', '41'
111
111
  :svc_rs
112
- else # AC, AL, AP, DF, ES, MG, PB, RJ, RN, RO, RR, RS, SC, SE, SP, TO
112
+ else # AC, AL, AP, DF, ES, MG, PB, RJ, RN, RO, RR, RS, SC, SE, SP, TO
113
113
  :svc_an
114
114
  end
115
115
  end
@@ -118,7 +118,7 @@ module BrNfe
118
118
  #
119
119
  # <b>Tipo de retorno: </b> _Hash_
120
120
  #
121
- def get_gateway_by_normal_operation
121
+ def get_gateway_by_normal_operation
122
122
  case "#{ibge_code_of_issuer_uf}"
123
123
  when '13'
124
124
  :am
@@ -144,7 +144,7 @@ module BrNfe
144
144
  :sp
145
145
  when '21', '15' # MA, PA
146
146
  :svan
147
- else
147
+ else
148
148
  # AC, AL, AP, ES, DF, PB, RJ, RM, RO, RR, SC, PI
149
149
  # 12, 27, 16, 32, 53, 25, 33, 24, 11, 14, 42, 22
150
150
  :svrs
@@ -175,7 +175,7 @@ module BrNfe
175
175
  end
176
176
 
177
177
  # Versão utilizada pelo webservice do estado para determinada ação.
178
- # Irá retornar a versão setada de acordo com o serviço e estado conforme
178
+ # Irá retornar a versão setada de acordo com o serviço e estado conforme
179
179
  # descrito em: http://www.nfe.fazenda.gov.br/portal/webServices.aspx
180
180
  #
181
181
  # <b>Tipo de retorno: </b> _Symbol_
@@ -250,11 +250,12 @@ module BrNfe
250
250
  paths << "#{BrNfe.root}/lib/br_nfe/product/xml/v1_10" if gateway_xml_version >= :v1_10
251
251
  paths << "#{BrNfe.root}/lib/br_nfe/product/xml/v2_00" if gateway_xml_version >= :v2_00
252
252
  paths << "#{BrNfe.root}/lib/br_nfe/product/xml/v2_01" if gateway_xml_version >= :v2_01
253
- paths << "#{BrNfe.root}/lib/br_nfe/product/xml/v3_10" if gateway_xml_version == :v3_10
254
-
253
+ paths << "#{BrNfe.root}/lib/br_nfe/product/xml/v3_10" if gateway_xml_version >= :v3_10
254
+ paths << "#{BrNfe.root}/lib/br_nfe/product/xml/v4_00" if gateway_xml_version == :v4_00
255
+
255
256
  @xml_current_dir_path = paths.reverse+["#{BrNfe.root}/lib/br_nfe/product/xml"]+super
256
257
  end
257
-
258
+
258
259
  # Método utilizado para saber se a operação será em contingência.
259
260
  #
260
261
  # <b>Tipo de retorno: </b> _Boolean_
@@ -271,13 +272,13 @@ module BrNfe
271
272
  # ✕ 5=Contingência FS-DA, com impressão do DANFE em formulário de segurança;
272
273
  # ✓ 6=Contingência SVC-AN (SEFAZ Virtual de Contingência do AN);
273
274
  # ✓ 7=Contingência SVC-RS (SEFAZ Virtual de Contingência do RS);
274
- # ✓ 9=Contingência off-line da NFC-e (as demais opções de contingência são válidas
275
+ # ✓ 9=Contingência off-line da NFC-e (as demais opções de contingência são válidas
275
276
  # também para a NFC-e).
276
277
  # Para a NFC-e somente estão disponíveis e são válidas as opções de contingência 5 e 9.
277
278
  def codigo_tipo_emissao(nfe)
278
279
  return 9 if nfe.nfce?
279
280
  case tipo_emissao
280
- when :normal
281
+ when :normal
281
282
  1
282
283
  when :svc
283
284
  if gateway == :svc_rs
@@ -66,6 +66,11 @@ module BrNfe
66
66
  @item.total_ipi_devolucao = @xml.css( @path[:total_ipi_devolucao] ).text.to_f
67
67
  @item.informacoes_adicionais = @xml.css( @path[:informacoes_adicionais] ).text
68
68
  @item.total_tributos = @xml.css( @path[:total_tributos] ).text.to_f
69
+
70
+ # NF-e 4.0
71
+ @item.escala_relevante = @xml.css( @path[:escala_relevante] ).text
72
+ @item.cnpj_fabricante = @xml.css( @path[:cnpj_fabricante] ).text
73
+ @item.codigo_beneficio_fiscal = @xml.css( @path[:codigo_beneficio_fiscal] ).text
69
74
  end
70
75
 
71
76
  def set_icms
@@ -93,7 +98,18 @@ module BrNfe
93
98
  total_base_calculo_st_retido: @xml.css( @path[:icms][:total_base_calculo_st_retido]).text.to_f,
94
99
  total_st_retido: @xml.css( @path[:icms][:total_st_retido] ).text.to_f,
95
100
  aliquota_credito_sn: @xml.css( @path[:icms][:aliquota_credito_sn] ).text.to_f,
96
- total_credito_sn: @xml.css( @path[:icms][:total_credito_sn] ).text.to_f
101
+ total_credito_sn: @xml.css( @path[:icms][:total_credito_sn] ).text.to_f,
102
+ # NF-e 4.0
103
+ cfp_base_calculo: @xml.css( @path[:icms][:cfp_base_calculo] ).text.to_f,
104
+ cfp_percentual: @xml.css( @path[:icms][:cfp_percentual] ).text.to_f,
105
+ cfp_valor: @xml.css( @path[:icms][:cfp_valor] ).text.to_f,
106
+ cfp_st_base_calculo: @xml.css( @path[:icms][:cfp_st_base_calculo] ).text.to_f,
107
+ cfp_st_percentual: @xml.css( @path[:icms][:cfp_st_percentual] ).text.to_f,
108
+ cfp_st_valor: @xml.css( @path[:icms][:cfp_st_valor] ).text.to_f,
109
+ cfp_st_retido_base_calculo: @xml.css( @path[:icms][:cfp_st_retido_base_calculo] ).text.to_f,
110
+ cfp_st_retido_percentual: @xml.css( @path[:icms][:cfp_st_retido_percentual] ).text.to_f,
111
+ cfp_st_retido_valor: @xml.css( @path[:icms][:cfp_st_retido_valor] ).text.to_f,
112
+ aliquota_consumidor_final: @xml.css( @path[:icms][:aliquota_consumidor_final] ).text.to_f,
97
113
  }
98
114
  end
99
115
  def set_ipi
@@ -134,7 +150,8 @@ module BrNfe
134
150
  def set_icms_uf_destino
135
151
  @item.icms_uf_destino do |icms_uf_destino|
136
152
  icms_uf_destino.total_base_calculo = @xml.css( @path[:icms_uf_destino][:total_base_calculo] ).text.to_f
137
- icms_uf_destino.percentual_fcp = @xml.css( @path[:icms_uf_destino][:percentual_fcp] ).text.to_f
153
+ icms_uf_destino.bc_fcp_uf_destino = @xml.css( @path[:icms_uf_destino][:bc_fcp_uf_destino] ).text.to_f
154
+ icms_uf_destino.percentual_fcp_uf_destino = @xml.css( @path[:icms_uf_destino][:percentual_fcp_uf_destino] ).text.to_f
138
155
  icms_uf_destino.aliquota_interna_uf_destino = @xml.css( @path[:icms_uf_destino][:aliquota_interna_uf_destino]).text.to_f
139
156
  icms_uf_destino.aliquota_interestadual = @xml.css( @path[:icms_uf_destino][:aliquota_interestadual] ).text.to_f
140
157
  icms_uf_destino.percentual_partilha_destino = @xml.css( @path[:icms_uf_destino][:percentual_partilha_destino]).text.to_f
@@ -17,7 +17,7 @@ module BrNfe
17
17
  def xml_version
18
18
  @xml_version
19
19
  end
20
-
20
+
21
21
  private
22
22
 
23
23
  def path
@@ -29,7 +29,12 @@ module BrNfe
29
29
  end
30
30
 
31
31
  def find_xml_version
32
- "v#{@xml.css("infNFe").attr("versao")}".gsub('.','_').to_sym
32
+ v = "v#{@xml.css("infNFe").attr("versao")}".gsub('.','_').to_sym
33
+ if v.in?( %i[v3_10 v4_00] )
34
+ v
35
+ else
36
+ :v4_00
37
+ end
33
38
  end
34
39
 
35
40
  def populate_invoice!
@@ -44,7 +49,9 @@ module BrNfe
44
49
  @invoice.codigo_tipo_emissao = @xml_nfe.css(path[:codigo_tipo_emissao]).text
45
50
  @invoice.codigo_nf = @xml_nfe.css(path[:codigo_nf]).text
46
51
  @invoice.natureza_operacao = @xml_nfe.css(path[:natureza_operacao]).text
47
- @invoice.forma_pagamento = @xml_nfe.css(path[:forma_pagamento]).text
52
+
53
+ @invoice.forma_pagamento = @xml_nfe.css(path[:forma_pagamento]).text # Removido na NF-e 4.0
54
+
48
55
  @invoice.modelo_nf = @xml_nfe.css(path[:modelo_nf]).text
49
56
  @invoice.serie = @xml_nfe.css(path[:serie]).text
50
57
  @invoice.numero_nf = @xml_nfe.css(path[:numero_nf]).text.to_i
@@ -96,6 +103,11 @@ module BrNfe
96
103
  @invoice.total_outras_despesas = @xml_nfe.css(path[:total_icms][:total_outras_despesas]).text.to_f
97
104
  @invoice.total_nf = @xml_nfe.css(path[:total_icms][:total_nf]).text.to_f
98
105
  @invoice.total_tributos = @xml_nfe.css(path[:total_icms][:total_tributos]).text.to_f
106
+ # NF-e v4
107
+ @invoice.total_fcp = @xml_nfe.css(path[:total_icms][:total_fcp]).text.to_f
108
+ @invoice.total_fcp_st = @xml_nfe.css(path[:total_icms][:total_fcp_st]).text.to_f
109
+ @invoice.total_fcp_st_retido = @xml_nfe.css(path[:total_icms][:total_fcp_st_retido]).text.to_f
110
+ @invoice.total_ipi_devolvido = @xml_nfe.css(path[:total_icms][:total_ipi_devolvido]).text.to_f
99
111
  end
100
112
 
101
113
  def build_service_total_values!
@@ -147,14 +159,21 @@ module BrNfe
147
159
  end
148
160
 
149
161
  def build_pagamentos!
162
+ if (path[:pagamentos][:troco])
163
+ # NF-e v4
164
+ @invoice.pagamento_troco = @xml_nfe.css(path[:pagamentos][:troco]).text.to_f
165
+ end
166
+
150
167
  @xml_nfe.css(path[:pagamentos][:root]).each do |xml_pag|
151
168
  @invoice.pagamentos << {
152
- forma_pagamento: xml_pag.css(path[:pagamentos][:forma_pagamento]).text,
153
- total: xml_pag.css(path[:pagamentos][:total]).text.to_f,
154
- tipo_integracao: xml_pag.css(path[:pagamentos][:tipo_integracao]).text,
155
- cartao_cnpj: xml_pag.css(path[:pagamentos][:cartao_cnpj]).text,
156
- cartao_bandeira: xml_pag.css(path[:pagamentos][:cartao_bandeira]).text,
157
- cartao_autorizacao: xml_pag.css(path[:pagamentos][:cartao_autorizacao]).text
169
+ forma_pagamento: xml_pag.css(path[:pagamentos][:forma_pagamento]).text,
170
+ total: xml_pag.css(path[:pagamentos][:total]).text.to_f,
171
+ tipo_integracao: xml_pag.css(path[:pagamentos][:tipo_integracao]).text,
172
+ cartao_cnpj: xml_pag.css(path[:pagamentos][:cartao_cnpj]).text,
173
+ cartao_bandeira: xml_pag.css(path[:pagamentos][:cartao_bandeira]).text,
174
+ cartao_autorizacao: xml_pag.css(path[:pagamentos][:cartao_autorizacao]).text,
175
+ # NF-e v4
176
+ indicacao_pagamento: xml_pag.css(path[:pagamentos][:indicacao_pagamento]).text,
158
177
  }
159
178
  end
160
179
  end
@@ -6,9 +6,9 @@ NCM = nf_xml_value_NCM( item.codigo_ncm )
6
6
  - item.codigos_nve.each do |nve|
7
7
  NVE = nf_xml_value_NVE(nve)
8
8
 
9
- - item.codigo_cest.present?
9
+ - if item.codigo_cest.present?
10
10
  CEST = nf_xml_value_CEST( item.codigo_cest )
11
-
11
+
12
12
  - if item.codigo_extipi.present?
13
13
  EXTIPI = nf_xml_value_EXTIPI( item.codigo_extipi )
14
14
 
@@ -1,5 +1,5 @@
1
1
  vBCUFDest = nf_xml_value_monetary( icms.total_base_calculo )
2
- pFCPUFDest = nf_xml_value_monetary( icms.percentual_fcp )
2
+ pFCPUFDest = nf_xml_value_monetary( icms.percentual_fcp_uf_destino )
3
3
  pICMSUFDest = nf_xml_value_monetary( icms.aliquota_interna_uf_destino )
4
4
  pICMSInter = nf_xml_value_monetary( icms.aliquota_interestadual )
5
5
  pICMSInterPart = nf_xml_value_monetary( icms.percentual_partilha_destino )
@@ -0,0 +1,45 @@
1
+ ide = render_xml 'infNFe/_tc_ide', nfe: nfe
2
+ emit = render_xml 'infNFe/_tc_emit'
3
+ / avulsa
4
+ dest = render_xml 'infNFe/_tc_dest', nfe: nfe
5
+
6
+ - if nfe.endereco_retirada
7
+ retirada = render_xml 'infNFe/_tc_retirada', nfe: nfe
8
+
9
+ - if nfe.endereco_entrega
10
+ entrega = render_xml 'infNFe/_tc_entrega', nfe: nfe
11
+
12
+ - nfe.autorizados_download_xml.each do |auth|
13
+ autXML
14
+ = render_xml('_tc_cpf_cnpj', cpf_cnpj: auth)
15
+
16
+ - nfe.itens.each_with_index do |item, i|
17
+ det nItem="#{i+1}"
18
+ = render_xml 'infNFe/_tc_det', item: item
19
+
20
+ total
21
+ = render_xml 'infNFe/_tc_total', nfe: nfe
22
+
23
+ transp
24
+ = render_xml('infNFe/_tc_transp', nfe: nfe)
25
+
26
+ - if nfe.fatura
27
+ cobr
28
+ = render_xml 'infNFe/_tc_cobr', nfe: nfe
29
+
30
+ pag
31
+ - nfe.pagamentos.each do |pagamento|
32
+ = render_xml 'infNFe/pag/_tc_detPag', pagamento: pagamento
33
+ - if nfe.pagamento_troco.to_f > 0
34
+ vTroco = nf_xml_value_monetary( nfe.pagamento_troco )
35
+
36
+ - if nfe.informacoes_fisco.present? || nfe.informacoes_contribuinte.present? || nfe.processos_referenciados.present?
37
+ infAdic
38
+ = render_xml 'infNFe/_tc_infAdic', nfe: nfe
39
+
40
+ - if nfe.exportacao_uf_saida.present? && nfe.exportacao_local_embarque.present?
41
+ exporta
42
+ = render_xml 'infNFe/_tc_exporta', nfe: nfe
43
+
44
+ / compra
45
+ / cana
@@ -0,0 +1,30 @@
1
+ cUF = emitente.endereco.codigo_ibge_uf
2
+ cNF = nf_xml_value_codigo_nf( nfe.codigo_nf )
3
+ natOp = nf_xml_value_text( nfe.natureza_operacao )
4
+ mod = nfe.modelo_nf
5
+ serie = nfe.serie
6
+ nNF = nfe.numero_nf
7
+ dhEmi = nf_xml_value_date_time( nfe.data_hora_emissao )
8
+ - if nfe.nfe?
9
+ dhSaiEnt = nf_xml_value_date_time( nfe.data_hora_expedicao )
10
+ tpNF = nfe.tipo_operacao
11
+ idDest = nf_xml_value_id_local_destino( nfe.destinatario.endereco )
12
+ cMunFG = nf_xml_value_codigo_ibge_municipio( emitente.endereco.codigo_municipio )
13
+ tpImp = nfe.tipo_impressao
14
+ tpEmis = codigo_tipo_emissao( nfe )
15
+ cDV = nfe.chave_de_acesso_dv
16
+ tpAmb = nf_xml_value_tipo_ambiente( env )
17
+ finNFe = nfe.finalidade_emissao
18
+ indFinal = nf_xml_value_consumidor_final( nfe.consumidor_final )
19
+ indPres = nfe.presenca_comprador
20
+ procEmi = nfe.processo_emissao
21
+ verProc = nfe.versao_aplicativo
22
+
23
+ - if contingencia?
24
+ dhCont = nf_xml_value_date_time(inicio_contingencia)
25
+ xJust = nf_xml_value_text( motivo_contingencia, 255 )
26
+
27
+ - if nfe.notas_referenciadas.size > 0
28
+ NFref
29
+ - nfe.notas_referenciadas.each do |ref|
30
+ refNFe = ref