Preorder changes:
- New Wohneinheit field bezeichner - technology & patchposition fields - isAdditionalOrder field - DELETE /preorder (Cancelling)
This commit is contained in:
@@ -21,6 +21,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
|
||||
$this->addRoute("/preorder", "submitPreorder", "POST");
|
||||
$this->addRoute("/preorder/:code", "getPreorder", "GET");
|
||||
$this->addRoute("/preorder/:code", "cancelPreorder", "DELETE");
|
||||
|
||||
$this->allowMissingOrigin = true;
|
||||
}
|
||||
@@ -103,6 +104,45 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
|
||||
}
|
||||
|
||||
protected function cancelPreorder($code) {
|
||||
$code = trim(strtoupper($code));
|
||||
if(!$code) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirst(['ucode' => $code, 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
|
||||
if(!$preorder) {
|
||||
// try oan id
|
||||
$preorder = PreorderModel::getFirst(['oaid' => $code, 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
|
||||
if(!$preorder) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found or cancelled already"]);
|
||||
}
|
||||
}
|
||||
|
||||
// check if user owns preorder
|
||||
if($preorder->partner_id != $this->me->address_id) {
|
||||
return mfResponse::Forbidden(["message" => "Permission denied"]);
|
||||
}
|
||||
|
||||
if($preorder->cancel_request) {
|
||||
if($preorder->cancel_approved) {
|
||||
return mfResponse::Forbidden(["message" => "Order already cancelled"]);
|
||||
} else {
|
||||
return mfResponse::Forbidden(["message" => "Cancellation request was already submitted"]);
|
||||
}
|
||||
}
|
||||
|
||||
// set cancel_date and canceller
|
||||
$preorder->cancel_request = date('U');
|
||||
$preorder->cancel_request_by = $this->me->id;
|
||||
if(!$preorder->save()) {
|
||||
return mfResponse::InternalServerError();
|
||||
}
|
||||
|
||||
return mfResponse::Ok(['message' => "Cancellation request submited"]);
|
||||
|
||||
}
|
||||
|
||||
protected function submitPreorder() {
|
||||
//var_dump($this->post);exit;
|
||||
if(!$this->campaigns) {
|
||||
@@ -147,7 +187,12 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::BadRequest(['message' => "customer data missing"]);
|
||||
}
|
||||
|
||||
/*
|
||||
$is_additional_order = false;
|
||||
if(array_key_exists("isAdditionalOrder", $this->post) && $this->post['isAdditionalOrder']) {
|
||||
$is_additional_order = true;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* check address
|
||||
*/
|
||||
if(!property_exists($this->post['address'],"street") || !$this->post['address']->street ||
|
||||
@@ -191,7 +236,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
$unit_search = [];
|
||||
foreach(['block','stiege','stock','tuer'] as $key) {
|
||||
foreach(['block','stiege','stock','tuer','unit_id'] as $key) {
|
||||
if(property_exists($this->post['address'], $key) && trim($this->post['address']->$key)) {
|
||||
$unit_search[$key] = trim($this->post['address']->$key);
|
||||
}
|
||||
@@ -214,7 +259,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::BadRequest(['message' => "Mandatory customer fields missing"]);
|
||||
}
|
||||
|
||||
/*
|
||||
/**************************************************************
|
||||
* search address in AddressDB
|
||||
*/
|
||||
$where = "1=1 ";
|
||||
@@ -237,7 +282,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$address = $this->db()->fetch_object($res);
|
||||
//var_dump($address);exit;
|
||||
|
||||
/*
|
||||
/* **************************************************************
|
||||
* search wohneinheit
|
||||
*/
|
||||
$update_unit = false;
|
||||
@@ -246,11 +291,14 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$unit = false;
|
||||
if(count($unit_search)) {
|
||||
//var_dump($unit_search);exit;
|
||||
foreach($unit_search as $field => $value) {
|
||||
if($field == "stock") continue; // only check for block, stiege and tuer
|
||||
$where .= " AND `$field` = '$value'";
|
||||
if(array_key_exists("unit_id", $unit_search)) {
|
||||
$where .= " AND bezeichner LIKE '".$unit_search['unit_id']."'";
|
||||
} else {
|
||||
foreach($unit_search as $field => $value) {
|
||||
if($field == "stock") continue; // only check for block, stiege and tuer
|
||||
$where .= " AND `$field` = '$value'";
|
||||
}
|
||||
}
|
||||
|
||||
// filter salesclusters
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(',', $this->filter_salescluster_ids).")";
|
||||
@@ -267,7 +315,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
} else {
|
||||
// if all unit values are empty try to find the unit with all empty values
|
||||
// failure is not an error, but must be checked by a human at some point
|
||||
$where = "hausnummer_id=".$address->hausnummer_id." AND (block = '' OR block IS NULL) AND (stiege = '' OR stiege IS NULL) AND (stock = '' OR stock IS NULL) AND (tuer = '' OR tuer IS NULL)";
|
||||
$where = "hausnummer_id=".$address->hausnummer_id." AND (block = '' OR block IS NULL) AND (stiege = '' OR stiege IS NULL) AND (stock = '' OR stock IS NULL) AND (tuer = '' OR tuer IS NULL) AND (bezeichner = '' OR bezeichner IS NLL)";
|
||||
if($zusatz) {
|
||||
$where .= " AND zusatz='$zusatz'";
|
||||
} else {
|
||||
@@ -289,11 +337,11 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
}
|
||||
|
||||
if($this->exist_is_error) {
|
||||
if($this->exist_is_error && !$is_additional_order) {
|
||||
/*
|
||||
* check if there is an existing preorder for this unit already
|
||||
*/
|
||||
if($unit) {
|
||||
if($unit && $unit->wohneinheit_id) {
|
||||
$existing_preorder = PreorderModel::getFirst(['adb_wohneinheit_id' => $unit->wohneinheit_id]);
|
||||
if($existing_preorder) {
|
||||
return mfResponse::Forbidden(['message' => "Für diese Wohneinheit liegt bereits eine Bestellung vor"]);
|
||||
@@ -355,6 +403,14 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$preorder_data['accept_withdrawal'] = 1;
|
||||
}
|
||||
|
||||
if($is_additional_order) {
|
||||
$preorder_data['is_additional_order'] = 1;
|
||||
} else {
|
||||
$preorder_data['is_additional_order'] = 0;
|
||||
}
|
||||
$preorder_data['technology'] = ($this->post['technology']) ? $this->post['technology'] : null;
|
||||
$preorder_data['patchposition'] = ($this->post['patchposition']) ? $this->post['patchposition'] : null;
|
||||
|
||||
/*
|
||||
* setup price
|
||||
*/
|
||||
@@ -442,8 +498,10 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
|
||||
//var_dump($this->allow_unit_update, $update_unit);exit;
|
||||
|
||||
// update wohneinheit if allowed
|
||||
// and unit search data was submitted
|
||||
/**************************************************
|
||||
* update wohneinheit if allowed
|
||||
* and unit search data was submitted
|
||||
*/
|
||||
|
||||
$unit_changed = false;
|
||||
|
||||
@@ -465,10 +523,11 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
// get units excluding unavailable units
|
||||
$where = "hausnummer_id=".$address->hausnummer_id;
|
||||
$where .= " AND block IS NULL";
|
||||
$where .= " AND stiege IS NULL";
|
||||
$where .= " AND stock IS NULL";
|
||||
$where .= " AND tuer IS NULL";
|
||||
$where .= " AND ( block = '' OR block IS NULL)";
|
||||
$where .= " AND ( stiege = '' OR stiege IS NULL)";
|
||||
$where .= " AND ( stock = '' OR stock IS NULL)";
|
||||
$where .= " AND ( tuer = '' OR tuer IS NULL)";
|
||||
$where .= " AND ( bezeichner = '' OR bezeichner IS NULL)";
|
||||
|
||||
if(count($exclude_wohneinheit_ids)) {
|
||||
$where .= " AND wohneinheit_id NOT IN (". implode(",",$exclude_wohneinheit_ids).")";
|
||||
@@ -488,7 +547,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
//echo "blah";exit;
|
||||
|
||||
$change_note_data = [];
|
||||
foreach(['block','stiege','stock','tuer'] as $unit_address_part) {
|
||||
foreach(['block','stiege','stock','tuer','bezeichner'] as $unit_address_part) {
|
||||
if($unit_search[$unit_address_part]) {
|
||||
$unit->$unit_address_part = $unit_search[$unit_address_part];
|
||||
$unit_changed = true;
|
||||
|
||||
Reference in New Issue
Block a user