Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix: Apply right formatting for money values in outflows section (#425)

Alessio Cappa04189dec002a
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 210dff919d..858e54a9b7 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -14,7 +14,7 @@ class PagesController < ApplicationController
expense_totals = Current.family.income_statement.expense_totals(period: @period)
@cashflow_sankey_data = build_cashflow_sankey_data(income_totals, expense_totals, family_currency)
- @outflows_data = build_outflows_donut_data(expense_totals)
+ @outflows_data = build_outflows_donut_data(expense_totals, family_currency)
@dashboard_sections = build_dashboard_sections
@@ -213,8 +213,7 @@ class PagesController < ApplicationController
{ nodes: nodes, links: links, currency_symbol: Money::Currency.new(currency_symbol).symbol }
end
- def build_outflows_donut_data(expense_totals)
- currency_symbol = Money::Currency.new(expense_totals.currency).symbol
+ def build_outflows_donut_data(expense_totals, family_currency)
total = expense_totals.total
# Only include top-level categories with non-zero amounts
@@ -226,12 +225,13 @@ class PagesController < ApplicationController
id: ct.category.id,
name: ct.category.name,
amount: ct.total.to_f.round(2),
+ currency: ct.currency,
percentage: ct.weight.round(1),
color: ct.category.color.presence || Category::UNCATEGORIZED_COLOR,
icon: ct.category.lucide_icon
}
end
- { categories: categories, total: total.to_f.round(2), currency_symbol: currency_symbol }
+ { categories: categories, total: total.to_f.round(2), currency: family_currency, currency_symbol: Money::Currency.new(family_currency).symbol }
end
end
diff --git a/app/views/pages/dashboard/_outflows_donut.html.erb b/app/views/pages/dashboard/_outflows_donut.html.erb
index c046a0a886..7751fa7433 100644
--- a/app/views/pages/dashboard/_outflows_donut.html.erb
+++ b/app/views/pages/dashboard/_outflows_donut.html.erb
@@ -33,7 +33,7 @@
</div>
<div class="text-3xl font-medium text-primary">
- <%= outflows_data[:currency_symbol] %><%= number_with_delimiter(outflows_data[:total], delimiter: ",") %>
+ <%= format_money Money.new(outflows_data[:total], outflows_data[:currency]) %>
</div>
</div>
@@ -84,7 +84,7 @@
<span class="text-sm font-medium text-primary truncate"><%= category[:name] %></span>
</div>
<div class="flex items-center gap-4 flex-shrink-0">
- <span class="text-sm font-medium text-primary whitespace-nowrap"><%= outflows_data[:currency_symbol] %><%= number_with_delimiter(category[:amount], delimiter: ",") %></span>
+ <span class="text-sm font-medium text-primary whitespace-nowrap"><%= format_money Money.new(category[:amount], category[:currency]) %></span>
<span class="text-sm text-secondary whitespace-nowrap"><%= category[:percentage] %>%</span>
</div>
<% end %>