216 lines
9.6 KiB
PHP
216 lines
9.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Projektes\Pages;
|
|
|
|
use App\Actions\Cloning\Reparieren;
|
|
use App\Actions\Validation\GutachtenValidation;
|
|
use App\Filament\Resources\Projektes\ProjekteResource;
|
|
use App\Models\Konto;
|
|
use App\Models\Projekte;
|
|
use App\Models\ProjektMethode;
|
|
use App\Models\ProjektObjekteImDetail;
|
|
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 Illuminate\Support\HtmlString;
|
|
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'),
|
|
/**
|
|
* 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(function ($record) {
|
|
return 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(function ($record) {
|
|
return 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(function ($record) {
|
|
return route('pdf', ['record' => $record, 'part' => 'paragraph']);
|
|
})
|
|
->openUrlInNewTab(),
|
|
])->label('Pdf')
|
|
->icon('phosphor-download')
|
|
->color('gray')
|
|
->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('gray')
|
|
->button(),
|
|
|
|
/**
|
|
* ADMIN
|
|
*/
|
|
ActionGroup::make([
|
|
/**
|
|
* EVALUATE
|
|
*/
|
|
Action::make('evaluate_gutachten')
|
|
->color('primary')
|
|
// ->hidden(fn ($record): bool => $record->bezahlt_am && ! $record->evaluation_gutachten ? false : true)
|
|
->label('Daten überprüfen')
|
|
->icon('phosphor-eye')
|
|
->action(function ($record): void {
|
|
GutachtenValidation::run($record);
|
|
$this->record->refresh();
|
|
}),
|
|
DeleteAction::make()->icon('heroicon-o-trash')
|
|
->label('Projekt löschen')
|
|
->modalDescription('Möchten Sie dieses Projekt wirklich löschen? Die Daten werden unwiderbringlich gelöscht, dieser Vorgang kann nicht rückgängig gemacht werden.')
|
|
->requiresConfirmation(),
|
|
|
|
Action::make('fix_cloned_method_id')
|
|
->label('Fix cloned Method Id')
|
|
->tooltip('Visible only by me')
|
|
->visible(fn () => Auth::user()->id == 1)
|
|
->icon('phosphor-arrow-fat-line-right-fill')
|
|
->modalIcon('phosphor-arrow-fat-line-right-fill')
|
|
->action(function ($record): void {
|
|
$res = ProjektObjekteImDetail::where('projekte_id', $record->id)->get();
|
|
foreach ($res as $row) {
|
|
$projekt_methode_id = ProjektMethode::where('cloned_from_id', $row->projekt_methode_id)->value('id');
|
|
if ($projekt_methode_id) {
|
|
ProjektObjekteImDetail::where('id', $row->id)->update(['projekt_methode_id' => $projekt_methode_id]);
|
|
}
|
|
}
|
|
}),
|
|
Action::make('reparieren')
|
|
->label('Daten reparieren ..')
|
|
// ->tooltip('Visible only by me')
|
|
// ->visible(fn () => Auth::user()->id == 1)
|
|
->modalIcon('phosphor-arrow-fat-line-right-fill')
|
|
->modalDescription(self::reparierenText())
|
|
// ->hidden(fn ($record): bool => ! $record->cloned_from_id)
|
|
->action(fn ($record) => Reparieren::run($record))
|
|
->icon('phosphor-arrow-fat-line-right-fill'),
|
|
])->label('Admin')
|
|
->icon('phosphor-user-circle')
|
|
->button(),
|
|
|
|
];
|
|
}
|
|
|
|
protected function getSavedNotificationTitle(): ?string
|
|
{
|
|
return 'Projekt Änderungen gespeichert';
|
|
}
|
|
|
|
protected function reparierenText(): ?HtmlString
|
|
{
|
|
$txt = '<div class="font-bold">Geklonte Projekte</div>';
|
|
$txt .= '<ol class="list-decimal">';
|
|
$txt .= '<li>Es werden Änderungen vom originalen <u>Objekt</u> und <u>Objekt im Detail</u> übernommen.</li>';
|
|
$txt .= '<li>Es werden gelöschte <u>Objekt</u> und <u>Objekt im Detail</u> ergänzt.</li>';
|
|
$txt .= '<li>Elemente ohne Verbindung zum Originale werden gelöscht.</li>';
|
|
$txt .= '</ol>';
|
|
$txt .= '<div class="font-bold">Alle Projekte</div>';
|
|
$txt .= '<ol class="list-decimal">';
|
|
$txt .= '<li><u>Objekt</u> ohne verbundene <u>Objekt im Detail</u> werden gelöscht.</li>';
|
|
$txt .= '<li><u>Objekt im Detail</u> ohne Verbindung zu einem <u>Objekt</u> werden gelöscht.</li>';
|
|
$txt .= '<li>Manuell hinzugefügte Elemente werden nicht gelöscht.</li>';
|
|
// $txt .= '<li>Doppelte <u>Objekt</u> oder <u>Objekt im Detail</u> werden gelöscht.</li>';
|
|
$txt .= '</ol>';
|
|
|
|
return new HtmlString($txt);
|
|
}
|
|
}
|