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

View File

@@ -49,7 +49,7 @@
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="adb_hausnummer_id">Adresse *</label>
<div class="col-lg-10">
<select class="form-control" name="adb_hausnummer_id" id="adb_hausnummer_id" />
<select class="form-control" name="adb_hausnummer_id" id="adb_hausnummer_id" <?=($preorder && $preorder->adb_wohneinheit_id && is_array($preorder->adb_wohneinheit->rimo_workorders) && count($preorder->adb_wohneinheit->rimo_workorders)) ? "disabled='disabled'" : ""?>>
<?php if($preorder->adb_hausnummer_id): ?>
<option value="<?=$preorder->adb_hausnummer_id?>" selected="selected"><?=$preorder->adb_hausnummer->plz->plz?> <?=$preorder->adb_hausnummer->strasse->ortschaft->name?>, <?=$preorder->adb_hausnummer->strasse->name?> <?=$preorder->adb_hausnummer->hausnummer?></option>
<?php endif; ?>
@@ -151,7 +151,7 @@
<div class="form-group row" id="wohneinheit_row">
<label class="col-lg-2 col-form-label" for="adb_wohneinheit_id">Wohneinheit *</label>
<div class="col-lg-10">
<select class="form-control" name="adb_wohneinheit_id" id="adb_wohneinheit_id" />
<select class="form-control" name="adb_wohneinheit_id" id="adb_wohneinheit_id" <?=($preorder && $preorder->adb_wohneinheit_id && is_array($preorder->adb_wohneinheit->rimo_workorders) && count($preorder->adb_wohneinheit->rimo_workorders)) ? "disabled='disabled'" : ""?>>
<?php if($preorder->adb_wohneinheit_id): ?>
<option value="<?=$preorder->adb_wohneinheit_id?>" selected="selected"><?=$preorder->adb_hausnummer->strasse->name?> <?=$preorder->adb_hausnummer->hausnummer?> <?=$preorder->adb_wohneinheit?><?=($preorder->adb_wohneinheit->extref) ? " (".$preorder->adb_wohneinheit->extref.")" : ""?></option>
<?php endif; ?>
@@ -187,7 +187,9 @@
<?php if(array_key_exists("interest", $campaign->types)): ?><option value="interest" <?=($preorder->type == "interest") ? "selected='selected'" : ""?>>Interessensbekundung</option><?php endif; ?>
<?php if(array_key_exists("provision", $campaign->types)): ?><option value="provision" <?=($preorder->type == "provision") ? "selected='selected'" : ""?>>Vorsorgeanschluss</option><?php endif; ?>
<?php if(array_key_exists("order", $campaign->types)): ?><option value="order" <?=($preorder->type == "order") ? "selected='selected'" : ""?>>Vollanschluss</option><?php endif; ?>
<?php if(array_key_exists("legacytransfer", $campaign->types)): ?><option value="legacytransfer" <?=($preorder->type == "legacytransfer") ? "selected='selected'" : ""?>>Bestandsübernahme</option><?php endif; ?>
<?php if(array_key_exists("reorder", $campaign->types)): ?><option value="reorder" <?=($preorder->type == "reorder") ? "selected='selected'" : ""?>>Nachbestellung</option><?php endif; ?>
</select>
</div>
</div>

View File

@@ -404,7 +404,9 @@
<a href="<?=self::getUrl("RimoWorkorder", "downloadAh", ["id" => $wo->id])?>" onclick="event.preventDefault(); downloadWorkorderAha(<?=$wo->id?>);"><i class="fas fa-fw fa-file-download ml-2"></i> AHA Blatt</a>
<small class="text-danger">(beta)</small>
</h4>
<small id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>-del"><a href="#" onclick="if(confirm('Achtung: Löscht die Workorder in thetool, aber NICHT in RIMO!')) return deleteWorkorder(<?=$preorder->id?>, <?=$wo->id?>)" class="text-danger"><i class="far fa-times-circle"></i> Workorder löschen</a></small>
<?php if($me->is("Admin")): ?>
<small id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>-del"><a href="#" onclick="if(confirm('Achtung: Löscht die Workorder in thetool, aber NICHT in RIMO!')) return deleteWorkorder(<?=$preorder->id?>, <?=$wo->id?>)" class="text-danger"><i class="far fa-times-circle"></i> Workorder löschen</a></small>
<?php endif; ?>
<table class="table table-sm table-striped" id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>">
<tr>
<th>Name</th>

View File

@@ -121,8 +121,9 @@
multiple="multiple" data-placeholder="Bitte auswählen ...">
<option value="interest" <?= (is_array($campaign->types) && array_key_exists("interest", $campaign->types)) ? "selected='selected'" : "" ?>><?= __("interest", "preorder") ?></option>
<option value="provision" <?= (is_array($campaign->types) && array_key_exists("provision", $campaign->types)) ? "selected='selected'" : "" ?>><?= __("provision", "preorder") ?></option>
<option value="order" <?= (is_array($campaign->types) && array_key_exists("order", $campaign->types)) ? "selected='selected'" : "netowner" ?>><?= __("order", "preorder") ?></option>
<option value="reorder" <?= (is_array($campaign->types) && array_key_exists("reorder", $campaign->types)) ? "selected='selected'" : "netowner" ?>><?= __("reorder", "preorder") ?></option>
<option value="order" <?= (is_array($campaign->types) && array_key_exists("order", $campaign->types)) ? "selected='selected'" : "" ?>><?= __("order", "preorder") ?></option>
<option value="reorder" <?= (is_array($campaign->types) && array_key_exists("reorder", $campaign->types)) ? "selected='selected'" : "" ?>><?= __("reorder", "preorder") ?></option>
<option value="legacytransfer" <?= (is_array($campaign->types) && array_key_exists("legacytransfer", $campaign->types)) ? "selected='selected'" : "" ?>><?= __("legacytransfer", "preorder") ?></option>
</select>
</div>
</div>

View File

@@ -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;
}

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();

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class PreorderAddTypeLegacyTransfer extends AbstractMigration
{
public function up(): void
{
if($this->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") {
}
}
}

View File

@@ -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";

View File

@@ -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();