From 4434a601d3c2fe996cd2fb7ed15a08a802720185 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 14 Dec 2016 11:49:16 +0100 Subject: [PATCH] Implements several helper methods for formatting amounts --- app/models/budget.rb | 4 ++++ app/models/budget/ballot.rb | 14 +++++++++++--- app/views/budgets/ballot/_ballot.html.erb | 4 ++-- app/views/budgets/ballot/_progress_bar.html.erb | 8 ++++---- app/views/budgets/investments/_sidebar.html.erb | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/models/budget.rb b/app/models/budget.rb index 3f9822964..ae5bdf71e 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -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 diff --git a/app/models/budget/ballot.rb b/app/models/budget/ballot.rb index fa7317dc8..79aa56ce7 100644 --- a/app/models/budget/ballot.rb +++ b/app/models/budget/ballot.rb @@ -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) diff --git a/app/views/budgets/ballot/_ballot.html.erb b/app/views/budgets/ballot/_ballot.html.erb index 99fdcd5cd..7ed6851ae 100644 --- a/app/views/budgets/ballot/_ballot.html.erb +++ b/app/views/budgets/ballot/_ballot.html.erb @@ -28,7 +28,7 @@

<%= t("budgets.ballots.show.amount_spent") %> - <%= @budget.formatted_amount(@ballot.amount_spent(@ballot.heading_for_group(group).id))) %> + <%= @ballot.formatted_amount_spent(@ballot.heading_for_group(group)) %>

<% else %> @@ -47,7 +47,7 @@

<%= 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 %>

<% end %> diff --git a/app/views/budgets/ballot/_progress_bar.html.erb b/app/views/budgets/ballot/_progress_bar.html.erb index 7c3190ba6..45c338b88 100644 --- a/app/views/budgets/ballot/_progress_bar.html.erb +++ b/app/views/budgets/ballot/_progress_bar.html.erb @@ -7,7 +7,7 @@
+ @ballot.amount_spent(@heading)) %>">
@@ -16,12 +16,12 @@ + @ballot.amount_spent(@heading)) %>">

- <%= @budget.format_amount(@ballot.amount_spent(@heading.id)) %> + <%= @ballot.formatted_amount_spent(@heading) %> <%= t("budget.progress_bar.available") %> - <%= @budget.format_amount(@ballot.amount_available(@heading)) %> + <%= @ballot.formatted_amount_available(@heading) %>

diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb index baeb72bd6..5dc6c1aad 100644 --- a/app/views/budgets/investments/_sidebar.html.erb +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -13,7 +13,7 @@ <%= 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)) %>

<% else %>