resetPage(); } public function updatedDateTo(): void { $this->resetPage(); } public function clearFilters(): void { $this->dateFrom = ''; $this->dateTo = ''; $this->resetPage(); } public function openApproveModal(int $id): void { $this->approvingBookingId = $id; $this->consultationType = 'free'; $this->paymentAmount = null; $this->paymentInstructions = ''; $this->showApproveModal = true; } public function quickApprove(): void { $consultation = Consultation::with('user')->findOrFail($this->approvingBookingId); if ($consultation->status !== ConsultationStatus::Pending) { session()->flash('error', __('admin.booking_already_processed')); $this->showApproveModal = false; return; } $this->validate([ 'consultationType' => ['required', 'in:free,paid'], 'paymentAmount' => ['required_if:consultationType,paid', 'nullable', 'numeric', 'min:0'], 'paymentInstructions' => ['nullable', 'string', 'max:1000'], ]); $oldStatus = $consultation->status->value; $type = $this->consultationType === 'paid' ? ConsultationType::Paid : ConsultationType::Free; $consultation->update([ 'status' => ConsultationStatus::Approved, 'consultation_type' => $type, 'payment_amount' => $type === ConsultationType::Paid ? $this->paymentAmount : null, 'payment_status' => $type === ConsultationType::Paid ? PaymentStatus::Pending : PaymentStatus::NotApplicable, ]); // Generate calendar file and send notification $icsContent = null; try { $calendarService = app(CalendarService::class); $icsContent = $calendarService->generateIcs($consultation); } catch (\Exception $e) { Log::error('Failed to generate calendar file', [ 'consultation_id' => $consultation->id, 'error' => $e->getMessage(), ]); } // Send appropriate notification/email based on guest/client if ($consultation->isGuest()) { Mail::to($consultation->guest_email)->queue( new GuestBookingApprovedMail( $consultation, app()->getLocale(), $this->paymentInstructions ?: null ) ); } elseif ($consultation->user) { $consultation->user->notify( new BookingApproved($consultation, $icsContent ?? '', $this->paymentInstructions ?: null) ); } // Log action AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'approve', 'target_type' => 'consultation', 'target_id' => $consultation->id, 'old_values' => ['status' => $oldStatus], 'new_values' => [ 'status' => ConsultationStatus::Approved->value, 'consultation_type' => $type->value, 'payment_amount' => $this->paymentAmount, ], 'ip_address' => request()->ip(), 'created_at' => now(), ]); $this->showApproveModal = false; session()->flash('success', __('admin.booking_approved')); } public function quickReject(int $id): void { $consultation = Consultation::with('user')->findOrFail($id); if ($consultation->status !== ConsultationStatus::Pending) { session()->flash('error', __('admin.booking_already_processed')); return; } $oldStatus = $consultation->status->value; $consultation->update([ 'status' => ConsultationStatus::Rejected, ]); // Send appropriate notification/email based on guest/client if ($consultation->isGuest()) { Mail::to($consultation->guest_email)->queue( new GuestBookingRejectedMail( $consultation, app()->getLocale(), null ) ); } elseif ($consultation->user) { $consultation->user->notify( new BookingRejected($consultation, null) ); } // Log action AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'reject', 'target_type' => 'consultation', 'target_id' => $consultation->id, 'old_values' => ['status' => $oldStatus], 'new_values' => [ 'status' => ConsultationStatus::Rejected->value, ], 'ip_address' => request()->ip(), 'created_at' => now(), ]); session()->flash('success', __('admin.booking_rejected')); } public function with(): array { return [ 'bookings' => Consultation::query() ->where('status', ConsultationStatus::Pending) ->when($this->dateFrom, fn ($q) => $q->where('booking_date', '>=', $this->dateFrom)) ->when($this->dateTo, fn ($q) => $q->where('booking_date', '<=', $this->dateTo)) ->with('user:id,full_name,email,phone,user_type') ->orderBy('booking_date') ->orderBy('booking_time') ->paginate(15), ]; } }; ?>
{{ __('admin.pending_bookings') }}
@if(session('success')) {{ session('success') }} @endif @if(session('error')) {{ session('error') }} @endif
{{ __('admin.date_from') }} {{ __('admin.date_to') }} @if($dateFrom || $dateTo) {{ __('common.clear') }} @endif
@forelse($bookings as $booking)
@if($booking->isGuest()) {{ __('admin.guest') }} @endif {{ $booking->getClientName() }} {{ $booking->status->label() }}
{{ \Carbon\Carbon::parse($booking->booking_date)->translatedFormat('l, d M Y') }}
{{ \Carbon\Carbon::parse($booking->booking_time)->format('g:i A') }}
{{ __('admin.submitted') }}: {{ $booking->created_at->translatedFormat('d M Y') }}

{{ Str::limit($booking->problem_summary, 150) }}

{{ __('admin.review') }} {{ __('admin.quick_approve') }} {{ __('admin.quick_reject') }}
@empty

{{ __('admin.no_pending_bookings') }}

@endforelse
{{ $bookings->links() }}
{{ __('admin.approve_booking') }} {{ __('admin.consultation_type') }} @if($consultationType === 'paid') {{ __('admin.payment_amount') }} * {{ __('admin.payment_instructions') }} @endif
{{ __('common.cancel') }} {{ __('admin.approve') }}