151 lines
6.4 KiB
PHP
151 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Projektes\Pages;
|
|
|
|
use App\Actions\Validation\GutachtenValidation;
|
|
use App\Filament\Resources\Projektes\ProjekteResource;
|
|
use App\Models\Konto;
|
|
use App\Models\Projekte;
|
|
use App\Traits\HasBackUrl;
|
|
use Carbon\Carbon;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\ActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Illuminate\Support\Facades\Auth;
|
|
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 [
|
|
/**
|
|
* FREISCHALTEN
|
|
* auth()->user()->konto->guthaben
|
|
*/
|
|
Action::make('freischalten')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? true : false)
|
|
->color('success')
|
|
->visible(fn (): bool => (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('primary')
|
|
->icon('phosphor-currency-eur')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? true : false)
|
|
->visible(fn (): bool => Auth::user()->konto->guthaben == 0)
|
|
->label('Konto laden')
|
|
->tooltip('Konto laden (Dirket nur bei Büro AVF möglich).')
|
|
->action(function () {
|
|
Konto::where('id', Auth::user()->konto_id)->update(['guthaben' => 10]);
|
|
}),
|
|
// ->requiresConfirmation()
|
|
// ->modalHeading('Kein Guthaben')
|
|
// ->modalIcon('heroicon-o-exclamation-triangle')
|
|
// ->modalDescription('Bitte laden sie Ihr Konto auf. (nicht aktive)')
|
|
// ->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';
|
|
}
|
|
}
|