Implements several helper methods for formatting amounts

This commit is contained in:
kikito
2016-12-14 11:49:16 +01:00
parent d5065fe021
commit 4434a601d3
5 changed files with 22 additions and 10 deletions

View File

@@ -61,5 +61,9 @@ class Budget < ActiveRecord::Base
def formatted_heading_price(heading)
formatted_amount(heading_price(heading))
end
def formatted_heading_amount_spent(heading)
formatted_amount(amount_spent(heading))
end
end

View File

@@ -16,12 +16,20 @@ class Budget
investments.sum(:price).to_i
end
def amount_spent(heading_id)
investments.by_heading(heading_id).sum(:price).to_i
def amount_spent(heading)
investments.by_heading(heading.id).sum(:price).to_i
end
def formatted_amount_spent(heading)
budget.formatted_amount(amount_spent(heading))
end
def amount_available(heading)
budget.heading_price(heading) - amount_spent(heading.id)
budget.heading_price(heading) - amount_spent(heading)
end
def formatted_amount_available(heading)
budget.formatted_amount(amount_available(heading))
end
def has_lines_in_group?(group)

View File

@@ -28,7 +28,7 @@
<h4 class="amount-spent text-right">
<%= t("budgets.ballots.show.amount_spent") %>
<span>
<%= @budget.formatted_amount(@ballot.amount_spent(@ballot.heading_for_group(group).id))) %>
<%= @ballot.formatted_amount_spent(@ballot.heading_for_group(group)) %>
</span>
</h4>
<% else %>
@@ -47,7 +47,7 @@
<h4>
<%= t("budgets.ballots.show.remaining",
amount_city: @budget.formatted_amount(@ballot.amount_available(@ballot.heading_for_group(group))))).html_safe %>
amount_city: @ballot.formatted_amount_available(@ballot.heading_for_group(group)).html_safe %>
</h4>
</div>
<% end %>

View File

@@ -7,7 +7,7 @@
<div class="progress-meter"
style="width:
<%= progress_bar_width(@budget.heading_price(@heading),
@ballot.amount_spent(@heading.id)) %>">
@ballot.amount_spent(@heading)) %>">
</div>
</div>
@@ -16,12 +16,12 @@
<span class="progress-meter spent-amount-meter"
style="width:
<%= progress_bar_width(@budget.heading_price(@heading),
@ballot.amount_spent(@heading.id)) %>">
@ballot.amount_spent(@heading)) %>">
<p id="amount-spent" class="progress-meter-text spent-amount-text">
<%= @budget.format_amount(@ballot.amount_spent(@heading.id)) %>
<%= @ballot.formatted_amount_spent(@heading) %>
<span id="amount-available" class="amount-available">
<%= t("budget.progress_bar.available") %>
<span><%= @budget.format_amount(@ballot.amount_available(@heading)) %></span>
<span><%= @ballot.formatted_amount_available(@heading) %></span>
</span>
</p>
</span>

View File

@@ -13,7 +13,7 @@
<em>
<%= t("budget.investments.index.sidebar.voted_html",
count: @ballot.investments.by_heading(@heading.id).count,
amount_spent: @budget.format_amount(@ballot.amount_spent(@heading))) %>
amount_spent: @ballot.formatted_amount_spent(@heading)) %>
</em>
</p>
<% else %>