From af3a97032be0099e31a94a12e20a28ee7218a1ae Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 17 Jul 2024 18:10:15 +0200 Subject: [PATCH 1/5] Added PreorderStatusflag tables and classes --- .../PreorderStatusflag/PreorderStatusflag.php | 5 + .../PreorderStatusflagModel.php | 133 +++++++++++++++ .../PreorderStatusflagValue.php | 5 + .../PreorderStatusflagValueModel.php | 152 ++++++++++++++++++ ...40717144237_create_preorderstatus_flag.php | 86 ++++++++++ 5 files changed, 381 insertions(+) create mode 100644 application/PreorderStatusflag/PreorderStatusflag.php create mode 100644 application/PreorderStatusflag/PreorderStatusflagModel.php create mode 100644 application/PreorderStatusflagValue/PreorderStatusflagValue.php create mode 100644 application/PreorderStatusflagValue/PreorderStatusflagValueModel.php create mode 100644 db/migrations/20240717144237_create_preorderstatus_flag.php diff --git a/application/PreorderStatusflag/PreorderStatusflag.php b/application/PreorderStatusflag/PreorderStatusflag.php new file mode 100644 index 000000000..a57a2cfaa --- /dev/null +++ b/application/PreorderStatusflag/PreorderStatusflag.php @@ -0,0 +1,5 @@ + $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(); + + $where = self::getSqlFilter($filter); + $res = $db->select("PreorderStatusflag", "*", "$where ORDER BY code LIMIT 1"); + if ($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new PreorderStatusflag($data); + if ($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("PreorderStatusflag", "*", "1=1 ORDER BY code"); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $items[] = new PreorderStatusflag($data); + } + } + return $items; + } + + public static function count($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) as cnt FROM PreorderStatusflag + 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(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM PreorderStatusflag + WHERE $where + ORDER BY code"; + + 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 PreorderStatusflag($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + if (array_key_exists("code", $filter)) { + $code = $filter['code']; + if (is_numeric($code)) { + $where .= " AND PreorderStatusflag.code=$code"; + } + } + + if (array_key_exists("create_by", $filter)) { + $create_by = $filter['create_by']; + if (is_numeric($create_by)) { + $where .= " AND PreorderStatusflag.create_by=$create_by"; + } + } + + return $where; + } + +} diff --git a/application/PreorderStatusflagValue/PreorderStatusflagValue.php b/application/PreorderStatusflagValue/PreorderStatusflagValue.php new file mode 100644 index 000000000..67f739735 --- /dev/null +++ b/application/PreorderStatusflagValue/PreorderStatusflagValue.php @@ -0,0 +1,5 @@ + $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(); + + $where = self::getSqlFilter($filter); + $res = $db->select("PreorderStatusflagValue", "*", "$where ORDER BY statusflag_id LIMIT 1"); + if ($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new PreorderStatusflagValue($data); + if ($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("PreorderStatusflagValue", "*", "1=1 ORDER BY statusflag_id"); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $items[] = new PreorderStatusflagValue($data); + } + } + return $items; + } + + public static function count($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) as cnt FROM PreorderStatusflagValue + 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(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM PreorderStatusflagValue + WHERE $where + ORDER BY statusflag_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 PreorderStatusflagValue($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + + + if (array_key_exists("preorder_id", $filter)) { + $preorder_id = $filter['preorder_id']; + if (is_numeric($preorder_id)) { + $where .= " AND PreorderStatusflagValue.preorder_id=$preorder_id"; + } + } + + if (array_key_exists("flag_id", $filter)) { + $flag_id = $filter['flag_id']; + if (is_numeric($flag_id)) { + $where .= " AND PreorderStatusflagValue.flag_id=$flag_id"; + } + } + + if (array_key_exists("value", $filter)) { + $value = $filter['value']; + if (is_numeric($value)) { + $where .= " AND PreorderStatusflagValue.value=$value"; + } + } + + + if (array_key_exists("create_by", $filter)) { + $create_by = $filter['create_by']; + if (is_numeric($create_by)) { + $where .= " AND PreorderStatusflagValue.create_by=$create_by"; + } + } + + return $where; + } + +} diff --git a/db/migrations/20240717144237_create_preorderstatus_flag.php b/db/migrations/20240717144237_create_preorderstatus_flag.php new file mode 100644 index 000000000..d77ab98d3 --- /dev/null +++ b/db/migrations/20240717144237_create_preorderstatus_flag.php @@ -0,0 +1,86 @@ +getEnvironment() == "thetool") { + $psf = $this->table("PreorderStatusflag"); + $psf->addColumn("code", "integer", ["null" => false]); + $psf->addColumn("name", "string", ["null" => false, "limit" => 64]); + $psf->addColumn("connection_type", "enum", ["null" => false, "values" => "all,single,multi", "default" => "all"]); + $psf->addColumn("create_by", "integer", ["null" => false]); + $psf->addColumn("edit_by", "integer", ["null" => false]); + $psf->addColumn("create", "integer", ["null" => false]); + $psf->addColumn("edit", "integer", ["null" => false]); + $psf->create(); + + $psf->insert([ + [ + "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(); + + $psfv = $this->table("PreorderStatusflagValue"); + $psfv->addColumn("flag_id", "integer", ["null" => false]); + $psfv->addColumn("value", "integer", ["null" => false]); + $psfv->addColumn("create_by", "integer", ["null" => false]); + $psfv->addColumn("edit_by", "integer", ["null" => false]); + $psfv->addColumn("create", "integer", ["null" => false]); + $psfv->addColumn("edit", "integer", ["null" => false]); + $psfv->save(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $this->table("PreorderStatusflagValue")->drop()->save(); + $this->table("PreorderStatusflag")->drop()->save(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} From f08111c9a4b19f461fa9f26fc7dfe7b26ab5bb20 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 18 Jul 2024 14:28:41 +0200 Subject: [PATCH 2/5] Added general history in Preorder --- .../Preorder/include/preorder-detail.php | 28 +- application/Preorder/Preorder.php | 32 +- .../PreorderHistory/PreorderHistory.php | 47 +- .../PreorderHistory/PreorderHistoryModel.php | 6 +- lib/mvcfronk/mfBase/mfBaseModel.php | 607 ++++++++++-------- 5 files changed, 415 insertions(+), 305 deletions(-) diff --git a/Layout/default/Preorder/include/preorder-detail.php b/Layout/default/Preorder/include/preorder-detail.php index a83498d5f..1d271623c 100644 --- a/Layout/default/Preorder/include/preorder-detail.php +++ b/Layout/default/Preorder/include/preorder-detail.php @@ -8,10 +8,10 @@ - is("Admin") && $preorder->adb_hausnummer->borderpoint_lat && $preorder->adb_hausnummer->borderpoint_long): ?> + @@ -471,11 +471,11 @@
-
Addressdetails
+
History
-

Status-Historie

+

Status Historie

@@ -484,7 +484,7 @@ history as $history): ?> - key != "preorderstatus_id") continue; ?> + key != "status_id") continue; ?> @@ -493,6 +493,26 @@
ZeitpunktNeuer Status
create)?> creator->name?>
+ +

Gesamte Historie

+ + + + + + + + + history as $history): ?> + + + + + + + + +
ZeitpunktBenutzerFeldAlter WertNeuer Wert
create)?>creator->name?>key?>getText("old")?>getText("new")?>
diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 1e12c17d8..cbb5e938a 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -39,6 +39,7 @@ class Preorder extends mfBaseModel { $this->creator = null; $this->editor = null; + // prevent potential infinite loop $nesting_level = mfValuecache::singleton()->get("preorder-save-nesting-level-".$this->id); if(!$nesting_level) { $nesting_level = 1; @@ -51,9 +52,6 @@ class Preorder extends mfBaseModel { return true; } - // prevent potential infinite loop - //if($this->in_after_save) return true; - //$this->in_after_save++; // update preorder OAID if it's different from the unit OAID // but only if the unit OAID is of the same origin as the campaign $old_oaid = $this->oaid; @@ -64,10 +62,9 @@ class Preorder extends mfBaseModel { } //TODO: history start - if($this->status_id != $this->_old_data->status_id) { + //if($this->status_id != $this->_old_data->status_id) { $this->createHistoryEntry(); - $this->_old_data->status_id = $this->status_id; - } + //} // run triggers based on new status $this->runStatusTrigger(); @@ -79,13 +76,22 @@ class Preorder extends mfBaseModel { } public function createHistoryEntry() { - $history = PreorderHistoryModel::create([ - "preorder_id" => $this->id, - "key" => 'preorderstatus_id', - "old_value" => $this->_old_data->status_id, - "new_value" => $this->status_id - ]); - $history->save(); + if(!$this->id) return true; + + $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(); + } + + } public function runStatusTrigger() { diff --git a/application/PreorderHistory/PreorderHistory.php b/application/PreorderHistory/PreorderHistory.php index fb39c4711..d52d38c26 100644 --- a/application/PreorderHistory/PreorderHistory.php +++ b/application/PreorderHistory/PreorderHistory.php @@ -1,6 +1,7 @@ key, $m)) { if(array_key_exists(1, $m)) { $object = ucfirst($m[1]); - - $value = new $object($value); - if(!$value->id) return null; + if($object == "Status") $object = "Preorderstatus"; + if($object == "Partner") $object = "Address"; + if($object == "Adb_hausnummer") $object = "ADBHausnummer"; + if($object == "Adb_wohneinheit") $object = "ADBWohneinheit"; + if(class_exists($object)) { + $value = new $object($value); + if(!$value->id) return null; + } } } return $value; + } + 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; + } } public function getProperty($name) { diff --git a/application/PreorderHistory/PreorderHistoryModel.php b/application/PreorderHistory/PreorderHistoryModel.php index e216d6908..e13ef7fd7 100644 --- a/application/PreorderHistory/PreorderHistoryModel.php +++ b/application/PreorderHistory/PreorderHistoryModel.php @@ -41,7 +41,7 @@ class PreorderHistoryModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $res = $db->select("PreorderHistory", "*", "$where ORDER BY preorder_id,`key`,`create` LIMIT 1"); + $res = $db->select("PreorderHistory", "*", "$where ORDER BY `create`,`key` LIMIT 1"); if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new PreorderHistory($data); @@ -59,7 +59,7 @@ class PreorderHistoryModel { $db = FronkDB::singleton(); - $res = $db->select("PreorderHistory", "*", "1=1 ORDER BY preorder_id,`key`,`create`"); + $res = $db->select("PreorderHistory", "*", "1=1 ORDER BY `create`,`key`"); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { $items[] = new PreorderHistory($data); @@ -91,7 +91,7 @@ class PreorderHistoryModel { $where = self::getSqlFilter($filter); $sql = "SELECT * FROM PreorderHistory WHERE $where - ORDER BY preorder_id,`key`,`create`"; + ORDER BY `create`,`key`"; mfLoghandler::singleton()->debug($sql); if (is_array($limit) && count($limit)) { diff --git a/lib/mvcfronk/mfBase/mfBaseModel.php b/lib/mvcfronk/mfBase/mfBaseModel.php index 0a704798f..206a3f9d1 100644 --- a/lib/mvcfronk/mfBase/mfBaseModel.php +++ b/lib/mvcfronk/mfBase/mfBaseModel.php @@ -4,314 +4,357 @@ * Does most of the dirty work in getting Database entries into * an object. * Takes an ID, or FronkDB table row for automatic loading - * @author fronk * @param optional ID or table row $_ + * @author fronk */ if(!defined("FRONKDB")) { - define("FRONKDB", true); + define("FRONKDB", true); } class mfBaseModel { - public $id; - public $data; - public $_old_data; - protected $create; - protected $edit; - private $worker; - protected $forcestr; + public $id; + public $data; + public $_old_data; + protected $create; + protected $edit; + private $worker; + protected $forcestr; - protected $mode = "new"; - protected $saved = 0; - protected $db; - protected $log; - protected $table=false; - protected $fieldprefix=false; + protected $mode = "new"; + protected $saved = 0; + protected $db; + protected $log; + protected $table = false; + protected $fieldprefix = false; - /** - * Takes ID or DB row as arguments - * @param id or table row $_ - */ - public function __construct($_=NULL) { - $this->log=mfLoghandler::singleton(); - $this->table=get_class($this); - $this->data = new stdClass(); - $this->_old_data = new stdClass(); + /** + * Takes ID or DB row as arguments + * @param id or table row $_ + */ + public function __construct($_ = NULL) { + $this->log = mfLoghandler::singleton(); + $this->table = get_class($this); + $this->data = new stdClass(); + $this->_old_data = new stdClass(); - if(defined("MFMODEL_USEFIELDPREFIX") && MFMODEL_USEFIELDPREFIX==true) { - $this->prefixfields=true; - } - - $this->data = new stdClass(); - - if(FRONKDB) { - $this->db=FronkDB::singleton(); - } - - if(method_exists($this, "init")) { - $this->init($_); - } - - if(is_numeric($_)) { - $this->fetch($_); - } elseif(is_object($_)) { - $this->load($_); - } - } - - public function load($row) { - if(!is_object($this->data)) { - $this->data = new stdClass(); - } - - foreach($row as $field => $value) { - if($this->fieldprefix) { - if(preg_match('/^'.$this->fieldprefix.'_(.+)$/',$field,$m)) { - $field=$m[1]; - } - } - if($field=="id" - || $field=="create" - || $field=="edit") continue; - $this->data->$field=$value; - } - - $this->id=$row->id; - - if(!property_exists($row, "create")) { - $row->create = date("U"); - } - if(!property_exists($row, "edit")) { - $row->edit = date("U"); - } - - $this->create=$row->create; - $this->edit=$row->edit; - if($this->fieldprefix) { - $prop=$this->fieldprefix."_id"; - $this->id=$row->$prop; - } - - $this->_old_data = clone($this->data); - $this->_old_data->id = $this->id; - $this->_old_data->create = $this->create; - $this->_old_data->edit = $this->edit; - - $this->mode = "update"; - - if(method_exists($this, "afterLoad")) { - $this->afterLoad(); - } - - return true; - } - - public function fetch($id) { - $where="id=$id"; - if($this->fieldprefix) { - $where=$this->fieldprefix."_id=$id"; - } - - $res=$this->db->select($this->table,"*","$where"); - if($this->db->num_rows($res)) { - $data=$this->db->fetch_object($res); - $this->load($data); - return true; - } - return false; - } - - public function update(Array $data) { - foreach($data as $key => $value) { - if($value === null) { - $this->$key = null; - } else { - $this->$key = $value; - } - } - } - - public function save() { - if(method_exists($this, "beforeSave")) { - $this->beforeSave(); - } - $fields=$this->buildFields(); - - $forcestr = array(); - - if(!$this->fieldprefix && is_array($this->forcestr) && count($this->forcestr)) { - $forcestr = $this->forcestr; - } - - if(is_array($this->forcestr) && count($this->forcestr)) { - foreach($this->forcestr as $fstr) { - $forcestr[] = $this->fieldprefix . "_$fstr"; - } - } - - if(!is_array($fields) or !count($fields)) { - return false; - } - - if($this->id) { - $id=$this->id; - $where="`id`=$id"; - if($this->fieldprefix) { - $where="`".$this->fieldprefix."_id`=$id"; - } - if($this->db->update($this->table,$fields,$where,$forcestr)) { - $this->saved++; - if(method_exists($this, "afterSave")) { - $this->afterSave(); + if(defined("MFMODEL_USEFIELDPREFIX") && MFMODEL_USEFIELDPREFIX == true) { + $this->prefixfields = true; } - return $id; - } - } else { - if($this->db->insert($this->table,$fields,$forcestr)) { - $id=mysqli_insert_id($this->db->link); - $this->id=$id; - $this->saved++; - if(method_exists($this, "afterSave")) { - $this->afterSave(); + + $this->data = new stdClass(); + + if(FRONKDB) { + $this->db = FronkDB::singleton(); } - return $id; - } - } - return false; - } - protected function buildFields() { - $fields = array(); - foreach($this->data as $field => $value) { - if($this->fieldprefix && !strstr($field,"_")) { - $field = $this->fieldprefix."_$field"; - } - $fields[$field]=$value; - } + if(method_exists($this, "init")) { + $this->init($_); + } - if(!$this->create) { - $this->create = date('U'); - } - $this->edit = date('U'); - - foreach(array("create","edit") as $f) { - $fields[$f] = $this->$f; - } - - if(method_exists($this, "afterBuildFields")) { - $fields = $this->afterBuildFields($fields); + if(is_numeric($_)) { + $this->fetch($_); + } elseif(is_object($_)) { + $this->load($_); + } } - - return $fields; - } - public function delete() { - if($this->id) { - $id=$this->id; - $where="id=$id"; - if($this->fieldprefix && !strstr($field,"_")) { - $where=$this->fieldprefix."_id=$id"; - } + public function load($row) { + if(!is_object($this->data)) { + $this->data = new stdClass(); + } + + foreach($row as $field => $value) { + if($this->fieldprefix) { + if(preg_match('/^' . $this->fieldprefix . '_(.+)$/', $field, $m)) { + $field = $m[1]; + } + } + if($field == "id" + || $field == "create" + || $field == "edit") continue; + $this->data->$field = $value; + } + + $this->id = $row->id; + + if(!property_exists($row, "create")) { + $row->create = date("U"); + } + if(!property_exists($row, "edit")) { + $row->edit = date("U"); + } + + $this->create = $row->create; + $this->edit = $row->edit; + if($this->fieldprefix) { + $prop = $this->fieldprefix . "_id"; + $this->id = $row->$prop; + } + + $this->_old_data = clone($this->data); + $this->_old_data->id = $this->id; + $this->_old_data->create = $this->create; + $this->_old_data->edit = $this->edit; + + $this->mode = "update"; + + if(method_exists($this, "afterLoad")) { + $this->afterLoad(); + } + + return true; + } + + public function fetch($id) { + $where = "id=$id"; + if($this->fieldprefix) { + $where = $this->fieldprefix . "_id=$id"; + } + + $res = $this->db->select($this->table, "*", "$where"); + if($this->db->num_rows($res)) { + $data = $this->db->fetch_object($res); + $this->load($data); + return true; + } + return false; + } + + public function update(array $data) { + foreach($data as $key => $value) { + if($value === null) { + $this->$key = null; + } else { + $this->$key = $value; + } + } + } + + public function save() { + if(method_exists($this, "beforeSave")) { + $this->beforeSave(); + } + $fields = $this->buildFields(); + + $forcestr = array(); + + if(!$this->fieldprefix && is_array($this->forcestr) && count($this->forcestr)) { + $forcestr = $this->forcestr; + } + + if(is_array($this->forcestr) && count($this->forcestr)) { + foreach($this->forcestr as $fstr) { + $forcestr[] = $this->fieldprefix . "_$fstr"; + } + } + + if(!is_array($fields) or !count($fields)) { + return false; + } + + if($this->id) { + $id = $this->id; + $where = "`id`=$id"; + if($this->fieldprefix) { + $where = "`" . $this->fieldprefix . "_id`=$id"; + } + if($this->db->update($this->table, $fields, $where, $forcestr)) { + $this->saved++; + if(method_exists($this, "afterSave")) { + $this->afterSave(); + } + return $id; + } + } else { + if($this->db->insert($this->table, $fields, $forcestr)) { + $id = mysqli_insert_id($this->db->link); + $this->id = $id; + $this->saved++; + if(method_exists($this, "afterSave")) { + $this->afterSave(); + } + return $id; + } + } + return false; + } + + protected function buildFields() { + $fields = array(); + foreach($this->data as $field => $value) { + if($this->fieldprefix && !strstr($field, "_")) { + $field = $this->fieldprefix . "_$field"; + } + $fields[$field] = $value; + } + + if(!$this->create) { + $this->create = date('U'); + } + $this->edit = date('U'); + + foreach(array("create", "edit") as $f) { + $fields[$f] = $this->$f; + } + + if(method_exists($this, "afterBuildFields")) { + $fields = $this->afterBuildFields($fields); + } + + return $fields; + } + + public function delete() { + if($this->id) { + $id = $this->id; + $where = "id=$id"; + if($this->fieldprefix && !strstr($field, "_")) { + $where = $this->fieldprefix . "_id=$id"; + } if(method_exists($this, "beforeDelete")) { // delete can be canceled if(!$this->beforeDelete()) { return false; } } - if($this->db->delete($this->table,$where)) { - if(method_exists($this, "afterDelete")) { - $this->afterDelete(); + if($this->db->delete($this->table, $where)) { + if(method_exists($this, "afterDelete")) { + $this->afterDelete(); + } + $this->data = new stdClass(); + $this->id = ""; + return true; + } } - $this->data=new stdClass(); - $this->id=""; - return true; - } - } - return false; - } - - public function new() { - if($this->mode == "new" && $this->saved <= 1) { - return "new"; - } else { - return "update"; + return false; } - } - - public function startTransaction() { - $this->db->query("START TRANSACTION"); - } - - public function commitTransaction() { - $this->db->query("COMMIT"); - } - - public function rollbackTransaction() { - $this->db->query("ROLLBACK"); - } - // generic functions for entity-classes - public function toArray() { - if(!$this->id) { - return []; - } - - $item = []; - $item['id'] = $this->id; - foreach($this->data as $key => $value) { - $item[$key] = $value; - } - - return $item; - } - - - public function __toString() { - return (string) $this->data->Name; - } - - public function __get($name) { - if($name == "create" || $name == "edit") { - if(isset($this->data->$name)) { - return $this->data->$name; - } else { - return $this->$name; - } - } - - - if(isset($this->data->$name)) { - return $this->data->$name; - } elseif(property_exists($this, $name)) { - if(method_exists($this, "getProperty")) { - $prop = $this->getProperty($name); - if($prop === null){ - return null; + protected function getChangedFields($include_system = false) { + if(!$this->_old_data->id) return []; + if(!is_object($this->data) || !is_object($this->_old_data)) { + return []; } - return $prop; - } else { - return $this->$name; - } - } - return null; - } - public function __set($name,$value) { - if($name=="create") { - $this->create=intval($value); - } - $this->data->$name=$value; - return true; - } + $changes = []; - public function __unset($name) { - unset($this->data->$name); - } - - public function __debugInfo() { - $vars = get_object_vars($this); - if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)"; - if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)'; - return $vars; - } + foreach($this->data as $field => $value) { + if(!$include_system && in_array($field, ["id", "create_by", "edit_by", "create", "edit"])) continue; + if(is_object($value)) continue; + + if(!property_exists($this->_old_data, $field)) { + $changes[] = $field; + continue; + } + if($value != $this->_old_data->$field) { + $changes[] = $field; + } + } + + foreach($this->_old_data as $field => $value) { + if(!$include_system && in_array($field, ["id", "create_by", "edit_by", "create", "edit"])) continue; + if(is_object($value)) continue; + + if(in_array($field, $changes)) { + continue; + } + if(!property_exists($this->data, $field)) { + $changes[] = $field; + continue; + } + + if($value != $this->data->$field) { + $changes[] = $field; + } + + } + + + return $changes; + } + + public function new() { + if($this->mode == "new" && $this->saved <= 1) { + return "new"; + } else { + return "update"; + } + } + + public function startTransaction() { + $this->db->query("START TRANSACTION"); + } + + public function commitTransaction() { + $this->db->query("COMMIT"); + } + + public function rollbackTransaction() { + $this->db->query("ROLLBACK"); + } + + // generic functions for entity-classes + public function toArray() { + if(!$this->id) { + return []; + } + + $item = []; + $item['id'] = $this->id; + foreach($this->data as $key => $value) { + $item[$key] = $value; + } + + return $item; + } + + + public function __toString() { + return (string)$this->data->Name; + } + + public function __get($name) { + if($name == "create" || $name == "edit") { + if(isset($this->data->$name)) { + return $this->data->$name; + } else { + return $this->$name; + } + } + + + if(isset($this->data->$name)) { + return $this->data->$name; + } elseif(property_exists($this, $name)) { + if(method_exists($this, "getProperty")) { + $prop = $this->getProperty($name); + if($prop === null) { + return null; + } + return $prop; + } else { + return $this->$name; + } + } + return null; + } + + public function __set($name, $value) { + if($name == "create") { + $this->create = intval($value); + } + $this->data->$name = $value; + return true; + } + + public function __unset($name) { + unset($this->data->$name); + } + + public function __debugInfo() { + $vars = get_object_vars($this); + if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)"; + if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)'; + return $vars; + } } From d54673289f346255e930b081e469050c90a8d372 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 18 Jul 2024 14:46:40 +0200 Subject: [PATCH 3/5] Fixed displaying status history in Preorder --- Layout/default/Preorder/include/preorder-detail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Layout/default/Preorder/include/preorder-detail.php b/Layout/default/Preorder/include/preorder-detail.php index 1d271623c..30aef601a 100644 --- a/Layout/default/Preorder/include/preorder-detail.php +++ b/Layout/default/Preorder/include/preorder-detail.php @@ -484,7 +484,7 @@ Neuer Status history as $history): ?> - key != "status_id") continue; ?> + key != "preorderstatus_id") continue; ?> create)?> creator->name?> From 724e2eccee39a477408e4752833479c1aeff5dfc Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 18 Jul 2024 15:05:24 +0200 Subject: [PATCH 4/5] Added birthday to Address --- Layout/default/Address/Form.php | 16 +++++++++- Layout/default/Address/View.php | 3 ++ application/Address/AddressController.php | 12 ++++++- application/Address/AddressModel.php | 1 + application/Preorder/Preorder.php | 2 -- .../20240718123809_address_add_birthdate.php | 31 +++++++++++++++++++ 6 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 db/migrations/20240718123809_address_add_birthdate.php diff --git a/Layout/default/Address/Form.php b/Layout/default/Address/Form.php index dca5d177d..3b53f3b26 100644 --- a/Layout/default/Address/Form.php +++ b/Layout/default/Address/Form.php @@ -120,7 +120,12 @@
- +
+ +
+ "> +
+
@@ -445,6 +450,15 @@ todayBtn: 'linked', autoclose: true }); + + $('#birthdate').datepicker({ + language: 'de', + format: "dd.mm.yyyy", + showWeekDays: true, + todayBtn: 'linked', + autoclose: true + }); + var bankdata_valid = false; diff --git a/Layout/default/Address/View.php b/Layout/default/Address/View.php index 199ca265c..29d1157a1 100644 --- a/Layout/default/Address/View.php +++ b/Layout/default/Address/View.php @@ -73,6 +73,9 @@ Email email?> + + Geburtsdatum + birthdate) ? (new DateTime($address->birthdate))->format("d.m.Y") : ""?> diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index 7a25bec41..4e0085f0d 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -266,7 +266,17 @@ class AddressController extends mfBaseController { $data['email'] = trim($r->email); $data['note'] = trim($r->note); $data['uid'] = trim($r->uid); - + + if(trim($r->birthdate)) { + try { + $data["birthdate"] = (DateTime::createFromFormat("d.m.Y", trim($r->birthdate)))->format("Y-m-d"); + } catch(Exception $e) { + $this->layout()->setFlash("Ungültiges Geburtsdaum", "warning"); + } + + } + + if($this->me->can("Fibu")) { $data["sepa_date"] = ($r->sepa_date) ? Layout::dateToInt($r->sepa_date) : null; diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index cd8b2053c..1c0f2841f 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -22,6 +22,7 @@ class AddressModel { public $fax; public $mobile; public $email; + public $birthday; public $uid; public $billing_type; public $billing_delivery; diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index cbb5e938a..2eadcf591 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -90,8 +90,6 @@ class Preorder extends mfBaseModel { ]); $history->save(); } - - } public function runStatusTrigger() { diff --git a/db/migrations/20240718123809_address_add_birthdate.php b/db/migrations/20240718123809_address_add_birthdate.php new file mode 100644 index 000000000..15240d16d --- /dev/null +++ b/db/migrations/20240718123809_address_add_birthdate.php @@ -0,0 +1,31 @@ +getEnvironment() == "thetool") { + $table = $this->table("Address"); + $table->addColumn("birthdate", "date", ["null" => true, "default" => null, "after" => "uid"]); + $table->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $this->table("Address")->removeColumn("birthdate")->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} From 4456c3e8fb9c6476fa34b8c43b1dc03979d45ea0 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Tue, 23 Jul 2024 16:50:25 +0200 Subject: [PATCH 5/5] added disable-filtering option --- public/plugins/vue/tt-components/tt-table.js | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/public/plugins/vue/tt-components/tt-table.js b/public/plugins/vue/tt-components/tt-table.js index 2aebd6873..25c82c5ed 100644 --- a/public/plugins/vue/tt-components/tt-table.js +++ b/public/plugins/vue/tt-components/tt-table.js @@ -149,21 +149,21 @@ Vue.component('tt-table', { (column.filter === 'dateRange' ? 'min-width: 260px;' : '') + (originalColumnWidths[column.key] ? 'width: ' + originalColumnWidths[column.key] + 'px;' : '')" > -
+ @click="column.sortable && !disableFiltering ? setOrder(column.key) : undefined"> {{ column.text }} -
- - - - - - + + + + + + @@ -264,7 +264,8 @@ Vue.component('tt-table', { excelExport: {type: Boolean, default: false}, config: {type: Object, default: () => ({}), required: true}, ssr: {type: Boolean, default: false}, - disableInitialFetch: {type: Boolean, default: false} + disableInitialFetch: {type: Boolean, default: false}, + disableFiltering: {type: Boolean, default: false} }, data() { return { window: window,