Commit 29f298f0 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Add collected_by to invoices — tracks who actually collected the payment

Auto-generated renewal invoices are created by the system, but
collected_by records the real person who collected the money from
the participant. Set on every payment collection via updatePaidAmount.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent da344cda
...@@ -46,6 +46,7 @@ class Invoice extends Model ...@@ -46,6 +46,7 @@ class Invoice extends Model
'last_printed_at', 'last_printed_at',
'created_by', 'created_by',
'approved_by', 'approved_by',
'collected_by',
]; ];
protected function casts(): array protected function casts(): array
...@@ -103,6 +104,11 @@ public function approver(): BelongsTo ...@@ -103,6 +104,11 @@ public function approver(): BelongsTo
return $this->belongsTo(User::class, 'approved_by'); return $this->belongsTo(User::class, 'approved_by');
} }
public function collector(): BelongsTo
{
return $this->belongsTo(User::class, 'collected_by');
}
public function enrollments(): HasMany public function enrollments(): HasMany
{ {
return $this->hasMany(\App\Domain\Training\Models\Enrollment::class); return $this->hasMany(\App\Domain\Training\Models\Enrollment::class);
......
...@@ -96,6 +96,7 @@ public function updatePaidAmount(Invoice $invoice, int $amount, User $actor): vo ...@@ -96,6 +96,7 @@ public function updatePaidAmount(Invoice $invoice, int $amount, User $actor): vo
{ {
$invoice->paid_amount += $amount; $invoice->paid_amount += $amount;
$invoice->due_amount = $invoice->total_amount - $invoice->paid_amount; $invoice->due_amount = $invoice->total_amount - $invoice->paid_amount;
$invoice->collected_by = $actor->id;
if ($invoice->due_amount <= 0) { if ($invoice->due_amount <= 0) {
$invoice->status = $invoice->due_amount < 0 $invoice->status = $invoice->due_amount < 0
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('invoices', function (Blueprint $table) {
$table->foreignId('collected_by')->nullable()->after('approved_by')->constrained('users')->nullOnDelete();
});
}
public function down(): void
{
Schema::table('invoices', function (Blueprint $table) {
$table->dropForeign(['collected_by']);
$table->dropColumn('collected_by');
});
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment