250 lines
11 KiB
PHP
250 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Projektes\Pages;
|
|
|
|
use App\Actions\Validation\GutachtenValidation;
|
|
use App\Filament\Imports\ProjektAllgemeinflaechenImporter;
|
|
use App\Filament\Imports\ProjektObjekteImDetailImporter;
|
|
use App\Filament\Resources\Projektes\ProjekteResource;
|
|
use App\Models\Konto;
|
|
use App\Models\ProjektAllgemeinflaechen;
|
|
use App\Models\Projekte;
|
|
use App\Models\ProjektObjekte;
|
|
use App\Traits\HasBackUrl;
|
|
use Carbon\Carbon;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\ActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\ImportAction;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Illuminate\Validation\Rules\File;
|
|
use Livewire\Attributes\On;
|
|
|
|
class EditProjekte extends EditRecord
|
|
{
|
|
use HasBackUrl;
|
|
|
|
protected static string $resource = ProjekteResource::class;
|
|
|
|
#[On('refreshProjektAllgemeinflaechen'), On('refreshProjektObjekteImDetail'), On('refreshMethods'), On('refreshOrientierung')]
|
|
public function refresh(): void {}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
/**
|
|
* IMPORT
|
|
*/
|
|
ActionGroup::make([
|
|
ImportAction::make('import_allgemeinflaechen')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->importer(ProjektAllgemeinflaechenImporter::class)
|
|
->csvDelimiter('|')
|
|
->modalIcon('phosphor-file-csv')
|
|
->modalHeading('Allgemeinflächen Import')
|
|
->modalContent(view('filament.pages.actions.import-allgemeinflaechen'))
|
|
->modalContentFooter(view('filament.pages.actions.footer-allgemeinflaechen'))
|
|
->label('Allgemeinflächen')
|
|
->icon('phosphor-upload')
|
|
->extraModalFooterActions([
|
|
Action::make('copy')
|
|
->tooltip('Kopiert die Spaltenname für die erste Zeile')
|
|
->color('success')
|
|
->label('Spalten Namen')
|
|
->action(function ($livewire) {
|
|
$livewire->js('window.navigator.clipboard.writeText("Geschoss|Raumart|Fläche");');
|
|
|
|
Notification::make()
|
|
->title('Spaltenname kopiert')
|
|
->success()
|
|
->send();
|
|
}),
|
|
|
|
Action::make('delete')
|
|
->label('Tabelle leeren')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->action(function ($record) {
|
|
ProjektAllgemeinflaechen::where('projekte_id', $record->id)->delete();
|
|
|
|
$this->record->refresh();
|
|
|
|
Notification::make()
|
|
->title('Tabelle geleert')
|
|
->success()
|
|
->send();
|
|
}),
|
|
])
|
|
->options(function ($record) {
|
|
return ['projekte_id' => $record->id];
|
|
})
|
|
->fileRules([
|
|
File::types(['csv', 'txt'])->max(1024),
|
|
]),
|
|
ImportAction::make('import_objekte')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->importer(ProjektObjekteImDetailImporter::class)
|
|
->csvDelimiter('|')
|
|
->modalIcon('phosphor-file-csv')
|
|
->modalHeading('Objekte im Detail Import')
|
|
->modalContent(view('filament.pages.actions.import-objektemitraeumen'))
|
|
->modalContentFooter(view('filament.pages.actions.footer-allgemeinflaechen'))
|
|
->label('Objekte')
|
|
->icon('phosphor-upload')
|
|
->extraModalFooterActions([
|
|
Action::make('copy')
|
|
->tooltip('Kopiert die Spaltenname für die erste Zeile')
|
|
->color('success')
|
|
->label('Spalten Namen')
|
|
->action(function ($livewire) {
|
|
$livewire->js('window.navigator.clipboard.writeText("Top Nummer|Geschoss|Raumart|Fläche");');
|
|
|
|
Notification::make()
|
|
->title('Spaltenname kopiert')
|
|
->success()
|
|
->send();
|
|
}),
|
|
Action::make('delete')
|
|
->tooltip('Löscht alle Objekte für dieses Projekt')
|
|
->label('Tabellen leeren')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->action(function ($record) {
|
|
ProjektObjekte::where('projekte_id', $record->id)->delete();
|
|
|
|
$this->record->refresh();
|
|
|
|
Notification::make()
|
|
->title('Tabellen geleert')
|
|
->success()
|
|
->send();
|
|
}),
|
|
])
|
|
->options(function ($record) {
|
|
return ['projekte_id' => $record->id];
|
|
})
|
|
->fileRules([
|
|
File::types(['csv', 'txt'])->max(1024),
|
|
]),
|
|
])->label('Import')
|
|
->icon('phosphor-upload')
|
|
->color('info')
|
|
->button(),
|
|
/**
|
|
* FREISCHALTEN
|
|
* auth()->user()->konto->guthaben
|
|
*/
|
|
Action::make('freischalten')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? true : false)
|
|
->color('warning')
|
|
->visible(fn (): bool => auth()->user()->konto->guthaben)
|
|
->requiresConfirmation()
|
|
->modalHeading('Gutachten freischalten?')
|
|
->tooltip('Von Ihrem Guthaben wird ein Punkt abgezogen.')
|
|
->modalIcon('phosphor-coins')
|
|
->modalDescription('Von Ihrem Guthaben wird ein Punkt abgezogen.')
|
|
->modalSubmitActionLabel('Bezahlen')
|
|
->action(function ($record) {
|
|
if (Konto::where('id', $record['konto_id'])->where('guthaben', '>', 0)->get()) {
|
|
Konto::where('id', $record['konto_id'])->decrement('guthaben', 1);
|
|
Projekte::where('id', $record['id'])->update(['bezahlt_am' => Carbon::now()]);
|
|
|
|
$this->record->refresh();
|
|
|
|
Notification::make()
|
|
->title('Gutachten freischaltet')
|
|
->success()
|
|
->send();
|
|
}
|
|
}),
|
|
Action::make('bezahlen')
|
|
->color('danger')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? true : false)
|
|
->visible(fn (): bool => ! auth()->user()->konto->guthaben)
|
|
->label('Konto laden')
|
|
->tooltip('Konto laden um Gutachten freizuschalten.')
|
|
->requiresConfirmation()
|
|
->modalHeading('Kein Guthaben')
|
|
->modalIcon('heroicon-o-exclamation-triangle')
|
|
->modalDescription('Bitte laden sie Ihr Konto auf')
|
|
->modalSubmitActionLabel('Konto aufladen'),
|
|
/**
|
|
* EVALUATE
|
|
*/
|
|
Action::make('evaluate_gutachten')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am && ! $record->evaluation_gutachten ? false : true)
|
|
->label('Evaluieren')
|
|
->icon('phosphor-eye')
|
|
->action(function ($record): void {
|
|
GutachtenValidation::controll($record);
|
|
$this->record->refresh();
|
|
}),
|
|
|
|
/**
|
|
* PDF
|
|
*/
|
|
ActionGroup::make([
|
|
/**
|
|
* STANDART TEXT
|
|
*/
|
|
Action::make('make-standard')
|
|
->hidden(fn ($record): bool => (! $record->bezahlt_am || ! $record->evaluation_gutachten) ? true : false)
|
|
->label('Standard Texte')
|
|
->icon('icon-pdf')
|
|
->url(fn ($record) => route('pdf', ['record' => $record, 'part' => 'standard']))
|
|
->openUrlInNewTab(),
|
|
/**
|
|
* NUTZWERTE
|
|
*/
|
|
Action::make('make-nutzwerte-file')
|
|
->hidden(fn ($record): bool => (! $record->bezahlt_am || ! $record->evaluation_gutachten) ? true : false)
|
|
->label('Nutzwertberechnung')
|
|
->icon('icon-pdf')
|
|
->url(fn ($record) => route('pdf', ['record' => $record, 'part' => 'nutzwerte']))
|
|
->openUrlInNewTab(),
|
|
/**
|
|
* PARAGRAPH 6
|
|
*/
|
|
Action::make('make-paragraph')
|
|
->hidden(fn ($record): bool => (! $record->bezahlt_am || ! $record->evaluation_gutachten) ? true : false)
|
|
->label('Auszug gem. §6 ')
|
|
->icon('icon-pdf')
|
|
->url(fn ($record) => route('pdf', ['record' => $record, 'part' => 'paragraph']))
|
|
->openUrlInNewTab(),
|
|
])->label('Pdf')
|
|
->icon('phosphor-download')
|
|
->color('info')
|
|
->button(),
|
|
|
|
/**
|
|
* EXCEL
|
|
*/
|
|
ActionGroup::make([
|
|
Action::make('excel-nutzwerte')
|
|
->label('Nutzfläche & Nutzwerte')
|
|
->icon('icon-excel')
|
|
->url(fn ($record) => route('excelnutzwerte', ['record' => $record]))
|
|
->hidden(fn ($record): bool => (! $record->bezahlt_am || ! $record->evaluation_gutachten) ? true : false)
|
|
->openUrlInNewTab(),
|
|
Action::make('excel-aufstellung')
|
|
->label('Nutzflächen Aufstellung')
|
|
->icon('icon-excel')
|
|
->url(fn ($record) => route('excelaufstellung', ['record' => $record]))
|
|
->hidden(fn ($record): bool => (! $record->bezahlt_am || ! $record->evaluation_gutachten) ? true : false)
|
|
->openUrlInNewTab(),
|
|
])->label('Excel')
|
|
->icon('phosphor-download')
|
|
->color('info')
|
|
->button(),
|
|
DeleteAction::make()->icon('heroicon-o-trash')
|
|
->modalDescription('Möchten Sie dieses Projekt wirklich löschen? Die Daten werden unwiderbringlich gelöscht, dieser Vorgang kann nicht rückgängig gemacht werden.'),
|
|
];
|
|
}
|
|
|
|
protected function getSavedNotificationTitle(): ?string
|
|
{
|
|
return 'Projekt Änderungen gespeichert';
|
|
}
|
|
}
|