Files
suivicpt/app/Models/RecurringTransaction.php
T
jeremy bayseandClaude Sonnet 5 9114bb2e8d Track who paid each depense, with a "Commun" (shared) fallback
Adds a "payé par" field to transactions and recurring transactions:
either a household member or null (shared/common expense). No per-
member account balances — this is purely a "who paid" label, the
household's overall balance is unchanged and unaffected by any
filtering.

- paid_by_user_id nullable FK on transactions and recurring_transactions
- Suivi: "payé par" selector on both entry forms (desktop dropdown,
  mobile buttons), a filter above the transaction table, a "payé par"
  column, and a summary tile showing this month's depenses grouped
  by payer (including Commun)
- Recurring transactions carry paid_by_user_id onto the transaction
  they generate when confirmed
- Running balance is computed from all transactions regardless of
  the payer filter, so it never gets skewed by the active filter

11 new Pest tests (assignment, common fallback, non-member rejection,
filter isolation from the balance calc, per-payer summary, recurring
propagation). 69/69 total pass, Pint clean, verified end-to-end on
production data (desktop + mobile, test row created and removed).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-01 08:24:14 +02:00

51 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class RecurringTransaction extends Model
{
protected $fillable = [
'household_id', 'category_id', 'paid_by_user_id', 'name', 'amount', 'day_of_month',
'active', 'last_generated_year', 'last_generated_month',
];
protected function casts(): array
{
return [
'amount' => 'decimal:2',
'active' => 'boolean',
];
}
public function household(): BelongsTo
{
return $this->belongsTo(Household::class);
}
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
public function paidBy(): BelongsTo
{
return $this->belongsTo(User::class, 'paid_by_user_id');
}
public function transactions(): HasMany
{
return $this->hasMany(Transaction::class);
}
public function wasGeneratedFor(int $year, int $month): bool
{
return $this->last_generated_year === $year && $this->last_generated_month === $month;
}
}