ADB addresses can be deleted now

This commit is contained in:
Frank Schubert
2025-03-20 19:59:18 +01:00
parent 9353591421
commit 0a1c1de44b
3 changed files with 47 additions and 0 deletions
@@ -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();
}