ADB addresses can be deleted now
This commit is contained in:
@@ -234,6 +234,7 @@
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("AddressDB", "view", ["id" => $address->id])?>"><i class="far fa-fw fa-eye" title="Adresse Anzeigen"></i></a>
|
||||
<a href="<?=self::getUrl("AddressDB", "edit", ["id" => $address->id])?>" class="pl-1"><i class="far fa-fw fa-edit" title="Adresse Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("AddressDB", "delete", ["id" => $address->id])?>" onclick="if(!confirm('Addresse und alle Wohneinheiten wirklich löschen?')) return false;"><i class="far fa-fw fa-trash-alt text-danger" title="Adresse Löschen"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -15,6 +15,13 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
$this->table = "Wohneinheit";
|
||||
}
|
||||
|
||||
protected function afterDelete() {
|
||||
foreach(ADBWohneinheitStatusflagValueModel::search(["wohneinheit_id" => $this->id]) as $flag_value) {
|
||||
$flag_value->delete();
|
||||
}
|
||||
$this->refreshUnitCount();
|
||||
}
|
||||
|
||||
protected function afterSave() {
|
||||
if(!$this->id) return true;
|
||||
if(!$this->hausnummer_id) return true;
|
||||
|
||||
@@ -411,6 +411,45 @@ class AddressDBController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Adresse nicht gefunden", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
$hausnummer = new ADBHausnummer($id);
|
||||
if(!$hausnummer->id) {
|
||||
$this->layout()->setFlash("Adresse nicht gefunden", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
foreach($hausnummer->wohneinheiten as $unit) {
|
||||
if(PreorderModel::count(["adb_wohneinheit_id" => $unit->id])) {
|
||||
$this->layout()->setFlash("Adresse kann nicht gelöscht werden, da Wohneinheiten in Verwendung sind", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
$oaid = OpenAccessIdModel::getFirstOaid($unit->oaid);
|
||||
if($oaid && $oaid->origin == "ofaa") {
|
||||
$this->layout()->setFlash("Adresse kann nicht gelöscht werden, da Wohneinheiten mit vergebenen OFAA OAIDs vorhanden sind", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
}
|
||||
|
||||
foreach($hausnummer->wohneinheiten as $unit) {
|
||||
// delete workorders
|
||||
foreach(RimoWorkorderModel::search(["adb_wohneinheit_id" => $unit->id]) as $wo) {
|
||||
$wo->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$hausnummer->delete();
|
||||
|
||||
$this->layout()->setFlash("Adresse erfolgreich gelöscht", "success");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
protected function exportAction() {
|
||||
return $this->exportAddressdb();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user