br_danfe 0.15.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.tool-versions +1 -0
  3. data/Gemfile.lock +35 -22
  4. data/Guardfile +2 -2
  5. data/README.md +23 -0
  6. data/br_danfe.gemspec +3 -2
  7. data/lib/br_danfe.rb +1 -1
  8. data/lib/br_danfe/danfe_lib/nfce.rb +1 -1
  9. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +1 -1
  10. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +1 -1
  11. data/lib/br_danfe/document_builder.rb +1 -1
  12. data/lib/br_danfe/helper.rb +7 -9
  13. data/lib/br_danfe/mdfe.rb +55 -0
  14. data/lib/br_danfe/mdfe_lib/authorization_protocol.rb +24 -0
  15. data/lib/br_danfe/mdfe_lib/document.rb +26 -0
  16. data/lib/br_danfe/mdfe_lib/drivers.rb +70 -0
  17. data/lib/br_danfe/mdfe_lib/fisco_control.rb +40 -0
  18. data/lib/br_danfe/mdfe_lib/header.rb +78 -0
  19. data/lib/br_danfe/mdfe_lib/mdfe_identification.rb +69 -0
  20. data/lib/br_danfe/mdfe_lib/notes.rb +94 -0
  21. data/lib/br_danfe/mdfe_lib/totalizer.rb +57 -0
  22. data/lib/br_danfe/mdfe_lib/vehicles.rb +80 -0
  23. data/lib/br_danfe/qr_code.rb +22 -0
  24. data/lib/br_danfe/version.rb +1 -1
  25. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +3 -3
  26. data/spec/br_danfe/helper_spec.rb +12 -0
  27. data/spec/br_danfe/mdfe_lib/authorization_protocol_spec.rb +35 -0
  28. data/spec/br_danfe/mdfe_lib/document_spec.rb +20 -0
  29. data/spec/br_danfe/mdfe_lib/drivers_spec.rb +88 -0
  30. data/spec/br_danfe/mdfe_lib/fisco_control_spec.rb +55 -0
  31. data/spec/br_danfe/mdfe_lib/header_spec.rb +126 -0
  32. data/spec/br_danfe/mdfe_lib/mdfe_identification_spec.rb +104 -0
  33. data/spec/br_danfe/mdfe_lib/notes_spec.rb +97 -0
  34. data/spec/br_danfe/mdfe_lib/totalizer_spec.rb +63 -0
  35. data/spec/br_danfe/mdfe_lib/vehicles_spec.rb +66 -0
  36. data/spec/br_danfe/mdfe_spec.rb +46 -0
  37. data/spec/br_danfe/{danfe_lib/nfce_lib/qr_code_spec.rb → qr_code_spec.rb} +10 -5
  38. data/spec/fixtures/mdfe/lib/document#render.pdf +0 -0
  39. data/spec/fixtures/mdfe/lib/document#text.align.pdf +0 -0
  40. data/spec/fixtures/mdfe/lib/document#text.pad.pdf +0 -0
  41. data/spec/fixtures/mdfe/lib/document#text.simple.pdf +0 -0
  42. data/spec/fixtures/mdfe/lib/document#text.size.pdf +0 -0
  43. data/spec/fixtures/mdfe/lib/document#text.style.pdf +0 -0
  44. data/spec/fixtures/mdfe/lib/fisco_control#barcode.pdf +0 -0
  45. data/spec/fixtures/mdfe/lib/header#render-qr-code.pdf +0 -0
  46. data/spec/fixtures/mdfe/lib/header#render-with_logo.pdf +0 -0
  47. data/spec/fixtures/mdfe/lib/header#render-without_logo.pdf +0 -0
  48. data/spec/fixtures/mdfe/lib/mdfe-with-multiple-pages.pdf +1945 -0
  49. data/spec/fixtures/mdfe/lib/mdfe.fixture.pdf +1286 -0
  50. data/spec/fixtures/mdfe/lib/notes#render-big-aditional-information.pdf +1943 -0
  51. data/spec/fixtures/mdfe/lib/xml-mdfe-multiples-pages.xml +116 -0
  52. data/spec/fixtures/mdfe/lib/xml-mdfe.xml +250 -0
  53. data/spec/fixtures/qr_code/qr_code#render.pdf +0 -0
  54. metadata +83 -34
  55. data/lib/br_danfe/danfe_lib/nfce_lib/qr_code.rb +0 -25
  56. data/lib/br_danfe/danfe_lib/nfe_lib/cep.rb +0 -11
  57. data/spec/br_danfe/danfe_lib/nfe_lib/cep_spec.rb +0 -10
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '0.15.1'.freeze
2
+ VERSION = '0.16.0'.freeze
3
3
  end
@@ -361,11 +361,11 @@ describe BrDanfe::DanfeLib::NfeLib::Infadic do
361
361
  end
362
362
 
363
363
  it 'renders title with box, subtitle, fisco box and address shipment information on the pdf' do
364
- expect(File.exist?(output_pdf)).to be_falsey
364
+ expect(File.exist?(output_pdf)).to be_falsey
365
365
 
366
- pdf.render_file output_pdf
366
+ pdf.render_file output_pdf
367
367
 
368
- expect("#{base_dir}infadic#address-shipment.pdf").to have_same_content_of file: output_pdf
368
+ expect("#{base_dir}infadic#address-shipment.pdf").to have_same_content_of file: output_pdf
369
369
  end
370
370
  end
371
371
 
@@ -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.text }.not_to raise_error NameError
11
+ end
12
+ end
13
+
14
+ context 'when prawn does not have the method' do
15
+ it 'throws an error' do
16
+ expect { subject.any_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,55 @@
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
+ after { File.delete(output_pdf) if File.exist?(output_pdf) }
31
+
32
+ it 'generates the title' do
33
+ title = 'CONTROLE DO FISCO'
34
+
35
+ subject.generate
36
+ expect(pdf_text).to include title
37
+ end
38
+
39
+ it 'generates the bar code' do
40
+ expect(File.exist?(output_pdf)).to be false
41
+
42
+ subject.generate
43
+ pdf.render_file output_pdf
44
+
45
+ expect("#{base_dir}fisco_control#barcode.pdf").to have_same_content_of file: output_pdf
46
+ end
47
+
48
+ it 'generates the nfe key' do
49
+ nfe_key = "Chave de Acesso\n32210717781119000141580010000001211000000003"
50
+
51
+ subject.generate
52
+ expect(pdf_text).to include nfe_key
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::Header 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
+ <mod>58</mod>
12
+ <serie>1</serie>
13
+ <nMDF>121</nMDF>
14
+ <cMDF>00000000</cMDF>
15
+ <dhEmi>2021-07-01T17:30:00-03:00</dhEmi>
16
+ <UFIni>ES</UFIni>
17
+ <UFFim>ES</UFFim>
18
+ </ide>
19
+ <emit>
20
+ <CNPJ>17781119000141</CNPJ>
21
+ <IE>082942625</IE>
22
+ <xNome>VENTURIM AGROCRIATIVA LTDA EPP</xNome>
23
+ <xFant>VENTURIM CONSERVAS</xFant>
24
+ <enderEmit>
25
+ <xLgr>RODOVIA ES 473 KM 13</xLgr>
26
+ <nro>0</nro>
27
+ <cMun>3205069</cMun>
28
+ <xMun>VENDA NOVA DO IMIGRANTE</xMun>
29
+ <CEP>29375000</CEP>
30
+ <UF>ES</UF>
31
+ </enderEmit>
32
+ </emit>
33
+ </infMDFe>
34
+ <infMDFeSupl>
35
+ <qrCodMDFe>https://dfe-portal.svrs.rs.gov.br/mdfe/QRCode?chMDFe=32210717781119000141580010000001211000000003&amp;tpAmb=1</qrCodMDFe>
36
+ </infMDFeSupl>
37
+ </MDFe>
38
+ </mdfeProc>
39
+ XML
40
+ end
41
+
42
+ let(:pdf) { BrDanfe::MdfeLib::Document.new }
43
+ let(:xml) { BrDanfe::XML.new(xml_as_string) }
44
+
45
+ let(:base_dir) { './spec/fixtures/mdfe/lib/' }
46
+ let(:output_pdf) { "#{base_dir}output.pdf" }
47
+
48
+ let(:logo_dimensions) { { width: 100, height: 100 } }
49
+ let(:logo) { 'spec/fixtures/logo.png' }
50
+
51
+ subject { described_class.new(pdf, xml, logo, logo_dimensions) }
52
+
53
+ let(:pdf_text) do
54
+ PDF::Inspector::Text.analyze(pdf.render).strings.join("\n")
55
+ end
56
+
57
+ after { File.delete(output_pdf) if File.exist?(output_pdf) }
58
+
59
+ describe '#generate' do
60
+ it 'generates the emitter informations' do
61
+ emitter_name = 'VENTURIM AGROCRIATIVA LTDA EPP'
62
+ emitter_address = "RODOVIA ES 473 KM 13, nº 0\nVENDA NOVA DO IMIGRANTE - ES CEP 29.375-000"
63
+
64
+ emitter_cnpj = "CNPJ: \n17781119000141"
65
+ emitter_ie = "IE: \n082942625"
66
+
67
+ subject.generate
68
+
69
+ expect(pdf_text).to include emitter_name
70
+ expect(pdf_text).to include emitter_address
71
+ expect(pdf_text).to include emitter_cnpj
72
+ expect(pdf_text).to include emitter_ie
73
+ end
74
+
75
+ it'generates the DAMDFE title' do
76
+ title = "DAMDFE\n - Documento Auxiliar de Manifesto Eletrônico de Documentos Fiscais"
77
+
78
+ subject.generate
79
+
80
+ expect(pdf_text).to include title
81
+ end
82
+
83
+ it 'generates the qr code' do
84
+ expect(File.exist?(output_pdf)).to be false
85
+
86
+ subject.generate
87
+ pdf.render_file output_pdf
88
+
89
+ expect("#{base_dir}header#render-qr-code.pdf").to have_same_content_of file: output_pdf
90
+ end
91
+
92
+ it 'generates the company CNPJ' do
93
+ cnpj = "CNPJ: \n17781119000141"
94
+
95
+ subject.generate
96
+
97
+ expect(pdf_text).to include cnpj
98
+ end
99
+
100
+ describe 'logo' do
101
+ context 'with logo' do
102
+ it 'generates the logo' do
103
+ expect(File.exist?(output_pdf)).to be false
104
+
105
+ subject.generate
106
+ pdf.render_file output_pdf
107
+
108
+ expect("#{base_dir}header#render-with_logo.pdf").to have_same_content_of file: output_pdf
109
+ end
110
+ end
111
+
112
+ context 'without logo' do
113
+ let(:logo) { '' }
114
+
115
+ it 'does not generate the logo' do
116
+ expect(File.exist?(output_pdf)).to be false
117
+
118
+ subject.generate
119
+ pdf.render_file output_pdf
120
+
121
+ expect("#{base_dir}header#render-without_logo.pdf").to have_same_content_of file: output_pdf
122
+ end
123
+ end
124
+ end
125
+ end
126
+ 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