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
@@ -13,9 +13,12 @@
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Enums\DocumentKind;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\Responsibility;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Filament\Forms\DocumentCompositionFields;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Pricing\CaseMoney;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseClosure;
|
||||
use App\Process\CaseLog;
|
||||
@@ -230,14 +233,37 @@ private function settleAction(): Action
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Completed, BookingStatus::Cancelled], true) && $this->record->settled_at === null)
|
||||
->modalHeading('Kaufmännisch abschließen')
|
||||
->modalDescription(fn (): string => 'Noch offen: '.implode(' ', CaseClosure::commercialPoints($this->record)).' Abschließen nur, wenn das geklärt ist (z. B. kleine Differenz akzeptiert, Forderung ausgebucht).')
|
||||
->schema([Textarea::make('note')->label('Begründung')->required()->rows(2)->maxLength(500)])
|
||||
->schema([
|
||||
// Decision O5: with portal collection an open payout needs its financial clarification, not only a reason.
|
||||
Select::make('clarification')->label('Wie ist die Auszahlung geklärt?')
|
||||
->options(CaseClosure::PAYOUT_CLARIFICATIONS)
|
||||
->visible(fn (): bool => $this->payoutOpen())
|
||||
->required(fn (): bool => $this->payoutOpen())
|
||||
->helperText('Eine Meldung des Portals über die Auszahlung ist kein Nachweis des Geldeingangs. „Als offene Forderung weiterführen“ legt eine Aufgabe an; der Vorgang bleibt kaufmännisch offen.'),
|
||||
Textarea::make('note')->label('Begründung')->required()->rows(2)->maxLength(500),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
CaseClosure::settle($this->record, trim((string) $data['note']), CaseLog::actor());
|
||||
try {
|
||||
CaseClosure::settle($this->record, trim((string) $data['note']), CaseLog::actor(), $data['clarification'] ?? null);
|
||||
} catch (ReservationException $exception) {
|
||||
Notification::make()->title('Nicht abgeschlossen')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
$this->record->refresh();
|
||||
Notification::make()->title('Kaufmännisch abgeschlossen')->success()->send();
|
||||
Notification::make()->title($this->record->settled_at !== null ? 'Kaufmännisch abgeschlossen' : 'Als offene Forderung weitergeführt')->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the portal's payout is open or deviating (decision O5).
|
||||
*/
|
||||
private function payoutOpen(): bool
|
||||
{
|
||||
return CaseMoney::of($this->record)->collector() === Responsibility::Portal
|
||||
&& collect(CaseClosure::commercialPoints($this->record))->contains(fn (string $point): bool => str_contains($point, 'Auszahlung'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open tasks the landlord can settle on the page (not the ones with an action of their own).
|
||||
*
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use App\Filament\Concerns\FollowsAdminMode;
|
||||
use App\Filament\Concerns\SelectsRecordProperty;
|
||||
use App\Filament\Resources\Channels\Pages\ChannelProcess;
|
||||
use App\Filament\Resources\Channels\Pages\ChannelProcessTest;
|
||||
use App\Filament\Resources\Channels\Pages\ChannelRules;
|
||||
use App\Filament\Resources\Channels\Pages\CreateChannel;
|
||||
use App\Filament\Resources\Channels\Pages\EditChannel;
|
||||
@@ -63,6 +64,7 @@ public static function getPages(): array
|
||||
'edit' => EditChannel::route('/{record}/edit'),
|
||||
'rules' => ChannelRules::route('/{record}/rules'),
|
||||
'process' => ChannelProcess::route('/{record}/process'),
|
||||
'test' => ChannelProcessTest::route('/{record}/test'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -211,6 +211,15 @@ public function save(): void
|
||||
Notification::make()->title('Ablauf gespeichert')->body('Gilt für neue Vorgänge.'.($running > 0 ? ' '.$running.' laufende Vorgänge behalten ihren bisherigen Ablauf.' : ''))->success()->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the process tester with the current – also unsaved – draft of this intake kind.
|
||||
*/
|
||||
public function test(): void
|
||||
{
|
||||
session()->put('process-tester.draft.'.$this->record->id.'.'.$this->intake, $this->drafts[$this->intake]);
|
||||
$this->redirect(ChannelResource::getUrl('test', ['record' => $this->record, 'intake' => $this->intake]));
|
||||
}
|
||||
|
||||
/**
|
||||
* The effective value a new case would get, for the landlord's comparison (expert view).
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Channels\Pages;
|
||||
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\UserRole;
|
||||
use App\Filament\Resources\Channels\ChannelResource;
|
||||
use App\Models\Channel;
|
||||
use App\Models\ProcessTestRun;
|
||||
use App\Models\User;
|
||||
use App\Process\ChannelProcessConfiguration;
|
||||
use App\Process\Tester\ProcessSandbox;
|
||||
use App\Process\Tester\ScenarioCatalogue;
|
||||
use App\Process\Tester\Scenarios\Scenario;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Ablauf testen (docs/Prozessarchitektur/Architektur/04): plays a predefined scenario with the channel's current – also
|
||||
* unsaved – process configuration in an isolated run and shows the report step by step. Nothing of a run reaches the
|
||||
* real data, mails, calendars or portals; on a server where the isolation cannot be established the tester is locked
|
||||
* and says why. Landlord administrators only (decision E8).
|
||||
*
|
||||
* @property Channel $record
|
||||
*/
|
||||
class ChannelProcessTest extends Page
|
||||
{
|
||||
use InteractsWithRecord;
|
||||
|
||||
protected static string $resource = ChannelResource::class;
|
||||
|
||||
protected static ?string $title = 'Ablauf testen';
|
||||
|
||||
protected string $view = 'filament.resources.channels.channel-process-test';
|
||||
|
||||
public string $intake = 'inquiry';
|
||||
|
||||
public string $scenario = '';
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
public array $inputs = [];
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
public array $draft = [];
|
||||
|
||||
public int $steps = 1;
|
||||
|
||||
public ?int $runId = null;
|
||||
|
||||
public static function canAccess(array $parameters = []): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
return $user instanceof User && $user->hasRole(UserRole::Admin);
|
||||
}
|
||||
|
||||
public function mount(int|string $record): void
|
||||
{
|
||||
$this->record = $this->resolveRecord($record);
|
||||
$intakes = array_map(fn (IntakeKind $intake): string => $intake->value, app(ChannelProcessConfiguration::class)->intakes($this->record));
|
||||
$requested = (string) request()->query('intake', '');
|
||||
$this->intake = in_array($requested, $intakes, true) ? $requested : ($intakes[0] ?? 'inquiry');
|
||||
$this->draft = (array) session()->get($this->draftKey(), []);
|
||||
if ($this->draft === []) {
|
||||
$current = app(ChannelProcessConfiguration::class)->current($this->record, IntakeKind::from($this->intake));
|
||||
$stored = (array) (($this->record->process_overrides ?? [])[$this->intake] ?? []);
|
||||
$this->draft = ['model' => $current['model'], 'variant' => $current['variant'], 'steps' => (array) ($stored['steps'] ?? []), 'settings' => []];
|
||||
}
|
||||
$this->scenario = (string) array_key_first($this->scenarios());
|
||||
$this->resetInputs();
|
||||
}
|
||||
|
||||
public function draftKey(): string
|
||||
{
|
||||
return 'process-tester.draft.'.$this->record->id.'.'.$this->intake;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, class-string<Scenario>>
|
||||
*/
|
||||
public function scenarios(): array
|
||||
{
|
||||
return ScenarioCatalogue::for(IntakeKind::from($this->intake), $this->record->isWebsite());
|
||||
}
|
||||
|
||||
public function updatedScenario(): void
|
||||
{
|
||||
$this->resetInputs();
|
||||
$this->runId = null;
|
||||
$this->steps = 1;
|
||||
}
|
||||
|
||||
private function resetInputs(): void
|
||||
{
|
||||
$class = $this->scenarios()[$this->scenario] ?? null;
|
||||
$this->inputs = $class === null ? [] : array_map(fn (array $input): mixed => $input['type'] === 'date' ? now()->modify((string) $input['default'])->toDateString() : $input['default'], $class::inputs());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function requirements(): array
|
||||
{
|
||||
return ProcessSandbox::requirements();
|
||||
}
|
||||
|
||||
public function start(): void
|
||||
{
|
||||
$this->steps = 1;
|
||||
$this->play();
|
||||
}
|
||||
|
||||
public function next(): void
|
||||
{
|
||||
$this->steps++;
|
||||
$this->play();
|
||||
}
|
||||
|
||||
private function play(): void
|
||||
{
|
||||
try {
|
||||
$run = app(ProcessSandbox::class)->run($this->record, IntakeKind::from($this->intake), $this->draft, $this->scenario, $this->inputs, $this->steps, auth()->user());
|
||||
$this->runId = $run->id;
|
||||
} catch (Throwable $exception) {
|
||||
Notification::make()->title('Test nicht möglich')->body($exception->getMessage())->danger()->persistent()->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function run(): ?ProcessTestRun
|
||||
{
|
||||
return $this->runId === null ? null : ProcessTestRun::query()->find($this->runId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<ProcessTestRun>
|
||||
*/
|
||||
public function recent(): iterable
|
||||
{
|
||||
return ProcessTestRun::query()->where('channel_id', $this->record->id)->latest()->limit(5)->get();
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('back')->label('Zurück zum Ablauf')->color('gray')->url(fn (): string => ChannelResource::getUrl('process', ['record' => $this->record])),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user