From d6b5d5d7f00ee3829e6e275a22488177d04302ab Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 23 Jan 2024 13:39:14 +0100 Subject: [PATCH] conditional oaid assignment on unit creation --- Layout/default/AddressDB/View.php | 6 +- Layout/default/OpenAccessId/ChangeUnit.php | 101 ++++++++++++++++++ Layout/default/OpenAccessId/Index.php | 5 +- application/AddressDB/AddressDBController.php | 19 +++- application/OpenAccessId/OpenAccessId.php | 2 +- .../OpenAccessId/OpenAccessIdController.php | 73 +++++++++++++ ...150833_netzgebiet_add_unit_create_oaid.php | 31 ++++++ 7 files changed, 233 insertions(+), 4 deletions(-) create mode 100644 Layout/default/OpenAccessId/ChangeUnit.php create mode 100644 db/migrations/20240122150833_netzgebiet_add_unit_create_oaid.php diff --git a/Layout/default/AddressDB/View.php b/Layout/default/AddressDB/View.php index f61d3d060..09d9325eb 100644 --- a/Layout/default/AddressDB/View.php +++ b/Layout/default/AddressDB/View.php @@ -127,7 +127,11 @@ $unit->id])?>"> id?> - oaid?> + + oaid && OpenAccessIdModel::getFirst(["oaid" => $unit->oaid])): ?> + ["oaid" => $unit->oaid]])?>" class="text-pink" target="_blank">oaid?> + + status->code?> - status->name?> ".(string)$unit."" : ""?> extref) ? "[".$unit->extref."]" : ""?> diff --git a/Layout/default/OpenAccessId/ChangeUnit.php b/Layout/default/OpenAccessId/ChangeUnit.php new file mode 100644 index 000000000..e5ff8b8f5 --- /dev/null +++ b/Layout/default/OpenAccessId/ChangeUnit.php @@ -0,0 +1,101 @@ + + + +
+
+
+
+ +
+

Wohneinheit

+
+
+
+ + +
+
+ +
+
+

id) ? "Wohneinheit bearbeiten" : "Neue Adresse"?>

+ +
"> + +
+
+ +
+ +
+ +
+
+ +
+ +
+ adb_wohneinheit_id && is_object($oaid->adb_wohneinheit)): ?> + adb_wohneinheit : ""?>" + /> + +
+
+ +
+ +
+ + Wohneinheit ID +

+
+
+ + +
+
+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+ + + + \ No newline at end of file diff --git a/Layout/default/OpenAccessId/Index.php b/Layout/default/OpenAccessId/Index.php index 39f6cc328..fd367b772 100644 --- a/Layout/default/OpenAccessId/Index.php +++ b/Layout/default/OpenAccessId/Index.php @@ -135,12 +135,15 @@ origin_id?> origin?> owner->getCompanyOrName()?> - ">adb_wohneinheit_id) ? $oaid->adb_wohneinheit_count."x" : ""?> + "> + adb_wohneinheit_id) ? $oaid->adb_wohneinheit_count."x" : ""?> + termination_id): ?> termination) && $oaid->termination->building_id) ? $oaid->termination->building->getAddress() : ""?> termination->name) ? " - ".$oaid->termination->name : ""?> adb_wohneinheit_id && is_object($oaid->adb_wohneinheit)): ?> + [adb_wohneinheit->hausnummer->strasse->gemeinde->name?>] adb_wohneinheit->hausnummer->plz->plz?> adb_wohneinheit->hausnummer->ortschaft->name?>, diff --git a/application/AddressDB/AddressDBController.php b/application/AddressDB/AddressDBController.php index b722634ce..3670858c0 100644 --- a/application/AddressDB/AddressDBController.php +++ b/application/AddressDB/AddressDBController.php @@ -370,7 +370,9 @@ class AddressDBController extends mfBaseController { $this->layout()->setFlash("Fehler beim Erstellen einer Wohneinheit!", "warning"); return $this->addAction(); } - $wohneinheit->oaid = $wohneinheit->getNewOAID(); + if($hausnummer->netzgebiet->unit_create_oaid) { + $wohneinheit->oaid = $wohneinheit->getNewOAID(); + } $wohneinheit->save(); $w++; } @@ -472,6 +474,9 @@ class AddressDBController extends mfBaseController { case 'findBuildings': $return = $this->findBuildingsApi(); break; + case 'getUnit': + $return = $this->getUnitApi(); + break; case "findUnit": break; default: @@ -487,6 +492,18 @@ class AddressDBController extends mfBaseController { $this->returnJson($data); } + private function getUnitApi() { + $id = $this->request->id; + if(!$id) return false; + + $unit = new ADBWohneinheit($id); + if(!$unit->id) return false; + + $return = $unit->hausnummer->getAddress(); + if((string)$unit) $return .= " ".(string)$unit; + return["string" => $return]; + } + private function findAddressApi() { $addresses = []; $search = trim($this->request->q); diff --git a/application/OpenAccessId/OpenAccessId.php b/application/OpenAccessId/OpenAccessId.php index 252dc159a..17e191361 100644 --- a/application/OpenAccessId/OpenAccessId.php +++ b/application/OpenAccessId/OpenAccessId.php @@ -258,7 +258,7 @@ class OpenAccessId extends mfBaseModel { $exp_data_update->rimo->ftu_name = $ftu_data['name']; $exp_data_update->rimo->ftu_assigned_date = date("U"); $this->export_data = json_encode($ext_data_update); - $this-save(); + $this->save(); } } } diff --git a/application/OpenAccessId/OpenAccessIdController.php b/application/OpenAccessId/OpenAccessIdController.php index 457004963..a5cf3e77c 100644 --- a/application/OpenAccessId/OpenAccessIdController.php +++ b/application/OpenAccessId/OpenAccessIdController.php @@ -85,6 +85,79 @@ class OpenAccessIdController extends mfBaseController { return $new_filter; } + protected function changeADBWohneinheitAction() { + $this->layout()->setTemplate("OpenAccessId/ChangeUnit"); + $id = $this->request->id; + if(!$id || $id <1) { + $this->layout()->setFlash("Ungültige OAID", "error"); + $this->redirect("OpenAccessId"); + } + + $oaid = new OpenAccessId($id); + if(!$oaid->id) { + $this->layout()->setFlash("Ungültige OAID", "error"); + $this->redirect("OpenAccessId"); + } + + $this->layout()->set("oaid", $oaid); + + if(!$this->request->new_unit_id) { + return true; + } + + // get old and new unit_id + $old_unit = ADBWohneinheitModel::getFirst(["oaid" => $oaid->oaid]); + $new_unit = new ADBWohneinheit($this->request->new_unit_id); + + + + + + + if($old_unit) { + $old_preorder = PreorderModel::getFirst(["adb_wohneinheit_id" => $old_unit->id]); + if($old_preorder) { + // remove oaid from preorder + $old_preorder->oaid = null; + $old_preorder->save(); + } + // unassign oaid from rimo ftu + // get oaid from rimo + // unassign ftu from aoid + // remove oaid from old unit + + // remove meta data from oaid + $oaid->assigned = 0; + $oaid->adb_wohneinheit_id = null; + $oaid->termination_id = null; + $oaid->exported = 0; + $oaid->exported_to = null; + $oaid->exported_data = null; + $oaid->address = null; + $oaid->unit_string = null; + $oaid->save(); + } + + if($new_unit) { + $new_preorder = PreorderModel::getFirst(["adb_wohneinheit_id" => $new_unit->id]); + // add oaid to new unit + // assign oaid to new ftu in rimo + if($new_preorder) { + // add oaid to preorder + $new_preorder->oaid = $oaid->oaid; + } + // save metadata to oaid + $oaid->assigned = date("U"); + $oaid->adb_wohneinheit_id = $new_unit->id; + $oaid->termination_id = null; + $oaid->exported = date("U"); + + } + + + + } + protected function importerAction() { $this->layout()->setTemplate("OpenAccessId/Importer"); diff --git a/db/migrations/20240122150833_netzgebiet_add_unit_create_oaid.php b/db/migrations/20240122150833_netzgebiet_add_unit_create_oaid.php new file mode 100644 index 000000000..7c322799b --- /dev/null +++ b/db/migrations/20240122150833_netzgebiet_add_unit_create_oaid.php @@ -0,0 +1,31 @@ +getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + $table = $this->table("Netzgebiet"); + $table->addColumn("unit_create_oaid", "integer", ["null" => false, "default" => 0, "after" => "unit_count"]); + $table->update(); + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + $this->table("Netzgebiet")->removeColumn("unit_create_oaid")->save(); + } + } +}