diff --git a/Layout/default/ConstructionConsent/Index.php b/Layout/default/ConstructionConsent/Index.php index 638cfe4d7..41c321810 100644 --- a/Layout/default/ConstructionConsent/Index.php +++ b/Layout/default/ConstructionConsent/Index.php @@ -170,6 +170,10 @@ $pagination_entity_name = "Zustimmungserklärungen";
+ $filter])?>"> + + CSV Export + Zustimmungserklärungen herunterladen diff --git a/application/ConstructionConsent/ConstructionConsent.php b/application/ConstructionConsent/ConstructionConsent.php index 837b8b801..1a09bbea6 100644 --- a/application/ConstructionConsent/ConstructionConsent.php +++ b/application/ConstructionConsent/ConstructionConsent.php @@ -115,7 +115,7 @@ class ConstructionConsent extends mfBaseModel { public function getProperty($name) { - if($this->$name == null) { + if($this->$name == null && $name !== 'netzgebiet_id') { if($name == "journal") { $journal = ConstructionConsentJournal::search(["constructionconsent_id" => $this->id], false, "id DESC"); diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php index 5a4b3a0b9..4675c9556 100644 --- a/application/ConstructionConsent/ConstructionConsentController.php +++ b/application/ConstructionConsent/ConstructionConsentController.php @@ -1145,4 +1145,106 @@ class ConstructionConsentController extends mfBaseController { self::returnJson(["results" => $parsedNetworks]); } + protected function downloadCSVAction() { + $filter = $this->request->filter; + if(!is_array($filter)) { + $this->layout()->setFlash("Fehler beim Erstellen der CSV", "error"); + return $this->redirect("ConstructionConsent"); + } + + $filter = $this->getPreparedFilter($filter); + $items = ConstructionConsent::search($filter); + $filename = 'Zustimmungserklärungen_' . date('Ymd_His') . '.csv'; + + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="' . rawurlencode($filename) . '"'); + header('Cache-Control: no-cache, no-store, must-revalidate'); + header('Pragma: no-cache'); + header('Expires: 0'); + + $output = fopen('php://output', 'w'); + fwrite($output, chr(0xEF) . chr(0xBB) . chr(0xBF)); // UTF-8 BOM for Excel + + $headers = [ + 'Projekt', + 'Objekttyp', + 'Objektadresse', + 'Name', + 'EZ', + 'KG', + 'GST', + 'GSTNR', + 'RIMO GN', + 'Nutzungslänge', + 'Leerrohr am Grundstück', + 'Leerrohr im Gebäude', + 'Schacht', + 'Eigentümer', + 'Planer Besichtigung', + 'Elektriker Besichtigung', + 'Leerverrohrung im Gebäude installiert', + 'Leerverrohrung bis FTU installiert', + 'Inhouse Verkabelung', + 'Anzahl Eigentümer', + 'Notiz', + 'Erstellt von', + 'Geändert von', + 'Erstellt am', + 'Geändert am', + 'Genehmigung überschrieben' + ]; + fputcsv($output, $headers, ','); + + if ($items) { + foreach ($items as $item) { + $createUser = UserModel::getOne($item->create_by); + $editUser = UserModel::getOne($item->edit_by); + + + + $address = ""; + if($item->object_type == "street") { + $address = $item->adb_strasse->name . ", " . $item->adb_strasse->ortschaft->name . " " . $item->adb_strasse->gemeinde->name; + } else { + $address = $item->adb_hausnummer->strasse->name . " " . $item->adb_hausnummer->hausnummer . ($item->adb_hausnummer->stiege ? "/".$item->adb_hausnummer->stiege : "") . " " . + $item->adb_hausnummer->plz->plz . " " . $item->adb_hausnummer->ortschaft->name . " " . + $item->adb_hausnummer->strasse->gemeinde->name; + } + + + $row = [ + $item->project->name, + $item->object_type === 'street' ? 'Straße' : 'Gebäude', + $address, + $item->name, + $item->ez, + $item->kg, + $item->gst, + $item->gstnr, + $item->rimo_gn, + $item->usage_length, + $item->usage_pipe_on_plot == 1 ? 'Ja' : 'Nein', + $item->usage_pipe_in_building == 1 ? 'Ja' : 'Nein', + $item->usage_manhole == 1 ? 'Ja' : 'Nein', + $item->usage_owner == 1 ? 'Ja' : 'Nein', + $item->inspection_planner > 0 ? date('d.m.Y H:i:s', $item->inspection_planner) : '', + $item->inspection_electrician > 0 ? date('d.m.Y H:i:s', $item->inspection_electrician) : '', + $item->conduit_installed_building > 0 ? date('d.m.Y H:i:s', $item->conduit_installed_building) : '', + $item->conduit_installed_ftu > 0 ? date('d.m.Y H:i:s', $item->conduit_installed_ftu) : '', + $item->inhouse_cabling > 0 ? date('d.m.Y H:i:s', $item->inhouse_cabling) : '', + $item->owners !== null ? count($item->owners) : '', + $item->note, + $createUser ? $createUser->name : '', + $editUser ? $editUser->name : '', + date('d.m.Y H:i:s', $item->create), + date('d.m.Y H:i:s', $item->edit), + $item->approve_override, + ]; + fputcsv($output, $row, ','); + } + } + + fclose($output); + exit(); + } }