193 lines
8.5 KiB
PHP
193 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Projektes\RelationManagers;
|
|
|
|
use App\Filament\Imports\RaeumealleImporter;
|
|
use App\Models\Raeumealle;
|
|
use Filament\Actions\BulkAction;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\ImportAction;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Enums\FontWeight;
|
|
use Filament\Tables\Columns\Summarizers\Sum;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Columns\TextInputColumn;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\HtmlString;
|
|
use Illuminate\Validation\Rules\File;
|
|
use Livewire\Component;
|
|
|
|
class RaeumeallesRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'raeumealles';
|
|
|
|
protected static ?string $title = 'Räume Alle';
|
|
|
|
protected static ?string $navigationLabel = 'Räume';
|
|
|
|
protected static ?string $modelLabel = 'Raum';
|
|
|
|
protected static ?string $pluralModelLabel = 'Räume';
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->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('refreshAllgemeinflaechen');
|
|
}),
|
|
TextInput::make('faktor')
|
|
->suffixIcon('phosphor-function')
|
|
->rules(['required', 'faktor' => 'decimal:0,2'])
|
|
->afterStateUpdated(function (Component $livewire) {
|
|
$livewire->dispatch('refreshRaeumealle');
|
|
})->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('refreshRaeumealle');
|
|
})->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('refreshRaeumealle');
|
|
})->validationMessages([
|
|
'required' => 'Die Eingabe einer Fläche ist erforderlich.',
|
|
'decimal' => 'Für die Fläche sind zwei Dezimalstellen erforderlich.',
|
|
]),
|
|
TextColumn::make('nutzwert')
|
|
->alignCenter()
|
|
->default(fn ($record): ?int => round($record->faktor * $record->flaeche))
|
|
->weight(FontWeight::ExtraBold),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('top_nummer')
|
|
->label('Top Nummer')
|
|
->searchable()
|
|
->options(function (): array {
|
|
return Raeumealle::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 Raeumealle::where('projekte_id', $this->getOwnerRecord()->id)->groupBy('geschoss')->orderBy('geschoss')->pluck('geschoss', 'geschoss')->toArray();
|
|
}),
|
|
SelectFilter::make('raumart')
|
|
->searchable()
|
|
->options(function (): array {
|
|
return Raeumealle::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(RaeumealleImporter::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()->after(function (Component $livewire) {
|
|
$livewire->dispatch('refreshRaeumealle');
|
|
}),
|
|
DeleteAction::make()->iconButton()->after(function (Component $livewire) {
|
|
$livewire->dispatch('refreshRaeumealle');
|
|
}),
|
|
])
|
|
->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) {
|
|
Raeumealle::where('id', '=', $record->id)
|
|
->update(
|
|
['faktor' => $data['faktor']]
|
|
);
|
|
}
|
|
})->after(function (Component $livewire) {
|
|
$livewire->dispatch('refreshRaeumealle');
|
|
}),
|
|
DeleteBulkAction::make()->after(function (Component $livewire) {
|
|
$livewire->dispatch('refreshRaeumealle');
|
|
}),
|
|
]),
|
|
]);
|
|
}
|
|
}
|