Files
fewo-stommer/app/Process/CaseActivities.php
T
LarsandClaude Opus 5.5 7e22e12cac U-A/U-B: Prozesskern mit Fachmodulen, versionierten Modellen, eingefrorenem Prozessplan, ProcessRunner (harte/weiche Abhängigkeiten), CasePricing, Loyalty nur im Tester
CaseActivities/CaseAutomation sind Fassaden über ProcessRunner. Verhaltensvergleich v0.11:
11 Abläufe und 198 Konstellationen gleich, beabsichtigte Abweichungen I-004/I-005 (F-001/F-002).
Volle Suite vor U-B: 785/785.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 14:49:44 +01:00

98 lines
4.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Process;
use App\Actions\EndInternalCase;
use App\Enums\BookingStatus;
use App\Enums\IntakeKind;
use App\Models\Booking;
use Carbon\CarbonImmutable;
/**
* The activities of a case derived from its process profile and its data (docs/Prozessarchitektur, P01–P05): which
* apply, which are done (by us or by the portal), what is waiting for somebody else and what the landlord has to do
* next. Nothing here is stored; the gates G1–G5 are these states, not an extra status machine.
*/
class CaseActivities
{
/** Activities that are listed on their own in the work list (they are not "the" next step of a case). */
private const LISTED_SEPARATELY = ['channel_block'];
/** Activities that are the next step whatever else is open. */
private const URGENT = ['task_portal_cancel_reported', 'task_portal_change_reported', 'task_portal_cancellation'];
/**
* The activities of the case in the order of its frozen process plan (ProcessRunner, Architektur V2).
*
* @return list<Activity>
*/
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]));
}
}