This commit is contained in:
salam committed 2026-10-10 15:57:19 +02:00
1 parent db1855ab25
commit 4931512a8f
2 files changed
+17 -98

No files matched your search

+14 -98
View File
@@ -2,14 +2,10 @@
namespace App\Actions\Cloning; namespace App\Actions\Cloning;
use App\Models\ProjektAllgemeinflaechen;
use App\Models\Projekte; use App\Models\Projekte;
use App\Models\ProjektInhaltsverzeichnis;
use App\Models\ProjektMerkmale;
use App\Models\ProjektMethode; use App\Models\ProjektMethode;
use App\Models\ProjektObjekte; use App\Models\ProjektObjekte;
use App\Models\ProjektObjekteImDetail; use App\Models\ProjektObjekteImDetail;
use App\Models\ProjektPlatzhalter;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
class Reparieren class Reparieren
@@ -27,108 +23,17 @@ class Reparieren
* projekt_objekte_im_details * projekt_objekte_im_details
* projekt_objektes * projekt_objektes
*/ */
$CLONED_FROM_ID = $record->cloned_from_id;
$ACTIVE_ID = $record->id; $ACTIVE_ID = $record->id;
/**
* Ist geklonet
*/
if($CLONED_FROM_ID){
// Lösche alle geklonten "Objekte" ohne Verbindung zu Original
ProjektObjekte::where('projekte_id', $ACTIVE_ID)->where('cloned_from_id', 0)->where('added_manuel', 0)->delete();
// Überprüfe geklontes Projekt
$originals = ProjektObjekte::where('projekte_id', $CLONED_FROM_ID)->get();
foreach ($originals as $original) {
$check = ProjektObjekte::where('projekte_id', $ACTIVE_ID)->where('cloned_from_id', $original->id)->get();
if (! $check) {
/**
* Im Original dazugekommen oder gelöscht
*/
$new = $original->replicate();
$new->projekte_id = $ACTIVE_ID;
$new->cloned_from_id = $CLONED_FROM_ID;
$new->save();
// Lösche alle geklonten "Objekte im Detail" ohne Verbindung zu Original
ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('cloned_from_id', 0)->where('added_manuel', 0)->delete();
$res2 = ProjektObjekteImDetail::where('projekte_id', $CLONED_FROM_ID)->where('projekt_objekte_id', $original->id)->get();
foreach ($res2 as $row2) {
$check = ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('raumart', $row2->raumart)->first();
if (! $check) {
$new2 = $row2->replicate();
$new2->projekte_id = $ACTIVE_ID;
$new2->projekt_objekte_id = $new->id;
$new2->cloned_from_id = $row2->id;
$new2->save();
}
}
}
}
ProjektAllgemeinflaechen::where('projekte_id', $ACTIVE_ID)->where('cloned_from_id', 0)->where('added_manuel', 0)->delete();
$res = ProjektAllgemeinflaechen::where('projekte_id', $CLONED_FROM_ID)->get();
foreach ($res as $row) {
$check = ProjektAllgemeinflaechen::where('projekte_id', $ACTIVE_ID)->where('raumart', $original->raumart)->first();
if (! $check) {
$new = $row->replicate();
$new->projekte_id = $ACTIVE_ID;
$new->cloned_from_id = $row->id;
$new->save();
}
}
ProjektInhaltsverzeichnis::where('projekte_id', $ACTIVE_ID)->where('cloned_from_id', 0)->where('added_manuel', 0)->delete();
$res = ProjektInhaltsverzeichnis::where('projekte_id', $CLONED_FROM_ID)->get();
foreach ($res as $row) {
$check = ProjektInhaltsverzeichnis::where('projekte_id', $ACTIVE_ID)->where('inhaltsverzeichnis_id', $original->inhaltsverzeichnis_id)->first();
if (! $check) {
$new = $row->replicate();
$new->projekte_id = $ACTIVE_ID;
$new->cloned_from_id = $row->id;
$new->save();
}
}
ProjektMerkmale::where('projekte_id', $ACTIVE_ID)->where('cloned_from_id', 0)->where('added_manuel', 0)->delete();
$res = ProjektMerkmale::where('projekte_id', $record->id)->get();
foreach ($res as $row) {
$check = ProjektInhaltsverzeichnis::where('projekte_id', $ACTIVE_ID)->where('name', $original->name)->first();
if (! $check) {
$new = $row->replicate();
$new->projekte_id = $ACTIVE_ID;
$new->cloned_from_id = $row->id;
$new->save();
}
}
$res = ProjektMethode::where('projekte_id', $record->id)->get();
foreach ($res as $row) {
$new = $row->replicate();
$new->projekte_id = $record->id;
$new->cloned_from_id = $row->id;
$new->save();
}
$res = ProjektPlatzhalter::where('projekte_id', $record->id)->get();
foreach ($res as $row) {
$new = $row->replicate();
$new->projekte_id = $record->id;
$new->cloned_from_id = $row->id;
$new->save();
}
}
// OBJEKTE IM DETAIL ZU OBJEKTE // OBJEKTE IM DETAIL ZU OBJEKTE
// Kontrolliere Verbindungen geklonter und nicht geklonter // Kontrolliere Verbindungen geklonter und nicht geklonter
// Select all childreen from project // Select all childreen from project
$res = ProjektObjekteImDetail::select('projekt_objekte_id')->where('projekte_id', $ACTIVE_ID)->groupBy('projekt_objekte_id')->get(); $res = ProjektObjekteImDetail::select('projekt_objekte_id')->where('projekte_id', $ACTIVE_ID)->groupBy('projekt_objekte_id')->get();
foreach ($res as $row) { foreach ($res as $row) {
// See if parent exists // See if parent exists
$res2 = ProjektObjekte::where('projekte_id', $ACTIVE_ID)->where('id', $row->projekt_objekte_id)->first(); $res2 = ProjektObjekte::where('projekte_id', $ACTIVE_ID)->where('id', $row->projekt_objekte_id)->first();
if(!$res){ if (! $res2) {
// If parent NOT exists delete all childreen // If parent NOT exists delete all childreen
ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_objekte_id', $row->projekt_objekte_id)->delete(); ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_objekte_id', $row->projekt_objekte_id)->delete();
} }
@@ -138,12 +43,23 @@ class Reparieren
foreach ($res as $row) { foreach ($res as $row) {
// See if cildreen exists // See if cildreen exists
$res2 = ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_objekte_id', $row->id)->first(); $res2 = ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_objekte_id', $row->id)->first();
if(!$res){ if (! $res2) {
// If childree NOT exists delete parent // If childree NOT exists delete parent
ProjektObjekte::where('id', $row->id)->delete(); ProjektObjekte::where('id', $row->id)->delete();
} }
} }
// METHODEN ZU OBJEKTE IM DETAIL
$res = ProjektMethode::where('projekte_id', $ACTIVE_ID)->get();
foreach ($res as $row) {
// See if cildreen exists
$res2 = ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_methode_id', $row->id)->first();
if (! $res2) {
// If childree NOT exists delete parent
ProjektMethode::where('id', $row->id)->delete();
}
}
Notification::make() Notification::make()
->title('Projekt reparieren') ->title('Projekt reparieren')
->body('Die Reparatur des Projektes war erfolgreich.') ->body('Die Reparatur des Projektes war erfolgreich.')
@@ -38,6 +38,9 @@ class ImportObjekteDirect
$flaeche = (float) str_replace(',', '.', trim($cells[3])); $flaeche = (float) str_replace(',', '.', trim($cells[3]));
$geschoss = trim($cells[1]);
// dd($top_nummer, $geschoss, $raumart, $flaeche);
if (is_numeric($flaeche) && $flaeche > 0 && $projekt_methode->id) { if (is_numeric($flaeche) && $flaeche > 0 && $projekt_methode->id) {
$objekt = ProjektObjekte::where('projekte_id', $projekte_id) $objekt = ProjektObjekte::where('projekte_id', $projekte_id)