Files
nutzwerte_fi4/app/Actions/Generate/Tabellen/ZuUndAbschlaege.php
T
2025-11-03 06:12:59 +01:00

77 lines
2.7 KiB
PHP

<?php
namespace App\Actions\Generate\Tabellen;
use App\Actions\Generate\Utilities\Format;
use App\Actions\Generate\Utilities\Html;
use App\Models\ProjektMerkmale;
use App\Models\ProjektMethode;
use App\Models\ProjektObjekte;
use App\Models\ProjektObjekteImDetail;
class ZuUndAbschlaege
{
public static function load(int $projekte_id)
{
$objekte = ProjektObjekte::select()
->with('orientierung')
->where('projekte_id', $projekte_id)
->where('nicht_in_orientierung', 0)
->get();
$has_loggien = ProjektMethode::where('projekte_id', $projekte_id)->where('methode_id', 2)->count();
if ($has_loggien) {
$header_row = ['Top Nummer', 'Geschoß', 'Typ', 'Nutzfläche', 'Loggia / Zusatzflächen', 'Gesamtnutzfläche'];
} else {
$header_row = ['Top Nummer', 'Geschoß', 'Typ', 'Nutzfläche'];
}
$projekt_merkmale = ProjektMerkmale::where('projekte_id', $projekte_id)->pluck('name', 'code');
$markmale_codes = [];
foreach ($projekt_merkmale as $key => $value) {
$markmale_codes[] = $key;
$header_row[] = $value;
}
$header_row[] = 'Summe Merkmale';
$header_row[] = 'Wohnungsbewertung';
$html = Html::table_header_90($header_row);
foreach ($objekte as $objekt) {
$detail = ProjektObjekteImDetail::where('projekt_objekte_id', $objekt->id)->get();
$flaeche = $detail->sum('flaeche');
$geschoss = $detail->first()->geschoss;
$html .= '<tr>';
$html .= Html::td($objekt['top_nummer'], 'left bl br bb');
$html .= Html::td($geschoss, 'center br bb');
$html .= Html::td($objekt['type'], 'wp20 br bb');
// Nutzfläache
$html .= Html::td(Format::dezimal($flaeche, 2).' m&sup2;', 'center br bb');
// Loggia
// $loggia = Raumalles::loggia($id);
// $gesnutzfl = $loggia + $objekt->qm_m1;
// $loggia = $loggia != 0 ? $loggia : '';
// $html .= Html::td($loggia, 'right br bb');
// // Gesammtnutzfläche = Nutzfläache + Loggia
// $html .= Html::td(Format::numeric($gesnutzfl, 2), 'right br bb');
// dd($objekt);
$nutwert = 0;
foreach ($markmale_codes as $code) {
$nutwert += $objekt[$code];
$html .= Html::td(Format::dezimal($objekt[$code], 2), 'center br bb');
}
$html .= Html::td(Format::dezimal($nutwert, 2), 'center br bb');
$html .= Html::td(Format::dezimal(100 + $nutwert, 2), 'right br bb');
$html .= '</tr>';
}
$html .= '</table>';
return $html;
}
}