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
@@ -10,9 +10,9 @@ module BrDanfe
|
|
10
10
|
def render
|
11
11
|
@pdf.render_blank_line
|
12
12
|
|
13
|
-
@pdf.text 'Consulte pela Chave de Acesso em', size:
|
14
|
-
@pdf.text @xml['urlChave'], size:
|
15
|
-
@pdf.text @xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), size:
|
13
|
+
@pdf.text 'Consulte pela Chave de Acesso em', size: 9, align: :center, style: :bold
|
14
|
+
@pdf.text @xml['urlChave'], size: 9, align: :center
|
15
|
+
@pdf.text @xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), size: 8, align: :center
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -12,9 +12,9 @@ module BrDanfe
|
|
12
12
|
identification = "NFC-e nº #{@xml['ide/nNF']} Série #{@xml['ide/serie']} #{emitted_at}"
|
13
13
|
|
14
14
|
@pdf.render_blank_line
|
15
|
-
@pdf.text identification, size:
|
16
|
-
@pdf.text "<b>Protocolo de autorização:</b> #{@xml['infProt/nProt']}", size:
|
17
|
-
@pdf.text "<b>Data de autorização: </b> #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", size:
|
15
|
+
@pdf.text identification, size: 9, align: :center, style: :bold
|
16
|
+
@pdf.text "<b>Protocolo de autorização:</b> #{@xml['infProt/nProt']}", size: 9, align: :center, inline_format: true
|
17
|
+
@pdf.text "<b>Data de autorização: </b> #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", size: 9, align: :center, inline_format: true
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -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
|
@@ -23,45 +23,57 @@ module BrDanfe
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def generate(footer_info)
|
26
|
-
|
27
|
-
|
26
|
+
last_index = @xmls.size - 1
|
27
|
+
|
28
|
+
@xmls.each_with_index do |xml, index|
|
29
|
+
break unless BrDanfe::Helper.nfe?(xml)
|
30
|
+
|
31
|
+
initial_number_of_pages = @document.page_count
|
32
|
+
render_on_first_page(xml)
|
33
|
+
render_on_each_page(footer_info, xml, initial_number_of_pages)
|
34
|
+
@document.start_new_page unless index == last_index
|
35
|
+
end
|
36
|
+
|
28
37
|
@document
|
29
38
|
end
|
30
39
|
|
31
|
-
def render_on_first_page
|
32
|
-
NfeLib::Ticket.new(@document,
|
33
|
-
NfeLib::Dest.new(@document,
|
34
|
-
NfeLib::Dup.new(@document,
|
35
|
-
NfeLib::Icmstot.new(@document,
|
36
|
-
NfeLib::Transp.new(@document,
|
37
|
-
n_vol = NfeLib::Vol.new(@document,
|
38
|
-
has_issqn = NfeLib::Issqn.new(@document,
|
39
|
-
NfeLib::Infadic.new(@document,
|
40
|
-
|
41
|
-
render_products
|
40
|
+
def render_on_first_page(xml)
|
41
|
+
NfeLib::Ticket.new(@document, xml).render
|
42
|
+
NfeLib::Dest.new(@document, xml).render
|
43
|
+
NfeLib::Dup.new(@document, xml).render
|
44
|
+
NfeLib::Icmstot.new(@document, xml).render
|
45
|
+
NfeLib::Transp.new(@document, xml).render
|
46
|
+
n_vol = NfeLib::Vol.new(@document, xml).render
|
47
|
+
has_issqn = NfeLib::Issqn.new(@document, xml).render
|
48
|
+
NfeLib::Infadic.new(@document, xml).render(n_vol)
|
49
|
+
|
50
|
+
render_products(has_issqn, xml)
|
42
51
|
end
|
43
52
|
|
44
|
-
def render_products(has_issqn)
|
45
|
-
NfeLib::DetBody.new(@document,
|
53
|
+
def render_products(has_issqn, xml)
|
54
|
+
NfeLib::DetBody.new(@document, xml).render(has_issqn)
|
46
55
|
end
|
47
56
|
|
48
|
-
def render_on_each_page(footer_info)
|
49
|
-
|
57
|
+
def render_on_each_page(footer_info, xml, initial_number_of_pages)
|
58
|
+
total_pages = @document.page_count + 1 - initial_number_of_pages
|
59
|
+
|
60
|
+
emitter = NfeLib::EmitHeader.new(@document, xml, @options.logo, @options.logo_dimensions)
|
61
|
+
|
62
|
+
total_pages.times do |page_index|
|
63
|
+
page = page_index + initial_number_of_pages
|
50
64
|
|
51
|
-
|
52
|
-
page
|
53
|
-
position = page == 1 ? 3.96 : 1.85
|
54
|
-
repeated_information page, position, emitter, footer_info
|
65
|
+
position = page_index + 1 == 1 ? 3.96 : 1.85
|
66
|
+
repeated_information(page, position, emitter, footer_info, xml, total_pages, page_index + 1)
|
55
67
|
end
|
56
68
|
end
|
57
69
|
|
58
|
-
def repeated_information(page, y_position, emitter, footer_info)
|
70
|
+
def repeated_information(page, y_position, emitter, footer_info, xml, total_pages, initial_page_of_pdf)
|
59
71
|
@document.go_to_page(page)
|
60
72
|
|
61
|
-
emitter.render
|
62
|
-
render_product_table_title
|
73
|
+
emitter.render(initial_page_of_pdf, y_position, total_pages)
|
74
|
+
render_product_table_title initial_page_of_pdf
|
63
75
|
render_footer_information footer_info
|
64
|
-
render_no_fiscal_value
|
76
|
+
render_no_fiscal_value(xml)
|
65
77
|
end
|
66
78
|
|
67
79
|
def render_product_table_title(page)
|
@@ -75,8 +87,8 @@ module BrDanfe
|
|
75
87
|
end
|
76
88
|
end
|
77
89
|
|
78
|
-
def render_no_fiscal_value
|
79
|
-
@document.stamp('has_no_fiscal_value') if BrDanfe::Helper.no_fiscal_value?(
|
90
|
+
def render_no_fiscal_value(xml)
|
91
|
+
@document.stamp('has_no_fiscal_value') if BrDanfe::Helper.no_fiscal_value?(xml)
|
80
92
|
end
|
81
93
|
end
|
82
94
|
end
|
@@ -9,10 +9,10 @@ module BrDanfe
|
|
9
9
|
@logo_dimensions = logo_dimensions
|
10
10
|
end
|
11
11
|
|
12
|
-
def render(page, y_position)
|
12
|
+
def render(page, y_position, total)
|
13
13
|
@y_position = y_position
|
14
14
|
company_box
|
15
|
-
danfe_box
|
15
|
+
danfe_box(page, total)
|
16
16
|
access_key_box
|
17
17
|
sefaz_box
|
18
18
|
render_emit y_position
|
@@ -50,7 +50,7 @@ module BrDanfe
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def cep
|
53
|
-
|
53
|
+
BrDanfe::Helper.format_cep(@xml['enderEmit/CEP'])
|
54
54
|
end
|
55
55
|
|
56
56
|
def logo
|
@@ -64,7 +64,7 @@ module BrDanfe
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
def danfe_box(page)
|
67
|
+
def danfe_box(page, total)
|
68
68
|
@pdf.ibox 3.92, 2.08, 8.21, @y_position
|
69
69
|
|
70
70
|
@pdf.ibox 0.60, 2.08, 8.21, @y_position, '', 'DANFE',
|
@@ -83,7 +83,7 @@ module BrDanfe
|
|
83
83
|
size: 8, align: :center, valign: :center, border: 0, style: :bold
|
84
84
|
|
85
85
|
@pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, '',
|
86
|
-
I18n.t('danfe.others.page', current: page, total:
|
86
|
+
I18n.t('danfe.others.page', current: page, total: total),
|
87
87
|
size: 8, align: :center, valign: :center, border: 0, style: :bold
|
88
88
|
end
|
89
89
|
|
@@ -7,7 +7,7 @@ module BrDanfe
|
|
7
7
|
bold: "#{BrDanfe.root_path}/fonts/tinos_bold.ttf",
|
8
8
|
italic: "#{BrDanfe.root_path}/fonts/tinos_italic.ttf",
|
9
9
|
bold_italic: "#{BrDanfe.root_path}/fonts/tinos_bold_italic.ttf",
|
10
|
-
normal: "#{BrDanfe.root_path}/fonts/tinos.ttf"
|
10
|
+
normal: "#{BrDanfe.root_path}/fonts/tinos.ttf"
|
11
11
|
}
|
12
12
|
|
13
13
|
document
|
data/lib/br_danfe/helper.rb
CHANGED
@@ -23,15 +23,19 @@ module BrDanfe
|
|
23
23
|
integer_part + ',' + decimal_part
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.format_datetime(xml_datetime)
|
27
|
-
formated = ''
|
26
|
+
def self.format_datetime(xml_datetime, with_time_zone: false)
|
27
|
+
formated = with_time_zone ? '%d/%m/%Y %H:%M:%S%:z' : '%d/%m/%Y %H:%M:%S'
|
28
|
+
xml_datetime.present? ? Time.parse(xml_datetime).strftime(formated) : ''
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.nfe?(xml)
|
32
|
+
nfe_code = '55'
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
formated = date.strftime('%d/%m/%Y %H:%M:%S')
|
32
|
-
end
|
34
|
+
xml['ide > mod'] == nfe_code
|
35
|
+
end
|
33
36
|
|
34
|
-
|
37
|
+
def self.format_cep(cep)
|
38
|
+
cep.sub(/(\d{2})(\d{3})(\d{3})/, '\\1.\\2-\\3')
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
BLACK_COLOR = '000000'.freeze
|
3
|
+
GRAY_COLOR = 'A0A0A0'.freeze
|
4
|
+
LIGHT_GRAY_COLOR = 'ECECEC'.freeze
|
5
|
+
|
6
|
+
class Mdfe
|
7
|
+
attr_reader :logo_options
|
8
|
+
|
9
|
+
def initialize(xml)
|
10
|
+
@xml = xml
|
11
|
+
@pdf = MdfeLib::Document.new
|
12
|
+
@logo_options = BrDanfe::Logo::Config.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def save_pdf(filename)
|
16
|
+
generate
|
17
|
+
@pdf.render_file(filename)
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_pdf
|
21
|
+
generate
|
22
|
+
@pdf.render
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def generate
|
28
|
+
generate_on_first_page
|
29
|
+
generate_on_each_page
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_on_first_page
|
33
|
+
MdfeLib::Totalizer.new(@pdf, @xml).generate
|
34
|
+
MdfeLib::AuthorizationProtocol.new(@pdf, @xml).generate
|
35
|
+
MdfeLib::FiscoControl.new(@pdf, @xml).generate
|
36
|
+
MdfeLib::Vehicles.new(@pdf, @xml).generate
|
37
|
+
MdfeLib::Drivers.new(@pdf, @xml).generate
|
38
|
+
MdfeLib::Notes.new(@pdf, @xml).generate
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_on_each_page
|
42
|
+
header = MdfeLib::Header.new(@pdf, @xml, @logo_options.logo, @logo_options.logo_dimensions)
|
43
|
+
mdfe_identification = MdfeLib::MdfeIdentification.new(@pdf, @xml)
|
44
|
+
|
45
|
+
@pdf.page_count.times do |i|
|
46
|
+
page = i + 1
|
47
|
+
|
48
|
+
@pdf.go_to_page page
|
49
|
+
|
50
|
+
header.generate
|
51
|
+
mdfe_identification.generate(page)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|