added new features

This commit is contained in:
Luca Haid
2025-03-25 13:49:16 +01:00
parent c94d7de181
commit af6a4e02f5
7 changed files with 199 additions and 33 deletions

View File

@@ -328,10 +328,10 @@ $pagination_entity_name = "Zustimmungserklärungen";
<th>Name</th>
<th>Objekttyp</th>
<th>Objektadresse</th>
<th>KG</th>
<th>GST-Nr.</th>
<th>Einlagezahl</th>
<th class="text-center">Anzahl Eigentümer</th>
<th>Anfragestatus</th>
<th>Anfrageresultat</th>
<th></th>
</tr>
@@ -351,9 +351,9 @@ $pagination_entity_name = "Zustimmungserklärungen";
<?=$item->adb_hausnummer->strasse->gemeinde->name?>
<?php endif; ?>
</td>
<td><?=$item->kg?></td>
<td><?=$item->gst?></td>
<td><?=$item->ez?></td>
<td class="text-center">
<?php
@@ -364,14 +364,16 @@ $pagination_entity_name = "Zustimmungserklärungen";
<?=$owner_count?>
<?php } ?>
</td>
<td><?=($item->status) ? __($item->status,"consent") : ""?></td>
<td>
<?php
// Determine the status based on the counts
$status_class = 'blue'; // Default to blue (all open)
if (isset($item->owner_result_counts['denied']) && $item->owner_result_counts['denied'] > 0) {
$status_class = 'red'; // Red if at least one denied
$approve_override = $item->approve_override;
if (isset($approve_override) && $approve_override) {
$status_class = 'green'; // Blue if approve override
} elseif (isset($item->owner_result_counts['denied']) && $item->owner_result_counts['denied'] > 0) {
$status_class = 'red';
// Red if at least one denied
} elseif ((isset($item->owner_result_counts['unresolvable']) && $item->owner_result_counts['unresolvable'] > 0) ||
(isset($item->owner_result_counts['moved']) && $item->owner_result_counts['moved'] > 0)) {
$status_class = 'yellow'; // Yellow if at least one unresolvable or moved

View File

@@ -111,6 +111,12 @@ $pagination_entity_name = "Adressen";
Die Nutzung der Liegenschaft seitens BB dient der Eigenversorgung der GE und/oder dessen Nutzer(in) und wird dieser entgeltlos zugestimmt
</td>
</tr>
<tr>
<th>Genehmigung überschreiben</th>
<td>
<input type="checkbox" id="approve_override" class="switchery" data-size="small" data-color="#25b343" data-toggle-param="approve_override" <?=($item->approve_override) ? "checked='checked'" : ""?> />
</td>
</tr>
<?php if($item->object_type == "building"): ?>
<tr>
<td colspan="2"><h4>Metadaten</h4></td>
@@ -453,7 +459,6 @@ $pagination_entity_name = "Adressen";
<div class="modal fade" id="newOwnerModal" aria-hidden="true" aria-labelledby="#newOwnerModelLabel" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form method="post" action="<?=self::getUrl("ConstructionConsentOwner", "save")?>">
<div class="modal-header">
<h3 class="modal-title" id="newOwnerModelLabel">Neuen Besitzer hinzufügen</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
@@ -462,6 +467,16 @@ $pagination_entity_name = "Adressen";
</div>
<div class="modal-body">
<?php if ($is_admin): ?>
<div class="form-group">
<label for="owner_id" class="col-form-label">Besitzer aus Vorbestellung suchen:</label>
<select class="form-control" name="owner_id" id="search-owner">
<option></option>
</select>
</div>
<hr>
<?php endif; ?>
<input type="hidden" name="constructionconsent_id" value="<?=$item->id?>" />
<input type="hidden" name="id" value="" />
<h4>Name & Anschrift</h4>
@@ -556,12 +571,6 @@ $pagination_entity_name = "Adressen";
<input type="hidden" name="owner_id" id="owner-upload-owner_id" value="" />
<div class="form-group">
<label for="owner-upload-name" class="col-form-label">Name *</label>
<input type="text" class="form-control" name="name" id="owner-upload-name" />
<small>Beschreibender Kurzname, z.B: Zustimmung oder Ablehnung</small>
</div>
<div class="form-group">
<label for="consentOwnerUpload" class="col-form-label">Datei auswählen *</label>
<input type="file" class="form-control" name="consentOwnerUpload" id="consentOwnerUpload" />
@@ -1053,6 +1062,76 @@ $pagination_entity_name = "Adressen";
});
}
$(document).ready(function() {
$('#search-owner').select2({
dropdownParent: $('#newOwnerModal'),
ajax: {
url: "<?=self::getUrl("ConstructionConsentOwner", "searchOwner")?>",
dataType: 'json',
delay: 250,
data: function(params) {
return {
search: params.term
};
},
processResults: function(data) {
return {
results: data.map(function(item) {
return {
id: item.id,
text: item.text,
fullData: item
};
})
};
},
cache: true
},
minimumInputLength: 2,
placeholder: 'Besitzer suchen...'
});
$('#search-owner').on('select2:select', function(e) {
var selectedData = e.params.data.fullData;
$("#newOwnerModal input[name=firstname]").val(selectedData.firstname);
$("#newOwnerModal input[name=lastname]").val(selectedData.lastname);
$("#newOwnerModal input[name=street]").val(selectedData.street);
$("#newOwnerModal input[name=zip]").val(selectedData.zip);
$("#newOwnerModal input[name=city]").val(selectedData.city);
$("#newOwnerModal input[name=phone]").val(selectedData.phone);
$("#newOwnerModal input[name=email]").val(selectedData.email);
});
$("#approve_override").on("change", function() {
const reason = prompt("Bitte geben Sie einen Grund für das Überschreiben der Genehmigung ein:");
if (reason != null) {
$.post("<?php echo self::getUrl("ConstructionConsentJournal", "save")?>", {
consent_id: <?=$item->id?>,
text: `Genehmigung überschreiben wurde ${$(this).prop("checked") ? "aktiviert" : "deaktiviert"} | Begründung: ${reason}`
}, function(success) {
if (success.status != "OK") {
notify("error", "Status konnte nicht gespeichert werden");
} else {
notify("success", "Status erfolgreich gespeichert");
}
}, 'json');
$.get("<?php echo self::getUrl("ConstructionConsent", "approveOverride")?>", {
consent_id: <?=$item->id?>,
checked: $(this).prop("checked") ? 1 : 0
}, function(success) {
if (success.status != "OK") {
notify("error", "Status konnte nicht gespeichert werden");
setTimeout(() => {location.reload()}, 150);
} else {
notify("success", "Status erfolgreich gespeichert");
setTimeout(() => {location.reload()}, 150);
}
}, 'json');
}
});
});
</script>

View File

@@ -386,22 +386,46 @@ class ConstructionConsent extends mfBaseModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT
ConstructionConsent.*,
COALESCE(SUM(cwo.result = 'denied'), 0) AS denied_count,
COALESCE(SUM(cwo.result = 'unresolvable'), 0) AS unresolvable_count,
COALESCE(SUM(cwo.result = 'moved'), 0) AS moved_count,
COALESCE(SUM(cwo.result = 'accepted'), 0) AS accepted_count,
COUNT(cwo.id) AS total_owners,
CASE
WHEN COALESCE(SUM(cwo.result = 'denied'), 0) > 0 THEN 'red'
WHEN COALESCE(SUM(cwo.result = 'unresolvable'), 0) > 0
OR COALESCE(SUM(cwo.result = 'moved'), 0) > 0 THEN 'yellow'
WHEN COALESCE(SUM(cwo.result = 'accepted'), 0) = COUNT(cwo.id)
AND COUNT(cwo.id) > 0 THEN 'green'
ELSE 'blue'
END AS status_light
FROM ConstructionConsent
$sql = "SELECT ConstructionConsent.*,
COALESCE(SUM(CASE
WHEN ConstructionConsent.approve_override = 1 THEN 0
ELSE (cwo.result = 'denied')
END), 0) AS denied_count,
COALESCE(SUM(CASE
WHEN ConstructionConsent.approve_override = 1 THEN 0
ELSE (cwo.result = 'unresolvable')
END), 0) AS unresolvable_count,
COALESCE(SUM(CASE
WHEN ConstructionConsent.approve_override = 1 THEN 0
ELSE (cwo.result = 'moved')
END), 0) AS moved_count,
COALESCE(SUM(CASE
WHEN ConstructionConsent.approve_override = 1 THEN 1
ELSE (cwo.result = 'accepted')
END), 0) AS accepted_count,
COUNT(cwo.id) AS total_owners,
CASE
WHEN ConstructionConsent.approve_override = 1 THEN 'green'
WHEN COALESCE(SUM(CASE
WHEN approve_override = 1 THEN 0
ELSE (cwo.result = 'denied')
END), 0) > 0 THEN 'red'
WHEN COALESCE(SUM(CASE
WHEN approve_override = 1 THEN 0
ELSE (cwo.result = 'unresolvable')
END), 0) > 0
OR COALESCE(SUM(CASE
WHEN approve_override = 1 THEN 0
ELSE (cwo.result = 'moved')
END), 0) > 0 THEN 'yellow'
WHEN COALESCE(SUM(CASE
WHEN approve_override = 1 THEN 1
ELSE (cwo.result = 'accepted')
END), 0) = COUNT(cwo.id)
AND COUNT(cwo.id) > 0 THEN 'green'
ELSE 'blue'
END AS status_light
FROM ConstructionConsent
LEFT JOIN ConstructionConsentOwner cwo ON ConstructionConsent.id = cwo.constructionconsent_id
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer vh ON ConstructionConsent.adb_hausnummer_id = vh.hausnummer_id
LEFT JOIN `".ADDRESSDB_DBNAME."`.Strasse vs ON ConstructionConsent.adb_strasse_id = vs.id

View File

@@ -111,6 +111,7 @@ class ConstructionConsentController extends mfBaseController {
protected function viewAction() : void {
$this->layout()->setTemplate("ConstructionConsent/View");
$this->layout()->set("is_admin", $this->me->isAdmin());
$id = $this->request->id;
if(!is_numeric($id) || $id < 1) {
@@ -1027,4 +1028,20 @@ class ConstructionConsentController extends mfBaseController {
"status_light_green" => getFilteredCount("status_light", "green", $baseFilter)
];
}
protected function approveOverrideAction() {
$consent_id = $this->request->consent_id;
$checked = $this->request->checked;
$consent = new ConstructionConsent($consent_id);
if(!$consent->id) {
$this->returnJson(["status" => "error"]);
}
$consent->update(["approve_override" => $checked]);
$consent->save();
$this->returnJson(["status" => "OK"]);
}
}

View File

@@ -70,14 +70,14 @@ class ConstructionConsentHistory extends mfBaseModel {
return "Nutzung Schacht/Verteiler/Abschluss";
case "usage_owner":
return "Nutzung Eigenvers. GE";
case "approve_override":
return "Genehmigung überschreiben";
case "rimo_plan":
return "Plan/Skizze aus Rimo";
case "plan_upload":
return "Plan/Skizze Upload";
case "constructionconsentproject_id":
return "Projekt";
case "inspection_planner":
return "Status Begehung mit Planer";
case "inspection_electrician";

View File

@@ -20,14 +20,16 @@ class ConstructionConsentOwnerController extends mfBaseController
protected function uploadDocumentAction() {
$owner_id = $this->request->owner_id;
$filename = trim($this->request->name);
$owner = new ConstructionConsentOwner($owner_id);
if(!$owner->id) {
$this->layout()->setFlash("Besitzer nicht gefunden!", "error");
$this->redirect("ConstructionConsent");
}
$constructionConsent = new ConstructionConsent($owner->constructionconsent_id);
$filename = "ZU_KG" . $constructionConsent->kg . "_EZ" . $constructionConsent->ez . "_GST" . $constructionConsent->gst . "_" . $constructionConsent->name . "_" . $owner->lastname . ".pdf";
$_FILES['consentOwnerUpload']['name'] = $filename;
if(is_array($_FILES) && array_key_exists("consentOwnerUpload", $_FILES) && !$_FILES['consentOwnerUpload']['error']) {
try {
// returns File object or throws Exception on error
@@ -221,4 +223,23 @@ class ConstructionConsentOwnerController extends mfBaseController
return ["message" => "Result saved successfully", "update" => ["id" => $owner->id, "result" => $owner->result, "result_text" => __($owner->result, "consent")]];
}
protected function searchOwnerAction() {
$search = $this->request->search;
$results = PreorderModel::search(['add-where' => " AND firstname LIKE '%$search%' OR lastname LIKE '%$search%'"]);
self::returnJson(array_map(function($result) {
return [
'id' => $result->id,
'firstname' => $result->firstname,
'lastname' => $result->lastname,
'street' => $result->street,
'zip' => $result->zip,
'city' => $result->city,
'phone' => $result->phone,
'email' => $result->email,
'text' => $result->firstname . " " . $result->lastname . " (" . $result->street . ", " . $result->zip . " " . $result->city . ") [" . $result->phone . " | " . $result->email . "]"
];
}, $results));
}
}

View File

@@ -0,0 +1,23 @@
<?php declare(strict_types = 1);
use Phinx\Migration\AbstractMigration;
final class ConstrConsentAddApproveOverride extends AbstractMigration {
public function up(): void {
if ($this->getEnvironment() == "thetool") {
$ConstructionConsentTable = $this->table("ConstructionConsent");
$ConstructionConsentTable
->addColumn("approve_override", "tinyinteger", ["default" => 0])
->save();
}
}
public function down(): void {
if ($this->getEnvironment() == "thetool") {
$ConstructionConsentTable = $this->table("ConstructionConsent");
$ConstructionConsentTable
->removeColumn("approve_override")
->save();
}
}
}