Stornoregeln mit automatischer Kostenberechnung, Storno-Verwaltung, Vertragsanlagen
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
- Stornoregel (Stufen nach Tagen vor Anreise, Mietpreis oder Gesamtpreis, Ersatzmieter-Gebuehr), je Vertragsvorlage, beim Angebot eingefroren, als Platzhalter im Vertrag - Stornierung (Gast-Link oder Verwaltung) berechnet die Kosten, legt einen Stornofall an; Verwaltung Stornierungen mit Vorschlag, Festlegung, Saldo, Abrechnung und Erlass; Gast sieht die Kosten vorab auf der Storno-Seite - Vertragsanlagen als eigene versionierte Dokumente mit Bedingung (immer, Zusatzleistung, Portal, von Hand), je Angebot ausgewaehlt und eingefroren; Zusatzleistungen in der Buchung erfassbar - FeWo-direkt-Installation legt die Stornoregel aus Paragraf 13 an Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5baf39441f
commit
0c4187edaf
37 files changed
+1440
-10
No files matched your search
@@ -6,13 +6,16 @@
|
||||
use App\Actions\ConfirmBooking;
|
||||
use App\Actions\DeclineBooking;
|
||||
use App\Actions\SendOffer;
|
||||
use App\Documents\OfferTerms;
|
||||
use App\Documents\RentalContract;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Filament\Actions\AssignGuestAction;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Models\Booking;
|
||||
use App\Models\ContractAnnex;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Models\Extra;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
@@ -22,6 +25,7 @@
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -88,7 +92,13 @@ protected function getHeaderActions(): array
|
||||
TextInput::make('price_adjustment_label')->label('Bezeichnung')->placeholder('Nachlass / Zuschlag')->maxLength(80),
|
||||
Text::make(fn (Get $get): string => $this->offerPricePreview($get))->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Vertragsvorlage')->schema([
|
||||
Section::make('Vertragsvorlage und Anlagen')->schema([
|
||||
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() ?? [])
|
||||
->helperText('Vorausgewählt: Anlagen der Vorlage, deren Bedingung zu dieser Buchung passt (z. B. gebuchtes Wäschepaket). Sie können Anlagen hinzufügen oder entfernen.'),
|
||||
Select::make('contract_template_id')
|
||||
->label('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())
|
||||
@@ -190,6 +200,31 @@ protected function getHeaderActions(): array
|
||||
$notification = Notification::make()->title($sent ? 'Bestätigung gesendet' : 'Versand fehlgeschlagen');
|
||||
($sent ? $notification->success() : $notification->danger()->body('Details im Postfach.'))->send();
|
||||
}),
|
||||
Action::make('services')
|
||||
->label('Zusatzleistungen erfassen')
|
||||
->icon(Heroicon::OutlinedPlusCircle)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired, BookingStatus::Completed], true))
|
||||
->modalDescription('Gebuchte Zusatzleistungen (kostenpflichtig oder kostenlos), z. B. aus einer Portalbuchung oder per E-Mail erfragt. Sie bestimmen, welche Vertragsanlagen angehängt werden. Der Preis der Buchung wird dadurch nicht verändert.')
|
||||
->fillForm(fn (): array => ['items' => collect((array) $this->record->extras)->map(fn ($quantity, $id): array => ['extra_id' => (int) $id, 'quantity' => (int) $quantity])->values()->all()])
|
||||
->schema([
|
||||
Repeater::make('items')
|
||||
->label('Leistungen')
|
||||
->schema([
|
||||
Select::make('extra_id')->label('Leistung')->options(fn (): array => Extra::query()->orderBy('name')->get()->mapWithKeys(fn (Extra $extra): array => [$extra->id => $extra->name.($extra->price > 0 ? ' ('.Money::format($extra->price).')' : ' (kostenlos)')])->all())->required(),
|
||||
TextInput::make('quantity')->label('Menge')->integer()->minValue(1)->default(1)->required(),
|
||||
])
|
||||
->columns(2)
|
||||
->addActionLabel('Leistung hinzufügen'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$extras = [];
|
||||
foreach ((array) ($data['items'] ?? []) as $item) {
|
||||
$extras[(int) $item['extra_id']] = ((int) ($extras[(int) $item['extra_id']] ?? 0)) + max(1, (int) $item['quantity']);
|
||||
}
|
||||
$this->record->update(['extras' => $extras]);
|
||||
Notification::make()->title('Zusatzleistungen gespeichert')->success()->send();
|
||||
}),
|
||||
Action::make('contractText')
|
||||
->label('Vertragstext ansehen')
|
||||
->icon(Heroicon::OutlinedDocumentMagnifyingGlass)
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CancellationPolicies;
|
||||
|
||||
use App\Filament\Concerns\FollowsAdminMode;
|
||||
use App\Filament\Forms\Components\EuroInput;
|
||||
use App\Filament\Resources\CancellationPolicies\Pages\CreateCancellationPolicy;
|
||||
use App\Filament\Resources\CancellationPolicies\Pages\EditCancellationPolicy;
|
||||
use App\Filament\Resources\CancellationPolicies\Pages\ListCancellationPolicies;
|
||||
use App\Models\CancellationPolicy;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Cancellation rules: stepped percentages by days before arrival. Assigned to contract templates.
|
||||
*/
|
||||
class CancellationPolicyResource extends Resource
|
||||
{
|
||||
use FollowsAdminMode;
|
||||
|
||||
protected static ?string $model = CancellationPolicy::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedReceiptPercent;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
|
||||
|
||||
protected static ?string $modelLabel = 'Stornoregel';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Stornoregeln';
|
||||
|
||||
protected static ?int $navigationSort = 7;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->label('Name')->required()->maxLength(120)->helperText('z. B. „Direktbuchung“ oder „FeWo-direkt“.'),
|
||||
Select::make('base')
|
||||
->label('Berechnungsgrundlage')
|
||||
->options([CancellationPolicy::BASE_RENT => 'Mietpreis (ohne Endreinigung, Service und Kurtaxe)', CancellationPolicy::BASE_TOTAL => 'Gesamtpreis'])
|
||||
->default(CancellationPolicy::BASE_RENT)
|
||||
->required(),
|
||||
Repeater::make('tiers')
|
||||
->label('Stufen')
|
||||
->helperText('Jede Stufe gilt, wenn bis zur Anreise mindestens so viele Tage bleiben. Beispiel: ab 60 Tagen 0 %, ab 30 Tagen 50 %, ab 0 Tagen 100 %. Die letzte Stufe (0 Tage) gilt für alles danach.')
|
||||
->schema([
|
||||
TextInput::make('min_days')->label('Ab Tagen vor Anreise')->integer()->minValue(0)->required(),
|
||||
TextInput::make('percent')->label('Entschädigung')->integer()->minValue(0)->maxValue(100)->suffix('%')->required(),
|
||||
])
|
||||
->columns(2)
|
||||
->default([['min_days' => 60, 'percent' => 0], ['min_days' => 30, 'percent' => 50], ['min_days' => 0, 'percent' => 100]])
|
||||
->minItems(1)
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
EuroInput::make('replacement_fee')->label('Gebühr bei Ersatzmieter (optional)'),
|
||||
Text::make(fn (?CancellationPolicy $record): HtmlString => new HtmlString($record ? '<strong>So steht es im Vertrag ({{ storno_regel }}):</strong><ul style="margin-top:.4rem">'.collect(CancellationPolicy::describe($record->snapshot()))->map(fn (string $line): string => '<li>'.e($line).'</li>')->implode('').'</ul>' : ''))->columnSpanFull(),
|
||||
Textarea::make('notes')->label('Interne Notiz')->rows(2)->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('name')
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Regel')->weight('medium')->searchable(),
|
||||
TextColumn::make('base')->label('Grundlage')->formatStateUsing(fn (string $state): string => $state === CancellationPolicy::BASE_TOTAL ? 'Gesamtpreis' : 'Mietpreis'),
|
||||
TextColumn::make('steps')->label('Stufen')->state(fn (CancellationPolicy $record): string => collect(CancellationPolicy::normalise((array) $record->tiers))->map(fn (array $tier): string => 'ab '.$tier['min_days'].' T: '.$tier['percent'].' %')->implode(' · ')),
|
||||
])
|
||||
->recordActions([EditAction::make(), DeleteAction::make()]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListCancellationPolicies::route('/'),
|
||||
'create' => CreateCancellationPolicy::route('/create'),
|
||||
'edit' => EditCancellationPolicy::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CancellationPolicies\Pages;
|
||||
|
||||
use App\Filament\Resources\CancellationPolicies\CancellationPolicyResource;
|
||||
use App\Models\CancellationPolicy;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCancellationPolicy extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CancellationPolicyResource::class;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['tiers'] = CancellationPolicy::normalise((array) ($data['tiers'] ?? []));
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CancellationPolicies\Pages;
|
||||
|
||||
use App\Filament\Resources\CancellationPolicies\CancellationPolicyResource;
|
||||
use App\Models\CancellationPolicy;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCancellationPolicy extends EditRecord
|
||||
{
|
||||
protected static string $resource = CancellationPolicyResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [DeleteAction::make()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$data['tiers'] = CancellationPolicy::normalise((array) ($data['tiers'] ?? []));
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CancellationPolicies\Pages;
|
||||
|
||||
use App\Filament\Resources\CancellationPolicies\CancellationPolicyResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCancellationPolicies extends ListRecords
|
||||
{
|
||||
protected static string $resource = CancellationPolicyResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [CreateAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Cancellations;
|
||||
|
||||
use App\Filament\Concerns\FollowsAdminMode;
|
||||
use App\Filament\Forms\Components\EuroInput;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Filament\Resources\Cancellations\Pages\ListCancellations;
|
||||
use App\Models\Cancellation;
|
||||
use App\Support\Money;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Cancellation management: every cancelled booking with the days before arrival, the cost proposed by its
|
||||
* cancellation rule, the amount finally charged, what was paid and what is still to collect or refund.
|
||||
*/
|
||||
class CancellationResource extends Resource
|
||||
{
|
||||
use FollowsAdminMode;
|
||||
|
||||
protected static ?string $model = Cancellation::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArchiveBoxXMark;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
|
||||
|
||||
protected static ?string $modelLabel = 'Stornierung';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Stornierungen';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('cancelled_on', 'desc')
|
||||
->description('Storno-Verwaltung: Kosten werden nach der Stornoregel der Vertragsvorlage vorgeschlagen. Sie legen den Betrag endgültig fest, rechnen ab oder erlassen ihn. Gäste erhalten hierzu keine automatische Mail.')
|
||||
->columns([
|
||||
TextColumn::make('booking.reference')->label('Buchung')->weight('medium')->description(fn (Cancellation $record): string => $record->booking->guest?->full_name ?? ''),
|
||||
TextColumn::make('cancelled_on')->label('Storniert am')->date('d.m.Y')->description(fn (Cancellation $record): string => $record->initiated_by === 'guest' ? 'durch den Gast' : 'durch die Verwaltung'),
|
||||
TextColumn::make('days_before')->label('Tage vor Anreise')->placeholder('–'),
|
||||
TextColumn::make('policy_name')->label('Stornoregel')->placeholder('Keine Regel')->description(fn (Cancellation $record): ?string => $record->percent !== null ? $record->percent.' % von '.Money::format((int) $record->base_amount) : null),
|
||||
TextColumn::make('calculated_fee')->label('Vorschlag')->formatStateUsing(fn (?int $state): string => $state === null ? '–' : Money::format($state)),
|
||||
TextColumn::make('final_fee')->label('Festgelegt')->formatStateUsing(fn (?int $state): string => $state === null ? '–' : Money::format($state)),
|
||||
TextColumn::make('paid_amount')->label('Bezahlt')->formatStateUsing(fn (int $state): string => Money::format($state)),
|
||||
TextColumn::make('balance')->label('Saldo')->state(fn (Cancellation $record): string => $record->balance() > 0 ? Money::format($record->balance()).' einzufordern' : ($record->balance() < 0 ? Money::format(-$record->balance()).' zu erstatten' : 'ausgeglichen')),
|
||||
TextColumn::make('status')->label('Status')->badge()->formatStateUsing(fn (string $state): string => match ($state) {
|
||||
Cancellation::SETTLED => 'Abgerechnet',
|
||||
Cancellation::WAIVED => 'Erlassen',
|
||||
default => 'Offen',
|
||||
})->color(fn (string $state): string => $state === Cancellation::OPEN ? 'warning' : 'success'),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')->label('Status')->options([Cancellation::OPEN => 'Offen', Cancellation::SETTLED => 'Abgerechnet', Cancellation::WAIVED => 'Erlassen'])->default(Cancellation::OPEN),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('booking')->label('Buchung')->icon(Heroicon::OutlinedArrowTopRightOnSquare)->color('gray')
|
||||
->url(fn (Cancellation $record): string => BookingResource::getUrl('view', ['record' => $record->booking])),
|
||||
Action::make('decide')
|
||||
->label('Kosten festlegen')
|
||||
->icon(Heroicon::OutlinedPencilSquare)
|
||||
->visible(fn (Cancellation $record): bool => $record->status === Cancellation::OPEN)
|
||||
->fillForm(fn (Cancellation $record): array => ['final_fee' => $record->final_fee ?? $record->calculated_fee, 'note' => $record->note])
|
||||
->schema([
|
||||
EuroInput::make('final_fee')->label('Endgültige Stornokosten')->required(),
|
||||
Textarea::make('note')->label('Begründung / Notiz')->rows(2),
|
||||
])
|
||||
->action(fn (array $data, Cancellation $record) => $record->update(['final_fee' => $data['final_fee'], 'note' => $data['note']])),
|
||||
Action::make('settle')
|
||||
->label('Abgerechnet')
|
||||
->icon(Heroicon::OutlinedCheck)
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Die Stornokosten sind beglichen bzw. Rückzahlung und Forderung sind erledigt.')
|
||||
->visible(fn (Cancellation $record): bool => $record->status === Cancellation::OPEN)
|
||||
->action(fn (Cancellation $record) => $record->update(['status' => Cancellation::SETTLED, 'settled_at' => now()])),
|
||||
Action::make('waive')
|
||||
->label('Erlassen')
|
||||
->icon(Heroicon::OutlinedXMark)
|
||||
->color('gray')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Es werden keine Stornokosten berechnet.')
|
||||
->visible(fn (Cancellation $record): bool => $record->status === Cancellation::OPEN)
|
||||
->action(fn (Cancellation $record) => $record->update(['status' => Cancellation::WAIVED, 'settled_at' => now()])),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$open = Cancellation::query()->where('status', Cancellation::OPEN)->count();
|
||||
|
||||
return $open > 0 ? (string) $open : null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeColor(): string
|
||||
{
|
||||
return 'warning';
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListCancellations::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Cancellations\Pages;
|
||||
|
||||
use App\Filament\Concerns\ListsCurrentProperty;
|
||||
use App\Filament\Resources\Cancellations\CancellationResource;
|
||||
use App\Models\Property;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListCancellations extends ListRecords
|
||||
{
|
||||
use ListsCurrentProperty;
|
||||
|
||||
protected static string $resource = CancellationResource::class;
|
||||
|
||||
protected function scopeToProperty(Builder $query, Property $property): Builder
|
||||
{
|
||||
return $query->whereHas('booking', fn (Builder $booking) => $booking->where('property_id', $property->id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContractAnnexes;
|
||||
|
||||
use App\Filament\Concerns\FollowsAdminMode;
|
||||
use App\Filament\Resources\ContractAnnexes\Pages\CreateContractAnnex;
|
||||
use App\Filament\Resources\ContractAnnexes\Pages\EditContractAnnex;
|
||||
use App\Filament\Resources\ContractAnnexes\Pages\ListContractAnnexes;
|
||||
use App\Models\Channel;
|
||||
use App\Models\ContractAnnex;
|
||||
use App\Models\Extra;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Contract annexes as documents of their own, versioned, with a condition that decides per booking whether the
|
||||
* annex is attached (always, when an extra service is booked, for a portal, only by hand).
|
||||
*/
|
||||
class ContractAnnexResource extends Resource
|
||||
{
|
||||
use FollowsAdminMode;
|
||||
|
||||
protected static ?string $model = ContractAnnex::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPaperClip;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
|
||||
|
||||
protected static ?string $modelLabel = 'Vertragsanlage';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Vertragsanlagen';
|
||||
|
||||
protected static ?int $navigationSort = 8;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->label('Name (intern)')->required()->maxLength(120)->helperText('z. B. „WLAN“, „Wäschepaket“, „Key Pickup“. Versionen haben denselben Namen.'),
|
||||
TextInput::make('title')->label('Überschrift im Vertrag')->required()->maxLength(200),
|
||||
Select::make('condition_type')
|
||||
->label('Wann wird die Anlage angehängt?')
|
||||
->options([
|
||||
ContractAnnex::ALWAYS => 'Immer, wenn die Vorlage sie enthält',
|
||||
ContractAnnex::EXTRA => 'Wenn eine bestimmte Zusatzleistung gebucht ist',
|
||||
ContractAnnex::CHANNEL => 'Nur bei Buchungen über ein bestimmtes Portal',
|
||||
ContractAnnex::MANUAL => 'Nur von Hand (im Angebot auswählen)',
|
||||
])
|
||||
->default(ContractAnnex::ALWAYS)
|
||||
->required()
|
||||
->live(),
|
||||
Select::make('condition_id')
|
||||
->label('Zusatzleistung / Portal')
|
||||
->options(fn (Get $get): array => match ($get('condition_type')) {
|
||||
ContractAnnex::EXTRA => Extra::query()->orderBy('name')->pluck('name', 'id')->all(),
|
||||
ContractAnnex::CHANNEL => Channel::query()->orderBy('name')->pluck('name', 'id')->all(),
|
||||
default => [],
|
||||
})
|
||||
->visible(fn (Get $get): bool => in_array($get('condition_type'), [ContractAnnex::EXTRA, ContractAnnex::CHANNEL], true))
|
||||
->required(fn (Get $get): bool => in_array($get('condition_type'), [ContractAnnex::EXTRA, ContractAnnex::CHANNEL], true)),
|
||||
RichEditor::make('body')
|
||||
->label('Text der Anlage (mit Platzhaltern wie {{ mieter }}, {{ wohnung.wlan_passwort }})')
|
||||
->toolbarButtons([['bold', 'italic', 'underline', 'link'], ['h2', 'h3'], ['bulletList', 'orderedList'], ['undo', 'redo']])
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
Textarea::make('notes')->label('Interne Notiz')->rows(2)->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('name')
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Anlage')->weight('medium')->searchable(),
|
||||
TextColumn::make('version')->label('Version')->badge(),
|
||||
TextColumn::make('condition')->label('Bedingung')->state(fn (ContractAnnex $record): string => match ($record->condition_type) {
|
||||
ContractAnnex::EXTRA => 'Zusatzleistung: '.(Extra::query()->find($record->condition_id)?->name ?? '?'),
|
||||
ContractAnnex::CHANNEL => 'Portal: '.(Channel::query()->find($record->condition_id)?->name ?? '?'),
|
||||
ContractAnnex::MANUAL => 'Nur von Hand',
|
||||
default => 'Immer',
|
||||
}),
|
||||
IconColumn::make('used')->label('In Angeboten')->boolean()->state(fn (ContractAnnex $record): bool => $record->isUsed()),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
Action::make('newVersion')
|
||||
->label('Neue Version')
|
||||
->icon(Heroicon::OutlinedDocumentDuplicate)
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Es wird eine Kopie mit der nächsten Versionsnummer angelegt. Die bisherige Version bleibt unverändert.')
|
||||
->action(function (ContractAnnex $record): void {
|
||||
Notification::make()->title('Version '.$record->newVersion()->version.' angelegt')->success()->send();
|
||||
}),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A version used in an offer is a document of record and is never edited; a new version is made instead.
|
||||
*/
|
||||
public static function canEdit(Model $record): bool
|
||||
{
|
||||
return ! $record->isUsed();
|
||||
}
|
||||
|
||||
public static function canDelete(Model $record): bool
|
||||
{
|
||||
return ! $record->isUsed();
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListContractAnnexes::route('/'),
|
||||
'create' => CreateContractAnnex::route('/create'),
|
||||
'edit' => EditContractAnnex::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContractAnnexes\Pages;
|
||||
|
||||
use App\Filament\Resources\ContractAnnexes\ContractAnnexResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateContractAnnex extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ContractAnnexResource::class;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['version'] = 1;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContractAnnexes\Pages;
|
||||
|
||||
use App\Filament\Resources\ContractAnnexes\ContractAnnexResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditContractAnnex extends EditRecord
|
||||
{
|
||||
protected static string $resource = ContractAnnexResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [DeleteAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContractAnnexes\Pages;
|
||||
|
||||
use App\Filament\Resources\ContractAnnexes\ContractAnnexResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListContractAnnexes extends ListRecords
|
||||
{
|
||||
protected static string $resource = ContractAnnexResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [CreateAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,10 @@
|
||||
namespace App\Filament\Resources\ContractTemplates\Schemas;
|
||||
|
||||
use App\Documents\ContractPlaceholders;
|
||||
use App\Models\CancellationPolicy;
|
||||
use App\Models\ContractAnnex;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Section;
|
||||
@@ -26,6 +29,16 @@ public static function configure(Schema $schema): Schema
|
||||
->helperText('z. B. „Direktbuchung“ oder „Portal XY“. Versionen derselben Vorlage haben denselben Namen.'),
|
||||
TextInput::make('version')->label('Version')->integer()->default(1)->disabled()->dehydrated(false)
|
||||
->helperText('Neue Versionen entstehen über „Neue Version“ in der Liste. Eine Vorlage, die in einem Angebot verwendet wurde, kann nicht mehr geändert werden.'),
|
||||
Select::make('cancellation_policy_id')
|
||||
->label('Stornoregel')
|
||||
->options(fn (): array => CancellationPolicy::query()->orderBy('name')->pluck('name', 'id')->all())
|
||||
->placeholder('Keine – Stornokosten von Hand')
|
||||
->helperText('Stufen und Berechnungsgrundlage für die automatische Berechnung der Stornokosten. Im Vertragstext mit {{ storno_regel }} einfügbar.'),
|
||||
Select::make('annex_ids')
|
||||
->label('Mögliche Anlagen dieser Vorlage')
|
||||
->multiple()
|
||||
->options(fn (): array => ContractAnnex::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractAnnex $annex): array => [$annex->id => $annex->label()])->all())
|
||||
->helperText('Welche davon einem Angebot angehängt werden, entscheidet die Bedingung der Anlage (z. B. gebuchte Zusatzleistung). Im Angebot lässt sich die Auswahl ändern.'),
|
||||
Section::make('Vertragsdokument')
|
||||
->description('Der ganze Vertrag als ein Text mit Platzhaltern (siehe unten). Ist hier etwas eingetragen, wird dieser Text als Mietvertrag verwendet – mit Briefkopf, Anrede, Paragrafen und optionaler Anlage. Leer lassen, um nur die Textbausteine darunter zu verwenden.')
|
||||
->columnSpanFull()
|
||||
|
||||
Reference in new issue
Block a user