Merge branch 'fronkdev' into 'master'

OAIDs can be released now

See merge request fronk/thetool!1348
This commit is contained in:
Frank Schubert
2025-05-16 12:54:50 +00:00
8 changed files with 95 additions and 30 deletions

View File

@@ -122,8 +122,8 @@
<th>Herkunft</th>
<th>Besitzer</th>
<th colspan="2" title="Anzahl ADB Wohneinheiten">Zugewiesen</th>
<th>Exportiert</th>
<th></th>
<th>Exportiert</th>
<th></th>
</tr>
<?php foreach($oaids as $oaid): ?>
@@ -136,6 +136,7 @@
<td><?=$oaid->owner->getCompanyOrName()?></td>
<td class="text-right <?=($oaid->adb_wohneinheit_count > 1 || $oaid->adb_wohneinheit_id && $oaid->adb_wohneinheit_count < 1) ? "text-danger" : ""?>">
<?=($oaid->adb_wohneinheit_id) ? $oaid->adb_wohneinheit_count."x" : ""?>
<a class="ml-2" href="<?=self::getUrl("OpenAccessId", "release", ["id" => $oaid->id])?>" title="OAID freigeben" onclick="if(!confirm('Sind Sie sicher, dass die OAID von Wohneinheit, Preorder und Rimo-FTU entfernt werden soll?')) return false;"><i class="far fa-link-slash"></i></a>
</td>
<td>
<?php if($oaid->termination_id): ?>
@@ -151,7 +152,11 @@
<?=((string)$oaid->adb_wohneinheit) ? " - ".(string)$oaid->adb_wohneinheit : ""?>
<?php endif; ?>
</td>
<td><?=($oaid->assigned) ? date("d.m.Y H:i",$oaid->assigned) : ""?></td>
<td>
<?php if($oaid->assigned): ?>
<?=date("d.m.Y H:i",$oaid->assigned)?>
<?php endif; ?>
</td>
<td>
<?php if($oaid->exported_to): ?>
[<?=$oaid->exported_to?>]

View File

@@ -17,7 +17,7 @@ class ADBHausnummer extends mfBaseModel {
mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$this->id, 0);
}
public function afterSave() {
public function afterSave($_params = []) {
// prevent potential infinite loop
$nesting_level = mfValuecache::singleton()->get("adbhausnummer-save-nesting-level-".$this->id);
if(!$nesting_level) {

View File

@@ -22,7 +22,7 @@ class ADBWohneinheit extends mfBaseModel {
$this->refreshUnitCount();
}
protected function afterSave() {
protected function afterSave($_params = []) {
if(!$this->id) return true;
if(!$this->hausnummer_id) return true;
@@ -40,8 +40,12 @@ class ADBWohneinheit extends mfBaseModel {
}
$this->logChanges();
// Statuschange from Rimo statuschange
AddressDB::handleRimoStatusUpdate($this->id);
if(!array_key_exists("no_updates", $_params) || !$_params['no_updates']) {
// Statuschange from Rimo statuschange
AddressDB::handleRimoStatusUpdate($this->id);
}
$this->refreshUnitCount();
}

View File

@@ -8,7 +8,7 @@ class ADBWohneinheitStatusflagValue extends mfBaseModel {
$this->table = "WohneinheitStatusflagValue";
}
protected function afterSave() {
protected function afterSave($_params = []) {
if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
// cascade new status to all preorders
foreach(PreorderModel::search(["adb_wohneinheit_id" => $this->wohneinheit_id]) as $preorder) {

View File

@@ -20,7 +20,7 @@ class Address extends mfBaseModel {
private $creator;
private $editor;
public function afterSave() {
public function afterSave($_params = []) {
// prevent potential infinite loop
if($this->in_after_save) return true;
$this->in_after_save++;

View File

@@ -86,7 +86,56 @@ class OpenAccessIdController extends mfBaseController {
return $new_filter;
}
protected function releaseAction() {
$id = $this->request->id;
if(!$id || $id <1) {
$this->layout()->setFlash("Ungültige OAID", "error");
$this->redirect("OpenAccessId");
}
$oaid = new OpenAccessId($id);
if(!$oaid->id) {
$this->layout()->setFlash("Ungültige OAID", "error");
$this->redirect("OpenAccessId");
}
$oaid->startTransaction();
// remove from Preorders
foreach(PreorderModel::search(["oaid" => $oaid->oaid]) as $preorder) {
$preorder->oaid = null;
$preorder->save(["no_oaid_update" => true, "dont_cascade" => true]);
}
// remove from Wohneinheiten
foreach(ADBWohneinheitModel::search(["oaid" => $oaid->oaid]) as $unit) {
$unit->oaid = null;
$unit->save(["no_updates" => 1]);
$ftu_id = $unit->ftu_data["id"];
if($ftu_id) {
$this->log->debug(__METHOD__.": trying to unassign Oaid ".$oaid->oaid." from Rimo FTU ".$ftu_id);
//Rimoapi::unassignOaid($oaid->oaid, $ftu_id);
}
}
$oaid->assigned = 0;
$oaid->adb_wohneinheit_id = null;
$oaid->exported = 0;
$oaid->exported_to = null;
$oaid->export_data = null;
$oaid->address = null;
$oaid->unit_string = null;
$oaid->save();
$oaid->commitTransaction();
$this->layout()->setFlash("OAID erfolgreich freigegeben");
$this->redirect("OpenAccessId");
}
protected function changeADBWohneinheitAction() {
$this->layout()->setTemplate("OpenAccessId/ChangeUnit");
$id = $this->request->id;

View File

@@ -38,13 +38,13 @@ class Preorder extends mfBaseModel {
}
}
public function beforeSave() {
public function beforeSave($_params = []) {
if(!isset($this->data->status_id)) {
$this->data->status_id = 1;
}
}
public function afterSave() {
public function afterSave($_params = []) {
// reset auto magic properties
$this->status = null;
$this->campaign = null;
@@ -71,29 +71,36 @@ class Preorder extends mfBaseModel {
return true;
}
// 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;
if(!array_key_exists("no_oaid_update", $_params) || !$_params['no_oaid_update']) {
// 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->setOrCreateOaid();
if($this->oaid != $old_oaid) {
$this->resetSaveNesting();
$this->save();
//return true;
$this->setOrCreateOaid();
if($this->oaid != $old_oaid) {
$this->resetSaveNesting();
$this->save();
//return true;
}
}
//TODO: history start
//if($this->status_id != $this->_old_data->status_id) {
$this->createHistoryEntry();
//}
$this->updateRimoWorkorderContact();
// run triggers based on new status
$this->runStatusTrigger();
// Cascade status changes down to adb_hausnummer and adb_wohneinheit
$this->cascadeStatus();
// Cascade status changes down all active preorders with the same hausnummer
$this->cascadeStatusToPreorders();
if(!array_key_exists("dont_cascade", $_params) || !$_params['dont_cascade']) {
$this->updateRimoWorkorderContact();
// run triggers based on new status
$this->runStatusTrigger();
// Cascade status changes down to adb_hausnummer and adb_wohneinheit
$this->cascadeStatus();
// Cascade status changes down all active preorders with the same hausnummer
$this->cascadeStatusToPreorders();
}
}
public function resetSaveNesting() {

View File

@@ -148,9 +148,9 @@ class mfBaseModel {
return true;
}
public function save() {
public function save($_params = []) {
if(method_exists($this, "beforeSave")) {
$this->beforeSave();
$this->beforeSave($_params);
}
$fields = $this->buildFields();
@@ -179,7 +179,7 @@ class mfBaseModel {
if($this->db->update($this->table, $fields, $where, $forcestr)) {
$this->saved++;
if(method_exists($this, "afterSave")) {
$this->afterSave();
$this->afterSave($_params);
}
return $id;
}
@@ -189,7 +189,7 @@ class mfBaseModel {
$this->id = $id;
$this->saved++;
if(method_exists($this, "afterSave")) {
$this->afterSave();
$this->afterSave($_params);
}
return $id;
}