diff --git a/Layout/default/header.php b/Layout/default/header.php
index 960564812..6f1b03592 100644
--- a/Layout/default/header.php
+++ b/Layout/default/header.php
@@ -28,6 +28,7 @@
+
diff --git a/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValue.php b/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValue.php
new file mode 100644
index 000000000..c20e63215
--- /dev/null
+++ b/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValue.php
@@ -0,0 +1,73 @@
+db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+ $this->table = "HausnummerStatusflagValue";
+ }
+
+ protected function afterSave() {
+ if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
+ // cascade new status to all preorders
+ foreach(PreorderModel::search(["adb_hausnummer_id" => $this->hausnummer_id]) as $preorder) {
+ // get PreorederStatusflag
+ $pflag = PreorderStatusflagModel::getFirst(["code" => $this->getProperty("flag")->code]);
+ if(!$pflag) {
+ $this->log->debug(__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found");
+ return true;
+ }
+
+ // find PreorderStatusflagValue or create it
+ $new = false;
+ $pflagval = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder->id, "flag_id" => $pflag->id]);
+ if(!$pflagval) {
+ $new = true;
+ $pflagval = PreorderStatusflagValueModel::create([
+ "preorder_id" => $preorder->id,
+ "flag_id" => $pflag->id,
+ "value" => 0
+ ]);
+ }
+ if($new || $pflagval->value != $this->value) {
+ $pflagval->value = $this->value;
+ //$this->log->debug(__METHOD__.": ".print_r($pflagval, true));
+ $pflagval->save();
+ $this->log->debug(__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id);
+ }
+ }
+ }
+ }
+
+
+ public function getProperty($name) {
+ if($this->$name == null) {
+
+ if($name == "flag") {
+ if(!$this->flag_id) return null;
+ $flag = new ADBStatusflag($this->flag_id);
+ if($flag->id) {
+ $this->flag = $flag;
+ }
+ return $this->flag;
+ }
+
+ $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;
+ }
+}
\ No newline at end of file
diff --git a/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValueModel.php b/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValueModel.php
new file mode 100644
index 000000000..4a55b6449
--- /dev/null
+++ b/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValueModel.php
@@ -0,0 +1,155 @@
+ $value) {
+ if(property_exists(get_called_class(), $field)) {
+ $model ->$field = $value;
+ }
+ }
+
+ $me = mfValuecache::singleton()->get("me");
+ if(!$me) {
+ $me = new User();
+ $me->loadMe();
+ mfValuecache::singleton()->set("me", $me);
+ }
+
+ 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 getFirst($filter) {
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT HausnummerStatusflagValue.* FROM HausnummerStatusflagValue
+ WHERE $where
+ ORDER BY hausnummer_id,flag_id
+ LIMIT 1";
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ADBHausnummerStatusflagValue($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("HausnummerStatusflagValue", "*", "1=1 ORDER BY hausnummer_id,flag_id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new ADBHausnummerStatusflagValue($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 HausnummerStatusflagValue
+ 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 HausnummerStatusflagValue.* FROM HausnummerStatusflagValue
+ WHERE $where
+ ORDER BY hausnummer_id,flag_id";
+
+ 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 ADBHausnummerStatusflagValue($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+
+ if(array_key_exists("hausnummer_id", $filter)) {
+ $hausnummer_id = $filter['hausnummer_id'];
+ if(is_numeric($hausnummer_id)) {
+ $where .= " AND hausnummer_id=$hausnummer_id";
+ } elseif(is_array($hausnummer_id) && count($hausnummer_id)) {
+ $where .= " AND hausnummer_id IN (". implode(",", $hausnummer_id).")";
+ } elseif($hausnummer_id === null) {
+ $where .= " AND hausnummer_id IS NULL";
+ }
+ }
+
+ if(array_key_exists("flag_id", $filter)) {
+ $flag_id = $filter['flag_id'];
+ if(is_numeric($flag_id)) {
+ $where .= " AND flag_id=$flag_id";
+ } elseif(is_array($flag_id) && count($flag_id)) {
+ $where .= " AND flag_id IN (". implode(",", $flag_id).")";
+ } elseif($flag_id === null) {
+ $where .= " AND flag_id IS NULL";
+ }
+ }
+
+ if(array_key_exists("value", $filter)) {
+ $value = FronkDB::singleton()->escape($filter['value']);
+ if($value) {
+ $where .= " AND `value`='$value'";
+ }
+ }
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
diff --git a/application/ADBStatusflag/ADBStatusflag.php b/application/ADBStatusflag/ADBStatusflag.php
new file mode 100644
index 000000000..a849bcfeb
--- /dev/null
+++ b/application/ADBStatusflag/ADBStatusflag.php
@@ -0,0 +1,9 @@
+db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+ $this->table = "Statusflag";
+ }
+}
\ No newline at end of file
diff --git a/application/ADBStatusflag/ADBStatusflagModel.php b/application/ADBStatusflag/ADBStatusflagModel.php
new file mode 100644
index 000000000..dec63ee09
--- /dev/null
+++ b/application/ADBStatusflag/ADBStatusflagModel.php
@@ -0,0 +1,140 @@
+ $value) {
+ if(property_exists(get_called_class(), $field)) {
+ $model ->$field = $value;
+ }
+ }
+
+ $me = mfValuecache::singleton()->get("me");
+ if(!$me) {
+ $me = new User();
+ $me->loadMe();
+ mfValuecache::singleton()->set("me", $me);
+ }
+
+ 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 getFirst($filter) {
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT Statusflag.* FROM Statusflag
+ WHERE $where
+ ORDER BY code,name
+ LIMIT 1";
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ADBStatusflag($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("Statusflag", "*", "1=1 ORDER BY code,name");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new ADBStatusflag($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 Statusflag
+ 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 Statusflag.* FROM Statusflag
+ WHERE $where
+ ORDER BY code,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 ADBStatusflag($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+
+ if(array_key_exists("code", $filter)) {
+ $code = FronkDB::singleton()->escape($filter['code']);
+ if($code) {
+ $where .= " AND `code`='$code'";
+ }
+ }
+
+ if(array_key_exists("connection_type", $filter)) {
+ $connection_type = FronkDB::singleton()->escape($filter['connection_type']);
+ if($connection_type) {
+ $where .= " AND `connection_type`='$connection_type'";
+ }
+ }
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
diff --git a/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValue.php b/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValue.php
new file mode 100644
index 000000000..ac116eba3
--- /dev/null
+++ b/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValue.php
@@ -0,0 +1,73 @@
+db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+ $this->table = "WohneinheitStatusflagValue";
+ }
+
+ protected function afterSave() {
+ if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
+ // cascade new status to all preorders
+ foreach(PreorderModel::search(["adb_wohneinheit_id" => $this->wohneinheit_id]) as $preorder) {
+ // get PreorederStatusflag
+ $pflag = PreorderStatusflagModel::getFirst(["code" => $this->getProperty("flag")->code]);
+ if(!$pflag) {
+ $this->log->debug(__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found");
+ return true;
+ }
+
+ // find PreorderStatusflagValue or create it
+ $new = false;
+ $pflagval = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder->id, "flag_id" => $pflag->id]);
+ if(!$pflagval) {
+ $new = true;
+ $pflagval = PreorderStatusflagValueModel::create([
+ "preorder_id" => $preorder->id,
+ "flag_id" => $pflag->id,
+ "value" => 0
+ ]);
+ }
+ if($new || $pflagval->value != $this->value) {
+ $pflagval->value = $this->value;
+ //$this->log->debug(__METHOD__.": ".print_r($pflagval, true));
+ $pflagval->save();
+ $this->log->debug(__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id);
+ }
+ }
+ }
+ }
+
+
+ public function getProperty($name) {
+ if($this->$name == null) {
+
+ if($name == "flag") {
+ if(!$this->flag_id) return null;
+ $flag = new ADBStatusflag($this->flag_id);
+ if($flag->id) {
+ $this->flag = $flag;
+ }
+ return $this->flag;
+ }
+
+ $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;
+ }
+}
\ No newline at end of file
diff --git a/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValueModel.php b/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValueModel.php
new file mode 100644
index 000000000..7f8b45276
--- /dev/null
+++ b/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValueModel.php
@@ -0,0 +1,155 @@
+ $value) {
+ if(property_exists(get_called_class(), $field)) {
+ $model ->$field = $value;
+ }
+ }
+
+ $me = mfValuecache::singleton()->get("me");
+ if(!$me) {
+ $me = new User();
+ $me->loadMe();
+ mfValuecache::singleton()->set("me", $me);
+ }
+
+ 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 getFirst($filter) {
+ $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT WohneinheitStatusflagValue.* FROM WohneinheitStatusflagValue
+ WHERE $where
+ ORDER BY wohneinheit_id,flag_id
+ LIMIT 1";
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ADBWohneinheitStatusflagValue($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("WohneinheitStatusflagValue", "*", "1=1 ORDER BY wohneinheit_id,flag_id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new ADBWohneinheitStatusflagValue($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 WohneinheitStatusflagValue
+ 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 WohneinheitStatusflagValue.* FROM WohneinheitStatusflagValue
+ WHERE $where
+ ORDER BY wohneinheit_id,flag_id";
+
+ 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 ADBWohneinheitStatusflagValue($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+
+ if(array_key_exists("wohneinheit_id", $filter)) {
+ $wohneinheit_id = $filter['wohneinheit_id'];
+ if(is_numeric($wohneinheit_id)) {
+ $where .= " AND wohneinheit_id=$wohneinheit_id";
+ } elseif(is_array($wohneinheit_id) && count($wohneinheit_id)) {
+ $where .= " AND wohneinheit_id IN (". implode(",", $wohneinheit_id).")";
+ } elseif($wohneinheit_id === null) {
+ $where .= " AND wohneinheit_id IS NULL";
+ }
+ }
+
+ if(array_key_exists("flag_id", $filter)) {
+ $flag_id = $filter['flag_id'];
+ if(is_numeric($flag_id)) {
+ $where .= " AND flag_id=$flag_id";
+ } elseif(is_array($flag_id) && count($flag_id)) {
+ $where .= " AND flag_id IN (". implode(",", $flag_id).")";
+ } elseif($flag_id === null) {
+ $where .= " AND flag_id IS NULL";
+ }
+ }
+
+ if(array_key_exists("value", $filter)) {
+ $value = FronkDB::singleton()->escape($filter['value']);
+ if($value) {
+ $where .= " AND `value`='$value'";
+ }
+ }
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
diff --git a/application/Api/v1/PreorderApicontroller.php b/application/Api/v1/PreorderApicontroller.php
index ac349895c..cc27d4160 100644
--- a/application/Api/v1/PreorderApicontroller.php
+++ b/application/Api/v1/PreorderApicontroller.php
@@ -1038,6 +1038,13 @@ class PreorderApicontroller extends mfBaseApicontroller {
$return['orderDate'] = date("Y-m-d",$preorder->order_date);
}
$return['status'] = $preorder->status->getApiArray();
+ /*foreach($preorder->statusflags as $sflag) {
+ $return['status']['flags'][$sflag->code] = [
+ "code" => $sflag->code,
+ "text" => $sflag->name,
+ "value" => ($sflag->value->value == 1)
+ ];
+ }*/
if($addon_data) {
$return["additionalData"] = $addon_data;
}
diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php
index cc7372ced..35175b231 100644
--- a/application/Preorder/Preorder.php
+++ b/application/Preorder/Preorder.php
@@ -81,15 +81,19 @@ class Preorder extends mfBaseModel {
$changed = $this->getChangedFields();
- foreach($changed as $field) {
- $this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'");
- $history = PreorderHistoryModel::create([
- "preorder_id" => $this->id,
- "key" => $field,
- "old_value" => $this->_old_data->$field,
- "new_value" => $this->data->$field
- ]);
- $history->save();
+ try {
+ foreach($changed as $field) {
+ $this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'");
+ $history = PreorderHistoryModel::create([
+ "preorder_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());
}
}
@@ -142,6 +146,7 @@ class Preorder extends mfBaseModel {
$trigger = new $classname($this, $new_status);
$trigger->run();
+
}
@@ -231,6 +236,58 @@ class Preorder extends mfBaseModel {
}
}
+ $flags = $this->getProperty("statusflags");
+
+ if(is_array($flags) && count($flags)) {
+ foreach($flags as $flag) {
+ if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_MATRIX)) {
+ $flag_matrix_item = TT_PREORDER_STATUS_MATRIX[$flag->code];
+ if(!$flag_matrix_item["flag"]) continue;
+
+ // set hausnummer flag
+ if($flag_matrix_item["h"]) {
+ $hflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["h"]]);
+ if(!$hflag) {
+ $this->log->warn("Statusflag Code ".$flag->code." does not exist");
+ }
+
+ $hflagval = ADBHausnummerStatusflagValueModel::getFirst(["hausnummer_id" => $this->adb_hausnummer_id, "flag_id" => $hflag->id]);
+ if(!$hflagval) {
+ $hflagval = ADBHausnummerStatusflagValueModel::create([
+ "hausnummer_id" => $this->adb_hausnummer_id,
+ "flag_id" => $hflag->id,
+ "value" => 0
+ ]);
+ }
+ $hflagval->value = $flag->value->value;
+ $hflagval->save();
+ $this->log->debug(__METHOD__.": Hausnummer flag ".$hflag->code." gespeichert");
+ }
+
+ // set wohneiheit flag
+ if($flag_matrix_item["w"] && $this->adb_wohneinheit_id) {
+ $wflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["w"]]);
+ if(!$wflag) {
+ $this->log->warn("Statusflag Code ".$flag->code." does not exist");
+ }
+
+ $wflagval = ADBWohneinheitStatusflagValueModel::getFirst(["wohneinheit_id" => $this->adb_wohneinheit_id, "flag_id" => $wflag->id]);
+ if(!$wflagval) {
+ $wflagval = ADBWohneinheitStatusflagValueModel::create([
+ "wohneinheit_id" => $this->adb_wohneinheit_id,
+ "flag_id" => $wflag->id,
+ "value" => 0
+ ]);
+ }
+ $wflagval->value = $flag->value->value;
+ $wflagval->save();
+ $this->log->debug(__METHOD__.": Wohneinheit flag ".$hflag->code." gespeichert");
+ }
+ }
+
+ }
+ }
+
return true;
}
@@ -544,6 +601,15 @@ class Preorder extends mfBaseModel {
$hausnummer = $this->getProperty("adb_hausnummer");
$wohneinheit = $this->getProperty("adb_wohneinheit");
$campaign = $this->getProperty("campaign");
+ $status = $this->getProperty("status")->getApiArray();
+
+ /*foreach($this->getProperty("statusflags") as $sflag) {
+ $status["flags"][$sflag->code] = [
+ "code" => $sflag->code,
+ "text" => $sflag->name,
+ "value" => ($sflag->value->value == 1)
+ ];
+ }*/
$a = [];
@@ -551,7 +617,7 @@ class Preorder extends mfBaseModel {
$a['oaid'] = $this->oaid;
$a['extref'] = $this->extref;
$a['orderDate'] = ($this->order_date) ? date("Y-m-d", $this->order_date) : null;
- $a['status'] = $this->getProperty("status")->getApiArray();
+ $a['status'] = $status;
$a['ciftoken'] = ($this->ciftoken) ? $this->ciftoken : null;
$a['cifurl'] = ($this->cifurl) ? $this->cifurl : null;
$a['cifcableurl'] = ($this->cifcableurl) ? $this->cifcableurl : null;
diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php
index 6cdcab285..ba397ae6b 100644
--- a/application/Preorder/PreorderController.php
+++ b/application/Preorder/PreorderController.php
@@ -953,9 +953,13 @@ class PreorderController extends mfBaseController {
}
$flagvalue->value = ($value) ? 1 : 0;
-
- if(!$flagvalue->save()) {
- return false;
+ //var_dump($flagvalue);exit;
+ try {
+ if(!$flagvalue->save()) {
+ return false;
+ }
+ } catch(Exception $e) {
+ $this->log->debug($e->getTraceAsString());
}
return ["message" => "Statusflag saved successfully"];
diff --git a/application/PreorderStatusflagValue/PreorderStatusflagValue.php b/application/PreorderStatusflagValue/PreorderStatusflagValue.php
index 4b2604abe..31c93ccf7 100644
--- a/application/PreorderStatusflagValue/PreorderStatusflagValue.php
+++ b/application/PreorderStatusflagValue/PreorderStatusflagValue.php
@@ -1,16 +1,39 @@
_old_data->value != $this->value) {
+ if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
$history = PreorderHistoryModel::create([
- "preorder_id" => $this->preorder_id,
- "key" => "preorderstatusflag-".$this->flag_id."-value",
- "old_value" => $this->_old_data->value,
+ "preorder_id" => $this->data->preorder_id,
+ "key" => "preorderstatusflag-".$this->data->flag_id."-value",
+ "old_value" => property_exists($this->_old_data, "value") ? $this->_old_data->value : null,
"new_value" => $this->data->value
]);
$history->save();
+ $this->getProperty("preorder")->afterSave();
}
}
+
+ 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;
+ }
}
\ No newline at end of file
diff --git a/application/Preorderstatus/Preorderstatus.php b/application/Preorderstatus/Preorderstatus.php
index 391d61669..8237f962d 100644
--- a/application/Preorderstatus/Preorderstatus.php
+++ b/application/Preorderstatus/Preorderstatus.php
@@ -10,7 +10,8 @@ class Preorderstatus extends mfBaseModel {
$a = [];
$a['code'] = (int)$this->code;
$a['text'] = $this->name;
-
+ //$a['flags'] = [];
+
return $a;
}
}
\ No newline at end of file
diff --git a/db/migrations/20240801102708_create_adb_status_flag.php b/db/migrations/20240801102708_create_adb_status_flag.php
new file mode 100644
index 000000000..fd8e00121
--- /dev/null
+++ b/db/migrations/20240801102708_create_adb_status_flag.php
@@ -0,0 +1,112 @@
+getEnvironment() == "thetool") {
+
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+ $hflag = $this->table("Statusflag");
+ $hflag->addColumn("code", "integer", ["null" => false]);
+ $hflag->addColumn("name", "string", ["null" => false, "limit" => 64]);
+ $hflag->addColumn("connection_type", "enum", ["null" => false, "values" => "all,single,multi", "default" => "all"]);
+ $hflag->addColumn("create_by", "integer", ["null" => false]);
+ $hflag->addColumn("edit_by", "integer", ["null" => false]);
+ $hflag->addColumn("create", "integer", ["null" => false]);
+ $hflag->addColumn("edit", "integer", ["null" => false]);
+ $hflag->create();
+
+ $hflag->insert([
+ [
+ "code" => 141,
+ "name" => "Conduit on property border and FCP prepaired",
+ "connection_type" => "all",
+ "create_by" => 1,
+ "edit_by" => 1,
+ "create" => date("U"),
+ "edit" => date("U")
+ ],
+ [
+ "code" => 145,
+ "name" => "Installation kit picked up or shipped",
+ "connection_type" => "all",
+ "create_by" => 1,
+ "edit_by" => 1,
+ "create" => date("U"),
+ "edit" => date("U")
+ ],
+ [
+ "code" => 150,
+ "name" => "Borderpoint connected",
+ "connection_type" => "all",
+ "create_by" => 1,
+ "edit_by" => 1,
+ "create" => date("U"),
+ "edit" => date("U")
+ ],
+ [
+ "code" => 200,
+ "name" => "Conduit in building",
+ "connection_type" => "all",
+ "create_by" => 1,
+ "edit_by" => 1,
+ "create" => date("U"),
+ "edit" => date("U")
+ ],
+ [
+ "code" => 242,
+ "name" => "Inhouse cabeling finished",
+ "connection_type" => "all",
+ "create_by" => 1,
+ "edit_by" => 1,
+ "create" => date("U"),
+ "edit" => date("U")
+ ],
+ ])->save();
+
+ $hvalue = $this->table("HausnummerStatusflagValue");
+ $hvalue->addColumn("hausnummer_id", "integer", ["null" => false]);
+ $hvalue->addColumn("flag_id", "integer", ["null" => false]);
+ $hvalue->addColumn("value", "integer", ["null" => false]);
+ $hvalue->addColumn("create_by", "integer", ["null" => false]);
+ $hvalue->addColumn("edit_by", "integer", ["null" => false]);
+ $hvalue->addColumn("create", "integer", ["null" => false]);
+ $hvalue->addColumn("edit", "integer", ["null" => false]);
+ $hvalue->addIndex("hausnummer_id");
+ $hvalue->addIndex(["hausnummer_id", "flag_id"]);
+ $hvalue->create();
+
+ $wvalue = $this->table("WohneinheitStatusflagValue");
+ $wvalue->addColumn("wohneinheit_id", "integer", ["null" => false]);
+ $wvalue->addColumn("flag_id", "integer", ["null" => false]);
+ $wvalue->addColumn("value", "integer", ["null" => false]);
+ $wvalue->addColumn("create_by", "integer", ["null" => false]);
+ $wvalue->addColumn("edit_by", "integer", ["null" => false]);
+ $wvalue->addColumn("create", "integer", ["null" => false]);
+ $wvalue->addColumn("edit", "integer", ["null" => false]);
+ $wvalue->addIndex("wohneinheit_id");
+ $wvalue->addIndex(["wohneinheit_id", "flag_id"]);
+ $wvalue->create();
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+ $this->table("WohneinheitStatusflagValue")->drop()->save();
+ $this->table("HausnummerStatusflagValue")->drop()->save();
+ $this->table("Statusflag")->drop()->save();
+
+ }
+ }
+}
diff --git a/scripts/invoice/fix-sepa-last-date.php b/scripts/invoice/fix-sepa-last-date.php
index 21c889937..27ea9574a 100644
--- a/scripts/invoice/fix-sepa-last-date.php
+++ b/scripts/invoice/fix-sepa-last-date.php
@@ -1,6 +1,6 @@
#!/usr/bin/php