From 7e4e208d18748cc295dc2cfcb3e220834c2bfc33 Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 3 Nov 2026 18:03:36 +0100 Subject: [PATCH] =?UTF-8?q?Vorgang:=20Schritte=20im=20Ablauf=20anklickbar?= =?UTF-8?q?=20=E2=80=93=20was=20geschah,=20Herkunft=20der=20Angaben,=20kor?= =?UTF-8?q?rigieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ein Klick auf einen Schritt im „Ablauf“ öffnet seine Einzelheiten: die Verlaufseinträge dieses Schritts und bei den Gastangaben jede Angabe mit Wert, Herkunft (Webseite, Link, E-Mail, KI, Sie), Zeitpunkt, Belegstelle, Sicherheit und offenen Abweichungen. - „Angaben korrigieren“ öffnet den Eintragsdialog: Ihre Eingabe gilt, der vorherige Wert bleibt im Nachweis; „Diesen Schritt ausführen“ führt direkt zur Aktion des Schritts. Co-Authored-By: Claude Opus 5.5 --- .../Resources/Bookings/Pages/ViewBooking.php | 34 ++++++ .../Bookings/Schemas/BookingInfolist.php | 5 +- app/Process/ActivityDetails.php | 102 ++++++++++++++++++ .../views/filament/activity-details.blade.php | 52 +++++++++ tests/Feature/CaseFactIntakeTest.php | 28 +++++ 5 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 app/Process/ActivityDetails.php create mode 100644 resources/views/filament/activity-details.blade.php diff --git a/app/Filament/Resources/Bookings/Pages/ViewBooking.php b/app/Filament/Resources/Bookings/Pages/ViewBooking.php index 8cc8232..6a51020 100644 --- a/app/Filament/Resources/Bookings/Pages/ViewBooking.php +++ b/app/Filament/Resources/Bookings/Pages/ViewBooking.php @@ -15,6 +15,7 @@ use App\Actions\SetBookingStatus; use App\Documents\OfferTerms; use App\Documents\RentalContract; +use App\Enums\ActivityState; use App\Enums\AdminMode; use App\Enums\AmountKind; use App\Enums\BookingStatus; @@ -43,6 +44,8 @@ use App\Models\User; use App\Pricing\PrivateStayPrice; use App\Pricing\QuoteException; +use App\Process\Activity; +use App\Process\ActivityDetails; use App\Process\CaseActivities; use App\Process\CaseAutomation; use App\Process\CaseLog; @@ -354,6 +357,37 @@ private function openFactConflicts(): string return $notes === [] ? '' : ' Abweichende Angaben des Gastes – bitte den richtigen Wert eintragen: '.implode(' · ', $notes); } + /** + * What lies behind one step of the progress list (clicked in "Ablauf"): its history entries and – for the guest's + * details – each detail with source, time, evidence and certainty, with the way to correct it or to do the step. + */ + public function activityDetailsAction(): Action + { + return Action::make('activityDetails') + ->modalHeading(fn (array $arguments): string => ActivityDetails::activity($this->record, (string) ($arguments['key'] ?? ''))?->label ?? 'Schritt') + ->modalWidth('4xl') + ->modalSubmitAction(false) + ->modalCancelActionLabel('Schließen') + ->modalContent(function (array $arguments): \Illuminate\Contracts\View\View { + $key = (string) ($arguments['key'] ?? ''); + $activity = ActivityDetails::activity($this->record, $key); + + return view('filament.activity-details', [ + 'activity' => $activity ?? new Activity($key, 'Schritt', ActivityState::NotApplicable), + 'events' => ActivityDetails::events($this->record, $key), + 'facts' => ActivityDetails::showsFacts($key) ? ActivityDetails::facts($this->record->loadMissing('guest')) : null, + ]); + }) + ->extraModalFooterActions(fn (array $arguments): array => array_values(array_filter([ + ActivityDetails::showsFacts((string) ($arguments['key'] ?? '')) && $this->record->internal_kind !== InternalKind::Block + ? Action::make('correctFacts')->label('Angaben korrigieren')->color('primary')->action(fn () => $this->replaceMountedAction('provideContact')) + : null, + ($step = ActivityDetails::activity($this->record, (string) ($arguments['key'] ?? ''))?->action) !== null && $step !== 'provideContact' + ? Action::make('doStep')->label('Diesen Schritt ausführen')->action(fn () => $this->replaceMountedAction($step)) + : null, + ]))); + } + /** * v0.11 data request: send the prepared question (or ask now although the case is set to asking by hand). */ diff --git a/app/Filament/Resources/Bookings/Schemas/BookingInfolist.php b/app/Filament/Resources/Bookings/Schemas/BookingInfolist.php index 6fdb51f..0d254d5 100644 --- a/app/Filament/Resources/Bookings/Schemas/BookingInfolist.php +++ b/app/Filament/Resources/Bookings/Schemas/BookingInfolist.php @@ -50,7 +50,7 @@ public static function configure(Schema $schema): Schema ->columnSpan(2) ->schema([ Section::make('Ablauf') - ->description('Was erledigt ist, was wartet und was noch kommt.') + ->description('Was erledigt ist, was wartet und was noch kommt. Ein Klick auf einen Schritt zeigt, was dort geschah und woher die Angaben stammen.') ->schema([TextEntry::make('activities')->hiddenLabel()->state(fn (Booking $record): HtmlString => self::activities($record))->html()]), Section::make('Preis und Zahlungen') ->schema([ @@ -217,7 +217,8 @@ private static function activities(Booking $booking): HtmlString $color = $colors[$activity->state->getColor()]; $strong = $activity->state->needsAction() ? 'font-weight:700' : ''; - return '
  • ' + // A click opens what lies behind the step (ViewBooking::activityDetailsAction). + return '
  • ' .''.$activity->state->icon().'' .''.e($activity->label) .($activity->detail ? ' · '.e($activity->detail).'' : '') diff --git a/app/Process/ActivityDetails.php b/app/Process/ActivityDetails.php new file mode 100644 index 0000000..d237c48 --- /dev/null +++ b/app/Process/ActivityDetails.php @@ -0,0 +1,102 @@ + ['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'], + '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 + */ + 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}> + */ + 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 $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; + } +} diff --git a/resources/views/filament/activity-details.blade.php b/resources/views/filament/activity-details.blade.php new file mode 100644 index 0000000..f5ff626 --- /dev/null +++ b/resources/views/filament/activity-details.blade.php @@ -0,0 +1,52 @@ +
    +
    + {{ $activity->state->getLabel() }}@if ($activity->detail) · {{ $activity->detail }}@endif +
    + + @if ($facts !== null) +
    +
    Angaben und ihre Herkunft
    + @if ($facts === []) +

    Noch keine Angaben.

    + @else + + + + + + + + @foreach ($facts as $row) + + + + + + @endforeach + +
    AngabeWertHerkunft
    {{ $row['label'] }}{{ $row['value'] ?? '–' }} + {{ $row['source'] ?? '–' }}@if ($row['at']) · {{ $row['at'] }}@endif + @if ($row['confidence'] !== null) · Sicherheit {{ number_format($row['confidence'] * 100, 0) }} %@endif + @if ($row['evidence'])
    Beleg: „{{ \Illuminate\Support\Str::limit($row['evidence'], 160) }}“
    @endif + @foreach ($row['open'] as $open)
    Offen: {{ $open }}
    @endforeach +
    +

    Stimmt etwas nicht, korrigieren Sie es mit „Angaben korrigieren“. Ihre Eingabe gilt, der vorherige Wert bleibt im Nachweis erhalten.

    + @endif +
    + @endif + +
    +
    Was dazu geschah
    + @if ($events->isEmpty()) +

    Keine Einträge zu diesem Schritt. Der vollständige Verlauf steht im Bereich „Verlauf“.

    + @else +
      + @foreach ($events as $event) +
    • {{ $event->occurred_at->format('d.m.Y H:i') }} · {{ $event->summary }}@if ($event->actor) ({{ $event->actor }})@endif + @if ($event->reason)
      Grund: {{ $event->reason }}
      @endif +
    • + @endforeach +
    + @endif +
    +
    diff --git a/tests/Feature/CaseFactIntakeTest.php b/tests/Feature/CaseFactIntakeTest.php index 27b2463..5ecd5bb 100644 --- a/tests/Feature/CaseFactIntakeTest.php +++ b/tests/Feature/CaseFactIntakeTest.php @@ -5,6 +5,7 @@ use App\Actions\ContributeCaseFacts; use App\Actions\CreateReservation; use App\Actions\DecideBookingWish; +use App\Actions\ProvideGuestContact; use App\Actions\SendInformation; use App\Actions\SendOffer; use App\Actions\SubmitBookingWish; @@ -15,23 +16,28 @@ use App\Enums\DocumentKind; use App\Enums\FactSource; use App\Exceptions\ReservationException; +use App\Filament\Resources\Bookings\Pages\ViewBooking; use App\Models\Booking; use App\Models\BookingTask; use App\Models\CaseFact; use App\Models\Channel; use App\Models\Guest; use App\Models\Property; +use App\Models\User; use App\Pricing\StayRequest; +use App\Process\ActivityDetails; use App\Process\CaseRequirements; use App\Support\Content; use App\Support\Settings; use Carbon\CarbonImmutable; use Database\Seeders\PropertySeeder; use Database\Seeders\SiteSeeder; +use Filament\Actions\Testing\TestAction; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; +use Livewire\Livewire; use Tests\TestCase; /** @@ -206,6 +212,28 @@ public function test_completing_the_address_continues_an_automatic_case(): void $this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status); } + /** A step of the progress list shows where each detail came from and lets the landlord correct it. */ + public function test_the_progress_list_shows_the_source_of_each_detail_and_the_landlord_corrects_it(): void + { + $this->actingAs(User::factory()->create()); + $booking = $this->request(); + app(ContributeCaseFacts::class)->handle($booking, ['guest.street' => 'Lindenallee 12'], FactSource::Extraction, ['reference' => 'message:1', 'evidence' => ['guest.street' => 'unsere Anschrift: Lindenallee 12'], 'confidence' => ['guest.street' => 0.9]]); + + Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) + ->assertSeeHtml('mountAction('activityDetails', { key: 'contact' })') + ->mountAction(TestAction::make('activityDetails')->arguments(['key' => 'contact'])) + ->assertActionMounted('activityDetails') + ->assertMountedActionModalSee(['Angaben und ihre Herkunft', 'Lindenallee 12', 'aus einer Nachricht erkannt (KI)', 'Sicherheit 90 %', 'unsere Anschrift: Lindenallee 12', 'Anfrageformular der Webseite']); + + Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) + ->callAction(TestAction::make('provideContact')->arguments([]), ['guest' => ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Lindenallee 21'], 'process' => ProvideGuestContact::MANUAL, 'guest_confirmed' => false]); + + $this->assertSame('Lindenallee 21', $booking->guest->fresh()->street); + $row = collect(ActivityDetails::facts($booking->fresh()))->firstWhere('field', 'guest.street'); + $this->assertSame(['Lindenallee 21', 'von Ihnen eingetragen'], [$row['value'], $row['source']]); + $this->assertSame('Lindenallee 12', CaseFact::query()->where('field', 'guest.street')->where('source', FactSource::Landlord)->sole()->previous_value, 'the corrected value stays in the evidence'); + } + /** * @param array $address */