Added Preordercampaign Admin function updateOaidFromUnit()
This commit is contained in:
@@ -98,7 +98,7 @@
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4>OAIDs auf Wohneinheiten updated</h4>
|
||||
<h4>OAIDs auf Wohneinheiten updaten</h4>
|
||||
<div class="row justify-content-end">
|
||||
<div class="col-10">
|
||||
<div class="row">
|
||||
@@ -118,6 +118,27 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4>OAID-Daten fixen</h4>
|
||||
<div class="row justify-content-end">
|
||||
<div class="col-10">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Setzt OAIDs auf aktuelle Wohneinheitsdaten (Adresse, FTU):
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-1">
|
||||
<div class="col">
|
||||
<a href="<?=self::getUrl("Preordercampaign","updateOaidFromUnit", ["id" => $campaign->id])?>" class="btn btn-primary"><i class="far fa-link-simple"></i> OAID mit Wohneinheitsdaten updaten</a><br />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@@ -291,7 +291,7 @@ class OpenAccessId extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function getExportData($key) {
|
||||
public function getExportData($key = false) {
|
||||
if(!$this->export_data) {
|
||||
return [];
|
||||
} else {
|
||||
@@ -299,12 +299,35 @@ class OpenAccessId extends mfBaseModel {
|
||||
if(!is_object($exdata)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if(!$key) {
|
||||
return $exdata;
|
||||
}
|
||||
|
||||
if(isset($exdata->$key)) {
|
||||
return $exdata->$key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateExportData($cat, $key, $value) {
|
||||
$exp_data = $this->getExportData();
|
||||
if(!$exp_data || !is_object($exp_data)) {
|
||||
$exp_data = new StdClass();
|
||||
}
|
||||
|
||||
if(property_exists($exp_data, $cat)) {
|
||||
$cat_data = $exp_data->$cat;
|
||||
} else {
|
||||
$cat_data = new StdClass();
|
||||
}
|
||||
//var_dump($cat_data);exit;
|
||||
$cat_data->$key = $value;
|
||||
$exp_data->$cat = $cat_data;
|
||||
var_dump($exp_data);
|
||||
$this->export_data = json_encode($exp_data);
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once APPDIR."/OpenAccessId/helper/rimo.php";
|
||||
|
||||
class OpenAccessIdController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
@@ -123,7 +125,11 @@ class OpenAccessIdController extends mfBaseController {
|
||||
$old_preorder->oaid = null;
|
||||
$old_preorder->save();
|
||||
}
|
||||
|
||||
$rimo = new OpenAccessId_Helper_Rimo($oaid->oaid);
|
||||
|
||||
// unassign oaid from rimo ftu
|
||||
//$rimo->unassignOaid($oaid)
|
||||
// get oaid from rimo
|
||||
// unassign ftu from aoid
|
||||
// remove oaid from old unit
|
||||
|
||||
@@ -755,6 +755,8 @@ class PreordercampaignController extends mfBaseController {
|
||||
$missing_oaid = 0;
|
||||
|
||||
foreach(PreorderModel::search(["preordercampaign_id" => $id, "connection_count" => 1, 'deleted' => 0]) as $preorder) {
|
||||
if($preorder->id != 997) continue;
|
||||
|
||||
if($preorder->type == "interest") {
|
||||
$this->log->debug(__METHOD__.": Ignoring Preorder ".$preorder->id.": is interest");
|
||||
continue;
|
||||
@@ -788,7 +790,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
$this->log->warning("Cannot export OAID to rimo because not found: ".$wohneinheit->oaid." (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")");
|
||||
continue;
|
||||
}
|
||||
|
||||
//var_dump($oaid);exit;
|
||||
if($oaid->exportToRimoAndAssignFtu()) {
|
||||
$oaid_assigned++;
|
||||
}
|
||||
@@ -798,4 +800,98 @@ class PreordercampaignController extends mfBaseController {
|
||||
$this->redirect("Preordercampaign", "Admin", ["id" => $id]);
|
||||
|
||||
}
|
||||
|
||||
protected function updateOaidFromUnit() {
|
||||
$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_updated = 0;
|
||||
|
||||
foreach(PreorderModel::search(["preordercampaign_id" => $id, "connection_count" => 1, '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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
//var_dump($oaid);exit;
|
||||
|
||||
|
||||
|
||||
if($oaid->adb_wohneinheit_id != $wohneinheit->id) {
|
||||
$rimo = new OpenAccessId_Helper_Rimo($oaid->oaid);
|
||||
|
||||
$unit_ftu_data = $wohneinheit->ftu_data;
|
||||
//var_dump($unit_ftu_data);
|
||||
if(!$unit_ftu_data) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$oaid_ftu = $oaid->getExportData("rimo");
|
||||
//var_dump($oaid_ftu);
|
||||
if($oaid_ftu->ftu_id) {
|
||||
$rimo->unassignOaid($oaid_ftu->ftu_id);
|
||||
$rimo->assignOaid($unit_ftu_data["id"]);
|
||||
|
||||
$oaid->updateExportData("rimo", "ftu_id", $unit_ftu_data["id"]);
|
||||
$oaid->updateExportData("rimo", "ftu_name", $unit_ftu_data["name"]);
|
||||
$oaid->updateExportData("rimo", "ftu_assigned_date", date("U"));
|
||||
$oaid->address = $wohneinheit->hausnummer->getAddress();
|
||||
$oaid->unit_string = (string)$wohneinheit;
|
||||
|
||||
$oaid->adb_wohneinheit_id = $wohneinheit->id;
|
||||
$oaid->assigned = date("U");
|
||||
$oaid->exported_to = "rimo";
|
||||
$oaid->exported = date('U');
|
||||
|
||||
//var_dump($oaid);exit;
|
||||
$oaid->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Done.", "success");
|
||||
$this->redirect("Preordercampaign", "Admin", ["id" => $id]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user