br_danfe 0.14.5 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tool-versions +1 -0
- data/Gemfile.lock +47 -36
- data/Guardfile +2 -2
- data/README.md +39 -0
- data/br_danfe.gemspec +6 -5
- data/lib/br_danfe/danfe.rb +8 -5
- data/lib/br_danfe/danfe_lib/base.rb +2 -2
- data/lib/br_danfe/danfe_lib/nfce.rb +15 -13
- data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +1 -1
- data/lib/br_danfe/danfe_lib/nfce_lib/footer.rb +2 -2
- data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +24 -10
- data/lib/br_danfe/danfe_lib/nfce_lib/key.rb +3 -3
- data/lib/br_danfe/danfe_lib/nfce_lib/nfce_identification.rb +3 -3
- data/lib/br_danfe/danfe_lib/nfce_lib/product_list.rb +44 -53
- data/lib/br_danfe/danfe_lib/nfce_lib/recipient.rb +1 -1
- data/lib/br_danfe/danfe_lib/nfce_lib/total_list.rb +16 -15
- data/lib/br_danfe/danfe_lib/nfe.rb +39 -27
- data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +1 -1
- data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +5 -5
- data/lib/br_danfe/document_builder.rb +1 -1
- data/lib/br_danfe/helper.rb +11 -7
- data/lib/br_danfe/mdfe.rb +55 -0
- data/lib/br_danfe/mdfe_lib/authorization_protocol.rb +24 -0
- data/lib/br_danfe/mdfe_lib/document.rb +26 -0
- data/lib/br_danfe/mdfe_lib/drivers.rb +70 -0
- data/lib/br_danfe/mdfe_lib/fisco_control.rb +40 -0
- data/lib/br_danfe/mdfe_lib/header.rb +78 -0
- data/lib/br_danfe/mdfe_lib/mdfe_identification.rb +69 -0
- data/lib/br_danfe/mdfe_lib/notes.rb +94 -0
- data/lib/br_danfe/mdfe_lib/totalizer.rb +57 -0
- data/lib/br_danfe/mdfe_lib/vehicles.rb +80 -0
- data/lib/br_danfe/qr_code.rb +22 -0
- data/lib/br_danfe/version.rb +1 -1
- data/lib/br_danfe.rb +1 -1
- data/spec/br_danfe/danfe_lib/nfce_lib/header_spec.rb +1 -1
- data/spec/br_danfe/danfe_lib/nfce_spec.rb +12 -1
- data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +2 -2
- data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +3 -3
- data/spec/br_danfe/danfe_lib/nfe_spec.rb +17 -1
- data/spec/br_danfe/danfe_spec.rb +16 -0
- data/spec/br_danfe/helper_spec.rb +12 -0
- data/spec/br_danfe/mdfe_lib/authorization_protocol_spec.rb +35 -0
- data/spec/br_danfe/mdfe_lib/document_spec.rb +20 -0
- data/spec/br_danfe/mdfe_lib/drivers_spec.rb +88 -0
- data/spec/br_danfe/mdfe_lib/fisco_control_spec.rb +55 -0
- data/spec/br_danfe/mdfe_lib/header_spec.rb +126 -0
- data/spec/br_danfe/mdfe_lib/mdfe_identification_spec.rb +104 -0
- data/spec/br_danfe/mdfe_lib/notes_spec.rb +97 -0
- data/spec/br_danfe/mdfe_lib/totalizer_spec.rb +63 -0
- data/spec/br_danfe/mdfe_lib/vehicles_spec.rb +66 -0
- data/spec/br_danfe/mdfe_spec.rb +46 -0
- data/spec/br_danfe/{danfe_lib/nfce_lib/qr_code_spec.rb → qr_code_spec.rb} +10 -5
- data/spec/fixtures/cce/lib/barcode#render.pdf +5 -3
- data/spec/fixtures/cce/v1.00/cce.fixture.pdf +15 -13
- data/spec/fixtures/mdfe/lib/document#render.pdf +0 -0
- data/spec/fixtures/mdfe/lib/document#text.align.pdf +0 -0
- data/spec/fixtures/mdfe/lib/document#text.pad.pdf +0 -0
- data/spec/fixtures/mdfe/lib/document#text.simple.pdf +0 -0
- data/spec/fixtures/mdfe/lib/document#text.size.pdf +0 -0
- data/spec/fixtures/mdfe/lib/document#text.style.pdf +0 -0
- data/spec/fixtures/mdfe/lib/fisco_control#barcode.pdf +0 -0
- data/spec/fixtures/mdfe/lib/header#render-qr-code.pdf +0 -0
- data/spec/fixtures/mdfe/lib/header#render-with_logo.pdf +0 -0
- data/spec/fixtures/mdfe/lib/header#render-without_logo.pdf +0 -0
- data/spec/fixtures/mdfe/lib/mdfe-with-multiple-pages.pdf +1945 -0
- data/spec/fixtures/mdfe/lib/mdfe.fixture.pdf +1286 -0
- data/spec/fixtures/mdfe/lib/notes#render-big-aditional-information.pdf +1943 -0
- data/spec/fixtures/mdfe/lib/xml-mdfe-multiples-pages.xml +116 -0
- data/spec/fixtures/mdfe/lib/xml-mdfe.xml +250 -0
- data/spec/fixtures/nfce/lib/document#render.pdf +22 -33
- data/spec/fixtures/nfce/lib/footer#render-with_additional_information.pdf +0 -0
- data/spec/fixtures/nfce/lib/footer#render.pdf +0 -0
- data/spec/fixtures/nfce/lib/header#render-homologation.pdf +0 -0
- data/spec/fixtures/nfce/lib/header#render-long_name_with_logo.pdf +0 -0
- data/spec/fixtures/nfce/lib/header#render-long_name_without_logo.pdf +0 -0
- data/spec/fixtures/nfce/lib/header#render-short_name_with_logo.pdf +0 -0
- data/spec/fixtures/nfce/lib/header#render-short_name_without_logo.pdf +0 -0
- data/spec/fixtures/nfce/lib/key#render.pdf +0 -0
- data/spec/fixtures/nfce/lib/nfce_identification#render.pdf +0 -0
- data/spec/fixtures/nfce/lib/product_list#render-with_many_products.pdf +0 -0
- data/spec/fixtures/nfce/lib/product_list#render-with_many_products_and_long_names.pdf +0 -0
- data/spec/fixtures/nfce/lib/product_list#render-with_single_product.pdf +0 -0
- data/spec/fixtures/nfce/lib/product_list#render-with_single_product_and_long_name.pdf +0 -0
- data/spec/fixtures/nfce/lib/product_list_with_many_products_and_long_names.xml +2 -2
- data/spec/fixtures/nfce/lib/product_list_with_single_product_and_long_name.xml +1 -1
- data/spec/fixtures/nfce/lib/qr_code#render.pdf +0 -0
- data/spec/fixtures/nfce/lib/recipient#render-company.pdf +0 -0
- data/spec/fixtures/nfce/lib/recipient#render-consumer_without_document.pdf +0 -0
- data/spec/fixtures/nfce/lib/recipient#render-foreign.pdf +0 -0
- data/spec/fixtures/nfce/lib/recipient#render-individual.pdf +0 -0
- data/spec/fixtures/nfce/lib/recipient#render-unidentified_consumer.pdf +0 -0
- data/spec/fixtures/nfce/lib/total_list#does_not_render-payment_methods.pdf +0 -0
- data/spec/fixtures/nfce/lib/total_list#render-grouped_payment_methods.pdf +0 -0
- data/spec/fixtures/nfce/lib/total_list#render-totals.pdf +0 -0
- data/spec/fixtures/nfce/lib/total_list#render-without_payment.pdf +0 -0
- data/spec/fixtures/nfce/lib/total_list#render.pdf +0 -0
- data/spec/fixtures/nfce/v4.00/multiples_xmls_on_the_same_pdf.pdf +1350 -0
- data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.fixture.pdf +0 -0
- data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.fixture.pdf +0 -0
- data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
- data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-v4.00.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf +0 -0
- data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +662 -662
- data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +410 -410
- data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +272 -272
- data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +272 -272
- data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +270 -270
- data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +6213 -6213
- data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +6083 -6083
- data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +270 -270
- data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +272 -272
- data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +2859 -2859
- data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +2859 -2859
- data/spec/fixtures/nfe/lib/document#lcnpj-blank.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lcnpj-invalid.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lcnpj-valid.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lie-blank-uf-invalid.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lie-blank.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lie-valid.pdf +0 -0
- data/spec/fixtures/nfe/lib/dup#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +511 -509
- data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +510 -508
- data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +507 -505
- data/spec/fixtures/nfe/lib/icmstot#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#address-shipment.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-difal.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-with_complementary_information.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-with_fisco_additional_information.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-with_street_data.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic_vol#render-extra_volume.pdf +0 -0
- data/spec/fixtures/nfe/lib/issqn#render-with_issqn.pdf +0 -0
- data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +0 -0
- data/spec/fixtures/nfe/lib/ticket#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_3.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_4.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +0 -0
- data/spec/fixtures/nfe/lib/vol#render.pdf +0 -0
- data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +733 -733
- data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +730 -730
- data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +3449 -3445
- data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +929 -927
- data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +3424 -3420
- data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +1178 -1176
- data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +11471 -0
- data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +1495 -1495
- data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +2444 -2444
- data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +2142 -2142
- data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +7096 -7096
- data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +2811 -2811
- data/spec/fixtures/qr_code/qr_code#render.pdf +0 -0
- metadata +92 -41
- data/lib/br_danfe/danfe_lib/nfce_lib/qr_code.rb +0 -25
- data/lib/br_danfe/danfe_lib/nfe_lib/cep.rb +0 -11
- data/spec/br_danfe/danfe_lib/nfe_lib/cep_spec.rb +0 -10
@@ -0,0 +1,80 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module MdfeLib
|
3
|
+
class Vehicles
|
4
|
+
def initialize(pdf, xml)
|
5
|
+
@pdf = pdf
|
6
|
+
@xml = xml
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate
|
10
|
+
@pdf.move_cursor_to 460
|
11
|
+
title
|
12
|
+
table_titles
|
13
|
+
generate_vehicles
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def title
|
19
|
+
title = 'Veículo'
|
20
|
+
|
21
|
+
@pdf.text_box(title, size: 12, align: :left, style: :bold, at: [0, @pdf.cursor])
|
22
|
+
end
|
23
|
+
|
24
|
+
def table_titles
|
25
|
+
plate = 'Placa'
|
26
|
+
rntrc = 'RNTRC'
|
27
|
+
|
28
|
+
@pdf.stroke_color GRAY_COLOR
|
29
|
+
@pdf.move_down 20
|
30
|
+
@pdf.text_box(plate, size: 9, align: :left, at: [0, @pdf.cursor])
|
31
|
+
@pdf.text_box(rntrc, size: 9, align: :left, at: [100, @pdf.cursor])
|
32
|
+
@pdf.move_down 10
|
33
|
+
@pdf.stroke_horizontal_line(0, 190, at: @pdf.cursor)
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_vehicles
|
37
|
+
@pdf.move_cursor_to 425
|
38
|
+
|
39
|
+
vehicles.each_with_index do |cell, index|
|
40
|
+
@pdf.bounding_box [0, @pdf.cursor], width: 190, height: 20 do
|
41
|
+
@pdf.stroke_color GRAY_COLOR
|
42
|
+
@pdf.dash([2], phase: 6)
|
43
|
+
@pdf.stroke_horizontal_line(0, 190, at: 26) unless index.zero?
|
44
|
+
@pdf.text cell[:content], cell[:options]
|
45
|
+
@pdf.undash
|
46
|
+
@pdf.move_down 20
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def vehicles
|
52
|
+
vehicle = []
|
53
|
+
vehicle += collect_vehicles('veicReboque')
|
54
|
+
vehicle += collect_vehicles('veicTracao')
|
55
|
+
|
56
|
+
vehicle
|
57
|
+
end
|
58
|
+
|
59
|
+
def collect_vehicles(tag)
|
60
|
+
vehicles = []
|
61
|
+
@xml.collect('xmlns', tag) { |rodo| vehicles += vehicle(rodo) }
|
62
|
+
|
63
|
+
vehicles
|
64
|
+
end
|
65
|
+
|
66
|
+
def vehicle(rodo)
|
67
|
+
[
|
68
|
+
cell_text(rodo.css('placa').text)
|
69
|
+
]
|
70
|
+
end
|
71
|
+
|
72
|
+
def cell_text(text, options = {})
|
73
|
+
cell = { content: text, options: { size: 12 } }
|
74
|
+
cell[:options].merge!(options)
|
75
|
+
|
76
|
+
cell
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
class QrCode
|
3
|
+
require 'rqrcode'
|
4
|
+
require 'chunky_png'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
def initialize(pdf:, xml:, qr_code_tag:, box_size:)
|
8
|
+
@pdf = pdf
|
9
|
+
@xml = xml
|
10
|
+
@qr_code_tag = qr_code_tag
|
11
|
+
@box_size = box_size
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
qrcode = RQRCode::QRCode.new(@qr_code_tag)
|
16
|
+
image = Tempfile.new(%w[qrcode png], binmode: true)
|
17
|
+
image.write(qrcode.as_png(module_px_size: 12).to_s)
|
18
|
+
|
19
|
+
@pdf.image(image, width: @box_size, height: @box_size, position: :center)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/br_danfe/version.rb
CHANGED
data/lib/br_danfe.rb
CHANGED
@@ -42,7 +42,7 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
|
|
42
42
|
BrDanfe::XML.new(xml)
|
43
43
|
end
|
44
44
|
|
45
|
-
let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm,
|
45
|
+
let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 6.cm) }
|
46
46
|
|
47
47
|
subject { described_class.new pdf, xml, logo, logo_options }
|
48
48
|
|
@@ -5,7 +5,7 @@ describe BrDanfe::DanfeLib::Nfce do
|
|
5
5
|
let(:base_dir) { './spec/fixtures/nfce/v4.00/' }
|
6
6
|
let(:xml) { BrDanfe::XML.new(File.read("#{base_dir}nfce.xml")) }
|
7
7
|
|
8
|
-
subject { described_class.new xml }
|
8
|
+
subject { described_class.new [xml] }
|
9
9
|
|
10
10
|
before do
|
11
11
|
subject.options.logo = 'spec/fixtures/logo.png'
|
@@ -53,5 +53,16 @@ describe BrDanfe::DanfeLib::Nfce do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
context 'when there is more than one xml' do
|
58
|
+
it 'renders multiple danfes on the same pdf' do
|
59
|
+
subject = described_class.new [xml, xml]
|
60
|
+
|
61
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
62
|
+
subject.save_pdf output_pdf
|
63
|
+
|
64
|
+
expect("#{base_dir}multiples_xmls_on_the_same_pdf.pdf").to have_same_content_of file: output_pdf
|
65
|
+
end
|
66
|
+
end
|
56
67
|
end
|
57
68
|
end
|
@@ -53,7 +53,7 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
|
|
53
53
|
|
54
54
|
context 'render emitter on first page' do
|
55
55
|
before do
|
56
|
-
subject.render 1, 3.96
|
56
|
+
subject.render 1, 3.96, 1
|
57
57
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
58
58
|
end
|
59
59
|
|
@@ -82,7 +82,7 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
|
|
82
82
|
|
83
83
|
context 'render emitter on second page' do
|
84
84
|
before do
|
85
|
-
subject.render 2, 1.85
|
85
|
+
subject.render 2, 1.85, 2
|
86
86
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
87
87
|
end
|
88
88
|
|
@@ -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
|
-
|
364
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
365
365
|
|
366
|
-
|
366
|
+
pdf.render_file output_pdf
|
367
367
|
|
368
|
-
|
368
|
+
expect("#{base_dir}infadic#address-shipment.pdf").to have_same_content_of file: output_pdf
|
369
369
|
end
|
370
370
|
end
|
371
371
|
|
@@ -5,7 +5,7 @@ describe BrDanfe::DanfeLib::Nfe do
|
|
5
5
|
let(:xml_file) {}
|
6
6
|
let(:xml) { BrDanfe::XML.new(xml_file) }
|
7
7
|
|
8
|
-
subject { described_class.new xml }
|
8
|
+
subject { described_class.new [xml] }
|
9
9
|
|
10
10
|
describe '#render_pdf' do
|
11
11
|
let(:base_dir) { './spec/fixtures/nfe/v3.10/' }
|
@@ -152,5 +152,21 @@ describe BrDanfe::DanfeLib::Nfe do
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
155
|
+
|
156
|
+
context 'when there is more than one xml' do
|
157
|
+
let(:base_dir) { './spec/fixtures/nfe/v3.10/' }
|
158
|
+
let(:xml_file) { File.read("#{base_dir}nfe_simples_nacional.xml") }
|
159
|
+
|
160
|
+
before { File.delete(output_pdf) if File.exist?(output_pdf) }
|
161
|
+
|
162
|
+
it 'renders multiple danfes on the same pdf' do
|
163
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
164
|
+
subject = described_class.new([xml, xml])
|
165
|
+
|
166
|
+
subject.save_pdf(output_pdf)
|
167
|
+
|
168
|
+
expect("#{base_dir}multiples.xmls.on.the.same.pdf.pdf").to have_same_content_of file: output_pdf
|
169
|
+
end
|
170
|
+
end
|
155
171
|
end
|
156
172
|
end
|
data/spec/br_danfe/danfe_spec.rb
CHANGED
@@ -22,6 +22,22 @@ describe BrDanfe::Danfe do
|
|
22
22
|
|
23
23
|
subject { described_class.new(xml) }
|
24
24
|
|
25
|
+
context 'xmls parameter' do
|
26
|
+
let(:mod) { 55 }
|
27
|
+
|
28
|
+
it 'accepts one xml' do
|
29
|
+
subject = described_class.new(xml)
|
30
|
+
|
31
|
+
expect(subject.class).to eq BrDanfe::DanfeLib::Nfe
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'accepts an array of xmls' do
|
35
|
+
subject = described_class.new([xml, xml])
|
36
|
+
|
37
|
+
expect(subject.class).to eq BrDanfe::DanfeLib::Nfe
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
25
41
|
context 'when the xml document type is NF-e' do
|
26
42
|
let(:mod) { 55 }
|
27
43
|
|
@@ -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
|