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; } }