Class: SunatBooks::Pdf::Base
- Inherits:
-
Prawn::Document
- Object
- Prawn::Document
- SunatBooks::Pdf::Base
show all
- Includes:
- Prawn::Table::Interface, Utils
- Defined in:
- lib/sunat_books/pdf/base.rb
Constant Summary
Constants included
from Utils
Utils::MONTHS
Instance Method Summary
collapse
-
#book_header(period, ruc, name, title = nil) ⇒ Object
-
#book_title(title) ⇒ Object
-
#get_counts(tickets) ⇒ Object
-
#get_mother_counts(tickets) ⇒ Object
-
#get_value(ticket, count) ⇒ Object
-
#make_sub_table(content, width = nil) ⇒ Object
-
#prawn_header(title, period, company) ⇒ Object
-
#sub_head(hash, book_name, blayout) ⇒ Object
-
#sub_head_options(column_widths) ⇒ Object
-
#sub_head_table(widths, arr, key) ⇒ Object
-
#table_body(fields, ticket, widths, aligns) ⇒ Object
-
#table_hash(field, ticket, tbody, widths, aligns) ⇒ Object
-
#table_head(fields, book_name, layout) ⇒ Object
Methods included from Utils
#add_align, #add_widths, #field_value, #formated_number, #get_column_widths, #get_date, #get_period, #get_row_sums, #order_data_row, #parse_day, #sum_count, #txt, #zero
#available_value?
Instance Method Details
47
48
49
50
51
52
53
|
# File 'lib/sunat_books/pdf/base.rb', line 47
def (period, ruc, name, title = nil)
move_down 5
txt name.to_s.upcase
txt "RUC: #{ruc}"
book_title("#{title} - #{period}")
move_down 5
end
|
#book_title(title) ⇒ Object
43
44
45
|
# File 'lib/sunat_books/pdf/base.rb', line 43
def book_title(title)
text title, align: :center, size: 8
end
|
#get_counts(tickets) ⇒ Object
106
107
108
|
# File 'lib/sunat_books/pdf/base.rb', line 106
def get_counts(tickets)
tickets.map(&:uniq_counts).flatten.uniq.sort
end
|
#get_mother_counts(tickets) ⇒ Object
110
111
112
|
# File 'lib/sunat_books/pdf/base.rb', line 110
def get_mother_counts(tickets)
tickets.map(&:uniq_mother_counts).flatten.uniq.sort
end
|
#get_value(ticket, count) ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/sunat_books/pdf/base.rb', line 114
def get_value(ticket, count)
active_amount = ticket.get_amount_by_mother_count(count)
pasive_amount = ticket.get_amount_by_mother_count(count, false)
active_amount - pasive_amount
end
|
#make_sub_table(content, width = nil) ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/sunat_books/pdf/base.rb', line 125
def make_sub_table(content, width = nil)
options = { cell_style: { width: width, size: 5, borders: [],
align: :right } }
content_row = []
content.each { |c| content_row << formated_number(c) }
make_table([content_row], options)
end
|
55
56
57
58
59
60
61
62
63
|
# File 'lib/sunat_books/pdf/base.rb', line 55
def (title, period, company)
repeat(:all) do
canvas do
bounding_box([bounds.left + 10, bounds.top - 10], width: 800) do
period, company.ruc, company.name, title
end
end
end
end
|
#sub_head(hash, book_name, blayout) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/sunat_books/pdf/base.rb', line 15
def sub_head(hash, book_name, blayout)
arr, current_key = nil
hash.each do |key, value|
k = I18n.t("books.#{book_name}.#{key}").mb_chars.upcase.to_s
v = value.collect do |s|
I18n.t("books.#{book_name}.#{s}").mb_chars.upcase.to_s
end
arr = [[{ content: k, colspan: value.length }], v]
current_key = key
end
sub_head_table(blayout["widths"], arr, current_key)
end
|
#sub_head_options(column_widths) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/sunat_books/pdf/base.rb', line 35
def sub_head_options(column_widths)
options = { cell_style: {
borders: [], size: 5, align: :center, padding: 1
} }
add_widths(column_widths, options, 22)
options
end
|
#sub_head_table(widths, arr, key) ⇒ Object
29
30
31
32
33
|
# File 'lib/sunat_books/pdf/base.rb', line 29
def sub_head_table(widths, arr, key)
column_widths = get_column_widths(widths, key)
options = sub_head_options(column_widths)
make_table(arr, options)
end
|
#table_body(fields, ticket, widths, aligns) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/sunat_books/pdf/base.rb', line 78
def table_body(fields, ticket, widths, aligns)
tbody = []
fields.each do |f|
if f.is_a? Hash
table_hash(f, ticket, tbody, widths, aligns)
else
tbody << field_value(ticket, f)
end
end
tbody
end
|
#table_hash(field, ticket, tbody, widths, aligns) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/sunat_books/pdf/base.rb', line 90
def table_hash(field, ticket, tbody, widths, aligns)
options = { cell_style: { borders: [], size: 5 } }
field.each do |key, value|
v = value.collect do |s|
value = field_value(ticket, s)
end
column_widths = get_column_widths(widths, key)
add_widths(column_widths, options, 28)
add_align(aligns, options, key) unless aligns.nil?
tbody << make_table([v], options)
end
end
|
#table_head(fields, book_name, layout) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/sunat_books/pdf/base.rb', line 65
def table_head(fields, book_name, layout)
thead = []
fields.each do |h|
if h.instance_of? Hash
r = sub_head(h, book_name, layout)
thead << r
else
thead << I18n.t("books.#{book_name}.#{h}").mb_chars.upcase.to_s
end
end
thead
end
|