mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Support uncategorized investments (#593)
* Support uncategorized investments * FIX sankey id collision * Fix reports * Fix hardcoded string and i8n * FIX plurals * Remove spending patterns section add net worth section to reports
This commit is contained in:
@@ -70,13 +70,9 @@
|
||||
</div>
|
||||
<div class="py-3 shadow-border-xs rounded-lg bg-container font-medium text-sm max-w-full">
|
||||
<% outflows_data[:categories].each_with_index do |category, idx| %>
|
||||
<%= link_to transactions_path(q: { categories: [category[:name]], start_date: period.date_range.first, end_date: period.date_range.last }),
|
||||
class: "flex items-center justify-between mx-3 p-3 rounded-lg cursor-pointer group gap-3",
|
||||
data: {
|
||||
turbo_frame: "_top",
|
||||
category_id: category[:id],
|
||||
action: "mouseenter->donut-chart#highlightSegment mouseleave->donut-chart#unhighlightSegment"
|
||||
} do %>
|
||||
<%
|
||||
category_content = capture do
|
||||
%>
|
||||
<div class="flex items-center gap-3 flex-1 min-w-0">
|
||||
<div class="h-6 w-6 flex-shrink-0 group-hover:scale-105 transition-all duration-300 rounded-full flex justify-center items-center"
|
||||
style="
|
||||
@@ -102,6 +98,24 @@
|
||||
<span class="text-sm text-secondary whitespace-nowrap w-10 lg:w-15"><%= category[:percentage] %>%</span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if category[:clickable] != false %>
|
||||
<%= link_to transactions_path(q: { categories: [category[:name]], start_date: period.date_range.first, end_date: period.date_range.last }),
|
||||
class: "flex items-center justify-between mx-3 p-3 rounded-lg cursor-pointer group gap-3",
|
||||
data: {
|
||||
turbo_frame: "_top",
|
||||
category_id: category[:id],
|
||||
action: "mouseenter->donut-chart#highlightSegment mouseleave->donut-chart#unhighlightSegment"
|
||||
} do %>
|
||||
<%= category_content %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="flex items-center justify-between mx-3 p-3 rounded-lg group gap-3"
|
||||
data-category-id="<%= category[:id] %>"
|
||||
data-action="mouseenter->donut-chart#highlightSegment mouseleave->donut-chart#unhighlightSegment">
|
||||
<%= category_content %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if idx < outflows_data[:categories].size - 1 %>
|
||||
<%= render "shared/ruler", classes: "mx-3 lg:mx-4" %>
|
||||
<% end %>
|
||||
|
||||
73
app/views/reports/_net_worth.html.erb
Normal file
73
app/views/reports/_net_worth.html.erb
Normal file
@@ -0,0 +1,73 @@
|
||||
<div class="space-y-6">
|
||||
<%# Main Net Worth Stats %>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<%# Current Net Worth %>
|
||||
<div class="p-4 bg-surface-inset rounded-lg">
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.net_worth.current_net_worth") %></p>
|
||||
<p class="text-xl font-semibold <%= net_worth_metrics[:current_net_worth] >= 0 ? "text-success" : "text-destructive" %>">
|
||||
<%= net_worth_metrics[:current_net_worth].format %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%# Period Change %>
|
||||
<div class="p-4 bg-surface-inset rounded-lg">
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.net_worth.period_change") %></p>
|
||||
<% if net_worth_metrics[:trend] %>
|
||||
<% trend = net_worth_metrics[:trend] %>
|
||||
<p class="text-xl font-semibold" style="color: <%= trend.color %>">
|
||||
<%= trend.value.format(signify_positive: true) %>
|
||||
</p>
|
||||
<p class="text-xs" style="color: <%= trend.color %>">
|
||||
<%= trend.value >= 0 ? "+" : "" %><%= trend.percent_formatted %>
|
||||
</p>
|
||||
<% else %>
|
||||
<p class="text-xl font-semibold text-tertiary">--</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%# Assets vs Liabilities %>
|
||||
<div class="p-4 bg-surface-inset rounded-lg">
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.net_worth.assets_vs_liabilities") %></p>
|
||||
<div class="flex items-baseline gap-2">
|
||||
<span class="text-lg font-semibold text-success"><%= net_worth_metrics[:total_assets].format %></span>
|
||||
<span class="text-xs text-tertiary">-</span>
|
||||
<span class="text-lg font-semibold text-destructive"><%= net_worth_metrics[:total_liabilities].format %></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%# Asset/Liability Breakdown %>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<%# Assets Summary %>
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-secondary mb-3"><%= t("reports.net_worth.total_assets") %></h3>
|
||||
<div class="space-y-2">
|
||||
<% net_worth_metrics[:asset_groups].each do |group| %>
|
||||
<div class="flex items-center justify-between py-2 border-b border-tertiary/50">
|
||||
<span class="text-sm text-primary"><%= group[:name] %></span>
|
||||
<span class="text-sm font-medium text-success"><%= group[:total].format %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if net_worth_metrics[:asset_groups].empty? %>
|
||||
<p class="text-sm text-tertiary py-2"><%= t("reports.net_worth.no_assets") %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%# Liabilities Summary %>
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-secondary mb-3"><%= t("reports.net_worth.total_liabilities") %></h3>
|
||||
<div class="space-y-2">
|
||||
<% net_worth_metrics[:liability_groups].each do |group| %>
|
||||
<div class="flex items-center justify-between py-2 border-b border-tertiary/50">
|
||||
<span class="text-sm text-primary"><%= group[:name] %></span>
|
||||
<span class="text-sm font-medium text-destructive"><%= group[:total].format %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if net_worth_metrics[:liability_groups].empty? %>
|
||||
<p class="text-sm text-tertiary py-2"><%= t("reports.net_worth.no_liabilities") %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -85,7 +85,7 @@
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-3 h-3 rounded-full flex-shrink-0" style="background-color: <%= group[:category_color] %>"></span>
|
||||
<span class="font-medium text-primary"><%= group[:category_name] %></span>
|
||||
<span class="text-xs text-tertiary whitespace-nowrap">(<%= group[:count] %> <%= t("reports.transactions_breakdown.table.transactions") %>)</span>
|
||||
<span class="text-xs text-tertiary whitespace-nowrap">(<%= t("reports.transactions_breakdown.table.entries", count: group[:count]) %>)</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="py-3 px-4 text-right">
|
||||
@@ -139,7 +139,7 @@
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-3 h-3 rounded-full flex-shrink-0" style="background-color: <%= group[:category_color] %>"></span>
|
||||
<span class="font-medium text-primary"><%= group[:category_name] %></span>
|
||||
<span class="text-xs text-tertiary whitespace-nowrap">(<%= group[:count] %> <%= t("reports.transactions_breakdown.table.transactions") %>)</span>
|
||||
<span class="text-xs text-tertiary whitespace-nowrap">(<%= t("reports.transactions_breakdown.table.entries", count: group[:count]) %>)</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="py-3 px-4 text-right">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="space-y-8">
|
||||
<div>
|
||||
<%# Month-over-Month Trends %>
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-secondary mb-4">
|
||||
@@ -78,121 +78,5 @@
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%# Spending Patterns %>
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-secondary mb-4">
|
||||
<%= t("reports.trends.spending_patterns") %>
|
||||
</h3>
|
||||
|
||||
<% if spending_patterns[:weekday_count] + spending_patterns[:weekend_count] > 0 %>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<%# Weekday Spending %>
|
||||
<div class="p-6 bg-surface-inset rounded-lg">
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<%= icon("calendar", class: "w-5 h-5 text-primary") %>
|
||||
<h4 class="font-medium text-primary"><%= t("reports.trends.weekday_spending") %></h4>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.trends.total") %></p>
|
||||
<p class="text-xl font-semibold text-primary">
|
||||
<%= Money.new(spending_patterns[:weekday_total], Current.family.currency).format %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.trends.avg_per_transaction") %></p>
|
||||
<p class="text-base font-medium text-secondary">
|
||||
<%= Money.new(spending_patterns[:weekday_avg], Current.family.currency).format %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.trends.transactions") %></p>
|
||||
<p class="text-base font-medium text-secondary">
|
||||
<%= spending_patterns[:weekday_count] %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%# Weekend Spending %>
|
||||
<div class="p-6 bg-surface-inset rounded-lg">
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<%= icon("calendar-check", class: "w-5 h-5 text-primary") %>
|
||||
<h4 class="font-medium text-primary"><%= t("reports.trends.weekend_spending") %></h4>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.trends.total") %></p>
|
||||
<p class="text-xl font-semibold text-primary">
|
||||
<%= Money.new(spending_patterns[:weekend_total], Current.family.currency).format %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.trends.avg_per_transaction") %></p>
|
||||
<p class="text-base font-medium text-secondary">
|
||||
<%= Money.new(spending_patterns[:weekend_avg], Current.family.currency).format %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="text-xs text-tertiary mb-1"><%= t("reports.trends.transactions") %></p>
|
||||
<p class="text-base font-medium text-secondary">
|
||||
<%= spending_patterns[:weekend_count] %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%# Comparison Insight %>
|
||||
<% if spending_patterns[:weekday_avg] > 0 && spending_patterns[:weekend_avg] > 0 %>
|
||||
<div class="mt-4 p-4 bg-container rounded-lg border border-tertiary">
|
||||
<div class="flex items-start gap-3">
|
||||
<%= icon("lightbulb", class: "w-5 h-5 text-warning mt-0.5") %>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-primary mb-1">
|
||||
<%= t("reports.trends.insight_title") %>
|
||||
</p>
|
||||
<p class="text-sm text-secondary">
|
||||
<%
|
||||
weekday = spending_patterns[:weekday_avg].to_f
|
||||
weekend = spending_patterns[:weekend_avg].to_f
|
||||
|
||||
if weekend > weekday
|
||||
percent_diff = ((weekend - weekday) / weekday * 100).round(0)
|
||||
if percent_diff > 20
|
||||
message = t("reports.trends.insight_higher_weekend", percent: percent_diff)
|
||||
else
|
||||
message = t("reports.trends.insight_similar")
|
||||
end
|
||||
elsif weekday > weekend
|
||||
percent_diff = ((weekday - weekend) / weekend * 100).round(0)
|
||||
if percent_diff > 20
|
||||
message = t("reports.trends.insight_higher_weekday", percent: percent_diff)
|
||||
else
|
||||
message = t("reports.trends.insight_similar")
|
||||
end
|
||||
else
|
||||
message = t("reports.trends.insight_similar")
|
||||
end
|
||||
%>
|
||||
<%= message %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="text-center py-8 text-tertiary">
|
||||
<%= t("reports.trends.no_spending_data") %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user