br_invoices_pdf 0.2.6.alpha.18 → 0.2.6.alpha.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/br_invoices_pdf.gemspec +1 -0
- data/lib/br_invoices_pdf/cfe/parser/access_key.rb +3 -1
- data/lib/br_invoices_pdf/cfe/parser/cnpj.rb +3 -1
- data/lib/br_invoices_pdf/cfe/parser/company_attributes.rb +3 -1
- data/lib/br_invoices_pdf/cfe/parser/cpf.rb +3 -1
- data/lib/br_invoices_pdf/cfe/parser/document_number.rb +3 -1
- data/lib/br_invoices_pdf/cfe/parser/fisco_obs.rb +3 -1
- data/lib/br_invoices_pdf/cfe/parser/payment.rb +3 -1
- data/lib/br_invoices_pdf/cfe/parser/payments.rb +6 -16
- data/lib/br_invoices_pdf/cfe/parser/products_data.rb +4 -2
- data/lib/br_invoices_pdf/cfe/parser/sat.rb +3 -1
- data/lib/br_invoices_pdf/cfe/parser.rb +5 -3
- data/lib/br_invoices_pdf/cfe/renderer/base_renderer.rb +5 -62
- data/lib/br_invoices_pdf/cfe/renderer/company_identification.rb +3 -0
- data/lib/br_invoices_pdf/cfe/renderer/fisco_info.rb +3 -0
- data/lib/br_invoices_pdf/cfe/renderer/header.rb +3 -0
- data/lib/br_invoices_pdf/cfe/renderer/payment_forms.rb +6 -12
- data/lib/br_invoices_pdf/cfe/renderer/product_table.rb +4 -48
- data/lib/br_invoices_pdf/cfe/renderer/qr_code.rb +5 -9
- data/lib/br_invoices_pdf/cfe/renderer/taxes_info.rb +5 -2
- data/lib/br_invoices_pdf/cfe/renderer/totals.rb +3 -24
- data/lib/br_invoices_pdf/cfe/renderer.rb +4 -18
- data/lib/br_invoices_pdf/cfe.rb +2 -1
- data/lib/br_invoices_pdf/errors/invalid_document_type.rb +2 -0
- data/lib/br_invoices_pdf/generator.rb +2 -0
- data/lib/br_invoices_pdf/nfce/parser/additional_info.rb +17 -0
- data/lib/br_invoices_pdf/nfce/parser/company.rb +25 -0
- data/lib/br_invoices_pdf/nfce/parser/customer.rb +32 -0
- data/lib/br_invoices_pdf/nfce/parser/emission_details.rb +51 -0
- data/lib/br_invoices_pdf/nfce/parser/payments.rb +30 -0
- data/lib/br_invoices_pdf/nfce/parser/products.rb +39 -0
- data/lib/br_invoices_pdf/nfce/parser/totals.rb +25 -0
- data/lib/br_invoices_pdf/nfce/parser.rb +33 -0
- data/lib/br_invoices_pdf/nfce/renderer/base_renderer.rb +22 -0
- data/lib/br_invoices_pdf/nfce/renderer/company_identification.rb +37 -0
- data/lib/br_invoices_pdf/nfce/renderer/customer_identification.rb +47 -0
- data/lib/br_invoices_pdf/nfce/renderer/fiscal_message.rb +46 -0
- data/lib/br_invoices_pdf/nfce/renderer/header.rb +32 -0
- data/lib/br_invoices_pdf/nfce/renderer/payment_forms.rb +73 -0
- data/lib/br_invoices_pdf/nfce/renderer/product_table.rb +23 -0
- data/lib/br_invoices_pdf/nfce/renderer/qr_code.rb +56 -0
- data/lib/br_invoices_pdf/nfce/renderer/taxes_info.rb +28 -0
- data/lib/br_invoices_pdf/nfce/renderer/totals.rb +30 -0
- data/lib/br_invoices_pdf/nfce/renderer.rb +37 -0
- data/lib/br_invoices_pdf/nfce.rb +11 -0
- data/lib/br_invoices_pdf/util/base_renderer.rb +121 -0
- data/lib/br_invoices_pdf/util/enum.rb +20 -0
- data/lib/br_invoices_pdf/util/mount_params.rb +26 -0
- data/lib/br_invoices_pdf/util/nfce_check_urls.rb +102 -0
- data/lib/br_invoices_pdf/util/pdf_renderer.rb +33 -0
- data/lib/br_invoices_pdf/util/product_table.rb +57 -0
- data/lib/br_invoices_pdf/util/xml_locate.rb +21 -0
- data/lib/br_invoices_pdf/version.rb +3 -1
- data/lib/br_invoices_pdf.rb +12 -0
- data/nfce.xml +160 -0
- metadata +32 -4
- data/lib/br_invoices_pdf/cfe/parser/base_parser.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4612f7674183ae8414be784152bf91c80eada118
|
4
|
+
data.tar.gz: f2e215f9ee6ef8eaba081f59106e36390e0b992a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94507762fe95b1a7c9d9d0875f71f8c954f37ab80460d35a6c5ab367e0cd1f112781e85235b036e41407e835be57830eba8832606ae18d65c767f300bc46d17c
|
7
|
+
data.tar.gz: 6827fa177ed6cc72252d92461f552667b0d90c52c30d3f25d65ce0c959c7a144fd174d77cfd6fc1d9a7586c8689232e5032bc4eed600af9abadca7c8e9afd7f5
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
engines:
|
2
|
+
rubocop:
|
3
|
+
enabled: false
|
4
|
+
#checks:
|
5
|
+
# Rubocop/Metrics/ClassLength:
|
6
|
+
# enabled: false
|
7
|
+
duplication:
|
8
|
+
enabled: true
|
9
|
+
config:
|
10
|
+
languages:
|
11
|
+
- ruby:
|
12
|
+
ratings:
|
13
|
+
paths:
|
14
|
+
- lib/**/*
|
15
|
+
exclude_paths:
|
16
|
+
- spec/**/*
|
17
|
+
- lib/br_invoices_pdf/nfce/parser/emission_details.rb
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/br_invoices_pdf.gemspec
CHANGED
@@ -1,28 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BrInvoicesPdf
|
2
4
|
module Cfe
|
3
5
|
module Parser
|
4
6
|
module Payments
|
5
|
-
extend
|
7
|
+
extend Util::XmlLocate
|
6
8
|
|
7
9
|
module_function
|
8
10
|
|
9
|
-
PAYMENT_TYPES = {
|
10
|
-
'01' => 'Dinheiro',
|
11
|
-
'02' => 'Cheque',
|
12
|
-
'03' => 'Cartão de Crédito',
|
13
|
-
'04' => 'Cartão de Débito',
|
14
|
-
'05' => 'Crédito Loja',
|
15
|
-
'10' => 'Vale Alimentação',
|
16
|
-
'11' => 'Vale Refeição',
|
17
|
-
'12' => 'Vale Presente',
|
18
|
-
'13' => 'Vale Combustível',
|
19
|
-
'99' => 'Outros'
|
20
|
-
}.freeze
|
21
|
-
|
22
11
|
def execute(xml)
|
23
12
|
node_payments = xml.locate('infCFe/pgto')
|
24
13
|
|
25
|
-
|
14
|
+
return unless node_payments
|
15
|
+
payments_by_nodes(node_payments) if node_payments.any?
|
26
16
|
end
|
27
17
|
|
28
18
|
def payments_by_nodes(node_payments)
|
@@ -34,7 +24,7 @@ module BrInvoicesPdf
|
|
34
24
|
|
35
25
|
def payment_by(element)
|
36
26
|
{
|
37
|
-
type: PAYMENT_TYPES[locate_element(element, 'cMP')],
|
27
|
+
type: Util::Enum::PAYMENT_TYPES[locate_element(element, 'cMP')],
|
38
28
|
amount: locate_element(element, 'vMP')
|
39
29
|
}
|
40
30
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BrInvoicesPdf
|
2
4
|
module Cfe
|
3
5
|
module Parser
|
4
6
|
module ProductsData
|
5
|
-
extend
|
7
|
+
extend Util::XmlLocate
|
6
8
|
|
7
9
|
module_function
|
8
10
|
|
@@ -27,7 +29,7 @@ module BrInvoicesPdf
|
|
27
29
|
|
28
30
|
def product_by(element)
|
29
31
|
FIELDS
|
30
|
-
.map { |(key, field)| [key, node_locate(element, field).force_encoding('UTF-8'
|
32
|
+
.map { |(key, field)| [key, node_locate(element, field).force_encoding('UTF-8')] }
|
31
33
|
.to_h
|
32
34
|
end
|
33
35
|
private_class_method :product_by
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'br_invoices_pdf/cfe/parser/access_key'
|
2
4
|
require 'br_invoices_pdf/cfe/parser/company_attributes'
|
3
5
|
require 'br_invoices_pdf/cfe/parser/cpf'
|
@@ -14,10 +16,10 @@ module BrInvoicesPdf
|
|
14
16
|
module Parser
|
15
17
|
module_function
|
16
18
|
|
17
|
-
|
19
|
+
PARSERS = {
|
18
20
|
sat_params: Sat,
|
19
21
|
document_number: DocumentNumber,
|
20
|
-
|
22
|
+
totals: Payment,
|
21
23
|
payments: Payments,
|
22
24
|
products: ProductsData,
|
23
25
|
company_attributes: CompanyAttributes,
|
@@ -28,7 +30,7 @@ module BrInvoicesPdf
|
|
28
30
|
}.freeze
|
29
31
|
|
30
32
|
def parse(xml)
|
31
|
-
|
33
|
+
PARSERS.reduce({}) do |response, (param, parser)|
|
32
34
|
{ **response, param => parser.execute(xml) }
|
33
35
|
end
|
34
36
|
end
|
@@ -1,74 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BrInvoicesPdf
|
2
4
|
module Cfe
|
3
5
|
module Renderer
|
4
6
|
module BaseRenderer
|
7
|
+
extend Util::BaseRenderer
|
8
|
+
|
5
9
|
module_function
|
6
10
|
|
7
|
-
ADDRESS_FORMAT = '%s, %s, %s, %s, %s/%s'
|
11
|
+
ADDRESS_FORMAT = '%s, %s, %s, %s, %s/%s'
|
8
12
|
def format_address(address)
|
9
13
|
ADDRESS_FORMAT % %i(public_place number complement neighborhood city state).map(&address.method(:[]))
|
10
14
|
end
|
11
|
-
|
12
|
-
def box(pdf, position, width)
|
13
|
-
pdf.bounding_box(position, width: width) do
|
14
|
-
pdf.pad(2) do
|
15
|
-
pdf.indent(2, 2) do
|
16
|
-
yield
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
pdf.stroke_bounds
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# :reek:FeatureEnvy
|
25
|
-
def pdf_setup(pdf)
|
26
|
-
pdf.bounding_box([0, pdf.cursor], width: page_content_width(pdf)) do
|
27
|
-
pdf.pad(10) do
|
28
|
-
pdf.indent(10, 10) do
|
29
|
-
yield
|
30
|
-
end
|
31
|
-
end
|
32
|
-
pdf.stroke_bounds
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
CNPJ_FORMAT = '%02d.%03d.%03d/%04d-%02d'.freeze
|
37
|
-
# :reek:FeatureEnvy
|
38
|
-
def format_cnpj(cnpj)
|
39
|
-
format(CNPJ_FORMAT, cnpj[0, 2].to_i, cnpj[2, 3].to_i, cnpj[5, 3].to_i,
|
40
|
-
cnpj[8, 4].to_i, cnpj[12, 2].to_i)
|
41
|
-
end
|
42
|
-
|
43
|
-
CPF_FORMAT = '%d.%d.%d-%d'.freeze
|
44
|
-
# :reek:FeatureEnvy
|
45
|
-
def format_cpf(cpf)
|
46
|
-
format(CPF_FORMAT, cpf[0, 3], cpf[3, 3], cpf[6, 3], cpf[9, 2])
|
47
|
-
end
|
48
|
-
|
49
|
-
# :reek:FeatureEnvy
|
50
|
-
def format_currency(number_string)
|
51
|
-
number = BigDecimal(number_string)
|
52
|
-
format('%.2f', number.truncate(2)).tr('.', ',')
|
53
|
-
end
|
54
|
-
|
55
|
-
# :reek:FeatureEnvy
|
56
|
-
def format_number(number_string, prec: 4)
|
57
|
-
number = BigDecimal(number_string)
|
58
|
-
format("%.#{prec}f", number.truncate(prec)).tr('.', ',')
|
59
|
-
end
|
60
|
-
|
61
|
-
# :reek:FeatureEnvy
|
62
|
-
def page_paper_width(name)
|
63
|
-
(name.is_a?(Array) ? name : PDF::Core::PageGeometry::SIZES[name]).first
|
64
|
-
end
|
65
|
-
|
66
|
-
# :reek:FeatureEnvy
|
67
|
-
def page_content_width(pdf)
|
68
|
-
page = pdf.page
|
69
|
-
margins = page.margins
|
70
|
-
page_paper_width(page.size) - margins[:left] - margins[:right]
|
71
|
-
end
|
72
15
|
end
|
73
16
|
end
|
74
17
|
end
|
@@ -1,19 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BrInvoicesPdf
|
2
4
|
module Cfe
|
3
5
|
module Renderer
|
4
6
|
module PaymentForms
|
7
|
+
extend Util::BaseRenderer
|
5
8
|
extend BaseRenderer
|
6
9
|
|
7
10
|
module_function
|
8
11
|
|
9
12
|
def execute(pdf, data)
|
10
|
-
pdf
|
11
|
-
width = page_content_width(pdf)
|
12
|
-
table_data = payments_table_data(data)
|
13
|
-
render_table(pdf, table_data, width)
|
14
|
-
end
|
15
|
-
|
16
|
-
pdf.move_down(5)
|
13
|
+
execute_payment_form(pdf, payments_table_data(data))
|
17
14
|
end
|
18
15
|
|
19
16
|
def render_table(pdf, table_data, width)
|
@@ -33,13 +30,10 @@ module BrInvoicesPdf
|
|
33
30
|
end
|
34
31
|
private_class_method :format_table
|
35
32
|
|
36
|
-
PAYMENTS_TABLE_BASE_DATA = [['FORMA DE PAGAMENTO', 'VALOR']].freeze
|
37
33
|
def payments_table_data(data)
|
38
|
-
payments_data = data
|
39
|
-
result + [[cur[:type], format_currency(cur[:amount])]]
|
40
|
-
end
|
34
|
+
payments_data = mount_payment_data(data)
|
41
35
|
|
42
|
-
add_default_values(payments_data, data[:
|
36
|
+
add_default_values(payments_data, data[:totals])
|
43
37
|
end
|
44
38
|
private_class_method :payments_table_data
|
45
39
|
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BrInvoicesPdf
|
2
4
|
module Cfe
|
3
5
|
module Renderer
|
4
6
|
module ProductTable
|
7
|
+
extend Util::BaseRenderer
|
8
|
+
extend Util::ProductTable
|
5
9
|
extend BaseRenderer
|
6
10
|
|
7
11
|
module_function
|
@@ -15,54 +19,6 @@ module BrInvoicesPdf
|
|
15
19
|
|
16
20
|
pdf.move_down(5)
|
17
21
|
end
|
18
|
-
|
19
|
-
def format_table(pdf, table_data)
|
20
|
-
width = page_content_width(pdf)
|
21
|
-
pdf.table(table_data, width: width) do |table|
|
22
|
-
format_row(table.row(0))
|
23
|
-
format_columns(table)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
private_class_method :format_table
|
27
|
-
|
28
|
-
def format_row(row)
|
29
|
-
row.font_style = :bold
|
30
|
-
row.align = :center
|
31
|
-
end
|
32
|
-
private_class_method :format_row
|
33
|
-
|
34
|
-
# :reek:FeatureEnvy
|
35
|
-
def format_columns(table)
|
36
|
-
table.columns(0..5).valign = :center
|
37
|
-
table.columns([2, 4, 5]).align = :right
|
38
|
-
table.column(3).align = :center
|
39
|
-
table_widths(table, table.width)
|
40
|
-
end
|
41
|
-
private_class_method :format_columns
|
42
|
-
|
43
|
-
# :reek:FeatureEnvy
|
44
|
-
def table_widths(table, width)
|
45
|
-
table.column(0).width = width * 0.16
|
46
|
-
table.columns([2, 3]).width = width * 0.155
|
47
|
-
table.column([4, 5]).width = width * 0.135
|
48
|
-
end
|
49
|
-
private_class_method :table_widths
|
50
|
-
|
51
|
-
PRODUCT_TABLE_BASE_DATA = [['CÓD.', 'DESCRIÇÃO', 'QTD.', 'UND.', 'V.UNIT', 'V.TOT']].freeze
|
52
|
-
# :reek:FeatureEnvy
|
53
|
-
def product_table_data(data)
|
54
|
-
data[:products].reduce(PRODUCT_TABLE_BASE_DATA) do |result, cur|
|
55
|
-
result + [[
|
56
|
-
cur[:code],
|
57
|
-
cur[:description],
|
58
|
-
format_number(cur[:quantity]),
|
59
|
-
cur[:unit_label],
|
60
|
-
format_currency(cur[:unit_value]),
|
61
|
-
format_currency(cur[:total_value])
|
62
|
-
]]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
private_class_method :product_table_data
|
66
22
|
end
|
67
23
|
end
|
68
24
|
end
|
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BrInvoicesPdf
|
2
4
|
module Cfe
|
3
5
|
module Renderer
|
4
6
|
module QrCode
|
7
|
+
extend Util::BaseRenderer
|
5
8
|
extend BaseRenderer
|
6
9
|
|
7
10
|
module_function
|
8
11
|
|
9
|
-
SAT_QRCODE_SEPARATOR = '|'
|
12
|
+
SAT_QRCODE_SEPARATOR = '|'
|
10
13
|
BARCODE_HEIGHT = 50
|
11
14
|
|
12
15
|
def execute(pdf, data)
|
@@ -50,19 +53,12 @@ module BrInvoicesPdf
|
|
50
53
|
end
|
51
54
|
private_class_method :generate_qr_code
|
52
55
|
|
53
|
-
def generate_qr_code_data(qr_code_string, qrcode_size)
|
54
|
-
qrcode = RQRCode::QRCode.new(qr_code_string)
|
55
|
-
blob = qrcode.as_png(size: qrcode_size.to_i, border_modules: 0).to_blob
|
56
|
-
StringIO.new(blob)
|
57
|
-
end
|
58
|
-
private_class_method :generate_qr_code_data
|
59
|
-
|
60
56
|
# rubocop:disable Metrics/AbcSize
|
61
57
|
def generate_qr_code_string(access_key, data)
|
62
58
|
sat_params = data[:sat_params]
|
63
59
|
access_key + SAT_QRCODE_SEPARATOR + sat_params[:emission_date] +
|
64
60
|
SAT_QRCODE_SEPARATOR + sat_params[:emission_hour] +
|
65
|
-
SAT_QRCODE_SEPARATOR + data[:
|
61
|
+
SAT_QRCODE_SEPARATOR + data[:totals][:total].delete('.') + SAT_QRCODE_SEPARATOR +
|
66
62
|
data[:company_attributes][:cnpj] + SAT_QRCODE_SEPARATOR +
|
67
63
|
sat_params[:document_qr_code_signature]
|
68
64
|
end
|
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BrInvoicesPdf
|
2
4
|
module Cfe
|
3
5
|
module Renderer
|
4
6
|
module TaxesInfo
|
7
|
+
extend Util::BaseRenderer
|
5
8
|
extend BaseRenderer
|
6
9
|
|
7
10
|
module_function
|
8
11
|
|
9
12
|
def execute(pdf, data)
|
10
13
|
box(pdf, [0, pdf.cursor], page_content_width(pdf)) do
|
11
|
-
tribute_values(pdf, data[:
|
14
|
+
tribute_values(pdf, data[:totals])
|
12
15
|
sat_params = data[:sat_params]
|
13
16
|
sat_number(pdf, sat_params[:sat_number])
|
14
17
|
date_values(pdf, sat_params)
|
@@ -17,7 +20,7 @@ module BrInvoicesPdf
|
|
17
20
|
|
18
21
|
def date_values(pdf, data)
|
19
22
|
time = data[:emission_date] + data[:emission_hour]
|
20
|
-
pdf.text(
|
23
|
+
pdf.text(Date.parse(time).strftime('%d/%m/%Y %H:%M:%S'), align: :center)
|
21
24
|
end
|
22
25
|
private_class_method :date_values
|
23
26
|
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BrInvoicesPdf
|
2
4
|
module Cfe
|
3
5
|
module Renderer
|
4
6
|
module Totals
|
7
|
+
extend Util::BaseRenderer
|
5
8
|
extend BaseRenderer
|
6
9
|
|
7
10
|
module_function
|
@@ -12,30 +15,6 @@ module BrInvoicesPdf
|
|
12
15
|
pdf.move_down(5)
|
13
16
|
end
|
14
17
|
|
15
|
-
def insert_box_info(pdf, data, xpos = 0)
|
16
|
-
third_width = page_content_width(pdf) * 0.333333333
|
17
|
-
ypos = pdf.cursor
|
18
|
-
box_info(data[:payment]).each do |(title, value)|
|
19
|
-
insert_box(pdf, title: title, value: value, xpos: xpos, ypos: ypos, third_width: third_width)
|
20
|
-
xpos += third_width
|
21
|
-
end
|
22
|
-
end
|
23
|
-
private_class_method :insert_box_info
|
24
|
-
|
25
|
-
# :reek:FeatureEnvy
|
26
|
-
def insert_box(pdf, params)
|
27
|
-
box(pdf, [params[:xpos], params[:ypos]], params[:third_width]) do
|
28
|
-
insert_texts(pdf, params[:title], params[:value])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
private_class_method :insert_box
|
32
|
-
|
33
|
-
def insert_texts(pdf, title, value)
|
34
|
-
pdf.text(title, style: :italic)
|
35
|
-
pdf.text(value, align: :right)
|
36
|
-
end
|
37
|
-
private_class_method :insert_texts
|
38
|
-
|
39
18
|
def box_info(data_payment)
|
40
19
|
[
|
41
20
|
['Total bruto dos itens', format_currency(data_payment[:total_price])],
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'br_invoices_pdf/cfe/renderer/company_identification'
|
2
4
|
require 'br_invoices_pdf/cfe/renderer/fisco_info'
|
3
5
|
require 'br_invoices_pdf/cfe/renderer/header'
|
@@ -12,7 +14,7 @@ module BrInvoicesPdf
|
|
12
14
|
module Renderer
|
13
15
|
module_function
|
14
16
|
|
15
|
-
|
17
|
+
extend Util::PdfRenderer
|
16
18
|
|
17
19
|
RENDERERS = [
|
18
20
|
CompanyIdentification,
|
@@ -25,24 +27,8 @@ module BrInvoicesPdf
|
|
25
27
|
FiscoInfo
|
26
28
|
].freeze
|
27
29
|
|
28
|
-
# :reek:FeatureEnvy
|
29
30
|
def pdf(data, options)
|
30
|
-
|
31
|
-
|
32
|
-
Prawn::Document.new(options.merge(page_size: [page_width, AUTO_HEIGHT_MOCK])) do |pdf|
|
33
|
-
pdf_content(pdf, data, page_width)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def pdf_content(pdf, data, page_width)
|
38
|
-
pdf.font_size(7) do
|
39
|
-
RENDERERS.each do |renderer|
|
40
|
-
renderer.execute(pdf, data)
|
41
|
-
end
|
42
|
-
|
43
|
-
page = pdf.page
|
44
|
-
page.dictionary.data[:MediaBox] = [0, pdf.y - page.margins[:bottom], page_width, AUTO_HEIGHT_MOCK]
|
45
|
-
end
|
31
|
+
generate_pdf(data, options, RENDERERS)
|
46
32
|
end
|
47
33
|
end
|
48
34
|
end
|
data/lib/br_invoices_pdf/cfe.rb
CHANGED