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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +20 -8
- data/.github/dependabot.yml +19 -0
- data/.rubocop.yml +24 -11
- data/.tool-versions +1 -0
- data/Gemfile.lock +69 -50
- data/Guardfile +4 -2
- data/README.md +23 -0
- data/bin/_guard-core +29 -0
- data/bin/guard +29 -0
- data/br_danfe.gemspec +9 -7
- data/lib/br_danfe/danfe_lib/nfce.rb +11 -9
- 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 +30 -16
- 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 +11 -9
- data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +1 -1
- data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +1 -2
- data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +5 -6
- data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +2 -1
- data/lib/br_danfe/document_builder.rb +1 -1
- data/lib/br_danfe/helper.rb +8 -10
- 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 +21 -0
- data/lib/br_danfe/mdfe_lib/header.rb +77 -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 +21 -0
- data/lib/br_danfe/version.rb +1 -1
- data/lib/br_danfe.rb +2 -2
- data/spec/br_danfe/danfe_lib/nfce_lib/footer_spec.rb +3 -2
- data/spec/br_danfe/danfe_lib/nfce_lib/header_spec.rb +6 -4
- data/spec/br_danfe/danfe_lib/nfce_lib/helper_spec.rb +2 -2
- data/spec/br_danfe/danfe_lib/nfce_lib/key_spec.rb +2 -2
- data/spec/br_danfe/danfe_lib/nfce_lib/nfce_identification_spec.rb +2 -2
- data/spec/br_danfe/danfe_lib/nfce_lib/recipient_spec.rb +10 -10
- data/spec/br_danfe/danfe_lib/nfce_lib/total_list_spec.rb +12 -12
- data/spec/br_danfe/danfe_lib/nfce_spec.rb +2 -1
- data/spec/br_danfe/danfe_lib/nfe_lib/cst_spec.rb +4 -4
- data/spec/br_danfe/danfe_lib/nfe_lib/dest_spec.rb +178 -178
- data/spec/br_danfe/danfe_lib/nfe_lib/det_body_spec.rb +274 -274
- data/spec/br_danfe/danfe_lib/nfe_lib/document_spec.rb +77 -77
- data/spec/br_danfe/danfe_lib/nfe_lib/dup_spec.rb +23 -23
- data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +37 -37
- data/spec/br_danfe/danfe_lib/nfe_lib/helper_spec.rb +34 -34
- data/spec/br_danfe/danfe_lib/nfe_lib/icmstot_spec.rb +19 -19
- data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +240 -240
- data/spec/br_danfe/danfe_lib/nfe_lib/infadic_vol_spec.rb +3 -2
- data/spec/br_danfe/danfe_lib/nfe_lib/issqn_spec.rb +16 -16
- data/spec/br_danfe/danfe_lib/nfe_lib/ticket_spec.rb +13 -13
- data/spec/br_danfe/danfe_lib/nfe_lib/transp_spec.rb +76 -76
- data/spec/br_danfe/danfe_lib/nfe_lib/vol_spec.rb +40 -40
- data/spec/br_danfe/danfe_lib/nfe_lib/xprod_spec.rb +118 -118
- data/spec/br_danfe/danfe_spec.rb +2 -2
- data/spec/br_danfe/helper_spec.rb +26 -14
- 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 +69 -0
- data/spec/br_danfe/mdfe_lib/header_spec.rb +135 -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 +45 -0
- data/spec/br_danfe/qr_code_spec.rb +31 -0
- data/spec/br_danfe/xml_spec.rb +6 -6
- 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/fisco_control#without-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-qr-code.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 +12 -23
- 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/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 +568 -447
- 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/qr_code/qr_code#render.pdf +0 -0
- data/spec/spec_helper.rb +1 -1
- metadata +118 -48
- 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/nfce_lib/qr_code_spec.rb +0 -35
- data/spec/br_danfe/danfe_lib/nfe_lib/cep_spec.rb +0 -10
@@ -0,0 +1,69 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module MdfeLib
|
3
|
+
class MdfeIdentification
|
4
|
+
def initialize(pdf, xml)
|
5
|
+
@pdf = pdf
|
6
|
+
@xml = xml
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate(page)
|
10
|
+
model
|
11
|
+
series
|
12
|
+
number
|
13
|
+
number_of_pages(page)
|
14
|
+
emitted_at
|
15
|
+
origin_uf
|
16
|
+
destination_uf
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def model
|
22
|
+
generate_box('Modelo', @xml['ide/mod'], 0)
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate_box(title, text, x_position, width = 40)
|
26
|
+
@pdf.move_cursor_to 655
|
27
|
+
|
28
|
+
@pdf.stroke do
|
29
|
+
@pdf.fill_color LIGHT_GRAY_COLOR
|
30
|
+
@pdf.fill_rectangle([x_position, @pdf.cursor], width, 35)
|
31
|
+
@pdf.fill_color BLACK_COLOR
|
32
|
+
end
|
33
|
+
|
34
|
+
@pdf.bounding_box([x_position, @pdf.cursor], width: width, height: 35) do
|
35
|
+
@pdf.move_down 5
|
36
|
+
@pdf.text_box(title, size: 10, at: [3, @pdf.cursor])
|
37
|
+
@pdf.move_down 15
|
38
|
+
@pdf.text_box(text, size: 12, at: [3, @pdf.cursor])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def series
|
43
|
+
generate_box('Série', @xml['ide/serie'], 40)
|
44
|
+
end
|
45
|
+
|
46
|
+
def number
|
47
|
+
generate_box('Número', @xml['ide/nMDF'], 80)
|
48
|
+
end
|
49
|
+
|
50
|
+
def number_of_pages(page)
|
51
|
+
text = "#{page}/#{@pdf.page_count}"
|
52
|
+
generate_box('FL', text, 125)
|
53
|
+
end
|
54
|
+
|
55
|
+
def emitted_at
|
56
|
+
date = Helper.format_datetime(@xml['dhEmi'])
|
57
|
+
generate_box('Data e hora de Emissão', date, 170, 110)
|
58
|
+
end
|
59
|
+
|
60
|
+
def origin_uf
|
61
|
+
generate_box('UF Carreg.', @xml['ide/UFIni'], 285, 70)
|
62
|
+
end
|
63
|
+
|
64
|
+
def destination_uf
|
65
|
+
generate_box('UF Descarreg.', @xml['ide/UFFim'], 345, 70)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module MdfeLib
|
3
|
+
class Notes
|
4
|
+
MAX_CHARS_ON_LINE = 120
|
5
|
+
|
6
|
+
def initialize(pdf, xml)
|
7
|
+
@pdf = pdf
|
8
|
+
@xml = xml
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate
|
12
|
+
title
|
13
|
+
aditional_information_first_page
|
14
|
+
aditional_information_taxpayer
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def title
|
20
|
+
title = 'Observações'
|
21
|
+
|
22
|
+
@pdf.move_down 20
|
23
|
+
@pdf.bounding_box [0, @pdf.cursor], width: 278, height: 20 do
|
24
|
+
@pdf.stroke_color GRAY_COLOR
|
25
|
+
@pdf.stroke_horizontal_line(0, 526, at: 6)
|
26
|
+
@pdf.text(title, size: 12, align: :left, style: :bold)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def aditional_information_first_page
|
31
|
+
fisco_information = @xml['infAdic/infAdFisco']
|
32
|
+
|
33
|
+
fisco_information_title = 'INFORMAÇÕES ADICIONAIS DE INTERESSE DO FISCO'
|
34
|
+
taxpayer_information_title = 'INFORMAÇÕES ADICIONAIS DE INTERESSE DO CONTRIBUINTE'
|
35
|
+
|
36
|
+
@pdf.bounding_box([0, @pdf.cursor], width: 526) do
|
37
|
+
if fisco_information.present?
|
38
|
+
@pdf.text(fisco_information_title, size: 10)
|
39
|
+
@pdf.move_down 5
|
40
|
+
@pdf.text(fisco_information, size: 10)
|
41
|
+
@pdf.move_down 10
|
42
|
+
end
|
43
|
+
|
44
|
+
if taxpayer_information_xml.present?
|
45
|
+
@pdf.text(taxpayer_information_title, size: 10)
|
46
|
+
@pdf.move_down 5
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def taxpayer_information_xml
|
52
|
+
@taxpayer_information_xml ||= @xml['infAdic/infCpl']
|
53
|
+
end
|
54
|
+
|
55
|
+
def aditional_information_taxpayer
|
56
|
+
first_page, next_page = fill_aditional_information_taxpayer(@pdf.cursor).values_at(:first_page, :next_page)
|
57
|
+
|
58
|
+
generate_aditional_information_taxpayer(first_page, @pdf.cursor)
|
59
|
+
|
60
|
+
if next_page.present?
|
61
|
+
@pdf.start_new_page
|
62
|
+
generate_aditional_information_taxpayer(next_page, y_position_next_pages)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def fill_aditional_information_taxpayer(height_on_first_page)
|
67
|
+
first_page = ''
|
68
|
+
next_page = ''
|
69
|
+
total_chars = 0
|
70
|
+
total_height = 0
|
71
|
+
|
72
|
+
taxpayer_information_xml.split.each do |word|
|
73
|
+
total_chars += word.split.count + 1
|
74
|
+
|
75
|
+
total_height += 10 if total_chars >= MAX_CHARS_ON_LINE
|
76
|
+
|
77
|
+
total_height <= height_on_first_page ? first_page += "#{word} " : next_page += "#{word} "
|
78
|
+
end
|
79
|
+
|
80
|
+
{ first_page: first_page, next_page: next_page }
|
81
|
+
end
|
82
|
+
|
83
|
+
def generate_aditional_information_taxpayer(data, position)
|
84
|
+
@pdf.bounding_box([0, position], width: 526) do
|
85
|
+
@pdf.text(data, size: 10)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def y_position_next_pages
|
90
|
+
600
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module MdfeLib
|
3
|
+
class Totalizer
|
4
|
+
def initialize(pdf, xml)
|
5
|
+
@pdf = pdf
|
6
|
+
@xml = xml
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate
|
10
|
+
generate_title
|
11
|
+
nfe_quantity
|
12
|
+
cte_quantity
|
13
|
+
total_weight
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def generate_title
|
19
|
+
title = 'Modelo Rodoviário de Carga'
|
20
|
+
|
21
|
+
@pdf.text_box(title, size: 12, align: :left, style: :bold, at: [0, 600])
|
22
|
+
end
|
23
|
+
|
24
|
+
def nfe_quantity
|
25
|
+
generate_box('QTD. NFe', @xml['qNFe'], 65)
|
26
|
+
end
|
27
|
+
|
28
|
+
def generate_box(title, text, x_position, width = 60)
|
29
|
+
@pdf.move_cursor_to 580
|
30
|
+
|
31
|
+
@pdf.stroke do
|
32
|
+
@pdf.fill_color LIGHT_GRAY_COLOR
|
33
|
+
@pdf.fill_rectangle([x_position, @pdf.cursor], width, 35)
|
34
|
+
@pdf.fill_color BLACK_COLOR
|
35
|
+
end
|
36
|
+
|
37
|
+
@pdf.bounding_box([x_position, @pdf.cursor], width: width, height: 35) do
|
38
|
+
@pdf.move_down 5
|
39
|
+
@pdf.text_box(title, size: 10, at: [3, @pdf.cursor])
|
40
|
+
@pdf.move_down 15
|
41
|
+
@pdf.text_box(text, size: 12, at: [3, @pdf.cursor])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def cte_quantity
|
46
|
+
generate_box('QTD. CTe', '', 0)
|
47
|
+
end
|
48
|
+
|
49
|
+
def total_weight
|
50
|
+
weight = ActiveSupport::NumberHelper.number_to_rounded(@xml['qCarga'], precision: 2)
|
51
|
+
weight = Helper.numerify(weight)
|
52
|
+
|
53
|
+
generate_box('Peso total (Kg)', weight, 130, 90)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -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,21 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
class QrCode
|
3
|
+
require 'rqrcode'
|
4
|
+
require 'chunky_png'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
def initialize(pdf:, qr_code_tag:, box_size:)
|
8
|
+
@pdf = pdf
|
9
|
+
@qr_code_tag = qr_code_tag
|
10
|
+
@box_size = box_size
|
11
|
+
end
|
12
|
+
|
13
|
+
def render
|
14
|
+
qrcode = RQRCode::QRCode.new(@qr_code_tag)
|
15
|
+
image = Tempfile.new(%w[qrcode png], binmode: true)
|
16
|
+
image.write(qrcode.as_png(module_px_size: 12).to_s)
|
17
|
+
|
18
|
+
@pdf.image(image, width: @box_size, height: @box_size, position: :center)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/br_danfe/version.rb
CHANGED
data/lib/br_danfe.rb
CHANGED
@@ -10,12 +10,12 @@ require 'ostruct'
|
|
10
10
|
require 'i18n'
|
11
11
|
require 'br_documents'
|
12
12
|
|
13
|
-
Dir[File.dirname(__FILE__)
|
13
|
+
Dir["#{File.dirname(__FILE__)}/**/*.rb"].sort.each { |f| require f }
|
14
14
|
I18n.load_path << File.expand_path('../config/locales/pt-BR.yml', __dir__)
|
15
15
|
Prawn::Font::AFM.hide_m17n_warning = true
|
16
16
|
|
17
17
|
module BrDanfe
|
18
18
|
def self.root_path
|
19
|
-
File.expand_path('
|
19
|
+
File.expand_path('..', __dir__)
|
20
20
|
end
|
21
21
|
end
|
@@ -7,7 +7,7 @@ describe BrDanfe::DanfeLib::NfceLib::Footer do
|
|
7
7
|
let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 5.cm) }
|
8
8
|
|
9
9
|
let(:xml_footer) do
|
10
|
-
xml =
|
10
|
+
xml = <<~XML
|
11
11
|
<nfeProc>
|
12
12
|
<NFe>
|
13
13
|
<infNFe>
|
@@ -19,7 +19,7 @@ describe BrDanfe::DanfeLib::NfceLib::Footer do
|
|
19
19
|
</infNFe>
|
20
20
|
</NFe>
|
21
21
|
</nfeProc>
|
22
|
-
|
22
|
+
XML
|
23
23
|
|
24
24
|
BrDanfe::XML.new(xml)
|
25
25
|
end
|
@@ -28,6 +28,7 @@ describe BrDanfe::DanfeLib::NfceLib::Footer do
|
|
28
28
|
|
29
29
|
describe '#render' do
|
30
30
|
before { File.delete(output_pdf) if File.exist?(output_pdf) }
|
31
|
+
|
31
32
|
it 'renders footer to the pdf' do
|
32
33
|
subject.render
|
33
34
|
expect(File.exist?(output_pdf)).to be_falsey
|
@@ -8,7 +8,7 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
|
|
8
8
|
let(:environment) { 1 }
|
9
9
|
|
10
10
|
let(:xml) do
|
11
|
-
xml =
|
11
|
+
xml = <<~XML
|
12
12
|
<nfeProc>
|
13
13
|
<NFe>
|
14
14
|
<infNFe>
|
@@ -37,12 +37,12 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
|
|
37
37
|
</infNFe>
|
38
38
|
</NFe>
|
39
39
|
</nfeProc>
|
40
|
-
|
40
|
+
XML
|
41
41
|
|
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
|
|
@@ -52,6 +52,8 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
|
|
52
52
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
53
53
|
end
|
54
54
|
|
55
|
+
after { File.delete(output_pdf) if File.exist?(output_pdf) }
|
56
|
+
|
55
57
|
context 'when has a short name' do
|
56
58
|
let(:company_name) { 'Test company' }
|
57
59
|
|
@@ -81,7 +83,7 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
|
|
81
83
|
let(:company_name) { 'Test company with some very long name to do a line break' }
|
82
84
|
|
83
85
|
context 'when has a logo' do
|
84
|
-
it 'renders the header with company name line breaked' do
|
86
|
+
it 'renders the header with company name line breaked and shrinked to fit' do
|
85
87
|
expect(File.exist?(output_pdf)).to be_falsey
|
86
88
|
pdf.render_file output_pdf
|
87
89
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe BrDanfe::DanfeLib::NfceLib::Helper do
|
4
4
|
let(:xml) do
|
5
|
-
xml =
|
5
|
+
xml = <<~XML
|
6
6
|
<enderDest>
|
7
7
|
<xLgr>Rua Tijucas</xLgr>
|
8
8
|
<nro>99</nro>
|
@@ -15,7 +15,7 @@ describe BrDanfe::DanfeLib::NfceLib::Helper do
|
|
15
15
|
<cPais>1058</cPais>
|
16
16
|
<xPais>Brasil</xPais>
|
17
17
|
</enderDest>
|
18
|
-
|
18
|
+
XML
|
19
19
|
|
20
20
|
BrDanfe::XML.new(xml)
|
21
21
|
end
|
@@ -5,7 +5,7 @@ describe BrDanfe::DanfeLib::NfceLib::Key do
|
|
5
5
|
let(:output_pdf) { "#{base_dir}output.pdf" }
|
6
6
|
|
7
7
|
let(:xml_key) do
|
8
|
-
xml =
|
8
|
+
xml = <<~XML
|
9
9
|
<nfeProc>
|
10
10
|
<NFe>
|
11
11
|
<infNFeSupl>
|
@@ -19,7 +19,7 @@ describe BrDanfe::DanfeLib::NfceLib::Key do
|
|
19
19
|
</infProt>
|
20
20
|
</protNFe>
|
21
21
|
</nfeProc>
|
22
|
-
|
22
|
+
XML
|
23
23
|
|
24
24
|
BrDanfe::XML.new(xml)
|
25
25
|
end
|
@@ -7,7 +7,7 @@ describe BrDanfe::DanfeLib::NfceLib::NfceIdentification do
|
|
7
7
|
let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 5.cm) }
|
8
8
|
|
9
9
|
let(:xml) do
|
10
|
-
xml =
|
10
|
+
xml = <<~XML
|
11
11
|
<nfeProc>
|
12
12
|
<NFe>
|
13
13
|
<infNFe>
|
@@ -25,7 +25,7 @@ describe BrDanfe::DanfeLib::NfceLib::NfceIdentification do
|
|
25
25
|
</infNFe>
|
26
26
|
</NFe>
|
27
27
|
</nfeProc>
|
28
|
-
|
28
|
+
XML
|
29
29
|
|
30
30
|
BrDanfe::XML.new(xml)
|
31
31
|
end
|
@@ -18,7 +18,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
18
18
|
context 'when has identified recipient' do
|
19
19
|
context 'when the recipient is a company' do
|
20
20
|
let(:xml_as_string) do
|
21
|
-
|
21
|
+
<<~XML
|
22
22
|
<nfeProc>
|
23
23
|
<NFe>
|
24
24
|
<dest>
|
@@ -34,7 +34,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
34
34
|
</dest>
|
35
35
|
</NFe>
|
36
36
|
</nfeProc>
|
37
|
-
|
37
|
+
XML
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'renders the CNPJ and company informations' do
|
@@ -47,7 +47,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
47
47
|
|
48
48
|
context 'when the recipient is an individual person' do
|
49
49
|
let(:xml_as_string) do
|
50
|
-
|
50
|
+
<<~XML
|
51
51
|
<nfeProc>
|
52
52
|
<NFe>
|
53
53
|
<dest>
|
@@ -63,7 +63,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
63
63
|
</dest>
|
64
64
|
</NFe>
|
65
65
|
</nfeProc>
|
66
|
-
|
66
|
+
XML
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'renders the CPF and individual informations' do
|
@@ -76,7 +76,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
76
76
|
|
77
77
|
context 'when the recipient is a foreign' do
|
78
78
|
let(:xml_as_string) do
|
79
|
-
|
79
|
+
<<~XML
|
80
80
|
<nfeProc>
|
81
81
|
<NFe>
|
82
82
|
<dest>
|
@@ -92,7 +92,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
92
92
|
</dest>
|
93
93
|
</NFe>
|
94
94
|
</nfeProc>
|
95
|
-
|
95
|
+
XML
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'renders the ID Estrangeiro and foreign informations' do
|
@@ -105,7 +105,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
105
105
|
|
106
106
|
context 'when the recipient does not have document' do
|
107
107
|
let(:xml_as_string) do
|
108
|
-
|
108
|
+
<<~XML
|
109
109
|
<nfeProc>
|
110
110
|
<NFe>
|
111
111
|
<dest>
|
@@ -120,7 +120,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
120
120
|
</dest>
|
121
121
|
</NFe>
|
122
122
|
</nfeProc>
|
123
|
-
|
123
|
+
XML
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'renders the name and the address of the consumer' do
|
@@ -134,7 +134,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
134
134
|
|
135
135
|
context 'when does not have identified recipient' do
|
136
136
|
let(:xml_as_string) do
|
137
|
-
|
137
|
+
<<~XML
|
138
138
|
<nfeProc>
|
139
139
|
<NFe>
|
140
140
|
<dest>
|
@@ -149,7 +149,7 @@ describe BrDanfe::DanfeLib::NfceLib::Recipient do
|
|
149
149
|
</dest>
|
150
150
|
</NFe>
|
151
151
|
</nfeProc>
|
152
|
-
|
152
|
+
XML
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'renders unidentified consumer' do
|
@@ -6,7 +6,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
6
6
|
|
7
7
|
let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 5.cm) }
|
8
8
|
let(:payment_xml) do
|
9
|
-
|
9
|
+
<<~XML
|
10
10
|
<pag>
|
11
11
|
<detPag>
|
12
12
|
<tPag>01</tPag>
|
@@ -21,10 +21,10 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
21
21
|
<vPag>66.70</vPag>
|
22
22
|
</detPag>
|
23
23
|
</pag>
|
24
|
-
|
24
|
+
XML
|
25
25
|
end
|
26
26
|
let(:xml_as_string) do
|
27
|
-
|
27
|
+
<<~XML
|
28
28
|
<nfeProc>
|
29
29
|
<NFe>
|
30
30
|
<infNFe>
|
@@ -43,7 +43,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
43
43
|
</infNFe>
|
44
44
|
</NFe>
|
45
45
|
</nfeProc>
|
46
|
-
|
46
|
+
XML
|
47
47
|
end
|
48
48
|
let(:xml_total_list) { BrDanfe::XML.new(xml_as_string) }
|
49
49
|
|
@@ -64,7 +64,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
64
64
|
|
65
65
|
describe 'about totals' do
|
66
66
|
let(:xml_as_string) do
|
67
|
-
|
67
|
+
<<~XML
|
68
68
|
<nfeProc>
|
69
69
|
<NFe>
|
70
70
|
<infNFe>
|
@@ -82,7 +82,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
82
82
|
</infNFe>
|
83
83
|
</NFe>
|
84
84
|
</nfeProc>
|
85
|
-
|
85
|
+
XML
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'renders the totals' do
|
@@ -95,7 +95,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
95
95
|
|
96
96
|
describe 'about payment methods' do
|
97
97
|
let(:payment_xml) do
|
98
|
-
|
98
|
+
<<~XML
|
99
99
|
<pag>
|
100
100
|
<detPag>
|
101
101
|
<tPag>01</tPag>
|
@@ -114,7 +114,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
114
114
|
<vPag>1.99</vPag>
|
115
115
|
</detPag>
|
116
116
|
</pag>
|
117
|
-
|
117
|
+
XML
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'does not render the ""without payment"" payment method ' do
|
@@ -126,7 +126,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
126
126
|
|
127
127
|
context 'when there are repeated payment methods' do
|
128
128
|
let(:payment_xml) do
|
129
|
-
|
129
|
+
<<~XML
|
130
130
|
<pag>
|
131
131
|
<detPag>
|
132
132
|
<tPag>01</tPag>
|
@@ -145,7 +145,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
145
145
|
<vPag>26.50</vPag>
|
146
146
|
</detPag>
|
147
147
|
</pag>
|
148
|
-
|
148
|
+
XML
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'renders grouped payment methods' do
|
@@ -158,7 +158,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
158
158
|
|
159
159
|
context 'when there are only "without payment" payment methods' do
|
160
160
|
let(:payment_xml) do
|
161
|
-
|
161
|
+
<<~XML
|
162
162
|
<pag>
|
163
163
|
<detPag>
|
164
164
|
<tPag>90</tPag>
|
@@ -173,7 +173,7 @@ describe BrDanfe::DanfeLib::NfceLib::TotalList do
|
|
173
173
|
<vPag>66.70</vPag>
|
174
174
|
</detPag>
|
175
175
|
</pag>
|
176
|
-
|
176
|
+
XML
|
177
177
|
end
|
178
178
|
|
179
179
|
it 'does not render payment methods' do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BrDanfe::DanfeLib::Nfce do
|
4
|
-
let(:output_pdf) { "#{base_dir}output.pdf" }
|
5
4
|
let(:base_dir) { './spec/fixtures/nfce/v4.00/' }
|
5
|
+
let(:output_pdf) { "#{base_dir}output.pdf" }
|
6
6
|
let(:xml) { BrDanfe::XML.new(File.read("#{base_dir}nfce.xml")) }
|
7
7
|
|
8
8
|
subject { described_class.new [xml] }
|
@@ -15,6 +15,7 @@ describe BrDanfe::DanfeLib::Nfce do
|
|
15
15
|
describe '#render_pdf' do
|
16
16
|
it 'renders the NFC-e pdf' do
|
17
17
|
expected = IO.binread("#{base_dir}rendered_nfce.fixture.pdf")
|
18
|
+
|
18
19
|
expect(subject.render_pdf).to eq expected
|
19
20
|
end
|
20
21
|
end
|