CaseActivities/CaseAutomation sind Fassaden über ProcessRunner. Verhaltensvergleich v0.11: 11 Abläufe und 198 Konstellationen gleich, beabsichtigte Abweichungen I-004/I-005 (F-001/F-002). Volle Suite vor U-B: 785/785. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.8 KiB
PHP
66 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace App\Process\Modules\Settlement;
|
||
|
||
use App\Enums\ActivityState;
|
||
use App\Enums\BookingStatus;
|
||
use App\Process\Activity;
|
||
use App\Process\CaseClosure;
|
||
use App\Process\CaseContext;
|
||
use App\Process\Modules\Dependency;
|
||
use App\Process\Modules\Module;
|
||
use App\Process\Modules\ModuleDefinition;
|
||
|
||
/**
|
||
* P05 (package 9): the commercial closing – payments, refunds and payouts cleared (CaseClosure::commercialPoints). With
|
||
* portal collection only after financial clearance; a portal report of a payout is no proof (decision O5).
|
||
*/
|
||
final class CommercialSettlement extends Module
|
||
{
|
||
public static function key(): string
|
||
{
|
||
return 'case.settlement';
|
||
}
|
||
|
||
public static function definition(): ModuleDefinition
|
||
{
|
||
return new ModuleDefinition(
|
||
label: 'Kaufmännisch abschließen',
|
||
purpose: 'Schließt den Vorgang kaufmännisch ab, wenn Zahlungen, Erstattungen und Auszahlungen geklärt sind.',
|
||
phase: 'P05',
|
||
requires: [Dependency::soft('case.closure')],
|
||
effects: ['case_write'],
|
||
waits: ['landlord', 'portal'],
|
||
triggers: ['payment.recorded', 'stay.closed'],
|
||
performers: ['landlord', 'system'],
|
||
events: ['settled'],
|
||
readsContractData: true,
|
||
);
|
||
}
|
||
|
||
public function applies(CaseContext $case): bool
|
||
{
|
||
$booking = $case->booking;
|
||
$settlementApplies = $booking->status === BookingStatus::Completed || $booking->status === BookingStatus::Cancelled;
|
||
|
||
return $settlementApplies || ($booking->isBinding() && ! $booking->isInternal()) || ($booking->isInternal() && (int) $booking->total > 0);
|
||
}
|
||
|
||
public function activities(CaseContext $case): array
|
||
{
|
||
$booking = $case->booking;
|
||
$settlementApplies = $booking->status === BookingStatus::Completed || $booking->status === BookingStatus::Cancelled;
|
||
$points = $settlementApplies && $booking->settled_at === null ? CaseClosure::commercialPoints($booking) : [];
|
||
|
||
return [new Activity('settlement', 'Kaufmännisch abschließen', match (true) {
|
||
$booking->settled_at !== null => ActivityState::Done,
|
||
! $settlementApplies => ActivityState::Later,
|
||
default => ActivityState::Waiting,
|
||
}, match (true) {
|
||
$booking->settled_at !== null => 'abgeschlossen am '.$booking->settled_at->format('d.m.Y').($booking->settled_by && $booking->settled_by !== CaseClosure::AUTOMATIC ? ' von '.$booking->settled_by : '').($booking->settled_note ? ' · '.$booking->settled_note : ''),
|
||
! $settlementApplies => 'nach dem Aufenthalt, wenn Zahlungen, Erstattungen und Auszahlungen geklärt sind',
|
||
default => 'offen: '.implode(' ', $points),
|
||
}, $settlementApplies && $booking->settled_at === null && $points !== [] ? 'settle' : null)];
|
||
}
|
||
}
|