nfe_reader 1.0.5 → 1.0.6

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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/nfe_reader.rb +4 -4
  4. data/lib/nfe_reader/address.rb +38 -0
  5. data/lib/nfe_reader/authorization.rb +8 -10
  6. data/lib/nfe_reader/billing.rb +21 -0
  7. data/lib/nfe_reader/billing/duplicate.rb +14 -0
  8. data/lib/nfe_reader/carrier.rb +12 -14
  9. data/lib/nfe_reader/customer.rb +15 -57
  10. data/lib/nfe_reader/delivery.rb +16 -18
  11. data/lib/nfe_reader/document.rb +63 -65
  12. data/lib/nfe_reader/export.rb +8 -10
  13. data/lib/nfe_reader/fiscal.rb +29 -31
  14. data/lib/nfe_reader/header.rb +114 -123
  15. data/lib/nfe_reader/helpers/attribute_helper.rb +24 -0
  16. data/lib/nfe_reader/helpers/creator_helper.rb +40 -0
  17. data/lib/{helpers → nfe_reader/helpers}/nokogiri_hash.rb +2 -0
  18. data/lib/nfe_reader/information.rb +17 -19
  19. data/lib/nfe_reader/nfe.rb +78 -87
  20. data/lib/nfe_reader/person.rb +53 -0
  21. data/lib/nfe_reader/product.rb +69 -67
  22. data/lib/nfe_reader/product/armament.rb +18 -20
  23. data/lib/nfe_reader/product/cane.rb +22 -24
  24. data/lib/nfe_reader/product/exportation.rb +15 -17
  25. data/lib/nfe_reader/product/fuel.rb +13 -15
  26. data/lib/nfe_reader/product/importation.rb +42 -44
  27. data/lib/nfe_reader/product/medicament.rb +15 -17
  28. data/lib/nfe_reader/product/vehicle.rb +113 -115
  29. data/lib/nfe_reader/provider.rb +10 -40
  30. data/lib/nfe_reader/purchase.rb +9 -12
  31. data/lib/nfe_reader/removal.rb +17 -19
  32. data/lib/nfe_reader/taxation/cofins.rb +41 -41
  33. data/lib/nfe_reader/taxation/cofins_st.rb +15 -17
  34. data/lib/nfe_reader/taxation/icms.rb +80 -81
  35. data/lib/nfe_reader/taxation/importation_tax.rb +14 -16
  36. data/lib/nfe_reader/taxation/ipi.rb +35 -37
  37. data/lib/nfe_reader/taxation/issqn.rb +17 -19
  38. data/lib/nfe_reader/taxation/pis.rb +41 -41
  39. data/lib/nfe_reader/taxation/pis_st.rb +16 -18
  40. data/lib/nfe_reader/total.rb +71 -71
  41. data/lib/nfe_reader/transport.rb +76 -89
  42. data/lib/nfe_reader/version.rb +2 -4
  43. data/nfe-reader.gemspec +2 -1
  44. data/test/nfe_reader/address_test.rb +75 -0
  45. data/test/nfe_reader/authorization_test.rb +2 -2
  46. data/test/nfe_reader/{collection → billing}/duplicate_test.rb +2 -2
  47. data/test/nfe_reader/{collection_test.rb → billing_test.rb} +13 -13
  48. data/test/nfe_reader/cane_test.rb +2 -2
  49. data/test/nfe_reader/carrier_test.rb +4 -4
  50. data/test/nfe_reader/customer_test.rb +6 -101
  51. data/test/nfe_reader/delivery_test.rb +2 -2
  52. data/test/nfe_reader/document_test.rb +2 -2
  53. data/test/nfe_reader/export_test.rb +2 -2
  54. data/test/nfe_reader/fiscal_test.rb +2 -2
  55. data/test/nfe_reader/header_test.rb +2 -2
  56. data/test/{helpers → nfe_reader/helpers}/attributte_helper_test.rb +3 -3
  57. data/test/{helpers → nfe_reader/helpers}/creator_helper_test.rb +3 -3
  58. data/test/{helpers → nfe_reader/helpers}/nokogiri_test.rb +1 -1
  59. data/test/nfe_reader/information_test.rb +2 -2
  60. data/test/nfe_reader/nfe_test.rb +13 -13
  61. data/test/nfe_reader/person_test.rb +60 -0
  62. data/test/nfe_reader/product/armament_test.rb +2 -2
  63. data/test/nfe_reader/product/exportation_test.rb +2 -2
  64. data/test/nfe_reader/product/fuel_test.rb +2 -2
  65. data/test/nfe_reader/product/importation_test.rb +2 -2
  66. data/test/nfe_reader/product/medicament_test.rb +2 -2
  67. data/test/nfe_reader/product/vehicle_test.rb +2 -2
  68. data/test/nfe_reader/product_test.rb +2 -2
  69. data/test/nfe_reader/provider_test.rb +5 -118
  70. data/test/nfe_reader/purchase_test.rb +2 -2
  71. data/test/nfe_reader/removal_test.rb +2 -2
  72. data/test/nfe_reader/taxation/cofins_st_test.rb +2 -2
  73. data/test/nfe_reader/taxation/cofins_test.rb +2 -2
  74. data/test/nfe_reader/taxation/icms_test.rb +2 -2
  75. data/test/nfe_reader/taxation/importation_tax_test.rb +2 -2
  76. data/test/nfe_reader/taxation/ipi_test.rb +2 -2
  77. data/test/nfe_reader/taxation/issqn_test.rb +2 -2
  78. data/test/nfe_reader/taxation/pis_st_test.rb +2 -2
  79. data/test/nfe_reader/taxation/pis_test.rb +2 -2
  80. data/test/nfe_reader/total_test.rb +2 -2
  81. data/test/nfe_reader/transport_test.rb +3 -3
  82. metadata +37 -17
  83. data/lib/helpers/attribute_helper.rb +0 -18
  84. data/lib/helpers/creator_helper.rb +0 -32
  85. data/lib/nfe_reader/collection.rb +0 -38
  86. data/lib/nfe_reader/collection/duplicate.rb +0 -16
@@ -1,16 +1,14 @@
1
1
  # encoding: UTF-8
2
- # Informações de Comércio Exterior
3
- module Nfe
4
- module Reader
5
- class Export
6
- include ::AttributeHelper
2
+ module NfeReader
3
+ # Informações de Comércio Exterior
4
+ class Export
5
+ include AttributeHelper
7
6
 
8
- attr_reader :state, :address
7
+ attr_reader :state, :address
9
8
 
10
- def initialize(attrs = {})
11
- @state = attrs[:UFEmbarq]
12
- @address = attrs[:xLocEmbarq]
13
- end
9
+ def initialize(attrs = {})
10
+ @state = attrs[:UFEmbarq]
11
+ @address = attrs[:xLocEmbarq]
14
12
  end
15
13
  end
16
14
  end
@@ -1,37 +1,35 @@
1
1
  # encoding: UTF-8
2
- module Nfe
3
- module Reader
4
- # Identificação do Fisco Emitente da NF-e
5
- class Fiscal
6
- include ::AttributeHelper
2
+ module NfeReader
3
+ # Identificação do Fisco Emitente da NF-e
4
+ class Fiscal
5
+ include AttributeHelper
7
6
 
8
- attr_reader :cnpj, :agency, :code, :name, :paid_date,
9
- :phone, :state, :number, :date, :value, :repartition
7
+ attr_reader :cnpj, :agency, :code, :name, :paid_date,
8
+ :phone, :state, :number, :date, :value, :repartition
10
9
 
11
- def initialize(attrs = {})
12
- # CNPJ emitente
13
- @cnpj = attrs[:CNPJ]
14
- # Órgão emitente
15
- @agency = attrs[:xOrgao]
16
- # Matrícula do agente do Fisco
17
- @code = attrs[:matr]
18
- # Nome do agente do Fisco
19
- @name = attrs[:xAgente]
20
- # Telefone do agente do Fisco
21
- @phone = attrs[:fone]
22
- # Estado
23
- @state = attrs[:UF]
24
- # Número do DAR(Documento de Arrecadação de Receita)
25
- @number = attrs[:nDAR]
26
- # Data
27
- @date = attrs[:dEmi]
28
- # Valor do DAR
29
- @value = attrs[:vDAR]
30
- # Repartição Fiscal emitente
31
- @repartition = attrs[:repEmi]
32
- # Data do Pagamento
33
- @paid_date = attrs[:dPag]
34
- end
10
+ def initialize(attrs = {})
11
+ # CNPJ emitente
12
+ @cnpj = attrs[:CNPJ]
13
+ # Órgão emitente
14
+ @agency = attrs[:xOrgao]
15
+ # Matrícula do agente do Fisco
16
+ @code = attrs[:matr]
17
+ # Nome do agente do Fisco
18
+ @name = attrs[:xAgente]
19
+ # Telefone do agente do Fisco
20
+ @phone = attrs[:fone]
21
+ # Estado
22
+ @state = attrs[:UF]
23
+ # Número do DAR(Documento de Arrecadação de Receita)
24
+ @number = attrs[:nDAR]
25
+ # Data
26
+ @date = attrs[:dEmi]
27
+ # Valor do DAR
28
+ @value = attrs[:vDAR]
29
+ # Repartição Fiscal emitente
30
+ @repartition = attrs[:repEmi]
31
+ # Data do Pagamento
32
+ @paid_date = attrs[:dPag]
35
33
  end
36
34
  end
37
35
  end
@@ -1,132 +1,123 @@
1
1
  # encoding: UTF-8
2
- module Nfe
3
- module Reader
4
- # Identificação da Nota Fiscal eletrônica
5
- class Header
6
- include ::AttributeHelper
2
+ module NfeReader
3
+ # Identificação da Nota Fiscal eletrônica
4
+ class Header
5
+ include AttributeHelper
6
+ include CreatorHelper
7
7
 
8
- attr_reader :state, :city, :sample_number, :operation, :number,
9
- :model, :emission, :emission_kind, :out, :out_time, :serie, :kind,
10
- :environment, :finality, :version, :payment, :process, :digit,
11
- :orientation, :emission_date, :destiny_code, :final_consumer,
12
- :consumer_presence, :contingency_date, :contingency_justification,
13
- :documents
8
+ attr_reader :state, :city, :sample_number, :operation, :number,
9
+ :model, :emission, :emission_kind, :out, :out_time, :serie, :kind,
10
+ :environment, :finality, :version, :payment, :process, :digit,
11
+ :orientation, :emission_date, :destiny_code, :final_consumer,
12
+ :consumer_presence, :contingency_date, :contingency_justification,
13
+ :documents
14
14
 
15
- # == Fields Values
16
- #
17
- # cUF: 11-Rondônia, 12-Acre, 13-Amazonas, 14-Roraima, 15-Pará, 16-Amapá, 17-Tocantins,
18
- # 21-Maranhão, 22-Piauí, 23-Ceará, 24-Rio Grande do Norte, 25-Paraíba, 26-Pernambuco,
19
- # 27-Alagoas, 28-Sergipe, 29-Bahia, 31-Minas Gerais, 32-Espírito Santo, 33-Rio de Janeiro,
20
- # 35-São Paulo, 41-Paraná, 42-Santa Catarina, 3-Rio Grande do Sul, 50-Mato Grosso do Sul,
21
- # 51-Mato Grosso, 52-Goiás, 53-DistritoFederal
22
- #
23
- # mod: 55 - NF-e, 65 - NFC-e
24
- #
25
- # indPag: 0 - Vista, 1 - Prazo, 2 - Outros
26
- #
27
- # tpNF: 0 - Entrada, 1 - Saida
28
- #
29
- # tpAmb: 1 - Producao, 2 - Homologacao
30
- #
31
- # finNFe: 1 - Normal,
32
- # 2 - Complementar,
33
- # 3 - Ajuste,
34
- # 4 - Devolução/Retorno.
35
- #
36
- # tpEmis: 1 - Normal, 2 - Contingência FS, 3 - Contingência SCAN, 4 - Contingência FS-DA
37
- #
38
- # tpImp: 1 - Retrato,
39
- # 2 - Paisagem,
40
- # 3 - DANFE Simplificado,
41
- # 4 - DANFE NFC-e,
42
- # 5 - DANFE NFC-e em mensagem eletrônica (o envio de
43
- # mensagem eletrônica pode ser feita de forma simultânea
44
- # com a impressão do DANFE; usar o tpImp=5 quando
45
- # esta for a única forma de disponibilização do DANFE).
46
- #
47
- # procEmit: 0 - emissão de NF-e com aplicativo do contribuinte,
48
- # 1 - emissão de NF-e avulsa pelo Fisco,
49
- # 2 - emissão de NF-e avulsa, pelo site,
50
- # 3 - emissão NF-e pelo contribuinte com aplicativo fornecido pelo Fisco,
51
- #
52
- # idDest: 1 - Operação interna,
53
- # 2 - Operação interestadual,
54
- # 3 - Operação com exterior
55
- #
56
- # indFinal: 0 - Não,
57
- # 1 - Consumidor final
58
- #
59
- # indPres: 0 - Não se aplica (por exemplo, Nota Fiscal complementar
60
- # ou de ajuste);
61
- # 1 - Operação presencial;
62
- # 2 - Operação não presencial, pela Internet;
63
- # 3 - Operação não presencial, Teleatendimento;
64
- # 4 - NFC-e em operação com entrega a domicílio;
65
- # 9 - Operação não presencial, outros.
15
+ # == Fields Values
16
+ #
17
+ # cUF: 11-Rondônia, 12-Acre, 13-Amazonas, 14-Roraima, 15-Pará, 16-Amapá, 17-Tocantins,
18
+ # 21-Maranhão, 22-Piauí, 23-Ceará, 24-Rio Grande do Norte, 25-Paraíba, 26-Pernambuco,
19
+ # 27-Alagoas, 28-Sergipe, 29-Bahia, 31-Minas Gerais, 32-Espírito Santo, 33-Rio de Janeiro,
20
+ # 35-São Paulo, 41-Paraná, 42-Santa Catarina, 3-Rio Grande do Sul, 50-Mato Grosso do Sul,
21
+ # 51-Mato Grosso, 52-Goiás, 53-DistritoFederal
22
+ #
23
+ # mod: 55 - NF-e, 65 - NFC-e
24
+ #
25
+ # indPag: 0 - Vista, 1 - Prazo, 2 - Outros
26
+ #
27
+ # tpNF: 0 - Entrada, 1 - Saida
28
+ #
29
+ # tpAmb: 1 - Producao, 2 - Homologacao
30
+ #
31
+ # finNFe: 1 - Normal,
32
+ # 2 - Complementar,
33
+ # 3 - Ajuste,
34
+ # 4 - Devolução/Retorno.
35
+ #
36
+ # tpEmis: 1 - Normal, 2 - Contingência FS, 3 - Contingência SCAN, 4 - Contingência FS-DA
37
+ #
38
+ # tpImp: 1 - Retrato,
39
+ # 2 - Paisagem,
40
+ # 3 - DANFE Simplificado,
41
+ # 4 - DANFE NFC-e,
42
+ # 5 - DANFE NFC-e em mensagem eletrônica (o envio de
43
+ # mensagem eletrônica pode ser feita de forma simultânea
44
+ # com a impressão do DANFE; usar o tpImp=5 quando
45
+ # esta for a única forma de disponibilização do DANFE).
46
+ #
47
+ # procEmit: 0 - emissão de NF-e com aplicativo do contribuinte,
48
+ # 1 - emissão de NF-e avulsa pelo Fisco,
49
+ # 2 - emissão de NF-e avulsa, pelo site,
50
+ # 3 - emissão NF-e pelo contribuinte com aplicativo fornecido pelo Fisco,
51
+ #
52
+ # idDest: 1 - Operação interna,
53
+ # 2 - Operação interestadual,
54
+ # 3 - Operação com exterior
55
+ #
56
+ # indFinal: 0 - Não,
57
+ # 1 - Consumidor final
58
+ #
59
+ # indPres: 0 - Não se aplica (por exemplo, Nota Fiscal complementar
60
+ # ou de ajuste);
61
+ # 1 - Operação presencial;
62
+ # 2 - Operação não presencial, pela Internet;
63
+ # 3 - Operação não presencial, Teleatendimento;
64
+ # 4 - NFC-e em operação com entrega a domicílio;
65
+ # 9 - Operação não presencial, outros.
66
66
 
67
- def initialize(attrs = {})
68
- # Estado
69
- @state = attrs[:cUF]
70
- # Cidade
71
- @city = attrs[:cMunFG]
72
- # Numero Aleatorio
73
- @sample_number = attrs[:cNF]
74
- # Natureza Operacao
75
- @operation = attrs[:natOp]
76
- # Numero da Nota
77
- @number = attrs[:nNF]
78
- # Modelo
79
- @model = attrs[:mod]
80
- # Data Emissao
81
- @emission = attrs[:dEmi]
82
- # Tipo de Emissao
83
- @emission_kind = attrs[:tpEmis]
84
- # Data de Saida
85
- @out = attrs[:dSaiEnt]
86
- # Hora de Saida
87
- @out_time = attrs[:hSaiEnt]
88
- # Data de Emissao
89
- @emission_date = attrs[:dhEmi]
90
- # Serie
91
- @serie = attrs[:serie]
92
- # Tipo da Nota
93
- @kind = attrs[:tpNF]
94
- # Ambiente
95
- @environment = attrs[:tpAmb]
96
- # Finalidade
97
- @finality = attrs[:finNFe]
98
- # Versao aplicativo do emissor
99
- @version = attrs[:verProc]
100
- # Pagamento
101
- @payment = attrs[:indPag]
102
- # Processo de Emissao
103
- @process = attrs[:procEmi]
104
- # Digito Verificador
105
- @digit = attrs[:cDV]
106
- # Orientação da Pagina
107
- @orientation = attrs[:tpImp]
108
- # Codigo do Destino
109
- @destiny_code = attrs[:idDest]
110
- # Consumidor final
111
- @final_consumer = attrs[:indFinal]
112
- # Indicador de presença do comprador
113
- @consumer_presence = attrs[:indPres]
67
+ def initialize(attrs = {})
68
+ # Estado
69
+ @state = attrs[:cUF]
70
+ # Cidade
71
+ @city = attrs[:cMunFG]
72
+ # Numero Aleatorio
73
+ @sample_number = attrs[:cNF]
74
+ # Natureza Operacao
75
+ @operation = attrs[:natOp]
76
+ # Numero da Nota
77
+ @number = attrs[:nNF]
78
+ # Modelo
79
+ @model = attrs[:mod]
80
+ # Data Emissao
81
+ @emission = attrs[:dEmi]
82
+ # Tipo de Emissao
83
+ @emission_kind = attrs[:tpEmis]
84
+ # Data de Saida
85
+ @out = attrs[:dSaiEnt]
86
+ # Hora de Saida
87
+ @out_time = attrs[:hSaiEnt]
88
+ # Data de Emissao
89
+ @emission_date = attrs[:dhEmi]
90
+ # Serie
91
+ @serie = attrs[:serie]
92
+ # Tipo da Nota
93
+ @kind = attrs[:tpNF]
94
+ # Ambiente
95
+ @environment = attrs[:tpAmb]
96
+ # Finalidade
97
+ @finality = attrs[:finNFe]
98
+ # Versao aplicativo do emissor
99
+ @version = attrs[:verProc]
100
+ # Pagamento
101
+ @payment = attrs[:indPag]
102
+ # Processo de Emissao
103
+ @process = attrs[:procEmi]
104
+ # Digito Verificador
105
+ @digit = attrs[:cDV]
106
+ # Orientação da Pagina
107
+ @orientation = attrs[:tpImp]
108
+ # Codigo do Destino
109
+ @destiny_code = attrs[:idDest]
110
+ # Consumidor final
111
+ @final_consumer = attrs[:indFinal]
112
+ # Indicador de presença do comprador
113
+ @consumer_presence = attrs[:indPres]
114
114
 
115
- # Contigencia
116
- @contingency_date = attrs[:dhCont]
117
- @contingency_justification = attrs[:xJust]
115
+ # Contigencia
116
+ @contingency_date = attrs[:dhCont]
117
+ @contingency_justification = attrs[:xJust]
118
118
 
119
- # Documento Fiscal Referenciado
120
- @documents = []
121
-
122
- if attrs[:NFref].is_a? Array
123
- attrs[:NFref].each do |document|
124
- @documents << Document.new(document)
125
- end
126
- elsif attrs[:NFref].is_a? Hash
127
- @documents << Document.new(attrs[:NFref])
128
- end
129
- end
119
+ # Documento Fiscal Referenciado
120
+ @documents = create_resources(Document, attrs[:NFref])
130
121
  end
131
122
  end
132
123
  end
@@ -0,0 +1,24 @@
1
+ module NfeReader
2
+ module AttributeHelper
3
+ def attributes
4
+ @attributes ||= attributes_to_hash
5
+ end
6
+
7
+ WITHELIST = %w(taxpayer_messages messages seals)
8
+
9
+ def attributes_to_hash
10
+ attrs = Hash.new
11
+
12
+ instance_variables.each do |var|
13
+ key = var.to_s.gsub /^@/, ''
14
+ value = instance_variable_get(var)
15
+
16
+ if [String, Hash].include?(value.class) || WITHELIST.include?(key)
17
+ attrs[key] = value
18
+ end
19
+ end
20
+
21
+ attrs
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ module NfeReader
2
+ module CreatorHelper
3
+ def create_resource(klass, attrs = {})
4
+ return unless attrs
5
+ klass.new(attrs)
6
+ end
7
+
8
+ def create_resources(klass, attrs = {})
9
+ resources = []
10
+
11
+ return resources unless attrs
12
+
13
+ if attrs.is_a? Hash
14
+ resources << klass.new(attrs)
15
+ else
16
+ attrs.each do |a|
17
+ resources << klass.new(a)
18
+ end
19
+ end
20
+
21
+ resources
22
+ end
23
+
24
+ def to_array(attrs = {})
25
+ array = []
26
+
27
+ return [] unless attrs
28
+
29
+ if attrs.is_a? Array
30
+ attrs.each do |hash|
31
+ array << hash.map { |key, value| value }
32
+ end
33
+ else
34
+ array << attrs.map { |key, value| value }
35
+ end
36
+
37
+ array
38
+ end
39
+ end
40
+ end
@@ -40,6 +40,8 @@ class Nokogiri::XML::Node
40
40
  unless child.next_sibling || child.previous_sibling
41
41
  return result
42
42
  end
43
+ elsif child.cdata?
44
+ return child.text
43
45
  elsif result_hash[name]
44
46
  if result_hash[name].is_a?(Object::Array)
45
47
  result_hash[name] << result
@@ -1,28 +1,26 @@
1
1
  # encoding: UTF-8
2
- module Nfe
3
- module Reader
4
- class Information
5
- include ::AttributeHelper
6
- include ::CreatorHelper
2
+ module NfeReader
3
+ class Information
4
+ include AttributeHelper
5
+ include CreatorHelper
7
6
 
8
- attr_reader :information, :information_taxpayer, :taxpayer_messages, :messages,
9
- :references
7
+ attr_reader :information, :information_taxpayer, :taxpayer_messages, :messages,
8
+ :references
10
9
 
11
- def initialize(attrs = {})
12
- @information = attrs[:infAdFisco]
13
- @information_taxpayer = attrs[:infCpl]
10
+ def initialize(attrs = {})
11
+ @information = attrs[:infAdFisco]
12
+ @information_taxpayer = attrs[:infCpl]
14
13
 
15
- if attrs[:procRef]
16
- @references = to_array(attrs[:procRef])
17
- end
14
+ if attrs[:procRef]
15
+ @references = to_array(attrs[:procRef])
16
+ end
18
17
 
19
- if attrs[:obsCont]
20
- @taxpayer_messages = to_array(attrs[:obsCont])
21
- end
18
+ if attrs[:obsCont]
19
+ @taxpayer_messages = to_array(attrs[:obsCont])
20
+ end
22
21
 
23
- if attrs[:obsFisco]
24
- @messages = to_array(attrs[:obsFisco])
25
- end
22
+ if attrs[:obsFisco]
23
+ @messages = to_array(attrs[:obsFisco])
26
24
  end
27
25
  end
28
26
  end