nfe_reader 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +38 -0
  6. data/Rakefile +13 -0
  7. data/lib/nfe_reader/authorization.rb +12 -0
  8. data/lib/nfe_reader/carrier.rb +16 -0
  9. data/lib/nfe_reader/collection/duplicate.rb +12 -0
  10. data/lib/nfe_reader/collection.rb +34 -0
  11. data/lib/nfe_reader/customer.rb +62 -0
  12. data/lib/nfe_reader/delivery.rb +20 -0
  13. data/lib/nfe_reader/document.rb +73 -0
  14. data/lib/nfe_reader/export.rb +12 -0
  15. data/lib/nfe_reader/fiscal.rb +33 -0
  16. data/lib/nfe_reader/header.rb +129 -0
  17. data/lib/nfe_reader/information.rb +38 -0
  18. data/lib/nfe_reader/product/armament.rb +22 -0
  19. data/lib/nfe_reader/product/cane.rb +42 -0
  20. data/lib/nfe_reader/product/exportation.rb +20 -0
  21. data/lib/nfe_reader/product/fuel.rb +18 -0
  22. data/lib/nfe_reader/product/importation.rb +49 -0
  23. data/lib/nfe_reader/product/medicament.rb +19 -0
  24. data/lib/nfe_reader/product/vehicle.rb +117 -0
  25. data/lib/nfe_reader/product.rb +90 -0
  26. data/lib/nfe_reader/provider.rb +43 -0
  27. data/lib/nfe_reader/purchase.rb +14 -0
  28. data/lib/nfe_reader/removal.rb +20 -0
  29. data/lib/nfe_reader/taxation/cofins.rb +43 -0
  30. data/lib/nfe_reader/taxation/cofins_st.rb +19 -0
  31. data/lib/nfe_reader/taxation/icms.rb +86 -0
  32. data/lib/nfe_reader/taxation/importation_tax.rb +17 -0
  33. data/lib/nfe_reader/taxation/ipi.rb +41 -0
  34. data/lib/nfe_reader/taxation/issqn.rb +22 -0
  35. data/lib/nfe_reader/taxation/pis.rb +42 -0
  36. data/lib/nfe_reader/taxation/pis_st.rb +19 -0
  37. data/lib/nfe_reader/total.rb +76 -0
  38. data/lib/nfe_reader/transport.rb +97 -0
  39. data/lib/nfe_reader/version.rb +5 -0
  40. data/lib/nfe_reader.rb +129 -0
  41. data/lib/nokogiri_hash.rb +60 -0
  42. data/nfe-reader.gemspec +24 -0
  43. data/test/files/sample-nfe.xml +234 -0
  44. data/test/files/sample2-nfe.xml +192 -0
  45. data/test/nfe_reader/authorization_test.rb +22 -0
  46. data/test/nfe_reader/cane_test.rb +71 -0
  47. data/test/nfe_reader/carrier_test.rb +46 -0
  48. data/test/nfe_reader/collection/duplicate_test.rb +27 -0
  49. data/test/nfe_reader/collection_test.rb +78 -0
  50. data/test/nfe_reader/customer_test.rb +133 -0
  51. data/test/nfe_reader/delivery_test.rb +57 -0
  52. data/test/nfe_reader/document_test.rb +113 -0
  53. data/test/nfe_reader/export_test.rb +22 -0
  54. data/test/nfe_reader/fiscal_test.rb +67 -0
  55. data/test/nfe_reader/header_test.rb +135 -0
  56. data/test/nfe_reader/information_test.rb +37 -0
  57. data/test/nfe_reader/product/armament_test.rb +32 -0
  58. data/test/nfe_reader/product/exportation_test.rb +34 -0
  59. data/test/nfe_reader/product/fuel_test.rb +44 -0
  60. data/test/nfe_reader/product/importation_test.rb +64 -0
  61. data/test/nfe_reader/product/medicament_test.rb +37 -0
  62. data/test/nfe_reader/product/vehicle_test.rb +133 -0
  63. data/test/nfe_reader/product_test.rb +125 -0
  64. data/test/nfe_reader/provider_test.rb +155 -0
  65. data/test/nfe_reader/purchase_test.rb +27 -0
  66. data/test/nfe_reader/removal_test.rb +57 -0
  67. data/test/nfe_reader/taxation/cofins_st_test.rb +37 -0
  68. data/test/nfe_reader/taxation/cofins_test.rb +42 -0
  69. data/test/nfe_reader/taxation/icms_test.rb +122 -0
  70. data/test/nfe_reader/taxation/importation_tax_test.rb +32 -0
  71. data/test/nfe_reader/taxation/ipi_test.rb +78 -0
  72. data/test/nfe_reader/taxation/issqn_test.rb +42 -0
  73. data/test/nfe_reader/taxation/pis_st_test.rb +37 -0
  74. data/test/nfe_reader/taxation/pis_test.rb +42 -0
  75. data/test/nfe_reader/total_test.rb +148 -0
  76. data/test/nfe_reader/transport_test.rb +172 -0
  77. data/test/nfe_reader_test.rb +125 -0
  78. data/test/nokogiri_test.rb +27 -0
  79. data/test/test_helper.rb +13 -0
  80. metadata +201 -0
@@ -0,0 +1,113 @@
1
+ require File.expand_path("../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Document do
4
+ def nfe_hash
5
+ {
6
+ NFref: {
7
+ refNFe: '1000000000000',
8
+ refCTe: '2000000000000',
9
+ refNF: {
10
+ cUF: 'State',
11
+ AAMM: '0010',
12
+ CNPJ: '99819146000120',
13
+ mod: '1',
14
+ serie: '1',
15
+ nNF: '1000'
16
+ },
17
+ refNFP: {
18
+ cUF: 'State',
19
+ AAMM: '0110',
20
+ CNPJ: '99819146000121',
21
+ CPF: '64046757655',
22
+ IE: '10010101010',
23
+ mod: '2',
24
+ serie: '2',
25
+ nNF: '1001',
26
+ },
27
+ refECF: {
28
+ mod: '2A',
29
+ nECF: '1000',
30
+ nCOO: '30471'
31
+ }
32
+ }
33
+ }
34
+ end
35
+
36
+ let(:document) { Nfe::Document.new(nfe_hash[:NFref]) }
37
+
38
+ it '#key' do
39
+ document.key.must_equal '1000000000000'
40
+ end
41
+
42
+ it '#nfe_state' do
43
+ document.nfe_state.must_equal 'State'
44
+ end
45
+
46
+ it '#nfe_year' do
47
+ document.nfe_year.must_equal '0010'
48
+ end
49
+
50
+ it '#nfe_cnpj' do
51
+ document.nfe_cnpj.must_equal '99819146000120'
52
+ end
53
+
54
+ it '#nfe_model' do
55
+ document.nfe_model.must_equal '1'
56
+ end
57
+
58
+ it '#nfe_serie' do
59
+ document.nfe_serie.must_equal '1'
60
+ end
61
+
62
+ it '#nfe_number' do
63
+ document.nfe_number.must_equal '1000'
64
+ end
65
+
66
+ it '#farmer_state' do
67
+ document.farmer_state.must_equal 'State'
68
+ end
69
+
70
+ it '#farmer_year' do
71
+ document.farmer_year.must_equal '0110'
72
+ end
73
+
74
+ it '#farmer_cnpj' do
75
+ document.farmer_cnpj.must_equal '99819146000121'
76
+ end
77
+
78
+ it '#farmer_cpf' do
79
+ document.farmer_cpf.must_equal '64046757655'
80
+ end
81
+
82
+ it '#farmer_ie' do
83
+ document.farmer_ie.must_equal '10010101010'
84
+ end
85
+
86
+ it '#farmer_model' do
87
+ document.farmer_model.must_equal '2'
88
+ end
89
+
90
+ it '#farmer_serie' do
91
+ document.farmer_serie.must_equal '2'
92
+ end
93
+
94
+ it '#farmer_number' do
95
+ document.farmer_number.must_equal '1001'
96
+ end
97
+
98
+ it '#cte_key' do
99
+ document.cte_key.must_equal '2000000000000'
100
+ end
101
+
102
+ it '#ecf_model' do
103
+ document.ecf_model.must_equal '2A'
104
+ end
105
+
106
+ it '#ecf_number' do
107
+ document.ecf_number.must_equal '1000'
108
+ end
109
+
110
+ it '#ecf_operation' do
111
+ document.ecf_operation.must_equal '30471'
112
+ end
113
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Export do
4
+ def nfe_hash
5
+ {
6
+ exporta: {
7
+ UFEmbarq: 'ST',
8
+ xLocEmbarq: 'Address'
9
+ }
10
+ }
11
+ end
12
+
13
+ let(:export) { Nfe::Export.new(nfe_hash[:exporta]) }
14
+
15
+ it '#state' do
16
+ export.state.must_equal 'ST'
17
+ end
18
+
19
+ it '#address' do
20
+ export.address.must_equal 'Address'
21
+ end
22
+ end
@@ -0,0 +1,67 @@
1
+ require File.expand_path("../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Fiscal do
4
+ def nfe_hash
5
+ {
6
+ avulsa: {
7
+ CNPJ: '99819146000120',
8
+ xOrgao: 'Agency',
9
+ matr: '183601271298',
10
+ xAgente: 'Agent',
11
+ fone: '55 5555 5555',
12
+ UF: 'State',
13
+ nDAR: '1000',
14
+ dEmi: '01-01-2000',
15
+ vDAR: '100.00',
16
+ repEmi: '1',
17
+ dPag: '02-01-2000'
18
+ }
19
+ }
20
+ end
21
+
22
+ let(:fiscal) { Nfe::Fiscal.new(nfe_hash[:avulsa]) }
23
+
24
+ it '#cnpj' do
25
+ fiscal.cnpj.must_equal '99819146000120'
26
+ end
27
+
28
+ it '#agency' do
29
+ fiscal.agency.must_equal 'Agency'
30
+ end
31
+
32
+ it '#code' do
33
+ fiscal.code.must_equal '183601271298'
34
+ end
35
+
36
+ it '#name' do
37
+ fiscal.name.must_equal 'Agent'
38
+ end
39
+
40
+ it '#phone' do
41
+ fiscal.phone.must_equal '55 5555 5555'
42
+ end
43
+
44
+ it '#state' do
45
+ fiscal.state.must_equal 'State'
46
+ end
47
+
48
+ it '#number' do
49
+ fiscal.number.must_equal '1000'
50
+ end
51
+
52
+ it '#date' do
53
+ fiscal.date.must_equal '01-01-2000'
54
+ end
55
+
56
+ it '#value' do
57
+ fiscal.value.must_equal '100.00'
58
+ end
59
+
60
+ it '#repartition' do
61
+ fiscal.repartition.must_equal '1'
62
+ end
63
+
64
+ it '#paid_date' do
65
+ fiscal.paid_date.must_equal '02-01-2000'
66
+ end
67
+ end
@@ -0,0 +1,135 @@
1
+ require File.expand_path("../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Header do
4
+ def nfe_hash
5
+ {
6
+ ide: {
7
+ cUF: 'ST',
8
+ cMunFG: '1342',
9
+ cNF: '00000',
10
+ natOp: '1234',
11
+ nNF: '1000',
12
+ mod: '55',
13
+ dEmi: '01/01/2000',
14
+ tpEmis: '1',
15
+ dSaiEnt: '02/01/2000',
16
+ hSaiEnt: '15:30',
17
+ dhEmi: '02/02/2000',
18
+ serie: '1',
19
+ tpNF: '1',
20
+ tpAmb: '2',
21
+ finNFe: '1',
22
+ verProc: '0.0.1',
23
+ indPag: '9',
24
+ procEmi: '0',
25
+ cDV: '1',
26
+ tpImp: '1',
27
+ idDest: '1',
28
+ indPres: '1',
29
+ indFinal: '0',
30
+ }
31
+ }
32
+ end
33
+
34
+ let(:header) { Nfe::Header.new(nfe_hash[:ide]) }
35
+
36
+ it '#final_consumer' do
37
+ header.final_consumer.must_equal '0'
38
+ end
39
+
40
+ it '#consumer_presence' do
41
+ header.consumer_presence.must_equal '1'
42
+ end
43
+
44
+ it '#contingency_date' do
45
+ header.contingency_date.must_be_nil
46
+ end
47
+
48
+ it '#contingency_justification' do
49
+ header.contingency_justification.must_be_nil
50
+ end
51
+
52
+ it '#destiny_code' do
53
+ header.destiny_code.must_equal '1'
54
+ end
55
+
56
+ it '#state' do
57
+ header.state.must_equal 'ST'
58
+ end
59
+
60
+ it '#city' do
61
+ header.city.must_equal '1342'
62
+ end
63
+
64
+ it '#sample_number' do
65
+ header.sample_number.must_equal '00000'
66
+ end
67
+
68
+ it '#operation' do
69
+ header.operation.must_equal '1234'
70
+ end
71
+
72
+ it '#number' do
73
+ header.number.must_equal '1000'
74
+ end
75
+
76
+ it '#model' do
77
+ header.model.must_equal '55'
78
+ end
79
+
80
+ it '#emission' do
81
+ header.emission.must_equal '01/01/2000'
82
+ end
83
+
84
+ it '#emission_kind' do
85
+ header.emission_kind.must_equal '1'
86
+ end
87
+
88
+ it '#emission_date' do
89
+ header.emission_date.must_equal '02/02/2000'
90
+ end
91
+
92
+ it '#out' do
93
+ header.out.must_equal '02/01/2000'
94
+ end
95
+
96
+ it '#out_time' do
97
+ header.out_time.must_equal '15:30'
98
+ end
99
+
100
+ it '#serie' do
101
+ header.serie.must_equal '1'
102
+ end
103
+
104
+ it '#kind' do
105
+ header.kind.must_equal '1'
106
+ end
107
+
108
+ it '#environment' do
109
+ header.environment.must_equal '2'
110
+ end
111
+
112
+ it '#finality' do
113
+ header.finality.must_equal '1'
114
+ end
115
+
116
+ it '#version' do
117
+ header.version.must_equal '0.0.1'
118
+ end
119
+
120
+ it '#payment' do
121
+ header.payment.must_equal '9'
122
+ end
123
+
124
+ it '#process' do
125
+ header.process.must_equal '0'
126
+ end
127
+
128
+ it '#digit' do
129
+ header.digit.must_equal '1'
130
+ end
131
+
132
+ it '#orientation' do
133
+ header.orientation.must_equal '1'
134
+ end
135
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path("../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Information do
4
+ def nfe_hash
5
+ {
6
+ infAdic: {
7
+ infAdFisco: 'Information',
8
+ infCpl: 'Taxpayer Information',
9
+
10
+ obsCont: [
11
+ { xCampo: '1', xTexto: 'One' },
12
+ { xCampo: '2', xTexto: 'Two' }
13
+ ],
14
+
15
+ obsFisco: [
16
+ { xCampo: '1', xTexto: 'One' },
17
+ { xCampo: '2', xTexto: 'Two' }
18
+ ],
19
+
20
+ procRef: [
21
+ { nProc: '789792342134363', indProc: '1' },
22
+ { nProc: '212343146458121', indProc: '1' }
23
+ ]
24
+ }
25
+ }
26
+ end
27
+
28
+ let(:information) { Nfe::Information.new(nfe_hash[:infAdic]) }
29
+
30
+ it '#information' do
31
+ information.information.must_equal 'Information'
32
+ end
33
+
34
+ it '#information_taxpayer' do
35
+ information.information_taxpayer.must_equal 'Taxpayer Information'
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Armament do
4
+ def nfe_hash
5
+ {
6
+ armament: {
7
+ tpArma: '1',
8
+ nSerie: '12345-678',
9
+ nCano: '0.5',
10
+ descr: 'Gun'
11
+ }
12
+ }
13
+ end
14
+
15
+ let(:armament) { Nfe::Armament.new(nfe_hash[:armament]) }
16
+
17
+ it '#kind' do
18
+ armament.kind.must_equal '1'
19
+ end
20
+
21
+ it '#serie' do
22
+ armament.serie.must_equal '12345-678'
23
+ end
24
+
25
+ it '#barrel' do
26
+ armament.barrel.must_equal '0.5'
27
+ end
28
+
29
+ it '#description' do
30
+ armament.description.must_equal 'Gun'
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Exportation do
4
+ def nfe_hash
5
+ {
6
+ detExport: {
7
+ nDraw: '1',
8
+ exportInd: {
9
+ nRE: '5001',
10
+ chNFe: '1000',
11
+ qExport: '10'
12
+ }
13
+ }
14
+ }
15
+ end
16
+
17
+ let(:exportation) { Nfe::Exportation.new(nfe_hash[:detExport]) }
18
+
19
+ it '#drawnback' do
20
+ exportation.drawnback.must_equal '1'
21
+ end
22
+
23
+ it '#number' do
24
+ exportation.number.must_equal '5001'
25
+ end
26
+
27
+ it '#key' do
28
+ exportation.key.must_equal '1000'
29
+ end
30
+
31
+ it '#amount' do
32
+ exportation.amount.must_equal '10'
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Fuel do
4
+ def nfe_hash
5
+ {
6
+ fuel: {
7
+ cProdANP: '10613541',
8
+ CODIF: '123456',
9
+ qTemp: '1700.00',
10
+ CIDE: {
11
+ qBCprod: '2000.00',
12
+ vAliqProd: '12.00',
13
+ vCIDE: '240.00',
14
+ }
15
+ }
16
+ }
17
+ end
18
+
19
+ let(:fuel) { Nfe::Fuel.new(nfe_hash[:fuel]) }
20
+
21
+ it '#anp' do
22
+ fuel.anp.must_equal '10613541'
23
+ end
24
+
25
+ it '#codif' do
26
+ fuel.codif.must_equal '123456'
27
+ end
28
+
29
+ it '#amount' do
30
+ fuel.amount.must_equal '1700.00'
31
+ end
32
+
33
+ it '#cide_base' do
34
+ fuel.cide_base.must_equal '2000.00'
35
+ end
36
+
37
+ it '#cide_aliquot' do
38
+ fuel.cide_aliquot.must_equal '12.00'
39
+ end
40
+
41
+ it '#cide_value' do
42
+ fuel.cide_value.must_equal '240.00'
43
+ end
44
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Importation do
4
+ def nfe_hash
5
+ {
6
+ importation: {
7
+ nDI: '120373',
8
+ dDI: '103846',
9
+ xLocDesemb: 'Local',
10
+ UFDesemb: 'ST',
11
+ dDesemb: '01/01/2000',
12
+ cExportador: '1312',
13
+ adi: {
14
+ nAdicaonSeqAdic: '1',
15
+ nSeqAdic: '1',
16
+ cFabricante: '1357',
17
+ vDescDI: '0.00'
18
+ }
19
+ }
20
+ }
21
+ end
22
+
23
+ let(:importation) { Nfe::Importation.new(nfe_hash[:importation]) }
24
+
25
+ it '#number' do
26
+ importation.number.must_equal '120373'
27
+ end
28
+
29
+ it '#date' do
30
+ importation.date.must_equal '103846'
31
+ end
32
+
33
+ it '#local' do
34
+ importation.local.must_equal 'Local'
35
+ end
36
+
37
+ it '#state' do
38
+ importation.state.must_equal 'ST'
39
+ end
40
+
41
+ it '#customs_clearance' do
42
+ importation.customs_clearance.must_equal '01/01/2000'
43
+ end
44
+
45
+ it '#exporter' do
46
+ importation.exporter.must_equal '1312'
47
+ end
48
+
49
+ it '#addition_number' do
50
+ importation.addition_number.must_equal '1'
51
+ end
52
+
53
+ it '#addition_sequence' do
54
+ importation.addition_sequence.must_equal '1'
55
+ end
56
+
57
+ it '#manufacturer' do
58
+ importation.manufacturer.must_equal '1357'
59
+ end
60
+
61
+ it '#addition_descount' do
62
+ importation.addition_descount.must_equal '0.00'
63
+ end
64
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Medicament do
4
+ def nfe_hash
5
+ {
6
+ medicament: {
7
+ nLote: '123980',
8
+ qLote: '12',
9
+ dFab: '01/01/2000',
10
+ dVal: '01/01/2004',
11
+ vPMC: '289.00'
12
+ }
13
+ }
14
+ end
15
+
16
+ let(:medicament) { Nfe::Medicament.new(nfe_hash[:medicament]) }
17
+
18
+ it '#lot_number' do
19
+ medicament.lot_number.must_equal '123980'
20
+ end
21
+
22
+ it '#lot_amount' do
23
+ medicament.lot_amount.must_equal '12'
24
+ end
25
+
26
+ it '#fabrication' do
27
+ medicament.fabrication.must_equal '01/01/2000'
28
+ end
29
+
30
+ it '#validity' do
31
+ medicament.validity.must_equal '01/01/2004'
32
+ end
33
+
34
+ it '#ceiling_price' do
35
+ medicament.ceiling_price.must_equal '289.00'
36
+ end
37
+ end