Feature/preorder add history

This commit is contained in:
Luca Haid
2024-07-17 13:34:22 +00:00
committed by Frank Schubert
parent 076b513039
commit 04153eb8d3
6 changed files with 332 additions and 2 deletions
+26 -2
View File
@@ -18,6 +18,7 @@ class Preorder extends mfBaseModel {
private $editor;
private $attribute = [];
private $logistics;
private $history;
public function afterLoad() {
if($this->uid === "string") {
@@ -49,7 +50,12 @@ class Preorder extends mfBaseModel {
if($this->oaid != $old_oaid) {
$this->save();
}
//TODO: history start
if($this->status_id != $this->_old_data->status_id) {
$this->createHistoryEntry();
}
// run triggers based on new status
$this->runStatusTrigger();
// Cascade status changes down to adb_hausnummer and adb_wohneinheit
@@ -59,6 +65,16 @@ class Preorder extends mfBaseModel {
$this->in_after_save--;
}
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();
}
public function runStatusTrigger() {
if(!$this->id) return true;
@@ -699,7 +715,15 @@ class Preorder extends mfBaseModel {
$this->logistics = $logistics;
return $this->logistics;
}
if($name == "history") {
$history = PreorderHistoryModel::search(["preorder_id" => $this->id]);
$this->history = $history;
return $this->history;
}
if($name == "attribute") {
if(!$this->attributes) {
return null;