diff --git a/app/Filament/Resources/Bookings/Schemas/BookingInfolist.php b/app/Filament/Resources/Bookings/Schemas/BookingInfolist.php index 0d254d5..415afc3 100644 --- a/app/Filament/Resources/Bookings/Schemas/BookingInfolist.php +++ b/app/Filament/Resources/Bookings/Schemas/BookingInfolist.php @@ -16,6 +16,8 @@ use App\Pricing\CaseMoney; use App\Process\CaseActivities; use App\Process\CaseAutomation; +use App\Process\ProcessCatalogue; +use App\Process\ProcessPlan; use App\Process\ProcessProfile; use App\Support\Money; use Carbon\CarbonImmutable; @@ -121,6 +123,7 @@ public static function configure(Schema $schema): Schema ->schema([ TextEntry::make('status')->label('Status')->badge(), TextEntry::make('case_type')->label('Vorgangsart')->state(fn (Booking $record): string => strtoupper($record->caseType()->value).' – '.$record->caseType()->getLabel()), + TextEntry::make('templates')->label('Funktionsschablonen')->state(fn (Booking $record): ?string => self::templates($record))->placeholder('– (fester Ablauf)'), TextEntry::make('intake')->label('Eingangsart')->state(fn (Booking $record): string => $record->intake?->getLabel() ?? '–'), TextEntry::make('sources')->label('Quellen und Kalenderdarstellungen')->state(fn (Booking $record): HtmlString => self::sources($record))->html()->columnSpanFull(), TextEntry::make('profile')->label('Abwicklungsprofil (eingefroren)')->state(fn (Booking $record): HtmlString => self::profile($record))->html()->columnSpanFull(), @@ -238,6 +241,17 @@ private static function history(Booking $booking): HtmlString return new HtmlString($rows === '' ? 'Noch keine Einträge.' : '
{{ $plan['label'] }} ({{ $plan['model'] }} Version {{ $plan['version'] }}{{ $plan['variant'] !== 'standard' ? ', Variante '.$plan['variant'] : '' }}) · Vorgangsart {{ $plan['case_type'] }}
+ @if (($plan['templates'] ?? []) !== []) +Fehler: {{ $event['error'] }}
@endif @isset($event['situation']){{ $event['status'] }} · {{ $event['situation'] }}
@endisset + @if (($event['independent'] ?? []) !== []) +Läuft unabhängig weiter, obwohl anderes wartet: {{ implode(', ', $event['independent']) }}
+ @endif + @if (($event['waiting'] ?? []) !== []) +Wartet / Nachweis fehlt: {{ implode(', ', $event['waiting']) }}
+ @endifFür diese Eingangsart gibt es keine Ablaufmodelle.
@endifPasst gerade nicht ({{ $restriction->kind }}): {{ $restriction->reason }}@if ($restriction->alternative)
Zulässig ist stattdessen: {{ $restriction->alternative }}.@endif @if ($restriction->change)
{{ $restriction->change }}.@endif
{{ $hint }}
@endforeach +Echte Bedingungen
', 'stay.cancellation' => 'Echtes Storno
']); + config(['mail.default' => 'array']); + Mail::swap(new MailManager($this->app)); + Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'test@example.org']); + Http::preventStrayRequests(); + $this->actingAs(User::factory()->create()); + } + + public function test_the_page_shows_the_business_decisions_first_and_keeps_the_steps_reachable(): void + { + $ds = $this->channel('Destination Solution', []); + + Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()]) + ->call('chooseModel', 'external.booking') + ->assertSee('Geschäftsentscheidungen') + ->assertSee('Wer zieht das Geld des Gastes ein?') + ->assertSee('Eigenes Inkasso') + ->assertSee('Portal-Inkasso') + ->assertSee('Eigene Vertragsdokumentation') + ->assertSee('Externe Vertragsunterlagen') + ->assertSee('Mehrstufige Mahnungen', escape: false) + ->assertSee('Einzelschritte einstellen') + ->assertSee('Zahlungen des Gastes'); + } + + public function test_an_archetype_moves_to_the_base_process_with_the_same_combination_and_saves(): void + { + $fewo = $this->channel('FeWo-direkt', [], 'mixed'); + $page = Livewire::test(ChannelProcess::class, ['record' => $fewo->getRouteKey()])->set('intake', 'booking'); + + $page->assertSee('Auf Schablonen umstellen')->call('applyPreset', 'a4.portal_booking'); + $this->assertSame(['external.booking', ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']], [$page->get('drafts')['booking']['model'], $page->get('drafts')['booking']['templates']]); + $this->assertSame([], $page->instance()->problems()); + + $page->call('save')->assertNotified('Ablauf gespeichert'); + $this->assertSame('external.booking', $fewo->fresh()->process_overrides['booking']['model']); + $this->assertEquals(['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own'], $fewo->fresh()->process_overrides['booking']['templates']); + + $booking = $this->takeOver($fewo->fresh(), 'FD-1'); + $this->assertEquals(['collection' => 'collection.portal@1', 'contract_documents' => 'contract_docs.own@1'], ProcessPlan::of($booking)->templates); + $this->assertSame('A4', strtoupper($booking->case_type->value)); + } + + public function test_a_template_the_portal_cannot_support_cannot_be_chosen_and_says_why(): void + { + $fewo = $this->channel('FeWo-direkt', [], 'mixed'); + $page = Livewire::test(ChannelProcess::class, ['record' => $fewo->getRouteKey()])->set('intake', 'booking')->call('applyPreset', 'a4.portal_booking'); + + $page->call('chooseTemplate', 'collection', 'collection.own'); + $this->assertSame('collection.portal', $page->get('drafts')['booking']['templates']['collection'], 'refused: FeWo-direkt collects the money'); + $page->assertSee('Passt gerade nicht')->assertSee('Zieht das Portal das Geld des Gastes ein?'); + + // The landlord corrects the capability first: now the template fits. + $page->set('capabilityDraft.collects_payment', '0')->call('chooseTemplate', 'collection', 'collection.own'); + $this->assertSame('collection.own', $page->get('drafts')['booking']['templates']['collection']); + } + + public function test_unconfirmed_capabilities_are_flagged_and_never_taken_as_proven(): void + { + $generic = $this->channel('Irgendein Portal', [], 'portal_booking'); + $options = app(ChannelProcessConfiguration::class)->templateOptions($generic, app(ProcessCatalogue::class)->model('external.booking')); + + $this->assertTrue($options['collection']['collection.own']['admissible'], 'unknown blocks nothing'); + $this->assertSame(['collects_payment'], $options['collection']['collection.own']['unconfirmed']); + $this->assertNotSame([], $options['contract_documents']['contract_docs.external']['hints']); + + $fewo = $this->channel('FeWo-direkt Profil', [], 'mixed'); + $suggested = app(ChannelProcessConfiguration::class)->templateOptions($fewo, app(ProcessCatalogue::class)->model('external.booking')); + $this->assertContains('collects_payment', $suggested['collection']['collection.portal']['unconfirmed'], 'a suggestion of the channel profile is not a confirmation'); + $this->assertStringContainsString('nicht als bestätigt', implode(' ', $suggested['collection']['collection.portal']['hints'])); + } + + /** The A4 → A3 regression of the archetypes, now as a switch of the collection template */ + public function test_switching_the_collection_template_shows_every_consequence_and_needs_the_confirmation(): void + { + $ds = $this->channel('Destination Solution', ['booking' => ['payments' => 'portal', 'guest_messages' => 'portal', 'contract_delivery' => 'manual', 'steps' => ['review.request' => ['on' => false]]]]); + $ds->update(['settings' => [...(array) $ds->settings, 'capabilities' => ['messages_guest' => ['value' => false, 'at' => now()->toIso8601String(), 'by' => 'Lars']]]]); + $page = Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()])->set('intake', 'booking'); + + $page->set('capabilityDraft.collects_payment', '0')->call('chooseModel', 'external.booking')->call('chooseTemplate', 'collection', 'collection.own'); + $conflicts = collect($page->instance()->conflicts())->map(fn (array $conflict): string => $conflict['setting']->value)->all(); + $this->assertEqualsCanonicalizing(['payments', 'guest_messages'], $conflicts, 'the stale collection and the stale portal communication are conflicts, not silent changes'); + $page->assertSee('Bisherige Einstellungen widersprechen'); + + $page->call('save')->assertNotified('Nicht gespeichert'); + $this->assertSame('portal', $ds->fresh()->process_overrides['booking']['payments'], 'nothing changed without the confirmation'); + + $page->set('acknowledge', true)->call('save')->assertNotified('Ablauf gespeichert'); + $saved = $ds->fresh()->process_overrides['booking']; + $this->assertSame('external.booking', $saved['model']); + $this->assertArrayNotHasKey('payments', $saved); + $this->assertArrayNotHasKey('guest_messages', $saved); + $this->assertSame('manual', $saved['contract_delivery'], 'parameters of the kept modules survive'); + $this->assertSame(['review.request' => ['on' => false]], $saved['steps'], 'so does a switched-off optional step'); + $this->assertStringContainsString('Bisher eingestellt', $ds->fresh()->settings['process_history'][0]['removed_settings'][0]); + $this->assertEquals(['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own'], $saved['templates']); + } + + public function test_the_impact_of_a_template_change_names_modules_responsibility_and_open_ends(): void + { + $fewo = $this->channel('FeWo-direkt', ['booking' => ['steps' => []]], 'mixed'); + app(ConfigureChannelProcess::class)->handle($fewo, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']]); + + $impact = app(ConfigurationImpact::class)->ofTemplates($fewo->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.external']]); + + $impact = collect($impact)->keyBy('area'); + $this->assertEqualsCanonicalizing(['Finanzabwicklung (Inkasso)', 'Vertragsdokumentation'], $impact->keys()->all()); + $finance = $impact['Finanzabwicklung (Inkasso)']; + $documents = $impact['Vertragsdokumentation']; + $this->assertSame(['Portal-Inkasso', 'Eigenes Inkasso'], [$finance['from'], $finance['to']]); + $this->assertSame(['Auszahlung des Portals'], $finance['removed']); + $this->assertSame(['Zahlungen des Gastes'], $finance['kept']); + $this->assertSame(['from' => 'Das Portal', 'to' => 'Wir'], $finance['responsibility']); + $this->assertContains('Mehrstufige Mahnungen (rechtliche Ausgestaltung offen)', $finance['extensions']); + $this->assertSame(['from' => 'Wir', 'to' => 'Das Portal'], $documents['responsibility']); + $this->assertSame([], app(ConfigurationImpact::class)->ofTemplates($fewo->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']]), 'no change, no impact'); + } + + public function test_the_modules_of_a_template_stay_individually_configurable_and_the_inheritance_holds(): void + { + Settings::tenant()->update(['process_defaults' => ['contract_delivery' => 'manual']]); + $ds = $this->channel('Destination Solution', []); + app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own']]); + + $page = Livewire::test(ChannelProcess::class, ['record' => $ds->fresh()->getRouteKey()])->set('intake', 'booking'); + $documents = collect($page->instance()->steps())->firstWhere('module', 'documents.send'); + $this->assertSame('Eigene Vertragsdokumentation', $documents['template']); + $this->assertContains('contract_delivery', array_column($documents['parameters'], 'key'), 'the module of the template has its own parameters'); + $this->assertNotNull($documents['mode_setting'], 'and its own mode'); + $this->assertSame('manual', app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking)->value(ProcessSetting::ContractDelivery)); + $this->assertSame(ProcessProfile::TENANT, app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking)->source(ProcessSetting::ContractDelivery)); + + $page->set('drafts.booking.settings.contract_delivery', 'automatic')->set('drafts.booking.settings.processing', 'approval')->call('save')->assertNotified('Ablauf gespeichert'); + $profile = app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking); + $this->assertSame(['automatic', ProcessProfile::CHANNEL], [$profile->value(ProcessSetting::ContractDelivery), $profile->source(ProcessSetting::ContractDelivery)]); + $this->assertSame(ProcessProfile::TEMPLATE, $profile->source(ProcessSetting::Payments)); + } + + public function test_a_template_does_not_override_a_parameter_set_by_hand_and_a_contradicting_responsibility_is_refused(): void + { + $ds = $this->channel('Destination Solution', []); + $configuration = app(ChannelProcessConfiguration::class); + + $problems = $configuration->problems($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'portal']]); + $this->assertNotSame([], $problems, 'a responsibility set by hand may not contradict the template'); + $this->assertStringContainsString('widerspricht der Schablone', implode(' ', $problems)); + $this->assertSame([], $configuration->problems($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'landlord', 'contract_delivery' => 'manual']])); + + $this->expectException(ValidationException::class); + app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'portal']]); + } + + public function test_changing_the_templates_leaves_running_cases_and_their_plans_untouched(): void + { + $ds = $this->channel('Destination Solution', []); + app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own']]); + $running = $this->takeOver($ds->fresh(), 'DS-ALT'); + $frozen = $running->fresh()->profile; + + app(ConfigureChannelProcess::class)->handle($ds->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.external'], 'capabilities' => ['collects_payment' => '1', 'provides_contract_documents' => '1']]); + $new = $this->takeOver($ds->fresh(), 'DS-NEU', '2027-09-10'); + + $this->assertSame($frozen, $running->fresh()->profile, 'the running case keeps profile and plan'); + $this->assertSame('collection.own@1', ProcessPlan::of($running->fresh())->templates['collection']); + $this->assertSame('collection.portal@1', ProcessPlan::of($new)->templates['collection']); + $this->assertSame(['landlord', 'portal'], [$running->fresh()->process()->payments()->value, $new->process()->payments()->value]); + } + + /** + * @param arrayEchte Bedingungen
', 'stay.cancellation' => 'Echtes Storno
']); + Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'vermieter@example.org', 'process_defaults' => ['processing' => 'automatic']]); + $this->user = User::factory()->create(); + ProcessTesterTest::template(); + $this->portal = Channel::factory()->for($this->property)->create(['name' => 'Destination Solution', 'booking_model' => 'portal_booking', 'status' => 'setup', 'is_active' => false, 'import_enabled' => false, 'settings' => ['import_url' => 'https://ds.example/a.ics', 'email_senders' => 'ds.example', 'portal_profile' => 'generic']]); + } + + /** + * @return array