class ProfitLoss
Constants
- COL
Attributes
cur[RW]
level[RW]
report[RW]
Public Class Methods
new(report)
click to toggle source
Calls superclass method
# File lib/models/profit_loss.rb, line 5 def initialize(report) super(page_layout: :portrait, top_margin:32, left_margin:32, right_margin:32,bottom_margin:32) level = 2 if level.nil? @report = report @level = @report['options'][:level] from = @report['options'][:from] to = @report['options'][:to] font_size(14) text "VFW Post 8600 Profit/Loss Report #{from} to #{to}", style: :bold, align: :center move_down 6 font_size(9) @cur = cursor.to_i generate_report end
Public Instance Methods
children(pad,kids)
click to toggle source
# File lib/models/profit_loss.rb, line 32 def children(pad,kids) kids.each do |k,v| if v[:children].blank? send "pad#{pad}#{@level}_row", k,v[:amount] unless v[:amount].zero? else # if @level == 1 if pad == @level unless v[:total].zero? send "pad#{pad}#{@level}_row",k,v[:total]+v[:amount] end else unless v[:total].zero? send "pad#{pad}#{@level}_row", k,v[:amount] pad += 1 children(pad,v[:children]) pad -= 1 send "pad#{pad}#{@level}_row", "Total #{k}",v[:amount] + v[:total] end end end end end
generate_report()
click to toggle source
# File lib/models/profit_loss.rb, line 20 def generate_report total_row("Income",'','Increase') pad = 1 children(pad,@report["Income"][:children]) total_row("Total Income",@report["Income"][:total]) pad = 1 total_row("Expenses",'','Decrease') children(pad,@report["Expense"][:children]) total_row("Total Expenses",@report["Expense"][:total]) total_row("Profit(+)/Loss(-)",@report["Income"][:total] - @report["Expense"][:total]) end
imoney(int,dollar="$")
click to toggle source
# File lib/models/profit_loss.rb, line 107 def imoney(int,dollar="$") return '' if int.to_i.zero? dollars = int / 100 cents = (int % 100) / 100.0 amt = dollars + cents set_zero = sprintf('%.2f',amt) # now have a string to 2 decimals '$'+set_zero.gsub(/(\d)(?=(\d{3})+(?!\d))/, "\\1,") # add commas end
pad11_row(acct,amount)
click to toggle source
# File lib/models/profit_loss.rb, line 64 def pad11_row(acct,amount) text_box acct, at: [10,@cur], width:130,align: :left text_box imoney(amount), at: [140,@cur], width:70,align: :right @cur -= 10 end
pad12_row(acct,amount)
click to toggle source
# File lib/models/profit_loss.rb, line 70 def pad12_row(acct,amount) text_box acct, at: [10,@cur], width:130,align: :left text_box imoney(amount), at: [210,@cur], width:70,align: :right @cur -= 10 end
pad13_row(acct,amount)
click to toggle source
def pad32_row(acct,amount)
text_box acct, at: [30,@cur], width:110,align: :left text_box imoney(amount), at: [140,@cur], width:70,align: :right @cur -= 10
end
# File lib/models/profit_loss.rb, line 89 def pad13_row(acct,amount) text_box acct, at: [10,@cur], width:130,align: :left text_box imoney(amount), at: [280,@cur], width:70,align: :right @cur -= 10 end
pad22_row(acct,amount)
click to toggle source
# File lib/models/profit_loss.rb, line 76 def pad22_row(acct,amount) text_box acct, at: [20,@cur], width:120,align: :left text_box imoney(amount), at: [140,@cur], width:70,align: :right @cur -= 10 end
pad23_row(acct,amount)
click to toggle source
# File lib/models/profit_loss.rb, line 95 def pad23_row(acct,amount) text_box acct, at: [20,@cur], width:120,align: :left text_box imoney(amount), at: [210,@cur], width:70,align: :right @cur -= 10 end
pad33_row(acct,amount)
click to toggle source
# File lib/models/profit_loss.rb, line 101 def pad33_row(acct,amount) text_box acct, at: [30,@cur], width:100,align: :left text_box imoney(amount), at: [140,@cur], width:70,align: :right @cur -= 10 end
total_row(name,amount,extra=nil)
click to toggle source
# File lib/models/profit_loss.rb, line 55 def total_row(name,amount,extra=nil) text_box name, at: [0,@cur], width:140,align: :left, style: :bold unless extra.nil? text_box extra, at: [COL[@level - 1],@cur], width:70,align: :right, style: :bold end text_box imoney(amount), at: [COL[@level],@cur], width:70,align: :right, style: :bold @cur -= 10 end