162 lines
7.2 KiB
PHP
162 lines
7.2 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 Filament\Actions\Action;
|
|
use Filament\Actions\ActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Livewire\Attributes\On;
|
|
|
|
class EditProjekte extends EditRecord
|
|
{
|
|
protected static string $resource = ProjekteResource::class;
|
|
|
|
#[On('refreshAllgemeinflaechen')]
|
|
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)
|
|
->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\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'),
|
|
/**
|
|
* GUTACHTEN
|
|
*/
|
|
ActionGroup::make([
|
|
Action::make('gutachten')
|
|
->disabled(fn ($record): bool => ! $record->pdf_gutachten_status)
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->color(fn ($record): string => match ($record->pdf_gutachten_status) {
|
|
1 => 'info',
|
|
default => 'gray',
|
|
})
|
|
->label('3) Herunterladen')
|
|
->icon('phosphor-file-pdf')
|
|
->url(fn ($record) => route('standard.download', ['record' => $record, 'mode' => 'file']))
|
|
->openUrlInNewTab(),
|
|
Action::make('make_gutachten')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->color(fn ($record): string => match ($record->evaluation) {
|
|
1 => 'info',
|
|
default => 'gray',
|
|
})
|
|
->disabled(fn ($record): bool => $record->evaluation ? false : true)
|
|
->label('2) Generieren')
|
|
->icon('phosphor-math-operations')
|
|
->url(fn ($record) => route('standard.download', ['record' => $record, 'mode' => 'new']))
|
|
->openUrlInNewTab(),
|
|
Action::make('evaluate_gutachten')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->color(fn ($record): string => match ($record->evaluation) {
|
|
1 => 'success',
|
|
default => 'primary',
|
|
})
|
|
->label('1) Evaluieren')
|
|
->icon(fn ($record): string => match ($record->evaluation) {
|
|
1 => 'phosphor-check',
|
|
default => 'phosphor-eye',
|
|
})
|
|
->action(function ($record): void {
|
|
GutachtenValidation::controll($record);
|
|
$this->record->refresh();
|
|
}),
|
|
])->label('Gutachten')
|
|
->icon('heroicon-m-ellipsis-vertical')
|
|
->button()
|
|
->color('primary'),
|
|
/**
|
|
* NUTZWERTE
|
|
*/
|
|
ActionGroup::make([
|
|
Action::make('nutzwerte')
|
|
->disabled(fn ($record): bool => ! $record->pdf_nutzwerte_status)
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->color(fn ($record): string => match ($record->pdf_gutachten_status) {
|
|
1 => 'info',
|
|
default => 'gray',
|
|
})
|
|
->label('Herunterladen')
|
|
->icon('phosphor-file-pdf')
|
|
->url(fn ($record) => route('nutzwerte.download', ['record' => $record, 'mode' => 'file']))
|
|
->openUrlInNewTab(),
|
|
Action::make('make_nutzwerte')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->label('Neu Berechnen')
|
|
->icon('phosphor-calculator')
|
|
->url(fn ($record) => route('nutzwerte.download', ['record' => $record, 'mode' => 'new']))
|
|
->openUrlInNewTab(),
|
|
])->label('Nutzwerte')
|
|
->icon('heroicon-m-ellipsis-vertical')
|
|
->button()
|
|
->color('primary'),
|
|
/**
|
|
* EXCEL
|
|
*/
|
|
ActionGroup::make([
|
|
Action::make('excel-nutzflaeche-nutzwerte')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->label('Nutzfläche & Nutzwerte')
|
|
->icon('icon-excel')
|
|
->url(fn ($record) => route('excel.download', ['record' => $record, 'mode' => 'file']))
|
|
->openUrlInNewTab(),
|
|
Action::make('excel-nutzflaechen-aufstellung')
|
|
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
|
|
->label('Nutzflächen Aufstellung')
|
|
->icon('icon-excel')
|
|
->url(fn ($record) => route('excel.download', ['record' => $record, 'mode' => 'file']))
|
|
->openUrlInNewTab(),
|
|
])->label('Spreadsheet')
|
|
->icon('heroicon-m-ellipsis-vertical')
|
|
->button()
|
|
->color('primary'),
|
|
DeleteAction::make(),
|
|
];
|
|
}
|
|
|
|
protected function getSavedNotificationTitle(): ?string
|
|
{
|
|
return 'Projekt Änderungen gespeichert';
|
|
}
|
|
}
|