Merge branch 'fronkdev' into 'master'
Updating contact in Preorder now triggers Rimo Workorder Update See merge request fronk/thetool!701
This commit is contained in:
@@ -84,7 +84,28 @@ class Preorder extends mfBaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function updateRimoWorkorderContact() {
|
public function updateRimoWorkorderContact() {
|
||||||
|
$contact_fields = [
|
||||||
|
"company",
|
||||||
|
"uid",
|
||||||
|
"firstname",
|
||||||
|
"lastname",
|
||||||
|
"phone",
|
||||||
|
"email"
|
||||||
|
];
|
||||||
|
$changed_fields = $this->getChangedFields();
|
||||||
|
|
||||||
|
$update = [];
|
||||||
|
foreach($changed_fields as $field) {
|
||||||
|
if(in_array($field, $contact_fields)) {
|
||||||
|
$update[$field] = $this->data->$field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($this->getProperty("adb_wohneinheit")->rimo_workorders as $workorder) {
|
||||||
|
Rimoapi::updateWorkorder($workorder->rimo_id, $update);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createHistoryEntry() {
|
public function createHistoryEntry() {
|
||||||
|
|||||||
@@ -180,4 +180,62 @@ class Rimoapi {
|
|||||||
$resp_data = json_decode($response);
|
$resp_data = json_decode($response);
|
||||||
return $resp_data;
|
return $resp_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function updateWorkorder($rimo_id, Array $data = []) {
|
||||||
|
$log = mfLoghandler::singleton();
|
||||||
|
|
||||||
|
if(!$rimo_id || !count($data)) {
|
||||||
|
$log->debug(__METHOD__.": no rimo id or no update data");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$contact_fields = [
|
||||||
|
"company" => "company",
|
||||||
|
"firstname" => "firstName",
|
||||||
|
"lastname" => "lastName",
|
||||||
|
"phone" => "phone",
|
||||||
|
"email" => "email"
|
||||||
|
];
|
||||||
|
|
||||||
|
$update_data = [];
|
||||||
|
|
||||||
|
foreach($data as $field => $value) {
|
||||||
|
if(array_key_exists($field, $contact_fields)) {
|
||||||
|
$update_data[$contact_fields[$field]] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var_dump($update_data);
|
||||||
|
if(!count($update_data)) {
|
||||||
|
$log->debug(__METHOD__.": no valid update data");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$update_data["orderId"] = $rimo_id;
|
||||||
|
$update_data['apiKey'] = RIMO_API_JSON_APIKEY;
|
||||||
|
|
||||||
|
$ctx_opts = [
|
||||||
|
'http' => [
|
||||||
|
'method' => 'PUT',
|
||||||
|
'header' => 'accept: application/json'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$qs = http_build_query($update_data);
|
||||||
|
|
||||||
|
$updateWorkorderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_UPDATE_WORKORDER;
|
||||||
|
$put_url = $updateWorkorderEp."?".$qs;
|
||||||
|
|
||||||
|
$ctx = stream_context_create($ctx_opts);
|
||||||
|
$log->debug(__METHOD__.": Updating Workorder Contact $rimo_id: $put_url");
|
||||||
|
$response = file_get_contents($put_url, false, $ctx);
|
||||||
|
|
||||||
|
if($response === false) {
|
||||||
|
$log->error("Fehler beim Updaten der Workorder $rimo_id in RIMO");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$resp_data = json_decode($response);
|
||||||
|
return $resp_data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user