Class: RegisterPdf

Inherits:
Prawn::Document
  • Object
show all
Defined in:
lib/models/register_pdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, cash) ⇒ RegisterPdf

Returns a new instance of RegisterPdf.



4
5
6
7
8
9
10
11
12
# File 'lib/models/register_pdf.rb', line 4

def initialize(date,cash)
  super( top_margin: 35)
  @date = Vfwcash.set_date(date).beginning_of_month
  @config = cash.config
  cash.get_fund_balances(@date,@date.end_of_month)
  @response = cash.split_ledger_api(@date)
  make_pdf
  number_pages "#{Date.today}   -   Page <page> of <total>", { :start_count_at => 0, :page_filter => :all, :at => [bounds.right - 100, 0], :align => :right, :size => 6 }
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



2
3
4
# File 'lib/models/register_pdf.rb', line 2

def date
  @date
end

#responseObject

Returns the value of attribute response.



2
3
4
# File 'lib/models/register_pdf.rb', line 2

def response
  @response
end

Instance Method Details

#balance_rowObject



18
19
20
# File 'lib/models/register_pdf.rb', line 18

def balance_row
  [{content:'',colspan: 2},"Beginning Balance",nil,nil,nil,nil,{content: money(@response[:balances][:checking][:bbalance]),align: :right}]
end

#build_tableObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/models/register_pdf.rb', line 28

def build_table
  @rows = [header]
  @rows << balance_row
  @response[:rows].each do |row|
    arr =  [row[:date],row[:num],row[:desc],row[:memo],row[:r]]
    arr << (row[:checking][:db].zero? ? nil : {content: money(row[:checking][:db]), align: :right})
    arr << (row[:checking][:cr].zero? ? nil : {content: money(row[:checking][:cr]), align: :right})
    arr << (row[:balance].zero? ? nil : {content: money(row[:balance]), align: :right})
    @rows << arr
  end
end

#draw_tableObject



40
41
42
43
44
45
46
47
48
# File 'lib/models/register_pdf.rb', line 40

def draw_table
  text "#{@config[:post][:post]} Checkbook Register - #{@date}", style: :bold, align: :center
  move_down(2)
  e = make_table @rows,row_colors: ["F8F8F8", "FFFFFF"],:cell_style => {:padding => [1, 2, 2, 1],border_color:"E0E0E0"}, 
    :column_widths => [40, 24, 150,110,10,40,40,40,40], header:true do
    row(0).font_style = :bold
  end
  e.draw
end

#headerObject



14
15
16
# File 'lib/models/register_pdf.rb', line 14

def header
  arr = ["Date", "Num","Description","Account","R","Debits","Credits", "Balance"]
end

#make_pdfObject



22
23
24
25
26
# File 'lib/models/register_pdf.rb', line 22

def make_pdf
  font_size 7
  build_table
  draw_table
end

#money(int) ⇒ Object



50
51
52
# File 'lib/models/register_pdf.rb', line 50

def money(int)
  Vfwcash.money(int)
end