141 lines
5.9 KiB
PHP
141 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Projektes\RelationManagers;
|
|
|
|
use App\Filament\Imports\ImportAllgemeinDirect;
|
|
use App\Models\ProjektAllgemeinflaechen;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\Hidden;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\Summarizers\Sum;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Support\HtmlString;
|
|
use Livewire\Component;
|
|
|
|
class ProjektAllgemeinflaechensRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'projekt_allgemeinflaechens';
|
|
|
|
protected static ?string $title = 'Allgemeinflächen';
|
|
|
|
protected static ?string $navigationLabel = 'Allgemeinflächen';
|
|
|
|
protected static ?string $modelLabel = 'Allgemeinflächen';
|
|
|
|
protected static ?string $pluralModelLabel = 'Allgemeinflächen';
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Hidden::make('added_manuel')->default(1),
|
|
TextInput::make('geschoss')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('raumart')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('flaeche')
|
|
->suffix(new HtmlString(' m²'))
|
|
->numeric()
|
|
->label('Fläche')
|
|
->rules(['required', 'flaeche' => 'decimal:2'])
|
|
->validationMessages([
|
|
'required' => 'Die Eingabe einer Fläche ist erforderlich.',
|
|
'decimal' => 'Für die Fläche sind zwei Dezimalstellen erforderlich.',
|
|
]),
|
|
])->columns(3);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->emptyStateDescription('Bitte Projekt zuerst freischalten und dann die Daten der Allgemeinflächen hochladen.')
|
|
->striped()
|
|
->recordTitleAttribute('geschoss')
|
|
->defaultPaginationPageOption(50)
|
|
->columns([
|
|
TextColumn::make('geschoss')->searchable()->sortable(),
|
|
TextColumn::make('raumart')->searchable()->sortable(),
|
|
TextColumn::make('flaeche')
|
|
->numeric(
|
|
decimalPlaces: 2,
|
|
decimalSeparator: ',',
|
|
thousandsSeparator: '.'
|
|
)
|
|
->summarize(Sum::make()->label('Gesammt')->numeric(
|
|
decimalPlaces: 2,
|
|
)->suffix(new HtmlString(' m²')))
|
|
->suffix(new HtmlString(' m²'))
|
|
->width('2rem')
|
|
->alignment('right')
|
|
->label('Fläche')
|
|
->searchable(),
|
|
])
|
|
->headerActions([
|
|
Action::make('import-text')
|
|
->icon('phosphor-upload')
|
|
->hidden(fn (): bool => $this->ownerRecord->bezahlt_am ? false : true)
|
|
->modalIcon('phosphor-file-csv')
|
|
->color('info')
|
|
->label('Hochladen')
|
|
->modalHeading('Allgemeinflächen hochladen')
|
|
->modalDescription(new HtmlString('<b>Objekte werden immer hinzugefügt!</b><br/>Spalten Separator:<br/>Strichpunkt ";" oder Pfeife "|"<br/>Immer vier Spalten verwenden, erste Spalte wird ignoriert.<br/><br/>Beispiel:<br/>Allgemein | EG | Eingang | 15,35<br/>Allgemein | EG | Eingang/ Stiegenhaus | 27,16'))
|
|
->schema([
|
|
Textarea::make('upload_data')
|
|
->required()
|
|
->label('Text hier einfügen:')
|
|
->extraInputAttributes(['onClick' => 'this.select()'])
|
|
->rows(5),
|
|
|
|
])
|
|
->action(function (array $data): void {
|
|
ImportAllgemeinDirect::run($data, $this->ownerRecord->id);
|
|
}),
|
|
Action::make('leeren')
|
|
->action(function () {
|
|
ProjektAllgemeinflaechen::where('projekte_id', $this->ownerRecord->id)->delete();
|
|
})
|
|
->icon('phosphor-trash')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->successNotification(
|
|
Notification::make()
|
|
->success()
|
|
->title('Allgemeinflächen gelöscht'),
|
|
),
|
|
CreateAction::make()
|
|
->hidden(fn (): bool => $this->ownerRecord->bezahlt_am ? false : true)
|
|
->icon('phosphor-file-plus')
|
|
->createAnother(false),
|
|
])
|
|
->recordActions([
|
|
EditAction::make()->iconButton()
|
|
->after(function (Component $livewire) {
|
|
$livewire->dispatch('refreshProjektAllgemeinflaechen');
|
|
}),
|
|
DeleteAction::make()->iconButton()->after(function (Component $livewire) {
|
|
$livewire->dispatch('refreshProjektAllgemeinflaechen');
|
|
}),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make()
|
|
->after(function (Component $livewire) {
|
|
$livewire->dispatch('refreshProjektAllgemeinflaechen');
|
|
}),
|
|
]),
|
|
]);
|
|
}
|
|
}
|