Added Preordertype legacytransfer + moved createWorkorder to Rimoapi

This commit is contained in:
Frank Schubert
2024-11-14 16:07:20 +01:00
parent 0c74af0e9d
commit 1fbccb62c5
10 changed files with 147 additions and 66 deletions
@@ -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;
}
+15 -10
View File
@@ -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();
@@ -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;
@@ -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;
}