wip controll and repair
This commit is contained in:
1 parent
4a509c6a16
commit
3dd1dad42f
19 files changed
+182
-91
No files matched your search
@@ -10,6 +10,7 @@ use App\Models\ProjektMethode;
|
||||
use App\Models\ProjektObjekte;
|
||||
use App\Models\ProjektObjekteImDetail;
|
||||
use App\Models\ProjektPlatzhalter;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class Reparieren
|
||||
{
|
||||
@@ -26,79 +27,130 @@ class Reparieren
|
||||
* projekt_objekte_im_details
|
||||
* projekt_objektes
|
||||
*/
|
||||
$ORIGINAL = $record->cloned_from_id;
|
||||
$GEKLONT = $record->id;
|
||||
$CLONED_FROM_ID = $record->cloned_from_id;
|
||||
$ACTIVE_ID = $record->id;
|
||||
|
||||
if($ORIGINAL){
|
||||
// überprüfe geklontes Projekt!
|
||||
$originals = ProjektObjekte::where('projekte_id', $ORIGINAL)->get();
|
||||
/**
|
||||
* 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', $GEKLONT)->where('top_nummer', $original->top_nummer)->get();
|
||||
dd($check);
|
||||
$check = ProjektObjekte::where('projekte_id', $ACTIVE_ID)->where('cloned_from_id', $original->id)->get();
|
||||
if (! $check) {
|
||||
/**
|
||||
* Im original dazugekommen
|
||||
* Im Original dazugekommen oder gelöscht
|
||||
*/
|
||||
$new = $original->replicate();
|
||||
$new->projekte_id = $GEKLONT;
|
||||
$new->projekte_id = $ACTIVE_ID;
|
||||
$new->cloned_from_id = $CLONED_FROM_ID;
|
||||
$new->save();
|
||||
|
||||
$res2 = ProjektObjekteImDetail::where('projekte_id', $ORIGINAL)->where('projekt_objekte_id', $original->id)->get();
|
||||
// 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', $GEKLONT)->where('raumart', $row2->raumart)->first();
|
||||
$check = ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('raumart', $row2->raumart)->first();
|
||||
if (! $check) {
|
||||
$new2 = $row2->replicate();
|
||||
$new2->projekte_id = $GEKLONT;
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
// $res = ProjektAllgemeinflaechen::where('projekte_id', $original_id)->get();
|
||||
// foreach ($res as $row) {
|
||||
// $check = ProjektInhaltsverzeichnis::where('projekte_id', $original_id)->where('raumart', $original->raumart)->first();
|
||||
// if (! $check) {
|
||||
// $new = $row->replicate();
|
||||
// $new->projekte_id = $record->id;
|
||||
// $new->save();
|
||||
// }
|
||||
// }
|
||||
// OBJEKTE IM DETAIL ZU OBJEKTE
|
||||
// Kontrolliere Verbindungen geklonter und nicht geklonter
|
||||
// Select all childreen from project
|
||||
$res = ProjektObjekteImDetail::select('projekt_objekte_id')->where('projekte_id', $ACTIVE_ID)->groupBy('projekt_objekte_id')->get();
|
||||
foreach ($res as $row) {
|
||||
// See if parent exists
|
||||
$res2 = ProjektObjekte::where('projekte_id', $ACTIVE_ID)->where('id', $row->projekt_objekte_id)->first();
|
||||
if(!$res){
|
||||
// If parent NOT exists delete all childreen
|
||||
ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_objekte_id', $row->projekt_objekte_id)->delete();
|
||||
}
|
||||
}
|
||||
// OBJEKTE ZU OBJEKTE IM DETAIL
|
||||
$res = ProjektObjekte::where('projekte_id', $ACTIVE_ID)->get();
|
||||
foreach ($res as $row) {
|
||||
// See if cildreen exists
|
||||
$res2 = ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_objekte_id', $row->id)->first();
|
||||
if(!$res){
|
||||
// If childree NOT exists delete parent
|
||||
ProjektObjekte::where('id', $row->id)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title('Projekt reparieren')
|
||||
->body('Die Reparatur des Projektes war erfolgreich.')
|
||||
->icon('heroicon-o-exclamation-triangle')
|
||||
->duration(10000)
|
||||
->success()
|
||||
->send();
|
||||
|
||||
// $res = ProjektInhaltsverzeichnis::where('projekte_id', $original_id)->get();
|
||||
// foreach ($res as $row) {
|
||||
// $check = ProjektInhaltsverzeichnis::where('projekte_id', $original_id)->where('top_nummer', $original->top_nummer)->first();
|
||||
// if (! $check) {
|
||||
// $new = $row->replicate();
|
||||
// $new->projekte_id = $record->id;
|
||||
// $new->save();
|
||||
// }
|
||||
// }
|
||||
// $res = ProjektPlatzhalter::where('projekte_id', $record->id)->get();
|
||||
// foreach ($res as $row) {
|
||||
// $new = $row->replicate();
|
||||
// $new->projekte_id = $record->id;
|
||||
// $new->save();
|
||||
// }
|
||||
// $res = ProjektMerkmale::where('projekte_id', $record->id)->get();
|
||||
// foreach ($res as $row) {
|
||||
// $new = $row->replicate();
|
||||
// $new->projekte_id = $record->id;
|
||||
// $new->save();
|
||||
// }
|
||||
// $res = ProjektMethode::where('projekte_id', $record->id)->get();
|
||||
// foreach ($res as $row) {
|
||||
// $new = $row->replicate();
|
||||
// $new->projekte_id = $record->id;
|
||||
// $new->save();
|
||||
// }
|
||||
// $res = ProjektPlatzhalter::where('projekte_id', $record->id)->get();
|
||||
// foreach ($res as $row) {
|
||||
// $new = $row->replicate();
|
||||
// $new->projekte_id = $record->id;
|
||||
// $new->save();
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user