Class: ProfitLoss
- Inherits:
-
Prawn::Document
- Object
- Prawn::Document
- ProfitLoss
- Defined in:
- lib/models/profit_loss.rb
Constant Summary collapse
- COL =
[140,210,280,350]
Instance Attribute Summary collapse
-
#cur ⇒ Object
Returns the value of attribute cur.
-
#level ⇒ Object
Returns the value of attribute level.
-
#report ⇒ Object
Returns the value of attribute report.
Instance Method Summary collapse
- #children(pad, kids) ⇒ Object
- #generate_report ⇒ Object
- #imoney(int, dollar = "$") ⇒ Object
-
#initialize(report) ⇒ ProfitLoss
constructor
A new instance of ProfitLoss.
- #pad11_row(acct, amount) ⇒ Object
- #pad12_row(acct, amount) ⇒ Object
- #pad13_row(acct, amount) ⇒ Object
- #pad22_row(acct, amount) ⇒ Object
- #pad23_row(acct, amount) ⇒ Object
- #pad33_row(acct, amount) ⇒ Object
- #total_row(name, amount, extra = nil) ⇒ Object
Constructor Details
#initialize(report) ⇒ ProfitLoss
Returns a new instance of ProfitLoss.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#cur ⇒ Object
Returns the value of attribute cur.
3 4 5 |
# File 'lib/models/profit_loss.rb', line 3 def cur @cur end |
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/models/profit_loss.rb', line 3 def level @level end |
#report ⇒ Object
Returns the value of attribute report.
3 4 5 |
# File 'lib/models/profit_loss.rb', line 3 def report @report end |
Instance Method Details
#children(pad, kids) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# 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 = "$") ⇒ Object
107 108 109 110 111 112 113 114 |
# 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) ⇒ Object
64 65 66 67 68 |
# 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) ⇒ Object
70 71 72 73 74 |
# 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) ⇒ Object
89 90 91 92 93 |
# 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) ⇒ Object
76 77 78 79 80 |
# 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) ⇒ Object
95 96 97 98 99 |
# 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) ⇒ Object
101 102 103 104 105 |
# 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) ⇒ Object
55 56 57 58 59 60 61 62 |
# 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 |