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

+77 -18
View File
@@ -5,11 +5,17 @@
use App\Documents\OfferTerms;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\ChannelBookingModel;
use App\Enums\CaseType;
use App\Enums\IntakeKind;
use App\Enums\ProcessingMode;
use App\Enums\ReferralSource;
use App\Enums\Responsibility;
use App\Models\Concerns\BelongsToTenant;
use App\Models\Concerns\HasChannelProvenance;
use App\Observers\BookingObserver;
use App\Process\CaseRecorder;
use App\Process\ProcessProfile;
use App\Process\ProcessSettings;
use Carbon\CarbonInterface;
use Database\Factories\BookingFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
@@ -24,8 +30,10 @@
use Illuminate\Support\HtmlString;
/**
* A reservation or booking. arrival is the first night, departure the day the guest leaves,
* so a departure and the next arrival on the same day do not collide.
* A case ("Vorgang", docs/Prozessarchitektur): one business occasion from its first arrival to its end – a request,
* a booking already binding on a portal, or an internal use. arrival is the first night, departure the day the guest
* leaves, so a departure and the next arrival on the same day do not collide. Guest, number of guests and amounts may
* be unknown (null) – unknown is never replaced by an invented value.
*/
#[ObservedBy(BookingObserver::class)]
#[Fillable([
@@ -33,6 +41,10 @@
'guest_id',
'status',
'source',
'intake',
'case_type',
'profile',
'processing_mode',
'import_channel_id',
'origin_channel_id',
'portal_reference',
@@ -94,9 +106,12 @@ public function isDirect(): bool
protected static function booted(): void
{
static::saving(fn (Booking $booking) => CaseRecorder::freeze($booking));
static::created(function (Booking $booking): void {
$booking->forceFill(['reference' => $booking->nextReference()])->saveQuietly();
CaseRecorder::created($booking);
});
static::updated(fn (Booking $booking) => CaseRecorder::updated($booking));
}
/**
@@ -134,6 +149,10 @@ protected function casts(): array
{
return [
'status' => BookingStatus::class,
'intake' => IntakeKind::class,
'case_type' => CaseType::class,
'profile' => 'array',
'processing_mode' => ProcessingMode::class,
'referral_source' => ReferralSource::class,
'arrival' => 'immutable_date',
'departure' => 'immutable_date',
@@ -189,6 +208,51 @@ public function importChannel(): BelongsTo
return $this->belongsTo(Channel::class, 'import_channel_id');
}
/** @return HasMany<BookingEvent, $this> */
public function events(): HasMany
{
return $this->hasMany(BookingEvent::class)->orderBy('occurred_at')->orderBy('id');
}
/**
* The channel whose settings apply: the one the case was imported from, else its origin channel (owner).
*/
public function processChannel(): ?Channel
{
return $this->importChannel ?? $this->originChannel;
}
/**
* The rules of this case as frozen when it came in (resolved now for a case that has none yet).
*/
public function process(): ProcessProfile
{
return filled($this->profile) ? ProcessProfile::fromArray($this->profile) : app(ProcessSettings::class)->forBooking($this);
}
public function caseType(): CaseType
{
return $this->case_type ?? $this->process()->caseType;
}
/**
* Automatic or manual: the decision taken on this case, else the setting frozen with its profile.
*/
public function processingMode(): ProcessingMode
{
return $this->processing_mode ?? $this->process()->processing();
}
public function isBinding(): bool
{
return in_array($this->status, BookingStatus::occupying(), true);
}
public function guestName(): string
{
return $this->guest?->full_name ?? 'Gast noch nicht bekannt';
}
/** @return HasMany<BlockedPeriod, $this> */
public function channelRepresentations(): HasMany
{
@@ -197,7 +261,7 @@ public function channelRepresentations(): HasMany
public function bookingChannelLabel(): string
{
return $this->originChannel?->name ?? $this->importChannel?->name ?? match ($this->source) {
return $this->originChannel?->name ?? $this->importChannel?->name ?? match ($this->source ?? 'website') {
'website' => 'Eigene Webseite',
'manual' => 'Manuell / direkt',
'phone' => 'Telefon',
@@ -275,14 +339,17 @@ public function paidAmount(): int
return (int) ($this->relationLoaded('payments') ? $this->payments->sum('amount') : $this->payments()->sum('amount'));
}
/**
* Amount still to be paid in cents; 0 while the price is unknown.
*/
public function openAmount(): int
{
return max(0, $this->total - $this->paidAmount());
return $this->total === null ? 0 : max(0, $this->total - $this->paidAmount());
}
public function openDeposit(): int
{
return max(0, $this->deposit - $this->paidAmount());
return $this->deposit === null ? 0 : max(0, $this->deposit - $this->paidAmount());
}
/**
@@ -290,24 +357,16 @@ public function openDeposit(): int
*/
public function requiresFullPayment(): bool
{
return $this->deposit_due_on !== null && $this->balance_due_on->lessThanOrEqualTo($this->deposit_due_on);
return $this->deposit_due_on !== null && $this->balance_due_on !== null && $this->balance_due_on->lessThanOrEqualTo($this->deposit_due_on);
}
/**
* Whether the landlord chases payments of this booking. Own bookings: always. Portal bookings: as configured
* per channel and kind – a reservation whose payment the portal collects (e.g. instant booking) needs no
* tasks, a mere inquiry passed on by the portal does.
* Whether the landlord chases payments of this case: only when the guest pays us (process profile – a portal that
* collects the money needs no tasks) and the price is known.
*/
public function wantsPaymentTasks(): bool
{
$channel = $this->importChannel ?? $this->originChannel;
if ($channel === null) {
return true;
}
return $channel->booking_model === ChannelBookingModel::PortalBooking
? $channel->payment_tasks_reservation
: $channel->payment_tasks_inquiry;
return $this->process()->payments() === Responsibility::Landlord && $this->total !== null && $this->total > 0;
}
/**