consultation = $consultation->load(['user']); } public function openApproveModal(): void { $this->showApproveModal = true; } public function openRejectModal(): void { $this->showRejectModal = true; } public function approve(): void { if ($this->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 = $this->consultation->status->value; $type = $this->consultationType === 'paid' ? ConsultationType::Paid : ConsultationType::Free; $this->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 $icsContent = null; try { $calendarService = app(CalendarService::class); $icsContent = $calendarService->generateIcs($this->consultation); } catch (\Exception $e) { Log::error('Failed to generate calendar file', [ 'consultation_id' => $this->consultation->id, 'error' => $e->getMessage(), ]); } // Send appropriate notification/email based on guest/client if ($this->consultation->isGuest()) { Mail::to($this->consultation->guest_email)->queue( new GuestBookingApprovedMail( $this->consultation, app()->getLocale(), $this->paymentInstructions ?: null ) ); } elseif ($this->consultation->user) { $this->consultation->user->notify( new BookingApproved( $this->consultation, $icsContent ?? '', $this->paymentInstructions ?: null ) ); } // Log action AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'approve', 'target_type' => 'consultation', 'target_id' => $this->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(), ]); session()->flash('success', __('admin.booking_approved')); $this->redirect(route('admin.bookings.pending'), navigate: true); } public function reject(): void { if ($this->consultation->status !== ConsultationStatus::Pending) { session()->flash('error', __('admin.booking_already_processed')); $this->showRejectModal = false; return; } $this->validate([ 'rejectionReason' => ['nullable', 'string', 'max:1000'], ]); $oldStatus = $this->consultation->status->value; $this->consultation->update([ 'status' => ConsultationStatus::Rejected, ]); // Send appropriate notification/email based on guest/client if ($this->consultation->isGuest()) { Mail::to($this->consultation->guest_email)->queue( new GuestBookingRejectedMail( $this->consultation, app()->getLocale(), $this->rejectionReason ?: null ) ); } elseif ($this->consultation->user) { $this->consultation->user->notify( new BookingRejected($this->consultation, $this->rejectionReason ?: null) ); } // Log action AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'reject', 'target_type' => 'consultation', 'target_id' => $this->consultation->id, 'old_values' => ['status' => $oldStatus], 'new_values' => [ 'status' => ConsultationStatus::Rejected->value, 'reason' => $this->rejectionReason, ], 'ip_address' => request()->ip(), 'created_at' => now(), ]); session()->flash('success', __('admin.booking_rejected')); $this->redirect(route('admin.bookings.pending'), navigate: true); } public function with(): array { // Guest bookings don't have consultation history if ($this->consultation->isGuest()) { return ['consultationHistory' => collect()]; } return [ 'consultationHistory' => Consultation::query() ->where('user_id', $this->consultation->user_id) ->where('id', '!=', $this->consultation->id) ->orderBy('booking_date', 'desc') ->limit(5) ->get(), ]; } }; ?>
{{ __('admin.client_name') }}
{{ $consultation->getClientName() }}
{{ __('admin.client_email') }}
{{ __('admin.client_phone') }}
@if($consultation->getClientPhone()) {{ $consultation->getClientPhone() }} @else - @endif
{{ __('admin.client_type') }}
{{ ucfirst($consultation->user?->user_type?->value ?? '-') }}
{{ __('admin.requested_date') }}
{{ \Carbon\Carbon::parse($consultation->booking_date)->translatedFormat('l, d M Y') }}
{{ __('admin.requested_time') }}
{{ \Carbon\Carbon::parse($consultation->booking_time)->format('g:i A') }}
{{ __('admin.submission_date') }}
{{ $consultation->created_at->translatedFormat('d M Y, g:i A') }}
{{ __('admin.current_status') }}
{{ __('admin.problem_summary') }}
{{ $consultation->problem_summary }}
{{ \Carbon\Carbon::parse($history->booking_date)->translatedFormat('d M Y') }}
{{ $history->consultation_type?->value ?? '-' }}
{{ __('admin.client') }}: {{ $consultation->getClientName() }}
{{ __('admin.date') }}: {{ \Carbon\Carbon::parse($consultation->booking_date)->translatedFormat('l, d M Y') }}
{{ __('admin.time') }}: {{ \Carbon\Carbon::parse($consultation->booking_time)->format('g:i A') }}
{{ __('admin.client') }}: {{ $consultation->getClientName() }}
{{ __('admin.date') }}: {{ \Carbon\Carbon::parse($consultation->booking_date)->translatedFormat('l, d M Y') }}
{{ __('admin.time') }}: {{ \Carbon\Carbon::parse($consultation->booking_time)->format('g:i A') }}