From 39c5894c724416cde3d12a9b956eb20fc1a6d915 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 11 Mar 2025 13:59:46 +0100 Subject: [PATCH] Wohneinheiten can be deleted in AddressDB now --- Layout/default/AddressDB/View.php | 2 + Layout/default/OpenAccessId/Index.php | 4 -- .../ADBWohneinheitController.php | 43 +++++++++++++++++++ application/Preorder/Preorder.php | 2 +- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Layout/default/AddressDB/View.php b/Layout/default/AddressDB/View.php index e33d48897..ed0bede47 100644 --- a/Layout/default/AddressDB/View.php +++ b/Layout/default/AddressDB/View.php @@ -154,6 +154,7 @@ Beschreibung Extref Best. + wohneinheiten as $unit): ?> @@ -191,6 +192,7 @@ 0 + $unit->id])?>" onclick="if(!confirm('Wohneinheit wirklich löschen?')) return false"> diff --git a/Layout/default/OpenAccessId/Index.php b/Layout/default/OpenAccessId/Index.php index fd367b772..cd0251af7 100644 --- a/Layout/default/OpenAccessId/Index.php +++ b/Layout/default/OpenAccessId/Index.php @@ -124,7 +124,6 @@ Zugewiesen Exportiert - @@ -162,9 +161,6 @@ exported) ? date("d.m.Y H:i", $oaid->exported) : ""?> - - - diff --git a/application/ADBWohneinheit/ADBWohneinheitController.php b/application/ADBWohneinheit/ADBWohneinheitController.php index 7906de192..0e110848e 100644 --- a/application/ADBWohneinheit/ADBWohneinheitController.php +++ b/application/ADBWohneinheit/ADBWohneinheitController.php @@ -101,5 +101,48 @@ class ADBWohneinheitController extends mfBaseController { $this->layout()->setFlash("Wohneinheit erfolgreich gespeichert.", "success"); $this->redirect("AddressDB", "view", ["id" => $unit->hausnummer_id]); } + + protected function deleteAction() { + $id = $this->request->id; + if(!is_numeric($id) || $id < 1) { + $this->layout()->setFlash("Wohneinheit nicht gefunden", "error"); + $this->redirect("AddressDB"); + } + + $unit = new ADBWohneinheit($id); + if(!$unit->id) { + $this->layout()->setFlash("Wohneinheit nicht gefunden", "error"); + $this->redirect("AddressDB"); + } + + $hausnummer_id = $unit->hausnummer_id; + + if($unit->oaid) { + $oaid = OpenAccessIdModel::getFirstOaid($unit->oaid); + if($oaid && $oaid->origin == "ofaa") { + $this->layout()->setFlash("Wohneinheit kann nicht gelöscht werden, da sie eine extern generierte OAID zugeordnet hat.", "error"); + $this->redirect("AddressDB", "view", ["id" => $hausnummer_id]); + } + } + + if(PreorderModel::getFirst(["adb_wohneinheit_id" => $unit->id])) { + $this->layout()->setFlash("Wohneinheit kann nicht gelöscht werden, da sie in einer Bestellung verwendet wird.", "error"); + $this->redirect("AddressDB", "view", ["id" => $hausnummer_id]); + } + + // delete workorders + foreach(RimoWorkorderModel::search(["adb_wohneinheit_id" => $unit->id]) as $wo) { + $wo->delete(); + } + + if(!$unit->delete()) { + $this->layout()->setFlash("Beim Löschen der Wohneinheit ist ein Fehler aufgetreten.", "error"); + $this->redirect("AddressDB", "view", ["id" => $hausnummer_id]); + } + + $this->layout()->setFlash("Wohneinheit erfolgreich gelöscht.", "success"); + $this->redirect("AddressDB", "view", ["id" => $hausnummer_id]); + + } } \ No newline at end of file diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 5be2f7463..ef51c3eb3 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -607,7 +607,7 @@ class Preorder extends mfBaseModel { $pflag_value->value = ($val) ? 1 : 0; //var_dump($pflag_value); $pflag_value->save(); - echo "saved value ".$pflag_value->value." for flag_id ".$pflag->id."\n"; + //echo "saved value ".$pflag_value->value." for flag_id ".$pflag->id."\n"; } return true;