Files
thetool/application/RimoWorkorder/RimoWorkorder.php
2025-04-14 15:08:12 +02:00

82 lines
2.3 KiB
PHP

<?php
class RimoWorkorder extends mfBaseModel {
private $adb_wohneinheit;
private $termination;
protected function beforeUpdate($data) {
if(!array_key_exists("edit_by", $data)) {
$me = new User();
$me->loadMe();
$data["edit_by"] = $me->id;
}
return $data;
}
public function afterSave() {
// prevent potential infinite loop
$nesting_level = mfValuecache::singleton()->get("rimoworkorder-save-nesting-level-".$this->id);
if(!$nesting_level) {
$nesting_level = 1;
} else {
$nesting_level++;
}
mfValuecache::singleton()->set("rimoworkorder-save-nesting-level-".$this->id, $nesting_level);
if($nesting_level > 1) {
return true;
}
// Statuschange from Rimo statuschange for all units
$wohneinheit = $this->getProperty("adb_wohneinheit");
if($wohneinheit) {
AddressDB::handleRimoStatusUpdate($wohneinheit->id);
}
}
public function getAha() {
if(!$this->id) return false;
if(!$this->adb_wohneinheit_id) return false;
$preorder = PreorderModel::getFirstActive(["adb_wohneinheit_id" => $this->adb_wohneinheit_id]);
$this->log->debug(__METHOD__.": Wohneinheit: ".$this->adb_wohneinheit_id);
$this->log->debug(__METHOD__.": Preorder: ".$preorder->id);
if(!$preorder) return false;
$api_creds = $preorder->getNetownerRimoApiCredentials();
$this->log->debug(__METHOD__.": Rimo Api Creds: ".print_r($api_creds, true));
if(!$api_creds) return false;
$apikey = $api_creds["prod"]["key"];
$ah = Rimoapi::getWorkorderAhaReport($apikey, $this->rimo_id);
return $ah;
}
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "adb_wohneinheit") {
$this->adb_wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
return $this->adb_wohneinheit;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}