diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php
index 33dd5df87..5c0a30544 100644
--- a/application/Preorder/Preorder.php
+++ b/application/Preorder/Preorder.php
@@ -5,6 +5,7 @@ class Preorder extends mfBaseModel {
private $in_after_save = 0;
private $status;
+ private $statusflags;
private $campaign;
private $partner;
private $discounts;
@@ -658,6 +659,18 @@ class Preorder extends mfBaseModel {
}
return $this->status;
}
+
+ if($name == "statusflags") {
+ $flags = [];
+ foreach(PreorderStatusflagModel::getAll() as $flag) {
+ $flag->preorder_id = $this->id;
+ $flags[$flag->id] = $flag;
+ }
+ if(count($flags)) {
+ $this->statusflags = $flags;
+ }
+ return $this->statusflags;
+ }
if($name == "partner") {
$this->partner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->partner_id);
diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php
index fb03d24e2..6cdcab285 100644
--- a/application/Preorder/PreorderController.php
+++ b/application/Preorder/PreorderController.php
@@ -914,6 +914,9 @@ class PreorderController extends mfBaseController {
case "savePatchposition":
$return = $this->savePatchpositionApi();
break;
+ case "setStatusFlag":
+ $return = $this->setStatusFlagAction();
+ break;
default:
$return = false;
}
@@ -926,7 +929,38 @@ class PreorderController extends mfBaseController {
$data['result'] = $return;
$this->returnJson($data);
}
-
+
+ private function setStatusFlagAction() {
+ $preorder_id = $this->request->preorder_id;
+ $flag_id = $this->request->flag_id;
+ $value = $this->request->value;
+
+ if(!$preorder_id || !$flag_id) {
+ return false;
+ }
+
+ $flag = new PreorderStatusflag($flag_id);
+ if(!$flag->id) {
+ return false;
+ }
+
+ $flagvalue = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder_id, "flag_id" => $flag_id]);
+ if(!$flagvalue) {
+ $flagvalue = PreorderStatusflagValueModel::create([
+ "preorder_id" => $preorder_id,
+ "flag_id" => $flag_id
+ ]);
+ }
+
+ $flagvalue->value = ($value) ? 1 : 0;
+
+ if(!$flagvalue->save()) {
+ return false;
+ }
+
+ return ["message" => "Statusflag saved successfully"];
+ }
+
private function getFilteredPreordersApi() {
$preorders = [];
$filter = [];
diff --git a/application/PreorderStatusflag/PreorderStatusflag.php b/application/PreorderStatusflag/PreorderStatusflag.php
index a57a2cfaa..b847aedd6 100644
--- a/application/PreorderStatusflag/PreorderStatusflag.php
+++ b/application/PreorderStatusflag/PreorderStatusflag.php
@@ -1,5 +1,52 @@
$name == null) {
+
+ if($name == "value") {
+ if(!$this->preorder_id) return null;
+ $value = PreorderStatusflagValueModel::getFirst(["preorder_id" => $this->preorder_id, "flag_id" => $this->id]);
+ $this->value = $value;
+ return $this->value;
+ }
+
+ if($name == "creator") {
+ $user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
+ if($user) {
+ $this->creator = $user;
+ return $this->creator;
+ }
+ $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 = new User($this->edit_by);
+ 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;
+ }
}
\ No newline at end of file
diff --git a/application/PreorderStatusflagValue/PreorderStatusflagValueModel.php b/application/PreorderStatusflagValue/PreorderStatusflagValueModel.php
index 74e960a85..2864edba6 100644
--- a/application/PreorderStatusflagValue/PreorderStatusflagValueModel.php
+++ b/application/PreorderStatusflagValue/PreorderStatusflagValueModel.php
@@ -5,8 +5,6 @@ class PreorderStatusflagValueModel {
public $preorder_id;
public $flag_id;
public $value;
- public $old_value;
- public $new_value;
public $create_by;
public $edit_by;
public $create;
@@ -42,7 +40,8 @@ class PreorderStatusflagValueModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
- $res = $db->select("PreorderStatusflagValue", "*", "$where ORDER BY statusflag_id LIMIT 1");
+
+ $res = $db->select("PreorderStatusflagValue", "*", "$where ORDER BY flag_id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new PreorderStatusflagValue($data);
@@ -60,7 +59,7 @@ class PreorderStatusflagValueModel {
$db = FronkDB::singleton();
- $res = $db->select("PreorderStatusflagValue", "*", "1=1 ORDER BY statusflag_id");
+ $res = $db->select("PreorderStatusflagValue", "*", "1=1 ORDER BY flag_id");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new PreorderStatusflagValue($data);
@@ -92,7 +91,7 @@ class PreorderStatusflagValueModel {
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM PreorderStatusflagValue
WHERE $where
- ORDER BY statusflag_id";
+ ORDER BY flag_id";
mfLoghandler::singleton()->debug($sql);
if (is_array($limit) && count($limit)) {
@@ -116,7 +115,6 @@ class PreorderStatusflagValueModel {
$where = "1=1 ";
-
if (array_key_exists("preorder_id", $filter)) {
$preorder_id = $filter['preorder_id'];
if (is_numeric($preorder_id)) {
diff --git a/db/migrations/20240717144237_create_preorderstatus_flag.php b/db/migrations/20240717144237_create_preorderstatus_flag.php
index d77ab98d3..296755643 100644
--- a/db/migrations/20240717144237_create_preorderstatus_flag.php
+++ b/db/migrations/20240717144237_create_preorderstatus_flag.php
@@ -58,12 +58,15 @@ final class CreatePreorderstatusFlag extends AbstractMigration
])->save();
$psfv = $this->table("PreorderStatusflagValue");
+ $psfv->addColumn("preorder_id", "integer", ["null" => false]);
$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->addIndex("preorder_id");
+ $psfv->addIndex(["preorder_id", "flag_id"]);
$psfv->save();
}