components([ Select::make('projekt_objekte_id') ->relationship('top_nummer', 'top_nummer', fn (Builder $query) => $query->where('projekte_id', $this->getOwnerRecord()->id)) ->required() ->searchable(), TextInput::make('geschoss') ->required() ->maxLength(255), TextInput::make('raumart') ->required() ->maxLength(255), TextInput::make('flaeche') ->suffix(new HtmlString(' m²')) ->rules(['required', 'flaeche' => 'decimal:2']) ->label('Fläche') ->validationMessages([ 'required' => 'Die Eingabe einer Fläche ist erforderlich.', 'decimal' => 'Für die Fläche sind zwei Dezimalstellen erforderlich.', ]) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshProjektAllgemeinflaechen'); }), TextInput::make('faktor') ->suffixIcon('phosphor-function') ->rules(['required', 'faktor' => 'decimal:0,2']) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); })->validationMessages([ 'required' => 'Die Eingabe eines Faktors ist erforderlich.', 'decimal' => 'Für den Faktors sind zwei Dezimalstellen erforderlich.', ]), ]); } public function table(Table $table): Table { return $table ->emptyStateDescription('Schalten Sie das Projekt frei und importieren Sie die Daten der Objekte.') ->striped() ->recordTitleAttribute('top_nummer') ->columns([ TextColumn::make('top_nummer.top_nummer') ->extraAttributes(['pointer-events' => 'none']) ->searchable() ->label('Top'), TextColumn::make('geschoss')->searchable(), TextColumn::make('raumart')->searchable(), TextInputColumn::make('faktor') ->extraInputAttributes(['onClick' => 'this.select()']) ->suffixIcon('phosphor-function') ->width('1rem') ->rules(['required', 'faktor' => 'decimal:0,2']) ->searchable() ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); })->validationMessages([ 'required' => 'Die Eingabe eines Faktors ist erforderlich.', 'decimal' => 'Für den Faktors sind zwei Dezimalstellen erforderlich.', ]), TextInputColumn::make('flaeche') ->extraInputAttributes(['onClick' => 'this.select()']) ->summarize(Sum::make()->label('Gesammt')->numeric( decimalPlaces: 2, )->suffix(new HtmlString(' m²'))) ->suffix(new HtmlString(' m²')) ->width('2rem') ->alignment('right') ->rules(['required', 'flaeche' => 'decimal:2']) ->label('Fläche') ->searchable() ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); })->validationMessages([ 'required' => 'Die Eingabe einer Fläche ist erforderlich.', 'decimal' => 'Für die Fläche sind zwei Dezimalstellen erforderlich.', ]), TextColumn::make('nutzwert') ->alignCenter() ->summarize(Sum::make()->label('Gesammt')) ->weight(FontWeight::ExtraBold), ]) ->filters([ SelectFilter::make('top_nummer') ->label('Top Nummer') ->relationship('top_nummer', 'top_nummer', fn (Builder $query) => $query->where('projekte_id', $this->getOwnerRecord()->id)) ->searchable(), SelectFilter::make('geschoss') ->preload() ->options(function (): array { return ProjektObjekteImDetail::where('projekte_id', $this->getOwnerRecord()->id)->groupBy('geschoss')->orderBy('geschoss')->pluck('geschoss', 'geschoss')->toArray(); }), SelectFilter::make('raumart') ->searchable() ->options(function (): array { return ProjektObjekteImDetail::where('projekte_id', $this->getOwnerRecord()->id)->groupBy('raumart')->orderBy('raumart')->pluck('raumart', 'raumart')->toArray(); }), ]) ->headerActions([ CreateAction::make() ->icon('phosphor-file-plus') ->createAnother(false), ]) ->recordActions([ EditAction::make()->iconButton() ->mutateDataUsing(function (array $data): array { $data['nutzwert'] = round($data['faktor'] * $data['flaeche']); return $data; })->after(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); }), DeleteAction::make()->iconButton()->after(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); }), ]) ->toolbarActions([ BulkActionGroup::make([ BulkAction::make('faktor') ->color('primary') ->label('Faktor zuweisen') ->schema([ TextInput::make('faktor') ->prefixIcon('phosphor-calculator') ->numeric() ->required(), ]) ->icon('phosphor-calculator') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = round($data['faktor'] * $record->flaeche); ProjektObjekteImDetail::where('id', '=', $record->id) ->update( [ 'faktor' => $data['faktor'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); }), DeleteBulkAction::make()->after(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); }), ]), ]); } }