Preorder: Status can now be changed manually
This commit is contained in:
@@ -211,6 +211,8 @@ class Preorder extends mfBaseModel {
|
||||
return $this->ucode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function generateNewUcode() {
|
||||
$chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
|
||||
$charsLength = strlen($chars);
|
||||
@@ -221,6 +223,25 @@ class Preorder extends mfBaseModel {
|
||||
return $ucode;
|
||||
}
|
||||
|
||||
public function createCifCode() {
|
||||
$cifcode = $this->generateNewCifcode();
|
||||
while(PreorderModel::search(['cifcode' => $cifcode])) {
|
||||
$cifcode = $this->generateNewCifcode();
|
||||
}
|
||||
$this->cifcode = $cifcode;
|
||||
return $this->cifcode;
|
||||
}
|
||||
|
||||
private function generateNewCifcode() {
|
||||
$chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxzy';
|
||||
$charsLength = strlen($chars);
|
||||
$cifcode = '';
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$cifcode .= $chars[rand(0, $charsLength - 1)];
|
||||
}
|
||||
return $cifcode;
|
||||
}
|
||||
|
||||
public function getApiArray() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
@@ -233,6 +254,8 @@ class Preorder extends mfBaseModel {
|
||||
|
||||
$a = [];
|
||||
$a['code'] = strtoupper($this->ucode);
|
||||
$a['cifcode'] = $this->cifcode;
|
||||
$a['cifurl'] = $this->cifurl;
|
||||
$a['oaid'] = $this->oaid;
|
||||
$a['extref'] = $this->extref;
|
||||
$a['status'] = $this->getProperty("status")->getApiArray();
|
||||
|
||||
@@ -249,6 +249,15 @@ class PreorderController extends mfBaseController {
|
||||
unset($filter['oaid']);
|
||||
}
|
||||
|
||||
if(array_key_exists("status", $filter) && is_array($filter['status']) && count($filter['status'])) {
|
||||
$new_filter['status_id'] = [];
|
||||
foreach($filter["status"] as $s) {
|
||||
if(is_numeric($s) && $s > 0) {
|
||||
$new_filter['status_id'][] = $s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if(array_key_exists("attributes", $filter) && count($filter['attributes'])) {
|
||||
|
||||
}*/
|
||||
@@ -785,6 +794,9 @@ class PreorderController extends mfBaseController {
|
||||
case "getFilteredPreorders":
|
||||
$return = $this->getFilteredPreordersApi();
|
||||
break;
|
||||
case "updateStatus":
|
||||
$return = $this->updateStatusApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
@@ -926,4 +938,32 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
private function updateStatusApi() {
|
||||
$preorder_id = $this->request->id;
|
||||
|
||||
if(!is_numeric($preorder_id) || $preorder_id < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$preorder = new Preorder($preorder_id);
|
||||
if(!$preorder->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$status_id = $this->request->status_id;
|
||||
if(!is_numeric($status_id) || $status_id < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$status = new Preorderstatus($status_id);
|
||||
if(!$status->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$preorder->status_id = $status_id;
|
||||
$preorder->save();
|
||||
|
||||
return ["message" => "Status saved successfully", "id" => $preorder_id, "status_id" => $status->id, "status_code" => $status->code, "status_text" => $status->name];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -321,21 +321,23 @@ class PreorderModel {
|
||||
if(array_key_exists("status_id", $filter)) {
|
||||
$status_id = $filter['status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND status_id=$status_id";
|
||||
$where .= " AND tt_preorder.status_id=$status_id";
|
||||
} elseif(is_array($status_id)) {
|
||||
$where .= " AND tt_preorder.status_id IN (". implode(",", $status_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("<status_id", $filter)) {
|
||||
$status_id = $filter['<status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND status_id < $status_id";
|
||||
$where .= " AND tt_preorder.status_id < $status_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists(">status_id", $filter)) {
|
||||
$status_id = $filter['>status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND status_id > $status_id";
|
||||
$where .= " AND tt_preorder.status_id > $status_id";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,6 +457,13 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("cifcode", $filter)) {
|
||||
$cifcode = FronkDB::singleton()->escape($filter['cifcode']);
|
||||
if($cifcode) {
|
||||
$where .= " AND cifcode LIKE '$cifcode'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid", $filter)) {
|
||||
$oaid = $filter['oaid'];
|
||||
if($oaid) {
|
||||
|
||||
Reference in New Issue
Block a user