This commit is contained in:
salam committed 2026-05-14 12:01:20 +02:00
1 parent 48deb69379
commit e34fa82499
16 files changed
+235 -228

No files matched your search

@@ -38,24 +38,20 @@ class ImportAllgemeinDirect
}
}
$recipient = auth()->user();
if ($error) {
Notification::make()
->title('Fehlerbeim Import')
->body('Daten konnten nicht in vier Spalten aufgeteilt werden. Falscher Separator?')
->danger()
->send();
->send()
->sendToDatabase($recipient);
} else {
Notification::make()
->title('Allgemeinflächen wurden erfolgreich importiert')
->body($new.' wurden Flächen hinzugefügt')
->success()
->send();
$recipient = auth()->user();
Notification::make()
->title('Allgemeinflächen wurden erfolgreich importiert')
->body($new.' wurden Flächen hinzugefügt')
->body('Es wurden '.$new.' Flächen hinzugefügt')
->success()
->send()
->sendToDatabase($recipient);
}
}
+45 -49
View File
@@ -16,13 +16,11 @@ class ImportObjekteDirect
$data = explode(PHP_EOL, $data['upload_data']);
$has_objekte = ProjektObjekte::where('projekte_id', $projekte_id)->count();
$has_detail = ProjektObjekteImDetail::where('projekte_id', $projekte_id)->count();
$new_objekte = 0;
$new_detail = 0;
$update_objekte = 0;
$update_detail = 0;
$projekt_objekte_check = 0;
$has_objekte_im_detail = ProjektObjekteImDetail::where('projekte_id', $projekte_id)->count();
$new_objekte_im_detail = 0;
$update_objekte_im_detail = 0;
foreach ($data as $row) {
$row = str_replace(';', '|', $row);
@@ -35,69 +33,67 @@ class ImportObjekteDirect
if (is_numeric($flaeche) && $flaeche > 0) {
$projekt_objekte = ProjektObjekte::firstOrCreate([
'projekte_id' => $projekte_id,
'top_nummer' => $top_nummer,
]);
$objekt = ProjektObjekte::where('projekte_id', $projekte_id)
->where('top_nummer', $top_nummer)
->first();
if ($projekt_objekte->new) { // some way to check
if ($projekt_objekte_check != $projekt_objekte->id) {
$new_objekte++;
}
} else {
if ($projekt_objekte_check != $projekt_objekte->id) {
$update_objekte++;
}
if ($objekt === null) {
$new_objekte++;
$objekt = new ProjektObjekte(['projekte_id' => $projekte_id, 'top_nummer' => $top_nummer]);
$objekt->save();
}
$projekt_objekte_check = $projekt_objekte->id;
$prokectimdetail = ProjektObjekteImDetail::firstOrCreate(
['projekte_id' => $projekte_id, 'projekt_objekte_id' => $projekt_objekte->id, 'geschoss' => $geschoss, 'raumart' => $raumart],
['flaeche' => $flaeche]
);
$objektImDetail = ProjektObjekteImDetail::where('projekte_id', $projekte_id)
->where('projekt_objekte_id', $objekt->id)
->where('geschoss', $geschoss)
->where('raumart', $raumart)
->first();
if ($prokectimdetail->new) { // some way to check
$new_detail++;
if ($objektImDetail === null) {
$new_objekte_im_detail++;
$objektImDetail = new ProjektObjekteImDetail([
'projekte_id' => $projekte_id,
'projekt_objekte_id' => $objekt->id,
'geschoss' => $geschoss,
'raumart' => $raumart,
]);
} else {
$update_detail++;
$update_objekte_im_detail++;
}
$objektImDetail->flaeche = $flaeche;
$objektImDetail->save();
}
}
Notification::make()
->title('Objekte im Detail wurden erfolgreich importiert')
->success()
->send();
/** @var User $user * */
$recipient = Auth::user();
Notification::make()
->title('Objekte im Detail wurden erfolgreich importiert')
->body(self::getBody($has_objekte, $has_detail, $new_objekte, $new_detail, $update_objekte, $update_detail))
->body(self::getBody($has_objekte, $has_objekte_im_detail, $new_objekte, $new_objekte_im_detail, $update_objekte_im_detail))
->success()
->send()
->sendToDatabase($recipient);
}
public static function getBody($has_objekte, $has_detail, $new_objekte, $new_detail, $update_objekte, $update_detail)
public static function getBody($has_objekte, $has_objekte_im_detail, $new_objekte, $new_objekte_im_detail, $update_objekte_im_detail)
{
return new HtmlString('<div class="grid grid-cols-2 gap-2 w-full">
<div class="col-span-2">Objekte</div>
<div>Bestehende</div>
<div>'.$has_objekte.'</div>
<div>Geänderte</div>
<div>'.$update_objekte.'</div>
<div>Neue</div>
<div>'.$new_objekte.'</div>
<div class="col-span-2">Objekte im Detail</div>
<div>Bestehende</div>
<div>'.$has_detail.'</div>
<div>Geänderte</div>
<div>'.$update_detail.'</div>
<div>Neue</div>
<div>'.$new_detail.'</div>
return new HtmlString('<div class="grid grid-cols-4 gap-1 w-full">
<div class="col-span-4 text-gray-500 font-bold">Objekte</div>
<div class="col-span-3 text-primary-500">Vorher</div>
<div class="text-primary-500">'.$has_objekte.'</div>
<div class="col-span-3 text-success-500">Neu</div>
<div class="text-success-500">'.$new_objekte.'</div>
<div class="col-span-4 text-gray-500 font-bold">Objekte im Detail</div>
<div class="col-span-3 text-primary-500">Vorher</div>
<div class="text-primary-500">'.$has_objekte_im_detail.'</div>
<div class="col-span-3 text-success-500">Neu</div>
<div class="text-success-500">'.$new_objekte_im_detail.'</div>
<div class="col-span-3 text-warning-500">Aktualisiert</div>
<div class="text-warning-500">'.$update_objekte_im_detail.'</div>
</div>');
}
}
@@ -35,7 +35,7 @@ class EditProjekte extends EditRecord
Action::make('freischalten')
->hidden(fn ($record): bool => $record->bezahlt_am ? true : false)
->color('success')
->visible(fn (): bool => Auth::user()->konto->guthaben)
->visible(fn (): bool => (bool) Auth::user()->konto->guthaben)
->requiresConfirmation()
->modalHeading('Gutachten freischalten?')
->tooltip('Von Ihrem Guthaben wird ein Punkt abgezogen.')
@@ -6,10 +6,10 @@ use App\Actions\Create\CreateProjektMethoden;
use App\Models\Aufstellung;
use App\Models\Methode;
use App\Models\ProjektMethode;
use App\Models\ProjektObjekteImDetail;
use Filament\Actions\Action;
use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
@@ -17,9 +17,7 @@ use Filament\Notifications\Notification;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\SelectColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\TextInputColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
@@ -83,31 +81,8 @@ class ProjektMethodesRelationManager extends RelationManager
->recordTitleAttribute('raumart')
->defaultPaginationPageOption(50)
->columns([
TextColumn::make('methode.name')
->searchable(),
TextColumn::make('aufstellung.name')
->searchable(),
// SelectColumn::make('methode_id')
// ->label('Methoden')
// ->optionsRelationship('methode', 'name')
// ->preloadOptions()
// ->rules(['required'])
// ->afterStateUpdated(function (Component $livewire) {
// $livewire->dispatch('refreshMethods');
// })->validationMessages([
// 'required' => 'Die Eingabe einer Methode ist erforderlich.',
// ]),
// SelectColumn::make('aufstellung_id')
// ->label('Aufstellung')
// ->optionsRelationship('aufstellung', 'name')
// ->preloadOptions()
// ->rules(['required'])
// ->afterStateUpdated(function (Component $livewire) {
// $livewire->dispatch('refreshMethods');
// })->validationMessages([
// 'required' => 'Die Eingabe einer Aufstellung ist erforderlich.',
// ]),
TextColumn::make('methode.name'),
TextColumn::make('aufstellung.name'),
TextColumn::make('raumart')
->searchable(),
TextColumn::make('faktor')
@@ -115,25 +90,20 @@ class ProjektMethodesRelationManager extends RelationManager
->icon('phosphor-function')
->searchable()
->label('Faktor'),
// TextInputColumn::make('faktor')
// ->extraInputAttributes(['onClick' => 'this.select()'])
// ->suffixIcon('phosphor-function')
// ->width('1rem')
// ->rules(['required', 'faktor' => 'decimal:0,2'])
// ->searchable()
// ->afterStateUpdated(function ($record) {
// $objects = ProjektObjekteImDetail::where('projekte_id', $record['projekte_id'])->where('raumart', $record['raumart'])->get();
// foreach ($objects as $value) {
// $nutzwert = round($record['faktor'] * $value->flaeche, 2);
// ProjektObjekteImDetail::where('id', $value->id)->update(['nutzwert' => $nutzwert]);
// }
// })->validationMessages([
// 'required' => 'Die Eingabe eines Faktors ist erforderlich.',
// 'decimal' => 'Für den Faktors sind zwei Dezimalstellen erforderlich.',
// ]),
])
->recordActions([
EditAction::make()->iconButton(),
DeleteAction::make()
->iconButton()
->modalDescription(new HtmlString('Es werden auch alle damit verbundenen <b>Räume im Detail</b> gelöscht.'))
->after(function (Component $livewire) {
$livewire->dispatch('refreshProjektObjekteImDetail');
})->successNotification(
Notification::make()
->success()
->title('Raume Methode gelöscht')
->body('Inclusive aller damit verbundenen Räume im Detail.'),
),
])
->filters([
SelectFilter::make('methodes')
@@ -150,6 +120,19 @@ class ProjektMethodesRelationManager extends RelationManager
])
->headerActions([
Action::make('Wohnnutzfläche')
->tooltip('Setzt alle leeren Felder auf "Normale Wohnnutzfläche"')
->icon('phosphor-arrow-bend-right-down')
->action(function (): void {
ProjektMethode::where('projekte_id', '=', $this->ownerRecord->id)->where('methode_id', '=', 0)->update(['methode_id' => 1]);
})->after(function (Component $livewire) {
$livewire->dispatch('refreshMethods');
Notification::make()
->title('Alle leeren Felder wurden auf "Normale Wohnnutzfläche" gesetzt.')
->success()
->send();
}),
Action::make('methoden')
->icon('phosphor-question')
->modalCancelAction(fn (Action $action) => $action->label('Schließen'))
@@ -149,7 +149,7 @@ class ProjektObjekteImDetailRelationManager extends RelationManager
->color('info')
->label('Hochladen')
->modalHeading('Objekte im Detail hochladen')
->modalDescription(new HtmlString('<b>Objekte werden immer hinzugefügt!</b><br/>Spalten Separator:<br/>Strichpunkt ";" oder Pfeife "|"<br/>Immer vier Spalten verwenden.<br/><br/>Beispiel:<br/>"APG 01";"UG ";"Stellplatz+ ";"14,25"<br/>"APG 02";"UG ";"Stellplatz";"12,94"'))
->modalDescription(new HtmlString('Daten fixiert auf: <b class="text-primary-500">Top, Geschoss und Raumart</b>. <br/>Bestehen diese wird die Reihe <b>aktualisiert</b>.<br/>Ansonnsten wird ein neue Reihe <b>hinzugefügt</b>!<br/><br/>Separator:<br/>Strichpunkt ";" oder Pfeife "|"<br/>Text ist <b>Vierspaltig</b>.<br/><br/>Beispiel:<br/>"APG 01";"UG ";"Stellplatz+ ";"14,25"<br/>"APG 02";"UG ";"Stellplatz";"12,94"'))
->schema([
Textarea::make('upload_data')
->required()
@@ -10,6 +10,7 @@ use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Select;
@@ -21,6 +22,8 @@ use Filament\Tables\Columns\SelectColumn;
use Filament\Tables\Columns\Summarizers\Sum;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\TextInputColumn;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Collection;
@@ -251,11 +254,26 @@ class ProjektObjekteRelationManager extends RelationManager
->alignCenter(),
])
->filters([
SelectFilter::make('orientierung_id')
->label('Orientierung')
->preload()
->searchable()
->options(function () {
$res = ProjektObjekte::where('projekte_id', $this->ownerRecord->id)
->where('orientierung_id', '>', 0)
->groupBy('orientierung_id')
->select('orientierung_id')
->get()
->toArray();
return Orientierung::whereIn('id', $res)->orderBy('id')->pluck('name', 'id');
}),
TernaryFilter::make('nicht_in_orientierung')
->default(0)
->label('Objekte "Nicht in Orientierung" anzeigen'),
])
->label('"Nicht in Orientierung" anzeigen'),
], FiltersLayout::AboveContent)
->deferFilters(false)
->filtersFormColumns(4)
->recordActions([
EditAction::make()->iconButton()
->mutateDataUsing(function (array $data): array {
@@ -601,6 +619,9 @@ class ProjektObjekteRelationManager extends RelationManager
})->after(function (Component $livewire) {
$livewire->dispatch('refreshOrientierung');
}),
DeleteBulkAction::make()->after(function (Component $livewire) {
$livewire->dispatch('refreshProjektObjekteImDetail');
}),
]),
]);
}