310 lines
10 KiB
PHP
310 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Generate;
|
|
|
|
use App\Actions\Generate\Tabellen\LadeProjekt;
|
|
use App\Models\Auftraggeber;
|
|
use App\Models\Gutachter;
|
|
use App\Models\Projekte;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Response;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|
|
|
class Excel
|
|
{
|
|
public static $projekt;
|
|
|
|
public static $gutachter;
|
|
|
|
public static $auftraggeber;
|
|
|
|
public static function make($projekte_id, $part)
|
|
{
|
|
|
|
self::$projekt = Projekte::where('id', $projekte_id)->first();
|
|
|
|
self::$gutachter = Gutachter::where('id', self::$projekt->gutachter_id)->first();
|
|
|
|
self::$auftraggeber = Auftraggeber::where('id', self::$projekt->auftraggeber_id)->first();
|
|
|
|
$filepath = Storage::disk('public')->path("/download/$projekte_id/");
|
|
$filename = \ucfirst($part).' '.preg_replace("'[^0-9a-zA-Z]'", '', self::$projekt->interner_name).'.xlsx';
|
|
if (! File::isDirectory($filepath)) {
|
|
File::makeDirectory($filepath, 0777, true, true);
|
|
}
|
|
$file = $filepath.$filename;
|
|
|
|
// SPREADSHEET start
|
|
$spreadsheet = new Spreadsheet;
|
|
|
|
$spreadsheet->getProperties()->setCreator(self::$gutachter->company)
|
|
->setLastModifiedBy(self::$gutachter->name)
|
|
->setTitle(self::$projekt->offizieller_name)
|
|
->setDescription(self::$projekt->interner_name.' - '.date('d-m-Y H:i:s'));
|
|
|
|
$_farbe_1 = [2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 51, 52, 53, 54, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 91, 92, 93, 94];
|
|
$_farbe_2 = [8, 19, 29];
|
|
|
|
$row = '1';
|
|
$coll = 'A';
|
|
|
|
$_headers = self::title_reihe();
|
|
$spreadsheet->setActiveSheetIndex(0);
|
|
foreach ($_headers as $key => $value) {
|
|
$cell = $coll.$row;
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->setCellValue($cell, $value);
|
|
|
|
if (\in_array($key, $_farbe_1)) {
|
|
$spreadsheet->getActiveSheet()->getStyle($cell)->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('dbeafe');
|
|
} elseif (\in_array($key, $_farbe_2)) {
|
|
$spreadsheet->getActiveSheet()->getStyle($cell)->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('fef9c2');
|
|
}
|
|
$sheet->getStyle($cell)
|
|
->getBorders()
|
|
->getOutline()
|
|
->setBorderStyle(Border::BORDER_THIN);
|
|
|
|
$coll++;
|
|
}
|
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
foreach ($sheet->getColumnIterator() as $column) {
|
|
$sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true);
|
|
}
|
|
|
|
$_projekt = LadeProjekt::project($projekte_id, false);
|
|
|
|
$row = 2;
|
|
$activeWorksheet = $spreadsheet->getActiveSheet();
|
|
foreach ($_projekt as $objekt) {
|
|
|
|
$activeWorksheet->setCellValue("B$row", $objekt[1][0]['top_nummer']);
|
|
/**
|
|
* Normale Wohnnutzflächen
|
|
*/
|
|
$flaeche = array_sum(array_column($objekt[1], 'flaeche'));
|
|
$beschreibung = array_column($objekt[1], 'raumart');
|
|
$faktor = (100 + $objekt[1][0]['objekt_nutzwert']) / 100;
|
|
$summe_nutzwert = $flaeche * $faktor;
|
|
|
|
/**
|
|
* Wintergarten, Loggien, unter Stiegen
|
|
*/
|
|
$loggien_flaeche = 0;
|
|
$loggien_sum = [];
|
|
if (isset($objekt[2])) {
|
|
foreach ($objekt[2] as $value) {
|
|
$loggien_sum[] = $value['raumart'].' '.$value['flaeche'].'m²';
|
|
$loggien_flaeche += $value['flaeche'];
|
|
$nutzwert = $value['flaeche'] * $value['faktor'];
|
|
$summe_nutzwert += $nutzwert;
|
|
}
|
|
}
|
|
$summe_nutzwert = round($summe_nutzwert);
|
|
|
|
/**
|
|
* Terasse, Balkon
|
|
*/
|
|
$balkon_sum = [];
|
|
if (isset($objekt[3])) {
|
|
foreach ($objekt[3] as $value) {
|
|
$balkon_sum[] = $value['raumart'].' '.$value['flaeche'].'m²';
|
|
$nutzwert = $value['flaeche'] * $value['faktor'];
|
|
$nutzwert = round($nutzwert) < 1 ? 1 : round($nutzwert);
|
|
$summe_nutzwert += $nutzwert;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Keller, Garten
|
|
*/
|
|
$keller_sum = [];
|
|
if (isset($objekt[4])) {
|
|
foreach ($objekt[4] as $value) {
|
|
$keller_sum[] = $value['raumart'].' '.$value['flaeche'].'m²';
|
|
$nutzwert = $value['flaeche'] * $value['faktor'];
|
|
$nutzwert = round($nutzwert) < 1 ? 1 : round($nutzwert);
|
|
$summe_nutzwert += $nutzwert;
|
|
}
|
|
}
|
|
|
|
$activeWorksheet->setCellValue("C$row", $summe_nutzwert);
|
|
$activeWorksheet->setCellValue("D$row", $flaeche);
|
|
$activeWorksheet->setCellValue("E$row", $loggien_flaeche);
|
|
$activeWorksheet->setCellValue("F$row", $loggien_flaeche + $flaeche);
|
|
|
|
$activeWorksheet->setCellValue("AQ$row", $objekt[1][0]['geschoss']);
|
|
$activeWorksheet->setCellValue("AR$row", $objekt[1][0]['orientierung']);
|
|
$activeWorksheet->setCellValue("AT$row", \implode(', ', $beschreibung));
|
|
if (count($loggien_sum)) {
|
|
$activeWorksheet->setCellValue("AU$row", \implode(', ', $loggien_sum));
|
|
}
|
|
if (count($balkon_sum)) {
|
|
$activeWorksheet->setCellValue("AV$row", \implode(', ', $balkon_sum));
|
|
}
|
|
if (count($keller_sum)) {
|
|
$activeWorksheet->setCellValue("AW$row", \implode(', ', $keller_sum));
|
|
}
|
|
$row++;
|
|
}
|
|
|
|
/**
|
|
* Stelleplätze
|
|
*/
|
|
$_projekt = LadeProjekt::project($projekte_id, true);
|
|
foreach ($_projekt as $objekt) {
|
|
$objekt = $objekt[5][0];
|
|
$activeWorksheet->setCellValue("B$row", $objekt['top_nummer']);
|
|
$activeWorksheet->setCellValue("I$row", $objekt['nutzwert']);
|
|
$activeWorksheet->setCellValue("I$row", $objekt['nutzwert']);
|
|
$activeWorksheet->setCellValue("L$row", $objekt['flaeche']);
|
|
$activeWorksheet->setCellValue("AT$row", $objekt['raumart']);
|
|
$row++;
|
|
}
|
|
|
|
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
|
$spreadsheet->setActiveSheetIndex(0);
|
|
// Rename worksheet
|
|
$spreadsheet->getActiveSheet()->setTitle('Daten für den Kaufvertrag');
|
|
// output
|
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
|
// $writer->save('php://output');
|
|
$writer->save($file);
|
|
|
|
$headers = [
|
|
'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
'Cache-Control: max-age=0',
|
|
'Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT',
|
|
'Cache-Control: cache, must-revalidate',
|
|
];
|
|
|
|
return Response::download($file, $filename, $headers);
|
|
}
|
|
|
|
private static function title_reihe()
|
|
{
|
|
return [
|
|
'Bautengruppe',
|
|
'TopNr',
|
|
'NWWhg',
|
|
'Nutzfläche',
|
|
'Loggia',
|
|
'Ges.Nutzfläche',
|
|
'AbstellplatzTop',
|
|
'AbstellplatzTop2',
|
|
'NWAbstellplatz',
|
|
'NWAbstellplatz2',
|
|
'Anzahl Pkw',
|
|
'Stellplatzfläche',
|
|
'Stellplatzfläche2',
|
|
'NW-Whg+Pkw1',
|
|
'NW-Whg+Pkw1+2',
|
|
'Gesamtnutzwert',
|
|
'Gesamtnutzwert2',
|
|
'Parifizierer',
|
|
'Datum_Parifi',
|
|
'Anzahl Whg',
|
|
'Anzahl AP',
|
|
'Durchgang',
|
|
'Anrede',
|
|
'Titel',
|
|
'Vorname',
|
|
'Nachname',
|
|
'Geburt',
|
|
'Beruf',
|
|
'PersonStraße',
|
|
'PLZ',
|
|
'Ort',
|
|
'Partner ja=1',
|
|
'Anrede_P',
|
|
'Titel_P',
|
|
'Vorname_P',
|
|
'Nachname_P',
|
|
'Geburt_P',
|
|
'Beruf_P',
|
|
'Straße_P',
|
|
'Plz_P',
|
|
'Ort_P',
|
|
'Haus',
|
|
'Lage',
|
|
'Orientierung',
|
|
'Orientierung PPL',
|
|
'Beschreibung',
|
|
'Loggien',
|
|
'Balkone',
|
|
'Zubehör',
|
|
'Grundkosten',
|
|
'Baukosten',
|
|
'15% Eigenmittel',
|
|
'zusätz. Eigenmittel',
|
|
'KP-Wohnung und AP',
|
|
'KP-Wohnung',
|
|
'KP-Stellplatz',
|
|
'KP-Stellplatz2',
|
|
'Kaufpreis',
|
|
'UST ja=1',
|
|
'KP WHG netto',
|
|
'Ust WHG',
|
|
'Brutto WHG',
|
|
'KP TG netto',
|
|
'Ust TG',
|
|
'Brutto TG',
|
|
'UST WHG+TG',
|
|
'Netto WHG+TG',
|
|
'Brutto WHG+TG',
|
|
'Fälligk_KP_1',
|
|
'Fälligk_KP_2',
|
|
'Fälligk_KP_3',
|
|
'KPTeil1',
|
|
'KPTeil1 UST',
|
|
'KPTeil2',
|
|
'KPTeil2 UST',
|
|
'KPTeil3',
|
|
'KPTeil3 UST',
|
|
'KPTeil4',
|
|
'KPTeil4 UST',
|
|
'Kontrolle_KP',
|
|
'Kontrolle_KP UST',
|
|
'pfand_ngs',
|
|
'pfand_ngs UST',
|
|
'VertrKo',
|
|
'Bankgarantie',
|
|
'Wohnung.WbfDarlehen',
|
|
'Globaldarlehen',
|
|
'Globaldarlehen abzügl.zusätzl.EM',
|
|
'Globalbank',
|
|
'GrundstückNummer',
|
|
'GstGröße',
|
|
'Einlagezahl',
|
|
'Grundbuch',
|
|
'Baubeginn',
|
|
'Baufertigstellung',
|
|
'Spät_Übergabe',
|
|
'Bau-Ausstatt',
|
|
'Architekt',
|
|
'Baubescheid',
|
|
'Zahl-Baubescheid',
|
|
'Baubescheid2',
|
|
'Zahl-Baubescheid2',
|
|
'UnterschriftKaufvertragAm',
|
|
'Beglaubigungsnummer',
|
|
'UB1_Datum',
|
|
'EFNR1',
|
|
'STNR1',
|
|
'UB2_Datum',
|
|
'EFNR2',
|
|
'STNR2',
|
|
'GVKB_Datum',
|
|
'GVKB_Zahl',
|
|
'Fremdfinanzierung',
|
|
'KPVertr',
|
|
'TZl',
|
|
];
|
|
}
|
|
}
|