Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Filament/Pages/ParticipantMonth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
80 changes: 80 additions & 0 deletions app/Filament/Pages/SavingsOverview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace App\Filament\Pages;

use App\Models\Expense;
use App\Models\Income;
use App\Models\MonthlyClosing;
use App\Models\Participant;
use App\Services\BudgetFunding;
use BackedEnum;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Url;

/** Show accumulated earmarked funds and their account holders for a selected month. */
class SavingsOverview extends Page
{
protected string $view = 'filament.pages.savings-overview';

protected static ?int $navigationSort = 3;

protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedWallet;

/** Month whose projected or frozen closing reserves are displayed. */
#[Url]
public string $month = '';

/** Default to this month while retaining direct links to historical months. */
public function mount(): void
{
$this->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<array<string, mixed>>, names: array<int, string>, 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];
}
}
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions lang/de/funding.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
18 changes: 18 additions & 0 deletions lang/en/funding.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
15 changes: 14 additions & 1 deletion resources/views/components/monthly-calculation.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
@props(['person'])
@props(['person', 'budgets' => []])
<dl class="hh-calculation">
<div><dt>{{ __('participants.account.income') }}</dt><dd>+{{ \App\Support\Money::format($person['income_cents']) }}</dd></div>
<div><dt>{{ __('participants.account.share') }}</dt><dd>{{ \App\Support\Money::format(-$person['share_cents']) }}</dd></div>
@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
<div><dt>{{ __('participants.account.'.$label) }}</dt><dd>{{ $amount > 0 ? '+' : '' }}{{ \App\Support\Money::format($amount) }}</dd></div>
@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)
<div class="hh-reserve-item">
<dt>{{ $budget['name'] }}</dt>
<dd>{{ $field === 'reserved_cents' ? '-' : '+' }}{{ \App\Support\Money::format($reserved) }}</dd>
</div>
@endif
@endforeach
@endif
@endif
@endforeach
<div class="hh-calculation-total"><dt>{{ __('participants.detail.left') }}</dt><dd class="{{ $person['remaining_cents'] < 0 ? 'hh-negative' : '' }}">{{ $person['remaining_cents'] > 0 ? '+' : '' }}{{ \App\Support\Money::format($person['remaining_cents']) }}</dd></div>
</dl>

<x-savings-explanation />
6 changes: 6 additions & 0 deletions resources/views/components/savings-explanation.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<details class="hh-savings-explanation">
<summary>{{ __('funding.savings.what') }}</summary>
<p>{{ __('funding.savings.meaning') }}</p>
<p>{{ __('funding.savings.example') }}</p>
<p>{{ __('funding.savings.setup') }}</p>
</details>
7 changes: 7 additions & 0 deletions resources/views/filament/household-style.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
</style>
2 changes: 1 addition & 1 deletion resources/views/filament/pages/participant-month.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</div>
<section class="hh-section">
<div class="hh-section-head"><h3>{{ __('participants.account.monthly') }}</h3></div>
<div class="hh-account-calculation"><x-monthly-calculation :person="$person" /></div>
<div class="hh-account-calculation"><x-monthly-calculation :person="$person" :budgets="$budgets" /></div>
</section>
<section class="hh-section">
<div class="hh-section-head"><h3>{{ __('participants.account.title') }}</h3></div>
Expand Down
48 changes: 48 additions & 0 deletions resources/views/filament/pages/savings-overview.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<x-filament-panels::page>
@php $money = fn ($cents) => \App\Support\Money::format($cents); @endphp
<div class="hh-stack">
<div class="hh-hero">
<div><div class="hh-kicker">{{ __('funding.savings.title') }}</div><h2>{{ __('funding.savings.hero') }}</h2><p>{{ __('funding.savings.intro') }}</p></div>
<label>{{ __('funding.savings.month') }}<br><input class="hh-input" type="month" wire:model.live="month" aria-label="{{ __('funding.savings.month') }}"></label>
</div>
<x-savings-explanation />
@if($problem)
<p role="alert" class="hh-warning">{{ $problem }}</p>
@else
<div class="hh-card">
<div class="hh-card-head"><x-filament::icon icon="heroicon-o-wallet" class="hh-icon" /><label>{{ __('funding.savings.total') }} · {{ \App\Support\Month::format($month) }}</label></div>
<div class="hh-number">{{ $money($total) }}</div>
<p class="hh-muted">{{ $closed ? __('funding.savings.closed') : __('funding.savings.planned') }}</p>
</div>
<div class="hh-savings-grid">
@forelse($budgets as $budget)
<section class="hh-section">
<div class="hh-section-head"><h3>{{ $budget['name'] }}</h3><x-filament::icon icon="heroicon-o-wallet" class="hh-icon" /></div>
<div class="hh-account-calculation">
<div><span class="hh-muted">{{ __('funding.closing') }}</span><div class="hh-number">{{ $money($budget['closing_cents']) }}</div></div>
<dl class="hh-calculation">
<div><dt>{{ __('funding.opening') }}</dt><dd>{{ $money($budget['opening_cents']) }}</dd></div>
<div><dt>{{ __('funding.receipts') }}</dt><dd>+{{ $money($budget['income_cents']) }}</dd></div>
<div><dt>{{ __('funding.spent') }}</dt><dd>{{ $money(-$budget['spent_cents']) }}</dd></div>
</dl>
<div class="hh-savings-holders">
<h4>{{ __('funding.savings.holders') }}</h4>
<dl class="hh-calculation">
@foreach($budget['balances'] as $participantId => $cents)
@if($cents !== 0)
<div><dt>{{ $names[$participantId] ?? '–' }}</dt><dd>{{ $money($cents) }}</dd></div>
@endif
@endforeach
</dl>
@if($budget['closing_cents'] === 0)<p class="hh-muted">{{ __('funding.savings.empty_pot') }}</p>@endif
</div>
</div>
</section>
@empty
<div class="hh-card"><p>{{ __('funding.no_budgets') }}</p><p class="hh-muted">{{ __('funding.budget_help') }}</p></div>
@endforelse
</div>
@endif
<a class="hh-link" href="{{ \App\Filament\Resources\Budgets\BudgetResource::getUrl() }}">{{ __('funding.savings.manage') }} →</a>
</div>
</x-filament-panels::page>
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<p class="hh-note">{{ __('funding.budget_note') }}</p>
<div class="hh-note"><a class="hh-link" href="{{ \App\Filament\Pages\SavingsOverview::getUrl(['month' => $this->month]) }}">{{ __('funding.savings.title') }} →</a></div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</header>
<div class="hh-personal-month">
<h3>{{ __('participants.account.monthly') }}</h3>
<x-monthly-calculation :person="$person" />
<x-monthly-calculation :person="$person" :budgets="$report['budgets'] ?? []" />
</div>
<div class="hh-personal-account">
@if($forecast)
Expand Down
Loading