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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -1
  3. data/lib/helpers/attribute_helper.rb +18 -0
  4. data/lib/helpers/creator_helper.rb +32 -0
  5. data/lib/nfe_reader/authorization.rb +10 -6
  6. data/lib/nfe_reader/carrier.rb +14 -10
  7. data/lib/nfe_reader/collection/duplicate.rb +10 -6
  8. data/lib/nfe_reader/collection.rb +28 -24
  9. data/lib/nfe_reader/customer.rb +56 -52
  10. data/lib/nfe_reader/delivery.rb +18 -14
  11. data/lib/nfe_reader/document.rb +65 -61
  12. data/lib/nfe_reader/export.rb +9 -5
  13. data/lib/nfe_reader/fiscal.rb +31 -27
  14. data/lib/nfe_reader/header.rb +120 -117
  15. data/lib/nfe_reader/information.rb +17 -26
  16. data/lib/nfe_reader/nfe.rb +130 -0
  17. data/lib/nfe_reader/product/armament.rb +20 -16
  18. data/lib/nfe_reader/product/cane.rb +22 -32
  19. data/lib/nfe_reader/product/exportation.rb +17 -13
  20. data/lib/nfe_reader/product/fuel.rb +15 -11
  21. data/lib/nfe_reader/product/importation.rb +44 -40
  22. data/lib/nfe_reader/product/medicament.rb +17 -13
  23. data/lib/nfe_reader/product/vehicle.rb +115 -111
  24. data/lib/nfe_reader/product.rb +67 -76
  25. data/lib/nfe_reader/provider.rb +39 -35
  26. data/lib/nfe_reader/purchase.rb +10 -6
  27. data/lib/nfe_reader/removal.rb +18 -14
  28. data/lib/nfe_reader/taxation/cofins.rb +41 -37
  29. data/lib/nfe_reader/taxation/cofins_st.rb +17 -13
  30. data/lib/nfe_reader/taxation/icms.rb +80 -76
  31. data/lib/nfe_reader/taxation/importation_tax.rb +16 -12
  32. data/lib/nfe_reader/taxation/ipi.rb +37 -33
  33. data/lib/nfe_reader/taxation/issqn.rb +19 -15
  34. data/lib/nfe_reader/taxation/pis.rb +41 -37
  35. data/lib/nfe_reader/taxation/pis_st.rb +18 -14
  36. data/lib/nfe_reader/total.rb +71 -67
  37. data/lib/nfe_reader/transport.rb +87 -83
  38. data/lib/nfe_reader/version.rb +1 -1
  39. data/lib/nfe_reader.rb +3 -130
  40. data/test/helpers/attributte_helper_test.rb +19 -0
  41. data/test/helpers/creator_helper_test.rb +28 -0
  42. data/test/{nokogiri_test.rb → helpers/nokogiri_test.rb} +1 -1
  43. data/test/nfe_reader/authorization_test.rb +2 -2
  44. data/test/nfe_reader/cane_test.rb +2 -2
  45. data/test/nfe_reader/carrier_test.rb +2 -2
  46. data/test/nfe_reader/collection/duplicate_test.rb +2 -2
  47. data/test/nfe_reader/collection_test.rb +3 -3
  48. data/test/nfe_reader/customer_test.rb +3 -3
  49. data/test/nfe_reader/delivery_test.rb +2 -2
  50. data/test/nfe_reader/document_test.rb +2 -2
  51. data/test/nfe_reader/export_test.rb +2 -2
  52. data/test/nfe_reader/fiscal_test.rb +2 -2
  53. data/test/nfe_reader/header_test.rb +2 -2
  54. data/test/nfe_reader/information_test.rb +2 -2
  55. data/test/{nfe_reader_test.rb → nfe_reader/nfe_test.rb} +15 -15
  56. data/test/nfe_reader/product/armament_test.rb +2 -2
  57. data/test/nfe_reader/product/exportation_test.rb +2 -2
  58. data/test/nfe_reader/product/fuel_test.rb +2 -2
  59. data/test/nfe_reader/product/importation_test.rb +27 -2
  60. data/test/nfe_reader/product/medicament_test.rb +2 -2
  61. data/test/nfe_reader/product/vehicle_test.rb +2 -2
  62. data/test/nfe_reader/product_test.rb +6 -6
  63. data/test/nfe_reader/provider_test.rb +3 -3
  64. data/test/nfe_reader/purchase_test.rb +2 -2
  65. data/test/nfe_reader/removal_test.rb +2 -2
  66. data/test/nfe_reader/taxation/cofins_st_test.rb +2 -2
  67. data/test/nfe_reader/taxation/cofins_test.rb +2 -2
  68. data/test/nfe_reader/taxation/icms_test.rb +2 -2
  69. data/test/nfe_reader/taxation/importation_tax_test.rb +2 -2
  70. data/test/nfe_reader/taxation/ipi_test.rb +2 -2
  71. data/test/nfe_reader/taxation/issqn_test.rb +2 -2
  72. data/test/nfe_reader/taxation/pis_st_test.rb +2 -2
  73. data/test/nfe_reader/taxation/pis_test.rb +2 -2
  74. data/test/nfe_reader/total_test.rb +2 -2
  75. data/test/nfe_reader/transport_test.rb +3 -3
  76. metadata +14 -7
  77. /data/lib/{nokogiri_hash.rb → helpers/nokogiri_hash.rb} +0 -0
@@ -1,48 +1,52 @@
1
1
  # encoding: UTF-8
2
2
  module Nfe
3
- # Declaração de Importação
4
- class Importation
5
- attr_reader :number, :date, :local, :state, :customs_clearance, :exporter,
6
- :addition_number, :addition_sequence, :manufacturer, :addition_descount,
7
- :drawn
3
+ module Reader
4
+ # Declaração de Importação
5
+ class Importation
6
+ include ::AttributeHelper
8
7
 
9
- def initialize(attrs = {})
10
- # Número do Documento de Importação
11
- @number = attrs[:nDI]
12
- # Data de Registro do documento
13
- @date = attrs[:dDI]
14
- # Local de desembaraço
15
- @local = attrs[:xLocDesemb]
16
- # Sigla da UF onde ocorreu o Desembaraço Aduaneiro
17
- @state = attrs[:UFDesemb]
18
- # Data do Desembaraço Aduaneiro
19
- @customs_clearance = attrs[:dDesemb]
20
- # Código do Exportador
21
- @exporter = attrs[:cExportador]
8
+ attr_reader :number, :date, :local, :state, :customs_clearance, :exporter,
9
+ :addition_number, :addition_sequence, :manufacturer, :addition_descount,
10
+ :drawn, :transport, :afrmm, :intermediate_kind, :cnpj, :uf_customer
22
11
 
23
- # Via de transporte internacional
24
- @transport = attrs[:tpViaTransp]
25
- # Valor da AFRMM - Adicional ao Frete para Renovação da Marinha Mercante
26
- @afrmm = attrs[:vAFRMM]
27
- # Forma de importação
28
- @intermediate_kind = attrs[:tpIntermedio]
29
- # CNPJ do adquirente
30
- @cnpj = attrs[:CNPJ]
31
- # Sigla da UF
32
- @uf_customer = attrs[:UFTerceiro]
12
+ def initialize(attrs = {})
13
+ # Número do Documento de Importação
14
+ @number = attrs[:nDI]
15
+ # Data de Registro do documento
16
+ @date = attrs[:dDI]
17
+ # Local de desembaraço
18
+ @local = attrs[:xLocDesemb]
19
+ # Sigla da UF onde ocorreu o Desembaraço Aduaneiro
20
+ @state = attrs[:UFDesemb]
21
+ # Data do Desembaraço Aduaneiro
22
+ @customs_clearance = attrs[:dDesemb]
23
+ # Código do Exportador
24
+ @exporter = attrs[:cExportador]
33
25
 
34
- # Adições
35
- if attrs[:adi]
36
- # Numero da Adição
37
- @addition_number = attrs[:adi][:nAdicaonSeqAdic]
38
- # Numero sequencial do item
39
- @addition_sequence = attrs[:adi][:nSeqAdic]
40
- # Código do fabricante estrangeiro
41
- @manufacturer = attrs[:adi][:cFabricante]
42
- # Valor do desconto do item
43
- @addition_descount = attrs[:adi][:vDescDI]
44
- # Drawback
45
- @drawn = attrs[:adi][:nDraw]
26
+ # Via de transporte internacional
27
+ @transport = attrs[:tpViaTransp]
28
+ # Valor da AFRMM - Adicional ao Frete para Renovação da Marinha Mercante
29
+ @afrmm = attrs[:vAFRMM]
30
+ # Forma de importação
31
+ @intermediate_kind = attrs[:tpIntermedio]
32
+ # CNPJ do adquirente
33
+ @cnpj = attrs[:CNPJ]
34
+ # Sigla da UF
35
+ @uf_customer = attrs[:UFTerceiro]
36
+
37
+ # Adições
38
+ if attrs[:adi]
39
+ # Numero da Adição
40
+ @addition_number = attrs[:adi][:nAdicaonSeqAdic]
41
+ # Numero sequencial do item
42
+ @addition_sequence = attrs[:adi][:nSeqAdic]
43
+ # Código do fabricante estrangeiro
44
+ @manufacturer = attrs[:adi][:cFabricante]
45
+ # Valor do desconto do item
46
+ @addition_descount = attrs[:adi][:vDescDI]
47
+ # Drawback
48
+ @drawn = attrs[:adi][:nDraw]
49
+ end
46
50
  end
47
51
  end
48
52
  end
@@ -1,19 +1,23 @@
1
1
  # encoding: UTF-8
2
2
  module Nfe
3
- class Medicament
4
- attr_reader :lot_number, :lot_amount, :fabrication, :validity, :ceiling_price
3
+ module Reader
4
+ class Medicament
5
+ include ::AttributeHelper
5
6
 
6
- def initialize(attrs = {})
7
- # Numero de Lote
8
- @lot_number = attrs[:nLote]
9
- # Quantidade de Lotes
10
- @lot_amount = attrs[:qLote]
11
- # Data de Fabricação
12
- @fabrication = attrs[:dFab]
13
- # Data de Validade
14
- @validity = attrs[:dVal]
15
- # Preço maximo venda para Consumidor Final
16
- @ceiling_price = attrs[:vPMC]
7
+ attr_reader :lot_number, :lot_amount, :fabrication, :validity, :ceiling_price
8
+
9
+ def initialize(attrs = {})
10
+ # Numero de Lote
11
+ @lot_number = attrs[:nLote]
12
+ # Quantidade de Lotes
13
+ @lot_amount = attrs[:qLote]
14
+ # Data de Fabricação
15
+ @fabrication = attrs[:dFab]
16
+ # Data de Validade
17
+ @validity = attrs[:dVal]
18
+ # Preço maximo venda para Consumidor Final
19
+ @ceiling_price = attrs[:vPMC]
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -1,117 +1,121 @@
1
1
  # encoding: UTF-8
2
2
  module Nfe
3
- class Vehicle
4
- attr_reader :operation, :chassi, :color, :color_name, :engine_power,
5
- :engine_capacities, :weight_net, :weight_gross, :serie, :fuel_kind,
6
- :engine_number, :cmt, :wheelbase, :year, :fabrication_year,
7
- :paint_kind, :kind, :vehicle_kind, :vin, :condiction, :model,
8
- :color_code, :capacity, :restriction
3
+ module Reader
4
+ class Vehicle
5
+ include ::AttributeHelper
9
6
 
10
- # Fields Values
11
- #
12
- # pOp: 1 - Venda concessionária,
13
- # 2 - Faturamento direto para consumidor final
14
- # 3 - Venda direta para grandes consumidores (frotista, governo, ...)
15
- # 0 - Outros
16
- #
17
- # tpComb: 01-Álcool
18
- # 02-Gasolina
19
- # 03-Diesel
20
- # (...) - Tabela Renavam 2.0
21
- #
22
- # tpVeic: Utilizar Tabela RENAVAM
23
- # 06-AUTOMÓVEL
24
- # 14-CAMINHÃO
25
- # 13-CAMINHONETA
26
- # ...
27
- #
28
- # espVeic: Utilizar Tabela RENAVAM
29
- # 1 - PASSAGEIRO
30
- # 2 - CARGA
31
- # 3 - MISTO
32
- # 4 - CORRIDA
33
- # 5 - TRAÇÃO
34
- # 6 - ESPECIAL
35
- #
36
- # VIN: R - Remarcado
37
- # N - Normal
38
- #
39
- # condVeic: 1 - Acabado;
40
- # 2 - Inacabado;
41
- # 3 - Semi-acabado
42
- #
43
- # cCorDEN: 01 - AMARELO
44
- # 02 - AZUL
45
- # 03 - BEGE
46
- # 04 - BRANCA
47
- # 05 - CINZA
48
- # 06 - DOURADA
49
- # 07 - GRENA
50
- # 08 - LARANJA
51
- # 09 - MARROM
52
- # 10 - PRATA
53
- # 11 - PRETA
54
- # 12 - ROSA
55
- # 13 - ROXA
56
- # 14 - VERDE
57
- # 15 - VERMELHA
58
- # 16 - FANTASIA
59
- #
60
- # tpRest: 0 - Não há;
61
- # 1 - Alienação Fiduciária;
62
- # 2 - Arrendamento Mercantil;
63
- # 3 - Reserva de Domínio;
64
- # 4 - Penhor de Veículos;
65
- #
66
- def initialize(attrs = {})
67
- # Tipo da operação
68
- @operation = attrs[:pOp]
69
- # Numero do Chassi
70
- @chassi = attrs[:chassi]
71
- # Cor do Fabricante
72
- @color = attrs[:cCor]
73
- # Nome da Cor do Fabricante
74
- @color_name = attrs[:xCor]
75
- # Potencia do Motor em CV
76
- @engine_power = attrs[:pot]
77
- # Potencia do Motor em CC
78
- @engine_capacities = attrs[:cilin]
79
- # Peso Liquido
80
- @weight_net = attrs[:pesoL]
81
- # Peso Bruto
82
- @weight_gross = attrs[:pesoB]
83
- # Numero serie
84
- @serie = attrs[:nSerie]
85
- # Tipo de Combustivel
86
- @fuel_kind = attrs[:tpComb]
87
- # Numeracao do Motor
88
- @engine_number = attrs[:nMotor]
89
- # CMT: Capacidade Maxima de Tração
90
- @cmt = attrs[:CMT]
91
- # Distancia entre os Eixos
92
- @wheelbase = attrs[:dist]
93
- # Ano do Modelo
94
- @year = attrs[:anoMod]
95
- # Ano de Fabricacao
96
- @fabrication_year = attrs[:anoFab]
97
- # Tipo de Pintura
98
- @paint_kind = attrs[:tpPint]
99
- # Tipo de Veiculo
100
- @kind = attrs[:tpVeic]
101
- # Especie do veiculo
102
- @vehicle_kind = attrs[:espVeic]
103
- # Condição do VIN
104
- @vin = attrs[:VIN]
105
- # Condições do Veiculo
106
- @condiction = attrs[:condVeic]
107
- # Modelo
108
- @model = attrs[:cMod]
109
- # Codigo da Cor
110
- @color_code = attrs[:cCorDEN]
111
- # Capacidade
112
- @capacity = attrs[:lota]
113
- # Restrição
114
- @restriction = attrs[:tpRest]
7
+ attr_reader :operation, :chassi, :color, :color_name, :engine_power,
8
+ :engine_capacities, :weight_net, :weight_gross, :serie, :fuel_kind,
9
+ :engine_number, :cmt, :wheelbase, :year, :fabrication_year,
10
+ :paint_kind, :kind, :vehicle_kind, :vin, :condiction, :model,
11
+ :color_code, :capacity, :restriction
12
+
13
+ # Fields Values
14
+ #
15
+ # pOp: 1 - Venda concessionária,
16
+ # 2 - Faturamento direto para consumidor final
17
+ # 3 - Venda direta para grandes consumidores (frotista, governo, ...)
18
+ # 0 - Outros
19
+ #
20
+ # tpComb: 01-Álcool
21
+ # 02-Gasolina
22
+ # 03-Diesel
23
+ # (...) - Tabela Renavam 2.0
24
+ #
25
+ # tpVeic: Utilizar Tabela RENAVAM
26
+ # 06-AUTOMÓVEL
27
+ # 14-CAMINHÃO
28
+ # 13-CAMINHONETA
29
+ # ...
30
+ #
31
+ # espVeic: Utilizar Tabela RENAVAM
32
+ # 1 - PASSAGEIRO
33
+ # 2 - CARGA
34
+ # 3 - MISTO
35
+ # 4 - CORRIDA
36
+ # 5 - TRAÇÃO
37
+ # 6 - ESPECIAL
38
+ #
39
+ # VIN: R - Remarcado
40
+ # N - Normal
41
+ #
42
+ # condVeic: 1 - Acabado;
43
+ # 2 - Inacabado;
44
+ # 3 - Semi-acabado
45
+ #
46
+ # cCorDEN: 01 - AMARELO
47
+ # 02 - AZUL
48
+ # 03 - BEGE
49
+ # 04 - BRANCA
50
+ # 05 - CINZA
51
+ # 06 - DOURADA
52
+ # 07 - GRENA
53
+ # 08 - LARANJA
54
+ # 09 - MARROM
55
+ # 10 - PRATA
56
+ # 11 - PRETA
57
+ # 12 - ROSA
58
+ # 13 - ROXA
59
+ # 14 - VERDE
60
+ # 15 - VERMELHA
61
+ # 16 - FANTASIA
62
+ #
63
+ # tpRest: 0 - Não há;
64
+ # 1 - Alienação Fiduciária;
65
+ # 2 - Arrendamento Mercantil;
66
+ # 3 - Reserva de Domínio;
67
+ # 4 - Penhor de Veículos;
68
+ #
69
+ def initialize(attrs = {})
70
+ # Tipo da operação
71
+ @operation = attrs[:pOp]
72
+ # Numero do Chassi
73
+ @chassi = attrs[:chassi]
74
+ # Cor do Fabricante
75
+ @color = attrs[:cCor]
76
+ # Nome da Cor do Fabricante
77
+ @color_name = attrs[:xCor]
78
+ # Potencia do Motor em CV
79
+ @engine_power = attrs[:pot]
80
+ # Potencia do Motor em CC
81
+ @engine_capacities = attrs[:cilin]
82
+ # Peso Liquido
83
+ @weight_net = attrs[:pesoL]
84
+ # Peso Bruto
85
+ @weight_gross = attrs[:pesoB]
86
+ # Numero serie
87
+ @serie = attrs[:nSerie]
88
+ # Tipo de Combustivel
89
+ @fuel_kind = attrs[:tpComb]
90
+ # Numeracao do Motor
91
+ @engine_number = attrs[:nMotor]
92
+ # CMT: Capacidade Maxima de Tração
93
+ @cmt = attrs[:CMT]
94
+ # Distancia entre os Eixos
95
+ @wheelbase = attrs[:dist]
96
+ # Ano do Modelo
97
+ @year = attrs[:anoMod]
98
+ # Ano de Fabricacao
99
+ @fabrication_year = attrs[:anoFab]
100
+ # Tipo de Pintura
101
+ @paint_kind = attrs[:tpPint]
102
+ # Tipo de Veiculo
103
+ @kind = attrs[:tpVeic]
104
+ # Especie do veiculo
105
+ @vehicle_kind = attrs[:espVeic]
106
+ # Condição do VIN
107
+ @vin = attrs[:VIN]
108
+ # Condições do Veiculo
109
+ @condiction = attrs[:condVeic]
110
+ # Modelo
111
+ @model = attrs[:cMod]
112
+ # Codigo da Cor
113
+ @color_code = attrs[:cCorDEN]
114
+ # Capacidade
115
+ @capacity = attrs[:lota]
116
+ # Restrição
117
+ @restriction = attrs[:tpRest]
118
+ end
115
119
  end
116
120
  end
117
121
  end
@@ -1,90 +1,81 @@
1
1
  # encoding: UTF-8
2
2
  module Nfe
3
- # Detalhamento de Produtos e Serviços da NF-e
4
- class Product
5
- attr_reader :number, :product_code, :product, :ean, :ncm, :cfop,
6
- :unit_sale, :value_sale, :amount_sale, :total, :gtin, :unit,
7
- :amount, :value, :kind, :ipi_exception, :freight, :insurance,
8
- :discount, :other_value, :importation, :icms, :ipi, :pis,
9
- :importation_tax, :exportation, :demand_number, :demand_item,
10
- :armament, :fuel
3
+ module Reader
4
+ # Detalhamento de Produtos e Serviços da NF-e
5
+ class Product
6
+ include ::AttributeHelper
7
+ include ::CreatorHelper
11
8
 
12
- # == Fields Values
13
- #
14
- # indTot: 0 - o valor do item (vProd) compõe o valor total da NF-e (vProd)
15
- # 1 - o valor do item (vProd) não compõe o valor total da NF-e (vProd) (v2.0)
16
- #
17
- def initialize(attrs = {})
18
- @number = attrs[:nItem]
19
-
20
- if attrs[:prod]
21
- @product_code = attrs[:prod][:cProd]
22
- @product = attrs[:prod][:xProd]
23
- @ean = attrs[:prod][:cEAN]
24
- @ncm = attrs[:prod][:NCM]
25
-
26
- # Sale
27
- @cfop = attrs[:prod][:CFOP]
28
- @unit_sale = attrs[:prod][:uCom]
29
- @amount_sale = attrs[:prod][:qCom]
30
- @value_sale = attrs[:prod][:vUnCom]
31
- @total = attrs[:prod][:vProd]
32
-
33
- # Numero do Pedido de Compra
34
- @demand_number = attrs[:prod][:xPed]
35
- # Item do Pedido de Compra
36
- @demand_item = attrs[:prod][:nItemPed]
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
37
16
 
38
- # GTIN (Global Trade ItemNumber)
39
- @gtin = attrs[:prod][:cEANTrib]
40
-
41
- @unit = attrs[:prod][:uTrib]
42
- @amount = attrs[:prod][:qTrib]
43
- @value = attrs[:prod][:vUnTrib]
44
- @kind = attrs[:prod][:indTot]
45
- @ipi_exception = attrs[:prod][:EXTIPI]
46
- @freight = attrs[:prod][:vFrete]
47
- @insurance = attrs[:prod][:vSeg]
48
- @discount = attrs[:prod][:vDesc]
49
- @other_value = attrs[:prod][:vOutro]
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]
50
24
 
51
- @importation = create_resource(Nfe::Importation, attrs[:prod][:DI])
52
- end
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]
53
37
 
54
- @armament = create_resources(Nfe::Armament, attrs[:arma]) if attrs[:arma]
55
- @medicament = create_resources(Nfe::Medicament, attrs[:med]) if attrs[:med]
56
- @fuel = Nfe::Fuel.new(attrs[:comb]) if attrs[:comb]
57
- @vehicle = Nfe::Vehicle.new(attrs[:veicProd]) if attrs[:veicProd]
38
+ # Numero do Pedido de Compra
39
+ @demand_number = attrs[:prod][:xPed]
40
+ # Item do Pedido de Compra
41
+ @demand_item = attrs[:prod][:nItemPed]
58
42
 
59
- @exportation = create_resources(Nfe::Exportation, attrs[:detExport])
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
60
58
 
61
- if attrs[:imposto]
62
- @icms = create_resources(Nfe::Icms, attrs[:imposto][:ICMS])
63
- @cofins = create_resources(Nfe::Cofins, attrs[:imposto][:COFINS])
64
- @pis = create_resources(Nfe::Pis, attrs[:imposto][:PIS])
65
- @importation_tax = create_resource(Nfe::ImportationTax, attrs[:imposto][:II])
66
- @ipi = create_resource(Nfe::Ipi, attrs[:imposto][:IPI])
67
- @pis_st = create_resource(Nfe::PisSt, attrs[:imposto][:PISST])
68
- @cofins_st = create_resource(Nfe::CofinsSt, attrs[:imposto][:COFINSST])
69
- @issqn = create_resource(Nfe::Issqn, attrs[:imposto][:ISSQN])
70
- end
71
- end
72
-
73
- def create_resource(klass, attrs = {})
74
- return unless attrs
75
- klass.new(attrs)
76
- end
77
-
78
- def create_resources(klass, attrs = {})
79
- resources = []
59
+ @fuel = Fuel.new(attrs[:comb]) if attrs[:comb]
60
+ @vehicle = Vehicle.new(attrs[:veicProd]) if attrs[:veicProd]
61
+
62
+ @armament = create_resources(Armament, attrs[:arma]) if attrs[:arma]
63
+ @medicament = create_resources(Medicament, attrs[:med]) if attrs[:med]
80
64
 
81
- return resources unless attrs
65
+ @exportation = create_resources(Exportation, attrs[:detExport])
82
66
 
83
- attrs.each do |a|
84
- resources << klass.new(a.last)
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
85
78
  end
86
-
87
- resources
88
79
  end
89
80
  end
90
81
  end
@@ -1,42 +1,46 @@
1
1
  # encoding: UTF-8
2
2
  module Nfe
3
- # Identificação do Emitente da Nota Fiscal eletrônica
4
- class Provider
5
- attr_reader :cnpj, :cpf, :name, :phone, :state_registration, :state_registration_st,
6
- :city_registration, :regime, :cnae, :address, :number, :complement, :neighborhood,
7
- :city_code, :city, :zip_code, :country_code, :country, :fantasy, :state
3
+ module Reader
4
+ # Identificação do Emitente da Nota Fiscal eletrônica
5
+ class Provider
6
+ include ::AttributeHelper
8
7
 
9
- # == Fields Values
10
- #
11
- # CRT: 1 - Simples Nacional,
12
- # 2 - Simples Nacional – excesso de sublimite de receita bruta,
13
- # 3 - Regime Normal
14
- #
15
- def initialize(attrs = {})
16
- # Provider Info
17
- @cnpj = attrs[:CNPJ]
18
- @cpf = attrs[:CPF]
19
- @name = attrs[:xNome]
20
- @fantasy = attrs[:xFant]
21
- @state_registration = attrs[:IE]
22
- @state_registration_st = attrs[:IEST]
23
- @city_registration = attrs[:IM]
24
- @regime = attrs[:CRT]
25
- @cnae = attrs[:CNAE]
8
+ attr_reader :cnpj, :cpf, :name, :phone, :state_registration, :state_registration_st,
9
+ :city_registration, :regime, :cnae, :address, :number, :complement, :neighborhood,
10
+ :city_code, :city, :zip_code, :country_code, :country, :fantasy, :state
26
11
 
27
- # Address
28
- if attrs[:enderEmit]
29
- @phone = attrs[:enderEmit][:fone]
30
- @address = attrs[:enderEmit][:xLgr]
31
- @number = attrs[:enderEmit][:nro]
32
- @complement = attrs[:enderEmit][:xCpl]
33
- @neighborhood = attrs[:enderEmit][:xBairro]
34
- @city_code = attrs[:enderEmit][:cMun]
35
- @city = attrs[:enderEmit][:xMun]
36
- @zip_code = attrs[:enderEmit][:CEP]
37
- @country_code = attrs[:enderEmit][:cPais]
38
- @country = attrs[:enderEmit][:xPais]
39
- @state = attrs[:enderEmit][:UF]
12
+ # == Fields Values
13
+ #
14
+ # CRT: 1 - Simples Nacional,
15
+ # 2 - Simples Nacional – excesso de sublimite de receita bruta,
16
+ # 3 - Regime Normal
17
+ #
18
+ def initialize(attrs = {})
19
+ # Provider Info
20
+ @cnpj = attrs[:CNPJ]
21
+ @cpf = attrs[:CPF]
22
+ @name = attrs[:xNome]
23
+ @fantasy = attrs[:xFant]
24
+ @state_registration = attrs[:IE]
25
+ @state_registration_st = attrs[:IEST]
26
+ @city_registration = attrs[:IM]
27
+ @regime = attrs[:CRT]
28
+ @cnae = attrs[:CNAE]
29
+
30
+ # Address
31
+ if attrs[:enderEmit]
32
+ @phone = attrs[:enderEmit][:fone]
33
+ @address = attrs[:enderEmit][:xLgr]
34
+ @number = attrs[:enderEmit][:nro]
35
+ @complement = attrs[:enderEmit][:xCpl]
36
+ @neighborhood = attrs[:enderEmit][:xBairro]
37
+ @city_code = attrs[:enderEmit][:cMun]
38
+ @city = attrs[:enderEmit][:xMun]
39
+ @zip_code = attrs[:enderEmit][:CEP]
40
+ @country_code = attrs[:enderEmit][:cPais]
41
+ @country = attrs[:enderEmit][:xPais]
42
+ @state = attrs[:enderEmit][:UF]
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -2,13 +2,17 @@
2
2
 
3
3
  # Informações de Compras
4
4
  module Nfe
5
- class Purchase
6
- attr_reader :number, :demand, :contract
5
+ module Reader
6
+ class Purchase
7
+ include ::AttributeHelper
7
8
 
8
- def initialize(attrs = {})
9
- @number = attrs[:xNEmp]
10
- @demand = attrs[:xPed]
11
- @contract = attrs[:xCont]
9
+ attr_reader :number, :demand, :contract
10
+
11
+ def initialize(attrs = {})
12
+ @number = attrs[:xNEmp]
13
+ @demand = attrs[:xPed]
14
+ @contract = attrs[:xCont]
15
+ end
12
16
  end
13
17
  end
14
18
  end