Class: SplitLedger
- Inherits:
-
Prawn::Document
- Object
- Prawn::Document
- SplitLedger
- Defined in:
- lib/models/split_ledger.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #balance_row ⇒ Object
- #build_table ⇒ Object
- #draw_table ⇒ Object
- #header ⇒ Object
-
#initialize(date, cash) ⇒ SplitLedger
constructor
A new instance of SplitLedger.
- #make_pdf ⇒ Object
- #money(int) ⇒ Object
Constructor Details
#initialize(date, cash) ⇒ SplitLedger
Returns a new instance of SplitLedger.
4 5 6 7 8 9 10 11 12 |
# File 'lib/models/split_ledger.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
#date ⇒ Object
Returns the value of attribute date.
2 3 4 |
# File 'lib/models/split_ledger.rb', line 2 def date @date end |
#response ⇒ Object
Returns the value of attribute response.
2 3 4 |
# File 'lib/models/split_ledger.rb', line 2 def response @response end |
Instance Method Details
#balance_row ⇒ Object
18 19 20 |
# File 'lib/models/split_ledger.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_table ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/models/split_ledger.rb', line 28 def build_table @rows = [header] @rows << balance_row @response[:rows].each do |row| arr = [row[:date],row[:num],row[:desc],nil,nil] 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 row[:details].each do |d| arr = [{content:'',colspan: 2},d[:memo], d[:name],d[:r], (d[:db].zero? ? nil : {content: money(d[:db]), align: :right}), (d[:cr].zero? ? nil : {content: money(d[:cr]), align: :right}), nil ] @rows << arr end end end |
#draw_table ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/models/split_ledger.rb', line 48 def draw_table text "#{@config[:post][:post]} Split Ledger - #{@date}", style: :bold, align: :center move_down(2) e = make_table @rows,:cell_style => {:padding => [1, 2, 2, 1],border_color:"E0E0E0"}, :column_widths => [40, 24, 150,100,10,40,40,40,40], header:true do row(0).font_style = :bold i = row_length - 1 0.upto(i) do |j| if cells[j,0].content.blank? row(j).style(:background_color => 'F8F8F8') end end end e.draw end |
#header ⇒ Object
14 15 16 |
# File 'lib/models/split_ledger.rb', line 14 def header arr = ["Date", "Num","Description","Account","R","Debits","Credits", "Balance"] end |
#make_pdf ⇒ Object
22 23 24 25 26 |
# File 'lib/models/split_ledger.rb', line 22 def make_pdf font_size 7 build_table draw_table end |