block_date = today()->format('Y-m-d'); } public function openCreateModal(): void { $this->reset(['editingId', 'block_date', 'is_all_day', 'start_time', 'end_time', 'reason', 'pendingBookings']); $this->block_date = today()->format('Y-m-d'); $this->is_all_day = true; $this->start_time = '09:00'; $this->end_time = '17:00'; $this->showModal = true; } public function openEditModal(int $id): void { $blockedTime = BlockedTime::findOrFail($id); $this->editingId = $id; $this->block_date = $blockedTime->block_date->format('Y-m-d'); $this->is_all_day = $blockedTime->isAllDay(); $this->start_time = $blockedTime->start_time ?? '09:00'; $this->end_time = $blockedTime->end_time ?? '17:00'; $this->reason = $blockedTime->reason ?? ''; $this->pendingBookings = []; $this->showModal = true; } public function closeModal(): void { $this->showModal = false; $this->reset(['editingId', 'pendingBookings']); $this->resetValidation(); } public function updatedBlockDate(): void { $this->checkPendingBookings(); } public function updatedIsAllDay(): void { $this->checkPendingBookings(); } public function updatedStartTime(): void { $this->checkPendingBookings(); } public function updatedEndTime(): void { $this->checkPendingBookings(); } public function checkPendingBookings(): void { if (empty($this->block_date)) { $this->pendingBookings = []; return; } $query = Consultation::query() ->whereDate('booking_date', $this->block_date) ->where('status', ConsultationStatus::Pending) ->with('user:id,full_name,company_name'); if (! $this->is_all_day && $this->start_time && $this->end_time) { $query->where(function ($q) { $q->where('booking_time', '>=', $this->start_time) ->where('booking_time', '<', $this->end_time); }); } $this->pendingBookings = $query->get()->map(fn ($c) => [ 'id' => $c->id, 'time' => $c->booking_time, 'client' => $c->user->full_name ?? $c->user->company_name ?? __('clients.unknown'), ])->toArray(); } public function save(): void { $rules = [ 'block_date' => ['required', 'date'], 'is_all_day' => ['boolean'], 'reason' => ['nullable', 'string', 'max:255'], ]; if (! $this->editingId) { $rules['block_date'][] = 'after_or_equal:today'; } if (! $this->is_all_day) { $rules['start_time'] = ['required']; $rules['end_time'] = ['required', 'after:start_time']; } $this->validate($rules, [ 'block_date.after_or_equal' => __('validation.block_date_future'), 'end_time.after' => __('validation.end_time_after_start'), ]); $data = [ 'block_date' => $this->block_date, 'start_time' => $this->is_all_day ? null : $this->start_time, 'end_time' => $this->is_all_day ? null : $this->end_time, 'reason' => $this->reason ?: null, ]; if ($this->editingId) { $blockedTime = BlockedTime::findOrFail($this->editingId); $oldValues = $blockedTime->toArray(); $blockedTime->update($data); $action = 'update'; } else { $blockedTime = BlockedTime::create($data); $oldValues = null; $action = 'create'; } AdminLog::create([ 'admin_id' => auth()->id(), 'action' => $action, 'target_type' => 'blocked_time', 'target_id' => $blockedTime->id, 'old_values' => $oldValues, 'new_values' => $data, 'ip_address' => request()->ip(), 'created_at' => now(), ]); $this->closeModal(); session()->flash('success', __('messages.blocked_time_saved')); } public function confirmDelete(int $id): void { $this->deletingId = $id; $this->showDeleteModal = true; } public function closeDeleteModal(): void { $this->showDeleteModal = false; $this->deletingId = null; } public function delete(): void { $blockedTime = BlockedTime::findOrFail($this->deletingId); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'delete', 'target_type' => 'blocked_time', 'target_id' => $blockedTime->id, 'old_values' => $blockedTime->toArray(), 'new_values' => null, 'ip_address' => request()->ip(), 'created_at' => now(), ]); $blockedTime->delete(); $this->closeDeleteModal(); session()->flash('success', __('messages.blocked_time_deleted')); } public function with(): array { $query = BlockedTime::query()->orderBy('block_date'); if ($this->filter === 'upcoming') { $query->upcoming(); } elseif ($this->filter === 'past') { $query->past()->orderByDesc('block_date'); } return [ 'blockedTimes' => $query->get(), ]; } }; ?>
{{ $blocked->reason }}
@endif