- Buchung ist der einheitliche Vorgang: Eingangsart, Vorgangsart A1–A6, eingefrorenes Abwicklungsprofil, gespeicherter Verlauf (booking_events); Gast, Personen und Beträge dürfen unbekannt sein, Platzhalter-Gäste werden migriert und nicht mehr angelegt - Einstellungen in Ebenen: Vermieterstandard (So arbeite ich), Abweichung der Wohnung (Experte), Abweichung je Portal und Eingangsart; ersetzt booking_model als Steuergröße - Ein Weg für extern verbindliche Buchungen (TakeOverExternalBooking) statt RecordPortalBooking und "Akte anlegen"; Portalpreis als belegte Gesamtposition - Startseite "Zu erledigen", neue Vorgangsseite mit nächstem Schritt, Automatik-Schalter, "Beenden" mit Storno statt Statusumschaltung; Status von Hand nur im Expertenmodus - Migration übernimmt bisheriges Verhalten unverändert (abweichende Wohnungswerte bleiben als Abweichung), Bericht: php artisan process:settings-report Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.4 KiB
PHP
85 lines
3.4 KiB
PHP
<?php
|
||
|
||
namespace App\Actions;
|
||
|
||
use App\Enums\BookingStatus;
|
||
use App\Enums\IntakeKind;
|
||
use App\Enums\ProcessingMode;
|
||
use App\Exceptions\ReservationException;
|
||
use App\Models\Booking;
|
||
use App\Models\Guest;
|
||
use App\Process\CaseAutomation;
|
||
use Illuminate\Support\Arr;
|
||
|
||
/**
|
||
* The guest's contact data arrived (portal message, e-mail, phone) and is entered on the booking. The landlord chooses
|
||
* whether the process continues automatically – a binding portal booking gets its contract, a request gets the
|
||
* offer – or by hand (data only). An already existing e-mail confirmation of the guest can be recorded as well.
|
||
*/
|
||
class ProvideGuestContact
|
||
{
|
||
public const AUTOMATIC = 'automatic';
|
||
|
||
public const MANUAL = 'manual';
|
||
|
||
public function __construct(private ConfirmBooking $confirm, private SendOffer $offer) {}
|
||
|
||
/**
|
||
* @param array<string, ?string> $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)) {
|
||
$missing = app(CaseAutomation::class)->documentBlockers($booking);
|
||
if ($missing !== []) {
|
||
throw new ReservationException('Kontaktdaten gespeichert. Die Unterlagen können noch nicht automatisch versendet werden: '.implode(' ', $missing));
|
||
}
|
||
$this->confirm->deliver($booking);
|
||
|
||
return 'Kontaktdaten gespeichert, Vertrag gesendet';
|
||
}
|
||
|
||
if ($booking->intake === IntakeKind::Booking) {
|
||
$this->confirm->handle($booking);
|
||
|
||
return 'Kontaktdaten gespeichert, Buchung bestätigt und Vertrag gesendet';
|
||
}
|
||
|
||
$this->offer->handle($booking);
|
||
|
||
return 'Kontaktdaten gespeichert, Angebot gesendet';
|
||
}
|
||
}
|