Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m59s
Eine Zusammenstellung vor jedem Dokument (Angebot, Bestaetigung, Buchungsunterlagen extern), Dokumentart je Vorgangsart, Freigaben fuer Vorlagen und Dokumentarten, Schutz vor unvereinbarten Bedingungen bei Portalbuchungen (E-004), kein doppelter Versand, Absicherung Hold 0 bis Paket 7, A6-Aufenthaltsbestaetigung vorbereitet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
91 lines
3.9 KiB
PHP
91 lines
3.9 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 Illuminate\Support\Arr;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
/**
|
||
* 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 AutoOffer $autoOffer, private SendBookingDocuments $documents) {}
|
||
|
||
/**
|
||
* @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)) {
|
||
$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';
|
||
}
|
||
}
|