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:
Frank Schubert
2024-11-06 15:16:07 +00:00
2 changed files with 79 additions and 0 deletions

View File

@@ -180,4 +180,62 @@ class Rimoapi {
$resp_data = json_decode($response);
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;
}
}