*/ public static function for(Booking $booking): array { return app(ProcessRunner::class)->activities($booking); } /** * What the landlord should do next on this case, or null when nothing is up to him. */ public static function next(Booking $booking): ?Activity { $activities = self::for($booking); // A report of the portal (cancellation, other dates) comes before everything else on the case. usort($activities, fn (Activity $a, Activity $b): int => (int) in_array($b->key, self::URGENT, true) <=> (int) in_array($a->key, self::URGENT, true)); foreach ($activities as $activity) { if ($activity->state->needsAction() && ! in_array($activity->key, self::LISTED_SEPARATELY, true)) { return $activity; } } return null; } /** * The state of the case in one sentence of plain words. */ public static function situation(Booking $booking): string { $today = CarbonImmutable::today(); if ($booking->isInternal()) { return implode(' · ', array_filter([ $booking->internal_kind?->getLabel() ?? 'Eigene Belegung', $booking->occasion, $booking->status === BookingStatus::Cancelled ? EndInternalCase::label($booking) : ($booking->departure <= $today ? 'beendet am '.$booking->departure->format('d.m.Y') : $booking->arrival->format('d.m.').'–'.$booking->departure->format('d.m.Y')), ])); } if ($booking->portal_cancellation_requested_at !== null && $booking->isBinding()) { return 'Gebucht über '.($booking->processChannel()?->name ?? 'ein Portal').' · Stornierung beim Portal veranlasst – bleibt gebucht, bis sie bestätigt ist'; } $channel = $booking->processChannel()?->name; $kind = $booking->intake === IntakeKind::Booking ? 'Gebucht über '.($channel ?? 'ein Portal') : ($channel ? 'Anfrage über '.$channel : ($booking->source === 'website' ? 'Anfrage über die Webseite' : 'Anfrage')); $state = match ($booking->status) { BookingStatus::Reserved => match (true) { $booking->isHoldActive() => 'Zeitraum reserviert bis '.$booking->hold_expires_at->format('d.m., H:i').' Uhr', $booking->wish_at !== null => 'Buchungswunsch liegt vor – noch nicht verbindlich, Zeitraum nicht reserviert', $booking->information_version > 0 => 'unverbindliche Auskunft gesendet, Zeitraum nicht reserviert', default => 'Zeitraum nicht reserviert', }, BookingStatus::OfferSent => $booking->isHoldActive() ? 'Angebot liegt beim Gast bis '.$booking->hold_expires_at->format('d.m., H:i').' Uhr' : 'Angebot abgelaufen', BookingStatus::Confirmed => 'fest gebucht', BookingStatus::DepositPaid => 'fest gebucht, Anzahlung erhalten', BookingStatus::Paid => 'fest gebucht, bezahlt', BookingStatus::Completed => $booking->settled_at !== null ? 'Aufenthalt und Kaufmännisches abgeschlossen' : 'Aufenthalt abgeschlossen, kaufmännisch noch offen', BookingStatus::Declined => 'ohne Buchung beendet', BookingStatus::Expired => 'Frist abgelaufen, ohne Buchung beendet', BookingStatus::Cancelled => 'storniert', }; $when = match (true) { ! $booking->isBinding() => null, $booking->departure <= $today => 'abgereist am '.$booking->departure->format('d.m.Y'), $booking->arrival <= $today => 'Gast ist vor Ort bis '.$booking->departure->format('d.m.Y'), default => 'Anreise in '.(int) $today->diffInDays($booking->arrival).' Tagen', }; return implode(' · ', array_filter([$kind, $state, $when])); } }