- IMAP-Abruf jede Minute (webklex/php-imap, ohne PHP-imap-Erweiterung) oder signierter Push von n8n - Parser für Buchungs-, Storno- und Anfrage-Mails (de/en), Buchungsnummer, An-/Abreise - Erkannte Buchungen werden sofort gesperrt und an handgepflegte Portale weitergegeben; Kalender-Abgleich übernimmt bzw. ersetzt Mail-Sperren - Unklare Mails: Prüf-Mail + Admin-Liste Portal-E-Mails mit Aktion Sperre anlegen - Überwachung des Postfachs in Monitor und /health/sync Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
161 lines
7.6 KiB
PHP
161 lines
7.6 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Properties\RelationManagers;
|
||
|
||
use App\Actions\SyncChannel;
|
||
use App\Channels\ChannelRegistry;
|
||
use App\Models\Channel;
|
||
use App\Models\ChannelSyncLog;
|
||
use Filament\Actions\Action;
|
||
use Filament\Actions\CreateAction;
|
||
use Filament\Actions\DeleteAction;
|
||
use Filament\Actions\EditAction;
|
||
use Filament\Forms\Components\Select;
|
||
use Filament\Forms\Components\TextInput;
|
||
use Filament\Forms\Components\Toggle;
|
||
use Filament\Infolists\Components\RepeatableEntry;
|
||
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
|
||
use Filament\Infolists\Components\TextEntry;
|
||
use Filament\Notifications\Notification;
|
||
use Filament\Resources\RelationManagers\RelationManager;
|
||
use Filament\Schemas\Components\Group;
|
||
use Filament\Schemas\Components\Utilities\Get;
|
||
use Filament\Schemas\Schema;
|
||
use Filament\Support\Icons\Heroicon;
|
||
use Filament\Tables\Columns\TextColumn;
|
||
use Filament\Tables\Table;
|
||
|
||
class ChannelsRelationManager extends RelationManager
|
||
{
|
||
protected static string $relationship = 'channels';
|
||
|
||
protected static ?string $title = 'Portale & Kanäle';
|
||
|
||
protected static ?string $modelLabel = 'Portal';
|
||
|
||
protected static ?string $pluralModelLabel = 'Portale';
|
||
|
||
public function form(Schema $schema): Schema
|
||
{
|
||
$registry = app(ChannelRegistry::class);
|
||
|
||
return $schema
|
||
->columns(2)
|
||
->components([
|
||
TextInput::make('name')
|
||
->label('Name')
|
||
->placeholder('z. B. FeWo-direkt')
|
||
->required()
|
||
->maxLength(100),
|
||
Select::make('connector')
|
||
->label('Anbindung')
|
||
->options($registry->options())
|
||
->default('ical')
|
||
->live()
|
||
->required(),
|
||
Group::make()
|
||
->columnSpanFull()
|
||
->schema(fn (Get $get): array => filled($get('connector')) ? $registry->connectors()[$get('connector')]::settingsSchema() : []),
|
||
TextEntry::make('export_url')
|
||
->label('Unsere Kalender-Adresse für dieses Portal')
|
||
->helperText('Diese Adresse im Portal unter „Kalender importieren“ eintragen. Sie enthält alle Belegungen außer denen dieses Portals.')
|
||
->state(fn (?Channel $record): ?string => $record?->exportUrl())
|
||
->copyable()
|
||
->visible(fn (?Channel $record): bool => $record !== null)
|
||
->columnSpanFull(),
|
||
TextInput::make('settings.email_senders')
|
||
->label('Absender der Buchungs-E-Mails (Schnellerkennung)')
|
||
->helperText('Komma-getrennt, z. B. „fewo-direkt.de, vrbo.com“. Buchungsbestätigungen dieser Absender werden sofort gesperrt.')
|
||
->maxLength(500)
|
||
->columnSpanFull(),
|
||
Toggle::make('requires_manual_blocking')
|
||
->label('Zusätzlich von Hand sperren (Sofortbuchung)')
|
||
->helperText('Bei jeder Belegung über andere Wege entsteht eine Aufgabe „Im Portal sperren“ – für Portale, die unseren Kalender zu selten abholen.')
|
||
->live()
|
||
->columnSpanFull(),
|
||
TextInput::make('manage_url')
|
||
->label('Link zum Kalender im Vermieterbereich')
|
||
->url()
|
||
->maxLength(2048)
|
||
->visible(fn (Get $get): bool => (bool) $get('requires_manual_blocking'))
|
||
->columnSpanFull(),
|
||
Toggle::make('is_active')
|
||
->label('Aktiv')
|
||
->default(true),
|
||
]);
|
||
}
|
||
|
||
public function table(Table $table): Table
|
||
{
|
||
return $table
|
||
->recordTitleAttribute('name')
|
||
->description('Unser System ist führend: Belegungen der Portale werden alle 5 Minuten eingelesen, jedes Portal erhält einen eigenen Kalender mit allen übrigen Belegungen.')
|
||
->columns([
|
||
TextColumn::make('name')->label('Portal')->weight('medium'),
|
||
TextColumn::make('status')
|
||
->label('Status')
|
||
->badge()
|
||
->state(fn (Channel $record): string => match (true) {
|
||
! $record->is_active => 'Inaktiv',
|
||
! $record->importsOccupations() => 'Nur Export',
|
||
$record->last_error !== null => 'Fehler',
|
||
$record->isStale() => 'Veraltet',
|
||
default => 'OK',
|
||
})
|
||
->color(fn (string $state): string => match ($state) {
|
||
'OK' => 'success',
|
||
'Fehler', 'Veraltet' => 'danger',
|
||
default => 'gray',
|
||
})
|
||
->tooltip(fn (Channel $record): ?string => $record->last_error),
|
||
TextColumn::make('last_success_at')->label('Letzter Abgleich')->since()->placeholder('–'),
|
||
TextColumn::make('requires_manual_blocking')
|
||
->label('Handpflege')
|
||
->formatStateUsing(fn (bool $state): string => $state ? 'ja' : '–'),
|
||
])
|
||
->headerActions([
|
||
CreateAction::make(),
|
||
])
|
||
->recordActions([
|
||
Action::make('sync')
|
||
->label('Jetzt abgleichen')
|
||
->icon(Heroicon::OutlinedArrowPath)
|
||
->visible(fn (Channel $record): bool => $record->importsOccupations())
|
||
->action(function (Channel $record, SyncChannel $syncChannel): void {
|
||
$log = $syncChannel->handle($record);
|
||
|
||
$log->successful
|
||
? Notification::make()->title("{$log->events} Belegungen eingelesen")->body("Neu: {$log->added}, geändert: {$log->changed}, entfernt: {$log->removed}, Konflikte: {$log->conflicts}")->success()->send()
|
||
: Notification::make()->title('Abgleich fehlgeschlagen')->body($log->message)->danger()->send();
|
||
}),
|
||
Action::make('logs')
|
||
->label('Protokoll')
|
||
->icon(Heroicon::OutlinedListBullet)
|
||
->color('gray')
|
||
->modalSubmitAction(false)
|
||
->modalCancelActionLabel('Schließen')
|
||
->schema([
|
||
RepeatableEntry::make('recentLogs')
|
||
->hiddenLabel()
|
||
->state(fn (Channel $record): array => $record->syncLogs()->limit(30)->get()->map(fn (ChannelSyncLog $log): array => [
|
||
'time' => $log->created_at->format('d.m. H:i'),
|
||
'result' => $log->successful ? "✓ {$log->events} Belegungen (+{$log->added} ~{$log->changed} -{$log->removed})" : '✗ '.$log->message,
|
||
'conflicts' => $log->conflicts ?: '',
|
||
])->all())
|
||
->table([
|
||
TableColumn::make('Zeit'),
|
||
TableColumn::make('Ergebnis'),
|
||
TableColumn::make('Konflikte'),
|
||
])
|
||
->schema([
|
||
TextEntry::make('time'),
|
||
TextEntry::make('result'),
|
||
TextEntry::make('conflicts'),
|
||
]),
|
||
]),
|
||
EditAction::make(),
|
||
DeleteAction::make(),
|
||
]);
|
||
}
|
||
}
|