events()->where('type', self::EVENT)->orderBy('occurred_at')->first(); if ($landlord !== null) { return ['source' => 'landlord', 'at' => CarbonImmutable::parse($landlord->occurred_at), 'label' => 'vom Vermieter bestätigt ('.$landlord->actor.')']; } $channelId = $booking->processChannel()?->id; if ($channelId === null) { return null; } $mail = PortalEmail::query()->where('channel_id', $channelId)->where('type', PortalEmailType::Booking) ->where(fn ($query) => $query ->when(filled($booking->portal_reference), fn ($by) => $by->orWhere('reference', $booking->portal_reference)) ->orWhereHas('blockedPeriod', fn ($block) => $block->withTrashed()->where('linked_booking_id', $booking->id))) ->orderBy('received_at')->first(); return $mail === null ? null : ['source' => 'mail', 'at' => CarbonImmutable::parse($mail->received_at), 'label' => 'Bestätigungsmail des Portals vom '.CarbonImmutable::parse($mail->received_at)->format('d.m.Y, H:i').' Uhr (laut Portal)']; } /** * Until when the confirmation is awaited (counted from the case's arrival in the system). */ public static function deadline(Booking $booking): CarbonImmutable { return CarbonImmutable::parse($booking->created_at)->addHours($booking->process()->portalConfirmationWaitHours()); } public static function isOverdue(Booking $booking): bool { return self::deadline($booking)->isPast(); } /** * The landlord states that the portal confirmed (e.g. checked in the portal's own interface). Recorded once. */ public static function confirm(Booking $booking, string $by, ?string $note = null): void { if ($booking->events()->where('type', self::EVENT)->exists()) { return; } CaseLog::record($booking, self::EVENT, 'Bestätigung des Portals vom Vermieter festgehalten', reason: $note, data: ['module' => 'portal.confirmation', 'level' => 'confirmed_by_landlord'], actor: $by); } }