nfe_reader 1.0.4 → 1.0.5
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.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/helpers/attribute_helper.rb +18 -0
- data/lib/helpers/creator_helper.rb +32 -0
- data/lib/nfe_reader/authorization.rb +10 -6
- data/lib/nfe_reader/carrier.rb +14 -10
- data/lib/nfe_reader/collection/duplicate.rb +10 -6
- data/lib/nfe_reader/collection.rb +28 -24
- data/lib/nfe_reader/customer.rb +56 -52
- data/lib/nfe_reader/delivery.rb +18 -14
- data/lib/nfe_reader/document.rb +65 -61
- data/lib/nfe_reader/export.rb +9 -5
- data/lib/nfe_reader/fiscal.rb +31 -27
- data/lib/nfe_reader/header.rb +120 -117
- data/lib/nfe_reader/information.rb +17 -26
- data/lib/nfe_reader/nfe.rb +130 -0
- data/lib/nfe_reader/product/armament.rb +20 -16
- data/lib/nfe_reader/product/cane.rb +22 -32
- data/lib/nfe_reader/product/exportation.rb +17 -13
- data/lib/nfe_reader/product/fuel.rb +15 -11
- data/lib/nfe_reader/product/importation.rb +44 -40
- data/lib/nfe_reader/product/medicament.rb +17 -13
- data/lib/nfe_reader/product/vehicle.rb +115 -111
- data/lib/nfe_reader/product.rb +67 -76
- data/lib/nfe_reader/provider.rb +39 -35
- data/lib/nfe_reader/purchase.rb +10 -6
- data/lib/nfe_reader/removal.rb +18 -14
- data/lib/nfe_reader/taxation/cofins.rb +41 -37
- data/lib/nfe_reader/taxation/cofins_st.rb +17 -13
- data/lib/nfe_reader/taxation/icms.rb +80 -76
- data/lib/nfe_reader/taxation/importation_tax.rb +16 -12
- data/lib/nfe_reader/taxation/ipi.rb +37 -33
- data/lib/nfe_reader/taxation/issqn.rb +19 -15
- data/lib/nfe_reader/taxation/pis.rb +41 -37
- data/lib/nfe_reader/taxation/pis_st.rb +18 -14
- data/lib/nfe_reader/total.rb +71 -67
- data/lib/nfe_reader/transport.rb +87 -83
- data/lib/nfe_reader/version.rb +1 -1
- data/lib/nfe_reader.rb +3 -130
- data/test/helpers/attributte_helper_test.rb +19 -0
- data/test/helpers/creator_helper_test.rb +28 -0
- data/test/{nokogiri_test.rb → helpers/nokogiri_test.rb} +1 -1
- data/test/nfe_reader/authorization_test.rb +2 -2
- data/test/nfe_reader/cane_test.rb +2 -2
- data/test/nfe_reader/carrier_test.rb +2 -2
- data/test/nfe_reader/collection/duplicate_test.rb +2 -2
- data/test/nfe_reader/collection_test.rb +3 -3
- data/test/nfe_reader/customer_test.rb +3 -3
- 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/nfe_reader/information_test.rb +2 -2
- data/test/{nfe_reader_test.rb → nfe_reader/nfe_test.rb} +15 -15
- 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 +27 -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 +6 -6
- data/test/nfe_reader/provider_test.rb +3 -3
- 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 +14 -7
- /data/lib/{nokogiri_hash.rb → helpers/nokogiri_hash.rb} +0 -0
data/lib/nfe_reader/total.rb
CHANGED
@@ -1,75 +1,79 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Nfe
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
:service_value, :service_base, :service_iss, :service_pis, :service_cofins,
|
7
|
-
:retention_pis, :retention_csll, :retention_irrf_base, :retention_cofins,
|
8
|
-
:retention_irrf, :retention_foresight_base, :retention_foresight
|
3
|
+
module Reader
|
4
|
+
class Total
|
5
|
+
include ::AttributeHelper
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# Valor ICMS
|
16
|
-
@icms = attrs[:ICMSTot][:vICMS]
|
17
|
-
# Base ICMS ST
|
18
|
-
@st_base = attrs[:ICMSTot][:vBCST]
|
19
|
-
# Valor ICMS ST
|
20
|
-
@st = attrs[:ICMSTot][:vST]
|
21
|
-
# Total de Produtos
|
22
|
-
@product = attrs[:ICMSTot][:vProd]
|
23
|
-
# Total de Frete
|
24
|
-
@freight = attrs[:ICMSTot][:vFrete]
|
25
|
-
# Total de Seguro
|
26
|
-
@insurance = attrs[:ICMSTot][:vSeg]
|
27
|
-
# Total de Desconto
|
28
|
-
@descount = attrs[:ICMSTot][:vDesc]
|
29
|
-
# Total de Imposto de Importacao
|
30
|
-
@ii = attrs[:ICMSTot][:vII]
|
31
|
-
# Total de IPI
|
32
|
-
@ipi = attrs[:ICMSTot][:vIPI]
|
33
|
-
# Total de PIS
|
34
|
-
@pis = attrs[:ICMSTot][:vPIS]
|
35
|
-
# Total de COFINS
|
36
|
-
@cofins = attrs[:ICMSTot][:vCOFINS]
|
37
|
-
# Total de Outros
|
38
|
-
@another = attrs[:ICMSTot][:vOutro]
|
39
|
-
# Total NFe
|
40
|
-
@total = attrs[:ICMSTot][:vNF]
|
41
|
-
end
|
7
|
+
attr_reader :icms_base, :icms, :st_base, :st, :product, :freight,
|
8
|
+
:insurance, :descount, :ii, :ipi, :pis, :cofins, :another, :total,
|
9
|
+
:service_value, :service_base, :service_iss, :service_pis, :service_cofins,
|
10
|
+
:retention_pis, :retention_csll, :retention_irrf_base, :retention_cofins,
|
11
|
+
:retention_irrf, :retention_foresight_base, :retention_foresight
|
42
12
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
13
|
+
def initialize(attrs = {})
|
14
|
+
# Impostos
|
15
|
+
if attrs[:ICMSTot]
|
16
|
+
# Base ICMS
|
17
|
+
@icms_base = attrs[:ICMSTot][:vBC]
|
18
|
+
# Valor ICMS
|
19
|
+
@icms = attrs[:ICMSTot][:vICMS]
|
20
|
+
# Base ICMS ST
|
21
|
+
@st_base = attrs[:ICMSTot][:vBCST]
|
22
|
+
# Valor ICMS ST
|
23
|
+
@st = attrs[:ICMSTot][:vST]
|
24
|
+
# Total de Produtos
|
25
|
+
@product = attrs[:ICMSTot][:vProd]
|
26
|
+
# Total de Frete
|
27
|
+
@freight = attrs[:ICMSTot][:vFrete]
|
28
|
+
# Total de Seguro
|
29
|
+
@insurance = attrs[:ICMSTot][:vSeg]
|
30
|
+
# Total de Desconto
|
31
|
+
@descount = attrs[:ICMSTot][:vDesc]
|
32
|
+
# Total de Imposto de Importacao
|
33
|
+
@ii = attrs[:ICMSTot][:vII]
|
34
|
+
# Total de IPI
|
35
|
+
@ipi = attrs[:ICMSTot][:vIPI]
|
36
|
+
# Total de PIS
|
37
|
+
@pis = attrs[:ICMSTot][:vPIS]
|
38
|
+
# Total de COFINS
|
39
|
+
@cofins = attrs[:ICMSTot][:vCOFINS]
|
40
|
+
# Total de Outros
|
41
|
+
@another = attrs[:ICMSTot][:vOutro]
|
42
|
+
# Total NFe
|
43
|
+
@total = attrs[:ICMSTot][:vNF]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Servicos
|
47
|
+
if attrs[:ISSQNtot]
|
48
|
+
# Valor do Servico
|
49
|
+
@service_value = attrs[:ISSQNtot][:vServ]
|
50
|
+
# Base de calculo do Servico
|
51
|
+
@service_base = attrs[:ISSQNtot][:vBC]
|
52
|
+
# ISS do Servico
|
53
|
+
@service_iss = attrs[:ISSQNtot][:vISS]
|
54
|
+
# Pis do Servico
|
55
|
+
@service_pis = attrs[:ISSQNtot][:vPIS]
|
56
|
+
# Cofins do Servico
|
57
|
+
@service_cofins = attrs[:ISSQNtot][:vCOFINS]
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
# Retencoes
|
61
|
+
if attrs[:retTrib]
|
62
|
+
# Retencao de PIS
|
63
|
+
@retention_pis = attrs[:retTrib][:vRetPIS]
|
64
|
+
# Retencao de COFINS
|
65
|
+
@retention_cofins = attrs[:retTrib][:vRetCOFINS]
|
66
|
+
# Retencao de CSLL
|
67
|
+
@retention_csll = attrs[:retTrib][:vRetCSLL]
|
68
|
+
# Base de Retencao do IRRF
|
69
|
+
@retention_irrf_base = attrs[:retTrib][:vBCIRRF]
|
70
|
+
# Valor de Retencao do IRRF
|
71
|
+
@retention_irrf = attrs[:retTrib][:vIRRF]
|
72
|
+
# Base de Retencao da Previdencia
|
73
|
+
@retention_foresight_base = attrs[:retTrib][:vBCRetPrev]
|
74
|
+
# Valor de Retencao da Previdencia
|
75
|
+
@retention_foresight = attrs[:retTrib][:vRetPrev]
|
76
|
+
end
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
data/lib/nfe_reader/transport.rb
CHANGED
@@ -1,97 +1,101 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Nfe
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
:hauling_state, :hauling_rntc, :wagon, :ferry, :volume_amount, :volume_kind,
|
7
|
-
:volume_brand, :volume_number, :weight_net, :weight_gross, :seals, :carrier
|
3
|
+
module Reader
|
4
|
+
class Transport
|
5
|
+
include ::AttributeHelper
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# 2- Por conta de terceiros;
|
14
|
-
# 9- Sem frete.
|
15
|
-
#
|
16
|
-
def initialize(attrs = {})
|
17
|
-
# Modalidade
|
18
|
-
@kind = attrs[:modFrete]
|
19
|
-
|
20
|
-
# == Grupo de Retenção do ICMS do transporte
|
21
|
-
if attrs[:retTransp]
|
22
|
-
# Valor do Servico
|
23
|
-
@service_value = attrs[:retTransp][:vServ]
|
24
|
-
# BC da Retenção do ICMS
|
25
|
-
@base = attrs[:retTransp][:vBCRet]
|
26
|
-
# Alíquota da Retenção
|
27
|
-
@icms_aliquot = attrs[:retTransp][:pICMSRet]
|
28
|
-
# Valor do ICMS Retido
|
29
|
-
@icms_value = attrs[:retTransp][:vICMSRet]
|
30
|
-
# CFOP
|
31
|
-
@cfop = attrs[:retTransp][:CFOP]
|
32
|
-
# Municipio gerador de ICMS
|
33
|
-
@city = attrs[:retTransp][:cMunFG]
|
34
|
-
end
|
7
|
+
attr_reader :kind, :service_value, :base, :icms_aliquot, :icms_value,
|
8
|
+
:cfop, :city, :vehicle_plaque, :vehicle_state, :vehicle_rntc, :hauling_palque,
|
9
|
+
:hauling_state, :hauling_rntc, :wagon, :ferry, :volume_amount, :volume_kind,
|
10
|
+
:volume_brand, :volume_number, :weight_net, :weight_gross, :seals, :carrier
|
35
11
|
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
12
|
+
# Fields Values:
|
13
|
+
#
|
14
|
+
# modFrete: 0- Por conta do emitente;
|
15
|
+
# 1- Por conta do destinatário/remetente;
|
16
|
+
# 2- Por conta de terceiros;
|
17
|
+
# 9- Sem frete.
|
18
|
+
#
|
19
|
+
def initialize(attrs = {})
|
20
|
+
# Modalidade
|
21
|
+
@kind = attrs[:modFrete]
|
22
|
+
|
23
|
+
# == Grupo de Retenção do ICMS do transporte
|
24
|
+
if attrs[:retTransp]
|
25
|
+
# Valor do Servico
|
26
|
+
@service_value = attrs[:retTransp][:vServ]
|
27
|
+
# BC da Retenção do ICMS
|
28
|
+
@base = attrs[:retTransp][:vBCRet]
|
29
|
+
# Alíquota da Retenção
|
30
|
+
@icms_aliquot = attrs[:retTransp][:pICMSRet]
|
31
|
+
# Valor do ICMS Retido
|
32
|
+
@icms_value = attrs[:retTransp][:vICMSRet]
|
33
|
+
# CFOP
|
34
|
+
@cfop = attrs[:retTransp][:CFOP]
|
35
|
+
# Municipio gerador de ICMS
|
36
|
+
@city = attrs[:retTransp][:cMunFG]
|
37
|
+
end
|
45
38
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
39
|
+
# == Veiculo
|
40
|
+
if attrs[:veicTransp]
|
41
|
+
# Placa
|
42
|
+
@vehicle_plaque = attrs[:veicTransp][:placa]
|
43
|
+
# Estado
|
44
|
+
@vehicle_state = attrs[:veicTransp][:UF]
|
45
|
+
# Registro Nacional de Transportador de Carga
|
46
|
+
@vehicle_rntc = attrs[:veicTransp][:RNTC]
|
47
|
+
end
|
55
48
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
# Espécie dos volumes
|
66
|
-
@volume_kind = attrs[:vol][:esp]
|
67
|
-
# Marca dos volumes
|
68
|
-
@volume_brand = attrs[:vol][:marca]
|
69
|
-
# Numeração dos volumes
|
70
|
-
@volume_number = attrs[:vol][:nVol]
|
71
|
-
# Peso Liquido
|
72
|
-
@weight_net = attrs[:vol][:pesoL]
|
73
|
-
# Peso Bruto
|
74
|
-
@weight_gross = attrs[:vol][:pesoB]
|
75
|
-
# Lacres
|
76
|
-
@seals = set_seals(attrs[:vol][:lacres])
|
77
|
-
end
|
49
|
+
# == Reboque
|
50
|
+
if attrs[:reboque]
|
51
|
+
# Placa
|
52
|
+
@hauling_palque = attrs[:reboque][:placa]
|
53
|
+
# Estado
|
54
|
+
@hauling_state = attrs[:reboque][:UF]
|
55
|
+
# Registro Nacional de Transportador de Carga
|
56
|
+
@hauling_rntc = attrs[:reboque][:RNTC]
|
57
|
+
end
|
78
58
|
|
79
|
-
|
80
|
-
|
81
|
-
|
59
|
+
# Vagao
|
60
|
+
@wagon = attrs[:vagao]
|
61
|
+
# Balsa
|
62
|
+
@ferry = attrs[:balsa]
|
63
|
+
|
64
|
+
# == Volume
|
65
|
+
if attrs[:vol]
|
66
|
+
# Quantidade de volumes
|
67
|
+
@volume_amount = attrs[:vol][:qVol]
|
68
|
+
# Espécie dos volumes
|
69
|
+
@volume_kind = attrs[:vol][:esp]
|
70
|
+
# Marca dos volumes
|
71
|
+
@volume_brand = attrs[:vol][:marca]
|
72
|
+
# Numeração dos volumes
|
73
|
+
@volume_number = attrs[:vol][:nVol]
|
74
|
+
# Peso Liquido
|
75
|
+
@weight_net = attrs[:vol][:pesoL]
|
76
|
+
# Peso Bruto
|
77
|
+
@weight_gross = attrs[:vol][:pesoB]
|
78
|
+
# Lacres
|
79
|
+
@seals = set_seals(attrs[:vol][:lacres])
|
80
|
+
end
|
81
|
+
|
82
|
+
# Transportadora
|
83
|
+
if attrs[:transporta]
|
84
|
+
@carrier = Carrier.new(attrs[:transporta])
|
85
|
+
end
|
82
86
|
end
|
83
|
-
end
|
84
87
|
|
85
|
-
|
86
|
-
|
88
|
+
def set_seals(attrs = {})
|
89
|
+
return unless attrs
|
87
90
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
if attrs.is_a? Array
|
92
|
+
seals = attrs.map { |l| l[:nLacre] }.join(', ')
|
93
|
+
else
|
94
|
+
seals = attrs[:nLacre]
|
95
|
+
end
|
93
96
|
|
94
|
-
|
97
|
+
seals
|
98
|
+
end
|
95
99
|
end
|
96
100
|
end
|
97
101
|
end
|
data/lib/nfe_reader/version.rb
CHANGED
data/lib/nfe_reader.rb
CHANGED
@@ -1,137 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require "nfe_reader/version"
|
3
3
|
require "nokogiri"
|
4
|
-
require "nokogiri_hash"
|
4
|
+
require "helpers/nokogiri_hash"
|
5
|
+
require "helpers/attribute_helper"
|
6
|
+
require "helpers/creator_helper"
|
5
7
|
|
6
8
|
%w(nfe_reader/product nfe_reader/collection nfe_reader/taxation nfe_reader).each do |namespace|
|
7
9
|
Dir[File.dirname(__FILE__) + "/../lib/#{namespace}/*.rb"].each { |file| require file }
|
8
|
-
end
|
9
|
-
|
10
|
-
module Nfe
|
11
|
-
module Reader
|
12
|
-
class Base
|
13
|
-
attr_reader :version, :number, :signature, :client, :information,
|
14
|
-
:header, :provider, :customer, :products, :collection, :transport,
|
15
|
-
:purchase, :cane, :export, :delivery, :removal,:enviroment,
|
16
|
-
:version_app, :key, :date, :protocol, :digest, :status, :description,
|
17
|
-
:total, :authorizations, :error, :trace
|
18
|
-
|
19
|
-
def initialize(file)
|
20
|
-
|
21
|
-
xml = file.is_a?(Nokogiri::XML::Document) ? file : Nokogiri::XML(file)
|
22
|
-
xml = xml.to_hash
|
23
|
-
|
24
|
-
# Versao da NFe
|
25
|
-
@version = xml[:nfeProc][:versao]
|
26
|
-
# Assinatura
|
27
|
-
@signature = xml[:nfeProc][:NFe][:Signature]
|
28
|
-
|
29
|
-
# Protocolo
|
30
|
-
if xml[:nfeProc][:protNFe]
|
31
|
-
protocol = xml[:nfeProc][:protNFe][:infProt]
|
32
|
-
|
33
|
-
@enviroment = protocol[:tpAmb]
|
34
|
-
@version_app = protocol[:verAplic]
|
35
|
-
@key = protocol[:chNFe]
|
36
|
-
@date = protocol[:dhRecbto]
|
37
|
-
@protocol = protocol[:nProt]
|
38
|
-
@digest = protocol[:digVal]
|
39
|
-
@status = protocol[:cStat]
|
40
|
-
@description = protocol[:xMotivo]
|
41
|
-
end
|
42
|
-
|
43
|
-
xml = xml[:nfeProc][:NFe][:infNFe]
|
44
|
-
|
45
|
-
# Numero da Nfe
|
46
|
-
@number = xml[:Id]
|
47
|
-
|
48
|
-
# Identificação da Nota Fiscal eletrônica
|
49
|
-
@header = Nfe::Header.new(xml[:ide])
|
50
|
-
|
51
|
-
# Identificação do Emitente da Nota Fiscal eletrônica
|
52
|
-
@provider = Nfe::Provider.new(xml[:emit])
|
53
|
-
|
54
|
-
# Identificação do Fisco Emitente da NF-e
|
55
|
-
if xml[:avulsa]
|
56
|
-
@fiscal = Nfe::Fiscal.new(xml[:avulsa])
|
57
|
-
end
|
58
|
-
|
59
|
-
# Identificação do Destinatário da Nota Fiscal eletrônica
|
60
|
-
@customer = Nfe::Customer.new(xml[:dest])
|
61
|
-
|
62
|
-
# Informacoes Adicional
|
63
|
-
if xml[:infAdic]
|
64
|
-
@information = Nfe::Information.new(xml[:infAdic])
|
65
|
-
end
|
66
|
-
|
67
|
-
# Detalhamento de Produtos e Serviços da NF-e
|
68
|
-
@products = []
|
69
|
-
if xml[:det].is_a? Array
|
70
|
-
xml[:det].each do |product|
|
71
|
-
@products << Nfe::Product.new(product)
|
72
|
-
end
|
73
|
-
else
|
74
|
-
@products << Nfe::Product.new(xml[:det])
|
75
|
-
end
|
76
|
-
|
77
|
-
# Totalizadores
|
78
|
-
@total = Nfe::Total.new(xml[:total])
|
79
|
-
|
80
|
-
# Informacao de Pagamento
|
81
|
-
if xml[:cobr]
|
82
|
-
@collection = Nfe::Collection.new(xml[:cobr])
|
83
|
-
end
|
84
|
-
|
85
|
-
# Transporte
|
86
|
-
if xml[:transp]
|
87
|
-
@transport = Nfe::Transport.new(xml[:transp])
|
88
|
-
end
|
89
|
-
|
90
|
-
# Identificação do Local de Entrega
|
91
|
-
if xml[:retirada]
|
92
|
-
@removal = Nfe::Removal.new(xml[:retirada])
|
93
|
-
end
|
94
|
-
|
95
|
-
# Identificação do Local de Retirada
|
96
|
-
if xml[:entrega]
|
97
|
-
@delivery = Nfe::Delivery.new(xml[:entrega])
|
98
|
-
end
|
99
|
-
|
100
|
-
# Autorização para obter XML
|
101
|
-
@authorizations = []
|
102
|
-
if xml[:autXML].is_a? Array
|
103
|
-
xml[:autXML].each do |product|
|
104
|
-
@authorizations << Nfe::Authorization.new(product)
|
105
|
-
end
|
106
|
-
elsif xml[:autXML].is_a? Hash
|
107
|
-
@authorizations << Nfe::Authorization.new(xml[:autXML])
|
108
|
-
end
|
109
|
-
|
110
|
-
# Informacoes de Comercio Exterior
|
111
|
-
if xml[:exporta]
|
112
|
-
@export = Nfe::Export.new(xml[:exporta])
|
113
|
-
end
|
114
|
-
|
115
|
-
# Informacoes de Compra
|
116
|
-
if xml[:compra]
|
117
|
-
@purchase = Nfe::Purchase.new(xml[:compra])
|
118
|
-
end
|
119
|
-
|
120
|
-
# Cana de Acucar
|
121
|
-
if xml[:cana]
|
122
|
-
@cane = Nfe::Cane.new(xml[:cana])
|
123
|
-
end
|
124
|
-
|
125
|
-
rescue => exception
|
126
|
-
@error = exception
|
127
|
-
@trace = exception.backtrace
|
128
|
-
ensure
|
129
|
-
file.close if file.respond_to? :close
|
130
|
-
end
|
131
|
-
|
132
|
-
def error?
|
133
|
-
!error.nil?
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
10
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
|
3
|
+
describe AttributeHelper do
|
4
|
+
class AttributeTest
|
5
|
+
include AttributeHelper
|
6
|
+
attr_accessor :first_name, :last_name
|
7
|
+
|
8
|
+
def initialize( attrs= {})
|
9
|
+
@first_name = attrs[:first_name]
|
10
|
+
@last_name = attrs[:last_name]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:attribute_test) { AttributeTest.new(first_name: 'Foo', last_name: 'Bar') }
|
15
|
+
|
16
|
+
it '#attributes'do
|
17
|
+
assert_equal attribute_test.attributes, Hash['first_name' => 'Foo', 'last_name' => 'Bar']
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
|
3
|
+
describe CreatorHelper do
|
4
|
+
class CreatorTest < Struct.new(:name)
|
5
|
+
include CreatorHelper
|
6
|
+
end
|
7
|
+
|
8
|
+
class ResourceTest < Struct.new(:name)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:creator_test) { CreatorTest.new('Foo') }
|
12
|
+
|
13
|
+
describe '#to_array'do
|
14
|
+
it { assert_equal creator_test.to_array([{name: 'Foo'}, {name: 'Bar'}]), [['Foo'], ['Bar']] }
|
15
|
+
it { assert_equal creator_test.to_array({name: 'Foo'}), [['Foo']] }
|
16
|
+
end
|
17
|
+
|
18
|
+
it '#create_resource'do
|
19
|
+
creator_test.create_resource(ResourceTest, 'Foo').must_be_instance_of ResourceTest
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#create_resource'do
|
23
|
+
let(:resources) { creator_test.create_resources(ResourceTest, [['Name', 'Foo'], ['Name', 'Bar']]) }
|
24
|
+
|
25
|
+
it { resources.must_be_instance_of Array }
|
26
|
+
it { resources.first.must_be_instance_of ResourceTest }
|
27
|
+
end
|
28
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe Nfe::Authorization do
|
3
|
+
describe Nfe::Reader::Authorization do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
autXML: {
|
@@ -10,7 +10,7 @@ describe Nfe::Authorization do
|
|
10
10
|
}
|
11
11
|
end
|
12
12
|
|
13
|
-
let(:authorization) { Nfe::Authorization.new(nfe_hash[:autXML]) }
|
13
|
+
let(:authorization) { Nfe::Reader::Authorization.new(nfe_hash[:autXML]) }
|
14
14
|
|
15
15
|
it '#cnpj' do
|
16
16
|
authorization.cnpj.must_equal '99819146000120'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe Nfe::Cane do
|
3
|
+
describe Nfe::Reader::Cane do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
cana: {
|
@@ -27,7 +27,7 @@ describe Nfe::Cane do
|
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
|
-
let(:cane) { Nfe::Cane.new(nfe_hash[:cana]) }
|
30
|
+
let(:cane) { Nfe::Reader::Cane.new(nfe_hash[:cana]) }
|
31
31
|
|
32
32
|
it '#harvest' do
|
33
33
|
cane.harvest.must_equal '2000'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe Nfe::Carrier do
|
3
|
+
describe Nfe::Reader::Carrier do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
transp: {
|
@@ -14,7 +14,7 @@ describe Nfe::Carrier do
|
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:carrier) { Nfe::Carrier.new(nfe_hash[:transp]) }
|
17
|
+
let(:carrier) { Nfe::Reader::Carrier.new(nfe_hash[:transp]) }
|
18
18
|
|
19
19
|
it '#cnpj' do
|
20
20
|
carrier.cnpj.must_equal '99819146000120'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe Nfe::Duplicate do
|
3
|
+
describe Nfe::Reader::Duplicate do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
duplicate: {
|
@@ -11,7 +11,7 @@ describe Nfe::Duplicate do
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:duplicate) { Nfe::Duplicate.new(nfe_hash[:duplicate]) }
|
14
|
+
let(:duplicate) { Nfe::Reader::Duplicate.new(nfe_hash[:duplicate]) }
|
15
15
|
|
16
16
|
it '#number' do
|
17
17
|
duplicate.number.must_equal '1'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe Nfe::Collection do
|
3
|
+
describe Nfe::Reader::Collection do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
collection: {
|
@@ -44,7 +44,7 @@ describe Nfe::Collection do
|
|
44
44
|
}
|
45
45
|
end
|
46
46
|
|
47
|
-
let(:collection) { Nfe::Collection.new(nfe_hash[:collection]) }
|
47
|
+
let(:collection) { Nfe::Reader::Collection.new(nfe_hash[:collection]) }
|
48
48
|
|
49
49
|
describe 'One duplicate' do
|
50
50
|
it '#number' do
|
@@ -69,7 +69,7 @@ describe Nfe::Collection do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
describe 'Two duplicate' do
|
72
|
-
let(:collection) { Nfe::Collection.new(collection_hash[:collection]) }
|
72
|
+
let(:collection) { Nfe::Reader::Collection.new(collection_hash[:collection]) }
|
73
73
|
|
74
74
|
it '#duplicates' do
|
75
75
|
collection.duplicates.size.must_equal 2
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe Nfe::Customer do
|
3
|
+
describe Nfe::Reader::Customer do
|
4
4
|
def customer_hash
|
5
5
|
{
|
6
6
|
dest: {
|
@@ -27,7 +27,7 @@ describe Nfe::Customer do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe 'with address' do
|
30
|
-
let(:customer) { Nfe::Customer.new(customer_hash[:dest]) }
|
30
|
+
let(:customer) { Nfe::Reader::Customer.new(customer_hash[:dest]) }
|
31
31
|
|
32
32
|
it '#foreign_code' do
|
33
33
|
customer.foreign_code.must_equal '10021312198423'
|
@@ -94,7 +94,7 @@ describe Nfe::Customer do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
describe 'without address' do
|
97
|
-
let(:customer) { Nfe::Customer.new }
|
97
|
+
let(:customer) { Nfe::Reader::Customer.new }
|
98
98
|
it '#phone' do
|
99
99
|
customer.number.must_be_nil
|
100
100
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe Nfe::Delivery do
|
3
|
+
describe Nfe::Reader::Delivery do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
entrega: {
|
@@ -17,7 +17,7 @@ describe Nfe::Delivery do
|
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
20
|
-
let(:delivery) { Nfe::Delivery.new(nfe_hash[:entrega]) }
|
20
|
+
let(:delivery) { Nfe::Reader::Delivery.new(nfe_hash[:entrega]) }
|
21
21
|
|
22
22
|
it '#cnpj' do
|
23
23
|
delivery.cnpj.must_equal '99819146000120'
|