components([
Select::make('projekt_objekte_id')
->relationship('top_nummer', 'top_nummer', fn (Builder $query) => $query->where('projekte_id', $this->getOwnerRecord()->id))
->required()
->searchable(),
Select::make('projekt_methode_id')
->relationship('methode', 'raumart', fn (Builder $query) => $query->where('projekte_id', $this->getOwnerRecord()->id))
->required()
->searchable(),
TextInput::make('geschoss')
->required()
->maxLength(255)
->suffixIcon('phosphor-building'),
TextInput::make('flaeche')
->suffix(new HtmlString(' m²'))
->numeric()
->inputMode('decimal')
->label('Fläche')
->rules(['required'])
->validationMessages([
'required' => 'Die Eingabe einer Fläche ist erforderlich.',
])
->afterStateUpdated(function (Component $livewire) {
$livewire->dispatch('refreshProjektAllgemeinflaechen');
}),
]);
}
public function table(Table $table): Table
{
return $table
->emptyStateDescription('Bitte Projekt freischalten und Daten hochladen.')
->striped()
->recordTitleAttribute('top_nummer')
->defaultPaginationPageOption(50)
->columns([
TextColumn::make('top_nummer.top_nummer')
->sortable()
->extraAttributes(['pointer-events' => 'none'])
->searchable()
->label('Top'),
TextColumn::make('geschoss')->searchable(),
TextColumn::make('methode.raumart')->searchable()->sortable(),
TextColumn::make('methode.faktor')
->numeric(2, ',')
->icon('phosphor-function')
->searchable()
->label('Faktor'),
TextColumn::make('flaeche')
->numeric(2, ',', '.')
->summarize(Sum::make()->label('Gesammt')->numeric(
decimalPlaces: 2,
)->suffix(new HtmlString(' m²')))
->suffix(new HtmlString(' m²'))
->width('2rem')
->alignment('right')
->label('Fläche')
->searchable(),
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))
->preload(),
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('projekt_methode_id')
->label('Methode')
->searchable()
->options(function (): array {
return ProjektMethode::where('projekte_id', $this->getOwnerRecord()->id)->orderBy('raumart')->pluck('raumart', 'id')->toArray();
}),
], FiltersLayout::AboveContent)
->deferFilters(false)
->filtersFormColumns(4)
->headerActions([
Action::make('import-text')
->icon('phosphor-upload')
->modalIcon('phosphor-file-csv')
->hidden(fn (): bool => $this->ownerRecord->bezahlt_am ? false : true)
->color('info')
->label('Hochladen')
->modalHeading('Objekte im Detail hochladen')
->modalDescription(new HtmlString('Daten fixiert auf: Top, Geschoss und Raumart.
Bestehen diese wird die Reihe aktualisiert.
Ansonnsten wird ein neue Reihe hinzugefügt!
Separator:
Strichpunkt ";" oder Pfeife "|"
Text ist Vierspaltig.
Beispiel:
"APG 01";"UG ";"Stellplatz+ ";"14,25"
"APG 02";"UG ";"Stellplatz";"12,94"'))
->schema([
Textarea::make('upload_data')
->required()
->label('Text hier einfügen:')
->extraInputAttributes(['onClick' => 'this.select()'])
->rows(5),
])
->action(function (array $data): void {
ImportObjekteDirect::run($data, $this->ownerRecord->id);
}),
CreateAction::make()
->hidden(fn (): bool => $this->ownerRecord->bezahlt_am ? false : true)
->icon('phosphor-file-plus')
->createAnother(false),
Action::make('nutzwerte')
->label('Nutzwerte')
->icon('phosphor-calculator')
->hidden(fn (): bool => $this->ownerRecord->bezahlt_am ? false : true)
->action(function () {
$res = ProjektObjekteImDetail::with('methode')
->where('projekte_id', $this->getOwnerRecord()->id)
->get();
foreach ($res as $row) {
if ($row->methode?->faktor || null) {
ProjektObjekteImDetail::where('id', $row->id)
->update(['nutzwert' => $row->flaeche * $row->methode->faktor]);
}
}
})->after(function (Component $livewire) {
$livewire->dispatch('refreshProjektObjekteImDetail');
}),
])
->recordActions([
EditAction::make()->iconButton()
->mutateDataUsing(function ($data, $record): array {
if (isset($record->methode->faktor)) {
$data['nutzwert'] = round($record->methode->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([
DeleteBulkAction::make()->after(function (Component $livewire) {
$livewire->dispatch('refreshProjektObjekteImDetail');
}),
]),
]);
}
}