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

@@ -0,0 +1,80 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* The booking becomes the one "case" (Vorgang) of every business occasion (docs/Prozessarchitektur, package 1 of
* UMSETZUNGSPLAN_v0.10): unknown guest, number of guests and amounts are allowed, every case knows its intake kind,
* its case type and the process profile frozen when it came in, and its history is stored as events. Settings get
* three levels: landlord defaults (tenant), optional deviations of a property (expert area) and of a channel per
* intake kind. Purely additive – nothing existing is removed here.
*/
return new class extends Migration
{
public function up(): void
{
Schema::table('bookings', function (Blueprint $table): void {
$table->foreignId('guest_id')->nullable()->change();
$table->unsignedTinyInteger('guests')->nullable()->change();
$table->json('quote')->nullable()->change();
$table->unsignedInteger('total')->nullable()->change();
$table->unsignedInteger('deposit')->nullable()->change();
$table->date('balance_due_on')->nullable()->change();
$table->string('intake', 12)->nullable()->after('source');
$table->string('case_type', 4)->nullable()->index()->after('intake');
$table->json('profile')->nullable()->after('case_type');
$table->string('processing_mode', 12)->nullable()->after('profile');
});
Schema::table('tenants', function (Blueprint $table): void {
$table->json('process_defaults')->nullable();
});
Schema::table('properties', function (Blueprint $table): void {
$table->json('process_overrides')->nullable();
});
Schema::table('channels', function (Blueprint $table): void {
$table->json('process_overrides')->nullable();
});
Schema::create('booking_events', function (Blueprint $table): void {
$table->id();
$table->foreignId('tenant_id')->nullable()->constrained()->cascadeOnDelete();
$table->foreignId('booking_id')->constrained()->cascadeOnDelete();
$table->string('type', 30);
$table->string('summary', 500);
$table->string('actor', 120)->nullable();
$table->text('reason')->nullable();
$table->json('data')->nullable();
$table->timestamp('occurred_at');
$table->timestamps();
$table->index(['booking_id', 'occurred_at']);
});
}
public function down(): void
{
Schema::dropIfExists('booking_events');
Schema::table('channels', function (Blueprint $table): void {
$table->dropColumn('process_overrides');
});
Schema::table('properties', function (Blueprint $table): void {
$table->dropColumn('process_overrides');
});
Schema::table('tenants', function (Blueprint $table): void {
$table->dropColumn('process_defaults');
});
Schema::table('bookings', function (Blueprint $table): void {
$table->dropIndex(['case_type']);
$table->dropColumn(['intake', 'case_type', 'profile', 'processing_mode']);
});
}
};
@@ -0,0 +1,213 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
/**
* Carries the existing data over to the case core without changing behaviour:
*
* 1. Process settings of the properties (handling mode, pre-reservation, hold, arrival info) become landlord defaults
* where all properties of a landlord agree. Where they differ, nothing is unified: the landlord default stays the
* built-in default and every property keeps its own value as a deviation (expert area). Report:
* `php artisan process:settings-report`.
* 2. Channel switches (payment tasks per booking model, contract templates) become channel deviations per intake kind.
* 3. Every existing case gets intake kind, case type and a profile frozen with exactly the values the old code used
* for it (origin "migration").
* 4. The history so far is written from the timestamps, payments, mails and finished tasks.
* 5. Placeholder guests ("Gast (Portal)", no e-mail) are detached; unknown guests stay unknown.
*
* Only plain queries – no models, so later model changes cannot alter what this migration did.
*/
return new class extends Migration
{
/** Old property column => setting key. */
private const PROPERTY_SETTINGS = [
'offer_mode' => 'processing',
'pre_reservation_enabled' => 'pre_reservation',
'hold_hours' => 'hold_hours',
'arrival_info_days_before' => 'arrival_info_days_before',
];
public function up(): void
{
$this->moveSettings();
$this->moveChannelSwitches();
$this->backfillCases();
$this->backfillHistory();
$this->detachPlaceholderGuests();
}
public function down(): void
{
DB::table('booking_events')->delete();
DB::table('bookings')->update(['intake' => null, 'case_type' => null, 'profile' => null, 'processing_mode' => null]);
DB::table('channels')->update(['process_overrides' => null]);
DB::table('properties')->update(['process_overrides' => null]);
DB::table('tenants')->update(['process_defaults' => null]);
}
private function moveSettings(): void
{
foreach (DB::table('properties')->get() as $property) {
$byTenant[$property->tenant_id][] = $property;
}
foreach ($byTenant ?? [] as $tenantId => $properties) {
$defaults = [];
$overrides = [];
foreach (self::PROPERTY_SETTINGS as $column => $key) {
$values = array_map(fn (object $property): mixed => $this->settingValue($column, $property->{$column}), $properties);
if (count(array_unique($values, SORT_REGULAR)) === 1) {
$defaults[$key] = $values[0];
continue;
}
foreach ($properties as $property) {
$overrides[$property->id][$key] = $this->settingValue($column, $property->{$column});
}
}
DB::table('tenants')->where('id', $tenantId)->update(['process_defaults' => json_encode($defaults)]);
foreach ($overrides as $propertyId => $values) {
DB::table('properties')->where('id', $propertyId)->update(['process_overrides' => json_encode($values)]);
}
}
}
private function settingValue(string $column, mixed $value): string|int|bool
{
return match ($column) {
'offer_mode' => $value === 'automatic' ? 'automatic' : 'manual',
'pre_reservation_enabled' => (bool) $value,
default => (int) $value,
};
}
private function moveChannelSwitches(): void
{
foreach (DB::table('channels')->get() as $channel) {
$inquiry = [];
$booking = [];
if (! $channel->payment_tasks_inquiry) {
$inquiry['payments'] = 'portal';
}
if (! $channel->payment_tasks_reservation) {
$booking['payments'] = 'portal';
}
if ($channel->contract_template_id !== null) {
$inquiry['contract_template_id'] = (int) $channel->contract_template_id;
}
if (($channel->contract_template_reservation_id ?? $channel->contract_template_id) !== null) {
$booking['contract_template_id'] = (int) ($channel->contract_template_reservation_id ?? $channel->contract_template_id);
}
DB::table('channels')->where('id', $channel->id)->update(['process_overrides' => json_encode(array_filter(['inquiry' => $inquiry, 'booking' => $booking]))]);
}
}
private function backfillCases(): void
{
$properties = DB::table('properties')->get()->keyBy('id');
$channels = DB::table('channels')->get()->keyBy('id');
foreach (DB::table('bookings')->orderBy('id')->get() as $booking) {
$property = $properties[$booking->property_id] ?? null;
$channel = $channels[$booking->import_channel_id ?? $booking->origin_channel_id ?? 0] ?? null;
$intake = $channel === null || $channel->booking_model === 'inquiry' ? 'inquiry' : 'booking';
// Exactly what the old code did: payment tasks by the channel's booking model, documents always ours.
$payments = $channel === null || ($channel->booking_model === 'portal_booking' ? $channel->payment_tasks_reservation : $channel->payment_tasks_inquiry) ? 'landlord' : 'portal';
$caseType = $intake === 'inquiry' ? ($channel === null ? 'a1' : 'a2') : ($payments === 'portal' ? 'a4' : 'a3');
$values = [
'processing' => $property?->offer_mode === 'automatic' ? 'automatic' : 'manual',
'pre_reservation' => (bool) ($property->pre_reservation_enabled ?? true),
'hold_hours' => (int) ($property->hold_hours ?? 48),
'documents' => 'landlord',
'payments' => $payments,
'guest_messages' => 'landlord',
'arrival_info_days_before' => (int) ($property->arrival_info_days_before ?? 3),
];
DB::table('bookings')->where('id', $booking->id)->update([
'intake' => $intake,
'case_type' => $caseType,
'profile' => json_encode([
'intake' => $intake,
'case_type' => $caseType,
'values' => $values,
'sources' => array_fill_keys(array_keys($values), 'migration'),
'frozen_at' => now()->toIso8601String(),
'origin' => 'migration',
]),
]);
}
}
private function backfillHistory(): void
{
$facts = [
'created_at' => 'Vorgang angelegt',
'contact_requested_at' => 'Gast um Kontaktdaten gebeten',
'offer_sent_at' => 'Angebot gesendet',
'accepted_at' => 'Angebot vom Gast angenommen',
'guest_confirmed_at' => 'Gast hat die Buchung per E-Mail bestätigt',
'confirmed_at' => 'Buchung verbindlich',
'confirmation_sent_at' => 'Bestätigung mit Unterlagen an den Gast gesendet',
'confirmation_failed_at' => 'Versand der Bestätigung fehlgeschlagen',
'arrival_info_sent_at' => 'Anreise-Informationen gesendet',
'review_requested_at' => 'Gast um eine Bewertung gebeten',
'cancelled_at' => 'Storniert',
'archived_at' => 'Archiviert',
];
$now = now();
foreach (DB::table('bookings')->orderBy('id')->get() as $booking) {
$rows = [];
$add = function (mixed $at, string $type, string $summary) use (&$rows, $booking, $now): void {
if ($at !== null) {
$rows[] = ['tenant_id' => $booking->tenant_id, 'booking_id' => $booking->id, 'type' => $type, 'summary' => mb_substr($summary, 0, 500), 'actor' => 'System', 'reason' => null, 'data' => null, 'occurred_at' => $at, 'created_at' => $now, 'updated_at' => $now];
}
};
foreach ($facts as $column => $summary) {
$add($booking->{$column} ?? null, 'migrated', $column === 'offer_sent_at' ? 'Angebot Version '.$booking->offer_version.' gesendet' : $summary);
}
foreach (DB::table('payments')->where('booking_id', $booking->id)->get() as $payment) {
$add($payment->paid_on ?? $payment->created_at, 'payment', ($payment->amount < 0 ? 'Erstattung ' : 'Zahlung ').number_format(abs($payment->amount) / 100, 2, ',', '.').' € erfasst');
}
foreach (DB::table('booking_messages')->where('booking_id', $booking->id)->get() as $message) {
$add($message->sent_at, 'mail', 'E-Mail: '.$message->subject);
}
foreach (DB::table('booking_tasks')->where('booking_id', $booking->id)->where('status', 'done')->get() as $task) {
$add($task->completed_at, 'task', 'Aufgabe erledigt ('.$task->kind.')');
}
$add($now, 'migrated', 'Bisheriger Verlauf aus den vorhandenen Daten übernommen');
foreach (array_chunk($rows, 100) as $chunk) {
DB::table('booking_events')->insert($chunk);
}
}
}
/**
* Guests created only to fill the required guest of a portal reservation: first name "Gast", the channel name in
* brackets as last name, no e-mail. Their cases now simply have no guest yet.
*/
private function detachPlaceholderGuests(): void
{
$placeholders = DB::table('guests')->where('first_name', 'Gast')->where('last_name', 'like', '(%)')->where(fn ($query) => $query->whereNull('email')->orWhere('email', ''))->pluck('id');
if ($placeholders->isEmpty()) {
return;
}
DB::table('bookings')->whereIn('guest_id', $placeholders)->update(['guest_id' => null]);
DB::table('blocked_periods')->whereIn('guest_id', $placeholders)->update(['guest_id' => null]);
foreach ($placeholders as $guestId) {
if (! DB::table('bookings')->where('guest_id', $guestId)->exists()) {
DB::table('guests')->where('id', $guestId)->delete();
}
}
}
};