Skip to content

Commit

Permalink
Show budget averages in family currency
Browse files Browse the repository at this point in the history
Fixes #1689
  • Loading branch information
zachgoll committed Jan 25, 2025
1 parent 7e0ec4b commit e617d79
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
12 changes: 12 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ def month_total(date: Date.current)
family.category_stats.month_total_for(self, date: date)
end

def avg_monthly_total_money
Money.new(avg_monthly_total, family.currency)
end

def median_monthly_total_money
Money.new(median_monthly_total, family.currency)
end

def month_total_money(date: Date.current)
Money.new(month_total(date: date), family.currency)
end

private
def category_level_limit
if subcategory? && parent.subcategory?
Expand Down
2 changes: 1 addition & 1 deletion app/views/budget_categories/_budget_category.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<% end %>
<% else %>
<p class="text-sm text-gray-500 font-medium">
<%= format_money(budget_category.category.avg_monthly_total) %> avg
<%= format_money(budget_category.category.avg_monthly_total_money, precision: 0) %> avg
</p>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/budget_categories/_budget_category_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="text-sm mr-3">
<p class="text-gray-900 font-medium mb-0.5"><%= budget_category.category.name %></p>

<p class="text-gray-500"><%= format_money(Money.new(budget_category.category.avg_monthly_total, budget_category.currency), precision: 0) %>/m average</p>
<p class="text-gray-500"><%= format_money(budget_category.category.avg_monthly_total_money, precision: 0) %>/m average</p>
</div>

<div class="ml-auto">
Expand Down
10 changes: 5 additions & 5 deletions app/views/budget_categories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<% if @budget_category.budget.initialized? %>
<p class="text-sm text-gray-500">
<span class="text-gray-900">
<%= format_money(@budget_category.actual_spending) %>
<%= format_money(@budget_category.actual_spending_money) %>
</span>
<span>/</span>
<span><%= format_money(@budget_category.budgeted_spending) %></span>
<span><%= format_money(@budget_category.budgeted_spending_money) %></span>
</p>
<% end %>
</div>
Expand Down Expand Up @@ -72,22 +72,22 @@
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500">Budgeted</dt>
<dd class="text-gray-900 font-medium">
<%= format_money @budget_category.budgeted_spending %>
<%= format_money @budget_category.budgeted_spending_money %>
</dd>
</div>
<% end %>

<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500">Monthly average spending</dt>
<dd class="text-gray-900 font-medium">
<%= format_money @budget_category.category.avg_monthly_total %>
<%= format_money @budget_category.category.avg_monthly_total_money, precision: 0 %>
</dd>
</div>

<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500">Monthly median spending</dt>
<dd class="text-gray-900 font-medium">
<%= format_money @budget_category.category.median_monthly_total %>
<%= format_money @budget_category.category.median_monthly_total_money, precision: 0 %>
</dd>
</div>
</dl>
Expand Down

0 comments on commit e617d79

Please sign in to comment.