Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Cashflow should use default period (and related) (#328)

Juan José Mata3c8ba643a0dc
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 07a7d10f0e..eaeb0a8b69 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -7,40 +7,14 @@ class PagesController < ApplicationController
@balance_sheet = Current.family.balance_sheet
@accounts = Current.family.accounts.visible.with_attached_logo
- # Handle cashflow period
- cashflow_period_param = params[:cashflow_period]
- @cashflow_period = if cashflow_period_param.present?
- begin
- Period.from_key(cashflow_period_param)
- rescue Period::InvalidKeyError
- Period.last_30_days
- end
- else
- Period.last_30_days
- end
-
- # Handle outflows period
- outflows_period_param = params[:outflows_period]
- @outflows_period = if outflows_period_param.present?
- begin
- Period.from_key(outflows_period_param)
- rescue Period::InvalidKeyError
- Period.last_30_days
- end
- else
- Period.last_30_days
- end
-
family_currency = Current.family.currency
- # Get data for cashflow section
- income_totals = Current.family.income_statement.income_totals(period: @cashflow_period)
- cashflow_expense_totals = Current.family.income_statement.expense_totals(period: @cashflow_period)
- @cashflow_sankey_data = build_cashflow_sankey_data(income_totals, cashflow_expense_totals, family_currency)
+ # Use the same period for all widgets (set by Periodable concern)
+ income_totals = Current.family.income_statement.income_totals(period: @period)
+ expense_totals = Current.family.income_statement.expense_totals(period: @period)
- # Get data for outflows section (using its own period)
- outflows_expense_totals = Current.family.income_statement.expense_totals(period: @outflows_period)
- @outflows_data = build_outflows_donut_data(outflows_expense_totals)
+ @cashflow_sankey_data = build_cashflow_sankey_data(income_totals, expense_totals, family_currency)
+ @outflows_data = build_outflows_donut_data(expense_totals)
@breadcrumbs = [ [ "Home", root_path ], [ "Dashboard", nil ] ]
end
diff --git a/app/views/pages/dashboard.html.erb b/app/views/pages/dashboard.html.erb
index f67237d480..34f3796cda 100644
--- a/app/views/pages/dashboard.html.erb
+++ b/app/views/pages/dashboard.html.erb
@@ -29,26 +29,22 @@
<div class="w-full space-y-6 pb-24">
<% if Current.family.accounts.any? %>
- <%= turbo_frame_tag "cashflow_sankey_section" do %>
+ <section class="bg-container py-4 rounded-xl shadow-border-xs mb-6">
+ <%= render partial: "pages/dashboard/cashflow_sankey", locals: {
+ sankey_data: @cashflow_sankey_data,
+ period: @period
+ } %>
+ </section>
+
+ <% if @outflows_data[:categories].present? %>
<section class="bg-container py-4 rounded-xl shadow-border-xs mb-6">
- <%= render partial: "pages/dashboard/cashflow_sankey", locals: {
- sankey_data: @cashflow_sankey_data,
- period: @cashflow_period
+ <%= render partial: "pages/dashboard/outflows_donut", locals: {
+ outflows_data: @outflows_data,
+ period: @period
} %>
</section>
<% end %>
- <% if @outflows_data[:categories].present? %>
- <%= turbo_frame_tag "outflows_donut_section" do %>
- <section class="bg-container py-4 rounded-xl shadow-border-xs mb-6">
- <%= render partial: "pages/dashboard/outflows_donut", locals: {
- outflows_data: @outflows_data,
- period: @outflows_period
- } %>
- </section>
- <% end %>
- <% end %>
-
<section class="bg-container py-4 rounded-xl shadow-border-xs">
<%= render partial: "pages/dashboard/net_worth_chart", locals: {
balance_sheet: @balance_sheet,
diff --git a/app/views/pages/dashboard/_cashflow_sankey.html.erb b/app/views/pages/dashboard/_cashflow_sankey.html.erb
index 1f9b30053b..bb49fa50f2 100644
--- a/app/views/pages/dashboard/_cashflow_sankey.html.erb
+++ b/app/views/pages/dashboard/_cashflow_sankey.html.erb
@@ -5,8 +5,8 @@
<%= t("pages.dashboard.cashflow_sankey.title") %>
</h2>
- <%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "cashflow_sankey_section" } do |form| %>
- <%= form.select :cashflow_period,
+ <%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "_top" } do |form| %>
+ <%= form.select :period,
Period.as_options,
{ selected: period.key },
data: { "auto-submit-form-target": "auto" },
diff --git a/app/views/pages/dashboard/_net_worth_chart.html.erb b/app/views/pages/dashboard/_net_worth_chart.html.erb
index 56a31f249e..2376d79c6c 100644
--- a/app/views/pages/dashboard/_net_worth_chart.html.erb
+++ b/app/views/pages/dashboard/_net_worth_chart.html.erb
@@ -6,7 +6,7 @@
<div class="space-y-2">
<div class="space-y-2">
<div class="flex items-center gap-2">
- <p class="text-sm text-secondary font-medium"><%= t(".title") %></p>
+ <h2 class="text-lg font-medium"><%= t(".title") %></h2>
</div>
<p class="text-primary -space-x-0.5 text-3xl font-medium <%= "animate-pulse" if balance_sheet.syncing? %>">
@@ -21,7 +21,7 @@
</div>
</div>
- <%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form" } do |form| %>
+ <%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "_top" } do |form| %>
<%= form.select :period,
Period.as_options,
{ selected: period.key },
diff --git a/app/views/pages/dashboard/_outflows_donut.html.erb b/app/views/pages/dashboard/_outflows_donut.html.erb
index 01c52f34cf..dd1aab80f9 100644
--- a/app/views/pages/dashboard/_outflows_donut.html.erb
+++ b/app/views/pages/dashboard/_outflows_donut.html.erb
@@ -5,8 +5,8 @@
<%= t("pages.dashboard.outflows_donut.title") %>
</h2>
- <%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "outflows_donut_section" } do |form| %>
- <%= form.select :outflows_period,
+ <%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "_top" } do |form| %>
+ <%= form.select :period,
Period.as_options,
{ selected: period.key },
data: { "auto-submit-form-target": "auto" },