OAID / Rimo Workorder update:
- OAIDs are now auto assigned to preorders/wohneinheiten on save - OAIDs can be exported to rimo via Preorder Admin functions - Preorder admin function createWorkorder automatically creates, exports and assigns OAIDs
This commit is contained in:
@@ -114,9 +114,9 @@
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="oan_id">OAN ID</label>
|
||||
<label class="col-lg-2 col-form-label" for="oaid">OAID</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="oan_id" id="oan_id" value="<?=$building->oan_id?>" />
|
||||
<input type="text" class="form-control" name="oaid" id="oaid" value="<?=$building->oaid?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
<th>POP</th>
|
||||
<th>Typ</th>
|
||||
<th>Objekt ID</th>
|
||||
<th>OAN ID</th>
|
||||
<th>OAID</th>
|
||||
<th>Adresse</th>
|
||||
<th>Einheiten</th>
|
||||
<th>Status</th>
|
||||
@@ -155,7 +155,7 @@
|
||||
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->pop->name?></td>
|
||||
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->type->name?></td>
|
||||
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->code?></td>
|
||||
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->oan_id?></td>
|
||||
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->oaid?></td>
|
||||
<td onclick="toggleBuilding(<?=$building->id?>)">
|
||||
<?=$building->street?><br />
|
||||
<?=$building->zip?> <?=$building->city?>
|
||||
|
||||
@@ -150,7 +150,14 @@
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?=($oaid->assigned) ? date("d.m.Y H:i",$oaid->assigned) : ""?></td>
|
||||
<td><?=($oaid->exported_to) ? $oaid->exported_to : ""?></td>
|
||||
<td>
|
||||
<?php if($oaid->exported_to): ?>
|
||||
[<?=$oaid->exported_to?>]
|
||||
<?php $ed = $oaid->getExportData($oaid->exported_to); if($ed): ?>
|
||||
<?=($ed->ftu_id) ? $ed->ftu_id : ""?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?=($oaid->exported) ? date("d.m.Y H:i", $oaid->exported) : ""?></td>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<!--a href="<?=self::getUrl("OpenAccessId", "edit", ["id" => $oaid->id])?>"><i class="far fa-edit" title="OAID Bearbeiten"></i></a-->
|
||||
|
||||
@@ -77,23 +77,34 @@
|
||||
<option value="order" <?=(isset($filter) && array_key_exists("type", $filter) && in_array("order", $filter['type'])) ? "selected='selected'" : ""?>>Vollanschluss</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_addon_services">Zusatzdienste</label>
|
||||
<select name="filter[addon_services]" id="filter_addon_services" class="form-control">
|
||||
<option></option>
|
||||
<option value="1" <?=(array_key_exists("addon_services", $filter) && $filter['addon_services'] == 1) ? "selected='selected'" : ""?>>Nur mit Zusatzdiensten</option>
|
||||
<option value="1" <?=(isset($filter['addon_services']) && $filter['addon_services'] == 1) ? "selected='selected'" : ""?>>Nur mit Zusatzdiensten</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_ucode">Bestellcode</label>
|
||||
<input type="text" class="form-control" name="filter[ucode]" id="filter_ucode" value="<?=$filter['ucode'] ?? ""?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_oaid">OAID</label>
|
||||
<input type="text" class="form-control" name="filter[oaid]" id="filter_oaid" value="<?=$filter['oaid'] ?? ""?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_address">Anschlussadresse</label>
|
||||
<input type="text" class="form-control" name="filter[address]" id="filter_address" value="<?=$filter['address']?>" />
|
||||
<input type="text" class="form-control" name="filter[address]" id="filter_address" value="<?=$filter['address'] ?? ""?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_kunde">Kunde</label>
|
||||
<input type="text" class="form-control" name="filter[kunde]" id="filter_kunde" value="<?=$filter['kunde']?>" />
|
||||
<input type="text" class="form-control" name="filter[kunde]" id="filter_kunde" value="<?=$filter['kunde'] ?? ""?>" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -117,7 +128,7 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_connection_count">Anzahl Anschlüsse</label>
|
||||
<select name="filter[connection_count]" id="filter_connection_count" class="form-control">
|
||||
<option value=""></option>
|
||||
@@ -218,16 +229,15 @@
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<?php if(!$me->is("preorderfront")): ?><th>Kampagne</th><?php endif; ?>
|
||||
<th>Bestelltyp</th>
|
||||
<th>Bestelltyp<br />Bestellcode</th>
|
||||
<th>Status</th>
|
||||
<th>Anschlussadresse</th>
|
||||
<th>Anschlüsse</th>
|
||||
<th>Anschlüsse<br />OAID</th>
|
||||
<th>Kunde</th>
|
||||
<th>Kontakt</th>
|
||||
<th>Partner</th>
|
||||
<th>Attribute</th>
|
||||
<th>Erstellt</th>
|
||||
<th>Zuletzt bearbeitet</th>
|
||||
<th>Erstellt<br />Bearbeitet</th>
|
||||
<?php if($me->is(["Admin","netowner"]) && $campaign->fulfillment == "rimo"): ?>
|
||||
<th></th>
|
||||
<?php endif; ?>
|
||||
@@ -236,7 +246,10 @@
|
||||
<?php foreach($preorders as $preorder): ?>
|
||||
<tr>
|
||||
<?php if(!$me->is("preorderfront")): ?><td><?=$preorder->campaign->name?></td><?php endif; ?>
|
||||
<td><?=__($preorder->type, "preorder")?></td>
|
||||
<td>
|
||||
<?=__($preorder->type, "preorder")?><br />
|
||||
<?=$preorder->ucode?>
|
||||
</td>
|
||||
<td>Aufgenommen</td>
|
||||
<?php if($preorder->building_id): ?>
|
||||
<td><?=$preorder->building->street?><br /><?=$preorder->building->zip?> <?=$preorder->building->city?></td>
|
||||
@@ -252,7 +265,10 @@
|
||||
<?php else: ?>
|
||||
<td></td>
|
||||
<?php endif; ?>
|
||||
<td><?=($preorder->connection_count) ? $preorder->connection_count : 1?></td>
|
||||
<td>
|
||||
<?=($preorder->connection_count) ? $preorder->connection_count : 1?><br />
|
||||
<span class="text-pink"><?=$preorder->oaid?></span>
|
||||
</td>
|
||||
<td>
|
||||
<?=($preorder->company) ? $preorder->company : $preorder->firstname." ".$preorder->lastname?><br />
|
||||
<?=$preorder->street?><?=($preorder->housenumber) ? " ".$preorder->housenumber : ""?><br />
|
||||
@@ -268,10 +284,13 @@
|
||||
<label><input type="checkbox" name="attributes_bep_specified" id="attributes_bep_specified-<?=$preorder->id?>" data-preorder-id="<?=$preorder->id?>" value="1" <?=(is_array($preorder->attribute) && array_key_exists("bep_specified", $preorder->attribute) && $preorder->attribute["bep_specified"]) ? "checked='checked'" : ""?> /> Borderpoint festgelegt</label><br />
|
||||
<label><input type="checkbox" name="attributes_inhouse_cabling_supplied" id="attributes_inhouse_cabling_supplied-<?=$preorder->id?>" data-preorder-id="<?=$preorder->id?>" value="1" <?=(is_array($preorder->attribute) && array_key_exists("inhouse_cabling_supplied", $preorder->attribute) && $preorder->attribute["inhouse_cabling_supplied"]) ? "checked='checked'" : ""?> /> Starterpaket erhalten</label>
|
||||
</td>
|
||||
<td><?=date('d.m.Y H:i', $preorder->create)?></td>
|
||||
<td id="update-<?=$preorder->id?>"><?=date('d.m.Y H:i', $preorder->edit)?></td>
|
||||
<td style="white-space: nowrap" class="text-monospace">
|
||||
<?=date('d.m.Y H:i', $preorder->create)?><br />
|
||||
<span id="update-<?=$preorder->id?>"><?=date('d.m.Y H:i', $preorder->edit)?></span>
|
||||
</td>
|
||||
|
||||
<?php if($me->is(["Admin", "netowner"]) && $campaign->fulfillment == "rimo"): ?>
|
||||
<td><?php if ($preorder->workorder_export_date):?><i class="fas fa-r" title="Rimo Workorder erstellt"></i><?php endif; ?></td>
|
||||
<td><?php if($preorder->adb_wohneinheit_id && is_object($preorder->adb_wohneinheit->rimo_workorder)):?><i class="fas fa-r" title="Rimo Workorder erstellt"></i><?php endif; ?></td>
|
||||
<?php endif; ?>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<?php if(!$me->is("preorderfront")): ?>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<div class="col-10">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Workorders erstellen für Vorbestellungen, für die noch keine Workorders erstellt wurden:<br />
|
||||
Workorders erstellen für Vorbestellungen, für die noch keine Workorders erstellt wurden. Exportiert OAID und weist sie FTU zu wenn benötigt:
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-1">
|
||||
@@ -42,23 +42,63 @@
|
||||
|
||||
|
||||
</div>
|
||||
<?php if($missing_extref_count || $failed_count): ?>
|
||||
<div class="row justify-content-end mt-2">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4>OAIDs in Rimo Home/FTU exportieren</h4>
|
||||
<div class="row justify-content-end">
|
||||
<div class="col-10">
|
||||
<div class="alert alert-warning">
|
||||
<?php if($missing_extref_count): ?>
|
||||
<?=$missing_extref_count?> Wohneinheiten ohne extref (SDIHome_...)<br />
|
||||
<?php endif; ?>
|
||||
<?php if($failed_count): ?>
|
||||
<?=$failed_count?> Workorders konnten nicht erstellt werden.
|
||||
<?php endif; ?>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Exportiert OAIDs nach Rimo und weist sie den FTUs der Homes zu:
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-1">
|
||||
<div class="col">
|
||||
<a href="<?=self::getUrl("Preordercampaign","exportOaidsToRimo", ["id" => $campaign->id])?>" class="btn btn-primary"><i class="far fa-r"></i> <i class="far fa-fw fa-link-simple"></i> OAIDs zu Homes/FTUs setzen</a><br />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4>OAIDs vergeben</h4>
|
||||
<div class="row justify-content-end">
|
||||
<div class="col-10">
|
||||
<div class="row mb-2">
|
||||
<div class="col">
|
||||
Vergibt fehlende OAIDs für Wohneinheiten und Vorbestellungen mit zugewiesener Wohneinheit
|
||||
aus OAID-Pool des Netzinhabers mit in Kampagne definierter Herkunft:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="post" action="<?=self::getUrl("Preordercampaign", "assignOpenAccessIdsToPreorders")?>">
|
||||
<input type="hidden" name="id" value="<?=$campaign->id?>" />
|
||||
<div class="form-group">
|
||||
<label for="origin_id">OAIDs aus Set (optional): </label>
|
||||
<input type="text" class="form-control" name="origin_id" id="origin_id" />
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary"><i class="far fa-fw fa-link-simple"></i> Fehlende Preorder-OAIDs vergeben</button><br />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -118,6 +118,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="oaid_origin">OAID Herkunft *</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="form-control" name="oaid_origin" id="oaid_origin" data-placeholder="Bitte auswählen ...">
|
||||
<option value="thetool" <?=($campaign->oaid_origin == "thetool") ? "selected='selected'" : ""?>>thetool</option>
|
||||
<option value="ofaa" <?=($campaign->oaid_origin == "ofaa") ? "selected='selected'" : ""?>>OFAA</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -50,12 +50,12 @@
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_name">Name</label>
|
||||
<input type="text" class="form-control" name="filter[name]" id="filter_name" value="<?=$filter['name']?>" />
|
||||
<input type="text" class="form-control" name="filter[name]" id="filter_name" value="<?=$filter['name'] ?? ""?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_area">Gebiet</label>
|
||||
<input type="text" class="form-control" name="filter[area]" id="filter_area" value="<?=$filter['area']?>" />
|
||||
<input type="text" class="form-control" name="filter[area]" id="filter_area" value="<?=$filter['area'] ?? ""?>" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -40,6 +40,15 @@ class ADBHausnummer extends mfBaseModel {
|
||||
return $data;
|
||||
}*/
|
||||
|
||||
public function getAddress() {
|
||||
$address = "[".$this->getProperty("strasse")->gemeinde->name."]";
|
||||
$address .= " ".$this->getProperty("plz")->plz;
|
||||
$address .= " ".$this->getProperty("ortschaft")->name.",";
|
||||
$address .= " ".$this->getProperty("strasse")->name;
|
||||
$address .= " ".$this->hausnummer;
|
||||
return $address;
|
||||
}
|
||||
|
||||
public function getNewOAID() {
|
||||
if(!$this->plz_id) {
|
||||
return false;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
class ADBWohneinheit extends mfBaseModel {
|
||||
private $hausnummer;
|
||||
private $rimo_workorder;
|
||||
|
||||
protected function init() {
|
||||
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
@@ -167,6 +168,11 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
$this->hausnummer = new ADBHausnummer($this->hausnummer_id);
|
||||
return $this->hausnummer;
|
||||
}
|
||||
|
||||
if($name == "rimo_workorder") {
|
||||
$this->rimo_workorder = RimoWorkorderModel::getFirst(['adb_wohneinheit_id' => $this->id]);
|
||||
return $this->rimo_workorder;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
|
||||
@@ -821,7 +821,7 @@ class AddressDBController extends mfBaseController {
|
||||
$u['street'] = $building->strasse . " ".$building->hausnummer;
|
||||
$u['zip'] = $building->plz;
|
||||
$u['city'] = $building->ortschaft;
|
||||
$u['oan_id'] = ($building->oan_id) ? $building->oan_id : "";
|
||||
$u['oaid'] = ($building->oaid) ? $building->oan_oaid : "";
|
||||
$u['code'] = ($building->code) ? $building->code : "";
|
||||
$u['units'] = ($building->units) ? $building->units : 1;
|
||||
//$u['units_used'] = $building->getUsedTerminationCount(true);
|
||||
|
||||
@@ -285,6 +285,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
if(array_key_exists(2, $m)) {
|
||||
$request_oaid_unit = "$request_oaid_hausnummer".$m[2];
|
||||
}
|
||||
} elseif(strlen($request_oaid) == 8) {
|
||||
$request_oaid_hausnummer = $request_oaid;
|
||||
$request_oaid_unit = $request_oaid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,9 +385,23 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
$res = $this->db()->select("view_hausnummer", "*", $where);
|
||||
if(!$this->db()->num_rows($res)) {
|
||||
// search for oaid in wohneinheit
|
||||
$hausnummer_unit = ADBWohneinheitModel::getFirst(["oaid" => $request_oaid_hausnummer]);
|
||||
if($hausnummer_unit) {
|
||||
$hausnummer_id = $hausnummer_unit->hausnummer_id;
|
||||
$where = "hausnummer_id=$hausnummer_id";
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(',', $this->filter_salescluster_ids).")";
|
||||
}
|
||||
$res = $this->db()->select("view_hausnummer", "*", $where);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$this->db()->num_rows($res)) {
|
||||
return mfResponse::NotFound(["message" => "OAID not found"]);
|
||||
}
|
||||
|
||||
$address = $this->db()->fetch_object($res);
|
||||
} else {
|
||||
$where = "1=1 ";
|
||||
@@ -810,7 +827,14 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$preorder = PreorderModel::create($preorder_data);
|
||||
$preorder->createUcode();
|
||||
//var_dump($preorder);exit;
|
||||
$preorder_id = $preorder->save();
|
||||
try {
|
||||
$preorder_id = $preorder->save();
|
||||
} catch (\Exception $e) {
|
||||
$err_id = uniqid('err');
|
||||
$this->log->error(__METHOD__.": [$err_id] Caught Exception while saving Preorder: ".$e->getMessage()."\n".$e->getTraceAsString());
|
||||
if($unit_changed) $unit->rollbackTransaction();
|
||||
return mfResponse::InternalServerError(["error_id" => $err_id, "message" => "error id: $err_id"]);
|
||||
}
|
||||
|
||||
if(!$preorder_id || !$preorder->ucode) {
|
||||
if($unit_changed) $unit->rollbackTransaction();
|
||||
|
||||
@@ -204,7 +204,7 @@ class BuildingController extends mfBaseController {
|
||||
$data['lineworker_id'] = ($r->lineworker_id) ? $r->lineworker_id : null;
|
||||
$data['networksection_id'] = ($r->networksection_id) ? $r->networksection_id : null;
|
||||
|
||||
$data['oan_id'] = trim($r->oan_id);
|
||||
$data['oaid'] = trim($r->oaid);
|
||||
$data['street'] = trim($r->street);
|
||||
$data['zip'] = trim($r->zip);
|
||||
$data['city'] = trim($r->city);
|
||||
@@ -299,8 +299,8 @@ class BuildingController extends mfBaseController {
|
||||
if($building->lineworker_id) {
|
||||
$data['lineworker_id'] = $building->lineworker_id;
|
||||
}*/
|
||||
if($building->oan_id) {
|
||||
$data['oan_id'] = $building->oan_id. "." . sprintf("%03d", $i);
|
||||
if($building->oaid) {
|
||||
$data['oaid'] = $building->oaid. "." . sprintf("%03d", $i);
|
||||
}
|
||||
|
||||
$term = TerminationModel::create($data);
|
||||
@@ -440,7 +440,7 @@ class BuildingController extends mfBaseController {
|
||||
foreach(BuildingModel::search(['network_id' => $network_id, 'code' => $search]) as $b) {
|
||||
$buildings[$b->id] = $b;
|
||||
}
|
||||
foreach(BuildingModel::search(['network_id' => $network_id, 'oan_id' => $search]) as $b) {
|
||||
foreach(BuildingModel::search(['network_id' => $network_id, 'oaid' => $search]) as $b) {
|
||||
$buildings[$b->id] = $b;
|
||||
}
|
||||
foreach(BuildingModel::search(['network_id' => $network_id, 'zip' => $search]) as $b) {
|
||||
@@ -458,7 +458,7 @@ class BuildingController extends mfBaseController {
|
||||
$u['street'] = $building->street;
|
||||
$u['zip'] = $building->zip;
|
||||
$u['city'] = $building->city;
|
||||
$u['oan_id'] = $building->oan_id;
|
||||
$u['oaid'] = $building->oaid;
|
||||
$u['code'] = $building->code;
|
||||
$u['units'] = ($building->units) ? $building->units : 1;
|
||||
$u['units_used'] = $building->getUsedTerminationCount(true);
|
||||
|
||||
@@ -9,7 +9,7 @@ class BuildingModel {
|
||||
public $lineworker_id = null;
|
||||
public $networksection_id = null;
|
||||
public $code = null;
|
||||
public $oan_id = null;
|
||||
public $oaid = null;
|
||||
public $street = null;
|
||||
public $zip = null;
|
||||
public $city = null;
|
||||
@@ -215,10 +215,10 @@ class BuildingModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("oan_id", $filter)) {
|
||||
$oan_id = FronkDB::singleton()->escape($filter['oan_id']);
|
||||
if($oan_id) {
|
||||
$where .= " AND Building.`oan_id` like '%$oan_id%'";
|
||||
if(array_key_exists("oaid", $filter)) {
|
||||
$oaid = FronkDB::singleton()->escape($filter['oaid']);
|
||||
if($oaid) {
|
||||
$where .= " AND Building.`oaid` like '%$oaid%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,248 @@ class OpenAccessId extends mfBaseModel {
|
||||
private $adb_wohneinheit;
|
||||
private $termination;
|
||||
|
||||
public function loadRandomUnassigned() {
|
||||
public function loadRandomUnassigned($attributes = []) {
|
||||
$where = "active = 1 AND assigned = 0 AND adb_wohneinheit_id IS NULL AND termination_id IS NULL AND exported = 0 AND exported_to IS NULL";
|
||||
|
||||
if(array_key_exists("owner_id", $attributes) && $attributes['owner_id']) {
|
||||
$owner_id = (int)$attributes['owner_id'];
|
||||
if(!$owner_id) {
|
||||
throw new Exception("Besitzer muss eine Zahl sein");
|
||||
}
|
||||
$where .= " AND owner_id = $owner_id";
|
||||
}
|
||||
|
||||
if(array_key_exists("origin", $attributes) && $attributes['origin']) {
|
||||
$origin = $attributes['origin'];
|
||||
if(!OpenAccessIdModel::getFirst(["origin" => $origin])) {
|
||||
throw new Exception("Origin '$origin' not found!");
|
||||
}
|
||||
$where .= " AND origin = '$origin'";
|
||||
}
|
||||
|
||||
if(array_key_exists("origin_id", $attributes) && $attributes['origin_id']) {
|
||||
$origin_id = $attributes['origin_id'];
|
||||
if(!OpenAccessIdModel::getFirst(["origin_id" => $origin_id])) {
|
||||
throw new Exception("OAID Set '$origin_id' not found!");
|
||||
}
|
||||
$where .= " AND origin_id = '$origin_id'";
|
||||
}
|
||||
|
||||
//var_dump($where);exit;
|
||||
$res = $this->db->select("OpenAccessId", "*", "$where ORDER BY RAND() LIMIT 1");
|
||||
|
||||
if(!$this->db->num_rows($res)) {
|
||||
throw new Exception("Konnte keine zufällige freie OAID laden!");
|
||||
}
|
||||
$data = $this->db->fetch_object($res);
|
||||
$this->load($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function exportToRimoAndAssignFtu() {
|
||||
// XXX for now only support ADB Addresses
|
||||
if(!$this->adb_wohneinheit_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* check Wohneinheit external data for FTU id (SDMMaterial_), or fetch it from RIMO
|
||||
*/
|
||||
|
||||
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
|
||||
if(!$wohneinheit->id || !$wohneinheit->extref) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fetch_ftu = true;
|
||||
$unit_extdata = new StdClass();
|
||||
|
||||
if($wohneinheit->external_data) {
|
||||
$extdata = json_decode($wohneinheit->external_data);
|
||||
|
||||
if(is_object($extdata)) {
|
||||
$unit_extdata = $extdata;
|
||||
}
|
||||
|
||||
if(is_object($extdata) && isset($extdata->rimo) && isset($extdata->rimo->ftu->id)) {
|
||||
//var_dump($extdata);exit;
|
||||
$fetch_ftu = false;
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
$createOrderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_QUERY_HOME;
|
||||
$get_url = $createOrderEp."?".$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;
|
||||
}
|
||||
|
||||
if(!is_array($resp_data->ftus->item) || !count($resp_data->ftus->item)) {
|
||||
$this->log->warning(__METHOD__.": Homes ftus object has no items ".$this->oaid);
|
||||
return false;
|
||||
}
|
||||
|
||||
$ftu_data = new StdClass();
|
||||
$ftu_data->id = $resp_data->ftus->item[0]->id;
|
||||
$ftu_data->name = $resp_data->ftus->item[0]->name;
|
||||
|
||||
if(!isset($unit_extdata->rimo)) {
|
||||
$unit_extdata->rimo = new StdClass();
|
||||
}
|
||||
|
||||
$unit_extdata->rimo->ftu = $ftu_data;
|
||||
$wohneinheit->external_data = json_encode($unit_extdata);
|
||||
$wohneinheit->save();
|
||||
} else { // $fetch_ftu == true
|
||||
$this->log->debug(__METHOD__.": OAID ".$this->oaid.": Home FTU id known already");
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* check if we have RIMO OAID data or create OAID in RIMO - POST /v1/oaid-management/oaids
|
||||
*/
|
||||
|
||||
$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();
|
||||
} else {
|
||||
$this->log->debug(__METHOD__.": OAID ".$this->oaid.": Already created in RIMO");
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* assign OAID to FTU - POST /v1/oaid-management/oaids/{oaidName}/ftu/{ftuExternalId}
|
||||
*/
|
||||
|
||||
// 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;
|
||||
|
||||
$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_ASSIGN_OAID_TO_FTU;
|
||||
$createOrderEp = str_replace("{oaidName}", $this->oaid, $createOrderEp);
|
||||
$createOrderEp = str_replace("{ftuExternalId}", $unit_extdata->rimo->ftu->id, $createOrderEp);
|
||||
$post_url = $createOrderEp."?".$qs;
|
||||
|
||||
$ctx = stream_context_create($ctx_opts);
|
||||
$this->log->debug(__METHOD__.": Assigning OAID to FTU in Rimo: $post_url");
|
||||
|
||||
$response = file_get_contents($post_url, false, $ctx);
|
||||
|
||||
if($response === false) {
|
||||
$this->log->error("Fehler beim Zuweisen der OAID '".$this->oaid."' zu RIMO FTU '".$unit_extdata->rimo->ftu->id."'\n");
|
||||
$workorders_failed++;
|
||||
return false;
|
||||
}
|
||||
|
||||
// add FTU id to external_data
|
||||
$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->ftu_id = $unit_extdata->rimo->ftu->id;
|
||||
$oaid_export_data->rimo->ftu_assigned_date = date('U');
|
||||
$this->export_data = json_encode($oaid_export_data);
|
||||
$this->save();
|
||||
} else {
|
||||
$this->log->debug(__METHOD__.": OAID ".$this->oaid.": Already assigned to FTU in Rimo");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function importFromCSV(File $file, $attributes = []) {
|
||||
$active = (int)$attributes['active'];
|
||||
$origin = $attributes['origin'];
|
||||
@@ -63,6 +300,20 @@ class OpenAccessId extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function getExportData($key) {
|
||||
if(!$this->export_data) {
|
||||
return [];
|
||||
} else {
|
||||
$exdata = json_decode($this->export_data);
|
||||
if(!is_object($exdata)) {
|
||||
return [];
|
||||
}
|
||||
if(isset($exdata->$key)) {
|
||||
return $exdata->$key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
|
||||
@@ -76,6 +76,26 @@ class OpenAccessIdModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getFirstOaid($oaid) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
if(!$oaid) return null;
|
||||
|
||||
$where = self::getSqlFilter(["oaid" => $oaid]);
|
||||
mfLoghandler::singleton()->debug($where);
|
||||
$res = $db->select("OpenAccessId", "*", "$where ORDER BY id");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new OpenAccessId($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
|
||||
@@ -17,6 +17,171 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function afterSave() {
|
||||
// update preorder OAID if it's different from the unit OAID
|
||||
// but only if the unit OAID is of the same origin as the campaign
|
||||
$old_oaid = $this->oaid;
|
||||
//$this->getOaidFromWohneinheitIfOriginMatch();
|
||||
$this->setOrCreateOaid();
|
||||
if($this->oaid != $old_oaid) {
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function setOrCreateOaid($oaid_attributes = false) {
|
||||
$campaign = new Preordercampaign($this->preordercampaign_id);
|
||||
if(!$campaign->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->adb_wohneinheit_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
|
||||
|
||||
if($this->oaid) {
|
||||
// If current OAID is from correct Origin then do nothing
|
||||
$current_oaid = OpenAccessIdModel::getFirstOaid($this->oaid);
|
||||
if(!$current_oaid) {
|
||||
return true; // this is a thetool oaid, so do nothing
|
||||
}
|
||||
if($campaign->oaid_origin == $current_oaid->origin) {
|
||||
// also check if wohneinheit has no oaid and set it
|
||||
if(!$wohneinheit->oaid) {
|
||||
$wohneinheit->oaid = $current_oaid->oaid;
|
||||
$wohneinheit->save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if($this->type == "interest") return true;
|
||||
|
||||
if(!$this->id) {
|
||||
$this->log->error(__METHOD__.": Tried to create OAID in unsaved Preorder");
|
||||
throw new Exception(__METHOD__.": Tried to create OAID in unsaved Preorder");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// use Wohneinehit OAID if available and from same origin
|
||||
$unit_oaid = $this->getOaidFromWohneinheitIfOriginMatch();
|
||||
if($unit_oaid) {
|
||||
$this->oaid = $unit_oaid;
|
||||
$this->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// else create new OAID
|
||||
|
||||
if(!$campaign->network) {
|
||||
$this->log->warning(__METHOD__.": Cannot create OAID: Invalid campaign Network");
|
||||
return false;
|
||||
}
|
||||
$netowner = new Address($campaign->network->owner_id);
|
||||
if(!$netowner->id) {
|
||||
$this->log->warning(__METHOD__.": Cannot create OAID: Invalid campaign Network Owner");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch($campaign->oaid_origin) {
|
||||
case "ofaa":
|
||||
if(!$oaid_attributes) {
|
||||
$oaid_attributes = [
|
||||
"origin" => $campaign->oaid_origin,
|
||||
"owner_id" => $campaign->network->owner_id
|
||||
];
|
||||
}
|
||||
|
||||
// get new OFAA OAID
|
||||
$oaid = new OpenAccessId();
|
||||
$oaid->loadRandomUnassigned($oaid_attributes);
|
||||
|
||||
if(!$oaid->oaid) {
|
||||
$this->layout->setFlash("Keine weiteren OAIDs verfügbar", "error");
|
||||
throw new Exception("Keine weiteren OAIDs verfügbar in ".$netowner->getCompanyOrName());
|
||||
} else {
|
||||
// make sure this OAID is not in use on another wohneinheit by accident
|
||||
$oaid_unit_count = ADBWohneinheitModel::count(['oaid' => $oaid->oaid]);
|
||||
$oaid_unit_try = 0;
|
||||
while($oaid_unit_count) {
|
||||
if($oaid_unit_try > 5) {
|
||||
$this->log->error(__METHOD__.": Can't find random OAID which is not already used in Wohneinheit by accident after 5 tries. Giving up");
|
||||
throw new Exception("Can't find random OAID which is not already used in Wohneinheit by accident after 5 tries. Giving up");
|
||||
}
|
||||
$oaid_unit_try++;
|
||||
|
||||
$oaid = new OpenAccessId();
|
||||
$oaid->loadRandomUnassigned($oaid_attributes);
|
||||
$oaid_unit_count = ADBWohneinheitModel::count(['oaid' => $oaid->oaid]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$oaid->oaid) {
|
||||
$this->log->error(__METHOD__.": Cannot generate OAID: OpenAccessId::loadRandomUnassigned() failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if($wohneinheit->oaid != $oaid->oaid) {
|
||||
$wohneinheit->oaid = $oaid->oaid;
|
||||
$wohneinheit->save();
|
||||
}
|
||||
|
||||
$this->oaid = $oaid->oaid;
|
||||
|
||||
$oaid->assigned = date('U');
|
||||
$oaid->adb_wohneinheit_id = $wohneinheit->id;
|
||||
$oaid->address = $wohneinheit->hausnummer->getAddress();
|
||||
$oaid->unit_string = (string)$wohneinheit;
|
||||
//var_dump($oaid);exit;
|
||||
if(!$oaid->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern der OAID für Preorder ".$preorder->id);
|
||||
$this->redirect("Preordercampaign", "Admin");
|
||||
}
|
||||
if(!$this->save()) {
|
||||
$oaid->assigned = 0;
|
||||
$oaid->adb_wohneinheit_id = null;
|
||||
$oaid->address = null;
|
||||
$oaid->unit_string = null;
|
||||
$oaid->save();
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case "thetool":
|
||||
// create new thethool OAID
|
||||
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
|
||||
if(!$wohneinheit->oaid) {
|
||||
$wohneinheit->oaid = $wohneinheit->getNewOAID();
|
||||
$wohneinheit->save();
|
||||
}
|
||||
if($wohneinheit->oaid) {
|
||||
$this->oaid = $wohneinheit->oaid;
|
||||
}
|
||||
$this->save();
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getOaidFromWohneinheitIfOriginMatch() {
|
||||
if($this->adb_wohneinheit_id) {
|
||||
$unit = new ADBWohneinheit($this->adb_wohneinheit_id);
|
||||
if($unit && $unit->oaid && $this->oaid != $unit->oaid) {
|
||||
|
||||
$campaign = new Preordercampaign($this->preordercampaign_id);
|
||||
$unit_oaid = OpenAccessIdModel::getFirst(["oaid" => $unit->oaid]);
|
||||
|
||||
if($unit_oaid->origin == $campaign->oaid_origin) {
|
||||
return $unit->oaid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function createUcode() {
|
||||
$ucode = $this->generateNewUcode();
|
||||
while(PreorderModel::search(['ucode' => $ucode])) {
|
||||
|
||||
@@ -173,10 +173,21 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
if(array_key_exists("rimo_workorder", $filter)) {
|
||||
if($filter["rimo_workorder"] == "1") {
|
||||
$new_filter['workorder_export_date'] = true;
|
||||
$new_filter['rimo_workorder'] = true;
|
||||
} elseif($filter["rimo_workorder"] == "0") {
|
||||
$new_filter['workorder_export_date'] = false;
|
||||
$new_filter['rimo_workorder'] = false;
|
||||
}
|
||||
unset($filter['rimo_workorder']);
|
||||
}
|
||||
|
||||
if(array_key_exists("ucode", $filter) && $filter['ucode']) {
|
||||
$new_filter['ucode'] = "%".$filter['ucode']."%";
|
||||
unset($filter['ucode']);
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid", $filter) && $filter['oaid']) {
|
||||
$new_filter['oaid'] = "%".$filter['oaid']."%";
|
||||
unset($filter['oaid']);
|
||||
}
|
||||
|
||||
/*if(array_key_exists("attributes", $filter) && count($filter['attributes'])) {
|
||||
@@ -184,7 +195,7 @@ class PreorderController extends mfBaseController {
|
||||
}*/
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
}
|
||||
@@ -278,6 +289,13 @@ class PreorderController extends mfBaseController {
|
||||
$data['termination_id'] = ($r->termination_id) ? $r->termination_id : null;
|
||||
|
||||
|
||||
$campaign = new Preordercampaign($r->campaign_id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Keine Kampagne ausgewählt!", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
|
||||
if($campaign->product_type != "setup_only") {
|
||||
$data['product_id'] = $r->product_id;
|
||||
}
|
||||
@@ -373,11 +391,6 @@ class PreorderController extends mfBaseController {
|
||||
$preorder->update($data);
|
||||
}
|
||||
|
||||
$campaign = new Preordercampaign($preorder->preordercampaign_id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Keine Kampagne ausgewählt!", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
//var_dump($preorder, $r);exit;
|
||||
// handle new address creation
|
||||
if(!$preorder->adb_hausnummer_id) {
|
||||
@@ -600,7 +613,9 @@ class PreorderController extends mfBaseController {
|
||||
/*
|
||||
* generate ucode and save
|
||||
*/
|
||||
$preorder->createUcode();
|
||||
if(!$preorder->ucode) {
|
||||
$preorder->createUcode();
|
||||
}
|
||||
$new_id = $preorder->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
|
||||
@@ -135,6 +135,7 @@ class PreorderModel {
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.RimoWorkorder tt_rimoworkorder ON (adb_wohneinheit.id = tt_rimoworkorder.adb_wohneinheit_id)
|
||||
WHERE $where
|
||||
ORDER BY $orderBy
|
||||
LIMIT 1";
|
||||
@@ -164,6 +165,7 @@ class PreorderModel {
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus as tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id),
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.RimoWorkorder tt_rimoworkorder ON (adb_wohneinheit.id = tt_rimoworkorder.adb_wohneinheit_id)
|
||||
JSON_TABLE(tt_preorder.addon_services,
|
||||
'$[*]' COLUMNS (
|
||||
ordered VARCHAR(64) PATH '$.ordered'
|
||||
@@ -195,6 +197,7 @@ class PreorderModel {
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus as tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id),
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.RimoWorkorder tt_rimoworkorder ON (adb_wohneinheit.id = tt_rimoworkorder.adb_wohneinheit_id)
|
||||
JSON_TABLE(tt_preorder.addon_services,
|
||||
'$[*]' COLUMNS (
|
||||
ordered VARCHAR(64) PATH '$.ordered'
|
||||
@@ -234,6 +237,7 @@ class PreorderModel {
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.RimoWorkorder tt_rimoworkorder ON (adb_wohneinheit.id = tt_rimoworkorder.adb_wohneinheit_id)
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
@@ -257,6 +261,7 @@ class PreorderModel {
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.RimoWorkorder tt_rimoworkorder ON (adb_wohneinheit.id = tt_rimoworkorder.adb_wohneinheit_id)
|
||||
WHERE $where
|
||||
ORDER BY lastname, firstname
|
||||
";
|
||||
@@ -445,14 +450,17 @@ class PreorderModel {
|
||||
if(array_key_exists("ucode", $filter)) {
|
||||
$ucode = FronkDB::singleton()->escape($filter['ucode']);
|
||||
if($ucode) {
|
||||
$where .= " AND ucode = '$ucode'";
|
||||
$where .= " AND ucode LIKE '$ucode'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid", $filter)) {
|
||||
$oaid = FronkDB::singleton()->escape($filter['oaid']);
|
||||
$oaid = $filter['oaid'];
|
||||
if($oaid) {
|
||||
$where .= " AND tt_preorder.oaid = '$oaid'";
|
||||
$oaid = FronkDB::singleton()->escape($oaid);
|
||||
$where .= " AND tt_preorder.oaid LIKE '$oaid'";
|
||||
} elseif($oaid === null) {
|
||||
$where .= " AND tt_preorder.oaid IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +476,16 @@ class PreorderModel {
|
||||
if($workorder_export_date === null || $workorder_export_date === false) {
|
||||
$where .= " AND (tt_preorder.workorder_export_date IS NULL OR tt_preorder.workorder_export_date = 0)";
|
||||
} elseif($workorder_export_date) {
|
||||
$where .= " AND tt_preorder.workorder_export_date > 1";
|
||||
$where .= " AND tt_preorder.workorder_export_date > 0";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rimo_workorder", $filter)) {
|
||||
$rimo_workorder = $filter['rimo_workorder'];
|
||||
if($rimo_workorder === null || $rimo_workorder === false) {
|
||||
$where .= " AND (tt_rimoworkorder.id IS NULL)";
|
||||
} elseif($rimo_workorder) {
|
||||
$where .= " AND tt_rimoworkorder.id IS NOT NULL";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,6 +219,12 @@ class PreordercampaignController extends mfBaseController {
|
||||
$data['fulfillment'] = "thetool";
|
||||
}
|
||||
|
||||
if($r->oaid_origin == "ofaa") {
|
||||
$data['oaid_origin'] = "ofaa";
|
||||
} else {
|
||||
$data['oaid_origin'] = "thetool";
|
||||
}
|
||||
|
||||
if($r->product_type == "setup_only") {
|
||||
$data['product_type'] = "setup_only";
|
||||
} elseif($r->product_type == "no_setup") {
|
||||
@@ -429,6 +435,83 @@ class PreordercampaignController extends mfBaseController {
|
||||
}
|
||||
|
||||
|
||||
protected function assignOpenAccessIdsToPreorders() {
|
||||
$this->layout()->setTemplate("Preordercampaign/Admin");
|
||||
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$campaign = new Preordercampaign($id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$assigned_oaids = 0;
|
||||
$multiple_unit = 0;
|
||||
|
||||
foreach(PreorderModel::search(["preordercampaign_id" => $id, "oaid" => null, 'deleted' => 0]) as $preorder) {
|
||||
if($preorder->type == "interest") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($preorder->oaid) {
|
||||
$this->log->warning(__METHOD__.": OAID is set already");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$preorder->adb_wohneinheit_id) {
|
||||
//echo "Keine Wohneinheit in Preorder (".$preorder->id.") ".$preorder->ucode." ".$preorder->oaid."\n";
|
||||
continue;
|
||||
}
|
||||
$wohneinheit = new ADBWohneinheit($preorder->adb_wohneinheit_id);
|
||||
if(!$wohneinheit->id) {
|
||||
$this->log->error(__METHOD__.": Wohneinheit nicht gefunden (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")");
|
||||
continue;
|
||||
}
|
||||
|
||||
/*if(!$wohneinheit->extref) {
|
||||
continue;
|
||||
}*/
|
||||
|
||||
$wohneinheit_count = PreorderModel::count(["deleted" => 0, "adb_wohneinheit_id" => $wohneinheit->id]);
|
||||
if($wohneinheit_count > 1) {
|
||||
$this->log->error(__METHOD__.": Wohneinheit ".$wohneinheit->id." is assigned to multiple preorders!");
|
||||
$multiple_unit++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$netowner = new Address($campaign->network->owner_id);
|
||||
//var_dump($netowner);exit;
|
||||
// get random active OAID from network owner pool
|
||||
|
||||
$oaid_attributes = [
|
||||
"owner_id" => $netowner->id,
|
||||
"origin" => $campaign->oaid_origin
|
||||
];
|
||||
|
||||
if($this->request->origin_id) {
|
||||
$oaid_attributes["origin_id"] = $this->request->origin_id;
|
||||
}
|
||||
|
||||
$preorder->setOrCreateOaid($oaid_attributes);
|
||||
|
||||
if($wohneinheit->oaid != $oaid->oaid) {
|
||||
$wohneinheit->oaid = $oaid->oaid;
|
||||
$wohneinheit->save();
|
||||
}
|
||||
|
||||
$assigned_oaids++;
|
||||
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("$assigned_oaids OAIDs wurden Vorbestellungen zugewiesen", "success");
|
||||
$this->redirect("Preordercampaign", "Admin", ["id" => $id]);
|
||||
}
|
||||
|
||||
protected function createRimoWorkordersAction() {
|
||||
$this->layout()->setTemplate("Preordercampaign/Admin");
|
||||
|
||||
@@ -449,7 +532,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
$workorders_created = 0;
|
||||
$workorders_failed = 0;
|
||||
|
||||
foreach(PreorderModel::search(["preordercampaign_id" => $id, "workorder_export_date" => null, 'deleted' => 0]) as $preorder) {
|
||||
foreach(PreorderModel::search(["preordercampaign_id" => $id, "rimo_workorder" => false, 'deleted' => 0]) as $preorder) {
|
||||
if($preorder->workorder_export_date) {
|
||||
$this->log->warning(__METHOD__.": workorder_export_date not null");
|
||||
}
|
||||
@@ -468,21 +551,28 @@ class PreordercampaignController extends mfBaseController {
|
||||
$this->log->error(__METHOD__.": Wohneinheit nicht gefunden (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(!$wohneinheit->extref) {
|
||||
$missing_extrefs[] = $preorder;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(!$preorder->oaid) {
|
||||
if(!$wohneinheit->oaid) {
|
||||
$wohneinheit->oaid = $wohneinheit->getNewOAID();
|
||||
$wohneinheit->save();
|
||||
$preorder->setOrCreateOaid();
|
||||
if(!$preorder->oaid) {
|
||||
continue;
|
||||
}
|
||||
$preorder->oaid = $wohneinheit->oaid;
|
||||
$preorder->save();
|
||||
}
|
||||
|
||||
|
||||
$oaid = OpenAccessIdModel::getFirstOaid($wohneinheit->oaid);
|
||||
if(!$oaid) {
|
||||
$this->log->warning(__METHOD__.": OAID '".$wohneinheit->oaid."' not found");
|
||||
continue;
|
||||
}
|
||||
// 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);
|
||||
@@ -515,11 +605,22 @@ class PreordercampaignController extends mfBaseController {
|
||||
$workorders_failed++;
|
||||
continue;
|
||||
}
|
||||
$preorder->workorder_export_date = date('U');
|
||||
$preorder->workorder_export_data = $response;
|
||||
$preorder->save();
|
||||
$workorders_created++;
|
||||
//$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 in Database! Invalid Response! (Preorder code: ".$preorder->ucode.") | Response: \n$response");
|
||||
throw new Exception("Cannot create RimoWorkorder in Database! Invalid Response! (Preorder code: ".$preorder->ucode.")");
|
||||
}
|
||||
|
||||
$wo = RimoWorkorderModel::create([
|
||||
"rimo_id" => $resp_data->id,
|
||||
"rimo_name" => $resp_data->name,
|
||||
"adb_wohneinheit_id" => $preorder->adb_wohneinheit_id,
|
||||
"create_data" => $response
|
||||
]);
|
||||
$workorders_created++;
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
@@ -551,9 +652,72 @@ class PreordercampaignController extends mfBaseController {
|
||||
$this->layout()->setFlash("Es konnten keine Workorders erstellt werden", "info");
|
||||
}
|
||||
|
||||
$this->redirect("Preordercampaign", "Admin", ["id" => $id]);
|
||||
|
||||
}
|
||||
|
||||
protected function exportOaidsToRimo() {
|
||||
|
||||
|
||||
$this->layout()->setTemplate("Preordercampaign/Admin");
|
||||
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$campaign = new Preordercampaign($id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$oaid_assigned = 0;
|
||||
$missing_units = 0;
|
||||
$missing_extrefs = 0;
|
||||
$missing_oaid = 0;
|
||||
|
||||
foreach(PreorderModel::search(["preordercampaign_id" => $id, 'deleted' => 0]) as $preorder) {
|
||||
if($preorder->type == "interest") {
|
||||
$this->log->debug(__METHOD__.": Ignoring Preorder ".$preorder->id.": is interest");
|
||||
continue;
|
||||
}
|
||||
|
||||
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");
|
||||
$missing_units++;
|
||||
continue;
|
||||
}
|
||||
$wohneinheit = new ADBWohneinheit($preorder->adb_wohneinheit_id);
|
||||
if(!$wohneinheit->id) {
|
||||
$this->log->error(__METHOD__.": Wohneinheit nicht gefunden (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$wohneinheit->extref) {
|
||||
$missing_extrefs++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$preorder->oaid) {
|
||||
$missing_oaid++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO; OpenaccessID::exportToRimoFtu
|
||||
$oaid = OpenAccessIdModel::getFirstOaid($wohneinheit->oaid);
|
||||
if(!$oaid) {
|
||||
$this->log->warning("Cannot export OAID to rimo because not found: ".$wohneinheit->oaid." (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")");
|
||||
continue;
|
||||
}
|
||||
|
||||
if($oaid->exportToRimoAndAssignFtu()) {
|
||||
$oaid_assigned++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("$oaid_assigned OAIDs erfolgreich erstellt und/oder FTUs zugeordnet.<br />$missing_units missing units<br />$missing_extrefs missing extref<br />$missing_oaid missing oaid");
|
||||
$this->redirect("Preordercampaign", "Admin", ["id" => $id]);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ class PreordercampaignModel {
|
||||
public $network_id;
|
||||
public $homes_count;
|
||||
public $fulfillment;
|
||||
public $oaid_origin;
|
||||
public $product_type;
|
||||
public $description;
|
||||
public $area;
|
||||
|
||||
33
application/RimoWorkorder/RimoWorkorder.php
Normal file
33
application/RimoWorkorder/RimoWorkorder.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class RimoWorkorder extends mfBaseModel {
|
||||
private $adb_wohneinheit;
|
||||
private $termination;
|
||||
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "adb_wohneinheit") {
|
||||
$this->adb_wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
|
||||
return $this->adb_wohneinheit;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
158
application/RimoWorkorder/RimoWorkorderModel.php
Normal file
158
application/RimoWorkorder/RimoWorkorderModel.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
class RimoWorkorderModel {
|
||||
public $rimo_id;
|
||||
public $rimo_name;
|
||||
public $adb_wohneinheit_id;
|
||||
public $termination_id;
|
||||
public $create_data;
|
||||
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new RimoWorkorder();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("RimoWorkorder", "*", "1=1 ORDER BY `create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new RimoWorkorder($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = null) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
mfLoghandler::singleton()->debug($where);
|
||||
$res = $db->select("RimoWorkorder", "*", "$where ORDER BY `create`");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new RimoWorkorder($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM RimoWorkorder
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM RimoWorkorder
|
||||
WHERE $where
|
||||
ORDER BY `create`";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new RimoWorkorder($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
$where = "1=1 ";
|
||||
|
||||
if(!is_array($filter)) {
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("adb_wohneinheit_id", $filter)) {
|
||||
$adb_wohneinheit_id = $filter['adb_wohneinheit_id'];
|
||||
if(is_numeric($adb_wohneinheit_id)) {
|
||||
$where .= " AND adb_wohneinheit_id = $adb_wohneinheit_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("termination_id", $filter)) {
|
||||
$termination_id = $filter['termination_id'];
|
||||
if(is_numeric($termination_id)) {
|
||||
$where .= " AND termination_id = $termination_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rimo_id", $filter)) {
|
||||
$rimo_id = $db->escape($filter['rimo_id']);
|
||||
if($rimo_id) {
|
||||
$where .= " AND rimo_id LIKE '$rimo_id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rimo_name", $filter)) {
|
||||
$rimo_name = $db->escape($filter['rimo_name']);
|
||||
if($rimo_name) {
|
||||
$where .= " AND rimo_name LIKE '$rimo_name'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ class TerminationModel {
|
||||
public $lineworker_id = null;
|
||||
public $name = null;
|
||||
public $code = null;
|
||||
public $oan_id = null;
|
||||
public $oaid = null;
|
||||
public $rimo_id = null;
|
||||
public $contact = null;
|
||||
public $phone = null;
|
||||
|
||||
71
scripts/preorder/delete-all-oaids-from-rimo.php
Normal file
71
scripts/preorder/delete-all-oaids-from-rimo.php
Normal file
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
die("disabled");
|
||||
//require 'vendor/autoload.php';
|
||||
require("../../config/config.php");
|
||||
|
||||
define('FRONKDB_SQLDEBUG',false);
|
||||
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||
|
||||
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||
|
||||
$me = new User(1);
|
||||
define("INTERNAL_USER_ID", $me->id);
|
||||
define("INTERNAL_USER_USERNAME", $me->username);
|
||||
|
||||
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
||||
$params['limit'] = 1000;
|
||||
$params['offset'] = 1;
|
||||
|
||||
$ctx_opts = [
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => 'accept: application/json'
|
||||
]
|
||||
];
|
||||
|
||||
$qs = http_build_query($params);
|
||||
//echo $qs."\n";
|
||||
|
||||
$createOrderEp = RIMO_API_JSON_URL."/v1/oaid-management/oaids";
|
||||
$get_url = $createOrderEp."?".$qs;
|
||||
$ctx = stream_context_create($ctx_opts);
|
||||
echo " Getting all OAIDs in Rimo: $get_url\n";
|
||||
$response = file_get_contents($get_url, false, $ctx);
|
||||
|
||||
//var_dump($response);exit;
|
||||
if($response === false) {
|
||||
echo "Fehler beim Auslesen der OAIDs aus RIMO\n";
|
||||
$workorders_failed++;
|
||||
return false;
|
||||
}
|
||||
|
||||
$all_oaids_json = json_decode($response);
|
||||
$all_oaids = $all_oaids_json->item;
|
||||
|
||||
foreach($all_oaids as $oaid_obj) {
|
||||
if(!$oaid_obj->name) continue;
|
||||
|
||||
$params = [];
|
||||
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
||||
$params['oaidName'] = $oaid_obj->name;
|
||||
|
||||
$ctx_opts = [
|
||||
'http' => [
|
||||
'method' => 'DELETE',
|
||||
'header' => 'accept: application/json'
|
||||
]
|
||||
];
|
||||
|
||||
$qs = http_build_query($params);
|
||||
//echo $qs."\n";
|
||||
|
||||
$createOrderEp = RIMO_API_JSON_URL."/v1/oaid-management/oaids";
|
||||
$delete_url = $createOrderEp."?".$qs;
|
||||
$ctx = stream_context_create($ctx_opts);
|
||||
echo " Deleting OAID ".$oaid_obj->name." from Rimo: $delete_url\n";
|
||||
$response = file_get_contents($delete_url, false, $ctx);
|
||||
echo "$response\n";
|
||||
}
|
||||
@@ -171,9 +171,11 @@ while($csv = fgetcsv($input, 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//echo $campaign->name." (".$network->name.")\n";
|
||||
$create_oaid = false;
|
||||
if($campaign->oaid_origin == "thetool") {
|
||||
$create_oaid = true;
|
||||
}
|
||||
|
||||
//var_dump($data);exit;
|
||||
$hausnummer = new ADBHausnummer($data->hausnummer_id);
|
||||
|
||||
$wohneinheiten = ADBWohneinheitModel::search(["hausnummer_id" => $hausnummer->id]);
|
||||
@@ -250,7 +252,7 @@ while($csv = fgetcsv($input, 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$unit->oaid) {
|
||||
if($create_oaid && !$unit->oaid) {
|
||||
$unit->oaid = $unit->getNewOAID();
|
||||
$unit->save();
|
||||
}
|
||||
@@ -312,7 +314,7 @@ while($csv = fgetcsv($input, 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$unit->oaid) {
|
||||
if($create_oaid && !$unit->oaid) {
|
||||
$unit->oaid = $unit->getNewOAID();
|
||||
$unit->save();
|
||||
}
|
||||
|
||||
52
scripts/preorder/migrate-workorders-to-table.php
Executable file
52
scripts/preorder/migrate-workorders-to-table.php
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
//require 'vendor/autoload.php';
|
||||
require("../../config/config.php");
|
||||
|
||||
define('FRONKDB_SQLDEBUG',false);
|
||||
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||
|
||||
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||
|
||||
$me = new User(1);
|
||||
define("INTERNAL_USER_ID", $me->id);
|
||||
define("INTERNAL_USER_USERNAME", $me->username);
|
||||
|
||||
|
||||
foreach(PreorderModel::search(["workorder_export_date" => true, "deleted" => 0]) as $preorder) {
|
||||
$wo_data = json_decode(($preorder->workorder_export_data));
|
||||
//var_dump($preorder->id, $wo_data);exit;
|
||||
|
||||
echo "rimo id: ".$wo_data->id."\n";
|
||||
echo "rimo name: ".$wo_data->name."\n";
|
||||
|
||||
|
||||
$rimo_id = $wo_data->id;
|
||||
$rimo_name = $wo_data->name;
|
||||
|
||||
if(RimoWorkorderModel::getFirst(["rimo_id" => $rimo_id])) {
|
||||
echo "Gibts scho! $rimo_id $rimo_name\n";
|
||||
continue;
|
||||
}
|
||||
if(RimoWorkorderModel::getFirst(["rimo_name" => $rimo_name])) {
|
||||
echo "Gibts scho(2)! $rimo_id $rimo_name\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$workorder = RimoWorkorderModel::create([
|
||||
"rimo_id" => $rimo_id,
|
||||
"rimo_name" => $rimo_name,
|
||||
"adb_wohneinheit_id" => $preorder->adb_wohneinheit_id,
|
||||
"create_data" => $preorder->workorder_export_data
|
||||
]);
|
||||
|
||||
if(!$workorder->save()) {
|
||||
echo "Error saving new Workorder (Preorder ".$preorder->id." $rimo_id $rimo_name";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -20,8 +20,12 @@ $mainlog = mfLoghandler::singleton();
|
||||
$log = new mfLog_File();
|
||||
$log->init(BASEDIR."/var/log/rimo-import.log");
|
||||
|
||||
$apiUrl = RIMO_API_JSON_URL_PROD;
|
||||
$apiToken = RIMO_API_JSON_APIKEY_PROD;
|
||||
$apiOwner = "rml";
|
||||
$apiEdition = "prod";
|
||||
$apiData = TT_RIMO_API_CREDS[$apiOwner][$apiEdition];
|
||||
|
||||
$apiUrl = $apiData["url"];
|
||||
$apiToken = $apiData["key"];
|
||||
|
||||
$epGetClusters = $apiUrl.RIMO_API_JSON_EP_GET_CLUSTERS;
|
||||
$epGetBuildings = $apiUrl.RIMO_API_JSON_EP_GET_BUILDINGS;
|
||||
@@ -33,7 +37,7 @@ if(!defined("RIMO_API_JSON_APIKEY_PROD")) {
|
||||
|
||||
$import_count = 0;
|
||||
|
||||
$baseParams = ['apiKey' => RIMO_API_JSON_APIKEY_PROD];
|
||||
$baseParams = ['apiKey' => $apiToken];
|
||||
|
||||
$ctxOptsPost = [
|
||||
'http' => [
|
||||
@@ -67,7 +71,8 @@ if($responseText === false) {
|
||||
}
|
||||
|
||||
$clustersResponse = json_decode($responseText);
|
||||
//var_dump($clustersResponse);
|
||||
var_dump($clustersResponse);
|
||||
exit;
|
||||
if(is_object($clustersResponse) && property_exists($clustersResponse, "item") && is_array($clustersResponse->item) && count($clustersResponse->item)) {
|
||||
|
||||
foreach($clustersResponse->item as $cluster) {
|
||||
|
||||
Reference in New Issue
Block a user