Class: SunatBooks::Pdf::SimplifiedDiary
Constant Summary
Constants included
from Utils
Utils::MONTHS
Instance Method Summary
collapse
-
#book_body(month, year, max_column = nil, period = nil) ⇒ Object
-
#draw_table_body(data, max_column, period) ⇒ Object
-
#draw_table_header(tickets, counts, total_sums, data, date) ⇒ Object
-
#entries_data(tickets, counts, total_sums, data, period_date) ⇒ Object
-
#initialize(company, tickets, month, year) ⇒ SimplifiedDiary
constructor
A new instance of SimplifiedDiary.
-
#not_moviment_data(data) ⇒ Object
-
#prawn_book(month, year) ⇒ Object
-
#prawn_new_page(period) ⇒ Object
-
#render_prawn_table(data) ⇒ Object
Methods included from PagesUtils
#not_moviment_page, #page_index, #page_not_full, #row_data, #setup_final_row_data, #setup_new_page, #setup_pages, #setup_row_pages, #split_data
#buys_entry, #calculate_totals, #close_entry, #current_sum_count, #get_row_sums, #increase_value, #initial_entry, #mother_count?, #other_entry, #sales_entry, #total_entry
Methods inherited from Base
#book_header, #book_title, #get_counts, #get_mother_counts, #get_value, #make_sub_table, #prawn_header, #sub_head, #sub_head_options, #sub_head_table, #table_body, #table_hash, #table_head
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?
Constructor Details
#initialize(company, tickets, month, year) ⇒ SimplifiedDiary
Returns a new instance of SimplifiedDiary.
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 13
def initialize(company, tickets, month, year)
super(page_layout: :landscape, margin: [5], page_size: "A4")
@company = company
@tickets = tickets
@main_title = "LIBRO DIARIO - FORMATO SIMPLIFICADO"
@counts = get_mother_counts @tickets
@total_sums = @counts.map { |count| CountSum.new(count) }
prawn_book(month, year)
end
|
Instance Method Details
#book_body(month, year, max_column = nil, period = nil) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 37
def book_body(month, year, max_column = nil, period = nil)
tickets = @tickets.where(period_month: month, period_year: year)
data = []
initial_day = get_date(year.to_i, month.to_i, 1)
(tickets, @counts, @total_sums, data, initial_day)
period_date = get_date(year, month, -1)
entries_data(tickets, @counts, @total_sums, data, period_date)
period, @company.ruc, @company.name, @main_title
draw_table_body(data, max_column, period)
end
|
#draw_table_body(data, max_column, period) ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 73
def draw_table_body(data, max_column, period)
return render_prawn_table(data) unless data.first.count > max_column
pages = split_data(data, max_column)
pages.each do |page|
prawn_new_page(period) unless page.page_number.zero?
render_prawn_table(page.data)
end
end
|
66
67
68
69
70
71
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 66
def (tickets, counts, total_sums, data, date)
data << ["FECHA", "OPERACIÓN", counts].flatten
initial_data = initial_entry(tickets, counts, total_sums)
data << [date, "ASIENTO INICIAL DEL PERIODO", initial_data].flatten
end
|
#entries_data(tickets, counts, total_sums, data, period_date) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 56
def entries_data(tickets, counts, total_sums, data, period_date)
return not_moviment_data(data) if tickets.empty?
sales_entry(tickets, counts, total_sums, data, period_date)
buys_entry(tickets, counts, total_sums, data, period_date)
other_entry(tickets, counts, total_sums, data)
close_entry(tickets, counts, total_sums, data)
total_entry(total_sums, data)
end
|
#not_moviment_data(data) ⇒ Object
52
53
54
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 52
def not_moviment_data(data)
data << [{ content: "SIN MOVIMIENTO EN EL PERIODO", colspan: 5 }]
end
|
#prawn_book(month, year) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 24
def prawn_book(month, year)
(month.to_i..12).each do |m|
start_new_page unless m == month.to_i
period = get_period(m, year)
x = bounds.left + 3
y = bounds.top - 10
bounding_box([x, y], width: 815, height: 510) do
book_body m, year, 20, period
end
end
end
|
#prawn_new_page(period) ⇒ Object
84
85
86
87
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 84
def prawn_new_page(period)
start_new_page
period, @company.ruc, @company.name, @main_title
end
|
#render_prawn_table(data) ⇒ Object
89
90
91
92
|
# File 'lib/sunat_books/pdf/simplified_diary.rb', line 89
def render_prawn_table(data)
table(data, header: true, cell_style: { borders: [], size: 6 },
column_widths: { 1 => 73 })
end
|