- Eigene Webseite als Kanal eigener Art (channels.kind = website), nur zur Konfiguration: Webseiten-Anfragen bleiben direkt (A1) ohne Kanalbezug; der Eintrag nimmt an Sync, Export, Überwachung und Sperraufgaben nicht teil (active()/Property::channels() nur Portale, Feed nur für Portale). - Neue Einstellungen im bestehenden ProcessSetting: Klärungsreservierung automatisch/Freigabe (15/180 min, 0 = keine), Rückfragemodus, Erinnerungen, Folgefragen, Erinnerungsabstand, Linkgültigkeit, Anschrift im Webformular verlangen (Standard: nein). - „Kanäle“ in der einfachen Ansicht: Webseite und Portale an einer Stelle, Verweis auf „Ihre Standards“; „Wirksame Einstellungen“ mit Spalte „Eigene Webseite“ und Herkunft „Webseite“. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
136 lines
6.0 KiB
PHP
136 lines
6.0 KiB
PHP
<?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 = 'Einrichtung';
|
|
|
|
protected static ?string $modelLabel = 'Vertragsanlage';
|
|
|
|
protected static ?string $pluralModelLabel = 'Vertragsanlagen';
|
|
|
|
protected static ?int $navigationSort = 2;
|
|
|
|
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()->portals()->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'),
|
|
];
|
|
}
|
|
}
|