forked from jamis/bucketwise
/
subscriptions_helper.rb
37 lines (31 loc) · 1.32 KB
/
subscriptions_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module SubscriptionsHelper
def blank_slate?
subscription.accounts.empty?
end
def balance_cell(container, options={})
balance = real_balance = container.balance
if container.respond_to?(:available_balance)
balance = container.available_balance
end
classes = %w(number)
classes += Array(options[:classes]) if options[:classes]
classes << "negative" if balance < 0
classes << "current_balance"
if container.is_a?(Account) && container.credit_card? && !container.limit.blank?
percentage_used = container.limit.abs.to_i == 0 ? 100 :
((container.balance.abs.to_f / container.limit.abs.to_f) * 100).to_i
classes << if percentage_used >= Account::DEFAULT_LIMIT_VALUES[:critical]: "critical"
elsif percentage_used >= Account::DEFAULT_LIMIT_VALUES[:high]: "high"
elsif percentage_used >= Account::DEFAULT_LIMIT_VALUES[:medium]: "medium"
else "low" end
end
content = format_amount(balance)
if real_balance != balance
content = "<span class='real_balance'>(" << format_amount(real_balance) << ")</span> #{content}"
end
content_tag(options.fetch(:tag, "td"), content, :class => classes.join(" "), :id => options[:id])
end
def format_amount(amount)
number_to_currency(amount.abs / 100.0)
end
end