generated from espoo-dev/rails_boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevent_procedures_report_pdf.rb
More file actions
81 lines (66 loc) · 1.84 KB
/
event_procedures_report_pdf.rb
File metadata and controls
81 lines (66 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true
class EventProceduresReportPdf
attr_reader :pdf, :items, :amount, :title
def initialize(pdf:, items:, amount:, title:)
@pdf = pdf
@items = items
@amount = amount
@title = title
@header_footer_height = 100
@line_spacing = 15
@text_box_padding = 10
@right_text_offset = 110
end
def generate
add_header
add_body
add_footer
end
private
def add_header
pdf.repeat(:all) do
HeaderPdf.new(pdf: pdf, title: title).generate
end
end
def add_footer
pdf.repeat(:all, dynamic: true) do
FooterPdf.new(pdf: pdf, amount: amount).generate
end
end
def add_body
pdf.move_down @line_spacing
items.each do |item|
start_new_page_if_needed
pdf.stroke_horizontal_rule
add_item_details(item)
pdf.move_down @line_spacing
end
end
def start_new_page_if_needed
return unless pdf.cursor < @header_footer_height
pdf.start_new_page
add_header
end
def add_item_details(item)
add_item_line(truncate_text(item.patient.name), item_paid?(item))
add_item_line(truncate_text(item.procedure.name), item.procedure.amount.format)
add_item_line(truncate_text(item.health_insurance.name), item_date(item))
end
def add_item_line(left_text, right_text)
pdf.bounding_box([0, pdf.cursor], width: pdf.bounds.width) do
pdf.text_box left_text, at: [3, pdf.cursor - @text_box_padding], size: 10, align: :left
pdf.text_box right_text, at: [pdf.bounds.width - @right_text_offset, pdf.cursor - @text_box_padding], size: 10,
align: :right
end
pdf.move_down @line_spacing
end
def truncate_text(text, length = 35)
text.length > length ? "#..." : text
end
def item_paid?(item)
item.payd ? "Pago" : "A Receber"
end
def item_date(item)
item.date.strftime("%d/%m/%Y")
end
end