$data */ protected function handleRecordCreation(array $data): Model { if (($data['kind'] ?? null) === BookingForm::OWN_USE) { $this->redirect(BlockedPeriodResource::getUrl()); $this->halt(); } try { $property = Property::query()->findOrFail($data['property_id']); $channel = filled($data['channel_id'] ?? null) ? Channel::query()->findOrFail($data['channel_id']) : null; $arrival = CarbonImmutable::parse($data['arrival']); $departure = CarbonImmutable::parse($data['departure']); $guest = Arr::only($data, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']); if ($data['kind'] === BookingForm::EXTERNAL) { return app(TakeOverExternalBooking::class)->handle($property, $channel, $arrival, $departure, [ 'guest' => $guest, 'guests' => filled($data['guests'] ?? null) ? (int) $data['guests'] : null, 'portal_reference' => $data['portal_reference'] ?? null, 'portal_total' => filled($data['portal_total'] ?? null) ? (int) $data['portal_total'] : null, 'notes' => $data['internal_notes'] ?? null, 'guest_confirmed' => (bool) ($data['guest_confirmed'] ?? false), ]); } $stay = new StayRequest($arrival, $departure, (int) $data['guests'], promoCode: filled($data['promo_code'] ?? null) ? $data['promo_code'] : null); $sendMails = (bool) ($data['send_mails'] ?? false); $booking = app(CreateReservation::class)->handle($property, $stay, $guest, source: 'manual', sendMails: $sendMails && ! ($data['confirm_immediately'] ?? false), originChannel: $channel); if ($data['confirm_immediately'] ?? false) { DB::transaction(fn () => app(ConfirmBooking::class)->bind($booking)); if ($sendMails && filled($booking->guest?->email)) { // The documents go out only when their composition needs no check; otherwise they wait on the case page. $waiting = app(SendBookingDocuments::class)->automatically($booking->fresh()); if ($waiting !== []) { Notification::make()->title('Gebucht – Unterlagen noch nicht gesendet')->body(implode(' ', $waiting))->warning()->send(); } } else { app(ConfirmBooking::class)->deliver($booking->fresh(), notifyGuest: false); } } } catch (QuoteException|ReservationException $exception) { Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send(); $this->halt(); } if (filled($data['internal_notes'] ?? null)) { $booking->update(['internal_notes' => trim(($booking->internal_notes ? $booking->internal_notes."\n\n" : '').$data['internal_notes'])]); } return $booking; } protected function getRedirectUrl(): string { /** @var Booking $record */ $record = $this->getRecord(); return BookingResource::getUrl('view', ['record' => $record]); } }