guest?->email)) { throw new ReservationException('Der Gast hat keine E-Mail-Adresse – bitte ohne Mail an den Gast stornieren oder die Adresse ergänzen.'); } DB::transaction(function () use ($booking, $costsTask, $by): void { $booking->lockForTransition(); if (! in_array($booking->status, BookingStatus::occupying(), true)) { throw ReservationException::invalidTransition($booking->status->getLabel(), 'storniert'); } $booking->update(['status' => BookingStatus::Cancelled, 'cancelled_at' => now()]); app(RecordCancellation::class)->handle($booking, 'landlord'); BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::CancellationRequest)->where('status', BookingTaskStatus::Open) ->update(['status' => BookingTaskStatus::Done, 'completed_by' => $by, 'completed_at' => now()]); if ($costsTask) { $cost = CancellationCost::calculate($booking); BookingTask::query()->firstOrCreate(['booking_id' => $booking->id, 'kind' => BookingTaskKind::CancellationFee], [ 'status' => BookingTaskStatus::Open, 'due_on' => today(), 'note' => $cost ? 'Vorschlag nach Stornoregel „'.$cost['policy'].'“: '.Money::format($cost['fee']).' ('.$cost['tier_text'].')' : 'Keine Stornoregel hinterlegt – Kosten von Hand festlegen.', ]); } }); $booking->loadMissing(['guest', 'property']); return $this->notify($booking, $notifyGuest); } private function notify(Booking $booking, bool $notifyGuest): bool { $informed = true; try { Mail::to(Settings::notificationRecipients())->send(new CancellationRequested($booking, cancelled: true)); } catch (Throwable $exception) { Log::warning('Stornomitteilung an den Vermieter nicht zugestellt', ['booking' => $booking->id, 'exception' => $exception::class]); } if ($notifyGuest) { try { Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingCancelled($booking, cancelled: true)); } catch (Throwable $exception) { $informed = false; Log::warning('Stornomail an den Gast nicht zugestellt', ['booking' => $booking->id, 'exception' => $exception::class]); } } return $informed; } }