@@ -196,12 +233,13 @@ $pagination_entity_name = "Adressen";
=$owner->email?>
- =__($owner->status, "consent")?>
+ =($owner->status) ? __($owner->status, "consent") : ""?>
+
+
+
+
+
+
+
+ Journal
+
+
+
+
+
+
+
+
+
+
+
+
+ journal as $j): ?>
+
+ | =date("d.m.Y H:i", $j->create)?> (=$j->creator?>) |
+
+ =nl2br($j->text)?>
+ |
+
+
+
+
+
+
+
+
+
+
+
+ History
+
+
+
+
+ | Zeitpunkt |
+ Benutzer |
+ Feld |
+ Alter Wert |
+ Neuer Wert |
+
+ history as $history): ?>
+
+ | =date("d.m.Y H:i:s", $history->create)?> |
+ =$history->creator->name?> |
+ =$history->getKey()?> |
+ =$history->getText("old")?> |
+ =$history->getText("new")?> |
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
\ No newline at end of file
diff --git a/application/ConstructionConsent/ConstructionConsent.php b/application/ConstructionConsent/ConstructionConsent.php
index 112de4a17..4f0533005 100644
--- a/application/ConstructionConsent/ConstructionConsent.php
+++ b/application/ConstructionConsent/ConstructionConsent.php
@@ -7,16 +7,44 @@ class ConstructionConsent extends mfBaseModel {
private $adb_hausnummer;
private $adb_strasse;
private $owners;
+ private $contacts;
private $file;
private $creator;
private $editor;
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_font = "ITC Officina Sans Std";
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 {
if($owner) {
$owners = [$owner];
@@ -53,6 +81,21 @@ class ConstructionConsent extends mfBaseModel {
public function getProperty($name) {
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") {
$project = new ConstructionConsentProject($this->constructionconsentproject_id);
if($project->id) {
@@ -98,7 +141,7 @@ class ConstructionConsent extends mfBaseModel {
}
if($name == "owners") {
- if(!$this->id) return null;
+ if(!$this->id) return [];
$owners = ConstructionConsentOwner::search(["constructionconsent_id" => $this->id]);
if(count($owners)) {
@@ -107,8 +150,23 @@ class ConstructionConsent extends mfBaseModel {
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(!$this->id) return null;
+ if(!$this->id) return [];
$file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $this->id]);
if($file) {
$this->file = $file;
diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php
index 78ec59313..346a53d64 100644
--- a/application/ConstructionConsent/ConstructionConsentController.php
+++ b/application/ConstructionConsent/ConstructionConsentController.php
@@ -268,9 +268,22 @@ class ConstructionConsentController extends mfBaseController {
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 {
if($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()) {
$this->layout()->setFlash("Fehler beim Speichern des Plans", "warning");
}
+
+ $history->save();
}
diff --git a/application/ConstructionConsentContact/ConstructionConsentContact.php b/application/ConstructionConsentContact/ConstructionConsentContact.php
new file mode 100644
index 000000000..855998e02
--- /dev/null
+++ b/application/ConstructionConsentContact/ConstructionConsentContact.php
@@ -0,0 +1,180 @@
+$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;
+ }
+}
\ No newline at end of file
diff --git a/application/ConstructionConsentContact/ConstructionConsentContactController.php b/application/ConstructionConsentContact/ConstructionConsentContactController.php
new file mode 100644
index 000000000..84d215b9d
--- /dev/null
+++ b/application/ConstructionConsentContact/ConstructionConsentContactController.php
@@ -0,0 +1,98 @@
+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]);
+ }
+}
\ No newline at end of file
diff --git a/application/ConstructionConsentHistory/ConstructionConsentHistory.php b/application/ConstructionConsentHistory/ConstructionConsentHistory.php
new file mode 100644
index 000000000..fc8f4d160
--- /dev/null
+++ b/application/ConstructionConsentHistory/ConstructionConsentHistory.php
@@ -0,0 +1,317 @@
+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 ";
+ }
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/application/ConstructionConsentJournal/ConstructionConsentJournal.php b/application/ConstructionConsentJournal/ConstructionConsentJournal.php
index a0e97f73f..d442d8c63 100644
--- a/application/ConstructionConsentJournal/ConstructionConsentJournal.php
+++ b/application/ConstructionConsentJournal/ConstructionConsentJournal.php
@@ -2,9 +2,32 @@
class ConstructionConsentJournal extends mfBaseModel {
+ private $creator;
+ private $editor;
+
public function getProperty($name) {
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);
$idfield = $name."_id";
@@ -33,7 +56,7 @@ class ConstructionConsentJournal extends mfBaseModel {
$model = new ConstructionConsentJournal();
$table_fields = [
- "constructionconsent_id", "type", "value", "text",
+ "constructionconsent_id", "text",
"create_by","edit_by","create","edit"
];
diff --git a/application/ConstructionConsentJournal/ConstructionConsentJournalController.php b/application/ConstructionConsentJournal/ConstructionConsentJournalController.php
new file mode 100644
index 000000000..f7203f25f
--- /dev/null
+++ b/application/ConstructionConsentJournal/ConstructionConsentJournalController.php
@@ -0,0 +1,58 @@
+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]);
+
+
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/ConstructionConsentOwner/ConstructionConsentOwner.php b/application/ConstructionConsentOwner/ConstructionConsentOwner.php
index b1d68c0cf..bad5c8712 100644
--- a/application/ConstructionConsentOwner/ConstructionConsentOwner.php
+++ b/application/ConstructionConsentOwner/ConstructionConsentOwner.php
@@ -6,6 +6,31 @@ class ConstructionConsentOwner extends mfBaseModel {
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) {
if($this->$name == null) {
diff --git a/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php b/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php
index 0f9bf12ef..25c390b7e 100644
--- a/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php
+++ b/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php
@@ -143,7 +143,7 @@ class ConstructionConsentOwnerController extends mfBaseController
return false;
}
- if(!in_array($new_status, ["new", "requested", "answered"])) {
+ if(!in_array($new_status, ['new', 'sent', 'returned', 'outstanding'])) {
return false;
}
@@ -164,26 +164,16 @@ class ConstructionConsentOwnerController extends mfBaseController
return false;
}
- // allow empty result
- if($new_result) {
- if(!in_array($new_result, ["success", "failure"])) {
- return false;
- }
-
- $owner->result = $new_result;
- } else {
- $owner->result = null;
+ if(!in_array($new_result, ['open', 'accepted', 'denied', 'unresolvable'])) {
+ return false;
}
+ $owner->result = $new_result;
if(!$owner->save()) {
return false;
}
- if($owner->result) {
- 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" => ""]];
- }
+ return ["message" => "Result saved successfully", "update" => ["id" => $owner->id, "result" => $owner->result, "result_text" => __($owner->result, "consent")]];
}
}
\ No newline at end of file
diff --git a/db/migrations/20250120145618_create_construction_consent_history_and_contact.php b/db/migrations/20250120145618_create_construction_consent_history_and_contact.php
index 65951e177..7eaf395a5 100644
--- a/db/migrations/20250120145618_create_construction_consent_history_and_contact.php
+++ b/db/migrations/20250120145618_create_construction_consent_history_and_contact.php
@@ -35,6 +35,7 @@ final class CreateConstructionConsentHistoryAndContact extends AbstractMigration
->addColumn("create", "integer", ["null" => false])
->addColumn("edit", "integer", ["null" => false]);
$ccc->create();
+
}
if($this->getEnvironment() == "addressdb") {
diff --git a/db/migrations/20250121164455_construction_consent_change_status_and_result.php b/db/migrations/20250121164455_construction_consent_change_status_and_result.php
new file mode 100644
index 000000000..c5529a71a
--- /dev/null
+++ b/db/migrations/20250121164455_construction_consent_change_status_and_result.php
@@ -0,0 +1,77 @@
+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") {
+
+ }
+ }
+}
diff --git a/lang/de.php b/lang/de.php
index e90f402e2..b2f73d703 100644
--- a/lang/de.php
+++ b/lang/de.php
@@ -70,13 +70,26 @@ $l["billing_period.24"] = "Zweijährlich";
$l["billing_period.46"] = "Dreijährlich";
$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.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.answered"] = "Antwort erhalten";
$l["consent.success"] = "Zustimmung erteilt";
$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.oestereich'] = "AT";
|