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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba1c5791d02df4dfb1c09a5c5207060233d22129
|
4
|
+
data.tar.gz: d21ea3e85feb073c68932cae0d5ff5176b276d45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71801667ed953056b6018147364723507d62c32a8730ed342f91c1ce3b58e5d6ea24d30558c980b92b6206ac692d1520c035177c25e5e1f5ef045d23af23f76d
|
7
|
+
data.tar.gz: ddc9fd204fdd0d4ad7bc462cbe015fddbd14f1bb3c9855a418dc15d6787a27ec3c9283a81cec738443f42acb21319aac2a181bfe6d7e4f3ff4892b1cadb9896e
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
##
|
1
|
+
## NfeReader ##
|
2
2
|
|
3
3
|
Gem to open Brazilian NF-e XML and convert to Ruby classes.
|
4
4
|
|
@@ -22,11 +22,11 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
### Usage
|
24
24
|
|
25
|
-
Open the xml file and import to
|
25
|
+
Open the xml file and import to NfeReader:
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
file = File.open('sample-nfe.xml')
|
29
|
-
nfe =
|
29
|
+
nfe = NfeReader::Nfe.new(file)
|
30
30
|
```
|
31
31
|
|
32
32
|
You can access class attributes:
|
data/lib/nfe_reader.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require "nfe_reader/version"
|
3
3
|
require "nokogiri"
|
4
|
-
require "helpers/nokogiri_hash"
|
5
|
-
require "helpers/attribute_helper"
|
6
|
-
require "helpers/creator_helper"
|
4
|
+
require "nfe_reader/helpers/nokogiri_hash"
|
5
|
+
require "nfe_reader/helpers/attribute_helper"
|
6
|
+
require "nfe_reader/helpers/creator_helper"
|
7
7
|
|
8
|
-
%w(nfe_reader/product nfe_reader/
|
8
|
+
%w(nfe_reader/product nfe_reader/billing nfe_reader/taxation nfe_reader).each do |namespace|
|
9
9
|
Dir[File.dirname(__FILE__) + "/../lib/#{namespace}/*.rb"].each { |file| require file }
|
10
10
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module NfeReader
|
2
|
+
class Address
|
3
|
+
include AttributeHelper
|
4
|
+
|
5
|
+
attr_reader :address, :number, :complement, :neighborhood,
|
6
|
+
:city_code, :city, :zip_code, :state, :country_code, :country,
|
7
|
+
:phone, :cnpj, :cpf
|
8
|
+
|
9
|
+
def initialize(attrs= {})
|
10
|
+
# CNPJ
|
11
|
+
@cnpj = attrs[:CNPJ]
|
12
|
+
# CPF
|
13
|
+
@cpf = attrs[:CPF]
|
14
|
+
# Logradouo
|
15
|
+
@address = attrs[:xLgr]
|
16
|
+
# Numero
|
17
|
+
@number = attrs[:nro]
|
18
|
+
# Complemento
|
19
|
+
@complement = attrs[:xCpl]
|
20
|
+
# Bairro
|
21
|
+
@neighborhood = attrs[:xBairro]
|
22
|
+
# Codigo IBGE Cidade
|
23
|
+
@city_code = attrs[:cMun]
|
24
|
+
# Nome Cidade
|
25
|
+
@city = attrs[:xMun]
|
26
|
+
# CEP
|
27
|
+
@zip_code = attrs[:CEP]
|
28
|
+
# Estado
|
29
|
+
@state = attrs[:UF]
|
30
|
+
# Codigo Pais
|
31
|
+
@country_code = attrs[:cPais]
|
32
|
+
# Pais
|
33
|
+
@country = attrs[:xPais]
|
34
|
+
# Telefone
|
35
|
+
@phone = attrs[:fone]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
include ::AttributeHelper
|
2
|
+
module NfeReader
|
3
|
+
# Pessoas Autorizadas para obter XML
|
4
|
+
class Authorization
|
5
|
+
include AttributeHelper
|
7
6
|
|
8
|
-
|
7
|
+
attr_reader :cnpj, :cpf
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
9
|
+
def initialize(attrs = {})
|
10
|
+
@cnpj = attrs[:CNPJ]
|
11
|
+
@cpf = attrs[:CPF]
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module NfeReader
|
3
|
+
# Mapeia as Cobrancas
|
4
|
+
class Billing
|
5
|
+
include AttributeHelper
|
6
|
+
include CreatorHelper
|
7
|
+
|
8
|
+
attr_reader :number, :value, :descount, :value_net, :duplicates
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
if attrs[:fat]
|
12
|
+
@number = attrs[:fat][:nFat]
|
13
|
+
@value = attrs[:fat][:vOrig]
|
14
|
+
@descount = attrs[:fat][:vDesc]
|
15
|
+
@value_net = attrs[:fat][:vLiq]
|
16
|
+
end
|
17
|
+
|
18
|
+
@duplicates = create_resources(Duplicate, attrs[:dup])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module NfeReader
|
3
|
+
class Duplicate
|
4
|
+
include AttributeHelper
|
5
|
+
|
6
|
+
attr_reader :number, :expiration, :value
|
7
|
+
|
8
|
+
def initialize(attrs = {})
|
9
|
+
@number = attrs[:nDup]
|
10
|
+
@expiration = attrs[:dVenc]
|
11
|
+
@value = attrs[:vDup]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/nfe_reader/carrier.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
include ::AttributeHelper
|
2
|
+
module NfeReader
|
3
|
+
class Carrier
|
4
|
+
include AttributeHelper
|
6
5
|
|
7
|
-
|
6
|
+
attr_reader :cnpj, :cpf, :name, :state_registration, :address, :city, :state
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
8
|
+
def initialize(attrs = {})
|
9
|
+
@cnpj = attrs[:CNPJ]
|
10
|
+
@cpf = attrs[:CPF]
|
11
|
+
@name = attrs[:xNome]
|
12
|
+
@state_registration = attrs[:IE]
|
13
|
+
@address = attrs[:xEnder]
|
14
|
+
@city = attrs[:xMun]
|
15
|
+
@state = attrs[:UF]
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
data/lib/nfe_reader/customer.rb
CHANGED
@@ -1,65 +1,23 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
include ::AttributeHelper
|
2
|
+
module NfeReader
|
3
|
+
# Identificação do Destinatário da Nota Fiscal eletrônica
|
4
|
+
class Customer
|
5
|
+
include AttributeHelper
|
7
6
|
|
8
|
-
|
9
|
-
:suframa, :phone, :address, :number, :neighborhood, :city_code,
|
10
|
-
:city, :state, :country_code, :country, :complement, :foreign_code,
|
11
|
-
:zip_code, :city_registration, :state_registration_code
|
7
|
+
attr_reader :person, :address
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
# == Fields Values
|
10
|
+
#
|
11
|
+
# indIEDest: 1 - Contribuinte ICMS (informar a IE do destinatário),
|
12
|
+
# 2 - Contribuinte isento de Inscrição no cadastro de Contribuintes do ICMS,
|
13
|
+
# 9 - Não Contribuinte, que pode ou não possuir Inscrição Estadual
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
@cpf = attrs[:CPF]
|
15
|
+
def initialize(attrs = {})
|
16
|
+
@person = Person.new(attrs)
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@state_registration = attrs[:IE]
|
27
|
-
# Inscrição na SUFRAMA
|
28
|
-
@suframa = attrs[:ISUF]
|
29
|
-
# Inscrição Municipal do Tomador do Serviço
|
30
|
-
@city_registration = attrs[:IM]
|
31
|
-
# Indicador da IE do Destinatário
|
32
|
-
@state_registration_code = attrs[:indIEDest]
|
33
|
-
# Email
|
34
|
-
@email = attrs[:email]
|
35
|
-
# Identificação do destinatário no caso de comprador estrangeiro
|
36
|
-
@foreign_code = attrs[:idEstrangeiro]
|
37
|
-
|
38
|
-
# Address
|
39
|
-
if attrs[:enderDest]
|
40
|
-
# Logradouro
|
41
|
-
@address = attrs[:enderDest][:xLgr]
|
42
|
-
# Numero
|
43
|
-
@number = attrs[:enderDest][:nro]
|
44
|
-
# Complemento
|
45
|
-
@complement = attrs[:enderDest][:xCpl]
|
46
|
-
# Bairro
|
47
|
-
@neighborhood = attrs[:enderDest][:xBairro]
|
48
|
-
# Código do município
|
49
|
-
@city_code = attrs[:enderDest][:cMun]
|
50
|
-
# Nome do município
|
51
|
-
@city = attrs[:enderDest][:xMun]
|
52
|
-
# Sigla da UF
|
53
|
-
@state = attrs[:enderDest][:UF]
|
54
|
-
# Código do CEP
|
55
|
-
@zip_code = attrs[:enderDest][:CEP]
|
56
|
-
# Codigo Pais
|
57
|
-
@country_code = attrs[:enderDest][:cPais]
|
58
|
-
# Nome do Pais
|
59
|
-
@country = attrs[:enderDest][:xPais]
|
60
|
-
# Telefone
|
61
|
-
@phone = attrs[:enderDest][:fone]
|
62
|
-
end
|
18
|
+
# Address
|
19
|
+
if attrs[:enderDest]
|
20
|
+
@address = Address.new(attrs[:enderDest])
|
63
21
|
end
|
64
22
|
end
|
65
23
|
end
|
data/lib/nfe_reader/delivery.rb
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
# Local de Entrega
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
include ::AttributeHelper
|
2
|
+
module NfeReader
|
3
|
+
# Identificação do Local de Entrega
|
4
|
+
class Delivery
|
5
|
+
include AttributeHelper
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
attr_reader :cnpj, :cpf, :address, :number, :complement,
|
8
|
+
:neighborhood, :city_code, :city, :state
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
10
|
+
def initialize(attrs = {})
|
11
|
+
@cnpj = attrs[:CNPJ]
|
12
|
+
@cpf = attrs[:CPF]
|
13
|
+
@address = attrs[:xLgr]
|
14
|
+
@number = attrs[:nro]
|
15
|
+
@complement = attrs[:xCpl]
|
16
|
+
@neighborhood = attrs[:xBairro]
|
17
|
+
@city_code = attrs[:cMun]
|
18
|
+
@city = attrs[:xMun]
|
19
|
+
@state = attrs[:UF]
|
22
20
|
end
|
23
21
|
end
|
24
22
|
end
|
data/lib/nfe_reader/document.rb
CHANGED
@@ -1,76 +1,74 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
include ::AttributeHelper
|
2
|
+
module NfeReader
|
3
|
+
# Documento Fiscal Referenciado
|
4
|
+
class Document
|
5
|
+
include AttributeHelper
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
attr_reader :key, :nfe_state, :nfe_year, :nfe_cnpj, :nfe_model,
|
8
|
+
:nfe_serie, :nfe_number, :farmer_state, :farmer_year, :farmer_cnpj,
|
9
|
+
:farmer_cpf, :farmer_ie, :farmer_model, :farmer_serie, :farmer_number,
|
10
|
+
:cte_key, :ecf_model, :ecf_number, :ecf_operation
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
# == Fields Values
|
13
|
+
# mod:
|
14
|
+
# refNF: 01 - modelo 01
|
15
|
+
# refNFP: 04 - NF de Produtor,
|
16
|
+
# 01 - NF (v2.0)
|
17
|
+
# refECF: 2B - Cupom Fiscal emitido por máquina registradora (não ECF),
|
18
|
+
# 2C - Cupom Fiscal PDV,
|
19
|
+
# 2D - Cupom Fiscal (emitido por ECF) (v2.0)
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def initialize(attrs = {})
|
22
|
+
# Chave da NF-e
|
23
|
+
@key = attrs[:refNFe]
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
25
|
+
# Referencia uma NF-e
|
26
|
+
if attrs[:refNF]
|
27
|
+
# Estado
|
28
|
+
@nfe_state = attrs[:refNF][:cUF]
|
29
|
+
# Ano e mes
|
30
|
+
@nfe_year = attrs[:refNF][:AAMM]
|
31
|
+
# CNPJ do emitente
|
32
|
+
@nfe_cnpj = attrs[:refNF][:CNPJ]
|
33
|
+
# Modelo do Documento Fiscal
|
34
|
+
@nfe_model = attrs[:refNF][:mod]
|
35
|
+
# Serie Documento Fiscal
|
36
|
+
@nfe_serie = attrs[:refNF][:serie]
|
37
|
+
# Numero Documento Fiscal
|
38
|
+
@nfe_number = attrs[:refNF][:nNF]
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
41
|
+
# NF de Produtor Rural
|
42
|
+
if attrs[:refNFP]
|
43
|
+
# Estado
|
44
|
+
@farmer_state = attrs[:refNFP][:cUF]
|
45
|
+
# Ano e mes
|
46
|
+
@farmer_year = attrs[:refNFP][:AAMM]
|
47
|
+
# CNPJ do emitente
|
48
|
+
@farmer_cnpj = attrs[:refNFP][:CNPJ]
|
49
|
+
# CPF do emitente
|
50
|
+
@farmer_cpf = attrs[:refNFP][:CPF]
|
51
|
+
# IE do emitente
|
52
|
+
@farmer_ie = attrs[:refNFP][:IE]
|
53
|
+
# Modelo do Documento Fiscal
|
54
|
+
@farmer_model = attrs[:refNFP][:mod]
|
55
|
+
# Serie Documento Fiscal
|
56
|
+
@farmer_serie = attrs[:refNFP][:serie]
|
57
|
+
# Numero Documento Fiscal
|
58
|
+
@farmer_number = attrs[:refNFP][:nNF]
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
61
|
+
# CT-e
|
62
|
+
@cte_key = attrs[:refCTe]
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
64
|
+
# Referencia uma ECF
|
65
|
+
if attrs[:refECF]
|
66
|
+
# Modelo do Documento Fiscal
|
67
|
+
@ecf_model = attrs[:refECF][:mod]
|
68
|
+
# Número de ordem sequencial do ECF
|
69
|
+
@ecf_number = attrs[:refECF][:nECF]
|
70
|
+
# Número do Contador de Ordem de Operação
|
71
|
+
@ecf_operation = attrs[:refECF][:nCOO]
|
74
72
|
end
|
75
73
|
end
|
76
74
|
end
|