Added Button to create RimoWorkorder for legacytransfer Preorders

This commit is contained in:
Frank Schubert
2024-11-14 17:35:53 +01:00
parent c5752de7b7
commit 667027c0f1
4 changed files with 152 additions and 2 deletions
+63
View File
@@ -530,6 +530,69 @@ class Preorder extends mfBaseModel {
}
}
public function createRimoWorkorder() {
if(!$this->adb_wohneinheit_id) {
return false;
}
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
if(!$wohneinheit->id) {
$this->log->error(__METHOD__.": Wohneinheit nicht gefunden (Preorder ".$this->id." ".$this->ucode." ".$this->oaid.")");
return false;
}
if(!$wohneinheit->extref) {
return false;
}
if(!$this->oaid) {
$this->setOrCreateOaid();
if(!$this->oaid) {
return false;
}
}
$oaid = OpenAccessIdModel::getFirstOaid($wohneinheit->oaid);
if(!$oaid) {
$this->log->warning(__METHOD__.": OAID '".$wohneinheit->oaid."' not found");
return false;
}
// create and assign OAID if not yet done
$oaid->exportToRimoAndAssignFtu();
// create Workorder
$data = [];
$data["firstname"] = trim($this->firstname);
$data["lastname"] = trim($this->lastname);
$data["company"] = trim($this->company);
$data["phone"] = trim($this->phone);
$data["email"] = trim($this->email);
$data["orderId"] = $this->ucode;
$response = Rimoapi::createWorkorder($wohneinheit->extref, $data);
//var_dump($response);exit;
if(!$response) {
$this->log->error(__METHOD__."Cannot create RimoWorkorder! Invalid Response! (Preorder ucode: ".$this->ucode.")");
return false;
}
$rimo_status = $response->state->userLabel;
if(!$rimo_status) {
$rimo_status = "";
}
$wo = RimoWorkorderModel::create([
"rimo_id" => $response->id,
"rimo_name" => $response->name,
"rimo_status" => $rimo_status,
"adb_wohneinheit_id" => $this->adb_wohneinheit_id,
"create_data" => json_encode($response)
]);
//var_dump($wo);exit;
$wo->save();
return $wo;
}
public function setNewStatusCode($new_status_code) {
if(!$new_status_code) return false;