updating Rimo subAddress when changing Home tuer

This commit is contained in:
Frank Schubert
2025-11-18 14:28:41 +01:00
parent be2c22ca50
commit db6d869286
4 changed files with 107 additions and 0 deletions

View File

@@ -189,6 +189,12 @@ class ADBHausnummerModel {
} }
/**
* @param $filter
* @param $limit
* @param $returnDBRessource
* @return ADBHausnummer[] ADBHausnummer Objects
*/
public static function search($filter, $limit = false, $returnDBRessource = false) { public static function search($filter, $limit = false, $returnDBRessource = false) {
$items = []; $items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);

View File

@@ -50,6 +50,8 @@ class ADBWohneinheit extends mfBaseModel {
if(!array_key_exists("no_updates", $_params) || !$_params['no_updates']) { if(!array_key_exists("no_updates", $_params) || !$_params['no_updates']) {
// Statuschange from Rimo statuschange // Statuschange from Rimo statuschange
AddressDB::handleRimoStatusUpdate($this->id); AddressDB::handleRimoStatusUpdate($this->id);
// Check if tuer has changed and sync to RIMO
$this->syncTuerToRimo();
} }
$this->refreshUnitCount(); $this->refreshUnitCount();
@@ -59,6 +61,59 @@ class ADBWohneinheit extends mfBaseModel {
return true; return true;
} }
private function syncTuerToRimo() {
// Check if tuer field has changed
$changes = $this->getChangedFields();
if(!in_array("tuer", $changes)) {
return true;
}
// Check if we have a RIMO external ID
if(!$this->extref) {
$this->log->debug("[".$this->_ruid."] ".__METHOD__.": No extref set, skipping RIMO sync");
return true;
}
// Get the hausnummer to access network owner
$hausnummer = $this->getProperty("hausnummer");
if(!$hausnummer || !$hausnummer->id) {
$this->log->debug("[".$this->_ruid."] ".__METHOD__.": No hausnummer found, skipping RIMO sync");
return true;
}
// Get RIMO API credentials
$creds = $hausnummer->getNetownerRimoApiCredentials();
if(!$creds) {
$this->log->warn("[".$this->_ruid."] ".__METHOD__.": No API credentials found for network owner");
return true;
}
// Get the API key (using prod environment)
$apikey = $creds["prod"]["key"];
if(!$apikey) {
$this->log->warn("[".$this->_ruid."] ".__METHOD__.": No API key found in credentials");
return true;
}
// Call RIMO API to update subAddress (tuer)
$this->log->info("[".$this->_ruid."] ".__METHOD__.": Syncing tuer change to RIMO for home ".$this->extref.": '".$this->tuer."'");
$subaddress = "";
if($this->tuer) {
$subaddress = "Top ".$this->tuer;
}
$result = Rimoapi::changeHomeSubAddress($apikey, $this->extref, $subaddress);
if($result) {
$this->log->info("[".$this->_ruid."] ".__METHOD__.": Successfully synced tuer to RIMO");
} else {
$this->log->error("[".$this->_ruid."] ".__METHOD__.": Failed to sync tuer to RIMO");
}
return $result;
}
public function refreshUnitCount() { public function refreshUnitCount() {
// ADBWohneinheit_onSave_noAutoUnitCount can be defined if doing bulk // ADBWohneinheit_onSave_noAutoUnitCount can be defined if doing bulk
// operations where unit count is calculated seperately // operations where unit count is calculated seperately

View File

@@ -482,6 +482,13 @@ class PreorderModel
return self::count($filter); return self::count($filter);
} }
/**
* @param $filter
* @param $limit
* @param $returnDBRessource
* @param $returnArray
* @return Preorder[]
*/
public static function searchActive($filter = [], $limit = false, $returnDBRessource = false, $returnArray = false) public static function searchActive($filter = [], $limit = false, $returnDBRessource = false, $returnArray = false)
{ {
if (!is_array($filter)) return false; if (!is_array($filter)) return false;

View File

@@ -52,6 +52,45 @@ class Rimoapi {
return true; return true;
} }
public static function changeHomeSubAddress($apikey, $home_external_id, $subAddress) {
if(!$apikey) return false;
if(!$home_external_id) return false;
$log = mfLoghandler::singleton();
// send request to Rimo Api
$params = [];
$params['apiKey'] = $apikey;
$params['homeId'] = $home_external_id;
$params['subAddress'] = $subAddress;
$ctx_opts = [
'http' => [
'method' => 'PUT',
'header' => 'accept: application/json'
]
];
$qs = http_build_query($params);
$changeSubAddressEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_CHANGE_HOME_SUBADDRESS;
$put_url = $changeSubAddressEp."?".$qs;
$ctx = stream_context_create($ctx_opts);
$log->debug(__METHOD__.": SubAddress Change in Rimo: $put_url");
$response = file_get_contents($put_url, false, $ctx);
$log->debug(__METHOD__.": response: ".print_r($response,true));
if($response === false) {
$log->error("Fehler beim Update der SubAddress in RIMO ".$home_external_id);
return false;
}
$resp_data = json_decode($response);
if(!$resp_data->id) return false;
return true;
}
public static function getFtuData($oaid, $home_external_id) { public static function getFtuData($oaid, $home_external_id) {
//$oaid = $oaid; //$oaid = $oaid;
$log = mfLoghandler::singleton(); $log = mfLoghandler::singleton();