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,28 +1,29 @@
1
- module Nfe
2
- module Reader
3
- class Nfe
4
- include ::AttributeHelper
1
+ module NfeReader
2
+ class Nfe
3
+ include AttributeHelper
4
+ include CreatorHelper
5
5
 
6
- attr_reader :version, :number, :signature, :client, :information,
7
- :header, :provider, :customer, :products, :collection, :transport,
8
- :purchase, :cane, :export, :delivery, :removal,:enviroment,
9
- :version_app, :key, :date, :protocol, :digest, :status, :description,
10
- :total, :authorizations, :error, :trace, :fiscal
6
+ attr_reader :version, :number, :signature, :client, :information,
7
+ :header, :provider, :customer, :products, :billing, :transport,
8
+ :purchase, :cane, :export, :delivery, :removal,:enviroment,
9
+ :version_app, :key, :date, :protocol, :digest, :status, :description,
10
+ :total, :authorizations, :error, :trace, :fiscal, :version_schema
11
11
 
12
- def initialize(file)
12
+ def initialize(file)
13
13
 
14
- xml = file.is_a?(Nokogiri::XML::Document) ? file : Nokogiri::XML(file)
15
- xml = xml.to_hash
14
+ xml = file.is_a?(Nokogiri::XML::Document) ? file : Nokogiri::XML(file)
15
+ xml = xml.to_hash
16
16
 
17
+ if xml[:nfeProc]
17
18
  # Versao da NFe
18
- @version = xml[:nfeProc][:versao]
19
+ @version_schema = xml[:nfeProc][:versao]
19
20
  # Assinatura
20
21
  @signature = xml[:nfeProc][:NFe][:Signature]
21
22
 
22
23
  # Protocolo
23
24
  if xml[:nfeProc][:protNFe]
24
25
  protocol = xml[:nfeProc][:protNFe][:infProt]
25
-
26
+
26
27
  @enviroment = protocol[:tpAmb]
27
28
  @version_app = protocol[:verAplic]
28
29
  @key = protocol[:chNFe]
@@ -34,97 +35,87 @@ module Nfe
34
35
  end
35
36
 
36
37
  xml = xml[:nfeProc][:NFe][:infNFe]
38
+ else
39
+ xml = xml[:NFe][:infNFe]
40
+ end
37
41
 
38
- # Numero da Nfe
39
- @number = xml[:Id]
40
-
41
- # Identificação da Nota Fiscal eletrônica
42
- @header = Header.new(xml[:ide])
42
+ # Numero da Nfe
43
+ @number = xml[:Id]
44
+ # Versao da NFe
45
+ @version = xml[:versao]
43
46
 
44
- # Identificação do Emitente da Nota Fiscal eletrônica
45
- @provider = Provider.new(xml[:emit])
47
+ # Identificação da Nota Fiscal eletrônica
48
+ @header = Header.new(xml[:ide])
46
49
 
47
- # Identificação do Fisco Emitente da NF-e
48
- if xml[:avulsa]
49
- @fiscal = Fiscal.new(xml[:avulsa])
50
- end
50
+ # Identificação do Emitente da Nota Fiscal eletrônica
51
+ @provider = Provider.new(xml[:emit])
51
52
 
52
- # Identificação do Destinatário da Nota Fiscal eletrônica
53
- @customer = Customer.new(xml[:dest])
53
+ # Identificação do Fisco Emitente da NF-e
54
+ if xml[:avulsa]
55
+ @fiscal = Fiscal.new(xml[:avulsa])
56
+ end
54
57
 
55
- # Informacoes Adicional
56
- if xml[:infAdic]
57
- @information = Information.new(xml[:infAdic])
58
- end
58
+ # Identificação do Destinatário da Nota Fiscal eletrônica
59
+ @customer = Customer.new(xml[:dest])
59
60
 
60
- # Detalhamento de Produtos e Serviços da NF-e
61
- @products = []
62
- if xml[:det].is_a? Array
63
- xml[:det].each do |product|
64
- @products << Product.new(product)
65
- end
66
- else
67
- @products << Product.new(xml[:det])
68
- end
69
-
70
- # Totalizadores
71
- @total = Total.new(xml[:total])
61
+ # Informacoes Adicional
62
+ if xml[:infAdic]
63
+ @information = Information.new(xml[:infAdic])
64
+ end
72
65
 
73
- # Informacao de Pagamento
74
- if xml[:cobr]
75
- @collection = Collection.new(xml[:cobr])
76
- end
66
+ # Detalhamento de Produtos e Serviços da NF-e
67
+ @products = create_resources(Product, xml[:det])
77
68
 
78
- # Transporte
79
- if xml[:transp]
80
- @transport = Transport.new(xml[:transp])
81
- end
69
+ # Totalizadores
70
+ @total = Total.new(xml[:total])
82
71
 
83
- # Identificação do Local de Entrega
84
- if xml[:retirada]
85
- @removal = Removal.new(xml[:retirada])
86
- end
72
+ # Informacao de Pagamento
73
+ if xml[:cobr]
74
+ @billing = Billing.new(xml[:cobr])
75
+ end
87
76
 
88
- # Identificação do Local de Retirada
89
- if xml[:entrega]
90
- @delivery = Delivery.new(xml[:entrega])
91
- end
77
+ # Transporte
78
+ if xml[:transp]
79
+ @transport = Transport.new(xml[:transp])
80
+ end
92
81
 
93
- # Autorização para obter XML
94
- @authorizations = []
95
- if xml[:autXML].is_a? Array
96
- xml[:autXML].each do |product|
97
- @authorizations << Authorization.new(product)
98
- end
99
- elsif xml[:autXML].is_a? Hash
100
- @authorizations << Authorization.new(xml[:autXML])
101
- end
82
+ # Identificação do Local de Entrega
83
+ if xml[:retirada]
84
+ @removal = Removal.new(xml[:retirada])
85
+ end
102
86
 
103
- # Informacoes de Comercio Exterior
104
- if xml[:exporta]
105
- @export = Export.new(xml[:exporta])
106
- end
87
+ # Identificação do Local de Retirada
88
+ if xml[:entrega]
89
+ @delivery = Delivery.new(xml[:entrega])
90
+ end
107
91
 
108
- # Informacoes de Compra
109
- if xml[:compra]
110
- @purchase = Purchase.new(xml[:compra])
111
- end
92
+ # Autorização para obter XML
93
+ @authorizations = create_resources(Authorization, xml[:autXML])
112
94
 
113
- # Cana de Acucar
114
- if xml[:cana]
115
- @cane = Cane.new(xml[:cana])
116
- end
95
+ # Informacoes de Comercio Exterior
96
+ if xml[:exporta]
97
+ @export = Export.new(xml[:exporta])
98
+ end
117
99
 
118
- rescue => exception
119
- @error = exception
120
- @trace = exception.backtrace
121
- ensure
122
- file.close if file.respond_to? :close
100
+ # Informacoes de Compra
101
+ if xml[:compra]
102
+ @purchase = Purchase.new(xml[:compra])
123
103
  end
124
104
 
125
- def error?
126
- !error.nil?
105
+ # Cana de Acucar
106
+ if xml[:cana]
107
+ @cane = Cane.new(xml[:cana])
127
108
  end
109
+
110
+ rescue => exception
111
+ @error = exception
112
+ @trace = exception.backtrace
113
+ ensure
114
+ file.close if file.respond_to? :close
115
+ end
116
+
117
+ def error?
118
+ !error.nil?
128
119
  end
129
120
  end
130
121
  end
@@ -0,0 +1,53 @@
1
+ module NfeReader
2
+ class Person
3
+ include AttributeHelper
4
+
5
+ attr_reader :cnpj, :cpf, :state_registration,
6
+ :name, :phone, :suframa, :email, :fantasy,
7
+ :state, :rntrc, :owner_kind, :state_registration_st,
8
+ :city_registration, :regime, :cnae, :foreign_code,
9
+ :state_registration_code
10
+
11
+ # == Fields Values
12
+ #
13
+ # CRT: 1 - Simples Nacional,
14
+ # 2 - Simples Nacional – excesso de sublimite de receita bruta,
15
+ # 3 - Regime Normal
16
+ #
17
+ def initialize(attrs = {})
18
+ # CNPJ
19
+ @cnpj = attrs[:CNPJ]
20
+ # CPF
21
+ @cpf = attrs[:CPF]
22
+ # Inscricao Estadual
23
+ @state_registration = attrs[:IE]
24
+ # Inscricao Estadual ST
25
+ @state_registration_st = attrs[:IEST]
26
+ # Codigo Inscricao Estadual
27
+ @state_registration_code = attrs[:indIEDest]
28
+ # Incsricao municipal
29
+ @city_registration = attrs[:IM]
30
+ # Nome
31
+ @name = attrs[:xNome]
32
+ # Fantasia Empresa
33
+ @fantasy = attrs[:xFant]
34
+ # Telefone
35
+ @phone = attrs[:fone]
36
+ # Incricao Suframa
37
+ @suframa = attrs[:ISUF]
38
+ # Email
39
+ @email = attrs[:email]
40
+ # Estado
41
+ @state = attrs[:UF]
42
+ # Regime
43
+ @regime = attrs[:CRT]
44
+ # CNAE
45
+ @cnae = attrs[:CNAE]
46
+ # Identificação do destinatário no caso de comprador estrangeiro
47
+ @foreign_code = attrs[:idEstrangeiro]
48
+ # Proprietario do Veiculo
49
+ @rntrc = attrs[:RNTRC]
50
+ @owner_kind = attrs[:tpProp]
51
+ end
52
+ end
53
+ end
@@ -1,80 +1,82 @@
1
1
  # encoding: UTF-8
2
- module Nfe
3
- module Reader
4
- # Detalhamento de Produtos e Serviços da NF-e
5
- class Product
6
- include ::AttributeHelper
7
- include ::CreatorHelper
2
+ module NfeReader
3
+ # Detalhamento de Produtos e Serviços da NF-e
4
+ class Product
5
+ include AttributeHelper
6
+ include CreatorHelper
8
7
 
9
- attr_reader :number, :code, :name, :ean, :ncm, :cfop,
10
- :unit_sale, :value_sale, :amount_sale, :total, :gtin, :unit,
11
- :amount, :value, :kind, :ipi_exception, :freight, :insurance,
12
- :discount, :other_value, :importation, :icms, :ipi, :pis,
13
- :importation_tax, :exportation, :demand_number, :demand_item,
14
- :armament, :fuel, :vehicle, :medicament, :cofins, :pis_st,
15
- :cofins_st, :issqn
8
+ attr_reader :number, :code, :name, :ean, :ncm, :cfop,
9
+ :unit_sale, :value_sale, :amount_sale, :total, :gtin, :unit,
10
+ :amount, :value, :kind, :ipi_exception, :freight, :insurance,
11
+ :discount, :other_value, :importation, :icms, :ipi, :pis,
12
+ :importation_tax, :exportation, :demand_number, :demand_item,
13
+ :armament, :fuel, :vehicle, :medicament, :cofins, :pis_st,
14
+ :cofins_st, :issqn, :tax_value, :fci
16
15
 
17
- # == Fields Values
18
- #
19
- # indTot: 0 - o valor do item (vProd) compõe o valor total da NF-e (vProd)
20
- # 1 - o valor do item (vProd) não compõe o valor total da NF-e (vProd) (v2.0)
21
- #
22
- def initialize(attrs = {})
23
- @number = attrs[:nItem]
16
+ # == Fields Values
17
+ #
18
+ # indTot: 0 - o valor do item (vProd) compõe o valor total da NF-e (vProd)
19
+ # 1 - o valor do item (vProd) não compõe o valor total da NF-e (vProd) (v2.0)
20
+ #
21
+ def initialize(attrs = {})
22
+ @number = attrs[:nItem]
23
+
24
+ if attrs[:prod]
25
+ @code = attrs[:prod][:cProd]
26
+ @name = attrs[:prod][:xProd]
27
+ @ean = attrs[:prod][:cEAN]
28
+ @ncm = attrs[:prod][:NCM]
24
29
 
25
- if attrs[:prod]
26
- @code = attrs[:prod][:cProd]
27
- @name = attrs[:prod][:xProd]
28
- @ean = attrs[:prod][:cEAN]
29
- @ncm = attrs[:prod][:NCM]
30
-
31
- # Sale
32
- @cfop = attrs[:prod][:CFOP]
33
- @unit_sale = attrs[:prod][:uCom]
34
- @amount_sale = attrs[:prod][:qCom]
35
- @value_sale = attrs[:prod][:vUnCom]
36
- @total = attrs[:prod][:vProd]
30
+ # Sale
31
+ @cfop = attrs[:prod][:CFOP]
32
+ @unit_sale = attrs[:prod][:uCom]
33
+ @amount_sale = attrs[:prod][:qCom]
34
+ @value_sale = attrs[:prod][:vUnCom]
35
+ @total = attrs[:prod][:vProd]
37
36
 
38
- # Numero do Pedido de Compra
39
- @demand_number = attrs[:prod][:xPed]
40
- # Item do Pedido de Compra
41
- @demand_item = attrs[:prod][:nItemPed]
37
+ # Numero do Pedido de Compra
38
+ @demand_number = attrs[:prod][:xPed]
39
+ # Item do Pedido de Compra
40
+ @demand_item = attrs[:prod][:nItemPed]
42
41
 
43
- # GTIN (Global Trade ItemNumber)
44
- @gtin = attrs[:prod][:cEANTrib]
45
-
46
- @unit = attrs[:prod][:uTrib]
47
- @amount = attrs[:prod][:qTrib]
48
- @value = attrs[:prod][:vUnTrib]
49
- @kind = attrs[:prod][:indTot]
50
- @ipi_exception = attrs[:prod][:EXTIPI]
51
- @freight = attrs[:prod][:vFrete]
52
- @insurance = attrs[:prod][:vSeg]
53
- @discount = attrs[:prod][:vDesc]
54
- @other_value = attrs[:prod][:vOutro]
55
-
56
- @importation = create_resource(Importation, attrs[:prod][:DI])
57
- end
42
+ # GTIN (Global Trade ItemNumber)
43
+ @gtin = attrs[:prod][:cEANTrib]
58
44
 
59
- @fuel = Fuel.new(attrs[:comb]) if attrs[:comb]
60
- @vehicle = Vehicle.new(attrs[:veicProd]) if attrs[:veicProd]
45
+ @unit = attrs[:prod][:uTrib]
46
+ @amount = attrs[:prod][:qTrib]
47
+ @value = attrs[:prod][:vUnTrib]
48
+ @kind = attrs[:prod][:indTot]
49
+ @ipi_exception = attrs[:prod][:EXTIPI]
50
+ @freight = attrs[:prod][:vFrete]
51
+ @insurance = attrs[:prod][:vSeg]
52
+ @discount = attrs[:prod][:vDesc]
53
+ @other_value = attrs[:prod][:vOutro]
54
+
55
+ @fci = attrs[:prod][:nFCI]
61
56
 
62
- @armament = create_resources(Armament, attrs[:arma]) if attrs[:arma]
63
- @medicament = create_resources(Medicament, attrs[:med]) if attrs[:med]
57
+ @importation = create_resource(Importation, attrs[:prod][:DI])
58
+ end
59
+
60
+ @fuel = Fuel.new(attrs[:comb]) if attrs[:comb]
61
+ @vehicle = Vehicle.new(attrs[:veicProd]) if attrs[:veicProd]
62
+
63
+ @armament = create_resources(Armament, attrs[:arma]) if attrs[:arma]
64
+ @medicament = create_resources(Medicament, attrs[:med]) if attrs[:med]
64
65
 
65
- @exportation = create_resources(Exportation, attrs[:detExport])
66
+ @exportation = create_resources(Exportation, attrs[:detExport])
66
67
 
67
- if attrs[:imposto]
68
- @icms = create_resources(Icms, attrs[:imposto][:ICMS])
69
- @cofins = create_resources(Cofins, attrs[:imposto][:COFINS])
70
- @pis = create_resources(Pis, attrs[:imposto][:PIS])
71
-
72
- @importation_tax = create_resource(ImportationTax, attrs[:imposto][:II])
73
- @ipi = create_resource(Ipi, attrs[:imposto][:IPI])
74
- @pis_st = create_resource(PisSt, attrs[:imposto][:PISST])
75
- @cofins_st = create_resource(CofinsSt, attrs[:imposto][:COFINSST])
76
- @issqn = create_resource(Issqn, attrs[:imposto][:ISSQN])
77
- end
68
+ if attrs[:imposto]
69
+ @tax_value = attrs[:imposto][:vTotTrib]
70
+
71
+ @icms = create_resources(Icms, attrs[:imposto][:ICMS])
72
+ @cofins = create_resources(Cofins, attrs[:imposto][:COFINS])
73
+ @pis = create_resources(Pis, attrs[:imposto][:PIS])
74
+
75
+ @importation_tax = create_resource(ImportationTax, attrs[:imposto][:II])
76
+ @ipi = create_resource(Ipi, attrs[:imposto][:IPI])
77
+ @pis_st = create_resource(PisSt, attrs[:imposto][:PISST])
78
+ @cofins_st = create_resource(CofinsSt, attrs[:imposto][:COFINSST])
79
+ @issqn = create_resource(Issqn, attrs[:imposto][:ISSQN])
78
80
  end
79
81
  end
80
82
  end
@@ -1,26 +1,24 @@
1
1
  # encoding: UTF-8
2
- module Nfe
3
- module Reader
4
- class Armament
5
- include ::AttributeHelper
2
+ module NfeReader
3
+ class Armament
4
+ include AttributeHelper
6
5
 
7
- attr_reader :kind, :serie, :barrel, :description
6
+ attr_reader :kind, :serie, :barrel, :description
8
7
 
9
- # Fields Values
10
- #
11
- # tpArma : 0 - Uso permitido;
12
- # 1 - Uso restrito;
13
- #
14
- def initialize(attrs = {})
15
- # Tipo de Arma
16
- @kind = attrs[:tpArma]
17
- # Serie
18
- @serie = attrs[:nSerie]
19
- # Cano
20
- @barrel = attrs[:nCano]
21
- # Descricao
22
- @description = attrs[:descr]
23
- end
8
+ # Fields Values
9
+ #
10
+ # tpArma : 0 - Uso permitido;
11
+ # 1 - Uso restrito;
12
+ #
13
+ def initialize(attrs = {})
14
+ # Tipo de Arma
15
+ @kind = attrs[:tpArma]
16
+ # Serie
17
+ @serie = attrs[:nSerie]
18
+ # Cano
19
+ @barrel = attrs[:nCano]
20
+ # Descricao
21
+ @description = attrs[:descr]
24
22
  end
25
23
  end
26
24
  end