fix clone

This commit is contained in:
salam committed 2026-09-17 08:35:36 +02:00
1 parent 82ee9d2dcf
commit 9a5ad32315
33 files changed
+654 -496

No files matched your search

+48 -46
View File
@@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Auth;
class CloneProjekt
{
public static function clone(Projekte $record)
public static function clone(Projekte $original_projekt)
{
/**
* projektes
@@ -28,66 +28,68 @@ class CloneProjekt
* projekt_objekte_im_details
* projekt_objektes
*/
$NEW = $record->replicate();
$NEW->cloned_from_id = $record->id;
$NEW->save();
$neues_projekt = $original_projekt->replicate();
$neues_projekt->cloned_from_id = $original_projekt->id;
$neues_projekt->save();
ProjektUser::create(['user_id' => Auth::user()->id, 'projekte_id' => $NEW->id, 'evaluation_gutachten' => 0]);
ProjektUser::create(['user_id' => Auth::user()->id, 'projekte_id' => $neues_projekt->id, 'evaluation_gutachten' => 0]);
$res = ProjektObjekte::where('projekte_id', $record->id)->get();
$methoden_map = [];
$projekt_methoden = ProjektMethode::where('projekte_id', $original_projekt->id)->get();
foreach ($projekt_methoden as $projekt_methode) {
$new_projekt_methode = $projekt_methode->replicate();
$new_projekt_methode->projekte_id = $neues_projekt->id;
$new_projekt_methode->cloned_from_id = $projekt_methode->id;
$new_projekt_methode->save();
$methoden_map[$projekt_methode->id] = $new_projekt_methode->id;
}
foreach ($res as $row) {
$new = $row->replicate();
$new->projekte_id = $NEW->id;
$new->cloned_from_id = $row->id;
$new->save();
$projekt_objekte = ProjektObjekte::where('projekte_id', $original_projekt->id)->get();
foreach ($projekt_objekte as $projekt_objekt) {
$new_projekt_objekt = $projekt_objekt->replicate();
$new_projekt_objekt->projekte_id = $neues_projekt->id;
$new_projekt_objekt->cloned_from_id = $projekt_objekt->id;
$new_projekt_objekt->save();
$res2 = ProjektObjekteImDetail::where('projekte_id', $record->id)->where('projekt_objekte_id', $row->id)->get();
foreach ($res2 as $row2) {
$new2 = $row2->replicate();
$new2->projekte_id = $NEW->id;
$new2->projekt_objekte_id = $new->id;
$new2->cloned_from_id = $row2->id;
$new2->save();
$projekt_objekt_im_details = ProjektObjekteImDetail::where('projekte_id', $original_projekt->id)->where('projekt_objekte_id', $projekt_objekt->id)->get();
foreach ($projekt_objekt_im_details as $projekt_objekt_im_detail) {
$new_projekt_objekt_im_detail = $projekt_objekt_im_detail->replicate();
$new_projekt_objekt_im_detail->projekte_id = $neues_projekt->id;
$new_projekt_objekt_im_detail->projekt_objekte_id = $new_projekt_objekt->id;
$new_projekt_objekt_im_detail->cloned_from_id = $projekt_objekt_im_detail->id;
$new_projekt_objekt_im_detail->projekt_methode_id = $methoden_map[$projekt_objekt_im_detail->projekt_methode_id];
$new_projekt_objekt_im_detail->save();
}
}
$res = ProjektAllgemeinflaechen::where('projekte_id', $record->id)->get();
$projekt_allgemeinflaechen = ProjektAllgemeinflaechen::where('projekte_id', $original_projekt->id)->get();
foreach ($projekt_allgemeinflaechen as $projekt_allgemeinflaeche) {
$new_projekt_allgemeinflaeche = $projekt_allgemeinflaeche->replicate();
$new_projekt_allgemeinflaeche->projekte_id = $neues_projekt->id;
$new_projekt_allgemeinflaeche->cloned_from_id = $projekt_allgemeinflaeche->id;
$new_projekt_allgemeinflaeche->save();
}
$projekt_inhaltsverzeichnise = ProjektInhaltsverzeichnis::where('projekte_id', $original_projekt->id)->get();
foreach ($projekt_inhaltsverzeichnise as $projekt_inhaltsverzeichnis) {
$new_projekt_inhaltsverzeichnis = $projekt_inhaltsverzeichnis->replicate();
$new_projekt_inhaltsverzeichnis->projekte_id = $neues_projekt->id;
$new_projekt_inhaltsverzeichnis->cloned_from_id = $projekt_inhaltsverzeichnis->id;
$new_projekt_inhaltsverzeichnis->save();
}
$res = ProjektMerkmale::where('projekte_id', $original_projekt->id)->get();
foreach ($res as $row) {
$new = $row->replicate();
$new->projekte_id = $NEW->id;
$new->projekte_id = $neues_projekt->id;
$new->cloned_from_id = $row->id;
$new->save();
}
$res = ProjektInhaltsverzeichnis::where('projekte_id', $record->id)->get();
$res = ProjektPlatzhalter::where('projekte_id', $original_projekt->id)->get();
foreach ($res as $row) {
$new = $row->replicate();
$new->projekte_id = $NEW->id;
$new->cloned_from_id = $row->id;
$new->save();
}
$res = ProjektMerkmale::where('projekte_id', $record->id)->get();
foreach ($res as $row) {
$new = $row->replicate();
$new->projekte_id = $NEW->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 = $NEW->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 = $NEW->id;
$new->projekte_id = $neues_projekt->id;
$new->cloned_from_id = $row->id;
$new->save();
}
+17 -23
View File
@@ -49,7 +49,7 @@ class GutachtenValidation
->duration(10000)
->body('Die Tabelle der <b>Allgemeinflächen</b> ist leer.')
->send();
return false;
}
foreach ($res as $value) {
@@ -61,7 +61,7 @@ class GutachtenValidation
->duration(10000)
->body('Für die Allgemeinfläche <b>'.$value->raumart.'</b> fehlt die Angabe des <u>Geschoßes</u>.')
->send();
return false;
}
if (! $value->raumart) {
@@ -83,7 +83,7 @@ class GutachtenValidation
->duration(10000)
->body('Für die Allgemeinfläche <b>'.$value->raumart.'</b> fehlt die Angabe der <u>Fläche</u>.')
->send();
return false;
}
}
@@ -95,11 +95,11 @@ class GutachtenValidation
$collect = [];
foreach ($res as $value) {
$res2 = ProjektObjekteImDetail::where('projekte_id', $record->id)->where('projekt_objekte_id', $value->id)->first();
if(!$res2){
if (! $res2) {
$collect[] = $value->top_nummer;
}
}
if($collect){
if ($collect) {
Notification::make()
->title('Fehler bei Verbindungen von Objekt zu Objekt im Detail')
->body('Für die <u>Objekte</u>:<div class="py-2 text-gray-500">'.implode(', ', $collect).'</div>fehlen die <u>Objekte im Detail</u>. Daten können nochmals hochladen werden.')
@@ -115,14 +115,14 @@ class GutachtenValidation
* jedes objekt im detail hat eine Verbindung zu einem objekt
*/
$res = ProjektObjekteImDetail::where('projekte_id', $record->id)->get();
$collect=[];
$collect = [];
foreach ($res as $value) {
$res2 = ProjektObjekte::where('projekte_id', $record->id)->where('id', $value->projekt_objekte_id)->first();
if(!$res2){
$collect[] = $value->geschoss .' '.$value->raumart;
if (! $res2) {
$collect[] = $value->geschoss.' '.$value->raumart;
}
}
if($collect){
if ($collect) {
Notification::make()
->title('Fehler bei Verbindungen von Objekt im Detail zu Objekt')
->body('Für die <u>Objekte im Detail</u>: <div class="py-2 text-gray-500">'.implode(', ', $collect).'</div>fehlt das<u>Objekte</u>. Daten können nochmals hochladen werden.')
@@ -133,23 +133,17 @@ class GutachtenValidation
return false;
}
/**
* ProjektObjekteImDetail + raumart
* -> cosistent
* ProjektMethode + raumart
*/
$raumarts_ObjekteImDetail = ProjektObjekteImDetail::where('projekte_id', $record->id)->groupBy('raumart')->pluck('raumart')->toArray();
$raumarts_Methode = ProjektMethode::where('projekte_id', $record->id)->pluck('raumart')->toArray();
$raumarts_oid = ProjektObjekteImDetail::where('projekte_id', $record->id)->groupBy('raumart')->pluck('raumart')->toArray();
$raumarts_meth = ProjektMethode::where('projekte_id', $record->id)->pluck('raumart')->toArray();
$extra_oid = array_diff($raumarts_oid, $raumarts_meth);
$extra_meth = array_diff($raumarts_meth, $raumarts_oid);
// dd($extra_oid, $raumarts_meth);
$extra_oid = array_diff($raumarts_ObjekteImDetail, $raumarts_Methode);
$extra_meth = array_diff($raumarts_Methode, $raumarts_ObjekteImDetail);
if ($extra_oid) {
$titel = \count($extra_oid) == 1 ? 'Für diese "Raumart" aus "Objekte im Detail" ist keine "Raum Methode" definiert' : 'Für diese "Raumarten" aus "Objekte im Detail" sind keine "Raum Methoden" definiert';
@@ -171,7 +165,7 @@ class GutachtenValidation
->icon('heroicon-o-exclamation-triangle')
->duration(10000)
->danger()
->body(implode('<br>', $extra_oid))
->body(implode('<br>', $extra_meth))
->send();
return false;
@@ -254,7 +248,7 @@ class GutachtenValidation
->duration(10000)
->body('Für den Raum mit der ID <b>'.$value->id.'</b> fehlt die Angabe der <u>Top Nummer</u>.')
->send();
return false;
}
if (! $value->projektobjekteimdetail->first()->raumart) {
@@ -333,7 +327,7 @@ class GutachtenValidation
->body('Inhaltsverzeichnis fehlt!')
->duration(10000)
->send();
return false;
}
@@ -7,11 +7,14 @@ 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\Forms\Components\Select;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Auth;
@@ -151,17 +154,37 @@ class EditProjekte extends EditRecord
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')
->schema([
Select::make('authorId')
->label('Author')
->options(Projekte::query()->pluck('interner_name', 'id'))
->required(),
])->action(function (array $data, Projekte $record): void {
$res = ProjektObjekteImDetail::where('projekte_id', 15)->get();
foreach ($res as $row) {
$projekt_methode_id = ProjektMethode::where('cloned_from_id', $row->projekt_methode_id)->value('id');
ProjektObjekteImDetail::where('id', $row->id)->update(['projekt_methode_id' => $projekt_methode_id]);
}
}),
Action::make('reparieren')
->color('success')
->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'),
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.'),
])->label('Admin')
->icon('phosphor-user-circle')
->button(),
@@ -272,7 +272,6 @@ class ProjektObjekteRelationManager extends RelationManager
return Orientierung::whereIn('id', $res)->orderBy('id')->pluck('name', 'id');
}),
TernaryFilter::make('nicht_in_orientierung')
->default(0)
->label('"Nicht in Orientierung" anzeigen'),
], FiltersLayout::AboveContent)
->deferFilters(false)
+9
View File
@@ -4,6 +4,15 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $projekte_id
* @property int $cloned_from_id
* @property int $added_manuel
* @property string $geschoss
* @property string $raumart
* @property float $flaeche
*/
class ProjektAllgemeinflaechen extends Model
{
protected $fillable = [
+21
View File
@@ -4,6 +4,27 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $projekte_id
* @property int $cloned_from_id
* @property int $added_manuel
* @property int $inhaltselement_id
* @property int $inhaltsverzeichnis_id
* @property int $textblock_id
* @property int $konto_textblock_id
* @property int $sort
* @property float $ordnungszahl
* @property string $name
* @property string $part
* @property int $ueberschrift_verbergen
* @property int $seite
* @property int $neue_seite
* @property int $no_edit
* @property string $textblock_name
* @property string $textblock
* @property string $textblock2
*/
class ProjektInhaltsverzeichnis extends Model
{
protected $fillable = [
+10 -1
View File
@@ -4,6 +4,15 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $projekte_id
* @property int $projekt_objekte_id
* @property int $cloned_from_id
* @property int $added_manuel
* @property string $code
* @property string $name
*/
class ProjektMerkmale extends Model
{
protected $fillable = [
@@ -14,7 +23,7 @@ class ProjektMerkmale extends Model
'name',
];
public static function getfreecode($projekte_id)
public static function getfreecode(int $projekte_id)
{
$possible = range('a', 'j');
+9 -1
View File
@@ -4,6 +4,15 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $projekte_id
* @property int $cloned_from_id
* @property int $methode_id
* @property int $aufstellung_id
* @property string $raumart
* @property float $faktor
*/
class ProjektMethode extends Model
{
protected $fillable = [
@@ -11,7 +20,6 @@ class ProjektMethode extends Model
'cloned_from_id',
'methode_id',
'aufstellung_id',
'geschoss',
'raumart',
'faktor',
];
+22 -1
View File
@@ -6,6 +6,28 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* @property int $id
* @property int $projekte_id
* @property int $cloned_from_id
* @property int $added_manuel
* @property int $orientierung_id
* @property int $nicht_in_orientierung
* @property string $top_nummer
* @property string $type
* @property string $raumart
* @property string $nutzwert
* @property string $a
* @property string $b
* @property string $c
* @property string $d
* @property string $e
* @property string $f
* @property string $g
* @property string $h
* @property string $i
* @property string $j
*/
class ProjektObjekte extends Model
{
protected $fillable = [
@@ -18,7 +40,6 @@ class ProjektObjekte extends Model
'type',
'raumart',
'nutzwert',
'added_manuel',
'a',
'b',
'c',
+15
View File
@@ -4,11 +4,26 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $projekte_id
* @property int $projekt_objekte_id
* @property int $projekt_methode_id
* @property int $cloned_from_id
* @property int $added_manuel
* @property int $methode_id
* @property int $top_nummer
* @property string $geschoss
* @property string $raumart
* @property float $flaeche
* @property int $nutzwert
*/
class ProjektObjekteImDetail extends Model
{
protected $fillable = [
'projekte_id',
'projekt_objekte_id',
'projekt_methode_id',
'cloned_from_id',
'added_manuel',
'methode_id',
+8
View File
@@ -4,6 +4,14 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $projekte_id
* @property int $cloned_from_id
* @property string $platzhalter
* @property string $platzhaltertext
* @property int $controll
*/
class ProjektPlatzhalter extends Model
{
protected $fillable = [
+18
View File
@@ -5,6 +5,24 @@ namespace App\Models;
use App\Models\Scopes\KontoScope;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $cloned_from_id
* @property int $konto_id
* @property int $auftraggeber_id
* @property string $interner_name
* @property string $offizieller_name
* @property string $ort
* @property string $beschreibung
* @property string $erstellung
* @property string $status
* @property int $projekt_farben_verwenden
* @property string $deckblatt_bg
* @property string $schmuckfarbe_header
* @property string $farbe_borders
* @property int $evaluation_gutachten
* @property int $pdf_nutzwerte_tabellen_umbruch
*/
class Projekte extends Model
{
protected $primaryKey = 'id';
+11 -1
View File
@@ -18,9 +18,19 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
/**
* @property int $id
* @property int $konto_id
* @property string $gender
* @property string $name
* @property string $email
* @property string $password
* @property int $agb_akzeptiert
* @property int $app_verified_at
*/
class User extends Authenticatable implements FilamentUser, HasAppAuthentication, HasAppAuthenticationRecovery, HasEmailAuthentication, MustVerifyEmail
{
/** @use HasFactory<\Database\Factories\UserFactory> */
/** @use HasFactory<UserFactory> */
use HasFactory, HasRoles, Notifiable, SoftDeletes;
/**