U-D/U-E/O5: Prozess-Tester im eigenen Prozess (standardmäßig gesperrt, 15 Negativtests, statischer Wächter), Szenarien und Bericht, Kanalereignisse (API-Eingang ohne Umbau von iCal/Mail), Abschluss nach finanzieller Klärung, Löschfrist 30 Tage
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c255783cec
commit
0689c0a591
68 files changed
+3350
-35
No files matched your search
@@ -3,8 +3,10 @@
|
||||
namespace App\Process;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Enums\Responsibility;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Pricing\CaseMoney;
|
||||
@@ -21,6 +23,16 @@
|
||||
*/
|
||||
final class CaseClosure
|
||||
{
|
||||
/** Kinds of financial clarification that allow settling an open portal payout (decision O5). */
|
||||
public const PAYOUT_CLARIFICATIONS = [
|
||||
'offset' => 'Verrechnung dokumentiert',
|
||||
'difference_booked' => 'Differenz geklärt und verbucht',
|
||||
'written_off' => 'Forderung ausgebucht',
|
||||
self::CLAIM_OPEN => 'Als offene Forderung weiterführen',
|
||||
];
|
||||
|
||||
public const CLAIM_OPEN = 'open_claim';
|
||||
|
||||
public const AUTOMATIC = 'automatisch';
|
||||
|
||||
/**
|
||||
@@ -92,8 +104,26 @@ public static function refresh(Booking $booking): void
|
||||
* The landlord settles the case although points are open (e.g. a small payout difference accepted); open commercial
|
||||
* tasks are closed with the same note. The reason is required and kept.
|
||||
*/
|
||||
public static function settle(Booking $booking, string $note, string $by): void
|
||||
public static function settle(Booking $booking, string $note, string $by, ?string $clarification = null): void
|
||||
{
|
||||
// Decision O5: with portal collection, an open or deviating payout is settled only after its financial
|
||||
// clarification – a reason alone is not enough, and a portal's report of a payout is no proof of the receipt.
|
||||
$payoutPoints = $booking->status !== BookingStatus::Cancelled && CaseMoney::of($booking)->collector() === Responsibility::Portal
|
||||
? self::portalMoney($booking, CaseMoney::of($booking)) : [];
|
||||
if ($payoutPoints !== [] && ! array_key_exists((string) $clarification, self::PAYOUT_CLARIFICATIONS)) {
|
||||
throw new ReservationException('Bei Inkasso durch das Portal ist der kaufmännische Abschluss erst nach finanzieller Klärung möglich: Auszahlung eingegangen, Verrechnung, verbuchte Differenz oder ausgebuchte Forderung. Offen: '.implode(' ', $payoutPoints));
|
||||
}
|
||||
if ($clarification === self::CLAIM_OPEN) {
|
||||
// The claim stays traceable: an open task of its own, the case stays commercially open.
|
||||
BookingTask::query()->firstOrCreate(['booking_id' => $booking->id, 'kind' => BookingTaskKind::OpenClaim, 'status' => BookingTaskStatus::Open], ['tenant_id' => $booking->tenant_id, 'due_on' => today()->addDays(14), 'note' => mb_substr($note, 0, 1000)]);
|
||||
CaseLog::record($booking, 'settled', 'Als offene Forderung weitergeführt', reason: $note, data: ['open_points' => $payoutPoints, 'clarification' => $clarification], actor: $by);
|
||||
|
||||
return;
|
||||
}
|
||||
if ($clarification !== null && isset(self::PAYOUT_CLARIFICATIONS[$clarification])) {
|
||||
$note = self::PAYOUT_CLARIFICATIONS[$clarification].': '.$note;
|
||||
}
|
||||
|
||||
foreach (BookingTask::query()->where('booking_id', $booking->id)->where('status', BookingTaskStatus::Open)->get() as $task) {
|
||||
if ($task->kind->isCommercial()) {
|
||||
$task->complete($by, 'Mit dem kaufmännischen Abschluss geklärt: '.$note);
|
||||
|
||||
Reference in new issue
Block a user