Dokumentenzusammenstellung und Vorlagensteuerung (Paket 3, Prozessarchitektur v0.10)
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m59s

Eine Zusammenstellung vor jedem Dokument (Angebot, Bestaetigung, Buchungsunterlagen
extern), Dokumentart je Vorgangsart, Freigaben fuer Vorlagen und Dokumentarten,
Schutz vor unvereinbarten Bedingungen bei Portalbuchungen (E-004), kein doppelter
Versand, Absicherung Hold 0 bis Paket 7, A6-Aufenthaltsbestaetigung vorbereitet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-01 19:44:52 +01:00
1 parent 64248c09fa
commit cf11c8a474
45 files changed
+2385 -144

No files matched your search

+2 -2
View File
@@ -62,7 +62,7 @@ public function test_next_step_follows_the_state_of_the_booking(): void
$this->assertStringContainsString('Angebot liegt beim Gast', CaseActivities::situation($offer));
$confirmed = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-12-01', 'departure' => '2026-12-05', 'deposit_due_on' => '2026-10-25', 'balance_due_on' => '2026-11-20', 'total' => 100000, 'deposit' => 30000]);
$this->assertSame('resendConfirmation', CaseActivities::next($confirmed)?->action);
$this->assertSame('sendDocuments', CaseActivities::next($confirmed)?->action);
$this->travelTo(CarbonImmutable::parse('2026-12-02 12:00'));
$confirmed->update(['status' => BookingStatus::Paid, 'total' => 0, 'deposit' => 0]);
@@ -77,7 +77,7 @@ public function test_portal_booking_is_recognised_without_payment_steps_and_asks
$this->assertSame(CaseType::A4, $booking->caseType());
$this->assertStringContainsString('Gebucht über FeWo-direkt', CaseActivities::situation($booking));
$this->assertSame('resendConfirmation', CaseActivities::next($booking)?->action);
$this->assertSame('sendDocuments', CaseActivities::next($booking)?->action);
$keys = array_map(fn ($activity) => $activity->key, CaseActivities::for($booking));
$this->assertContains('payment', $keys);
$this->assertNotContains('deposit', $keys);
+2 -2
View File
@@ -88,7 +88,7 @@ public function test_cost_is_calculated_from_the_rent_or_from_the_total_as_the_r
public function test_the_offer_freezes_the_rule_and_the_contract_can_show_it(): void
{
$policy = $this->policy();
$template = ContractTemplate::query()->create(['name' => 'Direkt', 'version' => 1, 'body' => '<p>Storno:</p>{{ storno_regel }}', 'cancellation_policy_id' => $policy->id]);
$template = ContractTemplate::query()->create(['released_at' => now(), 'name' => 'Direkt', 'version' => 1, 'body' => '<p>Storno:</p>{{ storno_regel }}', 'cancellation_policy_id' => $policy->id]);
$offer = app(SendOffer::class)->handle($this->booking(), ['contract_template_id' => $template->id]);
$policy->update(['tiers' => [['min_days' => 0, 'percent' => 5]]]);
@@ -168,7 +168,7 @@ private function booking(string $arrival = '2026-11-07', string $departure = '20
private function offerWith(CancellationPolicy $policy, string $arrival = '2026-11-07', string $departure = '2026-11-10', bool $confirm = false): Booking
{
$template = ContractTemplate::query()->firstOrCreate(['name' => 'T'.$policy->id, 'version' => 1], ['cancellation_policy_id' => $policy->id]);
$template = ContractTemplate::query()->firstOrCreate(['name' => 'T'.$policy->id, 'version' => 1], ['cancellation_policy_id' => $policy->id, 'released_at' => now()]);
$offer = app(SendOffer::class)->handle($this->booking($arrival, $departure), ['contract_template_id' => $template->id]);
if ($confirm) {
$offer->update(['status' => BookingStatus::Confirmed, 'hold_expires_at' => null]);
+2 -2
View File
@@ -128,8 +128,8 @@ public function test_a_property_deviation_sits_between_landlord_default_and_chan
/** 1.5 */
public function test_one_mixed_portal_handles_requests_and_bindings_differently(): void
{
$inquiryTemplate = ContractTemplate::query()->create(['name' => 'Anfrage', 'terms' => '<p>A</p>']);
$bookingTemplate = ContractTemplate::query()->create(['name' => 'Portalbuchung', 'terms' => '<p>B</p>']);
$inquiryTemplate = ContractTemplate::query()->create(['released_at' => now(), 'name' => 'Anfrage', 'terms' => '<p>A</p>']);
$bookingTemplate = ContractTemplate::query()->create(['released_at' => now(), 'name' => 'Portalbuchung', 'terms' => '<p>B</p>']);
$portal = Channel::factory()->for($this->property)->create(['booking_model' => 'mixed', 'process_overrides' => [
'inquiry' => ['contract_template_id' => $inquiryTemplate->id],
'booking' => ['contract_template_id' => $bookingTemplate->id, 'payments' => 'portal'],
+5 -5
View File
@@ -53,7 +53,7 @@ public function test_conditions_decide_which_annexes_fit_a_booking(): void
$withLinen = $this->annex('Wäsche', ContractAnnex::EXTRA, $linen->id);
$viaPortal = $this->annex('Portal', ContractAnnex::CHANNEL, $portal->id);
$manual = $this->annex('Key', ContractAnnex::MANUAL);
$template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'annex_ids' => [$always->id, $withLinen->id, $viaPortal->id, $manual->id]]);
$template = ContractTemplate::query()->create(['released_at' => now(), 'name' => 'T', 'version' => 1, 'annex_ids' => [$always->id, $withLinen->id, $viaPortal->id, $manual->id]]);
$plain = $this->booking();
$this->assertSame(['WLAN'], $template->annexesFor($plain)->pluck('name')->all());
@@ -68,7 +68,7 @@ public function test_conditions_decide_which_annexes_fit_a_booking(): void
public function test_the_offer_freezes_the_matching_annexes_and_shows_them_everywhere(): void
{
$annex = $this->annex('WLAN', ContractAnnex::ALWAYS, null, 'Anlage WLAN', '<p>WLAN für {{ mieter }}</p>');
$template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'body' => '<p>Vertrag</p>', 'annex_ids' => [$annex->id]]);
$template = ContractTemplate::query()->create(['released_at' => now(), 'name' => 'T', 'version' => 1, 'body' => '<p>Vertrag</p>', 'annex_ids' => [$annex->id]]);
$offer = app(SendOffer::class)->handle($this->booking(), ['contract_template_id' => $template->id]);
@@ -86,7 +86,7 @@ public function test_an_explicit_selection_in_the_offer_replaces_the_automatic_o
{
$auto = $this->annex('WLAN', ContractAnnex::ALWAYS);
$manual = $this->annex('Key', ContractAnnex::MANUAL);
$template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'annex_ids' => [$auto->id]]);
$template = ContractTemplate::query()->create(['released_at' => now(), 'name' => 'T', 'version' => 1, 'annex_ids' => [$auto->id]]);
$offer = app(SendOffer::class)->handle($this->booking(), ['contract_template_id' => $template->id, 'annex_ids' => [$manual->id]]);
$this->assertSame(['Key'], array_column($offer->offer_terms['annexes'], 'name'));
@@ -98,7 +98,7 @@ public function test_an_explicit_selection_in_the_offer_replaces_the_automatic_o
public function test_used_annex_versions_are_locked_and_new_versions_can_be_made(): void
{
$annex = $this->annex('WLAN', ContractAnnex::ALWAYS);
$template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'annex_ids' => [$annex->id]]);
$template = ContractTemplate::query()->create(['released_at' => now(), 'name' => 'T', 'version' => 1, 'annex_ids' => [$annex->id]]);
$this->assertTrue(ContractAnnexResource::canEdit($annex));
app(SendOffer::class)->handle($this->booking(), ['contract_template_id' => $template->id]);
@@ -113,7 +113,7 @@ public function test_recording_extra_services_in_the_booking_changes_the_presele
{
$linen = Extra::query()->create(['property_id' => $this->property->id, 'name' => 'Wäschepaket', 'price' => 0, 'pricing' => 'per_item', 'is_active' => true]);
$annex = $this->annex('Wäsche', ContractAnnex::EXTRA, $linen->id);
$template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'annex_ids' => [$annex->id]]);
$template = ContractTemplate::query()->create(['released_at' => now(), 'name' => 'T', 'version' => 1, 'annex_ids' => [$annex->id]]);
$this->property->update(['contract_template_id' => $template->id]);
$booking = $this->booking();
$this->actingAs(User::factory()->create());
+7 -3
View File
@@ -8,6 +8,7 @@
use App\Documents\OfferTerms;
use App\Enums\BookingStatus;
use App\Mail\BookingConfirmed;
use App\Mail\BookingDocumentation;
use App\Models\Booking;
use App\Models\Channel;
use App\Models\ContractTemplate;
@@ -81,7 +82,8 @@ public function test_offer_with_a_document_template_freezes_body_and_property_fa
public function test_template_without_a_body_keeps_the_text_blocks(): void
{
$template = $this->template('Bausteine', null, null, null);
$template->update(['texts' => ['terms' => '<p>NUR BAUSTEIN</p>']]);
$template->fill(['texts' => ['terms' => '<p>NUR BAUSTEIN</p>']])->applyStatements(released: true, portalTerms: false, actor: 'Test');
$template->save();
$offer = $this->offer(['contract_template_id' => $template->id]);
@@ -106,7 +108,9 @@ public function test_portal_reservation_uses_the_reservation_template_and_a_conf
$this->assertSame('FeWo-direkt', $booking->offer_terms['template']['name']);
$this->assertStringContainsString('PORTAL-VERTRAG', OfferTerms::document($booking)['body']);
Storage::disk('local')->assertExists($booking->contract_path);
Mail::assertSent(BookingConfirmed::class, fn (BookingConfirmed $mail): bool => ! str_contains($mail->render(), 'überweisen'));
// Binding on the portal: booking documentation without payment instructions (payments run via the portal).
Mail::assertSent(BookingDocumentation::class, fn (BookingDocumentation $mail): bool => ! str_contains($mail->render(), 'überweisen') && str_contains($mail->render(), 'Die Zahlung läuft über'));
Mail::assertNotSent(BookingConfirmed::class);
$inquiryPortal = Channel::factory()->for($this->property)->create(['booking_model' => 'inquiry', 'process_overrides' => ['inquiry' => ['contract_template_id' => $inquiry->id], 'booking' => ['contract_template_id' => $reservation->id]]]);
$this->assertSame($inquiry->id, OfferTerms::templateFor($this->booking(['import_channel_id' => $inquiryPortal->id, 'source' => 'portal', 'arrival' => '2026-12-01', 'departure' => '2026-12-03']))->id);
@@ -129,7 +133,7 @@ public function test_installer_creates_the_fewo_direkt_template_once_and_sets_pr
private function template(string $name, ?string $body, ?string $annexTitle, ?string $annexBody): ContractTemplate
{
return ContractTemplate::query()->create(['name' => $name, 'version' => 1, 'body' => $body, 'annex_title' => $annexTitle, 'annex_body' => $annexBody]);
return ContractTemplate::query()->create(['released_at' => now(), 'name' => $name, 'version' => 1, 'body' => $body, 'annex_title' => $annexTitle, 'annex_body' => $annexBody]);
}
/**
+1 -1
View File
@@ -120,7 +120,7 @@ public function test_final_contract_is_a_document_of_record_that_is_never_rewrit
*/
private function template(string $name, array $texts): ContractTemplate
{
return ContractTemplate::query()->create(['name' => $name, 'version' => 1, 'texts' => $texts]);
return ContractTemplate::query()->create(['released_at' => now(), 'name' => $name, 'version' => 1, 'texts' => $texts]);
}
/**
+375
View File
@@ -0,0 +1,375 @@
<?php
namespace Tests\Feature;
use App\Actions\AutoOffer;
use App\Actions\ConfirmBooking;
use App\Actions\CreateReservation;
use App\Actions\SendBookingDocuments;
use App\Actions\SendOffer;
use App\Actions\TakeOverExternalBooking;
use App\Documents\DocumentComposer;
use App\Documents\DocumentReleases;
use App\Documents\RentalContract;
use App\Enums\AdminMode;
use App\Enums\BookingStatus;
use App\Enums\DocumentKind;
use App\Enums\IntakeKind;
use App\Exceptions\ReservationException;
use App\Filament\Pages\HandlingSettings;
use App\Filament\Resources\Bookings\Pages\ViewBooking;
use App\Mail\BookingConfirmed;
use App\Mail\BookingDocumentation;
use App\Mail\OfferMade;
use App\Models\Booking;
use App\Models\CancellationPolicy;
use App\Models\Channel;
use App\Models\ContractTemplate;
use App\Models\Property;
use App\Models\User;
use App\Pricing\StayRequest;
use App\Process\CaseActivities;
use App\Support\Money;
use App\Support\Settings;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
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;
/**
* Package 3 of UMSETZUNGSPLAN_v0.10: one composition before every document, the right document per case type without
* choosing a template, no unagreed obligations for bookings already binding on a portal (E-004), no double sending and
* no change to documents already sent.
*/
class DocumentCompositionTest extends TestCase
{
use RefreshDatabase;
private Property $property;
private Channel $portal;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed([PropertySeeder::class, SiteSeeder::class]);
$this->property = Property::sole();
$this->portal = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt', 'booking_model' => 'portal_booking', 'process_overrides' => ['booking' => ['payments' => 'portal']]]);
Mail::fake();
Storage::fake('local');
Http::fake(['*' => Http::response('', 500)]);
$this->withoutVite();
$this->actingAs(User::factory()->create(['name' => 'Ingrid', 'admin_mode' => AdminMode::Simple]));
}
/** 3.1 */
public function test_the_offer_composition_shows_everything_and_an_adjustment_updates_it(): void
{
$booking = $this->request();
$composition = app(DocumentComposer::class)->compose($booking, DocumentKind::Offer);
$this->assertSame('Gesa Gast', $composition->recipientName());
$this->assertSame('gesa@example.org', $composition->recipientEmail());
$this->assertSame('aus Ihren Preisen berechnet', $composition->priceSource);
$this->assertTrue($composition->kind->hasAcceptanceLink());
$this->assertTrue($composition->canSendAutomatically());
$total = $composition->draft->total;
// The same picture the landlord sees in the dialog; an adjustment recalculates it.
$adjusted = app(DocumentComposer::class)->compose($booking, DocumentKind::Offer, ['price_adjustment' => -5000, 'price_adjustment_label' => 'Stammgast']);
$html = view('filament.document-composition', ['composition' => $adjusted, 'expert' => false, 'mailPreview' => '', 'documentPreview' => '', 'pdfUrl' => '#'])->render();
foreach (['Angebot mit Annahmelink', 'Gesa Gast · gesa@example.org', 'Herkunft: aus Ihren Preisen berechnet', 'Stornoregel', 'Vorlage', 'Anlagen', 'Stammgast', Money::format($total - 5000)] as $text) {
$this->assertStringContainsString(e($text), $html);
}
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callAction('sendOffer', ['price_adjustment' => '-50', 'price_adjustment_label' => 'Stammgast'])
->assertHasNoFormErrors()
->assertNotified('Angebot gesendet');
$this->assertSame($total - 5000, $booking->fresh()->total);
$this->assertSame('offer', $booking->events()->where('type', 'document')->sole()->data['kind']);
}
/** 3.2 */
public function test_each_case_gets_its_document_without_choosing_a_template(): void
{
$inquiryTemplate = $this->template('Direktanfrage', '<p>ANGEBOTSVERTRAG {{ mieter }}</p>');
$portalTemplate = $this->template('FeWo-direkt', '<p>PORTALUNTERLAGEN {{ mieter }}</p>', portalTerms: true);
Settings::tenant()->update(['process_defaults' => ['contract_template_id' => $inquiryTemplate->id]]);
$this->portal->update(['process_overrides' => ['booking' => ['payments' => 'portal', 'contract_template_id' => $portalTemplate->id]]]);
DocumentReleases::set(DocumentKind::ExternalRecord, true, 'Ingrid');
$request = app(SendOffer::class)->handle($this->request());
$this->assertSame('Direktanfrage', $request->offer_terms['template']['name']);
Mail::assertSent(OfferMade::class, fn (OfferMade $mail): bool => str_contains($mail->offerUrl, '/angebot/'));
$portalBooking = $this->portalBooking();
$composition = app(SendBookingDocuments::class)->compose($portalBooking);
$this->assertSame(DocumentKind::ExternalRecord, $composition->kind);
$this->assertFalse($composition->kind->hasAcceptanceLink());
$this->assertStringContainsString('eingestellt für FeWo-direkt', $composition->templateSource);
$this->assertTrue($composition->canSendAutomatically());
$this->assertTrue(app(SendBookingDocuments::class)->handle($portalBooking));
$portalBooking->refresh();
$this->assertSame('FeWo-direkt', $portalBooking->offer_terms['template']['name']);
$this->assertStringEndsWith('Buchungsunterlagen-'.$portalBooking->reference.'.pdf', $portalBooking->contract_path);
Mail::assertSent(BookingDocumentation::class, function (BookingDocumentation $mail): bool {
$html = $mail->render();
return ! str_contains($html, '/angebot/') && str_contains($html, 'Die Zahlung läuft über FeWo-direkt') && ! str_contains($html, 'überweisen');
});
Mail::assertNotSent(BookingConfirmed::class);
[$view, $data] = app(RentalContract::class)->view($portalBooking, DocumentKind::ExternalRecord);
$this->assertStringContainsString('Buchungsunterlagen', view($view, $data)->render());
}
/** 3.3 */
public function test_an_unconfirmed_fee_in_a_portal_template_needs_a_conscious_confirmation(): void
{
$policy = CancellationPolicy::query()->create(['name' => 'Direktbuchung Standard', 'base' => CancellationPolicy::BASE_RENT, 'tiers' => [['min_days' => 30, 'percent' => 0], ['min_days' => 0, 'percent' => 100]], 'replacement_fee' => 3500]);
$template = $this->template('FeWo-direkt Direktbuchung', '<p>Mietvertrag mit {{ mieter }}. Endreinigung 60,00 € extra.</p>');
$template->fill(['cancellation_policy_id' => $policy->id])->applyStatements(released: true, portalTerms: false, actor: 'Ingrid');
$template->save();
$this->portal->update(['process_overrides' => ['booking' => ['payments' => 'portal', 'contract_template_id' => $template->id]]]);
DocumentReleases::set(DocumentKind::ExternalRecord, true, 'Ingrid');
$booking = $this->portalBooking();
$points = app(SendBookingDocuments::class)->compose($booking)->toConfirm();
$this->assertStringContainsString('nicht als Wiedergabe der Bedingungen von FeWo-direkt bestätigt', implode(' ', $points));
$this->assertStringContainsString('Ersatzmieter-Gebühr '.Money::format(3500), implode(' ', $points));
$this->assertStringContainsString('60,00 € (im Text)', implode(' ', $points));
// Automatic: nothing goes out, the case says what to check.
$booking->update(['processing_mode' => 'automatic']);
$this->assertNotSame([], app(SendBookingDocuments::class)->automatically($booking->fresh()));
Mail::assertNothingSent();
$this->assertStringContainsString('vor dem Versand zu prüfen', CaseActivities::next($booking->fresh())->detail);
// By hand: refused without, sent with the explicit confirmation, which is recorded.
try {
app(SendBookingDocuments::class)->handle($booking->fresh());
$this->fail('Sending without confirmation must be refused.');
} catch (ReservationException $exception) {
$this->assertStringContainsString('ausdrücklich bestätigen', $exception->getMessage());
}
Mail::assertNothingSent();
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callAction('sendDocuments', ['acknowledged' => false])
->assertHasFormErrors(['acknowledged']);
Mail::assertNothingSent();
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callAction('sendDocuments', ['acknowledged' => true])
->assertNotified('Unterlagen gesendet');
Mail::assertSent(BookingDocumentation::class, 1);
$confirmed = $booking->events()->where('type', 'document')->where('summary', 'Hinweise vor dem Versand bestätigt')->sole();
$this->assertSame('Ingrid', $confirmed->actor);
$this->assertStringContainsString('Ersatzmieter-Gebühr', implode(' ', $confirmed->data['confirmed']));
}
public function test_without_any_template_a_portal_booking_does_not_get_our_website_terms_unchecked(): void
{
DocumentReleases::set(DocumentKind::ExternalRecord, true, 'Ingrid');
$booking = $this->portalBooking();
$this->assertStringContainsString('keine eigene Vorlage', implode(' ', app(SendBookingDocuments::class)->compose($booking)->toConfirm()));
}
public function test_documents_are_sent_once_whatever_runs_again(): void
{
$template = $this->template('FeWo-direkt', '<p>Buchung {{ mieter }}</p>', portalTerms: true);
$this->portal->update(['process_overrides' => ['booking' => ['payments' => 'portal', 'contract_template_id' => $template->id]]]);
DocumentReleases::set(DocumentKind::ExternalRecord, true, 'Ingrid');
$booking = $this->portalBooking();
$this->assertSame([], app(SendBookingDocuments::class)->automatically($booking));
$this->assertSame([], app(SendBookingDocuments::class)->automatically($booking->fresh()));
$this->assertTrue(app(SendBookingDocuments::class)->handle($booking));
Mail::assertSent(BookingDocumentation::class, 1);
}
public function test_an_offer_is_not_sent_twice_by_a_repeated_release_or_automatic_run(): void
{
$booking = $this->request();
$send = app(SendOffer::class);
$send->handle($booking, ['expected_version' => 0]);
try {
$send->handle($booking->fresh(), ['expected_version' => 0]);
$this->fail('A repeated release must not send a second offer.');
} catch (ReservationException $exception) {
$this->assertStringContainsString('schon ein Angebot gesendet', $exception->getMessage());
}
Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]);
app(AutoOffer::class)->handle($booking->fresh());
$this->assertSame(1, $booking->fresh()->offer_version);
Mail::assertSent(OfferMade::class, 1);
}
/** Hold = 0 until package 7: no binding offer by accident. */
public function test_without_reservation_an_offer_with_acceptance_link_needs_an_explicit_decision(): void
{
Settings::tenant()->update(['process_defaults' => ['pre_reservation' => false]]);
$booking = $this->request();
$this->assertNull($booking->hold_expires_at);
try {
app(SendOffer::class)->handle($booking);
$this->fail('An offer must not be made by accident when requests reserve nothing.');
} catch (ReservationException $exception) {
$this->assertStringContainsString('reservieren Anfragen den Zeitraum nicht', $exception->getMessage());
}
$this->assertSame(BookingStatus::Reserved, $booking->fresh()->status);
Mail::assertNothingSent();
Settings::tenant()->update(['process_defaults' => ['pre_reservation' => false, 'processing' => 'automatic']]);
$this->assertNotSame([], app(AutoOffer::class)->handle($booking->fresh()));
Mail::assertNothingSent();
app(SendOffer::class)->handle($booking->fresh(), ['acknowledged' => true]);
$this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status);
}
public function test_missing_contract_data_stops_the_automatic_offer(): void
{
$template = $this->template('Direkt', '<p>WLAN: {{ wohnung.wlan_passwort }}</p>');
Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic', 'contract_template_id' => $template->id]]);
Storage::fake('local');
$booking = $this->request(sendMails: true);
$this->assertSame(BookingStatus::Reserved, $booking->fresh()->status);
$this->assertStringContainsString('wohnung.wlan_passwort', implode(' ', app(AutoOffer::class)->blockers($booking->fresh())));
Mail::assertNotSent(OfferMade::class);
}
public function test_documents_already_sent_stay_as_they_were(): void
{
$template = $this->template('Direkt', '<p>ALTER TEXT {{ mieter }}</p>');
Settings::tenant()->update(['process_defaults' => ['contract_template_id' => $template->id]]);
$booking = app(SendOffer::class)->handle($this->request());
$offerHash = $booking->offer_hash;
app(ConfirmBooking::class)->handle($booking->fresh());
$booking->refresh();
$contract = $booking->contract_path;
$pdfHash = $booking->contract_pdf_sha256;
$template->fill(['body' => '<p>NEUER TEXT</p>'])->applyStatements(released: true, portalTerms: false, actor: 'Ingrid');
$template->save();
Settings::tenant()->update(['process_defaults' => ['contract_template_id' => null]]);
$composition = app(SendBookingDocuments::class)->compose($booking->fresh());
$this->assertTrue($composition->termsFrozen);
$this->assertStringContainsString('ALTER TEXT', $composition->terms['document']['body']);
$this->assertSame([], $composition->toConfirm());
app(ConfirmBooking::class)->resend($booking->fresh());
$booking->refresh();
$this->assertSame($contract, $booking->contract_path);
$this->assertSame($pdfHash, $booking->contract_pdf_sha256);
$this->assertSame($offerHash, $booking->offer_hash);
$this->assertStringContainsString('ALTER TEXT', $booking->offer_terms['document']['body']);
}
public function test_a_template_statement_lapses_when_its_text_changes(): void
{
$template = $this->template('Direkt', '<p>Text</p>', portalTerms: true);
$this->assertTrue($template->isReleased() && $template->confirmsPortalTerms());
$template->update(['body' => '<p>Geänderter Text</p>']);
$this->assertFalse($template->fresh()->isReleased());
$this->assertFalse($template->fresh()->confirmsPortalTerms());
$this->assertFalse($template->newVersion()->isReleased());
}
public function test_the_landlord_releases_the_booking_documentation_on_the_settings_page(): void
{
$this->actingAs(User::factory()->create(['name' => 'Ingrid', 'admin_mode' => AdminMode::Expert]));
$this->assertFalse(DocumentReleases::isReleased(DocumentKind::ExternalRecord));
Livewire::test(HandlingSettings::class)
->assertSee('Buchungsunterlagen (beim Portal gebucht) – freigegeben')
->fillForm(['document_releases' => ['external_record' => true]])
->call('save')
->assertHasNoFormErrors();
$this->assertTrue(DocumentReleases::isReleased(DocumentKind::ExternalRecord));
$this->assertSame('Ingrid', DocumentReleases::decision(DocumentKind::ExternalRecord)['by']);
}
/** A6 is prepared: a private stay gets a confirmation that is no rental contract, and it cannot be sent yet. */
public function test_a_private_stay_confirmation_is_prepared_without_a_rental_contract(): void
{
$booking = $this->request();
$booking->forceFill(['intake' => IntakeKind::Internal])->save();
$composition = app(DocumentComposer::class)->compose($booking->fresh());
$this->assertSame(DocumentKind::StayConfirmation, $composition->kind);
$this->assertFalse($composition->kind->containsContract());
$this->assertStringContainsString('späteren Ausbauschritt', implode(' ', $composition->blockers()));
[$view, $data] = app(RentalContract::class)->view($booking, DocumentKind::StayConfirmation);
$html = view($view, $data)->render();
$this->assertStringContainsString('nicht um einen Mietvertrag', $html);
$this->assertStringNotContainsString('Mietbedingungen', $html);
}
public function test_the_pdf_preview_shows_the_composition_without_saving_anything(): void
{
$booking = $this->request();
$response = $this->get(route('filament.admin.document-preview', ['booking' => $booking->getRouteKey(), 'kind' => 'offer', 'changes' => base64_encode(json_encode(['price_adjustment' => -5000]))]));
$response->assertOk()->assertHeader('Content-Type', 'application/pdf');
$this->assertSame(0, $booking->fresh()->offer_version);
$this->assertNull($booking->fresh()->offer_path);
}
private function request(bool $sendMails = false): Booking
{
return app(CreateReservation::class)->handle(
$this->property->fresh(),
new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2),
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org'],
sendMails: $sendMails,
);
}
private function portalBooking(): Booking
{
return app(TakeOverExternalBooking::class)->handle(
$this->property,
$this->portal,
CarbonImmutable::parse('2026-12-05'),
CarbonImmutable::parse('2026-12-12'),
['portal_total' => 97951, 'portal_reference' => 'HA-77', 'guest' => ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.org']],
);
}
private function template(string $name, string $body, bool $portalTerms = false): ContractTemplate
{
return ContractTemplate::query()->create([
'name' => $name,
'version' => 1,
'body' => $body,
'released_at' => now(),
'portal_terms_confirmed_at' => $portalTerms ? now() : null,
]);
}
}
+1
View File
@@ -232,6 +232,7 @@ public function test_the_landlord_sets_defaults_on_one_page_and_a_portal_deviate
Livewire::test(HandlingSettings::class)
->fillForm(['processing' => 'automatic', 'hold_hours' => 24, 'pre_reservation' => null])
->call('save')
->assertHasNoFormErrors()
->assertNotified('Gespeichert');
$this->assertSame(['processing' => 'automatic', 'hold_hours' => 24], Settings::tenant()->fresh()->process_defaults);
+38 -3
View File
@@ -8,11 +8,13 @@
use App\Actions\SetBookingStatus;
use App\Actions\TakeOverExternalBooking;
use App\Availability\AvailabilityChecker;
use App\Documents\DocumentReleases;
use App\Enums\AdminMode;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\CaseType;
use App\Enums\ChannelBookingModel;
use App\Enums\DocumentKind;
use App\Enums\OccupationKind;
use App\Enums\ProcessingMode;
use App\Exceptions\ReservationException;
@@ -22,10 +24,12 @@
use App\Filament\Resources\Bookings\Schemas\BookingForm;
use App\Filament\Resources\PortalOccupations\Pages\ViewPortalOccupation;
use App\Mail\BookingConfirmed;
use App\Mail\BookingDocumentation;
use App\Models\BlockedPeriod;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Channel;
use App\Models\ContractTemplate;
use App\Models\Property;
use App\Models\User;
use App\Process\CaseActivities;
@@ -83,21 +87,41 @@ public function test_a_binding_portal_booking_is_taken_over_without_offer_accept
public function test_entering_the_contact_data_can_send_the_documents_automatically(): void
{
$this->releaseDocumentation();
$booking = $this->takeOver(total: 50000);
$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('Kontaktdaten gespeichert, Unterlagen 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);
Mail::assertSent(BookingDocumentation::class, 1);
Mail::assertNotSent(BookingConfirmed::class);
}
public function test_without_released_documentation_the_automatic_run_stops_and_says_what_to_check(): void
{
$booking = $this->takeOver(total: 50000);
try {
app(ProvideGuestContact::class)->handle($booking, ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'gast@example.test'], ProvideGuestContact::AUTOMATIC);
$this->fail('The documents must not be sent automatically.');
} catch (ReservationException $exception) {
$this->assertStringContainsString('Arbeitsfassung', $exception->getMessage());
$this->assertStringContainsString('keine eigene Vorlage', $exception->getMessage());
}
$this->assertNull($booking->fresh()->contract_path);
Mail::assertNothingSent();
$this->assertSame('sendDocuments', CaseActivities::next($booking->fresh())?->action);
}
public function test_automatic_documents_wait_for_the_portal_price(): void
{
$this->releaseDocumentation();
$booking = $this->takeOver();
$this->expectException(ReservationException::class);
@@ -112,7 +136,7 @@ public function test_entering_the_contact_data_by_hand_sends_nothing_and_the_doc
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('resendConfirmation', CaseActivities::next($booking->fresh())?->action);
$this->assertSame('sendDocuments', CaseActivities::next($booking->fresh())?->action);
Mail::assertNothingSent();
}
@@ -317,4 +341,15 @@ private function takeOver(?int $total = null, ?string $reference = null, string
['portal_total' => $total, 'portal_reference' => $reference, 'guest' => $guest],
);
}
/**
* The landlord released the booking documentation and set a template for bookings via the portal that only
* reproduces the portal's terms.
*/
private function releaseDocumentation(): void
{
DocumentReleases::set(DocumentKind::ExternalRecord, true, 'Test');
$template = ContractTemplate::query()->create(['name' => 'FeWo-direkt', 'version' => 1, 'body' => '<p>Buchung von {{ mieter }}</p>', 'released_at' => now(), 'portal_terms_confirmed_at' => now()]);
$this->portal->update(['process_overrides' => ['booking' => ['contract_template_id' => $template->id]]]);
}
}