From a1eedf0ad350eb57a3ea939e1b9dc40ac81a126f Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 27 Nov 2025 17:17:18 +0100 Subject: [PATCH] Added FCP update to rimo-import --- scripts/adb-rimo-import/rimo-import.php | 98 +++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/scripts/adb-rimo-import/rimo-import.php b/scripts/adb-rimo-import/rimo-import.php index 9a303741a..4c8e6eb05 100755 --- a/scripts/adb-rimo-import/rimo-import.php +++ b/scripts/adb-rimo-import/rimo-import.php @@ -194,6 +194,7 @@ foreach ($clusters as $cluster_data) { $baseParams = ['apiKey' => $apiToken]; + $epGetBuilding = $apiUrl . RIMO_API_JSON_EP_QUERY_BUILDING; $epGetBuildings = $apiUrl . RIMO_API_JSON_EP_GET_BUILDINGS; $epGetWorkorders = $apiUrl . RIMO_API_JSON_EP_QUERY_WORKORDERS; $epGetService = $apiUrl . RIMO_API_JSON_EP_QUERY_SERVICE; @@ -977,6 +978,103 @@ foreach ($clusters as $cluster_data) { } echo "Cluster $cluster_rimo_id ($cluster_name): $hausnummer_count Buildings; $hausnummer_found_count Buildings verarbeitet; $homes_count Homes verarbeitet.\n"; } + + // get Netzgebiet FCPs + echo "updating FCPs {$adb_netzgebiet->name}\n"; + foreach(\ADBRimoFcp::getAll(["netzgebiet_id" => $adb_netzgebiet->id]) as $fcp) { + if(!$fcp->rimo_id) continue; + $fcp_external_id = $fcp->rimo_id; + + $params = $baseParams; + $params["buildingId"] = $fcp_external_id; + $qs = http_build_query($params); + + $req_url = $epGetBuilding . "?" . $qs; + $req_ctx = stream_context_create($ctxOptsGet); + + $responseText = file_get_contents($req_url, false, $req_ctx); + + if ($responseText === false) { + //echo "Error fetching FCP Building $fcp_external_id in cluster $cluster_rimo_id (" . $cluster->name . ")\n"; + continue; + } + + $buildingResponse = json_decode($responseText); + + $hausnummer_count = 0; + $hausnummer_found_count = 0; + $homes_count = 0; + + $rimo_building_list = []; + + if (!is_object($buildingResponse)) { + continue; + } + + $rimo_fcp = $buildingResponse; + + if(!property_exists($rimo_fcp, "executionState") || !is_object($rimo_fcp->executionState) + || !property_exists($rimo_fcp->executionState, "name") || !property_exists($rimo_fcp->executionState, "userLabel") + ) { + continue; + } + if(!property_exists($rimo_fcp, "operationalState") || !is_object($rimo_fcp->operationalState) + || !property_exists($rimo_fcp->operationalState, "name") || !property_exists($rimo_fcp->operationalState, "userLabel") + ) { + continue; + } + + $fcp_execstate_id = $rimo_fcp->executionState->name; + $fcp_execstate_label = $rimo_fcp->executionState->userLabel; + $fcp_opstate_id = $rimo_fcp->operationalState->name; + $fcp_opstate_label = $rimo_fcp->operationalState->userLabel; + + $fcp_changed = false; + + if($fcp->rimo_ex_state != $fcp_execstate_label) { + $fcp->rimo_ex_state = $fcp_execstate_label; + $fcp_changed = true; + } + if($fcp->rimo_op_state != $fcp_opstate_label) { + $fcp->rimo_op_state = $fcp_opstate_label; + $fcp_changed = true; + } + + if($fcp_changed) { + //var_dump($fcp); + $fcp->update((array)$fcp); + + // see if buildings and preorders need to get flag 141 set + foreach(TT_PREORDER_RIMO_FCP_STATUS_MATRIX as $matrix) { + if(!$matrix["pf"] && !$matrix["hf"]) { + continue; + } + //echo "checking if need to set pf {$matrix["pf"]} or hf {$matrix["hf"]}\n"; + + if(!is_array($matrix["fcpop"])) $matrix["fcpop"] = [$matrix["fcpop"]]; + if(!is_array($matrix["fcpex"])) $matrix["fcpex"] = [$matrix["fcpex"]]; + + if(!in_array(strtolower($fcp->rimo_ex_state), $matrix["fcpex"])) continue; + if(!in_array(strtolower($fcp->rimo_op_state), $matrix["fcpop"])) continue; + + + foreach(\ADBHausnummerModel::search(["fcp_id" => $fcp->id]) as $hausnummer) { + if(array_key_exists("hf", $matrix) && $matrix["hf"]) { + //echo "setting hausnummer {$hausnummer->id} flag {$matrix["hf"]}\n"; + $hausnummer->setStatusflag($matrix["hf"], 1); + } + if(array_key_exists("pf", $matrix) && $matrix["pf"]) { + foreach(\PreorderModel::searchActive(["adb_hausnummer_id" => $hausnummer->id]) as $preorder) { + //echo "setting preorder {$preorder->id} flag {$matrix["pf"]}\n"; + $preorder->setStatusFlag($matrix["pf"], 1); + } + } + } + break; + } + } + } + } //echo $response;