travelTo(CarbonImmutable::parse('2026-10-22 10:00')); $this->seed(PropertySeeder::class); Mail::fake(); $portal = Channel::factory()->for(Property::sole())->create(['name' => 'FeWo-direkt', 'booking_model' => 'portal_booking', 'process_overrides' => ['booking' => ['payments' => 'portal']]]); $this->booking = Booking::factory()->for(Property::sole())->create(['status' => BookingStatus::Completed, 'intake' => 'booking', 'import_channel_id' => $portal->id, 'origin_channel_id' => $portal->id, 'arrival' => '2026-10-10', 'departure' => '2026-10-17', 'total' => 97951, 'completed_at' => now()]); app(RecordPortalAmounts::class)->handle($this->booking->fresh(), null, [['kind' => 'payout_announced', 'amount' => 89469]], [], 'FeWo-direkt'); } public function test_a_reason_alone_does_not_settle_an_open_payout(): void { $this->expectException(ReservationException::class); CaseClosure::settle($this->booking->fresh(), 'Portal hat ausgezahlt', 'Lars'); } public function test_an_open_claim_stays_traceable_and_the_case_stays_commercially_open(): void { CaseClosure::settle($this->booking->fresh(), 'Auszahlung fehlt, beim Portal nachgefragt', 'Lars', CaseClosure::CLAIM_OPEN); $this->assertNull($this->booking->fresh()->settled_at); $this->assertTrue(BookingTask::query()->where('booking_id', $this->booking->id)->where('kind', BookingTaskKind::OpenClaim)->where('status', BookingTaskStatus::Open)->exists()); } public function test_a_written_off_claim_settles_with_its_clarification_on_record(): void { CaseClosure::settle($this->booking->fresh(), 'Kulanz, Betrag ausgebucht', 'Lars', 'written_off'); $booking = $this->booking->fresh(); $this->assertNotNull($booking->settled_at); $this->assertSame('Forderung ausgebucht: Kulanz, Betrag ausgebucht', $booking->settled_note); } public function test_the_received_payout_settles_by_itself(): void { app(RecordPayment::class)->handle($this->booking->fresh(), 89469, CarbonImmutable::today(), kind: PaymentKind::PortalPayout, source: 'FeWo-direkt'); $this->assertNotNull($this->booking->fresh()->settled_at); } }