Class: Ledger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, cash) ⇒ Ledger

Returns a new instance of Ledger.



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

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

#cwidthsObject

Returns the value of attribute cwidths.



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

def cwidths
  @cwidths
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#bbalance_rowObject



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

def bbalance_row
  cntnt = "Beginning balance #{@response[:month]}: "
  cntnt += "Total Current Assets #{money(@response[:balances][:savings][:bbalance] + @response[:balances][:checking][:bbalance])}"

  arr = [{content: cntnt,colspan:4,font_style: :bold}]
  arr << {content: money(@response[:balances][:checking][:bbalance]),colspan:2, align: :center,font_style: :bold}
  @response[:funds][:checking].each do |f|
    arr << { content: money(@response[:balances][:funds][f][:bbalance]),colspan:2, align: :center,font_style: :bold}
  end
  arr << {content: money(@response[:balances][:savings][:bbalance]),colspan:2, align: :center,font_style: :bold}
  arr
end

#build_tableObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/models/ledger.rb', line 75

def build_table
  @rows = [header]
  @rows << bbalance_row
  @response[:rows].each do |r|
    arr = []
    r.each do |k,v|
      if v.class == Hash
        arr << (v[:db].zero? ? nil :{content: (money(v[:db])), align: :right})
        arr << (v[:cr].zero? ? nil :{content: (money(v[:cr])), align: :right})
      else
        arr << v
      end
    end
    @rows << arr
  end
  @rows << summary_row
  @rows << ebalance_row
end

#draw_tableObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/models/ledger.rb', line 94

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

#ebalance_rowObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/models/ledger.rb', line 42

def ebalance_row
  cntnt = "Ending balance #{@response[:month]}: "
  cntnt += "Total Current Assets #{money(@response[:balances][:savings][:ebalance] + @response[:balances][:checking][:ebalance])}"

  arr = [{content: cntnt,colspan:4,font_style: :bold}]
  arr << {content: money(@response[:balances][:checking][:ebalance]),colspan:2, align: :center,font_style: :bold}
  @response[:funds][:checking].each do |f|
    arr << { content: money(@response[:balances][:funds][f][:ebalance]),colspan:2, align: :center,font_style: :bold}
  end
  arr << {content: money(@response[:balances][:savings][:ebalance]),colspan:2, align: :center,font_style: :bold}
  arr
end

#headerObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/models/ledger.rb', line 15

def header
  arr = ["Date", "Num","R", "Description", {content: "+ Checking -",colspan:2, align: :center}]
  @cwidths = [36, 22,8,108,32,32]
  @response[:funds][:checking].each do |f|
    arr << {content:"+ #{f} -",colspan:2, align: :center}
    @cwidths << 30
    @cwidths << 30
  end
  arr << {content:"+ Savings -",colspan:2, align: :center}
  @cwidths << 30
  @cwidths << 30
  arr
end

#make_pdfObject



69
70
71
72
73
# File 'lib/models/ledger.rb', line 69

def make_pdf
  font_size 6
  build_table
  draw_table
end

#money(int) ⇒ Object



105
106
107
# File 'lib/models/ledger.rb', line 105

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

#summary_rowObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/models/ledger.rb', line 55

def summary_row
  cntnt = "Debits/Credits Summary #{@response[:month]}: "
  arr = [{content: cntnt,colspan:4,font_style: :bold}]
  arr << {content: money(@response[:balances][:checking][:debits]), align: :right}
  arr << {content: money(@response[:balances][:checking][:credits]), align: :right}
  @response[:funds][:checking].each do |f|
    arr << {content: money(@response[:balances][:funds][f][:debits]), align: :right}
    arr << {content: money(@response[:balances][:funds][f][:credits]), align: :right}
  end
  arr << {content: money(@response[:balances][:savings][:debits]), align: :right}
  arr << {content: money(@response[:balances][:savings][:credits]), align: :right}
  arr
end