br_danfe 0.15.1 → 0.17.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +20 -8
  3. data/.github/dependabot.yml +19 -0
  4. data/.rubocop.yml +24 -11
  5. data/.tool-versions +1 -0
  6. data/Gemfile.lock +69 -50
  7. data/Guardfile +4 -2
  8. data/README.md +23 -0
  9. data/bin/_guard-core +29 -0
  10. data/bin/guard +29 -0
  11. data/br_danfe.gemspec +9 -7
  12. data/lib/br_danfe/danfe_lib/nfce.rb +11 -9
  13. data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +1 -1
  14. data/lib/br_danfe/danfe_lib/nfce_lib/footer.rb +2 -2
  15. data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +30 -16
  16. data/lib/br_danfe/danfe_lib/nfce_lib/key.rb +3 -3
  17. data/lib/br_danfe/danfe_lib/nfce_lib/nfce_identification.rb +3 -3
  18. data/lib/br_danfe/danfe_lib/nfce_lib/product_list.rb +44 -53
  19. data/lib/br_danfe/danfe_lib/nfce_lib/recipient.rb +1 -1
  20. data/lib/br_danfe/danfe_lib/nfce_lib/total_list.rb +16 -15
  21. data/lib/br_danfe/danfe_lib/nfe.rb +11 -9
  22. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +1 -1
  23. data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +1 -2
  24. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +5 -6
  25. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +2 -1
  26. data/lib/br_danfe/document_builder.rb +1 -1
  27. data/lib/br_danfe/helper.rb +8 -10
  28. data/lib/br_danfe/mdfe.rb +55 -0
  29. data/lib/br_danfe/mdfe_lib/authorization_protocol.rb +24 -0
  30. data/lib/br_danfe/mdfe_lib/document.rb +26 -0
  31. data/lib/br_danfe/mdfe_lib/drivers.rb +70 -0
  32. data/lib/br_danfe/mdfe_lib/fisco_control.rb +21 -0
  33. data/lib/br_danfe/mdfe_lib/header.rb +77 -0
  34. data/lib/br_danfe/mdfe_lib/mdfe_identification.rb +69 -0
  35. data/lib/br_danfe/mdfe_lib/notes.rb +94 -0
  36. data/lib/br_danfe/mdfe_lib/totalizer.rb +57 -0
  37. data/lib/br_danfe/mdfe_lib/vehicles.rb +80 -0
  38. data/lib/br_danfe/qr_code.rb +21 -0
  39. data/lib/br_danfe/version.rb +1 -1
  40. data/lib/br_danfe.rb +2 -2
  41. data/spec/br_danfe/danfe_lib/nfce_lib/footer_spec.rb +3 -2
  42. data/spec/br_danfe/danfe_lib/nfce_lib/header_spec.rb +6 -4
  43. data/spec/br_danfe/danfe_lib/nfce_lib/helper_spec.rb +2 -2
  44. data/spec/br_danfe/danfe_lib/nfce_lib/key_spec.rb +2 -2
  45. data/spec/br_danfe/danfe_lib/nfce_lib/nfce_identification_spec.rb +2 -2
  46. data/spec/br_danfe/danfe_lib/nfce_lib/recipient_spec.rb +10 -10
  47. data/spec/br_danfe/danfe_lib/nfce_lib/total_list_spec.rb +12 -12
  48. data/spec/br_danfe/danfe_lib/nfce_spec.rb +2 -1
  49. data/spec/br_danfe/danfe_lib/nfe_lib/cst_spec.rb +4 -4
  50. data/spec/br_danfe/danfe_lib/nfe_lib/dest_spec.rb +178 -178
  51. data/spec/br_danfe/danfe_lib/nfe_lib/det_body_spec.rb +274 -274
  52. data/spec/br_danfe/danfe_lib/nfe_lib/document_spec.rb +77 -77
  53. data/spec/br_danfe/danfe_lib/nfe_lib/dup_spec.rb +23 -23
  54. data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +37 -37
  55. data/spec/br_danfe/danfe_lib/nfe_lib/helper_spec.rb +34 -34
  56. data/spec/br_danfe/danfe_lib/nfe_lib/icmstot_spec.rb +19 -19
  57. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +240 -240
  58. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_vol_spec.rb +3 -2
  59. data/spec/br_danfe/danfe_lib/nfe_lib/issqn_spec.rb +16 -16
  60. data/spec/br_danfe/danfe_lib/nfe_lib/ticket_spec.rb +13 -13
  61. data/spec/br_danfe/danfe_lib/nfe_lib/transp_spec.rb +76 -76
  62. data/spec/br_danfe/danfe_lib/nfe_lib/vol_spec.rb +40 -40
  63. data/spec/br_danfe/danfe_lib/nfe_lib/xprod_spec.rb +118 -118
  64. data/spec/br_danfe/danfe_spec.rb +2 -2
  65. data/spec/br_danfe/helper_spec.rb +26 -14
  66. data/spec/br_danfe/mdfe_lib/authorization_protocol_spec.rb +35 -0
  67. data/spec/br_danfe/mdfe_lib/document_spec.rb +20 -0
  68. data/spec/br_danfe/mdfe_lib/drivers_spec.rb +88 -0
  69. data/spec/br_danfe/mdfe_lib/fisco_control_spec.rb +69 -0
  70. data/spec/br_danfe/mdfe_lib/header_spec.rb +135 -0
  71. data/spec/br_danfe/mdfe_lib/mdfe_identification_spec.rb +104 -0
  72. data/spec/br_danfe/mdfe_lib/notes_spec.rb +97 -0
  73. data/spec/br_danfe/mdfe_lib/totalizer_spec.rb +63 -0
  74. data/spec/br_danfe/mdfe_lib/vehicles_spec.rb +66 -0
  75. data/spec/br_danfe/mdfe_spec.rb +45 -0
  76. data/spec/br_danfe/qr_code_spec.rb +31 -0
  77. data/spec/br_danfe/xml_spec.rb +6 -6
  78. data/spec/fixtures/mdfe/lib/document#render.pdf +0 -0
  79. data/spec/fixtures/mdfe/lib/document#text.align.pdf +0 -0
  80. data/spec/fixtures/mdfe/lib/document#text.pad.pdf +0 -0
  81. data/spec/fixtures/mdfe/lib/document#text.simple.pdf +0 -0
  82. data/spec/fixtures/mdfe/lib/document#text.size.pdf +0 -0
  83. data/spec/fixtures/mdfe/lib/document#text.style.pdf +0 -0
  84. data/spec/fixtures/mdfe/lib/fisco_control#barcode.pdf +0 -0
  85. data/spec/fixtures/mdfe/lib/fisco_control#without-barcode.pdf +0 -0
  86. data/spec/fixtures/mdfe/lib/header#render-qr-code.pdf +0 -0
  87. data/spec/fixtures/mdfe/lib/header#render-with_logo.pdf +0 -0
  88. data/spec/fixtures/mdfe/lib/header#render-without-qr-code.pdf +0 -0
  89. data/spec/fixtures/mdfe/lib/header#render-without_logo.pdf +0 -0
  90. data/spec/fixtures/mdfe/lib/mdfe-with-multiple-pages.pdf +1945 -0
  91. data/spec/fixtures/mdfe/lib/mdfe.fixture.pdf +1286 -0
  92. data/spec/fixtures/mdfe/lib/notes#render-big-aditional-information.pdf +1943 -0
  93. data/spec/fixtures/mdfe/lib/xml-mdfe-multiples-pages.xml +116 -0
  94. data/spec/fixtures/mdfe/lib/xml-mdfe.xml +250 -0
  95. data/spec/fixtures/nfce/lib/document#render.pdf +12 -23
  96. data/spec/fixtures/nfce/lib/footer#render-with_additional_information.pdf +0 -0
  97. data/spec/fixtures/nfce/lib/footer#render.pdf +0 -0
  98. data/spec/fixtures/nfce/lib/header#render-homologation.pdf +0 -0
  99. data/spec/fixtures/nfce/lib/header#render-long_name_with_logo.pdf +0 -0
  100. data/spec/fixtures/nfce/lib/header#render-long_name_without_logo.pdf +0 -0
  101. data/spec/fixtures/nfce/lib/header#render-short_name_with_logo.pdf +0 -0
  102. data/spec/fixtures/nfce/lib/header#render-short_name_without_logo.pdf +0 -0
  103. data/spec/fixtures/nfce/lib/key#render.pdf +0 -0
  104. data/spec/fixtures/nfce/lib/nfce_identification#render.pdf +0 -0
  105. data/spec/fixtures/nfce/lib/product_list#render-with_many_products.pdf +0 -0
  106. data/spec/fixtures/nfce/lib/product_list#render-with_many_products_and_long_names.pdf +0 -0
  107. data/spec/fixtures/nfce/lib/product_list#render-with_single_product.pdf +0 -0
  108. data/spec/fixtures/nfce/lib/product_list#render-with_single_product_and_long_name.pdf +0 -0
  109. data/spec/fixtures/nfce/lib/product_list_with_many_products_and_long_names.xml +2 -2
  110. data/spec/fixtures/nfce/lib/product_list_with_single_product_and_long_name.xml +1 -1
  111. data/spec/fixtures/nfce/lib/recipient#render-company.pdf +0 -0
  112. data/spec/fixtures/nfce/lib/recipient#render-consumer_without_document.pdf +0 -0
  113. data/spec/fixtures/nfce/lib/recipient#render-foreign.pdf +0 -0
  114. data/spec/fixtures/nfce/lib/recipient#render-individual.pdf +0 -0
  115. data/spec/fixtures/nfce/lib/recipient#render-unidentified_consumer.pdf +0 -0
  116. data/spec/fixtures/nfce/lib/total_list#does_not_render-payment_methods.pdf +0 -0
  117. data/spec/fixtures/nfce/lib/total_list#render-grouped_payment_methods.pdf +0 -0
  118. data/spec/fixtures/nfce/lib/total_list#render-totals.pdf +0 -0
  119. data/spec/fixtures/nfce/lib/total_list#render-without_payment.pdf +0 -0
  120. data/spec/fixtures/nfce/lib/total_list#render.pdf +0 -0
  121. data/spec/fixtures/nfce/v4.00/multiples_xmls_on_the_same_pdf.pdf +568 -447
  122. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.fixture.pdf +0 -0
  123. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.fixture.pdf +0 -0
  124. data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
  125. data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
  126. data/spec/fixtures/qr_code/qr_code#render.pdf +0 -0
  127. data/spec/spec_helper.rb +1 -1
  128. metadata +118 -48
  129. data/lib/br_danfe/danfe_lib/nfce_lib/qr_code.rb +0 -25
  130. data/lib/br_danfe/danfe_lib/nfe_lib/cep.rb +0 -11
  131. data/spec/br_danfe/danfe_lib/nfce_lib/qr_code_spec.rb +0 -35
  132. data/spec/br_danfe/danfe_lib/nfe_lib/cep_spec.rb +0 -10
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe BrDanfe::Danfe do
4
4
  let(:xml) do
5
- <<-eos
5
+ <<~XML
6
6
  <nfeProc>
7
7
  <NFe>
8
8
  <infNFe>
@@ -17,7 +17,7 @@ describe BrDanfe::Danfe do
17
17
  </infNFe>
18
18
  </NFe>
19
19
  </nfeProc>
20
- eos
20
+ XML
21
21
  end
22
22
 
23
23
  subject { described_class.new(xml) }
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe BrDanfe::Helper do
4
4
  describe '.no_fiscal_value?' do
5
5
  let(:xml_homologation) do
6
- xml = <<-eos
6
+ xml = <<~XML
7
7
  <nfeProc>
8
8
  <NFe>
9
9
  <infNFe>
@@ -18,25 +18,25 @@ describe BrDanfe::Helper do
18
18
  </protNFe>
19
19
  </NFe>
20
20
  </nfeProc>
21
- eos
21
+ XML
22
22
 
23
23
  Nokogiri::XML(xml)
24
24
  end
25
25
 
26
26
  let(:xml_unauthorized) do
27
- xml = <<-eos
27
+ xml = <<~XML
28
28
  <nfeProc>
29
29
  <protNFe>
30
30
  <infProt></infProt>
31
31
  </protNFe>
32
32
  </nfeProc>
33
- eos
33
+ XML
34
34
 
35
35
  Nokogiri::XML(xml)
36
36
  end
37
37
 
38
38
  let(:xml_authorized) do
39
- xml = <<-eos
39
+ xml = <<~XML
40
40
  <nfeProc>
41
41
  <NFe>
42
42
  <infNFe>
@@ -51,7 +51,7 @@ describe BrDanfe::Helper do
51
51
  </infProt>
52
52
  </protNFe>
53
53
  </nfeProc>
54
- eos
54
+ XML
55
55
 
56
56
  Nokogiri::XML(xml)
57
57
  end
@@ -78,13 +78,13 @@ describe BrDanfe::Helper do
78
78
  describe '.unauthorized?' do
79
79
  context 'when XML is unauthorized' do
80
80
  let(:xml_unauthorized) do
81
- xml = <<-eos
81
+ xml = <<~XML
82
82
  <nfeProc>
83
83
  <protNFe>
84
84
  <infProt></infProt>
85
85
  </protNFe>
86
86
  </nfeProc>
87
- eos
87
+ XML
88
88
 
89
89
  Nokogiri::XML(xml)
90
90
  end
@@ -96,7 +96,7 @@ describe BrDanfe::Helper do
96
96
 
97
97
  context 'when XML is authorized' do
98
98
  let(:xml_authorized) do
99
- xml = <<-eos
99
+ xml = <<~XML
100
100
  <nfeProc>
101
101
  <protNFe>
102
102
  <infProt>
@@ -104,7 +104,7 @@ describe BrDanfe::Helper do
104
104
  </infProt>
105
105
  </protNFe>
106
106
  </nfeProc>
107
- eos
107
+ XML
108
108
 
109
109
  Nokogiri::XML(xml)
110
110
  end
@@ -118,7 +118,7 @@ describe BrDanfe::Helper do
118
118
  describe '.homologation?' do
119
119
  context 'when tpAmb is equal to "2"' do
120
120
  let(:xml_homologation) do
121
- xml = <<-eos
121
+ xml = <<~XML
122
122
  <nfeProc>
123
123
  <NFe>
124
124
  <infNFe>
@@ -128,7 +128,7 @@ describe BrDanfe::Helper do
128
128
  </infNFe>
129
129
  </NFe>
130
130
  </nfeProc>
131
- eos
131
+ XML
132
132
 
133
133
  Nokogiri::XML(xml)
134
134
  end
@@ -140,7 +140,7 @@ describe BrDanfe::Helper do
140
140
 
141
141
  context 'when tpAmb is different to "2"' do
142
142
  let(:xml_production) do
143
- xml = <<-eos
143
+ xml = <<~XML
144
144
  <nfeProc>
145
145
  <NFe>
146
146
  <infNFe>
@@ -150,7 +150,7 @@ describe BrDanfe::Helper do
150
150
  </infNFe>
151
151
  </NFe>
152
152
  </nfeProc>
153
- eos
153
+ XML
154
154
 
155
155
  Nokogiri::XML(xml)
156
156
  end
@@ -212,5 +212,17 @@ describe BrDanfe::Helper do
212
212
  expect(described_class.format_datetime('')).to eql ''
213
213
  end
214
214
  end
215
+
216
+ describe 'when has timezone' do
217
+ it 'returns the formated string with the timezone' do
218
+ expect(described_class.format_datetime('2013-10-18T13:54:04-03:00', with_time_zone: true)).to eql '18/10/2013 13:54:04-03:00'
219
+ end
220
+ end
221
+ end
222
+
223
+ describe '.format_cep' do
224
+ it 'returns a formatted CEP' do
225
+ expect(described_class.format_cep('12345678')).to eql '12.345-678'
226
+ end
215
227
  end
216
228
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::AuthorizationProtocol do
4
+ let(:xml_as_string) do
5
+ <<~XML
6
+ <?xml version="1.0" encoding="UTF-8"?>
7
+ <mdfeProc xmlns="http://www.portalfiscal.inf.br/mdfe" versao="3.00">
8
+ <protMDFe versao="3.00" xmlns="http://www.portalfiscal.inf.br/mdfe">
9
+ <infProt Id="MDFe932210002534081">
10
+ <dhRecbto>2021-07-01T17:39:16-03:00</dhRecbto>
11
+ <nProt>932210002534081</nProt>
12
+ </infProt>
13
+ </protMDFe>
14
+ </mdfeProc>
15
+ XML
16
+ end
17
+
18
+ let(:pdf) { BrDanfe::MdfeLib::Document.new }
19
+ let(:xml) { BrDanfe::XML.new(xml_as_string) }
20
+
21
+ subject { described_class.new(pdf, xml) }
22
+
23
+ let(:pdf_text) do
24
+ PDF::Inspector::Text.analyze(pdf.render).strings.join("\n")
25
+ end
26
+
27
+ describe '#generate' do
28
+ it 'generates the authorization protocol' do
29
+ authorization_protocol = "Protocolo de autorização\n932210002534081 - 01/07/2021 17:39:16-03:00"
30
+
31
+ subject.generate
32
+ expect(pdf_text).to include authorization_protocol
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::Document do
4
+ let(:base_dir) { './spec/fixtures/mdfe/lib/' }
5
+ let(:output_pdf) { "#{base_dir}output.pdf" }
6
+
7
+ describe '#method_missing' do
8
+ context 'when prawn has the method' do
9
+ it 'does not throws an error' do
10
+ expect(subject).to respond_to :text
11
+ end
12
+ end
13
+
14
+ context 'when prawn does not have the method' do
15
+ it 'throws an error' do
16
+ expect { subject.non_existent_method }.to raise_error NameError
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::Drivers do
4
+ let(:xml_as_string) do
5
+ <<~XML
6
+ <?xml version="1.0" encoding="UTF-8"?>
7
+ <mdfeProc xmlns="http://www.portalfiscal.inf.br/mdfe" versao="3.00">
8
+ <MDFe xmlns="http://www.portalfiscal.inf.br/mdfe">
9
+ <infMDFe Id="MDFe32210717781119000141580010000001211000000003" versao="3.00">
10
+ <infModal versaoModal="3.00">
11
+ <rodo>
12
+ <infANTT/>
13
+ <veicTracao>
14
+ <placa>RQM8B64</placa>
15
+ <RENAVAM>01259587867</RENAVAM>
16
+ <tara>0</tara>
17
+ <capKG>1500</capKG>
18
+ <capM3>0</capM3>
19
+ <condutor>
20
+ <xNome>EDUARDO DANIEL</xNome>
21
+ <CPF>11585756709</CPF>
22
+ </condutor>
23
+ <tpRod>04</tpRod>
24
+ <tpCar>02</tpCar>
25
+ <UF>ES</UF>
26
+ </veicTracao>
27
+ <veicReboque>
28
+ <placa>RVA1B90</placa>
29
+ <RENAVAM>123456789</RENAVAM>
30
+ <tara>0</tara>
31
+ <capKG>1500</capKG>
32
+ <capM3>0</capM3>
33
+ <condutor>
34
+ <xNome>JOAO DA SILVA</xNome>
35
+ <CPF>9876654312</CPF>
36
+ </condutor>
37
+ <tpRod>04</tpRod>
38
+ <tpCar>02</tpCar>
39
+ <UF>SC</UF>
40
+ </veicReboque>
41
+ <veicReboque>
42
+ <placa>DFE4U78</placa>
43
+ <RENAVAM>045784572</RENAVAM>
44
+ <tara>0</tara>
45
+ <capKG>1500</capKG>
46
+ <capM3>0</capM3>
47
+ <condutor>
48
+ <xNome>ANTÔNIO DA SILVA</xNome>
49
+ <CPF>9856478238</CPF>
50
+ </condutor>
51
+ <tpRod>04</tpRod>
52
+ <tpCar>02</tpCar>
53
+ <UF>SC</UF>
54
+ </veicReboque>
55
+ </rodo>
56
+ </infModal>
57
+ </infMDFe>
58
+ </MDFe>
59
+ </mdfeProc>
60
+ XML
61
+ end
62
+
63
+ let(:pdf) { BrDanfe::MdfeLib::Document.new }
64
+ let(:xml) { BrDanfe::XML.new(xml_as_string) }
65
+
66
+ subject { described_class.new(pdf, xml) }
67
+
68
+ let(:pdf_text) do
69
+ PDF::Inspector::Text.analyze(pdf.render).strings.join("\n")
70
+ end
71
+
72
+ describe '#generate' do
73
+ it 'generates the title' do
74
+ title = 'Condutor'
75
+
76
+ subject.generate
77
+ expect(pdf_text).to include title
78
+ end
79
+
80
+ it 'generates the title of table' do
81
+ cpf = 'CPF'
82
+ name = 'Nome'
83
+
84
+ subject.generate
85
+ expect(pdf_text).to include cpf, name
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::FiscoControl do
4
+ let(:base_dir) { './spec/fixtures/mdfe/lib/' }
5
+ let(:output_pdf) { "#{base_dir}output.pdf" }
6
+
7
+ let(:xml_as_string) do
8
+ <<~XML
9
+ <?xml version="1.0" encoding="UTF-8"?>
10
+ <mdfeProc xmlns="http://www.portalfiscal.inf.br/mdfe" versao="3.00">
11
+ <protMDFe versao="3.00" xmlns="http://www.portalfiscal.inf.br/mdfe">
12
+ <infProt Id="MDFe932210002534081">
13
+ <chMDFe>32210717781119000141580010000001211000000003</chMDFe>
14
+ </infProt>
15
+ </protMDFe>
16
+ </mdfeProc>
17
+ XML
18
+ end
19
+
20
+ let(:pdf) { BrDanfe::MdfeLib::Document.new }
21
+ let(:xml) { BrDanfe::XML.new(xml_as_string) }
22
+
23
+ subject { described_class.new(pdf, xml) }
24
+
25
+ let(:pdf_text) do
26
+ PDF::Inspector::Text.analyze(pdf.render).strings.join("\n")
27
+ end
28
+
29
+ describe '#generate' do
30
+ before { File.delete(output_pdf) if File.exist?(output_pdf) }
31
+
32
+ it 'generates the title' do
33
+ subject.generate
34
+ expect(pdf_text).to include 'CONTROLE DO FISCO'
35
+ end
36
+
37
+ it 'generates the bar code' do
38
+ expect(File.exist?(output_pdf)).to be false
39
+
40
+ subject.generate
41
+ pdf.render_file output_pdf
42
+
43
+ expect("#{base_dir}fisco_control#barcode.pdf").to have_same_content_of file: output_pdf
44
+ end
45
+
46
+ it 'generates the nfe key' do
47
+ subject.generate
48
+ expect(pdf_text).to include "Chave de Acesso\n32210717781119000141580010000001211000000003"
49
+ end
50
+
51
+ context 'when the XML does not have protMDFe tag' do
52
+ let(:xml_as_string) do
53
+ <<~XML
54
+ <?xml version="1.0" encoding="UTF-8"?>
55
+ <mdfeProc xmlns="http://www.portalfiscal.inf.br/mdfe" versao="3.00"></mdfeProc>
56
+ XML
57
+ end
58
+
59
+ it 'does not generate the bar code and the nfe key' do
60
+ expect(File.exist?(output_pdf)).to be false
61
+
62
+ subject.generate
63
+ pdf.render_file output_pdf
64
+
65
+ expect("#{base_dir}fisco_control#without-barcode.pdf").to have_same_content_of file: output_pdf
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::Header do
4
+ let(:qr_code_mdfe) do
5
+ url = 'https://dfe-portal.svrs.rs.gov.br/mdfe/QRCode?chMDFe=32210717781119000141580010000001211000000003&amp;tpAmb=1'
6
+ "<qrCodMDFe>#{url}</qrCodMDFe>"
7
+ end
8
+ let(:xml_as_string) do
9
+ <<~XML
10
+ <?xml version="1.0" encoding="UTF-8"?>
11
+ <mdfeProc xmlns="http://www.portalfiscal.inf.br/mdfe" versao="3.00">
12
+ <MDFe xmlns="http://www.portalfiscal.inf.br/mdfe">
13
+ <infMDFe Id="MDFe32210717781119000141580010000001211000000003" versao="3.00">
14
+ <ide>
15
+ <mod>58</mod>
16
+ <serie>1</serie>
17
+ <nMDF>121</nMDF>
18
+ <cMDF>00000000</cMDF>
19
+ <dhEmi>2021-07-01T17:30:00-03:00</dhEmi>
20
+ <UFIni>ES</UFIni>
21
+ <UFFim>ES</UFFim>
22
+ </ide>
23
+ <emit>
24
+ <CNPJ>17781119000141</CNPJ>
25
+ <IE>082942625</IE>
26
+ <xNome>VENTURIM AGROCRIATIVA LTDA EPP</xNome>
27
+ <xFant>VENTURIM CONSERVAS</xFant>
28
+ <enderEmit>
29
+ <xLgr>RODOVIA ES 473 KM 13</xLgr>
30
+ <nro>0</nro>
31
+ <cMun>3205069</cMun>
32
+ <xMun>VENDA NOVA DO IMIGRANTE</xMun>
33
+ <CEP>29375000</CEP>
34
+ <UF>ES</UF>
35
+ </enderEmit>
36
+ </emit>
37
+ </infMDFe>
38
+ <infMDFeSupl>
39
+ #{qr_code_mdfe}
40
+ </infMDFeSupl>
41
+ </MDFe>
42
+ </mdfeProc>
43
+ XML
44
+ end
45
+ let(:pdf) { BrDanfe::MdfeLib::Document.new }
46
+ let(:xml) { BrDanfe::XML.new(xml_as_string) }
47
+ let(:logo_dimensions) { { width: 100, height: 100 } }
48
+ let(:logo) { 'spec/fixtures/logo.png' }
49
+
50
+ subject { described_class.new(pdf, xml, logo, logo_dimensions) }
51
+
52
+ let(:pdf_text) do
53
+ PDF::Inspector::Text.analyze(pdf.render).strings.join("\n")
54
+ end
55
+
56
+ describe '#generate' do
57
+ let(:base_dir) { './spec/fixtures/mdfe/lib/' }
58
+ let(:output_pdf) { "#{base_dir}output.pdf" }
59
+
60
+ before { File.delete(output_pdf) if File.exist?(output_pdf) }
61
+
62
+ it 'generates the emitter informations' do
63
+ emitter_name = 'VENTURIM AGROCRIATIVA LTDA EPP'
64
+ emitter_address = "RODOVIA ES 473 KM 13, nº 0\nVENDA NOVA DO IMIGRANTE - ES CEP 29.375-000"
65
+
66
+ emitter_cnpj = "CNPJ: \n17781119000141"
67
+ emitter_ie = "IE: \n082942625"
68
+
69
+ subject.generate
70
+
71
+ expect(pdf_text).to include emitter_name
72
+ expect(pdf_text).to include emitter_address
73
+ expect(pdf_text).to include emitter_cnpj
74
+ expect(pdf_text).to include emitter_ie
75
+ end
76
+
77
+ it 'generates the DAMDFE title' do
78
+ subject.generate
79
+ expect(pdf_text).to include "DAMDFE\n - Documento Auxiliar de Manifesto Eletrônico de Documentos Fiscais"
80
+ end
81
+
82
+ it 'generates the QR-code' do
83
+ expect(File.exist?(output_pdf)).to be false
84
+
85
+ subject.generate
86
+ pdf.render_file output_pdf
87
+
88
+ expect("#{base_dir}header#render-qr-code.pdf").to have_same_content_of file: output_pdf
89
+ end
90
+
91
+ context 'if the QR-code URL is not present' do
92
+ let(:qr_code_mdfe) { '<qrCodMDFe></qrCodMDFe>' }
93
+
94
+ it 'does not generates the QR-code' do
95
+ expect(File.exist?(output_pdf)).to be false
96
+
97
+ subject.generate
98
+ pdf.render_file output_pdf
99
+
100
+ expect("#{base_dir}header#render-without-qr-code.pdf").to have_same_content_of file: output_pdf
101
+ end
102
+ end
103
+
104
+ it 'generates the company CNPJ' do
105
+ subject.generate
106
+ expect(pdf_text).to include "CNPJ: \n17781119000141"
107
+ end
108
+
109
+ describe 'logo' do
110
+ context 'with logo' do
111
+ it 'generates the logo' do
112
+ expect(File.exist?(output_pdf)).to be false
113
+
114
+ subject.generate
115
+ pdf.render_file output_pdf
116
+
117
+ expect("#{base_dir}header#render-with_logo.pdf").to have_same_content_of file: output_pdf
118
+ end
119
+ end
120
+
121
+ context 'without logo' do
122
+ let(:logo) { '' }
123
+
124
+ it 'does not generate the logo' do
125
+ expect(File.exist?(output_pdf)).to be false
126
+
127
+ subject.generate
128
+ pdf.render_file output_pdf
129
+
130
+ expect("#{base_dir}header#render-without_logo.pdf").to have_same_content_of file: output_pdf
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::MdfeIdentification do
4
+ let(:xml_as_string) do
5
+ <<~XML
6
+ <?xml version="1.0" encoding="UTF-8"?>
7
+ <mdfeProc xmlns="http://www.portalfiscal.inf.br/mdfe" versao="3.00">
8
+ <MDFe xmlns="http://www.portalfiscal.inf.br/mdfe">
9
+ <infMDFe Id="MDFe32210717781119000141580010000001211000000003" versao="3.00">
10
+ <ide>
11
+ <cUF>32</cUF>
12
+ <tpAmb>1</tpAmb>
13
+ <tpEmit>2</tpEmit>
14
+ <mod>58</mod>
15
+ <serie>1</serie>
16
+ <nMDF>121</nMDF>
17
+ <cMDF>00000000</cMDF>
18
+ <cDV>3</cDV>
19
+ <modal>1</modal>
20
+ <dhEmi>2021-07-01T17:30:00-03:00</dhEmi>
21
+ <tpEmis>1</tpEmis>
22
+ <procEmi>0</procEmi>
23
+ <verProc>hivelog-mdfe-0.1.0</verProc>
24
+ <UFIni>ES</UFIni>
25
+ <UFFim>SC</UFFim>
26
+ <infMunCarrega>
27
+ <cMunCarrega>3205069</cMunCarrega>
28
+ <xMunCarrega>VENDA NOVA DO IMIGRANTE</xMunCarrega>
29
+ </infMunCarrega>
30
+ <dhIniViagem>2021-07-01T17:30:00-03:00</dhIniViagem>
31
+ </ide>
32
+ </infMDFe>
33
+ </MDFe>
34
+ </mdfeProc>
35
+ XML
36
+ end
37
+
38
+ let(:pdf) { BrDanfe::MdfeLib::Document.new }
39
+ let(:xml) { BrDanfe::XML.new(xml_as_string) }
40
+
41
+ subject { described_class.new(pdf, xml) }
42
+
43
+ let(:pdf_text) do
44
+ PDF::Inspector::Text.analyze(pdf.render).strings.join("\n")
45
+ end
46
+
47
+ describe '#generate' do
48
+ it 'generates the model' do
49
+ model = "Modelo\n58"
50
+
51
+ subject.generate(1)
52
+
53
+ expect(pdf_text).to include model
54
+ end
55
+
56
+ it 'generates the series' do
57
+ series = "Série\n1"
58
+
59
+ subject.generate(1)
60
+
61
+ expect(pdf_text).to include series
62
+ end
63
+
64
+ it 'generates the number' do
65
+ number = "Número\n121"
66
+
67
+ subject.generate(1)
68
+
69
+ expect(pdf_text).to include number
70
+ end
71
+
72
+ it 'generates the page number' do
73
+ pages = "FL\n1/1"
74
+
75
+ subject.generate(1)
76
+
77
+ expect(pdf_text).to include pages
78
+ end
79
+
80
+ it 'generates the emitted date and hour' do
81
+ datetime = "Data e hora de Emissão\n01/07/2021 17:30:00"
82
+
83
+ subject.generate(1)
84
+
85
+ expect(pdf_text).to include datetime
86
+ end
87
+
88
+ it 'generates the origin uf' do
89
+ origin_uf = "UF Carreg.\nES"
90
+
91
+ subject.generate(1)
92
+
93
+ expect(pdf_text).to include origin_uf
94
+ end
95
+
96
+ it 'generates the destination uf' do
97
+ destination_uf = "UF Descarreg.\nSC"
98
+
99
+ subject.generate(1)
100
+
101
+ expect(pdf_text).to include destination_uf
102
+ end
103
+ end
104
+ end