Vorgangskern und geführte Vorgangsbearbeitung (Pakete 1 und 2, Prozessarchitektur v0.10)

- Buchung ist der einheitliche Vorgang: Eingangsart, Vorgangsart A1–A6, eingefrorenes
  Abwicklungsprofil, gespeicherter Verlauf (booking_events); Gast, Personen und Beträge
  dürfen unbekannt sein, Platzhalter-Gäste werden migriert und nicht mehr angelegt
- Einstellungen in Ebenen: Vermieterstandard (So arbeite ich), Abweichung der Wohnung
  (Experte), Abweichung je Portal und Eingangsart; ersetzt booking_model als Steuergröße
- Ein Weg für extern verbindliche Buchungen (TakeOverExternalBooking) statt
  RecordPortalBooking und "Akte anlegen"; Portalpreis als belegte Gesamtposition
- Startseite "Zu erledigen", neue Vorgangsseite mit nächstem Schritt, Automatik-Schalter,
  "Beenden" mit Storno statt Statusumschaltung; Status von Hand nur im Expertenmodus
- Migration übernimmt bisheriges Verhalten unverändert (abweichende Wohnungswerte bleiben
  als Abweichung), Bericht: php artisan process:settings-report

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-01 16:25:46 +01:00
1 parent 9005c12164
commit 3a728c3255
78 files changed
+4296 -1180

No files matched your search

+107 -72
View File
@@ -4,26 +4,31 @@
use App\Actions\OpenPortalFile;
use App\Actions\ProvideGuestContact;
use App\Actions\RecordPortalBooking;
use App\Actions\ResolveChannelOccupation;
use App\Actions\SetBookingStatus;
use App\Actions\TakeOverExternalBooking;
use App\Availability\AvailabilityChecker;
use App\Enums\AdminMode;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\CaseType;
use App\Enums\ChannelBookingModel;
use App\Enums\OccupationKind;
use App\Enums\ProcessingMode;
use App\Exceptions\ReservationException;
use App\Filament\Resources\Bookings\Pages\CreateBooking;
use App\Filament\Resources\Bookings\Pages\ListBookings;
use App\Filament\Resources\Bookings\Pages\ViewBooking;
use App\Filament\Resources\Bookings\Schemas\BookingForm;
use App\Filament\Resources\PortalOccupations\Pages\ViewPortalOccupation;
use App\Mail\BookingConfirmed;
use App\Models\BlockedPeriod;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Channel;
use App\Models\Property;
use App\Models\User;
use App\Pricing\StayRequest;
use App\Support\BookingProgress;
use App\Process\CaseActivities;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
@@ -35,8 +40,9 @@
use Tests\TestCase;
/**
* Portal bookings entered without contact data, the contract process that follows (automatic or by hand),
* manual status changes, the archive and the clarification of portal occupations.
* Bookings already binding on a portal (A3–A5): one way to take them over – entered by hand or found in the portal
* calendar –, the documents that follow (automatic or released by hand), manual status corrections, ending, the
* archive and the clarification of portal occupations.
*/
class PortalBookingTest extends TestCase
{
@@ -59,97 +65,107 @@ protected function setUp(): void
$this->withoutVite();
}
public function test_a_portal_booking_without_contact_data_occupies_the_dates_but_creates_no_contract(): void
public function test_a_binding_portal_booking_is_taken_over_without_offer_acceptance_or_contract(): void
{
$booking = $this->record(RecordPortalBooking::CONFIRM, total: 123400, reference: 'HA-123');
$booking = $this->takeOver(total: 123400, reference: 'HA-123', guest: ['first_name' => 'Erika', 'last_name' => 'Muster']);
$this->assertSame(BookingStatus::Confirmed, $booking->status);
$this->assertSame(CaseType::A3, $booking->case_type);
$this->assertSame($this->portal->id, $booking->origin_channel_id);
$this->assertSame('HA-123', $booking->portal_reference);
$this->assertSame(123400, $booking->total);
$this->assertSame(0, $booking->offer_version);
$this->assertSame('', $booking->guest->email);
$this->assertNull($booking->contract_path);
$this->assertSame(BookingProgress::PORTAL_BOOKING, BookingProgress::kind($booking));
$this->assertSame('Kontaktdaten fehlen', BookingProgress::next($booking)['title']);
$this->assertSame('provideContact', CaseActivities::next($booking)?->action);
Mail::assertNothingSent();
}
public function test_an_immediate_contract_needs_the_email_address(): void
public function test_entering_the_contact_data_can_send_the_documents_automatically(): void
{
$this->expectException(ReservationException::class);
$booking = $this->takeOver(total: 50000);
$this->record(RecordPortalBooking::CONTRACT);
}
public function test_entering_the_contact_data_can_start_the_contract_automatically(): void
{
$booking = $this->record(RecordPortalBooking::CONFIRM);
$message = app(ProvideGuestContact::class)->handle($booking, ['email' => 'Gast@Example.test', 'street' => 'Hauptstr. 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn'], ProvideGuestContact::AUTOMATIC, guestConfirmed: true);
$message = app(ProvideGuestContact::class)->handle($booking, ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'Gast@Example.test', 'street' => 'Hauptstr. 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn'], ProvideGuestContact::AUTOMATIC, guestConfirmed: true);
$booking->refresh();
$this->assertSame('Kontaktdaten gespeichert, Vertrag gesendet', $message);
$this->assertSame('gast@example.test', $booking->guest->email);
$this->assertNotNull($booking->contract_path);
$this->assertNotNull($booking->guest_confirmed_at);
$this->assertSame(ProcessingMode::Automatic, $booking->processing_mode);
Mail::assertSent(BookingConfirmed::class, 1);
}
public function test_entering_the_contact_data_by_hand_sends_nothing(): void
public function test_automatic_documents_wait_for_the_portal_price(): void
{
$booking = $this->record(RecordPortalBooking::CONFIRM);
$booking = $this->takeOver();
app(ProvideGuestContact::class)->handle($booking, ['email' => 'gast@example.test'], ProvideGuestContact::MANUAL);
$this->expectException(ReservationException::class);
$this->expectExceptionMessage('Gesamtpreis');
app(ProvideGuestContact::class)->handle($booking, ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'gast@example.test'], ProvideGuestContact::AUTOMATIC);
}
public function test_entering_the_contact_data_by_hand_sends_nothing_and_the_documents_become_the_next_step(): void
{
$booking = $this->takeOver(total: 50000);
app(ProvideGuestContact::class)->handle($booking, ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'gast@example.test'], ProvideGuestContact::MANUAL);
$this->assertNull($booking->fresh()->contract_path);
$this->assertSame('Vertrag senden', BookingProgress::next($booking->fresh())['title']);
$this->assertSame('resendConfirmation', CaseActivities::next($booking->fresh())?->action);
Mail::assertNothingSent();
}
public function test_a_recorded_request_stays_open_and_automatic_continuation_needs_an_email(): void
{
$booking = $this->record(RecordPortalBooking::RECORD);
$this->assertSame(BookingStatus::Reserved, $booking->status);
$this->expectException(ReservationException::class);
app(ProvideGuestContact::class)->handle($booking, ['phone' => '0123'], ProvideGuestContact::AUTOMATIC);
}
public function test_the_booking_form_records_a_portal_booking_and_the_page_offers_the_contact_actions(): void
public function test_the_new_dialog_takes_over_a_portal_booking_and_the_page_leads_to_the_contact_data(): void
{
$this->actingAs(User::factory()->create());
Livewire::test(CreateBooking::class)
->fillForm([
'property_id' => $this->property->id, 'guests' => 2, 'arrival' => '2026-11-07', 'departure' => '2026-11-10',
'channel_id' => $this->portal->id, 'portal_reference' => 'HA-9', 'portal_process' => RecordPortalBooking::CONFIRM,
'first_name' => 'Erika', 'last_name' => 'Muster',
'kind' => BookingForm::EXTERNAL,
'property_id' => $this->property->id, 'arrival' => '2026-11-07', 'departure' => '2026-11-10',
'channel_id' => $this->portal->id, 'portal_reference' => 'HA-9',
])
->call('create')
->assertHasNoFormErrors();
$booking = Booking::query()->sole();
$this->assertSame('HA-9', $booking->portal_reference);
$this->assertNull($booking->guest_id);
$this->assertNull($booking->guests);
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->assertActionVisible('requestContact')
->callAction('requestContact')
->assertSee('Name und Kontaktdaten des Gastes eintragen')
->assertSee('Gesamtpreis laut Portal eintragen')
->callAction(TestAction::make('requestContact')->arguments([]))
->assertNotified('Als angefragt vermerkt')
->callAction('provideContact', ['guest' => ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.test'], 'process' => ProvideGuestContact::MANUAL, 'guest_confirmed' => false])
->assertNotified('Kontaktdaten gespeichert');
->callAction(TestAction::make('provideContact')->arguments([]), ['guest' => ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.test'], 'process' => ProvideGuestContact::MANUAL, 'guest_confirmed' => false])
->assertNotified('Kontaktdaten gespeichert')
->callAction(TestAction::make('portalPrice')->arguments([]), ['portal_total' => '979.51', 'guests' => 2])
->assertNotified('Preis gespeichert');
$this->assertNotNull($booking->fresh()->contact_requested_at);
$this->assertSame('erika@example.test', $booking->fresh()->guest->email);
$booking->refresh();
$this->assertNotNull($booking->contact_requested_at);
$this->assertSame('erika@example.test', $booking->guest->email);
$this->assertSame(97951, $booking->total);
$this->assertSame(2, $booking->guests);
}
public function test_status_can_be_changed_by_hand_with_a_reason_and_the_calendar_is_checked(): void
public function test_status_can_be_corrected_by_hand_but_a_binding_booking_never_falls_back_to_a_request(): void
{
$booking = $this->record(RecordPortalBooking::CONFIRM);
$booking = $this->takeOver();
$set = app(SetBookingStatus::class);
$set->handle($booking, BookingStatus::Paid, 'Zahlung über das Portal erhalten', 'Test');
$this->assertSame(BookingStatus::Paid, $booking->fresh()->status);
$this->assertStringContainsString('Zahlung über das Portal erhalten', $booking->fresh()->internal_notes);
$this->assertSame('Von Hand gesetzt: Zahlung über das Portal erhalten', $booking->events()->where('type', 'status')->reorder()->latest('id')->value('reason'));
try {
$set->handle($booking->fresh(), BookingStatus::Reserved, 'zurück');
$this->fail('A binding booking must not become a request again.');
} catch (ReservationException) {
$this->assertSame(BookingStatus::Paid, $booking->fresh()->status);
}
$booking->update(['status' => BookingStatus::Expired]);
$other = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-11-08', 'departure' => '2026-11-09']);
@@ -168,12 +184,15 @@ public function test_status_can_be_changed_by_hand_with_a_reason_and_the_calenda
$set->handle($booking->fresh(), BookingStatus::Cancelled, 'nicht erlaubt');
}
public function test_the_manual_status_action_is_not_offered_for_the_own_website_process(): void
public function test_the_manual_status_action_is_an_expert_function_and_not_offered_for_the_website_process(): void
{
$own = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['source' => 'website', 'arrival' => '2026-11-07', 'departure' => '2026-11-10']);
$portal = $this->record(RecordPortalBooking::CONFIRM, arrival: '2026-12-01', departure: '2026-12-04');
$this->actingAs(User::factory()->create());
$portal = $this->takeOver(arrival: '2026-12-01', departure: '2026-12-04');
$this->actingAs(User::factory()->create(['admin_mode' => AdminMode::Simple]));
Livewire::test(ViewBooking::class, ['record' => $portal->getRouteKey()])->assertDontSee('Status von Hand ändern');
$this->actingAs(User::factory()->create(['admin_mode' => AdminMode::Expert]));
Livewire::test(ViewBooking::class, ['record' => $own->getRouteKey()])->assertDontSee('Status von Hand ändern');
Livewire::test(ViewBooking::class, ['record' => $portal->getRouteKey()])->assertSee('Status von Hand ändern')
->callAction(TestAction::make('setStatus')->arguments([]), ['status' => BookingStatus::Paid->value, 'reason' => 'Portal zahlt aus'])
@@ -181,6 +200,21 @@ public function test_the_manual_status_action_is_not_offered_for_the_own_website
$this->assertSame(BookingStatus::Paid, $portal->fresh()->status);
}
public function test_ending_a_portal_booking_cancels_it_and_asks_to_cancel_on_the_portal_too(): void
{
$booking = $this->takeOver(total: 50000);
$this->actingAs(User::factory()->create());
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callAction('end', ['initiated_by' => 'guest', 'reason' => 'Gast storniert im Portal', 'costs_task' => true])
->assertNotified('Buchung storniert');
$this->assertSame(BookingStatus::Cancelled, $booking->fresh()->status);
$this->assertTrue(BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::PortalCancellation)->exists());
$this->assertSame('Gast storniert im Portal', $booking->events()->where('type', 'status')->reorder()->latest('id')->value('reason'));
$this->assertSame('Stornierung im Portal veranlassen bzw. prüfen', CaseActivities::next($booking->fresh())?->label);
}
public function test_archived_bookings_leave_the_list_but_keep_everything(): void
{
$past = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Completed, 'arrival' => '2026-09-01', 'departure' => '2026-09-05']);
@@ -195,7 +229,7 @@ public function test_archived_bookings_leave_the_list_but_keep_everything(): voi
public function test_the_list_filters_by_channel_period_and_missing_contact_data(): void
{
$portalBooking = $this->record(RecordPortalBooking::CONFIRM, arrival: '2026-12-01', departure: '2026-12-04');
$portalBooking = $this->takeOver(arrival: '2026-12-01', departure: '2026-12-04');
$own = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-11-07', 'departure' => '2026-11-10']);
$this->actingAs(User::factory()->create());
@@ -218,9 +252,9 @@ public function test_an_independent_occupation_with_a_booking_channel_is_no_long
$this->assertSame(OccupationKind::Reservation, $block->fresh()->occupation_kind);
}
public function test_a_portal_reservation_from_the_calendar_gets_a_booking_file_and_stays_occupied(): void
public function test_a_portal_reservation_from_the_calendar_becomes_one_case_and_stays_occupied(): void
{
$block = BlockedPeriod::factory()->for($this->property)->create(['channel_id' => $this->portal->id, 'source' => 'channel', 'external_uid' => 'u2', 'starts_on' => '2026-12-10', 'ends_on' => '2026-12-14', 'occupation_kind' => OccupationKind::Reservation]);
$block = BlockedPeriod::factory()->for($this->property)->create(['channel_id' => $this->portal->id, 'source' => 'channel', 'external_uid' => 'u2', 'starts_on' => '2026-12-10', 'ends_on' => '2026-12-14', 'occupation_kind' => OccupationKind::Reservation, 'ical_interpretation' => ['fields' => ['guest_first_name' => 'Mia']]]);
$checker = app(AvailabilityChecker::class);
$this->assertFalse($checker->isAvailable($this->property, CarbonImmutable::parse('2026-12-10'), CarbonImmutable::parse('2026-12-14')));
@@ -228,8 +262,10 @@ public function test_a_portal_reservation_from_the_calendar_gets_a_booking_file_
$this->assertSame(BookingStatus::Confirmed, $booking->status);
$this->assertSame($this->portal->id, $booking->origin_channel_id);
$this->assertSame(BookingProgress::PORTAL_BOOKING, BookingProgress::kind($booking));
$this->assertSame('', $booking->guest->email);
$this->assertSame(CaseType::A3, $booking->case_type);
$this->assertNull($booking->guest_id);
$this->assertNull($booking->total);
$this->assertStringContainsString('Name laut Kalender: Mia', $booking->internal_notes);
$this->assertTrue($block->fresh()->is_representation);
$this->assertSame($booking->id, $block->fresh()->linked_booking_id);
$this->assertFalse($checker->isAvailable($this->property, CarbonImmutable::parse('2026-12-10'), CarbonImmutable::parse('2026-12-14')));
@@ -237,7 +273,7 @@ public function test_a_portal_reservation_from_the_calendar_gets_a_booking_file_
$this->assertSame(1, Booking::query()->count());
}
public function test_a_blocked_period_gets_no_booking_file(): void
public function test_a_blocked_period_does_not_become_a_booking(): void
{
$block = BlockedPeriod::factory()->for($this->property)->create(['channel_id' => $this->portal->id, 'source' => 'channel', 'external_uid' => 'u3', 'starts_on' => '2026-12-10', 'ends_on' => '2026-12-14', 'occupation_kind' => OccupationKind::Block]);
@@ -245,7 +281,7 @@ public function test_a_blocked_period_gets_no_booking_file(): void
app(OpenPortalFile::class)->handle($block);
}
public function test_the_occupation_page_offers_the_file_and_leads_to_the_booking(): void
public function test_the_occupation_page_takes_the_reservation_over_and_leads_to_the_case(): void
{
$block = BlockedPeriod::factory()->for($this->property)->create(['channel_id' => $this->portal->id, 'source' => 'channel', 'external_uid' => 'u4', 'starts_on' => '2026-12-10', 'ends_on' => '2026-12-14', 'occupation_kind' => OccupationKind::Reservation]);
$this->actingAs(User::factory()->create());
@@ -254,32 +290,31 @@ public function test_the_occupation_page_offers_the_file_and_leads_to_the_bookin
$booking = Booking::query()->sole();
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->assertSee('Ablauf: Meilensteine und Aktivitäten')
->assertSee('Bisheriger Verlauf')
->assertSee('Standardprozess')
->assertSee('Kontaktdaten eintragen');
->assertSee('Als Nächstes')
->assertSee('Ablauf')
->assertSee('Verlauf')
->assertSee('Gebucht über FeWo-direkt')
->assertSee('Gast noch nicht bekannt');
}
public function test_every_milestone_lists_its_activities_and_the_history_records_what_happened(): void
public function test_the_history_records_what_happened_with_its_actor(): void
{
$booking = $this->record(RecordPortalBooking::CONFIRM);
$booking = $this->takeOver();
$steps = collect(BookingProgress::steps($booking))->keyBy('label');
$this->assertFalse($steps['Gast & Kontaktdaten']['activities'][1]['done']);
$this->assertSame('Kontaktdaten eintragen', $steps['Gast & Kontaktdaten']['activities'][1]['action']);
$this->assertSame(['Vorgang angelegt (FeWo-direkt)', 'Buchung verbindlich bestätigt'], array_column(BookingProgress::history($booking), 'label'));
$this->assertSame(['Vorgang angelegt: Portalbuchung, Abwicklung bei uns (FeWo-direkt)', 'Beim Portal verbindlich gebucht – übernommen'], $booking->events()->pluck('summary')->all());
}
private function record(string $process, ?int $total = null, ?string $reference = null, string $arrival = '2026-11-07', string $departure = '2026-11-10'): Booking
/**
* @param array<string, ?string>|null $guest
*/
private function takeOver(?int $total = null, ?string $reference = null, string $arrival = '2026-11-07', string $departure = '2026-11-10', ?array $guest = null): Booking
{
return app(RecordPortalBooking::class)->handle(
return app(TakeOverExternalBooking::class)->handle(
$this->property,
$this->portal,
new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2),
['first_name' => 'Erika', 'last_name' => 'Muster'],
$process,
$reference,
$total,
CarbonImmutable::parse($arrival),
CarbonImmutable::parse($departure),
['portal_total' => $total, 'portal_reference' => $reference, 'guest' => $guest],
);
}
}