Module: Clinvoice::RenderItems

Defined in:
lib/clinvoice/render_items.rb

Class Method Summary collapse

Class Method Details

.call(pdf, data_items) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/clinvoice/render_items.rb', line 5

def self.call(pdf, data_items)
  pdf.move_down 20

  pdf.table(items(data_items), width: pdf.bounds.width) do
    style(row(1..-1).columns(0..-1), padding: [4, 5, 4, 5], borders: [:bottom], border_color: 'dddddd')
    style(row(0), background_color: 'e9e9e9', border_color: 'dddddd', font_style: :bold)
    style(row(0).columns(0..-1), borders: i[top bottom])
    style(row(0).columns(0), borders: i[top left bottom])
    style(row(0).columns(-1), borders: i[top right bottom])
    style(row(-1), border_width: 2)
    style(column(2..-1), align: :right)
    style(columns(0), width: 280)
  end

  pdf.move_down 10
end

.formatted_items(items) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/clinvoice/render_items.rb', line 31

def self.formatted_items(items)
  items.map do |item|
    [
      item[0],
      Clinvoice::Helper.format_currency(item[1]),
      item[2],
      Clinvoice::Helper.format_currency(item[3])
    ]
  end
end

.items(data_items) ⇒ Object



24
25
26
27
28
29
# File 'lib/clinvoice/render_items.rb', line 24

def self.items(data_items)
  header = ['Description', 'Unit Cost', 'Quantity', 'Line Total']
  blank_line = [' ', ' ', ' ', ' ']

  [header] + formatted_items(data_items) + [blank_line]
end