Merge branch 'fronkdev' into 'master'
ADB addresses can be deleted now See merge request fronk/thetool!1128
This commit is contained in:
@@ -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