| Statusflags |
@@ -158,7 +168,20 @@
- | =$unit->status->code?> - =$unit->status->name?> |
+
+ =$unit->status->code?> - =$unit->status->name?>
+
+ |
=((string)$unit) ? "".(string)$unit."" : ""?> |
=($unit->extref) ? "[".$unit->extref."]" : ""?> |
=PreorderModel::countActive(["adb_wohneinheit_id" => $unit->id])?> |
@@ -183,4 +206,148 @@
+
\ No newline at end of file
diff --git a/application/ADBHausnummer/ADBHausnummer.php b/application/ADBHausnummer/ADBHausnummer.php
index 8a441367f..558e646f8 100644
--- a/application/ADBHausnummer/ADBHausnummer.php
+++ b/application/ADBHausnummer/ADBHausnummer.php
@@ -35,6 +35,8 @@ class ADBHausnummer extends mfBaseModel {
$this->getGpsCoords();
}
+ $this->logChanges();
+
// Statuschange from Rimo statuschange for all units
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $this->id]) as $wohneinheit) {
@@ -42,6 +44,34 @@ class ADBHausnummer extends mfBaseModel {
}
+ }
+
+ public function resetSaveNesting() {
+ mfValuecache::singleton()->delete("adbhausnummer-save-nesting-level-" . $this->id);
+ }
+
+ private function logChanges() {
+ $changes = $this->getChangedFields();
+ if(!count($changes)) return true;
+
+ $logstr = "";
+
+ foreach($changes as $key) {
+ if($key == "status_id") {
+ $old_status = new ADBStatus($this->_old_data->status_id);
+ $new_status = new ADBStatus($this->data->status_id);
+ $logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."' [".$old_status->code." => ".$new_status->code."]";
+ } else {
+ $logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."'";
+ }
+ }
+
+ $me = new User();
+ $me->loadMe();
+ $this->log->info(__CLASS__." Changes: User ".$me->username." $logstr");
+
+ return true;
+
}
public function getBuildingType() {
diff --git a/application/ADBRimoFcp/ADBRimoFcp.php b/application/ADBRimoFcp/ADBRimoFcp.php
new file mode 100644
index 000000000..d542df249
--- /dev/null
+++ b/application/ADBRimoFcp/ADBRimoFcp.php
@@ -0,0 +1,195 @@
+db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+ $this->table = "RimoFcp";
+ }
+
+ public function getProperty($name) {
+ if($this->$name == null) {
+
+ $classname = ucfirst($name);
+ $idfield = $name."_id";
+ $this->$name = new $classname($this->$idfield);
+
+ if($this->$name->id) {
+ return $this->$name;
+ } else {
+ return null;
+ }
+ }
+
+ return $this->$name;
+ }
+
+ /********************************
+ * Begin static Model functions
+ */
+
+ public static function create(Array $data) {
+ $model = new ADBRimoFcp();
+
+ $table_fields = [
+ "netzgebiet_id", "name", "rimo_id", "label", "building_type", "rimo_ex_state", "rimo_op_state", "gps_lat", "gps_long",
+ "create","edit"
+ ];
+
+ foreach($data as $field => $value) {
+ if(in_array($field, $table_fields)) {
+ $model->$field = $value;
+ }
+ }
+
+ return $model;
+ }
+
+ public static function getFirst($filter) {
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT RimoFcp.* FROM RimoFcp
+ WHERE $where
+ ORDER BY name
+ LIMIT 1";
+
+ mfLoghandler::singleton()->debug($sql);
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ADBRimoFcp($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+ $res = $db->select("RimoFcp", "*", "1=1 ORDER BY name");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new ADBRimoFcp($data);
+ }
+ }
+ return $items;
+
+ }
+
+
+ public static function count($filter) {
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) as cnt FROM RimoFcp
+ WHERE $where
+ ";
+
+ $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) {
+ $items = [];
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT RimoFcp.* FROM RimoFcp
+ WHERE $where
+ ORDER BY name";
+
+ mfLoghandler::singleton()->debug($sql);
+ 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'];
+ }
+ }
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new ADBRimoFcp($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+ if(array_key_exists("netzgebiet_id", $filter)) {
+ $netzgebiet_id = $filter['netzgebiet_id'];
+ if(is_numeric($netzgebiet_id)) {
+ $where .= " AND netzgebiet_id=$netzgebiet_id";
+ } elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) {
+ $where .= " AND netzgebiet_id IN (". implode(",", $netzgebiet_id).")";
+ } elseif($netzgebiet_id === null) {
+ $where .= " AND netzgebiet_id IS NULL";
+ }
+ }
+
+ if(array_key_exists("name", $filter)) {
+ $name = $db->escape($filter['name']);
+ if($name) {
+ $where .= " AND RimoFcp.name='$name'";
+ }
+ }
+
+ if(array_key_exists("label", $filter)) {
+ $label = $db->escape($filter['label']);
+ if($label) {
+ $where .= " AND RimoFcp.label='$label'";
+ }
+ }
+
+ if(array_key_exists("building_type", $filter)) {
+ $building_type = $db->escape($filter['building_type']);
+ if($building_type) {
+ $where .= " AND RimoFcp.building_type='$building_type'";
+ }
+ }
+
+ if(array_key_exists("rimo_ex_state", $filter)) {
+ $rimo_ex_state = $db->escape($filter['rimo_ex_state']);
+ if($rimo_ex_state) {
+ $where .= " AND RimoFcp.rimo_ex_state='$rimo_ex_state'";
+ }
+ }
+
+ if(array_key_exists("rimo_op_state", $filter)) {
+ $rimo_op_state = $db->escape($filter['rimo_op_state']);
+ if($rimo_op_state) {
+ $where .= " AND RimoFcp.rimo_op_state='$rimo_op_state'";
+ }
+ }
+
+ if(array_key_exists("rimo_id", $filter)) {
+ $rimo_id = $db->escape($filter['rimo_id']);
+ if($rimo_id) {
+ $where .= " AND RimoFcp.rimo_id='$rimo_id'";
+ }
+ }
+
+
+
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+}
diff --git a/application/ADBStatus/ADBStatusModel.php b/application/ADBStatus/ADBStatusModel.php
index 517ec4b03..9a5bb3159 100644
--- a/application/ADBStatus/ADBStatusModel.php
+++ b/application/ADBStatus/ADBStatusModel.php
@@ -120,6 +120,7 @@ class ADBStatusModel {
$where = "1=1 ";
//var_dump($filter);exit;
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
if(array_key_exists("code", $filter)) {
$code = $filter['code'];
@@ -127,6 +128,20 @@ class ADBStatusModel {
$where .= " AND code=$code";
}
}
+
+ if(array_key_exists("type", $filter)) {
+ $type = $db->escape($filter['type']);
+ if($type) {
+ $where .= " AND type='$type'";
+ }
+ }
+
+ if(array_key_exists("!type", $filter)) {
+ $type = $db->escape($filter['!type']);
+ if($type) {
+ $where .= " AND (type IS NULL OR NOT type='$type')";
+ }
+ }
//var_dump($filter, $where);exit;
diff --git a/application/ADBWohneinheit/ADBWohneinheit.php b/application/ADBWohneinheit/ADBWohneinheit.php
index e6441c2d7..ea2e3df16 100644
--- a/application/ADBWohneinheit/ADBWohneinheit.php
+++ b/application/ADBWohneinheit/ADBWohneinheit.php
@@ -30,6 +30,7 @@ class ADBWohneinheit extends mfBaseModel {
return true;
}
+ $this->logChanges();
// Statuschange from Rimo statuschange
AddressDB::handleRimoStatusUpdate($this->id);
@@ -77,6 +78,34 @@ class ADBWohneinheit extends mfBaseModel {
}
+ public function resetSaveNesting() {
+ mfValuecache::singleton()->delete("adbwohneinheit-save-nesting-level-" . $this->id);
+ }
+
+ private function logChanges() {
+ $changes = $this->getChangedFields();
+ if(!count($changes)) return true;
+
+ $logstr = "";
+
+ foreach($changes as $key) {
+ if($key == "status_id") {
+ $old_status = new ADBStatus($this->_old_data->status_id);
+ $new_status = new ADBStatus($this->data->status_id);
+ $logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."' [".$old_status->code." => ".$new_status->code."]";
+ } else {
+ $logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."'";
+ }
+ }
+
+ $me = new User();
+ $me->loadMe();
+ $this->log->info(__CLASS__." Changes: User ".$me->username." $logstr");
+
+ return true;
+
+ }
+
public function setNewStatusCode($new_status_code) {
if(!$new_status_code) return false;
diff --git a/application/AddressDB/AddressDBController.php b/application/AddressDB/AddressDBController.php
index b3cbe0688..775afff86 100644
--- a/application/AddressDB/AddressDBController.php
+++ b/application/AddressDB/AddressDBController.php
@@ -742,6 +742,12 @@ class AddressDBController extends mfBaseController {
case "findAddress":
$return = $this->findAddressApi();
break;
+ case "updateAddressStatus":
+ $return = $this->updateAddressStatusApi();
+ break;
+ case "updateUnitStatus":
+ $return = $this->updateUnitStatusApi();
+ break;
case "getFilteredBuildings":
$return = $this->getFilteredBuildingsApi();
break;
@@ -783,7 +789,117 @@ class AddressDBController extends mfBaseController {
$data['result'] = $return;
$this->returnJson($data);
}
-
+
+ private function updateAddressStatusApi() {
+ $address_id = $this->request->id;
+
+ if(!is_numeric($address_id) || $address_id < 1) {
+ return ["error" => 1];
+ return false;
+ }
+
+ $address = new ADBHausnummer($address_id);
+ if(!$address->id) {
+ return ["error" => 2];
+ return false;
+ }
+
+ $status_id = $this->request->status_id;
+ if(!is_numeric($status_id) || $status_id < 1) {
+ return ["error" => 3];
+ return false;
+ }
+
+ $status = new ADBStatus($status_id);
+ if(!$status->id) {
+ return ["error" => 4];
+ return false;
+ }
+
+ $address->status_id = $status_id;
+ $address->save();
+
+ $update = [
+ "id" => $address_id,
+ "status_id" => $status_id,
+ "status_code" => $status->code,
+ "status_text" => $status->name,
+ "units" => []
+ ];
+
+ foreach(ADBWohneinheitModel::search(["hausnummer_id" => $address->id]) as $affected_unit) {
+ $up = [
+ "id" => $affected_unit->id,
+ "status_id" => $affected_unit->status_id,
+ "status_code" => $affected_unit->status->code,
+ "status_text" => $affected_unit->status->name,
+ ];
+
+ $update["units"][] = $up;
+ }
+
+ return ["message" => "Status saved successfully", "id" => $address_id, "updates" => $update];
+ }
+
+ private function updateUnitStatusApi() {
+ $unit_id = $this->request->id;
+
+ if(!is_numeric($unit_id) || $unit_id < 1) {
+ return ["error" => 1];
+ return false;
+ }
+
+ $unit = new ADBWohneinheit($unit_id);
+ if(!$unit->id) {
+ return ["error" => 2];
+ return false;
+ }
+
+ $status_id = $this->request->status_id;
+ if(!is_numeric($status_id) || $status_id < 1) {
+ return ["error" => 3];
+ return false;
+ }
+
+ $status = new ADBStatus($status_id);
+ if(!$status->id) {
+ return ["error" => 4];
+ return false;
+ }
+
+ $linkes_units = [];
+ foreach(ADBWohneinheitModel::search(["hausnummer_id" => $unit->hausnummer_id]) as $lu) {
+ $linkes_units[$lu->id] = $lu->status_id;
+ }
+
+ $unit->status_id = $status_id;
+ $unit->save();
+
+ $update = [
+ "id" => $unit_id,
+ "status_id" => $status_id,
+ "status_code" => $status->code,
+ "status_text" => $status->name,
+ "units" => []
+ ];
+
+ foreach(ADBWohneinheitModel::search(["hausnummer_id" => $unit->hausnummer_id]) as $affected_unit) {
+ if(!array_key_exists($affected_unit->id, $linkes_units)) continue;
+ if($linkes_units[$affected_unit->id] == $affected_unit->status_id) continue;
+
+ $up = [
+ "id" => $affected_unit->id,
+ "status_id" => $affected_unit->status_id,
+ "status_code" => $affected_unit->status->code,
+ "status_text" => $affected_unit->status->name,
+ ];
+
+ $update["units"][] = $up;
+ }
+
+ return ["message" => "Status saved successfully", "id" => $unit_id, "updates" => $update];
+ }
+
private function getUnitApi() {
$id = $this->request->id;
if(!$id) return false;
diff --git a/db/migrations/20241205145604_adb_status_add_type.php b/db/migrations/20241205145604_adb_status_add_type.php
new file mode 100644
index 000000000..330b93b9e
--- /dev/null
+++ b/db/migrations/20241205145604_adb_status_add_type.php
@@ -0,0 +1,31 @@
+getEnvironment() == "thetool") {
+
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+ $table = $this->table("Status");
+ $table->addColumn("type", "enum", ["null" => true, "default" => null, "values" => "hausnummer,wohneinheit", "after" => "name"]);
+ $table->update();
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+ $this->table("Status")->removeColumn("type")->update();
+ }
+ }
+}
|