guest?->email)) { throw new ReservationException('Vor dem E-Mail-Versand bitte die E-Mail-Adresse des zugeordneten Gastes ergänzen.'); } DB::transaction(function () use ($booking, $useTodaysPrice): void { $booking->lockForTransition(); if ($booking->status !== BookingStatus::Reserved || $booking->wish_at === null) { throw ReservationException::invalidTransition($booking->status->getLabel(), 'als Buchungswunsch bestätigt'); } // G2a also before the binding confirmation of a wish (v0.11, B3), by hand as well. if (($missing = CaseRequirements::blocker($booking->load('guest'), CaseRequirements::WISH_CONFIRMATION)) !== null) { throw new ReservationException($missing); } if ($useTodaysPrice) { $quote = $this->offer->quoteFor($booking, new StayRequest($booking->arrival, $booking->departure, $booking->guests, $booking->extras ?? [], $booking->promo_code), (int) $booking->price_adjustment, (string) ($booking->price_adjustment_label ?: 'Zuschlag')); if ($quote->total() > (int) $booking->total) { throw new ReservationException('Der heutige Preis ist höher als der Preis der Auskunft. Ohne Zustimmung des Gastes geht das nicht – bitte eine neue Auskunft senden.'); } $booking->update(['quote' => $quote->toArray(), 'total' => $quote->total(), 'deposit' => $quote->deposit(), 'balance_due_on' => $quote->balanceDueOn->toDateString()]); } $this->confirm->bind($booking); $booking->update([ 'accepted_at' => $booking->wish_at, 'acceptance' => [ 'via' => 'booking_wish', 'information_version' => $booking->wish['information_version'] ?? $booking->information_version, 'wish_at' => $booking->wish_at?->toIso8601String(), 'total' => $booking->total, 'quote_sha256' => SendInformation::quoteHash($booking), 'terms_sha256' => $booking->wish['terms_sha256'] ?? null, 'confirmed_by' => CaseLog::actor(), 'confirmed_at' => now()->toIso8601String(), ], ]); $this->closeTasks($booking, 'Bestätigt.'); }); $booking->refresh(); CaseLog::record($booking, 'wish', 'Buchungswunsch bestätigt – Buchung verbindlich'); return $this->confirm->deliver($booking, $notifyGuest); } /** * @throws ReservationException */ public function decline(Booking $booking, ?string $reason = null, bool $notifyGuest = true): void { DB::transaction(function () use ($booking): void { $booking->lockForTransition(); if ($booking->status !== BookingStatus::Reserved) { throw ReservationException::invalidTransition($booking->status->getLabel(), 'abgesagt'); } $booking->update(['status' => BookingStatus::Declined, 'declined_by' => 'us', 'hold_expires_at' => null]); $this->closeTasks($booking, 'Abgesagt.'); }); CaseLog::record($booking, 'wish', 'Buchungswunsch abgesagt', reason: $reason); if ($notifyGuest && filled($booking->guest?->email)) { try { Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingWishAnswered($booking->fresh(), 'declined')); } catch (Throwable $exception) { Log::warning('Absage zum Buchungswunsch nicht zugestellt', ['booking' => $booking->id, 'exception' => $exception::class]); } } } private function closeTasks(Booking $booking, string $note): void { foreach (BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::BookingWish)->where('status', BookingTaskStatus::Open)->get() as $task) { $task->complete(CaseLog::actor(), $note); } } }