components([ Select::make('methode_id') ->label('Methoden') ->options(Methode::pluck('name', 'id')) ->rules(['required']) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshMethods'); })->validationMessages([ 'required' => 'Die Eingabe einer Methode ist erforderlich.', ]) ->live(), Select::make('aufstellung_id') ->visible(fn (Get $get): bool => ! in_array($get('methode_id'), [1, 5])) ->label('Aufstellung') ->options(Aufstellung::pluck('name', 'id')) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshMethods'); }), TextInput::make('faktor') ->visible(fn (Get $get): bool => $get('methode_id') != 1) ->suffixIcon('phosphor-function') ->numeric() ->label('Fläche') ->rules(['required']) ->validationMessages([ 'required' => 'Die Eingabe einer Fläche ist erforderlich.', ]) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshMethods'); }), ])->columns(1); } public function table(Table $table): Table { return $table ->striped() ->recordTitleAttribute('raumart') ->defaultPaginationPageOption(50) ->columns([ TextColumn::make('methode.name'), TextColumn::make('aufstellung.name'), TextColumn::make('raumart') ->searchable(), TextColumn::make('faktor') ->numeric(2, ',') ->icon('phosphor-function') ->searchable() ->label('Faktor'), ]) ->recordActions([ EditAction::make()->iconButton(), DeleteAction::make() ->iconButton() ->modalDescription(new HtmlString('Es werden auch alle damit verbundenen Räume im Detail gelöscht.')) ->after(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); })->successNotification( Notification::make() ->success() ->title('Raume Methode gelöscht') ->body('Inclusive aller damit verbundenen Räume im Detail.'), ), ]) ->filters([ SelectFilter::make('methodes') ->label('Methoden') ->relationship('methode', 'name'), TernaryFilter::make('methode_id') ->label('Methode ist zugeordnet'), TernaryFilter::make('faktor') ->label('Faktor fehlt') ->queries( true: fn (Builder $query) => $query->where('faktor', '=', 0), false: fn (Builder $query) => $query->where('faktor', '>', 0), ), ], FiltersLayout::AboveContent) ->deferFilters(false) ->filtersFormColumns(4) ->headerActions([ Action::make('Wohnnutzfläche') ->tooltip('Setzt alle leeren Felder auf "Normale Wohnnutzfläche"') ->icon('phosphor-arrow-bend-right-down') ->action(function (): void { ProjektMethode::where('projekte_id', '=', $this->ownerRecord->id)->where('methode_id', '=', 0)->update(['methode_id' => 1]); })->after(function (Component $livewire) { $livewire->dispatch('refreshMethods'); Notification::make() ->title('Alle leeren Felder wurden auf "Normale Wohnnutzfläche" gesetzt.') ->success() ->send(); }), Action::make('methoden') ->icon('phosphor-question') ->modalCancelAction(fn (Action $action) => $action->label('Schließen')) ->modalSubmitAction(false) ->modalHeading('Hilfe zu Methoden') ->slideOver() ->modalContent(view('filament.pages.actions.methoden')), Action::make('erstellen') ->action(fn (CreateProjektMethoden $createProjektMethoden) => $createProjektMethoden->create($this->ownerRecord)) ->requiresConfirmation() ->hidden(fn (): bool => $this->ownerRecord->bezahlt_am ? false : true) ->modalHeading('Raum Methoden erstellen') ->modalDescription(new HtmlString('Daten werden aus der Tabelle "Objekte im Detail" generiert. Änderungen werden übernommen nicht mehr verwendete Objekte gelöscht.
Um die Tabelle neu zu generieren bitte die Tabelle vorher leeren.')) ->modalSubmitActionLabel('Generieren') ->label('Generieren') ->tooltip('Daten werden aus der Tabelle "Objekte im Detail" generiert.') ->icon('heroicon-o-cog-8-tooth') ->extraModalFooterActions([ Action::make('delete') ->label('Leeren') ->color('danger') ->requiresConfirmation() ->action(function () { ProjektMethode::where('projekte_id', $this->ownerRecord->id)->delete(); Notification::make() ->title('Tabelle "Raum Methode" wurde geleert') ->success() ->send(); }), ]) ->after(function (Component $livewire) { $livewire->dispatch('refreshMethods'); }), ]) ->toolbarActions([ BulkActionGroup::make([ BulkAction::make('faktor') ->color('primary') ->label('Faktor zuweisen') ->schema([ TextInput::make('faktor') ->prefixIcon('phosphor-function') ->numeric() ->required(), ]) ->icon('phosphor-function') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { /** @var object $record */ ProjektMethode::where('id', '=', $record->id) ->update( ['faktor' => $data['faktor']] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshMethods'); }), BulkAction::make('methode') ->color('primary') ->label('Methode zuweisen') ->schema([ Select::make('methode_id') ->label('Methode') ->prefixIcon('phosphor-calculator') ->options(Methode::pluck('name', 'id')) ->required(), ]) ->icon('phosphor-calculator') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { /** @var object $record */ ProjektMethode::where('id', '=', $record->id) ->update( ['methode_id' => $data['methode_id']] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshMethods'); }), BulkAction::make('aufstellung') ->color('primary') ->label('Aufstellung zuweisen') ->schema([ Select::make('aufstellung_id') ->label('Aufstellung') ->prefixIcon('phosphor-finn-the-human') ->options(Aufstellung::pluck('name', 'id')) ->required(), ]) ->icon('phosphor-finn-the-human') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { /** @var object $record */ ProjektMethode::where('id', '=', $record->id) ->update( ['aufstellung_id' => $data['aufstellung_id']] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshMethods'); }), ]), ]); } }