From 1fbccb62c52b579800fe717ecb65975572bb7be1 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 14 Nov 2024 16:07:20 +0100 Subject: [PATCH] Added Preordertype legacytransfer + moved createWorkorder to Rimoapi --- Layout/default/Preorder/Form.php | 6 +- .../Preorder/include/preorder-detail.php | 4 +- Layout/default/Preordercampaign/Form.php | 5 +- .../MaintenanceNotification.php | 18 ++++- application/Preorder/PreorderController.php | 25 ++++--- .../Preordercampaign/Preordercampaign.php | 4 +- .../PreordercampaignController.php | 70 ++++++------------- ...1939_preorder_add_type_legacy_transfer.php | 31 ++++++++ lang/de.php | 1 + lib/Rimoapi/Rimoapi.php | 49 +++++++++++++ 10 files changed, 147 insertions(+), 66 deletions(-) create mode 100644 db/migrations/20241114131939_preorder_add_type_legacy_transfer.php diff --git a/Layout/default/Preorder/Form.php b/Layout/default/Preorder/Form.php index 8e82ad06e..9a53e51eb 100644 --- a/Layout/default/Preorder/Form.php +++ b/Layout/default/Preorder/Form.php @@ -49,7 +49,7 @@
- adb_wohneinheit_id && is_array($preorder->adb_wohneinheit->rimo_workorders) && count($preorder->adb_wohneinheit->rimo_workorders)) ? "disabled='disabled'" : ""?>> adb_hausnummer_id): ?> @@ -151,7 +151,7 @@
- adb_wohneinheit_id && is_array($preorder->adb_wohneinheit->rimo_workorders) && count($preorder->adb_wohneinheit->rimo_workorders)) ? "disabled='disabled'" : ""?>> adb_wohneinheit_id): ?> @@ -187,7 +187,9 @@ types)): ?> types)): ?> types)): ?> + types)): ?> types)): ?> +
diff --git a/Layout/default/Preorder/include/preorder-detail.php b/Layout/default/Preorder/include/preorder-detail.php index 5b51b019b..61a45576b 100644 --- a/Layout/default/Preorder/include/preorder-detail.php +++ b/Layout/default/Preorder/include/preorder-detail.php @@ -404,7 +404,9 @@ $wo->id])?>" onclick="event.preventDefault(); downloadWorkorderAha(id?>);"> AHA Blatt (beta) - Workorder löschen + is("Admin")): ?> + Workorder löschen + diff --git a/Layout/default/Preordercampaign/Form.php b/Layout/default/Preordercampaign/Form.php index e617e91cf..47fc8777a 100644 --- a/Layout/default/Preordercampaign/Form.php +++ b/Layout/default/Preordercampaign/Form.php @@ -121,8 +121,9 @@ multiple="multiple" data-placeholder="Bitte auswählen ..."> - - + + + diff --git a/application/MaintenanceNotification/MaintenanceNotification.php b/application/MaintenanceNotification/MaintenanceNotification.php index ec7d130c2..738304980 100644 --- a/application/MaintenanceNotification/MaintenanceNotification.php +++ b/application/MaintenanceNotification/MaintenanceNotification.php @@ -60,19 +60,35 @@ class MaintenanceNotification extends mfBaseModel { $mnlog->save(); } + $this->sent = date("U"); + $this->save(); + + // send to xinon + $mnlog = MaintenanceNotificationLog::getFirst(["maintenancenotification_id" => $this->id, "email" => "internal-email"]); + if($mnlog) { + // was sent already + return true; + } + $to = "wartungsverteiler.team@xinon.at"; $body .= "\n\nPLZ Liste:\n\n"; $body .= implode("\n", $this->getProperty("plzs")); $email = new Emailnotification(); $email->setSubject($subject); - $email->setHtmlBody($body); + $email->setBody($body); $email->setFrom($from, $from_name); $email->setTo($to); $email->setHeader("X-".ucfirst(MFAPPNAME)."-mnid", $this->id); $email->send(); $this->log->info(__METHOD__.": Sending MaintenanceNotification to $to"); + $mnlog = MaintenanceNotificationLog::create([ + "maintenancenotification_id" => $this->id, + "email" => "internal-email", + "sent" => date("U"), + ]); + return true; } diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php index 4f0651449..831350fda 100644 --- a/application/Preorder/PreorderController.php +++ b/application/Preorder/PreorderController.php @@ -381,16 +381,15 @@ class PreorderController extends mfBaseController { $mode = "add"; } - /* - * data colletion - */ - $data = []; - $data['preordercampaign_id'] = $r->campaign_id; - $data['building_id'] = ($r->building_id) ? $r->building_id : null; - $data['adb_hausnummer_id'] = $r->adb_hausnummer_id; - $data['adb_wohneinheit_id'] = ($r->adb_wohneinheit_id) ? $r->adb_wohneinheit_id : null; - $data['termination_id'] = ($r->termination_id) ? $r->termination_id : null; + $data = []; + if($mode == "add" || !$preorder->adb_wohneinheit_id || !is_array($preorder->adb_wohneinheit->rimo_workorders) || !count($preorder->adb_wohneinheit->rimo_workorders)) { + $data['preordercampaign_id'] = $r->campaign_id; + $data['building_id'] = ($r->building_id) ? $r->building_id : null; + $data['adb_hausnummer_id'] = $r->adb_hausnummer_id; + $data['adb_wohneinheit_id'] = ($r->adb_wohneinheit_id) ? $r->adb_wohneinheit_id : null; + $data['termination_id'] = ($r->termination_id) ? $r->termination_id : null; + } $campaign = new Preordercampaign($r->campaign_id); if(!$campaign->id) { @@ -423,6 +422,12 @@ class PreorderController extends mfBaseController { case "order": $data['type'] = "order"; break; + case "reorder": + $data["type"] = "reorder"; + break; + case "legacytransfer": + $data["type"] = "legacytransfer"; + break; } switch($r->connection_type) { @@ -755,7 +760,7 @@ class PreorderController extends mfBaseController { $this->redirect("Preorder", "Index", $qs); } - $preorder->deleted = date('U'); + //$preorder->deleted = date('U'); $preorder->deleted_by = $this->me->id; $preorder->status_id = 23; // 910 - Cancelled (ohne weitere Begründung) $preorder->save(); diff --git a/application/Preordercampaign/Preordercampaign.php b/application/Preordercampaign/Preordercampaign.php index df2f98487..99627ec2c 100644 --- a/application/Preordercampaign/Preordercampaign.php +++ b/application/Preordercampaign/Preordercampaign.php @@ -36,13 +36,13 @@ class Preordercampaign extends mfBaseModel { } public function addTypes(Array $types) { - $allowd_types = ["interest","provision","order","reorder"]; + $allowd_types = ["interest","provision","order","reorder","legacytransfer"]; $new_types = []; foreach($types as $type) { if(!in_array($type, $allowd_types)) { - $this->log->debug("$type not in allowed_types"); + $this->log->debug(__METHOD__.": $type not in allowed_types"); continue; } $new_types[] = $type; diff --git a/application/Preordercampaign/PreordercampaignController.php b/application/Preordercampaign/PreordercampaignController.php index 3b16c3691..a187435bf 100644 --- a/application/Preordercampaign/PreordercampaignController.php +++ b/application/Preordercampaign/PreordercampaignController.php @@ -709,10 +709,10 @@ class PreordercampaignController extends mfBaseController { $preorder->setOrCreateOaid($oaid_attributes); - if($wohneinheit->oaid != $oaid->oaid) { + /*if($wohneinheit->oaid != $oaid->oaid) { $wohneinheit->oaid = $oaid->oaid; $wohneinheit->save(); - } + }*/ $assigned_oaids++; @@ -747,7 +747,7 @@ class PreordercampaignController extends mfBaseController { $this->log->warning(__METHOD__.": workorder_export_date not null"); } - if($preorder->type == "interest") { + if($preorder->type == "interest" || $preorder->type == "legacytransfer") { continue; } @@ -781,57 +781,31 @@ class PreordercampaignController extends mfBaseController { } // create and assign OAID if not yet done $oaid->exportToRimoAndAssignFtu(); - + // create Workorder - $params['apiKey'] = RIMO_API_JSON_APIKEY; - $params["homeId"] = $wohneinheit->extref; - $params["firstName"] = trim($preorder->firstname); - $params["lastName"] = trim($preorder->lastname); - $params["company"] = trim($preorder->company); - $params["phone"] = trim($preorder->phone); - $params["email"] = trim($preorder->email); - $params["orderId"] = $preorder->ucode; - //$params["openAccessId"] = $preorder->oaid; // TODO: flag in campaign to include OAID or not - - $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_WORKORDER; - $post_url = $createOrderEp."?".$qs; - $ctx = stream_context_create($ctx_opts); - $this->log->debug(__METHOD__.": Creating Workorder: $post_url"); - - $response = file_get_contents($post_url, false, $ctx); - - if($response === false) { - echo "Fehler beim Exportieren der Workorder für Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid."\n"; - $workorders_failed++; - continue; - } - //$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("Cannot create RimoWorkorder! Invalid Response! (Preorder code: ".$preorder->ucode.") | Response: \n$response"); - throw new Exception("Cannot create RimoWorkorder! Invalid Response! (Preorder code: ".$preorder->ucode.")"); + $data = []; + $data["firstname"] = trim($preorder->firstname); + $data["lastname"] = trim($preorder->lastname); + $data["company"] = trim($preorder->company); + $data["phone"] = trim($preorder->phone); + $data["email"] = trim($preorder->email); + $data["orderId"] = $preorder->ucode; + + $response = Rimoapi::createWorkorder($wohneinheit->extref, $data); + + if(!$response) { + $this->log->error("Cannot create RimoWorkorder! Invalid Response! (Preorder ucode: ".$preorder->ucode.")"); + throw new Exception("Cannot create RimoWorkorder! Invalid Response! (Preorder ucode: ".$preorder->ucode.")"); } - $rimo_status = $resp_data->status->userLabel; + $rimo_status = $response->status->userLabel; if(!$rimo_status) { $rimo_status = ""; } $wo = RimoWorkorderModel::create([ - "rimo_id" => $resp_data->id, - "rimo_name" => $resp_data->name, + "rimo_id" => $response->id, + "rimo_name" => $response->name, "rimo_status" => $rimo_status, "adb_wohneinheit_id" => $preorder->adb_wohneinheit_id, "create_data" => $response @@ -903,7 +877,7 @@ class PreordercampaignController extends mfBaseController { if(!$preorder->adb_wohneinheit_id) { //echo "Keine Wohneinheit in Preorder (".$preorder->id.") ".$preorder->ucode." ".$preorder->oaid."\n"; - $this->log->debug(__METHOD__.": Ignoring Preorder ".$preorder->id.": missing unit"); + //$this->log->debug(__METHOD__.": Ignoring Preorder ".$preorder->id.": missing unit"); $missing_units++; continue; } @@ -959,7 +933,7 @@ class PreordercampaignController extends mfBaseController { foreach(PreorderModel::searchActive(["preordercampaign_id" => $id, "connection_count" => 1]) as $preorder) { if($preorder->type == "interest") { - $this->log->debug(__METHOD__.": Ignoring Preorder ".$preorder->id.": is interest"); + //$this->log->debug(__METHOD__.": Ignoring Preorder ".$preorder->id.": is interest"); continue; } diff --git a/db/migrations/20241114131939_preorder_add_type_legacy_transfer.php b/db/migrations/20241114131939_preorder_add_type_legacy_transfer.php new file mode 100644 index 000000000..4dcf861bc --- /dev/null +++ b/db/migrations/20241114131939_preorder_add_type_legacy_transfer.php @@ -0,0 +1,31 @@ +getEnvironment() == "thetool") { + $table = $this->table("Preorder"); + $table->changeColumn("type", "enum", ["values" => "interest,provision,order,reorder,legacytransfer"]); + $table->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/lang/de.php b/lang/de.php index b637fbb98..a57d0a599 100644 --- a/lang/de.php +++ b/lang/de.php @@ -47,6 +47,7 @@ $l['preorder.interest'] = "Interessenbekundung"; $l['preorder.provision'] = "Vorsorgeanschluss"; $l['preorder.order'] = "Vollanschluss"; $l['preorder.reorder'] = "Nachbestellung"; +$l['preorder.legacytransfer'] = "Bestandsübernahme"; $l['preorder.single-dwelling'] = "Einfamilienhaus"; $l['preorder.multi-dwelling'] = "Mehrfamilienhaus"; diff --git a/lib/Rimoapi/Rimoapi.php b/lib/Rimoapi/Rimoapi.php index 8c1d3300b..847fcc99a 100644 --- a/lib/Rimoapi/Rimoapi.php +++ b/lib/Rimoapi/Rimoapi.php @@ -181,6 +181,55 @@ class Rimoapi { return $resp_data; } + public static function createWorkorder($home_id, $data = []) { + $log = mfLoghandler::singleton(); + + if(!$home_id) return false; + + $create_fields = [ + "company" => "company", + "firstname" => "firstName", + "lastname" => "lastName", + "phone" => "phone", + "email" => "email", + "orderId" => "orderId" + ]; + + $params = []; + $params['apiKey'] = RIMO_API_JSON_APIKEY; + + $ctx_opts = [ + 'http' => [ + 'method' => 'POST', + 'header' => 'accept: application/json' + ] + ]; + + foreach($data as $field => $value) { + if(array_key_exists($field, $create_fields)) { + $params[$create_fields[$field]] = $value; + } + } + + $params["homeId"] = $home_id; + + $qs = http_build_query($params); + //echo $qs."\n"; + + $createOrderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_CREATE_WORKORDER; + $post_url = $createOrderEp."?".$qs; + $ctx = stream_context_create($ctx_opts); + $log->debug(__METHOD__.": Creating Workorder: $post_url"); + + $response = file_get_contents($post_url, false, $ctx); + + if($response === false) { + return false; + } + + return json_decode($response); + } + public static function updateWorkorder($rimo_id, Array $data = []) { $log = mfLoghandler::singleton();
Name