- 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>
72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Process;
|
|
|
|
use App\Models\Booking;
|
|
use App\Models\BookingEvent;
|
|
use Carbon\CarbonInterface;
|
|
|
|
/**
|
|
* Writes the stored history of a case. Model hooks record the facts (status, documents, payments, mails); actions
|
|
* that know more (who acted on whose behalf, and why) wrap their work in {@see self::context()}.
|
|
*/
|
|
class CaseLog
|
|
{
|
|
public const SYSTEM = 'System';
|
|
|
|
public const GUEST = 'Gast';
|
|
|
|
private static ?string $actor = null;
|
|
|
|
private static ?string $reason = null;
|
|
|
|
/**
|
|
* Runs the callback with a named actor and/or reason for every entry written meanwhile.
|
|
*
|
|
* @template T
|
|
*
|
|
* @param callable(): T $callback
|
|
* @return T
|
|
*/
|
|
public static function context(callable $callback, ?string $actor = null, ?string $reason = null): mixed
|
|
{
|
|
[$previousActor, $previousReason] = [self::$actor, self::$reason];
|
|
self::$actor = $actor ?? $previousActor;
|
|
self::$reason = $reason ?? $previousReason;
|
|
|
|
try {
|
|
return $callback();
|
|
} finally {
|
|
[self::$actor, self::$reason] = [$previousActor, $previousReason];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public static function record(Booking $booking, string $type, string $summary, ?string $reason = null, array $data = [], ?string $actor = null, ?CarbonInterface $at = null): BookingEvent
|
|
{
|
|
$event = new BookingEvent([
|
|
'booking_id' => $booking->id,
|
|
'type' => $type,
|
|
'summary' => mb_substr($summary, 0, 500),
|
|
'actor' => $actor ?? self::actor(),
|
|
'reason' => $reason ?? self::$reason,
|
|
'data' => $data === [] ? null : $data,
|
|
'occurred_at' => $at ?? now(),
|
|
]);
|
|
$event->tenant_id = $booking->tenant_id;
|
|
$event->save();
|
|
|
|
return $event;
|
|
}
|
|
|
|
/**
|
|
* Who is acting right now: the named actor, the signed-in user or the system (scheduler, mail import).
|
|
*/
|
|
public static function actor(): string
|
|
{
|
|
return self::$actor ?? auth()->user()?->name ?? self::SYSTEM;
|
|
}
|
|
}
|