diff --git a/Layout/default/Dashboard/Dashboard.php b/Layout/default/Dashboard/Dashboard.php
index 04ac15333..3ece4a87a 100644
--- a/Layout/default/Dashboard/Dashboard.php
+++ b/Layout/default/Dashboard/Dashboard.php
@@ -1,4 +1,6 @@
-
-
\ No newline at end of file
+
+log->debug("Rendering Dashboard page took $thetime microseconds");
+?>
\ No newline at end of file
diff --git a/Layout/default/OpenAccessId/ChangeUnit.php b/Layout/default/OpenAccessId/ChangeUnit.php
index e5ff8b8f5..5eb66bd5a 100644
--- a/Layout/default/OpenAccessId/ChangeUnit.php
+++ b/Layout/default/OpenAccessId/ChangeUnit.php
@@ -41,7 +41,7 @@
adb_wohneinheit_id && is_object($oaid->adb_wohneinheit)): ?>
adb_wohneinheit : ""?>"
+ value="[=$oaid->adb_wohneinheit->hausnummer->strasse->gemeinde->name?>] =$oaid->adb_wohneinheit->hausnummer->plz->plz?>=$oaid->adb_wohneinheit->hausnummer->ortschaft->name?>, =$oaid->adb_wohneinheit->hausnummer->strasse->name?> =$oaid->adb_wohneinheit->hausnummer->hausnummer?>=((string)$oaid->adb_wohneinheit) ? " - ".(string)$oaid->adb_wohneinheit : ""?>"
/>
diff --git a/application/Dashboard/DashboardController.php b/application/Dashboard/DashboardController.php
index 1e11ee82f..e3b01677d 100644
--- a/application/Dashboard/DashboardController.php
+++ b/application/Dashboard/DashboardController.php
@@ -11,8 +11,6 @@ class DashboardController extends mfBaseController {
}
protected function indexAction() {
-
-
if($this->me->is("preorderfront")) {
$this->redirect("Preorder");
}
@@ -82,8 +80,8 @@ class DashboardController extends mfBaseController {
$status_connected = PreorderModel::count(["preordercampaign_id" => $campaign_ids, "deleted" => 0, "status_code" => 500]);
$partner_orders = $this->getPartnerOrderCount($campaign_ids);
- $partner_orders_by_status = $this->getPartnerOrdersByStatus($campaign_ids);
-
+ $partner_orders_by_status = $this->getPartnerOrdersByStatus($campaign_ids);
+
$total_orders = $partner_orders["total"];
unset($partner_orders["total"]);
@@ -187,10 +185,10 @@ class DashboardController extends mfBaseController {
$orders[$name] = [];
$orders[$name]["total"] = 0;
}
- if(!array_key_exists($preorder->status_id, $orders[$name])) {
- $orders[$name][$preorder->status_id] = 0;
+ if(!array_key_exists($preorder->status->id, $orders[$name])) {
+ $orders[$name][$preorder->status->id] = 0;
}
- $orders[$name][$preorder->status_id]++;
+ $orders[$name][$preorder->status->id]++;
$orders[$name]["total"]++;
}
//var_dump($orders);exit;
diff --git a/application/OpenAccessId/OpenAccessId.php b/application/OpenAccessId/OpenAccessId.php
index 17e191361..5d00553d0 100644
--- a/application/OpenAccessId/OpenAccessId.php
+++ b/application/OpenAccessId/OpenAccessId.php
@@ -1,5 +1,7 @@
oaid);
+
// XXX for now only support ADB Addresses
if(!$this->adb_wohneinheit_id) {
return true;
@@ -68,7 +72,10 @@ class OpenAccessId extends mfBaseModel {
$unit_extdata = new StdClass();
if($wohneinheit->external_data) {
- $extdata = json_decode($wohneinheit->external_data);
+ $json_data = json_decode($wohneinheit->external_data);
+ if(is_object($json_data)) {
+ $extdata = $json_data;
+ }
if(is_object($extdata)) {
$unit_extdata = $extdata;
@@ -81,39 +88,7 @@ class OpenAccessId extends mfBaseModel {
}
if($fetch_ftu) {
- // query Home to get FTU data from RIMO - GET /queryHomeWithId
- $params['apiKey'] = RIMO_API_JSON_APIKEY;
- $params["homeId"] = $wohneinheit->extref;
-
- $ctx_opts = [
- 'http' => [
- 'method' => 'GET',
- 'header' => 'accept: application/json'
- ]
- ];
-
- $qs = http_build_query($params);
- //echo $qs."\n";
-
- $queryHomeEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_QUERY_HOME;
- $get_url = $queryHomeEp."?".$qs;
- $ctx = stream_context_create($ctx_opts);
- $this->log->debug(__METHOD__.": Getting Home to fetch FTU: $get_url");
- //exit;
- $response = file_get_contents($get_url, false, $ctx);
-
- if($response === false) {
- $this->log->error("Fehler beim auslesen der FTU ".$this->oaid."\n");
- return false;
- }
- //$preorder->workorder_export_date = date('U');
- //$preorder->workorder_export_data = $response;
- //$preorder->save();
- $resp_data = json_decode($response);
- if(!is_object($resp_data)) {
- $this->log->error(__METHOD__.": OAID ".$this->oaid.": Cannot fetch Home from RIMO! Invalid Response!");
- return false;
- }
+ $resp_data = $rimo->getFtuData($wohneinheit->extref);
if(!is_array($resp_data->ftus->item) || !count($resp_data->ftus->item)) {
$this->log->warning(__METHOD__.": Homes ftus object has no items ".$this->oaid);
@@ -140,54 +115,8 @@ class OpenAccessId extends mfBaseModel {
*/
$existing_rimo_export_data = $this->getExportData("rimo");
- if(!is_object($existing_rimo_export_data) || !isset($existing_rimo_export_data->oaid_id) || !isset($existing_rimo_export_data->name)) {
- $params = [];
- $params['apiKey'] = RIMO_API_JSON_APIKEY;
- $params['oaidName'] = $this->oaid;
-
- $ctx_opts = [
- 'http' => [
- 'method' => 'POST',
- 'header' => 'accept: application/json'
- ]
- ];
-
- $qs = http_build_query($params);
- //echo $qs."\n";
-
- $createOrderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_CREATE_OAID;
- $post_url = $createOrderEp."?".$qs;
- $ctx = stream_context_create($ctx_opts);
- $this->log->debug(__METHOD__.": Creating OAID in Rimo: $post_url");
- $response = file_get_contents($post_url, false, $ctx);
- //var_dump($response);exit;
- if($response === false) {
- $this->log->error("Fehler beim Erstellen der OAID in RIMO ".$this->oaid."\n");
- $workorders_failed++;
- return false;
- }
-
- $resp_data = json_decode($response);
- if(!$resp_data->id || !$resp_data->name) {
- $this->log->warning(__METHOD__.": Create OAID returned no ID or oaid name ".$this->oaid);
- return false;
- }
-
- // mark OAID as exported
- $oaid_export_data = new StdClass();
- if($this->export_data) {
- $oaid_export_data = json_decode($this->export_data);
- }
- if(!isset($oaid_export_data->rimo)) {
- $oaid_export_data->rimo = new StdClass();
- }
- $oaid_export_data->rimo->oaid_id = $resp_data->id;
- $oaid_export_data->rimo->name = $resp_data->name;
- $oaid_export_data->rimo->ftu_id = null;
- $this->exported_to = "rimo";
- $this->exported = date('U');
- $this->export_data = json_encode($oaid_export_data);
- $this->save();
+ if(!is_object($existing_rimo_export_data) || (!isset($existing_rimo_export_data->oaid_id) || !$existing_rimo_export_data->oaid_id) || (!isset($existing_rimo_export_data->name) || !$existing_rimo_export_data->name)) {
+ $this->createInRimo();
} else {
$this->log->debug(__METHOD__.": OAID ".$this->oaid.": Already created in RIMO");
@@ -198,68 +127,39 @@ class OpenAccessId extends mfBaseModel {
$ftu_data = $wohneinheit->ftu_data;
if($ftu_data['id'] && $ftu_data['name']) {
- $params = [];
- $params['apiKey'] = RIMO_API_JSON_APIKEY;
+ $resp_data = $rimo->getOaid();
- $ctx_opts = [
- 'http' => [
- 'method' => 'GET',
- 'header' => 'accept: application/json'
- ]
- ];
-
- $qs = http_build_query($params);
- //echo $qs."\n";
-
- $getOaidEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_OAID;
- $getOaidEp .= "/".$this->oaid;
- $get_url = $getOaidEp."?".$qs;
- $ctx = stream_context_create($ctx_opts);
- $this->log->debug(__METHOD__.": Getting OAID from Rimo: $get_url");
- $response = file_get_contents($get_url, false, $ctx);
- //var_dump($response);exit;
- if($response === false) {
- $this->log->error("Fehler beim abfragen der OAID in RIMO ".$this->oaid."\n");
- return false;
+ if(!$resp_data) {
+ // oaid was not found in rimo, try creating it
+ $resp_data = $this->createInRimo();
}
- $resp_data = json_decode($response);
- if($resp_data->terminiationUnit && $resp_data->terminiationUnit->id) {
+ $assign_oaid = false;
+
+ if($resp_data && $resp_data->terminiationUnit && $resp_data->terminiationUnit->id) {
if($ftu_data['id'] != $resp_data->terminiationUnit->id) {
$old_ftu_id = $resp_data->terminiationUnit->id;
-
// unassign oaid from FTU
- $ctx_opts["http"]["method"] = "DELETE";
- $unassignEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_UNASSIGN_OAID_TO_FTU;
- $unassignEp = str_replace("{oaidName}", $this->oaid, $unassignEp);
- $unassignEp = str_replace("{ftuExternalId}", $old_ftu_id, $unassignEp);
+ $resp_data = $rimo->unassignOaid($old_ftu_id);
+ $assign_oaid = true;
- $delete_url = $unassignEp."?".$qs;
- $ctx = stream_context_create($ctx_opts);
- $this->log->debug(__METHOD__.": Unassigning OAID from FTU $old_ftu_id: $delete_url");
- $response = file_get_contents($delete_url, false, $ctx);
-
-
- // assign oaid to Wohneinheit FTU
- $ctx_opts["http"]["method"] = "POST";
- $assignEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_ASSIGN_OAID_TO_FTU;
- $assignEp = str_replace("{oaidName}", $this->oaid, $assignEp);
- $assignEp = str_replace("{ftuExternalId}", $ftu_data['id'], $assignEp);
-
- $post_url = $assignEp."?".$qs;
- $ctx = stream_context_create($ctx_opts);
- $this->log->debug(__METHOD__.": Assigning OAID to current FTU ".$ftu_data['id'].": $post_url");
- $response = file_get_contents($post_url, false, $ctx);
-
- // update OAID export data
- $exp_data_update = json_decode($this->export_data);
- $exp_data_update->rimo->ftu_id = $ftu_data['id'];
- $exp_data_update->rimo->ftu_name = $ftu_data['name'];
- $exp_data_update->rimo->ftu_assigned_date = date("U");
- $this->export_data = json_encode($ext_data_update);
- $this->save();
}
+ } else {
+ $assign_oaid = true;
+ }
+
+ if ($assign_oaid) {
+ // assign oaid to Wohneinheit FTU
+ $resp_data = $rimo->assignOaid($ftu_data['id']);
+
+ // update OAID export data
+ $exp_data_update = json_decode($this->export_data);
+ $exp_data_update->rimo->ftu_id = $ftu_data['id'];
+ $exp_data_update->rimo->ftu_name = $ftu_data['name'];
+ $exp_data_update->rimo->ftu_assigned_date = date("U");
+ $this->export_data = json_encode($exp_data_update);
+ $this->save();
}
}
}
@@ -275,6 +175,7 @@ class OpenAccessId extends mfBaseModel {
// check if we assigned the OAID to a RIMO FTU already
$existing_rimo_export_data = $this->getExportData("rimo");
if(!is_object($existing_rimo_export_data) || !isset($existing_rimo_export_data->oaid_id) || !isset($existing_rimo_export_data->ftu_id)) {
+ /*
$params = [];
$params['apiKey'] = RIMO_API_JSON_APIKEY;
@@ -303,11 +204,16 @@ class OpenAccessId extends mfBaseModel {
$workorders_failed++;
return false;
}
+ */
+ $resp_data = $rimo->assignOaid($unit_extdata->rimo->ftu->id);
// add FTU id to external_data
$oaid_export_data = new StdClass();
if($this->export_data) {
- $oaid_export_data = json_decode($this->export_data);
+ $json_data = json_decode($this->export_data);
+ if(is_object($json_data)) {
+ $oaid_export_data = $json_data;
+ }
}
if(!isset($oaid_export_data->rimo)) {
$oaid_export_data->rimo = new StdClass();
@@ -325,6 +231,36 @@ class OpenAccessId extends mfBaseModel {
return true;
}
+ public function createInRimo() {
+ $rimo = new OpenAccessId_Helper_Rimo($this->oaid);
+
+ $resp_data = $rimo->createOaid();
+ if(!$resp_data) {
+ return false;
+ }
+
+ // mark OAID as exported
+ $oaid_export_data = new StdClass();
+ if($this->export_data) {
+ $json_data = json_decode($this->export_data);
+ if(is_object($json_data)) {
+ $oaid_export_data = $json_data;
+ }
+ }
+ if(!isset($oaid_export_data->rimo)) {
+ $oaid_export_data->rimo = new StdClass();
+ }
+ $oaid_export_data->rimo->oaid_id = $resp_data->id;
+ $oaid_export_data->rimo->name = $resp_data->name;
+ $oaid_export_data->rimo->ftu_id = null;
+ $this->exported_to = "rimo";
+ $this->exported = date('U');
+ $this->export_data = json_encode($oaid_export_data);
+ $this->save();
+
+ return true;
+ }
+
public function importFromCSV(File $file, $attributes = []) {
$active = (int)$attributes['active'];
$origin = $attributes['origin'];
diff --git a/application/OpenAccessId/OpenAccessIdController.php b/application/OpenAccessId/OpenAccessIdController.php
index a5cf3e77c..02857edd6 100644
--- a/application/OpenAccessId/OpenAccessIdController.php
+++ b/application/OpenAccessId/OpenAccessIdController.php
@@ -108,7 +108,9 @@ class OpenAccessIdController extends mfBaseController {
// get old and new unit_id
$old_unit = ADBWohneinheitModel::getFirst(["oaid" => $oaid->oaid]);
$new_unit = new ADBWohneinheit($this->request->new_unit_id);
-
+ if(!$new_unit->id) {
+ $new_unit = false;
+ }
diff --git a/application/OpenAccessId/helper/rimo.php b/application/OpenAccessId/helper/rimo.php
new file mode 100644
index 000000000..c506d91ca
--- /dev/null
+++ b/application/OpenAccessId/helper/rimo.php
@@ -0,0 +1,179 @@
+oaid = $oaid;
+ $this->log = mfLoghandler::singleton();
+ }
+
+ public function getFtuData($home_external_id) {
+ // query Home to get FTU data from RIMO - GET /queryHomeWithId
+ $params = [];
+ $params['apiKey'] = RIMO_API_JSON_APIKEY;
+ $params["homeId"] = $home_external_id;
+
+ $ctx_opts = [
+ 'http' => [
+ 'method' => 'GET',
+ 'header' => 'accept: application/json'
+ ]
+ ];
+
+ $qs = http_build_query($params);
+ //echo $qs."\n";
+
+ $queryHomeEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_QUERY_HOME;
+ $get_url = $queryHomeEp."?".$qs;
+ $ctx = stream_context_create($ctx_opts);
+ $this->log->debug(__METHOD__.": Getting Home to fetch FTU: $get_url");
+ $response = file_get_contents($get_url, false, $ctx);
+
+ if($response === false) {
+ $this->log->error("Fehler beim auslesen der FTU ".$this->oaid."\n");
+ return false;
+ }
+
+ $resp_data = json_decode($response);
+ if(!is_object($resp_data)) {
+ $this->log->error(__METHOD__.": OAID ".$this->oaid.": Cannot fetch Home from RIMO! Invalid Response!");
+ return false;
+ }
+
+ return $resp_data;
+ }
+
+ public function getOaid() {
+ $params = [];
+ $params['apiKey'] = RIMO_API_JSON_APIKEY;
+
+ $ctx_opts = [
+ 'http' => [
+ 'method' => 'GET',
+ 'header' => 'accept: application/json'
+ ]
+ ];
+
+ $qs = http_build_query($params);
+ //echo $qs."\n";
+
+ $getOaidEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_OAID;
+ $getOaidEp .= "/".$this->oaid;
+ $get_url = $getOaidEp."?".$qs;
+ $ctx = stream_context_create($ctx_opts);
+ $this->log->debug(__METHOD__.": Getting OAID from Rimo: $get_url");
+ $response = file_get_contents($get_url, false, $ctx);
+ //var_dump($response);exit;
+ if($response === false) {
+ $this->log->error("Fehler beim abfragen der OAID in RIMO ".$this->oaid."\n");
+ return false;
+ }
+
+ $resp_data = json_decode($response);
+ if(!is_object($resp_data)) {
+ $this->log->error(__METHOD__.": OAID ".$this->oaid.": Cannot fetch OAID from RIMO! Invalid Response!");
+ return false;
+ }
+
+ return $resp_data;
+ }
+
+ public function createOaid() {
+ $params = [];
+ $params['apiKey'] = RIMO_API_JSON_APIKEY;
+ $params['oaidName'] = $this->oaid;
+
+ $ctx_opts = [
+ 'http' => [
+ 'method' => 'POST',
+ 'header' => 'accept: application/json'
+ ]
+ ];
+
+ $qs = http_build_query($params);
+ //echo $qs."\n";
+
+ $createOrderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_CREATE_OAID;
+ $post_url = $createOrderEp."?".$qs;
+ $ctx = stream_context_create($ctx_opts);
+ $this->log->debug(__METHOD__.": Creating OAID in Rimo: $post_url");
+ $response = file_get_contents($post_url, false, $ctx);
+ //var_dump($response);exit;
+ if($response === false) {
+ $this->log->error("Fehler beim Erstellen der OAID in RIMO ".$this->oaid."\n");
+ return false;
+ }
+
+ $resp_data = json_decode($response);
+ if(!$resp_data->id || !$resp_data->name) {
+ $this->log->warning(__METHOD__.": Create OAID returned no ID or oaid name ".$this->oaid);
+ return false;
+ }
+
+ return $resp_data;
+ }
+
+ public function unassignOaid($ftu_external_id) {
+ $params = [];
+ $params['apiKey'] = RIMO_API_JSON_APIKEY;
+
+ $ctx_opts = [
+ 'http' => [
+ 'method' => 'DELETE',
+ 'header' => 'accept: application/json'
+ ]
+ ];
+
+ $qs = http_build_query($params);
+
+ $unassignEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_UNASSIGN_OAID_TO_FTU;
+ $unassignEp = str_replace("{oaidName}", $this->oaid, $unassignEp);
+ $unassignEp = str_replace("{ftuExternalId}", $ftu_external_id, $unassignEp);
+
+ $delete_url = $unassignEp."?".$qs;
+ $ctx = stream_context_create($ctx_opts);
+ $this->log->debug(__METHOD__.": Unassigning OAID from FTU $ftu_external_id: $delete_url");
+ $response = file_get_contents($delete_url, false, $ctx);
+
+ if($response === false) {
+ $this->log->error("Fehler beim Unassignen der OAID in RIMO ".$this->oaid.": $delete_url\n");
+ return false;
+ }
+
+ $resp_data = json_decode($response);
+ return $resp_data;
+ }
+
+ public function assignOaid($ftu_external_id) {
+ $params = [];
+ $params['apiKey'] = RIMO_API_JSON_APIKEY;
+
+ $ctx_opts = [
+ 'http' => [
+ 'method' => 'POST',
+ 'header' => 'accept: application/json'
+ ]
+ ];
+
+ $qs = http_build_query($params);
+
+ $assignEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_ASSIGN_OAID_TO_FTU;
+ $assignEp = str_replace("{oaidName}", $this->oaid, $assignEp);
+ $assignEp = str_replace("{ftuExternalId}", $ftu_external_id, $assignEp);
+
+ $post_url = $assignEp."?".$qs;
+ $ctx = stream_context_create($ctx_opts);
+ $this->log->debug(__METHOD__.": Assigning OAID to current FTU $ftu_external_id: $post_url");
+ $response = file_get_contents($post_url, false, $ctx);
+
+ if($response === false) {
+ $this->log->error("Fehler beim Assignen der OAID ".$this->oaid." in RIMO ".$this->oaid."\n");
+ return false;
+ }
+
+ $resp_data = json_decode($response);
+ return $resp_data;
+ }
+}
\ No newline at end of file