Merge branch 'ConstructionConsent/add-export' into 'master'

added export feature constr consent

See merge request fronk/thetool!1303
This commit is contained in:
Luca Haid
2025-05-07 12:07:22 +00:00
3 changed files with 107 additions and 1 deletions

View File

@@ -170,6 +170,10 @@ $pagination_entity_name = "Zustimmungserklärungen";
<?php endif; ?>
</div>
<div class="col text-right">
<a class="btn btn-outline-success" style="cursor: pointer" href="<?=self::getUrl("ConstructionConsent", "downloadCSV", ["filter" => $filter])?>">
<i class="fas fa-file-csv fa-fw" title="CSV Export" aria-hidden="true" class="mr-1 chevron-icon"></i>
CSV Export
</a>
<a class="btn btn-success text-white" style="cursor: pointer" data-toggle="modal" data-target="#downloadModal">
<i class="fas fa-download"></i> Zustimmungserklärungen herunterladen
</a>

View File

@@ -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");

View File

@@ -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();
}
}