nfe_reader 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +13 -0
- data/lib/nfe_reader/authorization.rb +12 -0
- data/lib/nfe_reader/carrier.rb +16 -0
- data/lib/nfe_reader/collection/duplicate.rb +12 -0
- data/lib/nfe_reader/collection.rb +34 -0
- data/lib/nfe_reader/customer.rb +62 -0
- data/lib/nfe_reader/delivery.rb +20 -0
- data/lib/nfe_reader/document.rb +73 -0
- data/lib/nfe_reader/export.rb +12 -0
- data/lib/nfe_reader/fiscal.rb +33 -0
- data/lib/nfe_reader/header.rb +129 -0
- data/lib/nfe_reader/information.rb +38 -0
- data/lib/nfe_reader/product/armament.rb +22 -0
- data/lib/nfe_reader/product/cane.rb +42 -0
- data/lib/nfe_reader/product/exportation.rb +20 -0
- data/lib/nfe_reader/product/fuel.rb +18 -0
- data/lib/nfe_reader/product/importation.rb +49 -0
- data/lib/nfe_reader/product/medicament.rb +19 -0
- data/lib/nfe_reader/product/vehicle.rb +117 -0
- data/lib/nfe_reader/product.rb +90 -0
- data/lib/nfe_reader/provider.rb +43 -0
- data/lib/nfe_reader/purchase.rb +14 -0
- data/lib/nfe_reader/removal.rb +20 -0
- data/lib/nfe_reader/taxation/cofins.rb +43 -0
- data/lib/nfe_reader/taxation/cofins_st.rb +19 -0
- data/lib/nfe_reader/taxation/icms.rb +86 -0
- data/lib/nfe_reader/taxation/importation_tax.rb +17 -0
- data/lib/nfe_reader/taxation/ipi.rb +41 -0
- data/lib/nfe_reader/taxation/issqn.rb +22 -0
- data/lib/nfe_reader/taxation/pis.rb +42 -0
- data/lib/nfe_reader/taxation/pis_st.rb +19 -0
- data/lib/nfe_reader/total.rb +76 -0
- data/lib/nfe_reader/transport.rb +97 -0
- data/lib/nfe_reader/version.rb +5 -0
- data/lib/nfe_reader.rb +129 -0
- data/lib/nokogiri_hash.rb +60 -0
- data/nfe-reader.gemspec +24 -0
- data/test/files/sample-nfe.xml +234 -0
- data/test/files/sample2-nfe.xml +192 -0
- data/test/nfe_reader/authorization_test.rb +22 -0
- data/test/nfe_reader/cane_test.rb +71 -0
- data/test/nfe_reader/carrier_test.rb +46 -0
- data/test/nfe_reader/collection/duplicate_test.rb +27 -0
- data/test/nfe_reader/collection_test.rb +78 -0
- data/test/nfe_reader/customer_test.rb +133 -0
- data/test/nfe_reader/delivery_test.rb +57 -0
- data/test/nfe_reader/document_test.rb +113 -0
- data/test/nfe_reader/export_test.rb +22 -0
- data/test/nfe_reader/fiscal_test.rb +67 -0
- data/test/nfe_reader/header_test.rb +135 -0
- data/test/nfe_reader/information_test.rb +37 -0
- data/test/nfe_reader/product/armament_test.rb +32 -0
- data/test/nfe_reader/product/exportation_test.rb +34 -0
- data/test/nfe_reader/product/fuel_test.rb +44 -0
- data/test/nfe_reader/product/importation_test.rb +64 -0
- data/test/nfe_reader/product/medicament_test.rb +37 -0
- data/test/nfe_reader/product/vehicle_test.rb +133 -0
- data/test/nfe_reader/product_test.rb +125 -0
- data/test/nfe_reader/provider_test.rb +155 -0
- data/test/nfe_reader/purchase_test.rb +27 -0
- data/test/nfe_reader/removal_test.rb +57 -0
- data/test/nfe_reader/taxation/cofins_st_test.rb +37 -0
- data/test/nfe_reader/taxation/cofins_test.rb +42 -0
- data/test/nfe_reader/taxation/icms_test.rb +122 -0
- data/test/nfe_reader/taxation/importation_tax_test.rb +32 -0
- data/test/nfe_reader/taxation/ipi_test.rb +78 -0
- data/test/nfe_reader/taxation/issqn_test.rb +42 -0
- data/test/nfe_reader/taxation/pis_st_test.rb +37 -0
- data/test/nfe_reader/taxation/pis_test.rb +42 -0
- data/test/nfe_reader/total_test.rb +148 -0
- data/test/nfe_reader/transport_test.rb +172 -0
- data/test/nfe_reader_test.rb +125 -0
- data/test/nokogiri_test.rb +27 -0
- data/test/test_helper.rb +13 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9577a7166d1dfbba0ad7b57254dd3eb94cfccd4
|
4
|
+
data.tar.gz: 6a2d44a5c5a7cbcbdd500d6641d53bfe0f19dee1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62c5560f41f0a6b05e52b5f742b4a0c5398ebb943ec4ac50f6eca6b88e1c5c9d593c20dbf216ec0101f45c1bc2ff54ef433c8ffb312860e6d7e0cb13735a564a
|
7
|
+
data.tar.gz: a18eaccdafd49ffd652bba05c0fdc50d57ed98aaa218441b9545794317d575b5402286be2e447fc9f3db4cc230531136fcd8b1d516158e742dac071663a4a900
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
runner.rb
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Eduardo Becker
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
## Nfe::Reader ##
|
2
|
+
|
3
|
+
Gem to open Brazilian NF-e XML and convert to Ruby classes.
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nfe-reader'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nfe-reader
|
18
|
+
|
19
|
+
### Dependencies
|
20
|
+
|
21
|
+
* nokogiri
|
22
|
+
|
23
|
+
### Usage
|
24
|
+
|
25
|
+
Open the xml file and import to Nfe::Reader:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
file = File.open('sample-nfe.xml')
|
29
|
+
nfe = Nfe::Reader::Base.new(file)
|
30
|
+
```
|
31
|
+
|
32
|
+
### Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/[my-github-username]/nfe-reader/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc 'Default: run unit tests.'
|
5
|
+
task default: :test
|
6
|
+
|
7
|
+
desc 'Run the tests.'
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.libs << 'test'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
class Carrier
|
4
|
+
attr_reader :cnpj, :cpf, :name, :ie, :address, :city, :state
|
5
|
+
|
6
|
+
def initialize(attrs = {})
|
7
|
+
@cnpj = attrs[:CNPJ]
|
8
|
+
@cpf = attrs[:CPF]
|
9
|
+
@name = attrs[:xNome]
|
10
|
+
@ie = attrs[:IE]
|
11
|
+
@address = attrs[:xEnder]
|
12
|
+
@city = attrs[:xMun]
|
13
|
+
@state = attrs[:UF]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
# Mapeia as Cobrancas
|
4
|
+
class Collection
|
5
|
+
attr_reader :number, :value, :descont, :value_net, :duplicates
|
6
|
+
|
7
|
+
def initialize(attrs = {})
|
8
|
+
if attrs[:fat]
|
9
|
+
@number = attrs[:fat][:nFat]
|
10
|
+
@value = attrs[:fat][:vOrig]
|
11
|
+
@descont = attrs[:fat][:vDesc]
|
12
|
+
@value_net = attrs[:fat][:vLiq]
|
13
|
+
end
|
14
|
+
|
15
|
+
@duplicates = set_duplicates(attrs[:dup])
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_duplicates(attrs = {})
|
19
|
+
duplicates = []
|
20
|
+
|
21
|
+
return duplicates unless attrs
|
22
|
+
|
23
|
+
if attrs.is_a? Array
|
24
|
+
attrs.each do |d|
|
25
|
+
duplicates << Nfe::Duplicate.new(d)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
duplicates << Nfe::Duplicate.new(attrs)
|
29
|
+
end
|
30
|
+
|
31
|
+
duplicates
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
# Identificação do Destinatário da Nota Fiscal eletrônica
|
4
|
+
class Customer
|
5
|
+
attr_reader :cnpj, :cpf, :name, :state_registration, :email,
|
6
|
+
:suframa, :phone, :address, :number, :neighborhood, :city_code,
|
7
|
+
:city, :state, :country_code, :country, :complement, :foreign_code,
|
8
|
+
:cep, :city_registration, :state_registration_code
|
9
|
+
|
10
|
+
# == Fields Values
|
11
|
+
#
|
12
|
+
# indIEDest: 1 - Contribuinte ICMS (informar a IE do destinatário),
|
13
|
+
# 2 - Contribuinte isento de Inscrição no cadastro de Contribuintes do ICMS,
|
14
|
+
# 9 - Não Contribuinte, que pode ou não possuir Inscrição Estadual
|
15
|
+
|
16
|
+
def initialize(attrs = {})
|
17
|
+
@cnpj = attrs[:CNPJ]
|
18
|
+
@cpf = attrs[:CPF]
|
19
|
+
|
20
|
+
# Razão Social ou nome do destinatário
|
21
|
+
@name = attrs[:xNome]
|
22
|
+
# Inscrição Estadual do Destinatário
|
23
|
+
@state_registration = attrs[:IE]
|
24
|
+
# Inscrição na SUFRAMA
|
25
|
+
@suframa = attrs[:ISUF]
|
26
|
+
# Inscrição Municipal do Tomador do Serviço
|
27
|
+
@city_registration = attrs[:IM]
|
28
|
+
# Indicador da IE do Destinatário
|
29
|
+
@state_registration_code = attrs[:indIEDest]
|
30
|
+
# Email
|
31
|
+
@email = attrs[:email]
|
32
|
+
# Identificação do destinatário no caso de comprador estrangeiro
|
33
|
+
@foreign_code = attrs[:idEstrangeiro]
|
34
|
+
|
35
|
+
# Address
|
36
|
+
if attrs[:enderDest]
|
37
|
+
# Logradouro
|
38
|
+
@address = attrs[:enderDest][:xLgr]
|
39
|
+
# Numero
|
40
|
+
@number = attrs[:enderDest][:nro]
|
41
|
+
# Complemento
|
42
|
+
@complement = attrs[:enderDest][:xCpl]
|
43
|
+
# Bairro
|
44
|
+
@neighborhood = attrs[:enderDest][:xBairro]
|
45
|
+
# Código do município
|
46
|
+
@city_code = attrs[:enderDest][:cMun]
|
47
|
+
# Nome do município
|
48
|
+
@city = attrs[:enderDest][:xMun]
|
49
|
+
# Sigla da UF
|
50
|
+
@state = attrs[:enderDest][:UF]
|
51
|
+
# Código do CEP
|
52
|
+
@zip_code = attrs[:enderDest][:CEP]
|
53
|
+
# Codigo Pais
|
54
|
+
@country_code = attrs[:enderDest][:cPais]
|
55
|
+
# Nome do Pais
|
56
|
+
@country = attrs[:enderDest][:xPais]
|
57
|
+
# Telefone
|
58
|
+
@phone = attrs[:enderDest][:fone]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Local de Entrega
|
2
|
+
module Nfe
|
3
|
+
# Identificação do Local de Entrega
|
4
|
+
class Delivery
|
5
|
+
attr_reader :cnpj, :cpf, :address, :number, :complement,
|
6
|
+
:neighborhood, :city_code, :city, :state
|
7
|
+
|
8
|
+
def initialize(attrs = {})
|
9
|
+
@cnpj = attrs[:CNPJ]
|
10
|
+
@cpf = attrs[:CPF]
|
11
|
+
@address = attrs[:xLgr]
|
12
|
+
@number = attrs[:nro]
|
13
|
+
@complement = attrs[:xCpl]
|
14
|
+
@neighborhood = attrs[:xBairro]
|
15
|
+
@city_code = attrs[:cMun]
|
16
|
+
@city = attrs[:xMun]
|
17
|
+
@state = attrs[:UF]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
# Documento Fiscal Referenciado
|
4
|
+
class Document
|
5
|
+
attr_reader :key, :nfe_state, :nfe_year, :nfe_cnpj, :nfe_model,
|
6
|
+
:nfe_serie, :nfe_number, :farmer_state, :farmer_year, :farmer_cnpj,
|
7
|
+
:farmer_cpf, :farmer_ie, :farmer_model, :farmer_serie, :farmer_number,
|
8
|
+
:cte_key, :ecf_model, :ecf_number, :ecf_operation
|
9
|
+
|
10
|
+
# == Fields Values
|
11
|
+
# mod:
|
12
|
+
# refNF: 01 - modelo 01
|
13
|
+
# refNFP: 04 - NF de Produtor,
|
14
|
+
# 01 - NF (v2.0)
|
15
|
+
# refECF: 2B - Cupom Fiscal emitido por máquina registradora (não ECF),
|
16
|
+
# 2C - Cupom Fiscal PDV,
|
17
|
+
# 2D - Cupom Fiscal (emitido por ECF) (v2.0)
|
18
|
+
|
19
|
+
def initialize(attrs = {})
|
20
|
+
# Chave da NF-e
|
21
|
+
@key = attrs[:refNFe]
|
22
|
+
|
23
|
+
# Referencia uma NF-e
|
24
|
+
if attrs[:refNF]
|
25
|
+
# Estado
|
26
|
+
@nfe_state = attrs[:refNF][:cUF]
|
27
|
+
# Ano e mes
|
28
|
+
@nfe_year = attrs[:refNF][:AAMM]
|
29
|
+
# CNPJ do emitente
|
30
|
+
@nfe_cnpj = attrs[:refNF][:CNPJ]
|
31
|
+
# Modelo do Documento Fiscal
|
32
|
+
@nfe_model = attrs[:refNF][:mod]
|
33
|
+
# Serie Documento Fiscal
|
34
|
+
@nfe_serie = attrs[:refNF][:serie]
|
35
|
+
# Numero Documento Fiscal
|
36
|
+
@nfe_number = attrs[:refNF][:nNF]
|
37
|
+
end
|
38
|
+
|
39
|
+
# NF de Produtor Rural
|
40
|
+
if attrs[:refNFP]
|
41
|
+
# Estado
|
42
|
+
@farmer_state = attrs[:refNFP][:cUF]
|
43
|
+
# Ano e mes
|
44
|
+
@farmer_year = attrs[:refNFP][:AAMM]
|
45
|
+
# CNPJ do emitente
|
46
|
+
@farmer_cnpj = attrs[:refNFP][:CNPJ]
|
47
|
+
# CPF do emitente
|
48
|
+
@farmer_cpf = attrs[:refNFP][:CPF]
|
49
|
+
# IE do emitente
|
50
|
+
@farmer_ie = attrs[:refNFP][:IE]
|
51
|
+
# Modelo do Documento Fiscal
|
52
|
+
@farmer_model = attrs[:refNFP][:mod]
|
53
|
+
# Serie Documento Fiscal
|
54
|
+
@farmer_serie = attrs[:refNFP][:serie]
|
55
|
+
# Numero Documento Fiscal
|
56
|
+
@farmer_number = attrs[:refNFP][:nNF]
|
57
|
+
end
|
58
|
+
|
59
|
+
# CT-e
|
60
|
+
@cte_key = attrs[:refCTe]
|
61
|
+
|
62
|
+
# Referencia uma ECF
|
63
|
+
if attrs[:refECF]
|
64
|
+
# Modelo do Documento Fiscal
|
65
|
+
@ecf_model = attrs[:refECF][:mod]
|
66
|
+
# Número de ordem sequencial do ECF
|
67
|
+
@ecf_number = attrs[:refECF][:nECF]
|
68
|
+
# Número do Contador de Ordem de Operação
|
69
|
+
@ecf_operation = attrs[:refECF][:nCOO]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
# Identificação do Fisco Emitente da NF-e
|
4
|
+
class Fiscal
|
5
|
+
attr_reader :cnpj, :agency, :code, :name, :paid_date,
|
6
|
+
:phone, :state, :number, :date, :value, :repartition
|
7
|
+
|
8
|
+
def initialize(attrs = {})
|
9
|
+
# CNPJ emitente
|
10
|
+
@cnpj = attrs[:CNPJ]
|
11
|
+
# Órgão emitente
|
12
|
+
@agency = attrs[:xOrgao]
|
13
|
+
# Matrícula do agente do Fisco
|
14
|
+
@code = attrs[:matr]
|
15
|
+
# Nome do agente do Fisco
|
16
|
+
@name = attrs[:xAgente]
|
17
|
+
# Telefone do agente do Fisco
|
18
|
+
@phone = attrs[:fone]
|
19
|
+
# Estado
|
20
|
+
@state = attrs[:UF]
|
21
|
+
# Número do DAR(Documento de Arrecadação de Receita)
|
22
|
+
@number = attrs[:nDAR]
|
23
|
+
# Data
|
24
|
+
@date = attrs[:dEmi]
|
25
|
+
# Valor do DAR
|
26
|
+
@value = attrs[:vDAR]
|
27
|
+
# Repartição Fiscal emitente
|
28
|
+
@repartition = attrs[:repEmi]
|
29
|
+
# Data do Pagamento
|
30
|
+
@paid_date = attrs[:dPag]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
# Identificação da Nota Fiscal eletrônica
|
4
|
+
class Header
|
5
|
+
attr_reader :state, :city, :sample_number, :operation, :number,
|
6
|
+
:model, :emission, :emission_kind, :out, :out_time, :serie, :kind,
|
7
|
+
:environment, :finality, :version, :payment, :process, :digit,
|
8
|
+
:orientation, :emission_date, :destiny_code, :final_consumer,
|
9
|
+
:consumer_presence, :contingency_date, :contingency_justification,
|
10
|
+
:documents
|
11
|
+
|
12
|
+
# == Fields Values
|
13
|
+
#
|
14
|
+
# cUF: 11-Rondônia, 12-Acre, 13-Amazonas, 14-Roraima, 15-Pará, 16-Amapá, 17-Tocantins,
|
15
|
+
# 21-Maranhão, 22-Piauí, 23-Ceará, 24-Rio Grande do Norte, 25-Paraíba, 26-Pernambuco,
|
16
|
+
# 27-Alagoas, 28-Sergipe, 29-Bahia, 31-Minas Gerais, 32-Espírito Santo, 33-Rio de Janeiro,
|
17
|
+
# 35-São Paulo, 41-Paraná, 42-Santa Catarina, 3-Rio Grande do Sul, 50-Mato Grosso do Sul,
|
18
|
+
# 51-Mato Grosso, 52-Goiás, 53-DistritoFederal
|
19
|
+
#
|
20
|
+
# mod: 55 - NF-e, 65 - NFC-e
|
21
|
+
#
|
22
|
+
# indPag: 0 - Vista, 1 - Prazo, 2 - Outros
|
23
|
+
#
|
24
|
+
# tpNF: 0 - Entrada, 1 - Saida
|
25
|
+
#
|
26
|
+
# tpAmb: 1 - Producao, 2 - Homologacao
|
27
|
+
#
|
28
|
+
# finNFe: 1 - Normal,
|
29
|
+
# 2 - Complementar,
|
30
|
+
# 3 - Ajuste,
|
31
|
+
# 4 - Devolução/Retorno.
|
32
|
+
#
|
33
|
+
# tpEmis: 1 - Normal, 2 - Contingência FS, 3 - Contingência SCAN, 4 - Contingência FS-DA
|
34
|
+
#
|
35
|
+
# tpImp: 1 - Retrato,
|
36
|
+
# 2 - Paisagem,
|
37
|
+
# 3 - DANFE Simplificado,
|
38
|
+
# 4 - DANFE NFC-e,
|
39
|
+
# 5 - DANFE NFC-e em mensagem eletrônica (o envio de
|
40
|
+
# mensagem eletrônica pode ser feita de forma simultânea
|
41
|
+
# com a impressão do DANFE; usar o tpImp=5 quando
|
42
|
+
# esta for a única forma de disponibilização do DANFE).
|
43
|
+
#
|
44
|
+
# procEmit: 0 - emissão de NF-e com aplicativo do contribuinte,
|
45
|
+
# 1 - emissão de NF-e avulsa pelo Fisco,
|
46
|
+
# 2 - emissão de NF-e avulsa, pelo site,
|
47
|
+
# 3 - emissão NF-e pelo contribuinte com aplicativo fornecido pelo Fisco,
|
48
|
+
#
|
49
|
+
# idDest: 1 - Operação interna,
|
50
|
+
# 2 - Operação interestadual,
|
51
|
+
# 3 - Operação com exterior
|
52
|
+
#
|
53
|
+
# indFinal: 0 - Não,
|
54
|
+
# 1 - Consumidor final
|
55
|
+
#
|
56
|
+
# indPres: 0 - Não se aplica (por exemplo, Nota Fiscal complementar
|
57
|
+
# ou de ajuste);
|
58
|
+
# 1 - Operação presencial;
|
59
|
+
# 2 - Operação não presencial, pela Internet;
|
60
|
+
# 3 - Operação não presencial, Teleatendimento;
|
61
|
+
# 4 - NFC-e em operação com entrega a domicílio;
|
62
|
+
# 9 - Operação não presencial, outros.
|
63
|
+
|
64
|
+
def initialize(attrs = {})
|
65
|
+
# Estado
|
66
|
+
@state = attrs[:cUF]
|
67
|
+
# Cidade
|
68
|
+
@city = attrs[:cMunFG]
|
69
|
+
# Numero Aleatorio
|
70
|
+
@sample_number = attrs[:cNF]
|
71
|
+
# Natureza Operacao
|
72
|
+
@operation = attrs[:natOp]
|
73
|
+
# Numero da Nota
|
74
|
+
@number = attrs[:nNF]
|
75
|
+
# Modelo
|
76
|
+
@model = attrs[:mod]
|
77
|
+
# Data Emissao
|
78
|
+
@emission = attrs[:dEmi]
|
79
|
+
# Tipo de Emissao
|
80
|
+
@emission_kind = attrs[:tpEmis]
|
81
|
+
# Data de Saida
|
82
|
+
@out = attrs[:dSaiEnt]
|
83
|
+
# Hora de Saida
|
84
|
+
@out_time = attrs[:hSaiEnt]
|
85
|
+
# Data de Emissao
|
86
|
+
@emission_date = attrs[:dhEmi]
|
87
|
+
# Serie
|
88
|
+
@serie = attrs[:serie]
|
89
|
+
# Tipo da Nota
|
90
|
+
@kind = attrs[:tpNF]
|
91
|
+
# Ambiente
|
92
|
+
@environment = attrs[:tpAmb]
|
93
|
+
# Finalidade
|
94
|
+
@finality = attrs[:finNFe]
|
95
|
+
# Versao aplicativo do emissor
|
96
|
+
@version = attrs[:verProc]
|
97
|
+
# Pagamento
|
98
|
+
@payment = attrs[:indPag]
|
99
|
+
# Processo de Emissao
|
100
|
+
@process = attrs[:procEmi]
|
101
|
+
# Digito Verificador
|
102
|
+
@digit = attrs[:cDV]
|
103
|
+
# Orientação da Pagina
|
104
|
+
@orientation = attrs[:tpImp]
|
105
|
+
# Codigo do Destino
|
106
|
+
@destiny_code = attrs[:idDest]
|
107
|
+
# Consumidor final
|
108
|
+
@final_consumer = attrs[:indFinal]
|
109
|
+
# Indicador de presença do comprador
|
110
|
+
@consumer_presence = attrs[:indPres]
|
111
|
+
|
112
|
+
# Contigencia
|
113
|
+
@contingency_date = attrs[:dhCont]
|
114
|
+
@contingency_justification = attrs[:xJust]
|
115
|
+
|
116
|
+
# Documento Fiscal Referenciado
|
117
|
+
@documents = []
|
118
|
+
|
119
|
+
if attrs[:NFref].is_a? Array
|
120
|
+
attrs[:NFref].each do |document|
|
121
|
+
@documents << Nfe::Document.new(document)
|
122
|
+
end
|
123
|
+
elsif attrs[:NFref].is_a? Hash
|
124
|
+
@documents << Nfe::Document.new(attrs[:NFref])
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
class Information
|
4
|
+
attr_reader :information, :information_taxpayer, :taxpayer_messages, :messages,
|
5
|
+
:references
|
6
|
+
|
7
|
+
def initialize(attrs = {})
|
8
|
+
@information = attrs[:infAdFisco]
|
9
|
+
@information_taxpayer = attrs[:infCpl]
|
10
|
+
|
11
|
+
if attrs[:procRef]
|
12
|
+
@references = to_array(attrs[:procRef])
|
13
|
+
end
|
14
|
+
|
15
|
+
if attrs[:obsCont]
|
16
|
+
@taxpayer_messages = to_array(attrs[:obsCont])
|
17
|
+
end
|
18
|
+
|
19
|
+
if attrs[:obsFisco]
|
20
|
+
@messages = to_array(attrs[:obsFisco])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_array(attrs = {})
|
25
|
+
array = []
|
26
|
+
|
27
|
+
if attrs.is_a? Array
|
28
|
+
attrs.each do |hash|
|
29
|
+
array << hash.map { |key, value| value }
|
30
|
+
end
|
31
|
+
else
|
32
|
+
array << attrs.map { |key, value| value }
|
33
|
+
end
|
34
|
+
|
35
|
+
array
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
class Armament
|
4
|
+
attr_reader :kind, :serie, :barrel, :description
|
5
|
+
|
6
|
+
# Fields Values
|
7
|
+
#
|
8
|
+
# tpArma : 0 - Uso permitido;
|
9
|
+
# 1 - Uso restrito;
|
10
|
+
#
|
11
|
+
def initialize(attrs = {})
|
12
|
+
# Tipo de Arma
|
13
|
+
@kind = attrs[:tpArma]
|
14
|
+
# Serie
|
15
|
+
@serie = attrs[:nSerie]
|
16
|
+
# Cano
|
17
|
+
@barrel = attrs[:nCano]
|
18
|
+
# Descricao
|
19
|
+
@description = attrs[:descr]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Nfe
|
2
|
+
class Cane
|
3
|
+
attr_reader :harvest, :month, :month_amount, :previous_amount, :amount,
|
4
|
+
:value, :deduction_value, :net_value, :days, :deductions
|
5
|
+
|
6
|
+
def initialize(attrs = {})
|
7
|
+
@harvest = attrs[:safra]
|
8
|
+
@month = attrs[:ref]
|
9
|
+
@month_amount = attrs[:qTotMes]
|
10
|
+
@previous_amount = attrs[:qTotAnt]
|
11
|
+
@amount = attrs[:qTotGer]
|
12
|
+
@value = attrs[:vFor]
|
13
|
+
@deduction_value = attrs[:vTotDed]
|
14
|
+
@net_value = attrs[:vLiqFor]
|
15
|
+
|
16
|
+
@days = []
|
17
|
+
|
18
|
+
if attrs[:forDia]
|
19
|
+
@days = to_array(attrs[:forDia])
|
20
|
+
end
|
21
|
+
|
22
|
+
if attrs[:deduc]
|
23
|
+
@deductions = to_array(attrs[:deduc])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_array(attrs = {})
|
28
|
+
array = []
|
29
|
+
|
30
|
+
if attrs.is_a? Array
|
31
|
+
attrs.each do |hash|
|
32
|
+
array << hash.map { |key, value| value }
|
33
|
+
end
|
34
|
+
else
|
35
|
+
array << attrs.map { |key, value| value }
|
36
|
+
end
|
37
|
+
|
38
|
+
array
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
class Exportation
|
4
|
+
attr_reader :drawnback, :number, :key, :amount
|
5
|
+
|
6
|
+
def initialize(attrs = {})
|
7
|
+
# Número do ato concessório de Drawback
|
8
|
+
@drawnback = attrs[:nDraw]
|
9
|
+
|
10
|
+
if attrs[:exportInd]
|
11
|
+
# Número do Registro de Exportação
|
12
|
+
@number = attrs[:exportInd][:nRE]
|
13
|
+
# Chave de Acesso da NF-e recebida para exportação
|
14
|
+
@key = attrs[:exportInd][:chNFe]
|
15
|
+
# Quantidade do item realmente exportado
|
16
|
+
@amount= attrs[:exportInd][:qExport]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Nfe
|
3
|
+
class Fuel
|
4
|
+
attr_reader :anp, :codif, :amount, :cide_base, :cide_aliquot, :cide_value
|
5
|
+
|
6
|
+
def initialize(attrs = {})
|
7
|
+
@anp = attrs[:cProdANP]
|
8
|
+
@codif = attrs[:CODIF]
|
9
|
+
@amount = attrs[:qTemp]
|
10
|
+
|
11
|
+
if attrs[:CIDE]
|
12
|
+
@cide_base = attrs[:CIDE][:qBCprod]
|
13
|
+
@cide_aliquot = attrs[:CIDE][:vAliqProd]
|
14
|
+
@cide_value = attrs[:CIDE][:vCIDE]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|