br_danfe 0.16.0 → 0.17.3
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/Gemfile.lock +41 -35
- data/Guardfile +3 -1
- data/bin/_guard-core +29 -0
- data/bin/guard +29 -0
- data/br_danfe.gemspec +7 -6
- 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/dup.rb +1 -2
- data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +6 -7
- data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +2 -1
- data/lib/br_danfe/helper.rb +1 -1
- data/lib/br_danfe/mdfe.rb +1 -1
- data/lib/br_danfe/mdfe_lib/authorization_protocol.rb +1 -1
- data/lib/br_danfe/mdfe_lib/fisco_control.rb +6 -25
- data/lib/br_danfe/mdfe_lib/header.rb +7 -8
- data/lib/br_danfe/mdfe_lib/mdfe_identification.rb +1 -1
- data/lib/br_danfe/mdfe_lib/notes.rb +1 -1
- data/lib/br_danfe/qr_code.rb +1 -2
- 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 +55 -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 +237 -237
- 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 +15 -15
- data/spec/br_danfe/mdfe_lib/document_spec.rb +2 -2
- data/spec/br_danfe/mdfe_lib/fisco_control_spec.rb +21 -7
- data/spec/br_danfe/mdfe_lib/header_spec.rb +27 -18
- data/spec/br_danfe/mdfe_lib/notes_spec.rb +5 -5
- data/spec/br_danfe/mdfe_lib/totalizer_spec.rb +1 -1
- data/spec/br_danfe/mdfe_spec.rb +4 -5
- data/spec/br_danfe/qr_code_spec.rb +4 -13
- data/spec/br_danfe/xml_spec.rb +6 -6
- data/spec/fixtures/mdfe/lib/fisco_control#without-barcode.pdf +0 -0
- data/spec/fixtures/mdfe/lib/header#render-without-qr-code.pdf +0 -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/nfe/lib/emit_header#render-nfe_key.pdf +945 -0
- data/spec/spec_helper.rb +1 -1
- metadata +38 -16
@@ -14,19 +14,54 @@ module BrDanfe
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
+
def render_headers(headers)
|
18
|
+
2.times { @pdf.render_blank_line }
|
19
|
+
cursor = @pdf.cursor
|
20
|
+
headers.each_with_index do |header, index|
|
21
|
+
cursor -= 10 if index == 1
|
22
|
+
@pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: 0.3.cm do
|
23
|
+
@pdf.text header[:content], header[:options]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
17
28
|
def headers
|
18
29
|
[
|
19
|
-
header_column('
|
20
|
-
header_column('
|
21
|
-
header_column('Qtde', :right),
|
30
|
+
header_column('CÓDIGO - DESCRIÇÃO', :left),
|
31
|
+
header_column('QTD', :left),
|
22
32
|
header_column('UN', :right),
|
23
|
-
header_column('
|
24
|
-
header_column('
|
33
|
+
header_column('VL UNIT', :right),
|
34
|
+
header_column('TOTAL', :right)
|
25
35
|
]
|
26
36
|
end
|
27
37
|
|
28
38
|
def header_column(title, align)
|
29
|
-
{ content: title, options: { align: align, size:
|
39
|
+
{ content: title, options: { align: align, size: 9, style: :bold } }
|
40
|
+
end
|
41
|
+
|
42
|
+
def columns
|
43
|
+
[
|
44
|
+
{ width: 6.7.cm, position: 0 },
|
45
|
+
{ width: 1.7.cm, position: 0.cm },
|
46
|
+
{ width: 1.cm, position: 1.7.cm },
|
47
|
+
{ width: 1.7.cm, position: 2.7.cm },
|
48
|
+
{ width: 2.3.cm, position: 4.4.cm }
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_products
|
53
|
+
@pdf.render_blank_line
|
54
|
+
products.each do |product|
|
55
|
+
cursor = @pdf.cursor
|
56
|
+
|
57
|
+
product.each_with_index do |cell, index|
|
58
|
+
cursor -= 10 if index == 1
|
59
|
+
@pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: 0.3.cm do
|
60
|
+
options = cell[:options].merge(overflow: :truncate)
|
61
|
+
@pdf.text_box cell[:content], options
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
30
65
|
end
|
31
66
|
|
32
67
|
def products
|
@@ -35,9 +70,8 @@ module BrDanfe
|
|
35
70
|
|
36
71
|
def product(det)
|
37
72
|
[
|
38
|
-
cell_text(det.css('prod/cProd').text),
|
39
|
-
cell_text(det.css('prod/
|
40
|
-
cell_number(BrDanfe::Helper.numerify(det.css('prod/qCom').text)),
|
73
|
+
cell_text("#{det.css('prod/cProd').text} - #{det.css('prod/xProd').text}"),
|
74
|
+
cell_text(BrDanfe::Helper.numerify(det.css('prod/qCom').text), align: :left),
|
41
75
|
cell_text(det.css('prod/uCom').text, align: :right),
|
42
76
|
cell_number(BrDanfe::Helper.numerify(det.css('prod/vUnCom').text)),
|
43
77
|
cell_number(BrDanfe::Helper.numerify(det.css('prod/vProd').text))
|
@@ -45,7 +79,7 @@ module BrDanfe
|
|
45
79
|
end
|
46
80
|
|
47
81
|
def cell_text(text, options = {})
|
48
|
-
cell = { content: text, options: { border_width: 0, size:
|
82
|
+
cell = { content: text, options: { border_width: 0, size: 9 } }
|
49
83
|
cell[:options].merge!(options)
|
50
84
|
cell
|
51
85
|
end
|
@@ -53,49 +87,6 @@ module BrDanfe
|
|
53
87
|
def cell_number(text)
|
54
88
|
cell_text(text, align: :right)
|
55
89
|
end
|
56
|
-
|
57
|
-
def columns
|
58
|
-
[
|
59
|
-
{ width: 0.9.cm, position: 0 },
|
60
|
-
{ width: 2.6.cm, position: 0.9.cm },
|
61
|
-
{ width: 1.1.cm, position: 3.5.cm },
|
62
|
-
{ width: 0.4.cm, position: 4.6.cm },
|
63
|
-
{ width: 1.2.cm, position: 5.cm },
|
64
|
-
{ width: 1.2.cm, position: 6.2.cm }
|
65
|
-
]
|
66
|
-
end
|
67
|
-
|
68
|
-
def render_headers(headers)
|
69
|
-
2.times { @pdf.render_blank_line }
|
70
|
-
cursor = @pdf.cursor
|
71
|
-
headers.each_with_index do |header, index|
|
72
|
-
@pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: 0.2.cm do
|
73
|
-
@pdf.text header[:content], header[:options]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def render_products
|
79
|
-
@pdf.render_blank_line
|
80
|
-
index_of_product_name = 1
|
81
|
-
products.each do |product|
|
82
|
-
box_height = box_height(product[index_of_product_name][:content])
|
83
|
-
cursor = @pdf.cursor
|
84
|
-
|
85
|
-
product.each_with_index do |cell, index|
|
86
|
-
@pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: box_height do
|
87
|
-
@pdf.text cell[:content], cell[:options]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def box_height(content)
|
94
|
-
line_height_base = 0.23.cm
|
95
|
-
|
96
|
-
lines = content.scan(/[\s\S]{1,20}( |$)/).length
|
97
|
-
line_height_base * lines
|
98
|
-
end
|
99
90
|
end
|
100
91
|
end
|
101
92
|
end
|
@@ -18,12 +18,13 @@ module BrDanfe
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def subtotal
|
21
|
+
@pdf.render_blank_line
|
21
22
|
cursor = @pdf.cursor
|
22
|
-
@pdf.bounding_box [
|
23
|
-
@pdf.text 'Subtotal R$', size:
|
23
|
+
@pdf.bounding_box [3.5.cm, cursor], width: 1.6.cm, height: 0.4.cm do
|
24
|
+
@pdf.text 'Subtotal R$', size: 9, align: :left
|
24
25
|
end
|
25
|
-
@pdf.bounding_box [
|
26
|
-
@pdf.text BrDanfe::Helper.numerify(@xml['ICMSTot > vProd'].to_f), size:
|
26
|
+
@pdf.bounding_box [5.1.cm, cursor], width: 1.6.cm, height: 0.4.cm do
|
27
|
+
@pdf.text BrDanfe::Helper.numerify(@xml['ICMSTot > vProd'].to_f), size: 9, align: :right
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
@@ -31,16 +32,16 @@ module BrDanfe
|
|
31
32
|
@pdf.render_blank_line
|
32
33
|
|
33
34
|
cursor = @pdf.cursor
|
34
|
-
print_text('
|
35
|
-
print_text(@xml.css('det').count.to_s, cursor, size:
|
35
|
+
print_text('QTD. TOTAL DE ITENS', cursor, size: 10, align: :left)
|
36
|
+
print_text(@xml.css('det').count.to_s, cursor, size: 10, align: :right)
|
36
37
|
|
37
38
|
cursor = @pdf.cursor
|
38
|
-
print_text('
|
39
|
-
print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vDesc'].to_f), cursor, size:
|
39
|
+
print_text('DESCONTO R$', cursor, size: 10, align: :left)
|
40
|
+
print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vDesc'].to_f), cursor, size: 10, align: :right)
|
40
41
|
|
41
42
|
cursor = @pdf.cursor
|
42
|
-
print_text('
|
43
|
-
print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vNF'].to_f), cursor, size:
|
43
|
+
print_text('VALOR TOTAL R$', cursor, size: 10, align: :left, style: :bold)
|
44
|
+
print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vNF'].to_f), cursor, size: 10, align: :right, style: :bold)
|
44
45
|
end
|
45
46
|
|
46
47
|
def payment_methods
|
@@ -59,19 +60,19 @@ module BrDanfe
|
|
59
60
|
@pdf.render_blank_line
|
60
61
|
|
61
62
|
cursor = @pdf.cursor
|
62
|
-
print_text('
|
63
|
-
print_text('
|
63
|
+
print_text('FORMA PAGTO.', cursor, size: 9, align: :left, style: :bold)
|
64
|
+
print_text('VLR PAGO R$', cursor, size: 9, align: :right, style: :bold)
|
64
65
|
|
65
66
|
payments.each do |key, value|
|
66
67
|
cursor = @pdf.cursor
|
67
|
-
print_text(I18n.t("nfce.payment_methods.#{key}"), cursor, size:
|
68
|
-
print_text(BrDanfe::Helper.numerify(value.to_f), cursor, size:
|
68
|
+
print_text(I18n.t("nfce.payment_methods.#{key}"), cursor, size: 9, align: :left)
|
69
|
+
print_text(BrDanfe::Helper.numerify(value.to_f), cursor, size: 9, align: :right)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
74
|
def print_text(text, cursor, options)
|
74
|
-
@pdf.bounding_box [0, cursor], width: 7.
|
75
|
+
@pdf.bounding_box [0, cursor], width: 6.7.cm, height: 0.35.cm do
|
75
76
|
@pdf.text text, options
|
76
77
|
end
|
77
78
|
end
|
@@ -10,15 +10,17 @@ module BrDanfe
|
|
10
10
|
def create_watermark
|
11
11
|
@document.create_stamp('has_no_fiscal_value') do
|
12
12
|
@document.fill_color '7d7d7d'
|
13
|
-
@document.text_box
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
@document.text_box(
|
14
|
+
I18n.t('danfe.others.has_no_fiscal_value'),
|
15
|
+
size: 2.2.cm,
|
16
|
+
width: @document.bounds.width,
|
17
|
+
height: @document.bounds.height,
|
18
|
+
align: :center,
|
19
|
+
valign: :center,
|
20
|
+
at: [0, @document.bounds.height],
|
21
|
+
rotate: 45,
|
22
|
+
rotate_around: :center
|
23
|
+
)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -38,8 +38,7 @@ module BrDanfe
|
|
38
38
|
|
39
39
|
def dtduplicata(det)
|
40
40
|
dtduplicata = det.css('dVenc').text
|
41
|
-
dtduplicata
|
42
|
-
dtduplicata
|
41
|
+
"#{dtduplicata[8, 2]}/#{dtduplicata[5, 2]}/#{dtduplicata[0, 4]}"
|
43
42
|
end
|
44
43
|
|
45
44
|
def normal
|
@@ -38,11 +38,10 @@ module BrDanfe
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def address
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
formatted
|
41
|
+
"#{@xml['enderEmit/xLgr']}, #{@xml['enderEmit/nro']}\n" \
|
42
|
+
"#{@xml['enderEmit/xBairro']} - #{cep}\n" \
|
43
|
+
"#{@xml['enderEmit/xMun']}/#{@xml['enderEmit/UF']}\n" \
|
44
|
+
"#{phone} #{@xml['enderEmit/email']}"
|
46
45
|
end
|
47
46
|
|
48
47
|
def phone
|
@@ -89,9 +88,9 @@ module BrDanfe
|
|
89
88
|
|
90
89
|
def access_key_box
|
91
90
|
@pdf.ibox 2.22, 10.02, 10.29, @y_position
|
92
|
-
@pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml['chNFe']
|
91
|
+
@pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml['infProt > chNFe']
|
93
92
|
@pdf.ibox 0.85, 10.02, 10.29, @y_position + 2.22, I18n.t('danfe.chNFe'),
|
94
|
-
@xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), style: :bold, align: :center
|
93
|
+
@xml['infProt > chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), style: :bold, align: :center
|
95
94
|
end
|
96
95
|
|
97
96
|
def sefaz_box
|
data/lib/br_danfe/helper.rb
CHANGED
@@ -20,7 +20,7 @@ module BrDanfe
|
|
20
20
|
decimal_part = separated_number[1] || '00'
|
21
21
|
decimal_part += '0' if decimal_part.size < 2
|
22
22
|
|
23
|
-
integer_part
|
23
|
+
"#{integer_part},#{decimal_part}"
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.format_datetime(xml_datetime, with_time_zone: false)
|
data/lib/br_danfe/mdfe.rb
CHANGED
@@ -14,7 +14,7 @@ module BrDanfe
|
|
14
14
|
|
15
15
|
def authorization
|
16
16
|
title = 'Protocolo de autorização'
|
17
|
-
protocol = @xml['infProt/nProt']
|
17
|
+
protocol = "#{@xml['infProt/nProt']} - #{Helper.format_datetime(@xml['infProt/dhRecbto'], with_time_zone: true)}"
|
18
18
|
|
19
19
|
@pdf.text_box(title, size: 9, align: :left, style: :bold, at: [0, 510])
|
20
20
|
@pdf.text_box(protocol, size: 11, align: :left, at: [0, 500])
|
@@ -3,37 +3,18 @@ module BrDanfe
|
|
3
3
|
class FiscoControl
|
4
4
|
def initialize(pdf, xml)
|
5
5
|
@pdf = pdf
|
6
|
-
@
|
6
|
+
@nfe_key = xml['mdfeProc > protMDFe > infProt > chMDFe']
|
7
7
|
end
|
8
8
|
|
9
9
|
def generate
|
10
|
-
|
11
|
-
barcode
|
12
|
-
generate_nfe_key
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def title
|
18
|
-
title = 'CONTROLE DO FISCO'
|
19
|
-
|
20
|
-
@pdf.text_box(title, size: 9, align: :left, at: [250, 600])
|
21
|
-
end
|
22
|
-
|
23
|
-
def barcode
|
24
|
-
barcode = Barby::Code128C.new(nfe_key)
|
25
|
-
barcode.annotate_pdf(@pdf, x: 250, y: 530, height: 50)
|
26
|
-
end
|
10
|
+
@pdf.text_box('CONTROLE DO FISCO', size: 9, align: :left, at: [250, 600])
|
27
11
|
|
28
|
-
|
29
|
-
@xml['mdfeProc > protMDFe > infProt > chMDFe']
|
30
|
-
end
|
12
|
+
return if @nfe_key.blank?
|
31
13
|
|
32
|
-
|
33
|
-
title = 'Chave de Acesso'
|
14
|
+
Barby::Code128C.new(@nfe_key).annotate_pdf(@pdf, x: 250, y: 530, height: 50)
|
34
15
|
|
35
|
-
@pdf.text_box(
|
36
|
-
@pdf.text_box(nfe_key, size: 11, align: :left, at: [250, 500])
|
16
|
+
@pdf.text_box('Chave de Acesso', size: 9, align: :left, style: :bold, at: [250, 510])
|
17
|
+
@pdf.text_box(@nfe_key, size: 11, align: :left, at: [250, 500])
|
37
18
|
end
|
38
19
|
end
|
39
20
|
end
|
@@ -11,7 +11,7 @@ module BrDanfe
|
|
11
11
|
def generate
|
12
12
|
generate_emit
|
13
13
|
generate_title
|
14
|
-
|
14
|
+
generate_qr_code if @xml['qrCodMDFe'].present?
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
@@ -34,9 +34,8 @@ module BrDanfe
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def address
|
37
|
-
|
38
|
-
|
39
|
-
formatted
|
37
|
+
"#{@xml['enderEmit/xLgr']}, nº #{@xml['enderEmit/nro']}\n" \
|
38
|
+
"#{@xml['enderEmit/xMun']} - #{@xml['enderEmit/UF']} CEP #{cep}\n"
|
40
39
|
end
|
41
40
|
|
42
41
|
def cep
|
@@ -44,7 +43,7 @@ module BrDanfe
|
|
44
43
|
end
|
45
44
|
|
46
45
|
def company_informations
|
47
|
-
|
46
|
+
"<b>CNPJ: </b>#{@xml['emit/CNPJ']} <b>IE: </b>#{@xml['emit/IE']}"
|
48
47
|
end
|
49
48
|
|
50
49
|
def logo
|
@@ -65,12 +64,12 @@ module BrDanfe
|
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
68
|
-
def
|
67
|
+
def generate_qr_code
|
69
68
|
box_size = 40.mm
|
70
|
-
security_margin = box_size + box_size / 10.0
|
69
|
+
security_margin = box_size + (box_size / 10.0)
|
71
70
|
|
72
71
|
@pdf.bounding_box([414, 780], width: security_margin, height: security_margin) do
|
73
|
-
BrDanfe::QrCode.new(pdf: @pdf,
|
72
|
+
BrDanfe::QrCode.new(pdf: @pdf, qr_code_tag: @xml['qrCodMDFe'], box_size: box_size).render
|
74
73
|
end
|
75
74
|
end
|
76
75
|
end
|
@@ -74,7 +74,7 @@ module BrDanfe
|
|
74
74
|
|
75
75
|
total_height += 10 if total_chars >= MAX_CHARS_ON_LINE
|
76
76
|
|
77
|
-
total_height <= height_on_first_page ? first_page += word
|
77
|
+
total_height <= height_on_first_page ? first_page += "#{word} " : next_page += "#{word} "
|
78
78
|
end
|
79
79
|
|
80
80
|
{ first_page: first_page, next_page: next_page }
|
data/lib/br_danfe/qr_code.rb
CHANGED
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
|