ADB addresses can be deleted now
This commit is contained in:
@@ -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