- 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>
76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\BookingTaskKind;
|
|
use App\Enums\BookingTaskStatus;
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use App\Process\CaseLog;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Something the landlord has to do about a booking. One task per booking and kind; a finished or
|
|
* dismissed task is never created again.
|
|
*/
|
|
#[Fillable(['booking_id', 'kind', 'status', 'due_on', 'note', 'completed_by', 'completed_at'])]
|
|
class BookingTask extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::created(function (BookingTask $task): void {
|
|
if ($task->booking !== null) {
|
|
CaseLog::record($task->booking, 'task', 'Aufgabe: '.$task->kind->getLabel());
|
|
}
|
|
});
|
|
static::updated(function (BookingTask $task): void {
|
|
if ($task->wasChanged('status') && $task->status !== BookingTaskStatus::Open && $task->booking !== null) {
|
|
CaseLog::record($task->booking, 'task', 'Aufgabe '.($task->status === BookingTaskStatus::Done ? 'erledigt' : 'verworfen').': '.$task->kind->getLabel(), actor: $task->completed_by);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'kind' => BookingTaskKind::class,
|
|
'status' => BookingTaskStatus::class,
|
|
'due_on' => 'immutable_date',
|
|
'completed_at' => 'immutable_datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Booking, $this>
|
|
*/
|
|
public function booking(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Booking::class);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<BookingTask> $query
|
|
* @return Builder<BookingTask>
|
|
*/
|
|
#[Scope]
|
|
protected function open(Builder $query): Builder
|
|
{
|
|
return $query->where('status', BookingTaskStatus::Open);
|
|
}
|
|
|
|
public function complete(string $by): void
|
|
{
|
|
$this->update(['status' => BookingTaskStatus::Done, 'completed_by' => $by, 'completed_at' => now()]);
|
|
}
|
|
}
|