From 945b5f4127feeeb255f99417a00aa338c54876e1 Mon Sep 17 00:00:00 2001 From: Triopsi Date: Wed, 25 Nov 2026 10:43:32 +0000 Subject: [PATCH 1/3] feat(dashboard): add personal account forecasts and improve monthly overview - show account balance forecasts in monthly, yearly and participant views - display monthly calculations and savings reserves - redesign participant cards and fix widget overflow - adjust dashboard sizing to fit widget content --- .../Widgets/MonthlyParticipantsTable.php | 5 +- app/Services/AccountBalanceForecast.php | 14 ++++- lang/de/participants.php | 20 ++++++ lang/en/participants.php | 20 ++++++ resources/css/monthly-dashboard.css | 3 + resources/js/monthly-dashboard.js | 42 +++++++------ .../components/account-calculation.blade.php | 32 ++++++++++ .../components/monthly-calculation.blade.php | 12 ++++ .../views/filament/household-style.blade.php | 55 ++++++++++++++++ .../pages/participant-month.blade.php | 13 ++-- .../views/filament/pages/year-plan.blade.php | 8 +++ .../widgets/monthly-participants.blade.php | 63 +++++++++++++++++++ 12 files changed, 257 insertions(+), 30 deletions(-) create mode 100644 resources/views/components/account-calculation.blade.php create mode 100644 resources/views/components/monthly-calculation.blade.php create mode 100644 resources/views/filament/widgets/monthly-participants.blade.php diff --git a/app/Filament/Widgets/MonthlyParticipantsTable.php b/app/Filament/Widgets/MonthlyParticipantsTable.php index b767c39..8dbbcce 100644 --- a/app/Filament/Widgets/MonthlyParticipantsTable.php +++ b/app/Filament/Widgets/MonthlyParticipantsTable.php @@ -26,6 +26,8 @@ class MonthlyParticipantsTable extends TableWidget protected int|string|array $columnSpan = 'full'; + protected string $view = 'filament.widgets.monthly-participants'; + /** * Configure participant rows, monthly detail links and cent-exact monetary columns. */ @@ -76,8 +78,7 @@ public function table(Table $table): Table : '–'), $this->moneyColumn('paid_cents', 'paid'), $this->moneyColumn('balance_cents', 'balance'), - ]) - ->contentFooter(fn (): View => view('filament.widgets.monthly-participants-footer', ['report' => $this->settlementReport])); + ]); } /** Resolve the live cash forecast separately from the selected month's settlement snapshot. diff --git a/app/Services/AccountBalanceForecast.php b/app/Services/AccountBalanceForecast.php index 4b09088..982bc1e 100644 --- a/app/Services/AccountBalanceForecast.php +++ b/app/Services/AccountBalanceForecast.php @@ -17,7 +17,7 @@ final class AccountBalanceForecast * Frozen settlements supply historical changes. Missing months block later projections * instead of silently assuming zero. Changing the starting point never rewrites closings. * - * @return array> + * @return array>> */ public function between(string $fromMonth, string $toMonth): array { @@ -60,7 +60,9 @@ public function between(string $fromMonth, string $toMonth): array foreach ($active as $participant) { $id = $participant->id; $person = $people->get($id); - if ($month === $participant->account_balance_month) { + $openingBalance = $balances[$id] ?? $participant->account_balance_cents; + $isStartingMonth = $month === $participant->account_balance_month; + if ($isStartingMonth) { $balances[$id] = $participant->account_balance_cents; } elseif ($problem !== null || $person === null) { $errors[$id] ??= $problem ?? __('participants.account.missing_month'); @@ -72,6 +74,14 @@ public function between(string $fromMonth, string $toMonth): array } if ($month >= $fromMonth) { $result[$month][$id] = [ + 'observed_balance_cents' => $participant->account_balance_cents, + 'observed_month' => $participant->account_balance_month, + 'opening_balance_cents' => $openingBalance, + 'is_starting_month' => $isStartingMonth, + 'income_cents' => $isStartingMonth ? 0 : ($person['income_cents'] ?? 0), + 'share_cents' => $isStartingMonth ? 0 : ($person['share_cents'] ?? 0), + 'savings_deposited_cents' => $isStartingMonth ? 0 : ($person['savings_deposited_cents'] ?? 0), + 'reserved_cents' => $person['reserved_cents'] ?? 0, 'balance_cents' => isset($errors[$id]) ? null : $balances[$id], 'available_cents' => isset($errors[$id]) || $person === null ? null : $balances[$id] - ($person['reserved_cents'] ?? 0), 'recovered_month' => $recovered[$id] ?? null, diff --git a/lang/de/participants.php b/lang/de/participants.php index 6eeea66..42e2f61 100644 --- a/lang/de/participants.php +++ b/lang/de/participants.php @@ -5,6 +5,26 @@ */ return [ 'account' => [ + 'calculation_details' => 'Rechenweg anzeigen', + 'more_figures' => 'Alle Kennzahlen als Tabelle', + 'no_balance' => 'Noch kein Kontostand hinterlegt', + 'no_balance_help' => 'Mit einem Ausgangsstand siehst du hier auch dein Guthaben oder Minus am Monatsende.', + 'edit_balance' => 'Kontostand hinterlegen', + 'details' => 'Monatsdetails öffnen', + 'explanation' => 'So wird gerechnet', + + 'opening_reserves' => 'Reservierte Spartöpfe zu Monatsbeginn', + 'opening' => 'Kontostand zu Monatsbeginn', + 'observed' => 'Eingetragener Ausgangsstand', + 'income' => 'Einnahmen', + 'share' => 'Eigener Kostenanteil', + 'savings' => 'Spargutschriften auf diesem Konto', + 'reserves' => 'Reservierte Spartöpfe', + 'starting' => 'Dies ist der eingetragene Monatsendstand. Einnahmen und Kosten dieses Monats werden nicht erneut verrechnet.', + 'monthly' => 'Monatsrechnung', + 'change' => 'Veränderung seit Ausgangsstand', + 'savings_help' => 'Spargutschriften sind im Kostenanteil enthalten und bleiben auf diesem Konto. Deshalb werden sie hier wieder hinzugerechnet.', + 'title' => 'Kontostand-Prognose', 'month' => 'Kontostand am Ende dieses Monats', 'balance' => 'Erfasster Kontostand', diff --git a/lang/en/participants.php b/lang/en/participants.php index 8f3f970..55014e8 100644 --- a/lang/en/participants.php +++ b/lang/en/participants.php @@ -5,6 +5,26 @@ */ return [ 'account' => [ + 'calculation_details' => 'Show calculation', + 'more_figures' => 'All figures as a table', + 'no_balance' => 'No account balance recorded yet', + 'no_balance_help' => 'Add a starting balance to see your projected month-end balance or overdraft here.', + 'edit_balance' => 'Add account balance', + 'details' => 'Open monthly details', + 'explanation' => 'How this is calculated', + + 'opening_reserves' => 'Reserved savings at start of month', + 'opening' => 'Balance at start of month', + 'observed' => 'Recorded starting balance', + 'income' => 'Income', + 'share' => 'Own cost share', + 'savings' => 'Savings credited to this account', + 'reserves' => 'Reserved savings pots', + 'starting' => 'This is the recorded month-end balance. Income and costs for this month are not applied again.', + 'monthly' => 'Monthly calculation', + 'change' => 'Change since starting balance', + 'savings_help' => 'Savings credits are included in the cost share and stay in this account, so they are added back here.', + 'title' => 'Account balance forecast', 'month' => 'Balance at the end of this month', 'balance' => 'Recorded account balance', diff --git a/resources/css/monthly-dashboard.css b/resources/css/monthly-dashboard.css index 67b98b0..5948be3 100644 --- a/resources/css/monthly-dashboard.css +++ b/resources/css/monthly-dashboard.css @@ -31,3 +31,6 @@ .hh-dashboard [x-cloak] { display: none !important; } @media (prefers-reduced-motion: reduce) { .hh-dashboard .grid-stack-item { transition: none !important; } } @media (max-width: 767px) { .hh-dashboard .hh-widget-drag { display: none; } } + +/* Personal overview follows its content rather than a fixed table viewport. */ +.hh-dashboard [gs-id="participants"] .hh-widget-body > .fi-wi-widget { height: auto; flex: none; } diff --git a/resources/js/monthly-dashboard.js b/resources/js/monthly-dashboard.js index 4e92bdd..3585bdc 100644 --- a/resources/js/monthly-dashboard.js +++ b/resources/js/monthly-dashboard.js @@ -11,8 +11,8 @@ window.monthlyDashboard = (initialLayout, messages) => { let savedLayout = structuredClone(initialLayout); let media; let onBreakpoint; - let transferObserver; - let transferFrame; + let contentObserver; + let contentFrame; return { editing: false, @@ -48,24 +48,24 @@ window.monthlyDashboard = (initialLayout, messages) => { media.addEventListener('change', onBreakpoint); onBreakpoint(); grid.on('resizestop dragstop', () => this.resizeCharts()); - const transferElement = grid.getGridItems().find((item) => item.gridstackNode.id === 'transfers'); - if (transferElement) { - transferElement.gridstackNode.resizeToContentParent = '.hh-widget-body'; + contentObserver = new ResizeObserver(() => this.fitContentWidgets()); + for (const id of ['transfers', 'participants']) { + const element = grid.getGridItems().find((item) => item.gridstackNode.id === id); + if (element) { + element.gridstackNode.resizeToContentParent = '.hh-widget-body'; + } + const content = element?.querySelector('.hh-widget-body > .fi-wi-widget'); + if (content) contentObserver.observe(content); } - const transferContent = transferElement?.querySelector('.hh-widget-body > .fi-wi-widget'); - if (transferContent) { - transferObserver = new ResizeObserver(() => this.fitTransfers()); - transferObserver.observe(transferContent); - } - this.fitTransfers(); + this.fitContentWidgets(); }); }, /** Remove library listeners when Livewire navigation destroys this dashboard. */ destroy() { media?.removeEventListener('change', onBreakpoint); - transferObserver?.disconnect(); - cancelAnimationFrame(transferFrame); + contentObserver?.disconnect(); + cancelAnimationFrame(contentFrame); grid?.destroy(false); }, @@ -145,16 +145,18 @@ window.monthlyDashboard = (initialLayout, messages) => { /** Allow Filament's Chart.js canvases to refit after a widget or viewport changes size. */ resizeCharts() { - this.fitTransfers(); + this.fitContentWidgets(); requestAnimationFrame(() => window.dispatchEvent(new Event('resize'))); }, - /** Fit payment cards after content, width or disclosure changes and push following widgets down. */ - fitTransfers() { - cancelAnimationFrame(transferFrame); - transferFrame = requestAnimationFrame(() => { - const element = grid?.getGridItems().find((item) => item.gridstackNode.id === 'transfers'); - if (element) grid.resizeToContent(element); + /** Fit payment and participant cards after content, width or disclosure changes and push following widgets down. */ + fitContentWidgets() { + cancelAnimationFrame(contentFrame); + contentFrame = requestAnimationFrame(() => { + for (const id of ['transfers', 'participants']) { + const element = grid?.getGridItems().find((item) => item.gridstackNode.id === id); + if (element) grid.resizeToContent(element); + } }); }, }; diff --git a/resources/views/components/account-calculation.blade.php b/resources/views/components/account-calculation.blade.php new file mode 100644 index 0000000..b84359f --- /dev/null +++ b/resources/views/components/account-calculation.blade.php @@ -0,0 +1,32 @@ +@props(['forecast']) +@php + $money = fn ($cents) => \App\Support\Money::format($cents); + $signed = fn ($cents) => ($cents > 0 ? '+' : '').$money($cents); +@endphp + diff --git a/resources/views/components/monthly-calculation.blade.php b/resources/views/components/monthly-calculation.blade.php new file mode 100644 index 0000000..03a39b3 --- /dev/null +++ b/resources/views/components/monthly-calculation.blade.php @@ -0,0 +1,12 @@ +@props(['person']) +
+
{{ __('participants.account.income') }}
+{{ \App\Support\Money::format($person['income_cents']) }}
+
{{ __('participants.account.share') }}
{{ \App\Support\Money::format(-$person['share_cents']) }}
+ @foreach(['opening_reserved_cents' => 'opening_reserves', 'savings_deposited_cents' => 'savings', 'reserved_cents' => 'reserves'] as $field => $label) + @if(($person[$field] ?? 0) !== 0) + @php $amount = $field === 'reserved_cents' ? -$person[$field] : $person[$field]; @endphp +
{{ __('participants.account.'.$label) }}
{{ $amount > 0 ? '+' : '' }}{{ \App\Support\Money::format($amount) }}
+ @endif + @endforeach +
{{ __('participants.detail.left') }}
{{ $person['remaining_cents'] > 0 ? '+' : '' }}{{ \App\Support\Money::format($person['remaining_cents']) }}
+
diff --git a/resources/views/filament/household-style.blade.php b/resources/views/filament/household-style.blade.php index 44c1ac7..26bdb75 100644 --- a/resources/views/filament/household-style.blade.php +++ b/resources/views/filament/household-style.blade.php @@ -41,4 +41,59 @@ .dark .hh-payment-card{background:#1c1c1f;border-color:#36383b;border-top-color:#2dd4bf}.dark .hh-payment-breakdown{border-color:#36383b}.dark .hh-payment-reference{background:#232729}.dark .hh-payment-label,.dark .hh-payment-help{color:#a4bcb7}.dark .hh-payment-equation-total{border-color:#36383b}.dark .hh-payment-equation-total strong,.dark .hh-payment-sign,.dark .hh-payment-arrow{color:#5eead4}.dark .hh-payment-empty{border-color:#34494b} .hh-cost-share{display:flex;flex-direction:column;gap:.3rem;min-width:12rem;white-space:normal;font-variant-numeric:tabular-nums}.hh-cost-share>strong{font-size:1.1rem;color:#0f766e}.hh-cost-funded,.hh-cost-assigned,.hh-cost-funding>div{display:flex;justify-content:space-between;gap:1rem;font-size:.8rem}.hh-cost-funded{margin-top:.4rem;color:#697c80}.hh-cost-assigned{border-top:1px solid #dbe5e4;padding-top:.4rem}.hh-cost-funding{display:grid;gap:.5rem;min-width:11rem;font-variant-numeric:tabular-nums}.hh-cost-funding>div{color:#697c80}.hh-cost-funding .hh-cost-remainder{color:#0f766e;border-top:1px solid #dbe5e4;padding-top:.5rem}.dark .hh-cost-share>strong,.dark .hh-cost-funding .hh-cost-remainder{color:#5eead4}.dark .hh-cost-funded,.dark .hh-cost-funding>div{color:#a4bcb7}.dark .hh-cost-assigned,.dark .hh-cost-funding .hh-cost-remainder{border-color:#36383b} + +.hh-account-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,320px),1fr));gap:1rem;padding:0 1.5rem 1.5rem}.hh-account-panel{border:1px solid #dbe5e4;border-radius:.75rem;overflow:hidden;min-width:0}.hh-account-panel>h3{padding:1rem 1.25rem;background:#f3f7f6;font-weight:650}.hh-account-panel>.hh-calculation{padding:1rem 1.25rem}.hh-account-panel>p{padding:1rem 1.25rem}.hh-account-calculation{padding:1.25rem 1.5rem;display:grid;gap:1rem}.hh-account-origin{display:flex;justify-content:space-between;align-items:baseline;gap:1rem;flex-wrap:wrap;padding:.85rem 1rem;border-radius:.5rem;background:#f3f7f6;font-size:.85rem}.hh-account-origin strong{font-variant-numeric:tabular-nums;white-space:nowrap}.hh-calculation{margin:0;display:grid;gap:.65rem}.hh-calculation>div{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:baseline;gap:1rem}.hh-calculation dt{font-size:.875rem}.hh-calculation dd{margin:0;text-align:right;white-space:nowrap;font-variant-numeric:tabular-nums;font-weight:600}.hh-calculation-total{border-top:1px solid #9bb3af;padding-top:.85rem;font-weight:700}.hh-calculation-total dd{border-bottom:3px double #9bb3af;padding-bottom:.35rem}.hh-calculation-final{background:#edf7f3;padding:.85rem;border-radius:.5rem}.hh-table tfoot th{border-top:1px solid #9bb3af;border-bottom:3px double #9bb3af;font-weight:700}.dark .hh-account-panel{border-color:#34494b}.dark .hh-account-origin,.dark .hh-account-panel>h3{background:#213738;color:#c0d9d5}.dark .hh-calculation-final{background:#213738} + +/* Let the section wrap its cards even inside a fixed-height dashboard cell. */ +.hh-dashboard .hh-widget-body > .fi-wi-widget.hh-personal-widget { height: auto; flex: none; } +.hh-dashboard .fi-wi-widget.hh-personal-widget > .fi-section { flex: none; min-height: auto; height: auto; } +.hh-personal-overview { container-type: inline-size; display: grid; gap: 1.5rem; min-width: 0; } +.hh-personal-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 28rem), 1fr)); align-items: stretch; gap: 1.25rem; } +.hh-personal-card { min-width: 0; border: 1px solid #dbe5e4; border-radius: 1rem; background: #fff; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 2px 8px rgb(15 23 42 / .03); } +.hh-personal-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; padding: 1.25rem; border-bottom: 1px solid #dbe5e4; background: #f6f9f8; } +.hh-personal-head .hh-person { font-size: 1.05rem; gap: .75rem; } +.hh-personal-head .hh-avatar { width: 2.5rem; height: 2.5rem; } +.hh-personal-head .hh-link { text-decoration: none; } +.hh-personal-period { padding: .3rem .65rem; border: 1px solid #dbe5e4; border-radius: 99px; font-size: .75rem; color: #5b7074; white-space: nowrap; } +.hh-personal-month, .hh-personal-account { padding: 1.25rem; } +.hh-personal-card h3 { margin: 0 0 1.25rem; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; color: #5b7074; } +.hh-personal-card .hh-calculation { gap: 1rem; } +.hh-personal-card .hh-calculation > div { gap: 1.5rem; } +.hh-personal-card .hh-calculation dt { line-height: 1.6; } +.hh-personal-card .hh-calculation-total { margin-top: .25rem; padding-top: 1.25rem; } +.hh-personal-card .hh-calculation-total dd { font-size: 1.15rem; } +.hh-personal-account { border-top: 1px solid #dbe5e4; background: #f6f9f8; flex: 1; } +.hh-personal-start { display: flex; justify-content: space-between; align-items: center; gap: 1rem; font-size: .85rem; } +.hh-personal-start small { display: block; margin-top: .35rem; color: #697c80; } +.hh-personal-start strong { white-space: nowrap; font-variant-numeric: tabular-nums; } +.hh-personal-result { display: grid; gap: .5rem; padding: 1.1rem 1.25rem; margin: 1.25rem 0 .75rem; border: 1px solid #cce8df; border-radius: .75rem; background: #eaf6f0; } +.hh-personal-result > span { font-size: .85rem; color: #5b7074; } +.hh-personal-result > strong { width: fit-content; font-size: 1.85rem; line-height: 1.3; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.035em; color: #0f766e; } +.hh-personal-disclosure { min-width: 0; font-size: .85rem; } +.hh-personal-disclosure > summary { width: fit-content; cursor: pointer; color: #0c8276; padding: .5rem 0; font-weight: 500; } +.hh-personal-disclosure > summary:focus-visible { outline: 2px solid #14b8a6; outline-offset: 4px; border-radius: .25rem; } +.hh-personal-disclosure > .hh-account-calculation { padding: 1.25rem 0 0; } +.hh-personal-empty { display: flex; align-items: start; gap: 1rem; } +.hh-personal-empty h3 { margin-bottom: .5rem; } +.hh-personal-empty p { color: #697c80; font-size: .85rem; line-height: 1.7; margin-bottom: 1rem; } +.hh-personal-empty .hh-icon { margin-top: .15rem; } +.hh-personal-help p { margin-top: .75rem; line-height: 1.7; max-width: 75ch; } +.hh-personal-table > .fi-ta { margin-top: 1rem; } +.dark .hh-personal-card { background: #18181b; border-color: #36383b; } +.dark .hh-personal-head, .dark .hh-personal-account { border-color: #36383b; background: #202425; } +.dark .hh-personal-period { border-color: #3a4645; color: #a4bcb7; } +.dark .hh-personal-result { background: #193b34; border-color: #2b554a; } +.dark .hh-personal-result > strong { color: #5eead4; } +.dark .hh-personal-account { background: #202425; } +.dark .hh-personal-card h3, .dark .hh-personal-start small, .dark .hh-personal-result > span, .dark .hh-personal-empty p { color: #a4bcb7; } +.dark .hh-personal-disclosure > summary { color: #66dac4; } +@container (max-width: 380px) { + .hh-personal-head, .hh-personal-month, .hh-personal-account { padding: 1rem; } + .hh-personal-card .hh-calculation > div { gap: .75rem; } + .hh-personal-card .hh-calculation-total dd { font-size: 1rem; } +} + +.hh-personal-footer { display: flex; flex-wrap: wrap; align-items: start; column-gap: 1.5rem; row-gap: .5rem; border-top: 1px solid #dbe5e4; padding-top: .75rem; } +.hh-personal-footer > details[open] { flex-basis: 100%; } +.dark .hh-personal-footer { border-color: #36383b; } diff --git a/resources/views/filament/pages/participant-month.blade.php b/resources/views/filament/pages/participant-month.blade.php index b7680e2..f650922 100644 --- a/resources/views/filament/pages/participant-month.blade.php +++ b/resources/views/filament/pages/participant-month.blade.php @@ -35,16 +35,17 @@
{{ __('funding.remaining_help') }}
{{ __('funding.reserved') }}: {{ $money($person['reserved_cents'] ?? 0) }}
+
+

{{ __('participants.account.monthly') }}

+ +

{{ __('participants.account.title') }}

- @if($accountForecast && $accountForecast['balance_cents'] !== null) -

{{ __('participants.account.projected') }}: {{ $money($accountForecast['balance_cents']) }}

- @if($accountForecast['available_cents'] !== null)

{{ __('participants.account.available') }}: {{ $money($accountForecast['available_cents']) }}

@endif - @if($accountForecast['recovered_month'])

{{ __('participants.account.recovered') }}: {{ \App\Support\Month::format($accountForecast['recovered_month']) }}

@endif + @if($accountForecast) + @else -

{{ __('participants.account.setup') }}

+

{{ __('participants.account.setup') }}

@endif - @if($accountForecast['error'] ?? null)

{{ $accountForecast['error'] }}

@endif

{{ __('participants.account.forecast_help') }}

diff --git a/resources/views/filament/pages/year-plan.blade.php b/resources/views/filament/pages/year-plan.blade.php index 30ed99f..ce7c70d 100644 --- a/resources/views/filament/pages/year-plan.blade.php +++ b/resources/views/filament/pages/year-plan.blade.php @@ -12,6 +12,14 @@ @if($accountParticipants->isEmpty())

{{ __('participants.account.setup') }}

@else +
@foreach($accountParticipants as $accountParticipant)@endforeach@foreach($rows as $row) diff --git a/resources/views/filament/widgets/monthly-participants.blade.php b/resources/views/filament/widgets/monthly-participants.blade.php new file mode 100644 index 0000000..f7c5221 --- /dev/null +++ b/resources/views/filament/widgets/monthly-participants.blade.php @@ -0,0 +1,63 @@ + + @php + $report = $this->settlementReport; + $forecasts = $this->accountForecast; + $signed = fn ($cents) => ($cents > 0 ? '+' : '').\App\Support\Money::format($cents); + @endphp + +
+
+ @foreach($report['participants'] as $person) + @php $forecast = $forecasts[$person['id']] ?? null; @endphp +
+
+ + {{ \App\Support\Month::format($month) }} +
+
+

{{ __('participants.account.monthly') }}

+ +
+ +
+ @endforeach +
+ +
+
+
From 13c3e943625ce9236213e24eddac0cbf06b5eeca Mon Sep 17 00:00:00 2001 From: Triopsi Date: Wed, 25 Nov 2026 12:08:18 +0000 Subject: [PATCH 2/3] feat(savings): add savings overview and explain reserved funds - add dedicated overview page with monthly balances and account holders - break down personal reserves by savings pot - explain savings pots and reserved amounts - link budget widget to savings overview - preserve frozen balances for closed months --- app/Filament/Pages/ParticipantMonth.php | 2 +- app/Filament/Pages/SavingsOverview.php | 80 +++++++++++++++++++ lang/de/funding.php | 18 +++++ lang/en/funding.php | 18 +++++ .../components/monthly-calculation.blade.php | 15 +++- .../components/savings-explanation.blade.php | 6 ++ .../views/filament/household-style.blade.php | 7 ++ .../pages/participant-month.blade.php | 2 +- .../filament/pages/savings-overview.blade.php | 48 +++++++++++ .../widgets/monthly-budgets-footer.blade.php | 1 + .../widgets/monthly-participants.blade.php | 2 +- tests/Feature/IncomeFundingTest.php | 39 +++++++++ tests/Feature/SavingsOverviewTest.php | 70 ++++++++++++++++ 13 files changed, 304 insertions(+), 4 deletions(-) create mode 100644 app/Filament/Pages/SavingsOverview.php create mode 100644 resources/views/components/savings-explanation.blade.php create mode 100644 resources/views/filament/pages/savings-overview.blade.php create mode 100644 tests/Feature/SavingsOverviewTest.php diff --git a/app/Filament/Pages/ParticipantMonth.php b/app/Filament/Pages/ParticipantMonth.php index 8d0a1d9..179818f 100644 --- a/app/Filament/Pages/ParticipantMonth.php +++ b/app/Filament/Pages/ParticipantMonth.php @@ -82,6 +82,6 @@ protected function getViewData(): array $incomes = array_values(array_filter($report['incomes'], fn (array $income): bool => $income['participant_id'] === $this->participant->id)); $names = array_column($report['participants'], 'name', 'id'); - return ['person' => $person, 'expenses' => $expenses, 'incomes' => $incomes, 'names' => $names, 'emails' => Participant::pluck('email', 'id'), 'problem' => null, 'accountForecast' => app(AccountBalanceForecast::class)->between($this->month, $this->month)[$this->month][$this->participant->id] ?? null]; + return ['budgets' => $report['budgets'] ?? [], 'person' => $person, 'expenses' => $expenses, 'incomes' => $incomes, 'names' => $names, 'emails' => Participant::pluck('email', 'id'), 'problem' => null, 'accountForecast' => app(AccountBalanceForecast::class)->between($this->month, $this->month)[$this->month][$this->participant->id] ?? null]; } } diff --git a/app/Filament/Pages/SavingsOverview.php b/app/Filament/Pages/SavingsOverview.php new file mode 100644 index 0000000..94768ed --- /dev/null +++ b/app/Filament/Pages/SavingsOverview.php @@ -0,0 +1,80 @@ +month = $this->month ?: now()->format('Y-m'); + } + + /** Name the page and browser title. */ + public function getTitle(): string + { + return __('funding.savings.title'); + } + + /** Name the separate overview entry in the sidebar. */ + public static function getNavigationLabel(): string + { + return __('funding.savings.title'); + } + + /** Keep the balance overview beside monthly and annual planning. */ + public static function getNavigationGroup(): string + { + return __('nav.groups.overview'); + } + + /** Resolve reserves without requiring unrelated household bills to be allocatable. + * @return array{budgets: list>, names: array, total: int, closed: bool, problem: string|null} + */ + protected function getViewData(): array + { + $data = ['budgets' => [], 'names' => [], 'total' => 0, 'closed' => false, 'problem' => null]; + if (preg_match('/^\d{4}-(0[1-9]|1[0-2])$/D', $this->month) !== 1) { + return [...$data, 'problem' => __('funding.savings.invalid_month')]; + } + $closing = MonthlyClosing::where('month', $this->month)->whereNotNull('closed_at')->first(); + if ($closing) { + if (! array_key_exists('budgets', $closing->snapshot)) { + return [...$data, 'closed' => true, 'problem' => __('funding.savings.no_snapshot')]; + } + $budgets = $closing->snapshot['budgets']; + $names = array_column($closing->snapshot['participants'], 'name', 'id'); + } else { + try { + $budgets = app(BudgetFunding::class)->calculate($this->month, Income::orderBy('id')->get(), Expense::orderBy('id')->get())['budgets']; + } catch (ValidationException $exception) { + return [...$data, 'problem' => collect($exception->errors())->flatten()->implode(' ')]; + } + $names = Participant::pluck('name', 'id')->all(); + } + + return ['budgets' => $budgets, 'names' => $names, 'total' => array_sum(array_column($budgets, 'closing_cents')), 'closed' => $closing !== null, 'problem' => null]; + } +} diff --git a/lang/de/funding.php b/lang/de/funding.php index 0911996..df0f656 100644 --- a/lang/de/funding.php +++ b/lang/de/funding.php @@ -2,6 +2,24 @@ /** Zweckgebundene Einnahmen, Erstattungen und Verteilungseinkommen. */ return [ + 'savings' => [ + 'title' => 'Spartopf-Übersicht', + 'hero' => 'Eure Rücklagen auf einen Blick', + 'intro' => 'Alle Budgets und Spartöpfe mit ihrem angesammelten Guthaben zum Ende des ausgewählten Monats.', + 'month' => 'Monat', + 'total' => 'Insgesamt reserviert', + 'closed' => 'Gespeicherter Stand des abgeschlossenen Monats.', + 'planned' => 'Geplanter Monatsendstand auf Basis eurer erfassten Einnahmen und Kosten; kein bestätigter Bankkontostand.', + 'holders' => 'Auf wessen Konto ist das Geld reserviert?', + 'empty_pot' => 'In diesem Topf ist noch kein Guthaben übrig.', + 'manage' => 'Budgets & Spartöpfe verwalten', + 'invalid_month' => 'Bitte einen gültigen Monat auswählen.', + 'no_snapshot' => 'Für diesen alten Monatsabschluss wurden noch keine Topfstände gespeichert.', + 'what' => 'Was sind Spartöpfe und reservierte Beträge?', + 'meaning' => 'Ein Spartopf ist eine virtuelle Rücklage für einen bestimmten Zweck, zum Beispiel Urlaub oder Reparaturen. Das Geld bleibt auf dem Konto der zugeordneten Person, ist aber nicht mehr frei verfügbar. Ein Topf ist kein zusätzliches Bankkonto.', + 'example' => 'Beispiel: Im Urlaubstopf liegen 1,50 € und im Reparaturtopf 2,50 € für dich. „Reservierte Spartöpfe: −4,00 €“ zieht diese insgesamt 4,00 € vom frei verfügbaren Geld ab. Das Geld ist dadurch nicht ausgegeben. Reserven zu Monatsbeginn werden in der Monatsrechnung zuerst wieder hinzugerechnet, damit alte Rücklagen nicht doppelt abgezogen werden.', + 'setup' => 'Befüllen: Einnahmen einem Budget zuordnen oder unter Kosten eine Sparrate mit „Sparen / zurücklegen in Topf“ anlegen. Verwenden: Eine Ausgabe diesem Budget zuordnen. Was übrig bleibt, wird in den Folgemonat übertragen.', + ], 'savings_destination' => 'Sparen / zurücklegen in Topf', 'normal_expense' => 'Normale Ausgabe (keine Sparrate)', 'savings_help' => 'Zum Beispiel Bauspartopf oder Essenstopf. Der Betrag wird aus eurem vorhandenen Einkommen zurückgelegt und nach der gewählten Regel aufgeteilt. Bezahler ist die Person, die den Topf verwaltet. Keine zusätzliche Einnahme erfassen. Der frei verfügbare Monatsrest sinkt um den Sparanteil.', diff --git a/lang/en/funding.php b/lang/en/funding.php index 91899ed..2a00b05 100644 --- a/lang/en/funding.php +++ b/lang/en/funding.php @@ -2,6 +2,24 @@ /** Earmarked funding, reimbursements and salary-only allocation labels. */ return [ + 'savings' => [ + 'title' => 'Savings overview', + 'hero' => 'Your reserves at a glance', + 'intro' => 'All budgets and savings pots with their accumulated balance at the end of the selected month.', + 'month' => 'Month', + 'total' => 'Total reserved', + 'closed' => 'Saved balances from the closed month.', + 'planned' => 'Projected month-end balances based on recorded income and costs; not confirmed bank balances.', + 'holders' => 'Whose account holds these reserves?', + 'empty_pot' => 'No funds remain in this pot yet.', + 'manage' => 'Manage budgets & savings pots', + 'invalid_month' => 'Please select a valid month.', + 'no_snapshot' => 'This older monthly closing does not contain saved pot balances.', + 'what' => 'What are savings pots and reserved amounts?', + 'meaning' => 'A savings pot is a virtual reserve for a purpose such as holidays or repairs. The money stays in the assigned person’s account but is no longer freely available. A pot is not an additional bank account.', + 'example' => 'Example: Your holiday pot holds €1.50 and your repair pot holds €2.50. “Reserved savings pots: −€4.00” deducts the total €4.00 from freely available money. It has not been spent. Opening reserves are added back first in the monthly calculation so existing reserves are not deducted twice.', + 'setup' => 'Add funds by assigning income to a budget or creating a savings contribution under Costs. Use funds by assigning an expense to the budget. Remaining balances carry over to the next month.', + ], 'savings_destination' => 'Save / set aside in pool', 'normal_expense' => 'Regular expense (no savings contribution)', 'savings_help' => 'For example a home savings or food pool. This amount is set aside from existing income and split using the selected rule. The payer holds the pool funds. Do not record another income. Each participant’s available remainder decreases by their savings share.', diff --git a/resources/views/components/monthly-calculation.blade.php b/resources/views/components/monthly-calculation.blade.php index 03a39b3..2fff347 100644 --- a/resources/views/components/monthly-calculation.blade.php +++ b/resources/views/components/monthly-calculation.blade.php @@ -1,4 +1,4 @@ -@props(['person']) +@props(['person', 'budgets' => []])
{{ __('participants.account.income') }}
+{{ \App\Support\Money::format($person['income_cents']) }}
{{ __('participants.account.share') }}
{{ \App\Support\Money::format(-$person['share_cents']) }}
@@ -6,7 +6,20 @@ @if(($person[$field] ?? 0) !== 0) @php $amount = $field === 'reserved_cents' ? -$person[$field] : $person[$field]; @endphp
{{ __('participants.account.'.$label) }}
{{ $amount > 0 ? '+' : '' }}{{ \App\Support\Money::format($amount) }}
+ @if(in_array($field, ['reserved_cents', 'opening_reserved_cents'], true)) + @foreach($budgets as $budget) + @php $reserved = $budget[$field === 'opening_reserved_cents' ? 'opening_balances' : 'balances'][$person['id']] ?? 0; @endphp + @if($reserved !== 0) +
+
{{ $budget['name'] }}
+
{{ $field === 'reserved_cents' ? '-' : '+' }}{{ \App\Support\Money::format($reserved) }}
+
+ @endif + @endforeach + @endif @endif @endforeach
{{ __('participants.detail.left') }}
{{ $person['remaining_cents'] > 0 ? '+' : '' }}{{ \App\Support\Money::format($person['remaining_cents']) }}
+ + diff --git a/resources/views/components/savings-explanation.blade.php b/resources/views/components/savings-explanation.blade.php new file mode 100644 index 0000000..4fa1c43 --- /dev/null +++ b/resources/views/components/savings-explanation.blade.php @@ -0,0 +1,6 @@ +
+ {{ __('funding.savings.what') }} +

{{ __('funding.savings.meaning') }}

+

{{ __('funding.savings.example') }}

+

{{ __('funding.savings.setup') }}

+
diff --git a/resources/views/filament/household-style.blade.php b/resources/views/filament/household-style.blade.php index 26bdb75..892e436 100644 --- a/resources/views/filament/household-style.blade.php +++ b/resources/views/filament/household-style.blade.php @@ -96,4 +96,11 @@ .hh-personal-footer { display: flex; flex-wrap: wrap; align-items: start; column-gap: 1.5rem; row-gap: .5rem; border-top: 1px solid #dbe5e4; padding-top: .75rem; } .hh-personal-footer > details[open] { flex-basis: 100%; } .dark .hh-personal-footer { border-color: #36383b; } +.hh-calculation > .hh-reserve-item { padding-inline-start: 1rem; border-inline-start: 2px solid #dbe5e4; color: #697c80; } +.hh-calculation > .hh-reserve-item dt, .hh-calculation > .hh-reserve-item dd { font-size: .8rem; font-weight: 400; overflow-wrap: anywhere; } +.dark .hh-calculation > .hh-reserve-item { border-color: #34494b; color: #a4bcb7; } +.hh-savings-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,320px),1fr));gap:1rem;align-items:start} +.hh-savings-holders{border-top:1px solid #dbe5e4;padding-top:1rem}.hh-savings-holders h4{font-size:.8rem;font-weight:600;margin-bottom:.75rem} +.hh-savings-explanation{font-size:.85rem;line-height:1.7;margin-top:1rem}.hh-savings-explanation summary{cursor:pointer;color:#0c8276;width:fit-content}.hh-savings-explanation summary:focus-visible{outline:2px solid #14b8a6;outline-offset:4px}.hh-savings-explanation p{margin-top:.75rem;max-width:90ch} +.dark .hh-savings-holders{border-color:#34494b}.dark .hh-savings-explanation summary{color:#66dac4} diff --git a/resources/views/filament/pages/participant-month.blade.php b/resources/views/filament/pages/participant-month.blade.php index f650922..8cde2cc 100644 --- a/resources/views/filament/pages/participant-month.blade.php +++ b/resources/views/filament/pages/participant-month.blade.php @@ -37,7 +37,7 @@

{{ __('participants.account.monthly') }}

- +

{{ __('participants.account.title') }}

diff --git a/resources/views/filament/pages/savings-overview.blade.php b/resources/views/filament/pages/savings-overview.blade.php new file mode 100644 index 0000000..947e306 --- /dev/null +++ b/resources/views/filament/pages/savings-overview.blade.php @@ -0,0 +1,48 @@ + + @php $money = fn ($cents) => \App\Support\Money::format($cents); @endphp +
+
+
{{ __('funding.savings.title') }}

{{ __('funding.savings.hero') }}

{{ __('funding.savings.intro') }}

+ +
+ + @if($problem) + + @else +
+
+
{{ $money($total) }}
+

{{ $closed ? __('funding.savings.closed') : __('funding.savings.planned') }}

+
+
+ @forelse($budgets as $budget) +
+

{{ $budget['name'] }}

+ +
+ @empty +

{{ __('funding.no_budgets') }}

{{ __('funding.budget_help') }}

+ @endforelse +
+ @endif + {{ __('funding.savings.manage') }} → +
+
diff --git a/resources/views/filament/widgets/monthly-budgets-footer.blade.php b/resources/views/filament/widgets/monthly-budgets-footer.blade.php index 063abde..8538ddb 100644 --- a/resources/views/filament/widgets/monthly-budgets-footer.blade.php +++ b/resources/views/filament/widgets/monthly-budgets-footer.blade.php @@ -1 +1,2 @@

{{ __('funding.budget_note') }}

+ diff --git a/resources/views/filament/widgets/monthly-participants.blade.php b/resources/views/filament/widgets/monthly-participants.blade.php index f7c5221..4cfa2de 100644 --- a/resources/views/filament/widgets/monthly-participants.blade.php +++ b/resources/views/filament/widgets/monthly-participants.blade.php @@ -16,7 +16,7 @@

{{ __('participants.account.monthly') }}

- +
{{ __('yearplan.table.month') }}{{ $accountParticipant->name }}