Commit d66d0f07 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix all non-existent database column references across codebase

- TrainerShow: period_start→date, total_amount→amount, status 'pending'→'active'
- trainer-show.blade: period_start→date, sessions_count→quantity, total_amount→amount
- AttendanceResource: actual_check_in→check_in_at, date→session.session_date
- InvoiceResource: invoice_number→number, balance_due→due_amount, remove description_ar
- ReportService: paid_amount→status check, cancellation_reason→withdrawal_reason,
  wallet status→is_active, remove frozen_amount
- SendDailySummary: Organization→Academy, is_active→status='active'
- SendParentWeeklyReport: fix morph type + join through session_date
- DeactivateExpiredEnrollments: expiry_date→end_date
- CertificateController + NotifyGuardianOfAbsence + RemoveAttendanceRecords:
  morph type 'participant'→Participant::class
- SendInvoiceCancelledNotification: cancellation_reason→notes
- DeleteParticipant: remove phantom refunded_amount reference
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent b2a36e89
...@@ -13,8 +13,8 @@ class DeactivateExpiredEnrollments extends Command ...@@ -13,8 +13,8 @@ class DeactivateExpiredEnrollments extends Command
public function handle(): int public function handle(): int
{ {
$expired = Enrollment::where('status', 'active') $expired = Enrollment::where('status', 'active')
->whereNotNull('expiry_date') ->whereNotNull('end_date')
->where('expiry_date', '<', now()->toDateString()) ->where('end_date', '<', now()->toDateString())
->get(); ->get();
$count = 0; $count = 0;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Domain\Financial\Models\Payment; use App\Domain\Financial\Models\Payment;
use App\Domain\Identity\Models\Organization; use App\Domain\Shared\Models\Academy;
use App\Domain\Notification\Services\NotificationService; use App\Domain\Notification\Services\NotificationService;
use App\Domain\Participant\Models\Participant; use App\Domain\Participant\Models\Participant;
use App\Domain\Training\Models\Enrollment; use App\Domain\Training\Models\Enrollment;
...@@ -20,7 +20,7 @@ public function handle(NotificationService $notificationService): int ...@@ -20,7 +20,7 @@ public function handle(NotificationService $notificationService): int
{ {
$yesterday = now()->subDay()->toDateString(); $yesterday = now()->subDay()->toDateString();
$academies = Organization::where('is_active', true)->get(); $academies = Academy::where('status', 'active')->get();
foreach ($academies as $academy) { foreach ($academies as $academy) {
try { try {
......
...@@ -26,13 +26,14 @@ public function handle(NotificationService $notificationService): int ...@@ -26,13 +26,14 @@ public function handle(NotificationService $notificationService): int
foreach ($participants as $participant) { foreach ($participants as $participant) {
$attendance = DB::table('attendance_records') $attendance = DB::table('attendance_records')
->where('subject_type', 'participant') ->join('training_sessions', 'training_sessions.id', '=', 'attendance_records.training_session_id')
->where('subject_id', $participant->id) ->where('attendance_records.subject_type', \App\Domain\Participant\Models\Participant::class)
->whereBetween('date', [$weekStart, $weekEnd]) ->where('attendance_records.subject_id', $participant->id)
->whereBetween('training_sessions.session_date', [$weekStart, $weekEnd])
->selectRaw(" ->selectRaw("
COUNT(*) as total, COUNT(*) as total,
SUM(CASE WHEN status IN ('present','late','partial') THEN 1 ELSE 0 END) as attended, SUM(CASE WHEN attendance_records.status IN ('present','late','partial') THEN 1 ELSE 0 END) as attended,
SUM(CASE WHEN status = 'absent' THEN 1 ELSE 0 END) as absent SUM(CASE WHEN attendance_records.status = 'absent' THEN 1 ELSE 0 END) as absent
") ")
->first(); ->first();
......
...@@ -17,7 +17,7 @@ public function handle(ParticipantAbsent $event): void ...@@ -17,7 +17,7 @@ public function handle(ParticipantAbsent $event): void
{ {
try { try {
$participant = $event->record->subject; $participant = $event->record->subject;
if (!$participant || $event->record->subject_type !== 'participant') { if (!$participant || $event->record->subject_type !== \App\Domain\Participant\Models\Participant::class) {
return; return;
} }
......
...@@ -23,7 +23,7 @@ public function handle(InvoiceCancelled $event): void ...@@ -23,7 +23,7 @@ public function handle(InvoiceCancelled $event): void
data: [ data: [
'participant_name' => $event->invoice->billable?->person?->full_name ?? '', 'participant_name' => $event->invoice->billable?->person?->full_name ?? '',
'invoice_number' => $event->invoice->number, 'invoice_number' => $event->invoice->number,
'reason' => $event->invoice->cancellation_reason ?? '', 'reason' => $event->invoice->notes ?? '',
], ],
); );
} catch (\Throwable $e) { } catch (\Throwable $e) {
......
...@@ -105,7 +105,7 @@ public function installmentsDue(string $from, string $to, ?int $branchId = null) ...@@ -105,7 +105,7 @@ public function installmentsDue(string $from, string $to, ?int $branchId = null)
'participant' => $inst->paymentPlan?->invoice?->billable?->person?->name_ar ?? '', 'participant' => $inst->paymentPlan?->invoice?->billable?->person?->name_ar ?? '',
'phone' => $inst->paymentPlan?->invoice?->billable?->person?->phone ?? '', 'phone' => $inst->paymentPlan?->invoice?->billable?->person?->phone ?? '',
'amount' => $inst->amount, 'amount' => $inst->amount,
'paid' => $inst->paid_amount ?? 0, 'paid' => $inst->status === 'paid' ? $inst->amount : 0,
'due_date' => $inst->due_date?->format('Y-m-d'), 'due_date' => $inst->due_date?->format('Y-m-d'),
'status' => $inst->status, 'status' => $inst->status,
'invoice' => $inst->paymentPlan?->invoice?->number ?? '', 'invoice' => $inst->paymentPlan?->invoice?->number ?? '',
...@@ -426,7 +426,7 @@ public function cancellationsReport(string $from, string $to, ?int $branchId = n ...@@ -426,7 +426,7 @@ public function cancellationsReport(string $from, string $to, ?int $branchId = n
'group' => $e->group?->name_ar ?? '', 'group' => $e->group?->name_ar ?? '',
'enrolled_at' => $e->enrollment_date?->format('Y-m-d') ?? '', 'enrolled_at' => $e->enrollment_date?->format('Y-m-d') ?? '',
'cancelled_at' => $e->updated_at?->format('Y-m-d'), 'cancelled_at' => $e->updated_at?->format('Y-m-d'),
'reason' => $e->cancellation_reason ?? '', 'reason' => $e->withdrawal_reason ?? '',
]); ]);
} }
...@@ -642,7 +642,7 @@ public function walletBalances(?int $branchId = null): Collection ...@@ -642,7 +642,7 @@ public function walletBalances(?int $branchId = null): Collection
{ {
return Wallet::with(['owner.person']) return Wallet::with(['owner.person'])
->where('owner_type', 'App\\Domain\\Participant\\Models\\Participant') ->where('owner_type', 'App\\Domain\\Participant\\Models\\Participant')
->where('status', 'active') ->where('is_active', true)
->where('balance', '>', 0) ->where('balance', '>', 0)
->when($branchId, fn ($q) => $q->whereHasMorph('owner', [Participant::class], fn ($p) => $p->where('branch_id', $branchId))) ->when($branchId, fn ($q) => $q->whereHasMorph('owner', [Participant::class], fn ($p) => $p->where('branch_id', $branchId)))
->orderByDesc('balance') ->orderByDesc('balance')
...@@ -651,8 +651,8 @@ public function walletBalances(?int $branchId = null): Collection ...@@ -651,8 +651,8 @@ public function walletBalances(?int $branchId = null): Collection
'participant' => $w->owner?->person?->name_ar ?? '', 'participant' => $w->owner?->person?->name_ar ?? '',
'phone' => $w->owner?->person?->phone ?? '', 'phone' => $w->owner?->person?->phone ?? '',
'balance' => $w->balance, 'balance' => $w->balance,
'frozen' => $w->frozen_amount ?? 0, 'frozen' => 0,
'available' => $w->balance - ($w->frozen_amount ?? 0), 'available' => $w->balance,
'last_transaction' => $w->updated_at?->format('Y-m-d'), 'last_transaction' => $w->updated_at?->format('Y-m-d'),
]); ]);
} }
......
...@@ -24,7 +24,7 @@ public function handle(EnrollmentCancelled $event): void ...@@ -24,7 +24,7 @@ public function handle(EnrollmentCancelled $event): void
} }
AttendanceRecord::whereIn('training_session_id', $futureSessionIds) AttendanceRecord::whereIn('training_session_id', $futureSessionIds)
->where('subject_type', 'participant') ->where('subject_type', \App\Domain\Participant\Models\Participant::class)
->where('subject_id', $enrollment->participant_id) ->where('subject_id', $enrollment->participant_id)
->where('status', 'expected') ->where('status', 'expected')
->delete(); ->delete();
......
...@@ -16,7 +16,7 @@ public function attendance(Participant $participant, Enrollment $enrollment) ...@@ -16,7 +16,7 @@ public function attendance(Participant $participant, Enrollment $enrollment)
$enrollment->load('trainingGroup.program'); $enrollment->load('trainingGroup.program');
$stats = DB::table('attendance_records') $stats = DB::table('attendance_records')
->where('subject_type', 'participant') ->where('subject_type', Participant::class)
->where('subject_id', $participant->id) ->where('subject_id', $participant->id)
->join('training_sessions', 'training_sessions.id', '=', 'attendance_records.training_session_id') ->join('training_sessions', 'training_sessions.id', '=', 'attendance_records.training_session_id')
->where('training_sessions.training_group_id', $enrollment->training_group_id) ->where('training_sessions.training_group_id', $enrollment->training_group_id)
......
...@@ -11,10 +11,10 @@ public function toArray(Request $request): array ...@@ -11,10 +11,10 @@ public function toArray(Request $request): array
{ {
return [ return [
'id' => $this->id, 'id' => $this->id,
'date' => $this->date?->format('Y-m-d'), 'date' => $this->session?->session_date?->format('Y-m-d'),
'status' => $this->status?->value ?? $this->status, 'status' => $this->status?->value ?? $this->status,
'check_in_time' => $this->actual_check_in, 'check_in_time' => $this->check_in_at,
'check_out_time' => $this->actual_check_out, 'check_out_time' => $this->check_out_at,
'late_minutes' => $this->late_minutes, 'late_minutes' => $this->late_minutes,
'notes' => $this->notes, 'notes' => $this->notes,
'session' => $this->whenLoaded('session', fn () => [ 'session' => $this->whenLoaded('session', fn () => [
......
...@@ -12,16 +12,16 @@ public function toArray(Request $request): array ...@@ -12,16 +12,16 @@ public function toArray(Request $request): array
return [ return [
'id' => $this->id, 'id' => $this->id,
'uuid' => $this->uuid, 'uuid' => $this->uuid,
'invoice_number' => $this->invoice_number, 'invoice_number' => $this->number,
'status' => $this->status?->value ?? $this->status, 'status' => $this->status?->value ?? $this->status,
'total_amount' => $this->total_amount, 'total_amount' => $this->total_amount,
'paid_amount' => $this->paid_amount, 'paid_amount' => $this->paid_amount,
'balance_due' => $this->balance_due, 'balance_due' => $this->due_amount,
'due_date' => $this->due_date?->format('Y-m-d'), 'due_date' => $this->due_date?->format('Y-m-d'),
'created_at' => $this->created_at?->format('Y-m-d'), 'created_at' => $this->created_at?->format('Y-m-d'),
'items' => $this->whenLoaded('items', fn () => 'items' => $this->whenLoaded('items', fn () =>
$this->items->map(fn ($item) => [ $this->items->map(fn ($item) => [
'description' => $item->description_ar ?? $item->description, 'description' => $item->description,
'quantity' => $item->quantity, 'quantity' => $item->quantity,
'unit_price' => $item->unit_price, 'unit_price' => $item->unit_price,
'total_amount' => $item->total_amount, 'total_amount' => $item->total_amount,
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
use App\Domain\Attendance\Enums\AttendanceStatus; use App\Domain\Attendance\Enums\AttendanceStatus;
use App\Domain\Attendance\Models\AttendanceRecord; use App\Domain\Attendance\Models\AttendanceRecord;
use App\Domain\HR\Models\Trainer; use App\Domain\HR\Models\Trainer;
use App\Domain\Training\Models\Enrollment;
use App\Domain\Training\Models\TrainingGroup; use App\Domain\Training\Models\TrainingGroup;
use App\Domain\Training\Models\TrainingSession; use App\Domain\Training\Models\TrainingSession;
use Livewire\Attributes\Layout; use Livewire\Attributes\Layout;
...@@ -83,20 +82,20 @@ public function render() ...@@ -83,20 +82,20 @@ public function render()
// Recent compensations // Recent compensations
$recentCompensations = $this->trainer->compensations() $recentCompensations = $this->trainer->compensations()
->orderByDesc('period_start') ->orderByDesc('date')
->limit(6) ->limit(6)
->get(); ->get();
// Monthly earnings (current month) // Monthly earnings (current month)
$monthlyEarnings = $this->trainer->compensations() $monthlyEarnings = $this->trainer->compensations()
->where('period_start', '>=', now()->startOfMonth()) ->where('date', '>=', now()->startOfMonth())
->where('period_start', '<=', now()->endOfMonth()) ->where('date', '<=', now()->endOfMonth())
->sum('total_amount'); ->sum('amount');
// Advances balance // Advances balance
$pendingAdvances = $this->trainer->advances() $pendingAdvances = $this->trainer->advances()
->where('status', 'pending') ->where('status', 'active')
->sum('amount'); ->sum('remaining_balance');
return view('livewire.hr.trainer-show', [ return view('livewire.hr.trainer-show', [
'person' => $person, 'person' => $person,
......
...@@ -88,7 +88,7 @@ public function confirmRefund(int $invoiceId): void ...@@ -88,7 +88,7 @@ public function confirmRefund(int $invoiceId): void
->get(); ->get();
foreach ($confirmedPayments as $payment) { foreach ($confirmedPayments as $payment) {
$refundableAmount = $payment->amount - ($payment->refunded_amount ?? 0); $refundableAmount = $payment->amount;
if ($refundableAmount > 0) { if ($refundableAmount > 0) {
$paymentService->refund($payment, $refundableAmount, auth()->user()); $paymentService->refund($payment, $refundableAmount, auth()->user());
} }
......
...@@ -493,9 +493,9 @@ class="text-sm font-semibold text-blue-600 hover:text-blue-800 hover:underline"> ...@@ -493,9 +493,9 @@ class="text-sm font-semibold text-blue-600 hover:text-blue-800 hover:underline">
<tbody class="divide-y divide-gray-100"> <tbody class="divide-y divide-gray-100">
@foreach($recentCompensations as $comp) @foreach($recentCompensations as $comp)
<tr class="hover:bg-gray-50"> <tr class="hover:bg-gray-50">
<td class="px-4 py-3 text-gray-800" dir="ltr">{{ $comp->period_start?->format('Y-m-d') }} → {{ $comp->period_end?->format('Y-m-d') }}</td> <td class="px-4 py-3 text-gray-800" dir="ltr">{{ $comp->date?->format('Y-m-d') }}</td>
<td class="px-4 py-3 text-gray-600">{{ $comp->sessions_count ?? '—' }}</td> <td class="px-4 py-3 text-gray-600">{{ $comp->quantity ?? '—' }}</td>
<td class="px-4 py-3 font-medium text-gray-800" dir="ltr">{{ number_format($comp->total_amount / 100, 2) }} {{ __('ج.م') }}</td> <td class="px-4 py-3 font-medium text-gray-800" dir="ltr">{{ number_format($comp->amount / 100, 2) }} {{ __('ج.م') }}</td>
<td class="px-4 py-3"> <td class="px-4 py-3">
@php @php
$compStatusColors = ['calculated' => 'blue', 'approved' => 'green', 'paid' => 'emerald', 'cancelled' => 'red']; $compStatusColors = ['calculated' => 'blue', 'approved' => 'green', 'paid' => 'emerald', 'cancelled' => 'red'];
......
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