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>
43 lines
964 B
PHP
43 lines
964 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Transaction extends Model
|
|
{
|
|
protected $fillable = ['household_id', 'category_id', 'recurring_transaction_id', 'user_id', 'paid_by_user_id', 'date', 'date_effective', 'amount', 'details'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'date' => 'date',
|
|
'date_effective' => 'date',
|
|
'amount' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function household(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Household::class);
|
|
}
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function paidBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'paid_by_user_id');
|
|
}
|
|
}
|