Modellwahl über Kanalfähigkeiten mit erklärten Einschränkungen, Abgleich alter Werte, Ausführungsvarianten je Modul, getrennte Vertrags-/Buchungsinformation, Warten auf die Portalbestätigung mit Eskalation und Wiederaufnahme (Fälle C und D getestet). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
75 lines
3.0 KiB
PHP
75 lines
3.0 KiB
PHP
<?php
|
||
|
||
namespace App\Actions;
|
||
|
||
use App\Enums\BookingNoticeMode;
|
||
use App\Exceptions\ReservationException;
|
||
use App\Mail\BookingNotice;
|
||
use App\Models\Booking;
|
||
use App\Process\CaseLog;
|
||
use App\Process\ChannelCapabilities;
|
||
use App\Process\PortalConfirmation;
|
||
use Illuminate\Support\Facades\Mail;
|
||
|
||
/**
|
||
* Sends the guest of a binding booking a short booking information (V2.1, docs/Prozessarchitektur/V2.1/02 §4) – separate
|
||
* from the contract documentation, which has its own step. Once only (the history entry `booking_notice` is the record).
|
||
* Where the landlord chose „unless the portal confirmed“, it is not sent when the portal informs the guest itself (confirmed
|
||
* capability of the channel) and its booking confirmation for this case is on record; the reason is kept in the history.
|
||
*/
|
||
class SendBookingNotice
|
||
{
|
||
public const EVENT = 'booking_notice';
|
||
|
||
public static function sent(Booking $booking): bool
|
||
{
|
||
return $booking->events()->where('type', self::EVENT)->where('summary', 'not like', 'Keine eigene%')->exists();
|
||
}
|
||
|
||
/**
|
||
* Why no own notice is needed, or null when it is.
|
||
*/
|
||
public static function suppression(Booking $booking): ?string
|
||
{
|
||
if ($booking->process()->bookingNotice() !== BookingNoticeMode::AutomaticUnlessPortalConfirmed) {
|
||
return null;
|
||
}
|
||
$channel = $booking->processChannel();
|
||
if ($channel === null || app(ChannelCapabilities::class)->value($channel, ChannelCapabilities::MESSAGES_GUEST) !== true) {
|
||
return null;
|
||
}
|
||
$evidence = PortalConfirmation::evidence($booking);
|
||
|
||
return $evidence === null ? null : 'Das Portal informiert den Gast selbst und hat die Buchung bestätigt ('.$evidence['label'].').';
|
||
}
|
||
|
||
/**
|
||
* @throws ReservationException
|
||
*/
|
||
public function handle(Booking $booking, bool $automatic = false): bool
|
||
{
|
||
$booking->loadMissing(['guest', 'property']);
|
||
if (! $booking->isBinding()) {
|
||
throw ReservationException::invalidTransition($booking->status->getLabel(), 'mit einer Buchungsinformation bedacht');
|
||
}
|
||
if (self::sent($booking)) {
|
||
return true;
|
||
}
|
||
if (blank($booking->guest?->email)) {
|
||
throw new ReservationException('Vor dem Versand bitte die E-Mail-Adresse des Gastes ergänzen.');
|
||
}
|
||
if ($automatic && ($reason = self::suppression($booking)) !== null) {
|
||
if (! $booking->events()->where('type', self::EVENT)->exists()) {
|
||
CaseLog::record($booking, self::EVENT, 'Keine eigene Buchungsinformation nötig', reason: $reason, data: ['level' => 'stated_by_portal']);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingNotice($booking));
|
||
CaseLog::record($booking, self::EVENT, 'Buchungsinformation an den Gast gesendet', actor: $automatic ? CaseLog::SYSTEM.' (automatisch)' : null);
|
||
|
||
return true;
|
||
}
|
||
}
|