Add recurring transactions with monthly confirmation flow
New "Récurrences" section lets users define recurring depense/epargne models (name, category, default amount, day of month). Nothing is created automatically: from the day a recurrence is due, it appears as a pending proposal in Suivi (desktop + mobile) with an editable amount, so variable bills (electricity, etc.) can be adjusted before confirming. Dismissing a proposal skips it for the current month without creating a transaction, and it reappears the following month. - recurring_transactions table (household/category scoped, active flag, last_generated_year/month to prevent duplicate generation) - transactions.recurring_transaction_id nullable FK to trace origin - RecurringTransactionPolicy mirrors CategoryPolicy tenant scoping - 10 new Pest tests covering CRUD, tenant isolation, and the pending/confirm/dismiss lifecycle across month boundaries (travelTo) 58/58 tests pass, Pint clean, verified end-to-end against production data (test recurrence created and cleaned up). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
674c43afea
commit
b78c314569
@@ -6,6 +6,7 @@ namespace App\Livewire\Suivi;
|
||||
|
||||
use App\Enums\CategoryType;
|
||||
use App\Models\BudgetLine;
|
||||
use App\Models\RecurringTransaction;
|
||||
use App\Models\Transaction;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
@@ -65,6 +66,48 @@ class Index extends Component
|
||||
$transaction->delete();
|
||||
}
|
||||
|
||||
public function confirmRecurrence(int $recurringId, string $amount): void
|
||||
{
|
||||
$household = auth()->user()->currentHousehold;
|
||||
$recurring = $household->recurringTransactions()->findOrFail($recurringId);
|
||||
|
||||
$today = now();
|
||||
|
||||
if ($recurring->wasGeneratedFor((int) $today->year, (int) $today->month)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$household->transactions()->create([
|
||||
'category_id' => $recurring->category_id,
|
||||
'recurring_transaction_id' => $recurring->id,
|
||||
'user_id' => auth()->id(),
|
||||
'date' => $today->toDateString(),
|
||||
'date_effective' => $today->toDateString(),
|
||||
'amount' => $amount,
|
||||
'details' => $recurring->name,
|
||||
]);
|
||||
|
||||
$recurring->update([
|
||||
'last_generated_year' => $today->year,
|
||||
'last_generated_month' => $today->month,
|
||||
]);
|
||||
|
||||
$this->dispatch('transaction-added');
|
||||
}
|
||||
|
||||
public function dismissRecurrence(int $recurringId): void
|
||||
{
|
||||
$household = auth()->user()->currentHousehold;
|
||||
$recurring = $household->recurringTransactions()->findOrFail($recurringId);
|
||||
|
||||
$today = now();
|
||||
|
||||
$recurring->update([
|
||||
'last_generated_year' => $today->year,
|
||||
'last_generated_month' => $today->month,
|
||||
]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$household = auth()->user()->currentHousehold;
|
||||
@@ -106,6 +149,16 @@ class Index extends Component
|
||||
|
||||
$unaffected = max(0, $revenueBudget - $revenueTracked);
|
||||
|
||||
$today = now();
|
||||
$pendingRecurrences = $household->recurringTransactions()
|
||||
->with('category')
|
||||
->where('active', true)
|
||||
->where('day_of_month', '<=', $today->day)
|
||||
->get()
|
||||
->reject(fn (RecurringTransaction $r) => $r->wasGeneratedFor((int) $today->year, (int) $today->month))
|
||||
->sortBy('day_of_month')
|
||||
->values();
|
||||
|
||||
return view('livewire.suivi.index', [
|
||||
'transactions' => $transactions,
|
||||
'running' => $running,
|
||||
@@ -114,6 +167,7 @@ class Index extends Component
|
||||
'nbrTotal' => $transactions->count(),
|
||||
'lastEntry' => $transactions->first(),
|
||||
'unaffected' => $unaffected,
|
||||
'pendingRecurrences' => $pendingRecurrences,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user