Added button to create Netzbau Object from AdressDB
This commit is contained in:
@@ -177,6 +177,9 @@ class BuildingController extends mfBaseController {
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
|
||||
$adb_hausnummer_id = null;
|
||||
|
||||
//var_dump($r);exit;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
@@ -187,6 +190,9 @@ class BuildingController extends mfBaseController {
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
if($r->adb_hausnummer_id) {
|
||||
$adb_hausnummer_id = $r->adb_hausnummer_id;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$r->network_id || !$r->type_id) {
|
||||
@@ -215,10 +221,17 @@ class BuildingController extends mfBaseController {
|
||||
$data['contact'] = trim($r->contact);
|
||||
$data['phone'] = trim($r->phone);
|
||||
$data['email'] = trim($r->email);
|
||||
$data['units'] = trim($r->units);
|
||||
|
||||
$data['description'] = trim($r->description);
|
||||
$data['note'] = trim($r->note);
|
||||
|
||||
|
||||
if($adb_hausnummer_id) {
|
||||
$data["adb_hausnummer_id"] = $adb_hausnummer_id;
|
||||
$data['units'] = 0;
|
||||
} else {
|
||||
$data['units'] = trim($r->units);
|
||||
}
|
||||
|
||||
if($this->me->is(["Admin", "netowner"])) {
|
||||
if($r->gps_lat) $data['gps_lat'] = trim($r->gps_lat);
|
||||
if($r->gps_long) $data['gps_long'] = trim($r->gps_long);
|
||||
@@ -235,7 +248,7 @@ class BuildingController extends mfBaseController {
|
||||
|
||||
// check if building exists already
|
||||
$checkBuilding = BuildingModel::search(['=street' => $data['street'], '=city' => $data['city'], '=zip' => $data['zip']]);
|
||||
|
||||
|
||||
if($checkBuilding) {
|
||||
$this->layout()->setFlash("Objekt ist <a target='_blank' href='".self::getUrl("Building")."#building=".$checkBuilding[0]->id."'>bereits vorhanden</a>!", "error");
|
||||
$this->layout()->set("building", $building);
|
||||
@@ -283,30 +296,49 @@ class BuildingController extends mfBaseController {
|
||||
}
|
||||
|
||||
// Anschlüsse anlegen
|
||||
|
||||
if(!$building->terminations && $building->units > 0) {
|
||||
for($i = 1; $i <= $building->units; $i++) {
|
||||
$data = [];
|
||||
$data['building_id'] = $building->id;
|
||||
$data['code'] = $building->code . "." . sprintf("%03d", $i);
|
||||
|
||||
if($building->units == 1) {
|
||||
$data['contact'] = $building->contact;
|
||||
$data['phone'] = $building->phone;
|
||||
$data['email'] = $building->email;
|
||||
}
|
||||
/*
|
||||
// no more lineworker_id in Termination
|
||||
if($building->lineworker_id) {
|
||||
$data['lineworker_id'] = $building->lineworker_id;
|
||||
}*/
|
||||
if($building->oaid) {
|
||||
$data['oaid'] = $building->oaid. "." . sprintf("%03d", $i);
|
||||
}
|
||||
|
||||
$term = TerminationModel::create($data);
|
||||
$term->save();
|
||||
}
|
||||
|
||||
if($mode == "add" && $adb_hausnummer_id) {
|
||||
$i = 1;
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $adb_hausnummer_id]) as $wohneinheit) {
|
||||
$data = [];
|
||||
$data['building_id'] = $building->id;
|
||||
|
||||
$oaid_parts = explode(".", $wohneinheit->oaid);
|
||||
if($wohneinheit->oaid && array_key_exists(1, $oaid_parts)) {
|
||||
$data['code'] = $building->oaid . "." . $oaid_parts[1];
|
||||
} else {
|
||||
$data['code'] = $building->code . "." . sprintf("%04d", $i);
|
||||
}
|
||||
$data['oaid'] = $data['code'];
|
||||
|
||||
$term = TerminationModel::create($data);
|
||||
$term->save();
|
||||
|
||||
$i++;
|
||||
}
|
||||
} elseif(!$building->terminations && $building->units > 0) {
|
||||
for($i = 1; $i <= $building->units; $i++) {
|
||||
$data = [];
|
||||
$data['building_id'] = $building->id;
|
||||
$data['code'] = $building->code . "." . sprintf("%03d", $i);
|
||||
|
||||
if($building->units == 1) {
|
||||
$data['contact'] = $building->contact;
|
||||
$data['phone'] = $building->phone;
|
||||
$data['email'] = $building->email;
|
||||
}
|
||||
/*
|
||||
// no more lineworker_id in Termination
|
||||
if($building->lineworker_id) {
|
||||
$data['lineworker_id'] = $building->lineworker_id;
|
||||
}*/
|
||||
if($building->oaid) {
|
||||
$data['oaid'] = $building->oaid. "." . sprintf("%03d", $i);
|
||||
}
|
||||
|
||||
$term = TerminationModel::create($data);
|
||||
$term->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -343,7 +375,55 @@ class BuildingController extends mfBaseController {
|
||||
$this->layout()->setFlash("Objekt gelöscht", "success");
|
||||
$this->redirect("Building");
|
||||
}
|
||||
|
||||
|
||||
protected function createFromAdbAction() {
|
||||
$adb_hausnummer_id = $this->request->adb_hausnummer_id;
|
||||
|
||||
if(!$adb_hausnummer_id) {
|
||||
$this->layout()->setFlash("AddressDB Adresse nicht gefunden.", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
$hausnummer = new ADBHausnummer($adb_hausnummer_id);
|
||||
if(!$hausnummer->id) {
|
||||
$this->layout()->setFlash("AddressDB Adresse nicht gefunden.", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
$network = NetworkModel::getFirst(["adb_netzgebiet_id" => $hausnummer->netzgebiet_id]);
|
||||
if(!$network) {
|
||||
$this->layout()->setFlash("AddressDB-Netzgebiet ist keinem Netzbau-Netzgebiet zugeordnet!", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
$building_data = [];
|
||||
$building_data["adb_hausnummer_id"] = $hausnummer->id;
|
||||
$building_data["network_id"] = $network->id;
|
||||
$building_data["type_id"] = ($hausnummer->tool_building_type <= 1) ? 1 : 3; // 1 = EFH | 2 = MPH
|
||||
$building_data["status_id"] = 1;
|
||||
|
||||
if($hausnummer->oaid) {
|
||||
if(!BuildingModel::getFirst(["code" => $hausnummer->oaid])) {
|
||||
$building_data["code"] = $hausnummer->oaid;
|
||||
}
|
||||
$building_data["oaid"] = $hausnummer->oaid;
|
||||
}
|
||||
|
||||
$building_data["street"] = $hausnummer->strasse->name . " ".$hausnummer->hausnummer;
|
||||
$building_data["city"] = $hausnummer->strasse->gemeinde->name;
|
||||
$building_data["zip"] = $hausnummer->plz->plz;
|
||||
$building_data["gps_lat"] = $hausnummer->gps_lat;
|
||||
$building_data["gps_long"] = $hausnummer->gps_long;
|
||||
$building_data["units"] = "from_adb";
|
||||
$building_data["note"] = "Created from ADB Address {$hausnummer->id}";
|
||||
|
||||
$building = BuildingModel::create($building_data);
|
||||
$this->layout()->set("building", $building);
|
||||
$this->layout()->set("adb_hausnummer_id", $hausnummer->id);
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin","netowner","pipeplanner"])) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class BuildingModel {
|
||||
public $adb_hausnummer_id = null;
|
||||
public $network_id = null;
|
||||
public $pop_id = null;
|
||||
public $type_id = null;
|
||||
|
||||
Reference in New Issue
Block a user