nfe_reader 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/nfe_reader.rb +4 -4
- data/lib/nfe_reader/address.rb +38 -0
- data/lib/nfe_reader/authorization.rb +8 -10
- data/lib/nfe_reader/billing.rb +21 -0
- data/lib/nfe_reader/billing/duplicate.rb +14 -0
- data/lib/nfe_reader/carrier.rb +12 -14
- data/lib/nfe_reader/customer.rb +15 -57
- data/lib/nfe_reader/delivery.rb +16 -18
- data/lib/nfe_reader/document.rb +63 -65
- data/lib/nfe_reader/export.rb +8 -10
- data/lib/nfe_reader/fiscal.rb +29 -31
- data/lib/nfe_reader/header.rb +114 -123
- data/lib/nfe_reader/helpers/attribute_helper.rb +24 -0
- data/lib/nfe_reader/helpers/creator_helper.rb +40 -0
- data/lib/{helpers → nfe_reader/helpers}/nokogiri_hash.rb +2 -0
- data/lib/nfe_reader/information.rb +17 -19
- data/lib/nfe_reader/nfe.rb +78 -87
- data/lib/nfe_reader/person.rb +53 -0
- data/lib/nfe_reader/product.rb +69 -67
- data/lib/nfe_reader/product/armament.rb +18 -20
- data/lib/nfe_reader/product/cane.rb +22 -24
- data/lib/nfe_reader/product/exportation.rb +15 -17
- data/lib/nfe_reader/product/fuel.rb +13 -15
- data/lib/nfe_reader/product/importation.rb +42 -44
- data/lib/nfe_reader/product/medicament.rb +15 -17
- data/lib/nfe_reader/product/vehicle.rb +113 -115
- data/lib/nfe_reader/provider.rb +10 -40
- data/lib/nfe_reader/purchase.rb +9 -12
- data/lib/nfe_reader/removal.rb +17 -19
- data/lib/nfe_reader/taxation/cofins.rb +41 -41
- data/lib/nfe_reader/taxation/cofins_st.rb +15 -17
- data/lib/nfe_reader/taxation/icms.rb +80 -81
- data/lib/nfe_reader/taxation/importation_tax.rb +14 -16
- data/lib/nfe_reader/taxation/ipi.rb +35 -37
- data/lib/nfe_reader/taxation/issqn.rb +17 -19
- data/lib/nfe_reader/taxation/pis.rb +41 -41
- data/lib/nfe_reader/taxation/pis_st.rb +16 -18
- data/lib/nfe_reader/total.rb +71 -71
- data/lib/nfe_reader/transport.rb +76 -89
- data/lib/nfe_reader/version.rb +2 -4
- data/nfe-reader.gemspec +2 -1
- data/test/nfe_reader/address_test.rb +75 -0
- data/test/nfe_reader/authorization_test.rb +2 -2
- data/test/nfe_reader/{collection → billing}/duplicate_test.rb +2 -2
- data/test/nfe_reader/{collection_test.rb → billing_test.rb} +13 -13
- data/test/nfe_reader/cane_test.rb +2 -2
- data/test/nfe_reader/carrier_test.rb +4 -4
- data/test/nfe_reader/customer_test.rb +6 -101
- data/test/nfe_reader/delivery_test.rb +2 -2
- data/test/nfe_reader/document_test.rb +2 -2
- data/test/nfe_reader/export_test.rb +2 -2
- data/test/nfe_reader/fiscal_test.rb +2 -2
- data/test/nfe_reader/header_test.rb +2 -2
- data/test/{helpers → nfe_reader/helpers}/attributte_helper_test.rb +3 -3
- data/test/{helpers → nfe_reader/helpers}/creator_helper_test.rb +3 -3
- data/test/{helpers → nfe_reader/helpers}/nokogiri_test.rb +1 -1
- data/test/nfe_reader/information_test.rb +2 -2
- data/test/nfe_reader/nfe_test.rb +13 -13
- data/test/nfe_reader/person_test.rb +60 -0
- data/test/nfe_reader/product/armament_test.rb +2 -2
- data/test/nfe_reader/product/exportation_test.rb +2 -2
- data/test/nfe_reader/product/fuel_test.rb +2 -2
- data/test/nfe_reader/product/importation_test.rb +2 -2
- data/test/nfe_reader/product/medicament_test.rb +2 -2
- data/test/nfe_reader/product/vehicle_test.rb +2 -2
- data/test/nfe_reader/product_test.rb +2 -2
- data/test/nfe_reader/provider_test.rb +5 -118
- data/test/nfe_reader/purchase_test.rb +2 -2
- data/test/nfe_reader/removal_test.rb +2 -2
- data/test/nfe_reader/taxation/cofins_st_test.rb +2 -2
- data/test/nfe_reader/taxation/cofins_test.rb +2 -2
- data/test/nfe_reader/taxation/icms_test.rb +2 -2
- data/test/nfe_reader/taxation/importation_tax_test.rb +2 -2
- data/test/nfe_reader/taxation/ipi_test.rb +2 -2
- data/test/nfe_reader/taxation/issqn_test.rb +2 -2
- data/test/nfe_reader/taxation/pis_st_test.rb +2 -2
- data/test/nfe_reader/taxation/pis_test.rb +2 -2
- data/test/nfe_reader/total_test.rb +2 -2
- data/test/nfe_reader/transport_test.rb +3 -3
- metadata +37 -17
- data/lib/helpers/attribute_helper.rb +0 -18
- data/lib/helpers/creator_helper.rb +0 -32
- data/lib/nfe_reader/collection.rb +0 -38
- data/lib/nfe_reader/collection/duplicate.rb +0 -16
data/lib/nfe_reader/nfe.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module NfeReader
|
2
|
+
class Nfe
|
3
|
+
include AttributeHelper
|
4
|
+
include CreatorHelper
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
12
|
+
def initialize(file)
|
13
13
|
|
14
|
-
|
15
|
-
|
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
|
-
@
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
45
|
-
|
47
|
+
# Identificação da Nota Fiscal eletrônica
|
48
|
+
@header = Header.new(xml[:ide])
|
46
49
|
|
47
|
-
|
48
|
-
|
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
|
-
|
53
|
-
|
53
|
+
# Identificação do Fisco Emitente da NF-e
|
54
|
+
if xml[:avulsa]
|
55
|
+
@fiscal = Fiscal.new(xml[:avulsa])
|
56
|
+
end
|
54
57
|
|
55
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
74
|
-
|
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
|
-
|
79
|
-
|
80
|
-
@transport = Transport.new(xml[:transp])
|
81
|
-
end
|
69
|
+
# Totalizadores
|
70
|
+
@total = Total.new(xml[:total])
|
82
71
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
72
|
+
# Informacao de Pagamento
|
73
|
+
if xml[:cobr]
|
74
|
+
@billing = Billing.new(xml[:cobr])
|
75
|
+
end
|
87
76
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
77
|
+
# Transporte
|
78
|
+
if xml[:transp]
|
79
|
+
@transport = Transport.new(xml[:transp])
|
80
|
+
end
|
92
81
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
87
|
+
# Identificação do Local de Retirada
|
88
|
+
if xml[:entrega]
|
89
|
+
@delivery = Delivery.new(xml[:entrega])
|
90
|
+
end
|
107
91
|
|
108
|
-
|
109
|
-
|
110
|
-
@purchase = Purchase.new(xml[:compra])
|
111
|
-
end
|
92
|
+
# Autorização para obter XML
|
93
|
+
@authorizations = create_resources(Authorization, xml[:autXML])
|
112
94
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
95
|
+
# Informacoes de Comercio Exterior
|
96
|
+
if xml[:exporta]
|
97
|
+
@export = Export.new(xml[:exporta])
|
98
|
+
end
|
117
99
|
|
118
|
-
|
119
|
-
|
120
|
-
@
|
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
|
-
|
126
|
-
|
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
|
data/lib/nfe_reader/product.rb
CHANGED
@@ -1,80 +1,82 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
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
|
-
@
|
60
|
-
@
|
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
|
-
@
|
63
|
-
|
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
|
-
|
66
|
+
@exportation = create_resources(Exportation, attrs[:detExport])
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
3
|
-
|
4
|
-
|
5
|
-
include ::AttributeHelper
|
2
|
+
module NfeReader
|
3
|
+
class Armament
|
4
|
+
include AttributeHelper
|
6
5
|
|
7
|
-
|
6
|
+
attr_reader :kind, :serie, :barrel, :description
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|