Dokumentenzusammenstellung und Vorlagensteuerung (Paket 3, Prozessarchitektur v0.10)
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m59s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m59s
Eine Zusammenstellung vor jedem Dokument (Angebot, Bestaetigung, Buchungsunterlagen extern), Dokumentart je Vorgangsart, Freigaben fuer Vorlagen und Dokumentarten, Schutz vor unvereinbarten Bedingungen bei Portalbuchungen (E-004), kein doppelter Versand, Absicherung Hold 0 bis Paket 7, A6-Aufenthaltsbestaetigung vorbereitet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
64248c09fa
commit
cf11c8a474
45 files changed
+2385
-144
No files matched your search
@@ -6,17 +6,21 @@
|
||||
use App\Actions\ConfirmBooking;
|
||||
use App\Actions\DeclineBooking;
|
||||
use App\Actions\ProvideGuestContact;
|
||||
use App\Actions\SendBookingDocuments;
|
||||
use App\Actions\SendOffer;
|
||||
use App\Actions\SetBookingStatus;
|
||||
use App\Documents\OfferTerms;
|
||||
use App\Documents\RentalContract;
|
||||
use App\Enums\AdminMode;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\DocumentKind;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\ProcessingMode;
|
||||
use App\Enums\Responsibility;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Filament\Actions\AssignGuestAction;
|
||||
use App\Filament\Forms\Components\EuroInput;
|
||||
use App\Filament\Forms\DocumentCompositionFields;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Models\Booking;
|
||||
use App\Models\ContractAnnex;
|
||||
@@ -24,18 +28,16 @@
|
||||
use App\Models\Extra;
|
||||
use App\Models\User;
|
||||
use App\Pricing\PortalPrice;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseAutomation;
|
||||
use App\Process\CaseLog;
|
||||
use App\Support\Money;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
@@ -44,12 +46,14 @@
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Filament\Schemas\Components\Group;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Throwable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* The case page. At the top only what matters now: the next step as one large button, "Beenden" and the switch between
|
||||
@@ -84,6 +88,7 @@ protected function getHeaderActions(): array
|
||||
$this->requestContactAction(),
|
||||
AssignGuestAction::make(),
|
||||
$this->confirmAction(),
|
||||
$this->sendDocumentsAction(),
|
||||
$this->resendConfirmationAction(),
|
||||
$this->portalPriceAction(),
|
||||
$this->extendHoldAction(),
|
||||
@@ -125,10 +130,11 @@ private function sendOfferAction(): Action
|
||||
->icon(Heroicon::OutlinedPaperAirplane)
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Expired], true) && $this->record->intake !== IntakeKind::Booking)
|
||||
->modalHeading('Angebot an den Gast')
|
||||
->modalDescription('Alles ist vorbereitet: Preis, Vertragsvorlage, Anlagen und Gültigkeit kommen aus Ihren Einstellungen. Prüfen Sie die Angaben; „Anpassen“ nur bei Bedarf. Mit „Senden“ erhält der Gast das Angebot mit einem Link zum Annehmen.')
|
||||
->modalDescription('Alles ist vorbereitet: Preis, Vertragsvorlage, Anlagen und Gültigkeit kommen aus Ihren Einstellungen. Prüfen Sie die Zusammenstellung; „Anpassen“ nur bei Bedarf. Mit „Senden“ erhält der Gast das Angebot mit einem Link zum Annehmen.')
|
||||
->modalSubmitActionLabel('Senden')
|
||||
->modalWidth('3xl')
|
||||
->modalWidth('4xl')
|
||||
->fillForm(fn (): array => [
|
||||
'expected_version' => $this->record->offer_version,
|
||||
'arrival' => $this->record->arrival->toDateString(),
|
||||
'departure' => $this->record->departure->toDateString(),
|
||||
'guests' => $this->record->guests,
|
||||
@@ -137,16 +143,14 @@ private function sendOfferAction(): Action
|
||||
'price_adjustment_label' => $this->record->price_adjustment_label,
|
||||
'valid_until' => now()->addHours($this->record->process()->holdHours())->format('Y-m-d H:i'),
|
||||
'offer_message' => $this->record->offer_message,
|
||||
'annex_ids' => OfferTerms::templateFor($this->record)?->annexesFor($this->record)->pluck('id')->all() ?? [],
|
||||
'guest' => $this->record->guest?->only(['first_name', 'last_name', 'street', 'postal_code', 'city', 'phone']) ?? [],
|
||||
])
|
||||
->schema([
|
||||
Section::make('So geht das Angebot hinaus')->schema([
|
||||
Text::make(fn (Get $get): string => $this->offerPricePreview($get)),
|
||||
Text::make(fn (): string => 'Gast: '.$this->record->guestName().' · '.($this->record->guest?->email ?: 'keine E-Mail-Adresse')),
|
||||
Text::make(fn (): string => 'Vertragsvorlage: '.(OfferTerms::templateFor($this->record)?->label() ?? 'Texte der Webseite')),
|
||||
Textarea::make('offer_message')->label('Persönliche Nachricht an den Gast (optional)')->rows(3),
|
||||
]),
|
||||
Section::make('Anpassen')->description('Zeitraum, Preis, Vorlage, Gültigkeit, Angaben zum Gast')->collapsed()->schema([
|
||||
Hidden::make('expected_version'),
|
||||
...DocumentCompositionFields::make($this->record, DocumentKind::Offer, fn (Get $get): array => $this->offerChanges(self::formState($get, ['expected_version', 'arrival', 'departure', 'guests', 'promo_code', 'price_adjustment', 'price_adjustment_label', 'valid_until', 'offer_message', 'contract_template_id', 'annex_ids', 'guest']))),
|
||||
Textarea::make('offer_message')->label('Persönliche Nachricht an den Gast (optional)')->rows(3)->live(onBlur: true),
|
||||
Section::make('Anpassen')->description('Zeitraum, Preis, Vorlage, Gültigkeit, Angaben zum Gast – die Zusammenstellung oben rechnet sofort neu.')->collapsed()->schema([
|
||||
Section::make('Termin')->columns(3)->schema([
|
||||
DatePicker::make('arrival')->label('Anreise')->required()->live(onBlur: true),
|
||||
DatePicker::make('departure')->label('Abreise')->after('arrival')->required()->live(onBlur: true),
|
||||
@@ -155,38 +159,81 @@ private function sendOfferAction(): Action
|
||||
Section::make('Preis')->columns(3)->schema([
|
||||
TextInput::make('promo_code')->label('Rabattcode')->maxLength(50)->live(onBlur: true),
|
||||
TextInput::make('price_adjustment')->label('Preisanpassung')->helperText('Minus = Nachlass, z. B. -50')->numeric()->step(0.01)->suffix('€')->live(onBlur: true),
|
||||
TextInput::make('price_adjustment_label')->label('Bezeichnung')->placeholder('Nachlass / Zuschlag')->maxLength(80),
|
||||
]),
|
||||
Section::make('Vorlage und Anlagen')->schema([
|
||||
Select::make('contract_template_id')
|
||||
->label('Andere Vorlage für dieses Angebot')
|
||||
->options(fn (): array => ContractTemplate::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractTemplate $template): array => [$template->id => $template->label()])->all())
|
||||
->placeholder('wie eingestellt'),
|
||||
Select::make('annex_ids')
|
||||
->label('Anlagen')
|
||||
->multiple()
|
||||
->options(fn (): array => ContractAnnex::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractAnnex $annex): array => [$annex->id => $annex->label()])->all())
|
||||
->default(fn (): array => OfferTerms::templateFor($this->record)?->annexesFor($this->record)->pluck('id')->all() ?? []),
|
||||
TextInput::make('price_adjustment_label')->label('Bezeichnung')->placeholder('Nachlass / Zuschlag')->maxLength(80)->live(onBlur: true),
|
||||
]),
|
||||
...$this->templateFields(),
|
||||
DateTimePicker::make('valid_until')
|
||||
->label('Angebot gültig bis')
|
||||
->helperText(fn (): string => 'Eingestellt: '.$this->record->process()->holdHours().' Stunden. Bis dahin bleibt der Zeitraum reserviert.')
|
||||
->seconds(false)
|
||||
->after('now')
|
||||
->required(),
|
||||
->required()
|
||||
->live(onBlur: true),
|
||||
Section::make('Gast – so erscheint er im Vertrag')->columns(2)->schema([
|
||||
TextInput::make('guest.first_name')->label('Vorname')->required()->maxLength(100),
|
||||
TextInput::make('guest.last_name')->label('Nachname')->required()->maxLength(100),
|
||||
TextInput::make('guest.street')->label('Straße und Hausnummer')->maxLength(150),
|
||||
TextInput::make('guest.postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('guest.city')->label('Ort')->maxLength(100),
|
||||
TextInput::make('guest.phone')->label('Telefon')->maxLength(50),
|
||||
TextInput::make('guest.first_name')->label('Vorname')->required()->maxLength(100)->live(onBlur: true),
|
||||
TextInput::make('guest.last_name')->label('Nachname')->required()->maxLength(100)->live(onBlur: true),
|
||||
TextInput::make('guest.street')->label('Straße und Hausnummer')->maxLength(150)->live(onBlur: true),
|
||||
TextInput::make('guest.postal_code')->label('PLZ')->maxLength(20)->live(onBlur: true),
|
||||
TextInput::make('guest.city')->label('Ort')->maxLength(100)->live(onBlur: true),
|
||||
TextInput::make('guest.phone')->label('Telefon')->maxLength(50)->live(onBlur: true),
|
||||
]),
|
||||
]),
|
||||
])
|
||||
->action(fn (array $data, SendOffer $send) => $this->runWorkflow(fn () => $send->handle($this->record, $this->offerChanges($data)), 'Angebot gesendet'));
|
||||
}
|
||||
|
||||
/**
|
||||
* The documents of a binding case (confirmation with contract, or booking documentation of a portal booking), sent
|
||||
* after the landlord saw their composition.
|
||||
*/
|
||||
private function sendDocumentsAction(): Action
|
||||
{
|
||||
return Action::make('sendDocuments')
|
||||
->label(fn (): string => SendBookingDocuments::kindFor($this->record) === DocumentKind::ExternalRecord ? 'Buchungsunterlagen prüfen und senden' : 'Bestätigung prüfen und senden')
|
||||
->icon(Heroicon::OutlinedPaperAirplane)
|
||||
->visible(fn (): bool => $this->record->isBinding() && $this->record->confirmation_sent_at === null && $this->record->confirmation_failed_at === null && $this->record->process()->documents() === Responsibility::Landlord)
|
||||
->modalHeading(fn (): string => SendBookingDocuments::kindFor($this->record)->getLabel())
|
||||
->modalDescription('So gehen die Unterlagen an den Gast. „Anpassen“ nur bei Bedarf.')
|
||||
->modalSubmitActionLabel('Senden')
|
||||
->modalWidth('4xl')
|
||||
->fillForm(fn (): array => ['annex_ids' => $this->record->contract_path === null && $this->record->offer_version === 0 ? (OfferTerms::templateFor($this->record)?->annexesFor($this->record)->pluck('id')->all() ?? []) : null])
|
||||
->schema(fn (): array => [
|
||||
...DocumentCompositionFields::make($this->record, SendBookingDocuments::kindFor($this->record), fn (Get $get): array => $this->documentChanges(self::formState($get, ['contract_template_id', 'annex_ids']))),
|
||||
Section::make('Anpassen')->description('Vorlage und Anlagen für diesen Vorgang.')->collapsed()->visible($this->record->contract_path === null && $this->record->offer_version === 0)->schema($this->templateFields()),
|
||||
])
|
||||
->action(function (array $data, SendBookingDocuments $documents): void {
|
||||
$this->runWorkflow(function () use ($data, $documents): void {
|
||||
if (! $documents->handle($this->record, $this->documentChanges($data), (bool) ($data['acknowledged'] ?? false))) {
|
||||
throw new ReservationException('Der Versand ist fehlgeschlagen (Details im Postfach). Sie können ihn über „Unterlagen erneut senden“ wiederholen.');
|
||||
}
|
||||
}, 'Unterlagen gesendet');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Choice of template and annexes for one case; changing the template proposes its annexes.
|
||||
*
|
||||
* @return list<Section>
|
||||
*/
|
||||
private function templateFields(): array
|
||||
{
|
||||
return [
|
||||
Section::make('Vorlage und Anlagen')->schema([
|
||||
Select::make('contract_template_id')
|
||||
->label('Andere Vorlage für diesen Vorgang')
|
||||
->options(fn (): array => ContractTemplate::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractTemplate $template): array => [$template->id => $template->label().($template->isReleased() ? '' : ' – nicht freigegeben')])->all())
|
||||
->placeholder('wie eingestellt')
|
||||
->live()
|
||||
->afterStateUpdated(fn (Set $set, $state) => $set('annex_ids', OfferTerms::templateFor($this->record, $state)?->annexesFor($this->record)->pluck('id')->all() ?? [])),
|
||||
Select::make('annex_ids')
|
||||
->label('Anlagen')
|
||||
->multiple()
|
||||
->live()
|
||||
->options(fn (): array => ContractAnnex::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractAnnex $annex): array => [$annex->id => $annex->label()])->all()),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
private function provideContactAction(): Action
|
||||
{
|
||||
return Action::make('provideContact')
|
||||
@@ -253,15 +300,40 @@ private function requestContactAction(): Action
|
||||
|
||||
private function confirmAction(): Action
|
||||
{
|
||||
$kind = fn (): DocumentKind => $this->record->intake === IntakeKind::Booking ? DocumentKind::ExternalRecord : DocumentKind::Confirmation;
|
||||
|
||||
return Action::make('confirm')
|
||||
->label('Direkt verbindlich bestätigen')
|
||||
->icon(Heroicon::OutlinedCheckCircle)
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Expired], true))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Buchung direkt bestätigen')
|
||||
->modalDescription('Ohne Angebot und Annahme durch den Gast – nur wenn die Buchung schon anders verbindlich vereinbart wurde (z. B. am Telefon). Der Zeitraum wird fest belegt.')
|
||||
->schema([Toggle::make('notify')->label('Buchungsbestätigung an den Gast senden')->default(fn (): bool => filled($this->record->guest?->email))])
|
||||
->action(fn (array $data, ConfirmBooking $confirm) => $this->runWorkflow(fn () => $confirm->handle($this->record, $data['notify']), 'Buchung bestätigt'));
|
||||
->modalSubmitActionLabel('Bestätigen')
|
||||
->modalWidth('4xl')
|
||||
->fillForm(fn (): array => ['notify' => filled($this->record->guest?->email)])
|
||||
->schema(fn (): array => [
|
||||
Toggle::make('notify')->label('Unterlagen an den Gast senden')->live(),
|
||||
Group::make(DocumentCompositionFields::make($this->record, $kind(), fn (Get $get): array => [], fn (Get $get): bool => (bool) $get('notify')))
|
||||
->visible(fn (Get $get): bool => (bool) $get('notify')),
|
||||
])
|
||||
->action(function (array $data, ConfirmBooking $confirm, SendBookingDocuments $documents) use ($kind): void {
|
||||
$notify = (bool) ($data['notify'] ?? false);
|
||||
$acknowledged = (bool) ($data['acknowledged'] ?? false);
|
||||
|
||||
if ($notify) {
|
||||
$composition = DocumentCompositionFields::compose($this->record, $kind(), []);
|
||||
if (! $composition->canSendByHand($acknowledged)) {
|
||||
Notification::make()->title('Nicht möglich')->body(implode(' ', [...$composition->blockers(), ...$composition->toConfirm()]))->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->runWorkflow(function () use ($confirm, $documents, $notify, $acknowledged): void {
|
||||
DB::transaction(fn () => $confirm->bind($this->record));
|
||||
$notify ? $documents->handle($this->record->fresh(), [], $acknowledged) : $confirm->deliver($this->record->fresh(), notifyGuest: false);
|
||||
}, 'Buchung bestätigt');
|
||||
});
|
||||
}
|
||||
|
||||
private function resendConfirmationAction(): Action
|
||||
@@ -273,13 +345,12 @@ private function resendConfirmationAction(): Action
|
||||
default => 'Bestätigung erneut senden',
|
||||
})
|
||||
->icon(Heroicon::OutlinedEnvelope)
|
||||
->visible(fn (): bool => $this->record->isBinding() && filled($this->record->guest?->email))
|
||||
->visible(fn (): bool => $this->record->isBinding() && filled($this->record->guest?->email) && ($this->record->confirmation_sent_at !== null || $this->record->confirmation_failed_at !== null))
|
||||
->requiresConfirmation()
|
||||
->modalDescription(fn (): string => 'Der Gast erhält die Buchungsbestätigung mit dem Vertrag (Vorlage: '.(OfferTerms::templateFor($this->record)?->label() ?? 'Texte der Webseite').').')
|
||||
->modalDescription(fn (): string => 'Der Gast erhält dieselben Unterlagen noch einmal (Vorlage: '.(isset($this->record->offer_terms['template']['name']) ? $this->record->offer_terms['template']['name'].', Version '.$this->record->offer_terms['template']['version'] : 'Texte der Webseite').').')
|
||||
->action(function (ConfirmBooking $confirm): void {
|
||||
$missing = app(CaseAutomation::class)->documentBlockers($this->record);
|
||||
if ($missing !== []) {
|
||||
Notification::make()->title('Noch nicht möglich')->body(implode(' ', $missing))->warning()->send();
|
||||
if ($this->record->contract_path === null) {
|
||||
Notification::make()->title('Bitte zuerst prüfen')->body('Die Unterlagen wurden noch nie erstellt – bitte über „Unterlagen prüfen und senden“.')->warning()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -550,28 +621,31 @@ private function offerChanges(array $data): array
|
||||
{
|
||||
return [
|
||||
...$data,
|
||||
'acknowledged' => (bool) ($data['acknowledged'] ?? false),
|
||||
'price_adjustment' => filled($data['price_adjustment'] ?? null) ? (int) round((float) $data['price_adjustment'] * 100) : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Live price shown in the offer modal, calculated exactly like the offer itself.
|
||||
* The current values of some fields of a modal form.
|
||||
*
|
||||
* @param list<string> $fields
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function offerPricePreview(Get $get): string
|
||||
private static function formState(Get $get, array $fields): array
|
||||
{
|
||||
try {
|
||||
$stay = new StayRequest(CarbonImmutable::parse($get('arrival')), CarbonImmutable::parse($get('departure')), (int) $get('guests'), $this->record->extras ?? [], filled($get('promo_code')) ? (string) $get('promo_code') : null);
|
||||
$quote = app(PriceCalculator::class)->calculate($this->record->property, $stay);
|
||||
} catch (QuoteException $exception) {
|
||||
return 'Preis: '.$exception->getMessage();
|
||||
} catch (Throwable) {
|
||||
return 'Preis: bitte Termin und Personen angeben.';
|
||||
}
|
||||
return collect($fields)->mapWithKeys(fn (string $field): array => [$field => $get($field)])->all();
|
||||
}
|
||||
|
||||
$adjustment = filled($get('price_adjustment')) ? max((int) round((float) $get('price_adjustment') * 100), -$quote->rent()) : 0;
|
||||
$promo = filled($get('promo_code')) ? ($quote->promoCodeApplied ? ' · Rabattcode angewendet' : ' · Rabattcode gilt hier nicht') : '';
|
||||
|
||||
return 'Preis im Angebot: '.Money::format($quote->total() + $adjustment).' für '.$stay->arrival->format('d.m.').'–'.$stay->departure->format('d.m.Y').', '.$stay->guests.' Personen'.$promo;
|
||||
/**
|
||||
* Form data of the documents modal as composition changes.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function documentChanges(array $data): array
|
||||
{
|
||||
return array_filter(Arr::only($data, ['contract_template_id', 'annex_ids']), fn ($value): bool => $value !== null);
|
||||
}
|
||||
|
||||
private function runWorkflow(callable $workflow, string $successTitle): void
|
||||
|
||||
Reference in new issue
Block a user