Modellwahl über Kanalfähigkeiten mit erklärten Einschränkungen, Abgleich alter Werte, Ausführungsvarianten je Modul, getrennte Vertrags-/Buchungsinformation, Warten auf die Portalbestätigung mit Eskalation und Wiederaufnahme (Fälle C und D getestet). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
93 lines
4.6 KiB
PHP
93 lines
4.6 KiB
PHP
<?php
|
||
|
||
namespace App\Process\Modules\Settlement;
|
||
|
||
use App\Availability\AvailabilityChecker;
|
||
use App\Enums\ActivityState;
|
||
use App\Enums\BookingTaskKind;
|
||
use App\Enums\BookingTaskStatus;
|
||
use App\Models\BookingTask;
|
||
use App\Process\Activity;
|
||
use App\Process\CaseContext;
|
||
use App\Process\CaseRequirements;
|
||
use App\Process\Modules\Module;
|
||
use App\Process\Modules\ModuleDefinition;
|
||
use App\Process\Modules\StepState;
|
||
use Carbon\CarbonImmutable;
|
||
|
||
/**
|
||
* Event-driven work on the case (docs/Prozessarchitektur/Architektur/02 §4.1): every open task – a portal's
|
||
* cancellation or change report, a booking wish to decide, conflicting details, payment and service tasks – and the done
|
||
* tasks of the stay as its record. Tasks have no fixed place in the course; the model shows them where it lists events.
|
||
*/
|
||
final class CaseTasks extends Module
|
||
{
|
||
public static function key(): string
|
||
{
|
||
return 'case.tasks';
|
||
}
|
||
|
||
public static function definition(): ModuleDefinition
|
||
{
|
||
return new ModuleDefinition(
|
||
label: 'Aufgaben und Meldungen',
|
||
purpose: 'Zeigt offene Aufgaben des Vorgangs – Meldungen der Portale, Entscheidungen, Zahlungs- und Leistungsaufgaben.',
|
||
phase: 'P03',
|
||
executions: [],
|
||
condition: 'wenn eine Aufgabe oder Meldung vorliegt',
|
||
effects: ['case_write'],
|
||
waits: ['landlord'],
|
||
triggers: ['task.created', 'portal.report'],
|
||
toggle: ModuleDefinition::TOGGLE_EVENT_DRIVEN,
|
||
performers: ['landlord'],
|
||
events: ['task'],
|
||
);
|
||
}
|
||
|
||
public function activities(CaseContext $case): array
|
||
{
|
||
return BookingTask::query()->where('booking_id', $case->booking->id)
|
||
->where(fn ($query) => $query->where('status', BookingTaskStatus::Open)
|
||
->orWhere(fn ($done) => $done->where('status', BookingTaskStatus::Done)->whereIn('kind', [BookingTaskKind::Service, BookingTaskKind::Issue, BookingTaskKind::FollowUp, BookingTaskKind::PayoutCheck, BookingTaskKind::OpenClaim])))
|
||
->orderByRaw('due_on is null')->orderBy('due_on')->orderBy('id')->get()
|
||
->map(fn (BookingTask $task): Activity => self::task($task))
|
||
->all();
|
||
}
|
||
|
||
public function state(CaseContext $case): ?StepState
|
||
{
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* An open task of the case and the action that settles it.
|
||
*/
|
||
public static function task(BookingTask $task): Activity
|
||
{
|
||
$action = match ($task->kind) {
|
||
BookingTaskKind::PortalCancellation, BookingTaskKind::PortalCancellationReported => 'confirmPortalCancellation',
|
||
BookingTaskKind::PortalChangeReported => 'change',
|
||
BookingTaskKind::BookingWish => 'decideWish',
|
||
BookingTaskKind::ArrivalDetails => 'arrivalDetails',
|
||
BookingTaskKind::CancellationRequest => 'end',
|
||
BookingTaskKind::FactConflict => 'provideContact',
|
||
default => $task->kind->isPayment() ? null : 'completeTask',
|
||
};
|
||
$today = CarbonImmutable::today();
|
||
$state = match (true) {
|
||
$task->status === BookingTaskStatus::Done => ActivityState::Done,
|
||
$task->kind === BookingTaskKind::PayoutCheck && $task->due_on?->isAfter($today) => ActivityState::Waiting,
|
||
$task->kind === BookingTaskKind::Service && $task->due_on?->isAfter($today) => ActivityState::Later,
|
||
$task->kind === BookingTaskKind::BookingWish && $task->booking !== null && ! app(AvailabilityChecker::class)->isAvailable($task->booking->property, $task->booking->arrival, $task->booking->departure, ignore: $task->booking) => ActivityState::Problem,
|
||
// v0.11 (B3): the binding confirmation waits for the missing details as well.
|
||
$task->kind === BookingTaskKind::BookingWish && $task->booking !== null && CaseRequirements::missing($task->booking, CaseRequirements::WISH_CONFIRMATION) !== [] => ActivityState::Waiting,
|
||
default => ActivityState::Open,
|
||
};
|
||
$detail = $task->status === BookingTaskStatus::Done
|
||
? 'erledigt am '.$task->completed_at?->format('d.m.Y').($task->completed_by ? ' von '.$task->completed_by : '').($task->note ? ' · '.$task->note : '')
|
||
: trim(($state === ActivityState::Problem ? 'Achtung: Der Zeitraum ist inzwischen belegt – bitte absagen. · ' : '').($task->due_on ? 'fällig '.$task->due_on->format('d.m.Y') : '').($task->responsible ? ' · zuständig: '.$task->responsible : '').($task->note ? ' · '.$task->note : ''), ' ·');
|
||
|
||
return new Activity('task_'.$task->kind->value, $task->label(), $state, $detail, $state === ActivityState::Done ? null : $action);
|
||
}
|
||
}
|