Added orderDate to POST /preorder; setting status when creating preorder
This commit is contained in:
@@ -638,6 +638,14 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$preorder_data['accept_digging'] = 1;
|
||||
}
|
||||
|
||||
if(trim($this->post['orderDate'])) {
|
||||
$order_date = trim($this->post['orderDate']);
|
||||
$m = [];
|
||||
if(preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d)$/', $order_date, $m)) {
|
||||
$preorder_data['order_date'] = mktime(4,0,0,$m[2],$m[3],$m[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if($is_additional_order) {
|
||||
$preorder_data['is_additional_order'] = 1;
|
||||
} else {
|
||||
@@ -845,7 +853,25 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
*/
|
||||
$preorder = PreorderModel::create($preorder_data);
|
||||
$preorder->createUcode();
|
||||
//var_dump($preorder);exit;
|
||||
|
||||
/*
|
||||
* set status based on building or unit status
|
||||
*/
|
||||
$new_status = false;
|
||||
if($preorder->adb_wohneinheit_id) {
|
||||
$new_status = PreorderstatusModel::getFirst(["code" => $preorder->adb_wohneinheit->status->code]);
|
||||
if($preorder->adb_hausnummer->status->code > $preorder->adb_wohneinheit->status->code) {
|
||||
$new_status = PreorderstatusModel::getFirst(["code" => $preorder->adb_hausnummer->status->code]);
|
||||
}
|
||||
} elseif($preorder->adb_hausnummer_id) {
|
||||
$new_status = PreorderstatusModel::getFirst(["code" => $preorder->adb_hausnummer->status->code]);
|
||||
}
|
||||
if($new_status) {
|
||||
$preorder->status_id = $new_status->id;
|
||||
} else {
|
||||
$preorder->status_id = 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$preorder_id = $preorder->save();
|
||||
} catch (\Exception $e) {
|
||||
@@ -869,6 +895,10 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
if($preorder->extref) {
|
||||
$return['extref'] = $preorder->extref;
|
||||
}
|
||||
if($preorder->order_date) {
|
||||
$return['orderDate'] = date("Y-m-d",$preorder->order_date);
|
||||
}
|
||||
$return['status'] = $preorder->status->getApiArray();
|
||||
if($addon_data) {
|
||||
$return["additionalData"] = $addon_data;
|
||||
}
|
||||
|
||||
@@ -351,23 +351,23 @@ class Preorder extends mfBaseModel {
|
||||
return $ucode;
|
||||
}
|
||||
|
||||
public function createCifCode() {
|
||||
$cifcode = $this->generateNewCifcode();
|
||||
while(PreorderModel::search(['cifcode' => $cifcode])) {
|
||||
$cifcode = $this->generateNewCifcode();
|
||||
public function createCiftoken() {
|
||||
$ciftoken = $this->generateNewCiftoken();
|
||||
while(PreorderModel::search(['ciftoken' => $ciftoken])) {
|
||||
$ciftoken = $this->generateNewCiftoken();
|
||||
}
|
||||
$this->cifcode = $cifcode;
|
||||
return $this->cifcode;
|
||||
$this->ciftoken = $ciftoken;
|
||||
return $this->ciftoken;
|
||||
}
|
||||
|
||||
private function generateNewCifcode() {
|
||||
private function generateNewCiftoken() {
|
||||
$chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxzy';
|
||||
$charsLength = strlen($chars);
|
||||
$cifcode = '';
|
||||
$ciftoken = '';
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$cifcode .= $chars[rand(0, $charsLength - 1)];
|
||||
$ciftoken .= $chars[rand(0, $charsLength - 1)];
|
||||
}
|
||||
return $cifcode;
|
||||
return $ciftoken;
|
||||
}
|
||||
|
||||
public function getApiArray() {
|
||||
@@ -382,8 +382,6 @@ 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['orderDate'] = ($this->order_date) ? date("Y-m-d",$this->order_date) : null;
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
class PreorderModel {
|
||||
public $ucode;
|
||||
public $ciftoken;
|
||||
public $cifurl;
|
||||
public $status_id;
|
||||
public $preordercampaign_id;
|
||||
public $adb_hausnummer_id;
|
||||
public $adb_wohneinheit_id;
|
||||
public $address_created;
|
||||
public $address_created_by;
|
||||
public $oaid;
|
||||
public $extref;
|
||||
public $address_district;
|
||||
@@ -56,6 +60,10 @@ class PreorderModel {
|
||||
public $attributes;
|
||||
public $submit_type;
|
||||
public $submit_request;
|
||||
public $installation_date;
|
||||
public $workorder_export_date;
|
||||
public $workorder_export_data;
|
||||
public $order_date;
|
||||
|
||||
public $cancel_request;
|
||||
public $cancel_request_by;
|
||||
@@ -420,11 +428,11 @@ class PreorderModel {
|
||||
if(array_key_exists("type", $filter)) {
|
||||
$type = $filter['type'];
|
||||
if(is_array($type) && count($type)) {
|
||||
$where .= " AND type IN ('".implode("','",$type)."')";
|
||||
$where .= " AND tt_preorder.type IN ('".implode("','",$type)."')";
|
||||
} else {
|
||||
$type = FronkDB::singleton()->escape($filter['type']);
|
||||
if($type) {
|
||||
$where .= " AND type like '%$type%'";
|
||||
$where .= " AND tt_preorder.type like '%$type%'";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -432,11 +440,11 @@ class PreorderModel {
|
||||
if(array_key_exists("connection_type", $filter)) {
|
||||
$connection_type = $filter['connection_type'];
|
||||
if(is_array($connection_type) && count($connection_type)) {
|
||||
$where .= " AND connection_type IN ('".implode("','",$connection_type)."')";
|
||||
$where .= " AND tt_preorder.connection_type IN ('".implode("','",$connection_type)."')";
|
||||
} else {
|
||||
$connection_type = FronkDB::singleton()->escape($filter['connection_type']);
|
||||
if($connection_type) {
|
||||
$where .= " AND connection_type like '%$connection_type%'";
|
||||
$where .= " AND tt_preorder.connection_type like '%$connection_type%'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,6 +527,17 @@ paths:
|
||||
extref:
|
||||
type: string
|
||||
description: Providereigener Identifikationsstring. Wird unverändert gespeichert und kann statt `code` in `GET /preorder` und `DELETE /preorder` angegeben werden. **Darf nicht mit Dateiendung wie z.B. `.json`, `.csv` enden, da diese als Ausgabeformat interpretiert werden können**
|
||||
status:
|
||||
type: object
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
description: status ID
|
||||
example: 230
|
||||
text:
|
||||
type: string
|
||||
description: Statustext
|
||||
example: Fiber installation work assigned
|
||||
additionalData:
|
||||
type: object
|
||||
description: Benutzerdefiniertes Objekt. Wird unverändert gespeichert und in `GET /preorder` wieder ausgegeben
|
||||
|
||||
Reference in New Issue
Block a user