Files
fewo-stommer/app/Process/ActivityDetails.php
LarsandClaude Sonnet 5.5 8442d0a3d8 V2.1: Kanalfähigkeiten, Ausführungsvarianten, Dokumentenentkopplung, Portalbestätigung
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>
2026-11-05 07:54:11 +01:00

105 lines
4.6 KiB
PHP
Raw Permalink 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\Enums\FactSource;
use App\Models\Booking;
use App\Models\BookingEvent;
use App\Models\CaseFact;
use Illuminate\Support\Collection;
/**
* What lies behind one step of the case's progress list: the history entries that belong to it and – for the guest's
* details – every detail with its source, time, evidence and certainty (v0.11, S5), so the landlord can see where a
* value came from and correct it.
*/
final class ActivityDetails
{
/** History types per step (the step's own key or its prefix). */
private const EVENT_TYPES = [
'intake' => ['created', 'intake', 'profile', 'hold', 'mode'],
'contact' => ['facts', 'fact', 'guest', 'data_request', 'mail_in'],
'data_request' => ['data_request', 'mail_in', 'facts', 'fact'],
'information' => ['information', 'mail', 'hold'],
'wish' => ['wish'],
'wish_check' => ['wish', 'status'],
'offer' => ['offer', 'hold', 'mail', 'status'],
'acceptance' => ['offer', 'status'],
'binding' => ['status', 'portal_signal'],
'price' => ['price', 'amount'],
'documents' => ['document', 'mail'],
'booking_notice' => ['booking_notice', 'mail'],
'portal_confirmation' => ['portal_confirmation', 'evidence', 'task', 'mail'],
'arrival_info' => ['document', 'mail'],
'review' => ['mail'],
'payment' => ['payment', 'amount'],
'deposit' => ['payment'],
'balance' => ['payment'],
'payout' => ['payment', 'amount'],
'change_proposed' => ['change'],
'arrival_details' => ['task', 'services'],
'stay' => ['task', 'services', 'status'],
'closure' => ['task', 'status', 'settled'],
'settlement' => ['settled'],
'task_' => ['task'],
];
public static function activity(Booking $booking, string $key): ?Activity
{
return collect(CaseActivities::for($booking))->first(fn (Activity $activity): bool => $activity->key === $key);
}
/**
* @return Collection<int, BookingEvent>
*/
public static function events(Booking $booking, string $key): Collection
{
$types = self::EVENT_TYPES[$key] ?? (str_starts_with($key, 'task_') ? self::EVENT_TYPES['task_'] : []);
return $types === [] ? collect() : $booking->events()->whereIn('type', $types)->reorder()->latest('occurred_at')->latest('id')->limit(50)->get();
}
public static function showsFacts(string $key): bool
{
return in_array($key, ['contact', 'data_request', 'intake'], true);
}
/**
* Every detail of the guest and the stay with its current value and where it came from (latest decisive fact).
*
* @return list<array{field: string, label: string, value: ?string, source: ?string, actor: ?string, at: ?string, evidence: ?string, confidence: ?float, open: list<string>}>
*/
public static function facts(Booking $booking): array
{
$facts = CaseFact::query()->where('booking_id', $booking->id)->orderBy('id')->get()->groupBy('field');
$rows = [];
foreach ([...CaseRequirements::FIELDS, ...CaseRequirements::OPTIONAL_FIELDS] as $field => $label) {
$value = CaseRequirements::value($booking, $field);
/** @var Collection<int, CaseFact> $history */
$history = $facts->get($field, collect());
$decisive = $history->reverse()->first(fn (CaseFact $fact): bool => in_array($fact->outcome, [CaseFact::APPLIED, CaseFact::CONFIRMED], true));
$open = $history->filter(fn (CaseFact $fact): bool => in_array($fact->outcome, [CaseFact::CONFLICT, CaseFact::CHANGE_REQUEST], true) && $fact->created_at->greaterThanOrEqualTo($decisive?->created_at ?? $fact->created_at))
->map(fn (CaseFact $fact): string => '„'.$fact->value.'“ laut '.$fact->source->getLabel().' – '.$fact->outcomeLabel())->values()->all();
if (blank($value) && $history->isEmpty()) {
continue;
}
$rows[] = [
'field' => $field,
'label' => $label,
'value' => filled($value) ? (string) $value : null,
'source' => $decisive?->source instanceof FactSource ? $decisive->source->getLabel() : (filled($value) ? 'vor der Herkunftsaufzeichnung erfasst' : null),
'actor' => $decisive?->actor,
'at' => $decisive?->created_at?->format('d.m.Y, H:i'),
'evidence' => $decisive?->evidence,
'confidence' => $decisive?->confidence,
'open' => $open,
];
}
return $rows;
}
}