Added Journal/History/Contacts to ConstructionConsent

This commit is contained in:
Frank Schubert
2025-01-21 22:54:15 +01:00
parent 1db38f4b11
commit c0451c2621
14 changed files with 1084 additions and 27 deletions

View File

@@ -377,6 +377,18 @@
} }
$("#kg").change(updateGstnr);
$("#gst").change(updateGstnr);
function updateGstnr() {
let kg = $("#kg").val();
let gst = $("#gst").val();
if(!kg || !gst) return;
$("#gstnr").val(kg + gst);
}
</script> </script>
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?> <?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>

View File

@@ -60,10 +60,10 @@ $pagination_entity_name = "Adressen";
<?=$item->adb_hausnummer->strasse->gemeinde->name?> <?=$item->adb_hausnummer->strasse->gemeinde->name?>
</td> </td>
</tr><tr> </tr><tr>
<th>Anzahl Wohneinheiten</th> <th>Wohneinheiten</th>
<td><?=$item->adb_hausnummer->unit_count?></td> <td><?=$item->adb_hausnummer->unit_count?></td>
</tr><tr> </tr><tr>
<th>Anzahl Bestellungen</th> <th>Bestellungen</th>
<td><?=$item->preorder_count?></td> <td><?=$item->preorder_count?></td>
</tr> </tr>
<?php else: ?> <?php else: ?>
@@ -159,6 +159,43 @@ $pagination_entity_name = "Adressen";
</div> </div>
<div class="col-7"> <div class="col-7">
<div class="card border-top-warning">
<div class="card-body">
<h3 class="text-center mb-3">Ansprechpartner
<small><a data-toggle="modal" data-target="#newContactModal" href="#"><i class="fas fa-plus"></i> Neuen Ansprechpartner hinzufügen</a></small>
</h3>
<?php if(!is_array($item->contacts) || !count($item->contacts)): ?>
<i>Keine Ansprechpartner eingetragen</i>
<?php else: ?>
<table class="table table-sm table-striped table-hover">
<tr>
<th>Kontakttyp</th>
<th>Name</th>
<th>Telefon</th>
<th>Fax</th>
<th>Email</th>
<th></th>
</tr>
<?php foreach($item->contacts as $type => $contacts): ?>
<?php foreach($contacts as $contact): ?>
<tr>
<td class="text-monospace"><?=__($contact->type, "consent")?></td>
<td><?=$contact->name?></td>
<td><?=$contact->phone?></td>
<td><?=$contact->fax?></td>
<td><?=$contact->email?></td>
<td>
<!--a href="<?=self::getUrl("ConstructionConsentContact", "edit", ["contact_id" => $contact->id])?>" title="Ansprechpartner bearbeiten"><i class="far fa-fw fa-edit"></i></a-->
<a href="<?=self::getUrl("ConstructionConsentContact", "delete", ["contact_id" => $contact->id])?>" onclick="if(!confirm('Ansprechpartner wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
</div>
<div class="card border-top-success"> <div class="card border-top-success">
<div class="card-body"> <div class="card-body">
@@ -196,12 +233,13 @@ $pagination_entity_name = "Adressen";
<?=$owner->email?> <?=$owner->email?>
</td> </td>
<td class="text-monospace"> <td class="text-monospace">
<span id="status-<?=$owner->id?>-text" data-status-id="<?=$owner->status?>"><span id="status-<?=$owner->id?>-statustext"><?=__($owner->status, "consent")?></span> <a href="#" onclick="return toggleStatusControl(<?=$owner->id?>)"><i class="fas fa-fw fa-edit"></i></a></span> <span id="status-<?=$owner->id?>-text" data-status-id="<?=$owner->status?>"><span id="status-<?=$owner->id?>-statustext"><?=($owner->status) ? __($owner->status, "consent") : ""?></span> <a href="#" onclick="return toggleStatusControl(<?=$owner->id?>)"><i class="fas fa-fw fa-edit"></i></a></span>
<div class="input-group" id="status-<?=$owner->id?>-input" style="display:none"> <div class="input-group" id="status-<?=$owner->id?>-input" style="display:none">
<select class="form-control"> <select class="form-control">
<option value="new" <?=($owner->status == "new") ? "selected='selected'" : ""?>><?=__("new", "consent")?></option> <option value="new" <?=($owner->status == "new") ? "selected='selected'" : ""?>><?=__("new", "consent")?></option>
<option value="requested" <?=($owner->status == "requested") ? "selected='selected'" : ""?>><?=__("requested", "consent")?></option> <option value="sent" <?=($owner->status == "sent") ? "selected='selected'" : ""?>><?=__("sent", "consent")?></option>
<option value="answered" <?=($owner->status == "answered") ? "selected='selected'" : ""?>><?=__("answered", "consent")?></option> <option value="returned" <?=($owner->status == "returned") ? "selected='selected'" : ""?>><?=__("returned", "consent")?></option>
<option value="outstanding" <?=($owner->status == "outstanding") ? "selected='selected'" : ""?>><?=__("outstanding", "consent")?></option>
</select> </select>
<div class="input-group-append"> <div class="input-group-append">
<button type="button" class="btn btn-primary" title="Speichern" onclick="saveStatusControl(<?=$owner->id?>)"><i class="fas fa-check"></i></button> <button type="button" class="btn btn-primary" title="Speichern" onclick="saveStatusControl(<?=$owner->id?>)"><i class="fas fa-check"></i></button>
@@ -214,8 +252,10 @@ $pagination_entity_name = "Adressen";
<div class="input-group" id="result-<?=$owner->id?>-input" style="display:none"> <div class="input-group" id="result-<?=$owner->id?>-input" style="display:none">
<select class="form-control"> <select class="form-control">
<option></option> <option></option>
<option value="success" <?=($owner->result == "success") ? "selected='selected'" : ""?>><?=__("success", "consent")?></option> <option value="open" <?=($owner->result == "open") ? "selected='selected'" : ""?>><?=__("open", "consent")?></option>
<option value="failure" <?=($owner->result == "failure") ? "selected='selected'" : ""?>><?=__("failure", "consent")?></option> <option value="accepted" <?=($owner->result == "accepted") ? "selected='selected'" : ""?>><?=__("accepted", "consent")?></option>
<option value="denied" <?=($owner->result == "denied") ? "selected='selected'" : ""?>><?=__("denied", "consent")?></option>
<option value="unresolvable" <?=($owner->result == "unresolvable") ? "selected='selected'" : ""?>><?=__("unresolvable", "consent")?></option>
</select> </select>
<div class="input-group-append"> <div class="input-group-append">
<button type="button" class="btn btn-primary" title="Speichern" onclick="saveResultControl(<?=$owner->id?>)"><i class="fas fa-check"></i></button> <button type="button" class="btn btn-primary" title="Speichern" onclick="saveResultControl(<?=$owner->id?>)"><i class="fas fa-check"></i></button>
@@ -239,14 +279,86 @@ $pagination_entity_name = "Adressen";
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="card border-top-warning">
<div class="card-body">
<h4>Journal</h4>
<div class="card">
<div class="card-body">
<button type="button" class="btn btn-sm btn-info" onclick="$('#new-journal').toggle(); $('#new-journal-text').focus()"><i class="fas fa-plus"></i> Neuer Journaleintrag</button>
<div id="new-journal" class="hidden mt-2">
<form method="post" action="<?=self::getUrl("ConstructionConsentJournal", "save")?>">
<input type="hidden" name="consent_id" value="<?=$item->id?>" />
<textarea id="new-journal-text" name="text" class="form-control mb-2" style="height:120px;" placeholder="Text hier eingeben..."></textarea>
<button class="btn btn-sm btn-primary" type="submit"><i class="fas fa-save"></i> Speichern</button>
</form>
</div>
</div>
</div>
<table class="table table-striped table-sm journal">
<?php foreach($item->journal as $j): ?>
<tr>
<td style="white-space: nowrap" class="text-monospace"><?=date("d.m.Y H:i", $j->create)?> (<?=$j->creator?>)</td>
<td style="width: 100%">
<?=nl2br($j->text)?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="card border-top-info">
<div class="card-body">
<h4>History</h4>
<div style="max-height: 550px; overflow: scroll">
<table class="table table-sm table-striped">
<tr>
<th>Zeitpunkt</th>
<th>Benutzer</th>
<th>Feld</th>
<th>Alter Wert</th>
<th>Neuer Wert</th>
</tr>
<?php foreach($item->history as $history): ?>
<tr>
<td class="text-monospace"><?=date("d.m.Y H:i:s", $history->create)?></td>
<td><?=$history->creator->name?></td>
<td><?=$history->getKey()?></td>
<td class="text-monospace"><?=$history->getText("old")?></td>
<td class="text-monospace"><?=$history->getText("new")?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row">
</div> </div>
<div class="modal fade" id="newOwnerModal" aria-hidden="true" aria-labelledby="#newOwnerModelLabel" tabindex="-1"> <div class="modal fade" id="newOwnerModal" aria-hidden="true" aria-labelledby="#newOwnerModelLabel" tabindex="-1">
<div class="modal-dialog"> <div class="modal-dialog modal-dialog-centered">
<div class="modal-content"> <div class="modal-content">
<form method="post" action="<?=self::getUrl("ConstructionConsentOwner", "save")?>"> <form method="post" action="<?=self::getUrl("ConstructionConsentOwner", "save")?>">
<div class="modal-header"> <div class="modal-header">
@@ -353,6 +465,79 @@ $pagination_entity_name = "Adressen";
</div> </div>
</div> </div>
<div class="modal fade" id="newContactModal" aria-hidden="true" aria-labelledby="#newContactModelLabel" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form method="post" action="<?=self::getUrl("ConstructionConsentContact", "save")?>">
<div class="modal-header">
<h3 class="modal-title" id="newContactModelLabel">Neuen Ansprechpartner hinzufügen</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="constructionconsent_id" value="<?=$item->id?>" />
<div class="form-group">
<label for="street" class="col-form-label">Kontakttyp:</label>
<select class="form-control" name="type" id="contact_type">
<option value="property_manager">Hausverwaltung</option>
<option value="electrician">Elektriker</option>
<option value="contact">Ansprechpartner</option>
<option value="other">Sonstige</option>
</select>
</div>
<div class="form-group">
<label for="name" class="col-form-label">Name: *</label>
<textarea class="form-control" name="name" id="contact_name"></textarea>
</div>
<div class="form-group">
<label for="street" class="col-form-label">Straße:</label>
<input type="text" class="form-control" name="street" id="contact_street" />
</div>
<div class="form-group">
<label for="zip" class="col-form-label">PLZ / Ort:</label>
<div class="row">
<div class="col-4">
<input type="text" class="form-control" name="zip" id="contact_zip" />
</div>
<div class="col-8">
<input type="text" class="form-control" name="city" id="contact_city" />
</div>
</div>
</div>
<div class="form-group">
<label for="phone" class="col-form-label">Telefon:</label>
<input type="text" class="form-control" name="phone" id="contact_phone" />
</div>
<div class="form-group">
<label for="fax" class="col-form-label">Fax:</label>
<input type="text" class="form-control" name="fax" id="contact_fax" />
</div>
<div class="form-group">
<label for="email" class="col-form-label">Email:</label>
<input type="text" class="form-control" name="email" id="contact_email" />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Abbrechen</button>
<button type="submit" class="btn btn-primary">Speichern</button>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript"> <script type="text/javascript">
@@ -457,6 +642,11 @@ $pagination_entity_name = "Adressen";
'json'); 'json');
} }
function toggleJournal(order_id) {
$("#journal-container").find("div.opener").remove();
$("#journal-container").css("max-height", "750px").css("overflow", "auto");
}
</script> </script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?> <?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -7,16 +7,44 @@ class ConstructionConsent extends mfBaseModel {
private $adb_hausnummer; private $adb_hausnummer;
private $adb_strasse; private $adb_strasse;
private $owners; private $owners;
private $contacts;
private $file; private $file;
private $creator; private $creator;
private $editor; private $editor;
private $preorder_count; private $preorder_count;
private $journal;
private $history;
private $footer_text = "Energie Steiermark Breitband GmbH, A-8010 Graz, Leonhardgürtel 10, Telefon +43 (0)316 9000-0\nSitz Graz, FN 576705x, Landesgericht für ZRS Graz, ATU 77949678, breitband@e-steiermark.com, www.e-steiermark.com"; private $footer_text = "Energie Steiermark Breitband GmbH, A-8010 Graz, Leonhardgürtel 10, Telefon +43 (0)316 9000-0\nSitz Graz, FN 576705x, Landesgericht für ZRS Graz, ATU 77949678, breitband@e-steiermark.com, www.e-steiermark.com";
private $footer_font = "ITC Officina Sans Std"; private $footer_font = "ITC Officina Sans Std";
private $footer_size = "8"; private $footer_size = "8";
protected function afterSave() {
$this->createHistory();
}
private function createHistory() {
if(!$this->id) return true;
$changed = $this->getChangedFields();
try {
foreach($changed as $field) {
$this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'");
$history = ConstructionConsentHistory::create([
"constructionconsent_id" => $this->id,
"key" => $field,
"old_value" => $this->_old_data->$field,
"new_value" => $this->data->$field
]);
$history->save();
}
} catch(Exception $e) {
$this->log->debug($e->getTraceAsString());
}
}
public function createConsentFormPdf(ConstructionConsentOwner $owner = null) : ?string { public function createConsentFormPdf(ConstructionConsentOwner $owner = null) : ?string {
if($owner) { if($owner) {
$owners = [$owner]; $owners = [$owner];
@@ -53,6 +81,21 @@ class ConstructionConsent extends mfBaseModel {
public function getProperty($name) { public function getProperty($name) {
if($this->$name == null) { if($this->$name == null) {
if($name == "journal") {
$journal = ConstructionConsentJournal::search(["constructionconsent_id" => $this->id], false, "id DESC");
if($journal) {
$this->journal = $journal;
}
return $journal;
}
if($name == "history") {
$history = ConstructionConsentHistory::search(["constructionconsent_id" => $this->id], false, "id DESC");
if($history) {
$this->history = $history;
}
return $history;
}
if($name == "project") { if($name == "project") {
$project = new ConstructionConsentProject($this->constructionconsentproject_id); $project = new ConstructionConsentProject($this->constructionconsentproject_id);
if($project->id) { if($project->id) {
@@ -98,7 +141,7 @@ class ConstructionConsent extends mfBaseModel {
} }
if($name == "owners") { if($name == "owners") {
if(!$this->id) return null; if(!$this->id) return [];
$owners = ConstructionConsentOwner::search(["constructionconsent_id" => $this->id]); $owners = ConstructionConsentOwner::search(["constructionconsent_id" => $this->id]);
if(count($owners)) { if(count($owners)) {
@@ -107,8 +150,23 @@ class ConstructionConsent extends mfBaseModel {
return $this->owners; return $this->owners;
} }
if($name == "contacts") {
if(!$this->id) return [];
$contacts = [];
foreach(ConstructionConsentContact::search(["constructionconsent_id" => $this->id]) as $contact) {
if(!array_key_exists($contact->type, $contacts)) {
$contacts[$contact->type] = [];
}
$contacts[$contact->type][] = $contact;
}
if(count($contacts)) {
$this->contacts = $contacts;
}
return $contacts;
}
if($name == "file") { if($name == "file") {
if(!$this->id) return null; if(!$this->id) return [];
$file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $this->id]); $file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $this->id]);
if($file) { if($file) {
$this->file = $file; $this->file = $file;

View File

@@ -268,9 +268,22 @@ class ConstructionConsentController extends mfBaseController {
return $this->editAction(); return $this->editAction();
} }
$history = ConstructionConsentHistory::create([
"constructionconsent_id" => $item->id,
"key" => "plan_upload",
"old_value" => ($item->file) ? $item->file->file->id : null,
"new_value" => $file->id
]);
} else { } else {
if($r->submit_plan_file_id) { if($r->submit_plan_file_id) {
$file = new File($r->submit_plan_file_id); $file = new File($r->submit_plan_file_id);
$history = ConstructionConsentHistory::create([
"constructionconsent_id" => $item->id,
"key" => "rimo_plan",
"old_value" => ($item->file) ? $item->file->file->id : null,
"new_value" => $file->id
]);
} }
} }
@@ -291,6 +304,8 @@ class ConstructionConsentController extends mfBaseController {
if (!$ccf->save()) { if (!$ccf->save()) {
$this->layout()->setFlash("Fehler beim Speichern des Plans", "warning"); $this->layout()->setFlash("Fehler beim Speichern des Plans", "warning");
} }
$history->save();
} }

View File

@@ -0,0 +1,180 @@
<?php
class ConstructionConsentContact extends mfBaseModel {
private $consent;
public function getProperty($name) {
if($this->$name == null) {
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
/********************************
* Begin static Model functions
*/
public static function create(Array $data) {
$model = new ConstructionConsentContact();
$table_fields = [
"constructionconsent_id", "type", "name", "street", "zip", "city",
"phone", "fax", "email", "create_by","edit_by","create","edit"
];
foreach($data as $field => $value) {
if(in_array($field, $table_fields)) {
$model->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("ConstructionConsentContact", "*", "1 = 1 ORDER BY name");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ConstructionConsentContact($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT ConstructionConsentContact.* FROM ConstructionConsentContact
WHERE $where
ORDER BY adb_netzgebiet_id
LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ConstructionConsentContact($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function count($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM ConstructionConsentContact
WHERE $where
ORDER BY adb_netzgebiet_id
";
//mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false, $order = false) {
//var_dump($filter);exit;
$items = [];
if(!$order) {
$order = "name ASC";
}
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT ConstructionConsentContact.* FROM ConstructionConsentContact
WHERE $where
GROUP BY ConstructionConsentContact.id
ORDER BY $order";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[$data->id] = new ConstructionConsentContact($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
$db = FronkDB::singleton();
if(array_key_exists("constructionconsent_id", $filter)) {
$constructionconsent_id = $filter["constructionconsent_id"];
if(is_numeric($constructionconsent_id)) {
$where .= " AND constructionconsent_id='$constructionconsent_id'";
}
}
if(array_key_exists("type", $filter)) {
$type = $db->escape($filter["type"]);
if($type) {
$where .= " AND `type`='$type'";
}
}
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,98 @@
<?php
class ConstructionConsentContactController extends mfBaseController
{
protected function init(): void
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
protected function saveAction()
{
$r = $this->request;
//var_dump($r->get());exit;
$id = $r->contact_id;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$item = new ConstructionConsentContact($id);
if (!$item->id) {
$this->layout()->setFlash("Ansprechpartner nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
} else {
$id = false;
$mode = "add";
}
$cc_id = $r->constructionconsent_id;
$cc = new ConstructionConsent($cc_id);
if(!$cc_id || !$cc->id) {
$this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
$this->redirect("ConstructionConsent");
}
$data = [];
$data["constructionconsent_id"] = $cc_id;
$data["type"] = $r->type;
$data["name"] = $r->name;
$data["street"] = $r->street;
$data["zip"] = $r->zip;
$data["city"] = $r->city;
$data["country"] = $r->country;
$data["phone"] = $r->phone;
$data["fax"] = $r->fax;
$data["email"] = $r->email;
if($mode == "add") {
$item = ConstructionConsentContact::create($data);
} else {
$item->update($data);
}
if(!$item->save()) {
$this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
} else {
$this->layout()->setFlash("Ansprechpartner wurde erfolgreich gespeichert.", "success");
}
$this->redirect("ConstructionConsent", "View", ["id" => $cc_id]);
}
protected function deleteAction() {
$r = $this->request;
//var_dump($r->get());exit;
$id = $r->contact_id;
if(!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Ansprechpartner nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$contact = new ConstructionConsentContact($id);
if(!$contact->id) {
$this->layout()->setFlash("Ansprechpartner nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$cc_id = $contact->constructionconsent_id;
$cc = new ConstructionConsent($cc_id);
if(!$cc_id || !$cc->id) {
$this->layout()->setFlash("Beim Löschen ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
$this->redirect("ConstructionConsent");
}
$contact->delete();
$this->layout()->setFlash("Ansprechpartner wurde gelöscht.", "success");
$this->redirect("ConstructionConsent", "View", ["id" => $cc_id]);
}
}

View File

@@ -0,0 +1,317 @@
<?php
class ConstructionConsentHistory extends mfBaseModel {
private $consent;
private $creator;
private $editor;
public function getValue($type = "new", $raw = false) {
if($type != "old" && $type != "new") return null;
if($type == "new") {
$value = $this->new_value;
} else {
$value = $this->old_value;
}
if($raw) {
return $value;
}
$m = [];
if(preg_match('/(.+)_id/', $this->key, $m)) {
if(array_key_exists(1, $m)) {
$object = ucfirst($m[1]);
if($object == "Status") $object = "Preorderstatus";
if($object == "Partner") $object = "Address";
if($object == "Adb_hausnummer") $object = "ADBHausnummer";
if($object == "Adb_wohneinheit") $object = "ADBWohneinheit";
if($object == "Constructionconsentproject") $object = "ConstructionConsentProject";
if(class_exists($object)) {
$value = new $object($value);
if(!$value->id) return null;
}
}
}
return $value;
}
public function getKey() {
$key = $this->key;
if(preg_match('/^preorderstatusflag-(\d+)-/', $key, $m)) {
if(array_key_exists(1, $m)) {
$id = $m[1];
$psf = new Preorderstatusflag($id);
return "Status Flag ".$psf->code." - ".$psf->name;
}
}
switch($key) {
case "usage_length":
return "Nutzung Länge";
case "usage_pipe_on_plot":
return "Nutzung LWL auf Gst.";
case "usage_pipe_in_building":
return "Nutzung LWL in Gebäuden";
case "usage_manhole":
return "Nutzung Schacht/Verteiler/Abschluss";
case "usage_owner":
return "Nutzung Eigenvers. GE";
case "rimo_plan":
return "Plan/Skizze aus Rimo";
case "plan_upload":
return "Plan/Skizze Upload";
case "constructionconsentproject_id":
return "Projekt";
}
return $key;
}
public function getText($type = "new") {
$value = $this->getValue($type);
if($value === null) return "";
if($this->key == "attributes") {
$attribs = "";
$jdec = json_decode($value);
if(is_object($jdec)) {
foreach(get_object_vars($jdec) as $k => $v) {
$attribs .= "$k: $v<br />";
}
return $attribs;
}
}
if(!is_object($value)) {
return $value;
}
if(get_class($value) == "Preorderstatus") {
return $value->code." - ".$value->name;
}
if(get_class($value) == "Address") {
return $value->getCompanyOrName();
}
if(get_class($value) == "ADBHausnummer") {
return $value->getAddress();
}
if(get_class($value) == "ADBWohneinheit") {
return $value->id." - ".(string)$value;
}
if(get_class($value) == "Preordercampaign") {
return $value->name;
}
if(get_class($value) == "ConstructionConsentProject") {
return $value->name;
}
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "old" || $name == "new") {
return $this->getValue($name, false);
}
if($name == "old_raw") {
return $this->getValue("old", true);
}
if($name == "new_raw") {
return $this->getValue("new", true);
}
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) {
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
}
return $this->creator;
}
if($name == "editor") {
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($this->editor === null) {
$this->editor = new User($this->edit_by);
if($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
/********************************
* Begin static Model functions
*/
public static function create(Array $data) {
$model = new ConstructionConsentHistory();
$table_fields = [
"constructionconsent_id", "key", "old_value", "new_value",
"create_by","edit_by","create","edit"
];
foreach($data as $field => $value) {
if(in_array($field, $table_fields)) {
$model->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("ConstructionConsentHistory", "*", "1 = 1 ORDER BY `create`");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ConstructionConsentHistory($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT ConstructionConsentHistory.* FROM ConstructionConsentHistory
WHERE $where
ORDER BY adb_netzgebiet_id
LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ConstructionConsentHistory($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function count($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM ConstructionConsentHistory
WHERE $where
ORDER BY adb_netzgebiet_id
";
//mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false, $order = false) {
//var_dump($filter);exit;
$items = [];
if(!$order) {
$order = "`create` ASC";
}
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT ConstructionConsentHistory.* FROM ConstructionConsentHistory
WHERE $where
GROUP BY ConstructionConsentHistory.id
ORDER BY $order";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[$data->id] = new ConstructionConsentHistory($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
$db = FronkDB::singleton();
if(array_key_exists("constructionconsent_id", $filter)) {
$constructionconsent_id = $filter["constructionconsent_id"];
if(is_numeric($constructionconsent_id)) {
$where .= " AND constructionconsent_id='$constructionconsent_id'";
}
}
if(array_key_exists("key", $filter)) {
$key = $db->escape($filter["key"]);
if($key) {
$where .= " AND `key`='$key'";
}
}
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -2,9 +2,32 @@
class ConstructionConsentJournal extends mfBaseModel { class ConstructionConsentJournal extends mfBaseModel {
private $creator;
private $editor;
public function getProperty($name) { public function getProperty($name) {
if($this->$name == null) { if($this->$name == null) {
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) {
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
}
return $this->creator;
}
if($name == "editor") {
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($this->editor === null) {
$this->editor = new User($this->edit_by);
if($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name); $classname = ucfirst($name);
$idfield = $name."_id"; $idfield = $name."_id";
@@ -33,7 +56,7 @@ class ConstructionConsentJournal extends mfBaseModel {
$model = new ConstructionConsentJournal(); $model = new ConstructionConsentJournal();
$table_fields = [ $table_fields = [
"constructionconsent_id", "type", "value", "text", "constructionconsent_id", "text",
"create_by","edit_by","create","edit" "create_by","edit_by","create","edit"
]; ];

View File

@@ -0,0 +1,58 @@
<?php
class ConstructionConsentJournalController extends mfBaseController {
protected function init() {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
if(!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
protected function saveAction() {
$r = $this->request;
//var_dump($r);exit;
$consent_id = $r->consent_id;
if(!is_numeric($consent_id) || $consent_id < 1) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden!", "error");
$this->redirect("ConstructionConsent");
}
$consent = new ConstructionConsent($consent_id);
if(!$consent->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden!", "error");
$this->redirect("ConstructionConsent");
}
$text = trim(htmlentities($r->text));
if(!$text) {
$this->layout()->setFlash("Bitte Text eingeben", "error");
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
}
$journal = ConstructionConsentJournal::create([
"constructionconsent_id" => $consent->id,
"text" => $text
]);
if(!$journal->save()) {
$this->layout()->setFlash("Fehler beim speichern!", "error");
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
}
$this->layout()->setFlash("Journaleintrag gespeichert", "success");
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
}
}

View File

@@ -6,6 +6,31 @@ class ConstructionConsentOwner extends mfBaseModel {
private $result_file; private $result_file;
protected function afterSave() {
$this->createHistory();
}
private function createHistory() {
if(!$this->id) return true;
$changed = $this->getChangedFields();
try {
foreach($changed as $field) {
$this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'");
$history = ConstructionConsentHistory::create([
"constructionconsent_id" => $this->id,
"key" => "owner-".$this->id."-$field",
"old_value" => $this->_old_data->$field,
"new_value" => $this->data->$field
]);
$history->save();
}
} catch(Exception $e) {
$this->log->debug($e->getTraceAsString());
}
}
public function getProperty($name) { public function getProperty($name) {
if($this->$name == null) { if($this->$name == null) {

View File

@@ -143,7 +143,7 @@ class ConstructionConsentOwnerController extends mfBaseController
return false; return false;
} }
if(!in_array($new_status, ["new", "requested", "answered"])) { if(!in_array($new_status, ['new', 'sent', 'returned', 'outstanding'])) {
return false; return false;
} }
@@ -164,26 +164,16 @@ class ConstructionConsentOwnerController extends mfBaseController
return false; return false;
} }
// allow empty result if(!in_array($new_result, ['open', 'accepted', 'denied', 'unresolvable'])) {
if($new_result) { return false;
if(!in_array($new_result, ["success", "failure"])) {
return false;
}
$owner->result = $new_result;
} else {
$owner->result = null;
} }
$owner->result = $new_result;
if(!$owner->save()) { if(!$owner->save()) {
return false; return false;
} }
if($owner->result) { return ["message" => "Result saved successfully", "update" => ["id" => $owner->id, "result" => $owner->result, "result_text" => __($owner->result, "consent")]];
return ["message" => "Result saved successfully", "update" => ["id" => $owner->id, "result" => $owner->result, "result_text" => __($owner->result, "consent")]];
} else {
return ["message" => "Result saved successfully", "update" => ["id" => $owner->id, "result" => null, "result_text" => ""]];
}
} }
} }

View File

@@ -35,6 +35,7 @@ final class CreateConstructionConsentHistoryAndContact extends AbstractMigration
->addColumn("create", "integer", ["null" => false]) ->addColumn("create", "integer", ["null" => false])
->addColumn("edit", "integer", ["null" => false]); ->addColumn("edit", "integer", ["null" => false]);
$ccc->create(); $ccc->create();
} }
if($this->getEnvironment() == "addressdb") { if($this->getEnvironment() == "addressdb") {

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class ConstructionConsentChangeStatusAndResult extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("ConstructionConsent");
$table->changeColumn("status", "enum", ["null" => true, "default" => null, "values" => "new,sent,returned,outstanding"]);
$table->changeColumn("result", "enum", ["null" => true, "default" => null, "values" => "open,accepted,denied,unresolvable"]);
$table->addColumn("inspection_date_planner", "integer", ["null" => true, "default" => null, "after" => "result_text"]);
$table->addColumn("inspection_date_electrician", "integer", ["null" => true, "default" => null, "after" => "inspection_date_planner"]);
$table->addColumn("conduit_installed_building", "integer", ["null" => true, "default" => null, "after" => "inspection_date_electrician"]);
$table->addColumn("conduit_installed_ftu", "integer", ["null" => true, "default" => null, "after" => "conduit_installed_building"]);
$table->addColumn("inhouse_cabling", "integer", ["null" => true, "default" => null, "after" => "conduit_installed_ftu"]);
$table->update();
$this->execute("UPDATE ConstructionConsentOwner SET status=NULL, result=NULL");
$cco = $this->table("ConstructionConsentOwner");
$cco->changeColumn("status", "enum", ["null" => true, "default" => null, "values" => "new,sent,returned,outstanding"]);
$cco->changeColumn("result", "enum", ["null" => true, "default" => null, "values" => "open,accepted,denied,unresolvable"]);
$cco->update();
$this->execute("UPDATE ConstructionConsentOwner SET status='new', result='open'");
$cco->changeColumn("status", "enum", ["null" => true, "default" => "new", "values" => "new,sent,returned,outstanding"]);
$cco->changeColumn("result", "enum", ["null" => true, "default" => "open", "values" => "open,accepted,denied,unresolvable"]);
$cco->update();
$ccj = $this->table("ConstructionConsentJournal");
$ccj->removeColumn("type");
$ccj->removeColumn("value");
$ccj->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->execute("UPDATE ConstructionConsent SET status=NULL, result=NULL");
$table = $this->table("ConstructionConsent");
$table->changeColumn("result", "enum", ["null" => true, "default" => null, "values" => "new,requested,answered"]);
$table->changeColumn("status", "enum", ["null" => true, "default" => null, "values" => "success,failure"]);
$table->removeColumn("inspection_date_planner");
$table->removeColumn("inspection_date_electrician");
$table->removeColumn("conduit_installed_building");
$table->removeColumn("conduit_installed_ftu");
$table->removeColumn("inhouse_cabling");
$table->update();
$cco = $this->table("ConstructionConsentOwner");
$this->execute("UPDATE ConstructionConsentOwner SET status=NULL, result=NULL");
$cco->changeColumn("result", "enum", ["null" => true, "default" => null, "values" => "new,requested,answered"]);
$cco->changeColumn("status", "enum", ["null" => true, "default" => null, "values" => "success,failure"]);
$cco->update();
$ccj = $this->table("ConstructionConsentJournal");
$ccj->addColumn("type", "string", ["null" => true, "default" => null, "limit" => 255, "after" => "constructionconsent_id"]);
$ccj->addColumn("value", "string", ["null" => true, "default" => null, "limit" => 64, "after" => "type"]);
$ccj->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -70,13 +70,26 @@ $l["billing_period.24"] = "Zweijährlich";
$l["billing_period.46"] = "Dreijährlich"; $l["billing_period.46"] = "Dreijährlich";
$l["consent.building"] = "Gebäude"; $l["consent.building"] = "Gebäude";
$l["consent.street"] = "Straße/Grunstück"; $l["consent.street"] = "Straße/Grundstück";
$l["consent.new"] = "neu"; $l["consent.new"] = "neu";
$l["consent.sent"] = "Verschickt";
$l["consent.returned"] = "Retour";
$l["consent.outstanding"] = "Ausständig";
$l["consent.open"] = "Offen";
$l["consent.accepted"] = "Zugestimmt";
$l["consent.denied"] = "Abgelehnt";
$l["consent.unresolvable"] = "Uneinbringlich";
$l["consent.requested"] = "Angefragt"; $l["consent.requested"] = "Angefragt";
$l["consent.answered"] = "Antwort erhalten"; $l["consent.answered"] = "Antwort erhalten";
$l["consent.success"] = "Zustimmung erteilt"; $l["consent.success"] = "Zustimmung erteilt";
$l["consent.failure"] = "Zustimmung verweigert"; $l["consent.failure"] = "Zustimmung verweigert";
$l["consent.contact"] = "Ansprechpartner";
$l["consent.property_manager"] = "Hausverwaltung";
$l["consent.electrician"] = "Elektriker";
$l["consent.other"] = "Sonstige";
$l['cc.oesterreich'] = "AT"; $l['cc.oesterreich'] = "AT";
$l['cc.oestereich'] = "AT"; $l['cc.oestereich'] = "AT";