components([ TextInput::make('top_nummer') ->required() ->maxLength(255), 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('refreshProjektRaeumealle'); })->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 ->striped() ->recordTitleAttribute('top_nummer') ->columns([ TextColumn::make('top_nummer') ->extraAttributes(['pointer-events' => 'none']) ->searchable() ->label('Top'), TextColumn::make('geschoss')->searchable(), TextColumn::make('raumart')->searchable(), TextInputColumn::make('faktor') ->suffixIcon('phosphor-function') ->width('1rem') ->rules(['required', 'faktor' => 'decimal:0,2']) ->searchable() ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshProjektRaeumealle'); })->validationMessages([ 'required' => 'Die Eingabe eines Faktors ist erforderlich.', 'decimal' => 'Für den Faktors sind zwei Dezimalstellen erforderlich.', ]), TextInputColumn::make('flaeche') ->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('refreshProjektRaeumealle'); })->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') ->searchable() ->options(function (): array { return ProjektRaeumealle::where('projekte_id', $this->getOwnerRecord()->id)->groupBy('top_nummer')->orderBy('top_nummer')->pluck('top_nummer', 'top_nummer')->toArray(); }), SelectFilter::make('geschoss') ->searchable() ->options(function (): array { return ProjektRaeumealle::where('projekte_id', $this->getOwnerRecord()->id)->groupBy('geschoss')->orderBy('geschoss')->pluck('geschoss', 'geschoss')->toArray(); }), SelectFilter::make('raumart') ->searchable() ->options(function (): array { return ProjektRaeumealle::where('projekte_id', $this->getOwnerRecord()->id)->groupBy('raumart')->orderBy('raumart')->pluck('raumart', 'raumart')->toArray(); }), ]) // ], layout: FiltersLayout::AboveContentCollapsible) ->headerActions([ CreateAction::make() ->icon('phosphor-file-plus') ->createAnother(false), ImportAction::make() ->importer(ProjektRaeumealleImporter::class) ->label('Hochladen') ->icon('phosphor-upload') ->color('info') ->options([ 'projekte_id' => $this->getOwnerRecord()->id, ]) ->fileRules([ File::types(['csv', 'txt'])->max(1024), ]), ]) ->recordActions([ EditAction::make()->iconButton() ->mutateDataUsing(function (array $data): array { $data['nutzwert'] = round($data['faktor'] * $data['flaeche']); return $data; })->after(function (Component $livewire) { $livewire->dispatch('refreshProjektRaeumealle'); }), DeleteAction::make()->iconButton()->after(function (Component $livewire) { $livewire->dispatch('refreshProjektRaeumealle'); }), ]) ->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); ProjektRaeumealle::where('id', '=', $record->id) ->update( [ 'faktor' => $data['faktor'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshProjektRaeumealle'); }), DeleteBulkAction::make()->after(function (Component $livewire) { $livewire->dispatch('refreshProjektRaeumealle'); }), ]), ]); } }