import new

This commit is contained in:
salam committed 2026-04-15 15:59:56 +02:00
1 parent df55380236
commit 228927274d
12 files changed
+272 -207

No files matched your search

@@ -0,0 +1,47 @@
<?php
namespace App\Filament\Imports;
use App\Models\ProjektAllgemeinflaechen;
use Filament\Notifications\Notification;
class ImportAllgemeinDirect
{
public static function run($data, $projekte_id)
{
$data = explode(PHP_EOL, $data['upload_data']);
$new = 0;
foreach ($data as $row) {
$row = str_replace(';', '|', $row);
$cells = explode('|', $row);
$geschoss = trim($cells[1]);
$raumart = trim($cells[2]);
$flaeche = (float) str_replace(',', '.', trim($cells[3]));
if (is_numeric($flaeche) && $flaeche > 0) {
$allgemein = new ProjektAllgemeinflaechen;
$allgemein->projekte_id = $projekte_id;
$allgemein->geschoss = $geschoss;
$allgemein->raumart = $raumart;
$allgemein->flaeche = $flaeche;
$allgemein->save();
$new++;
}
}
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')
->success()
->sendToDatabase($recipient);
}
}
@@ -0,0 +1,99 @@
<?php
namespace App\Filament\Imports;
use App\Models\ProjektObjekte;
use App\Models\ProjektObjekteImDetail;
use Filament\Notifications\Notification;
use Illuminate\Support\HtmlString;
class ImportObjekteDirect
{
public static function run($data, $projekte_id)
{
$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;
foreach ($data as $row) {
$row = str_replace(';', '|', $row);
$cells = explode('|', $row);
$top_nummer = trim($cells[0]);
$geschoss = trim($cells[1]);
$raumart = trim($cells[2]);
$flaeche = (float) str_replace(',', '.', trim($cells[3]));
if (is_numeric($flaeche) && $flaeche > 0) {
$projekt_objekte = ProjektObjekte::firstOrCreate([
'projekte_id' => $projekte_id,
'top_nummer' => $top_nummer,
]);
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++;
}
}
$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]
);
if ($prokectimdetail->new) { // some way to check
$new_detail++;
} else {
$update_detail++;
}
}
}
Notification::make()
->title('Objekte im Detail wurden erfolgreich importiert')
->success()
->send();
$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))
->success()
->sendToDatabase($recipient);
}
public static function getBody($has_objekte, $has_detail, $new_objekte, $new_detail, $update_objekte, $update_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>
</div>');
}
}
@@ -3,25 +3,17 @@
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\Forms\Components\Radio;
use Filament\Forms\Components\Textarea;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rules\File;
use Livewire\Attributes\On;
class EditProjekte extends EditRecord
@@ -36,122 +28,6 @@ class EditProjekte extends EditRecord
protected function getHeaderActions(): array
{
return [
/**
* IMPORT
*/
ActionGroup::make([
Action::make('fix_line_endings')
->icon('phosphor-file-text')
->modalIcon('phosphor-file-csv')
->label('Daten direkt hochladen')
->schema([
Radio::make('tabel_mode')
->label('Tabellen Art')
->inline()
->options([
'allgemein' => 'Allgemeinflächen',
'objekte_in_detail' => 'Objekte im Detail',
]),
Textarea::make('upload_data')
->label('Daten hier einfügen')
->extraInputAttributes(['onClick' => 'this.select()'])
->rows(5),
]),
ImportAction::make('import_allgemeinflaechen')
->hidden(fn ($record): bool => $record->bezahlt_am ? false : true)
->importer(ProjektAllgemeinflaechenImporter::class)
->csvDelimiter('|')
->modalIcon('phosphor-file-csv')
->modalHeading('Dokument 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('Dokument 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
@@ -2,12 +2,17 @@
namespace App\Filament\Resources\Projektes\RelationManagers;
use App\Filament\Imports\ImportAllgemeinDirect;
use App\Models\ProjektAllgemeinflaechen;
use Filament\Actions\Action;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\Summarizers\Sum;
@@ -53,7 +58,7 @@ class ProjektAllgemeinflaechensRelationManager extends RelationManager
public function table(Table $table): Table
{
return $table
->emptyStateDescription('Schalten Sie das Projekt frei und importieren Sie die Daten der Allgemeinflächen.')
->emptyStateDescription('Bitte Projekt zuerst freischalten und dann die Daten der Allgemeinflächen hochladen.')
->striped()
->recordTitleAttribute('geschoss')
->columns([
@@ -75,6 +80,37 @@ class ProjektAllgemeinflaechensRelationManager extends RelationManager
->searchable(),
])
->headerActions([
Action::make('import-text')
->icon('phosphor-upload')
->hidden(fn (): bool => $this->ownerRecord->bezahlt_am ? false : true)
->modalIcon('phosphor-file-csv')
->color('info')
->label('Hochladen')
->modalHeading('Allgemeinflächen hochladen')
->modalDescription(new HtmlString('<b>Objekte werden immer hinzugefügt!</b><br/>Spalten-Separator ist der Strichpunkt ";" oder die Pfeife "|"'))
->schema([
Textarea::make('upload_data')
->required()
->label('Text hier einfügen:')
->extraInputAttributes(['onClick' => 'this.select()'])
->rows(5),
])
->action(function (array $data): void {
ImportAllgemeinDirect::run($data, $this->ownerRecord->id);
}),
Action::make('leeren')
->action(function () {
ProjektAllgemeinflaechen::where('projekte_id', $this->ownerRecord->id)->delete();
})
->icon('phosphor-trash')
->color('danger')
->requiresConfirmation()
->successNotification(
Notification::make()
->success()
->title('Allgemeinflächen gelöscht'),
),
CreateAction::make()
->icon('phosphor-file-plus')
->createAnother(false),
@@ -2,6 +2,7 @@
namespace App\Filament\Resources\Projektes\RelationManagers;
use App\Filament\Imports\ImportObjekteDirect;
use App\Models\ProjektObjekteImDetail;
use Filament\Actions\Action;
use Filament\Actions\BulkActionGroup;
@@ -10,6 +11,7 @@ use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
@@ -68,7 +70,7 @@ class ProjektObjekteImDetailRelationManager extends RelationManager
public function table(Table $table): Table
{
return $table
->emptyStateDescription('Schalten Sie das Projekt frei und importieren Sie die Daten der Objekte.')
->emptyStateDescription('Bitte Projekt freischalten und Daten hochladen.')
->striped()
->recordTitleAttribute('top_nummer')
->columns([
@@ -139,20 +141,40 @@ class ProjektObjekteImDetailRelationManager extends RelationManager
])
->deferFilters(false)
->headerActions([
Action::make('import-text')
->icon('phosphor-upload')
->modalIcon('phosphor-file-csv')
->color('info')
->label('Hochladen')
->modalHeading('Objekte im Detail hochladen')
->modalDescription(new HtmlString('<b>Objekte werden immer hinzugefügt!</b><br/>Spalten-Separator ist der Strichpunkt ";" oder die Pfeife "|"'))
->schema([
Textarea::make('upload_data')
->required()
->label('Text hier einfügen:')
->extraInputAttributes(['onClick' => 'this.select()'])
->rows(5),
])
->action(function (array $data): void {
ImportObjekteDirect::run($data, $this->ownerRecord->id);
}),
CreateAction::make()
->icon('phosphor-file-plus')
->createAnother(false),
Action::make('nutzwerte')
->label('Nutzwerte')
->icon('phosphor-gear')
->icon('phosphor-calculator')
->action(function () {
$res = ProjektObjekteImDetail::with('methode')
->where('projekte_id', $this->getOwnerRecord()->id)
->get();
foreach ($res as $row) {
ProjektObjekteImDetail::where('id', $row->id)
->update(['nutzwert' => $row->flaeche * $row->methode->faktor]);
if ($row->methode?->faktor || null) {
ProjektObjekteImDetail::where('id', $row->id)
->update(['nutzwert' => $row->flaeche * $row->methode->faktor]);
}
}
})->after(function (Component $livewire) {
@@ -58,7 +58,7 @@ class ProjektObjekteRelationManager extends RelationManager
return $table
// ->striped()
->emptyStateDescription('Schalten Sie das Projekt frei und importieren Sie die Daten der Objekte.')
->emptyStateDescription(new HtmlString('Bitte Projekt freischalten und unter <b class="text-primary-600">Objekte im Detail</b> Daten hochladen.'))
->recordTitleAttribute('top_nummer')
->description(new HtmlString('<span class="flex gap-1.5">Orientierungen, Zu- und Abschläge, '.Blade::render('<x-lucide-locate-off class="w-3 h-3 mt-1" />').' Nicht in Orientierung</span>'))
->columns([