Class: Balance

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, cash) ⇒ Balance

Returns a new instance of Balance.



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

def initialize(date,cash)
  super( top_margin: 35, page_layout: :landscape)
  @date = Vfwcash.set_date(date).beginning_of_month
  @m = Vfwcash.yyyymm(@date)
  @cash = cash
  cash.get_fund_balances(@date,@date.end_of_month)
  @config = @cash.config
  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

#cashObject

Returns the value of attribute cash.



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

def cash
  @cash
end

#cwidthsObject

Returns the value of attribute cwidths.



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

def cwidths
  @cwidths
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

Instance Method Details

#build_tableObject



70
71
72
73
74
75
76
# File 'lib/models/balance.rb', line 70

def build_table
  @rows = [header]
  @rows << checking_row
  @rows += fund_rows
  @rows << savings_row
  @rows << curr_assets_row
end

#checking_rowObject



19
20
21
22
23
24
25
26
27
# File 'lib/models/balance.rb', line 19

def checking_row
  arr = ["Checking"]
  arr << {content: money(@cash.balances[:checking][:bbalance]), align: :right}
  arr << {content: money(@cash.balances[:checking][:debits]), align: :right}
  arr << {content: money(@cash.balances[:checking][:credits]), align: :right}
  arr << {content: money(@cash.balances[:checking][:diff]), align: :right}
  arr << {content: money(@cash.balances[:checking][:ebalance]), align: :right}
  arr
end

#curr_assets_rowObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/models/balance.rb', line 53

def curr_assets_row
  arr = ["Curr Assets"]
  arr << {content: money(@cash.balances[:checking][:bbalance] + @cash.balances[:savings][:bbalance]), align: :right}
  arr << {content: money(@cash.balances[:checking][:debits] + @cash.balances[:savings][:debits]), align: :right}
  arr << {content: money(@cash.balances[:checking][:credits] + @cash.balances[:savings][:credits]), align: :right}
  arr << {content: money(@cash.balances[:checking][:diff] + @cash.balances[:savings][:diff]), align: :right}
  arr << {content: money(@cash.balances[:checking][:ebalance] + @cash.balances[:savings][:ebalance]), align: :right}
  arr

end

#draw_tableObject



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/models/balance.rb', line 78

def draw_table
  text "#{@config[:post][:post]} General Ledger Month Balances #{@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 => [60,60,60,60,60,60], header:true do
    
    row(0).font_style = :bold
    row(0).align = :center
    column(0).font_style = :bold
  end
  e.draw
end

#fund_rowsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/models/balance.rb', line 39

def fund_rows
  farr = []
  @cash.checking_funds.each do |f|
    arr = [f]
    arr << {content: money(@cash.balances[f][:bbalance]), align: :right}
    arr << {content: money(@cash.balances[f][:debits]), align: :right}
    arr << {content: money(@cash.balances[f][:credits]), align: :right}
    arr << {content: money(@cash.balances[f][:diff]), align: :right}
    arr << {content: money(@cash.balances[f][:ebalance]), align: :right}
    farr << arr
  end
  farr
end

#headerObject



15
16
17
# File 'lib/models/balance.rb', line 15

def header
  arr = %w(Fund BeginBal Debits Credits P/L EndBal)
end

#make_pdfObject



64
65
66
67
68
# File 'lib/models/balance.rb', line 64

def make_pdf
  font_size 9
  build_table
  draw_table
end

#money(int) ⇒ Object



91
92
93
# File 'lib/models/balance.rb', line 91

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

#savings_rowObject



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

def savings_row
  arr = ["Savings"]
  arr << {content: money(@cash.balances[:savings][:bbalance]), align: :right}
  arr << {content: money(@cash.balances[:savings][:debits]), align: :right}
  arr << {content: money(@cash.balances[:savings][:credits]), align: :right}
  arr << {content: money(@cash.balances[:savings][:diff]), align: :right}
  arr << {content: money(@cash.balances[:savings][:ebalance]), align: :right}
  arr
end