$contact first_name, last_name, email, phone, street, postal_code, city, country * @return string what was done, for the notification * * @throws ReservationException */ public function handle(Booking $booking, array $contact, string $process = self::MANUAL, bool $guestConfirmed = false): string { $contact = array_map(fn ($value) => filled($value) ? trim((string) $value) : null, Arr::only($contact, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'country'])); if (isset($contact['email'])) { $contact['email'] = mb_strtolower($contact['email']); } if ($process === self::AUTOMATIC && blank($contact['email'] ?? $booking->guest?->email)) { throw new ReservationException('Für den automatischen Ablauf wird die E-Mail-Adresse des Gastes benötigt.'); } if ($booking->guest === null) { if (blank($contact['first_name'] ?? null) || blank($contact['last_name'] ?? null)) { throw new ReservationException('Bitte Vor- und Nachnamen des Gastes angeben.'); } $guest = Guest::query()->create([...array_filter($contact, fn ($value) => $value !== null), 'email' => $contact['email'] ?? '']); $booking->update(['guest_id' => $guest->id]); } else { $booking->guest->update(array_filter($contact, fn ($value) => $value !== null)); } if ($guestConfirmed) { $booking->forceFill(['guest_confirmed_at' => $booking->guest_confirmed_at ?? now()])->save(); } $booking->refresh()->load('guest'); if ($process !== self::AUTOMATIC) { return 'Kontaktdaten gespeichert'; } $booking->update(['processing_mode' => ProcessingMode::Automatic]); if (in_array($booking->status, BookingStatus::occupying(), true)) { $reasons = $this->documents->automatically($booking); if ($reasons !== []) { throw new ReservationException('Kontaktdaten gespeichert. Die Unterlagen werden noch nicht automatisch versendet: '.implode(' ', $reasons)); } return 'Kontaktdaten gespeichert, Unterlagen gesendet'; } if ($booking->intake === IntakeKind::Booking) { DB::transaction(fn () => $this->confirm->bind($booking)); $reasons = $this->documents->automatically($booking->fresh()); if ($reasons !== []) { throw new ReservationException('Kontaktdaten gespeichert und Buchung bestätigt. Die Unterlagen werden noch nicht automatisch versendet: '.implode(' ', $reasons)); } return 'Kontaktdaten gespeichert, Buchung bestätigt und Unterlagen gesendet'; } $reasons = $this->autoOffer->handle($booking); if ($reasons !== []) { throw new ReservationException('Kontaktdaten gespeichert. Das Angebot wird noch nicht automatisch gesendet: '.implode(' ', $reasons)); } return 'Kontaktdaten gespeichert, Angebot gesendet'; } }