diff --git a/app/Actions/Generate/Tabellen/Zusammenstellung.php b/app/Actions/Generate/Tabellen/Zusammenstellung.php index 1838b23..4649f60 100644 --- a/app/Actions/Generate/Tabellen/Zusammenstellung.php +++ b/app/Actions/Generate/Tabellen/Zusammenstellung.php @@ -6,6 +6,7 @@ use App\Actions\Generate\PdfGenerator; use App\Actions\Generate\Utilities\Format; use App\Actions\Generate\Utilities\Html; use App\Models\ProjektObjekte; +use App\Models\ProjektObjekteImDetail; class Zusammenstellung { @@ -19,6 +20,8 @@ class Zusammenstellung $html = Html::table_header(['Top', 'Geschoß', 'Orientierung', 'Typ', 'Nutzwert', 'x2 *', '%']); + $geschosse = self::loadGeschosse($projekte_id); + $objekte = ProjektObjekte::select() ->with('orientierung') ->with('projektobjekteimdetail') @@ -31,7 +34,7 @@ class Zusammenstellung $html .= ''; $html .= Html::td($objekt->top_nummer, 'bl bb br'); - $html .= Html::td($objekt->projektobjekteimdetail->first()->geschoss, 'center br bb'); + $html .= Html::td($geschosse[$objekt->id], 'center br bb'); $html .= Html::td($objekt->orientierung?->name, 'center br bb'); $html .= Html::td($objekt?->type, 'center br bb'); @@ -97,4 +100,25 @@ class Zusammenstellung return $html; } + + public static function loadGeschosse($projekte_id) + { + $objekte = ProjektObjekteImDetail::where('projekte_id', $projekte_id)->get(); + + $arr = []; + foreach ($objekte as $objekt) { + $arr[$objekt->projekt_objekte_id][] = $objekt->geschoss; + } + + foreach ($arr as $key => $value) { + $value = array_unique($value); + if (count($value) > 1) { + $arr[$key] = implode('/', $value); + } else { + $arr[$key] = (string) array_first($value); + } + } + + return $arr; + } }