Merge branch 'fronkdev' into 'master'
Added button to create Netzbau Object from AdressDB See merge request fronk/thetool!1876
This commit is contained in:
@@ -335,6 +335,10 @@
|
||||
<a href="<?=self::getUrl("AddressDB", "view", ["id" => $address->id])?>"><i class="far fa-fw fa-eye" title="Adresse Anzeigen"></i></a>
|
||||
<a href="<?=self::getUrl("AddressDB", "edit", ["id" => $address->id])?>" class="pl-1"><i class="far fa-fw fa-edit" title="Adresse Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("AddressDB", "delete", ["id" => $address->id])?>" onclick="if(!confirm('Addresse und alle Wohneinheiten wirklich löschen?')) return false;"><i class="far fa-fw fa-trash-alt text-danger" title="Adresse Löschen"></i></a>
|
||||
|
||||
<?php if($me->is("Admin")): ?>
|
||||
<a href="<?=self::getUrl("Building", "createFromAdb", ["adb_hausnummer_id" => $address->id])?>" target="_blank"><i class="far fa-fw fa-person-digging text-success ml-2" title="Adresse in Netzbau anlegen"></i></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
<div class="card-body">
|
||||
|
||||
<input type="hidden" name="id" value="<?=$building->id?>" />
|
||||
<?php if(isset($adb_hausnummer_id)): ?>
|
||||
<input type="hidden" name="adb_hausnummer_id" value="<?=$adb_hausnummer_id?>" />
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="network_id">Netzgebiet *</label>
|
||||
@@ -70,7 +73,11 @@
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="units">Nutzungseinheiten *</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="number" class="form-control" name="units" id="units" value="<?=$building->units?>" />
|
||||
<?php if($building->units == "from_adb"): ?>
|
||||
<input type="text" class="form-control" name="units" id="units" value="(auto)" disabled="disabled" />
|
||||
<?php else: ?>
|
||||
<input type="number" class="form-control" name="units" id="units" value="<?=$building->units?>" />
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
36
db/migrations/20251111171837_termination_resize_code.php
Normal file
36
db/migrations/20251111171837_termination_resize_code.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class TerminationResizeCode extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("Termination");
|
||||
$table->changeColumn("code", "string", ["length" => 64, "null" => true, "default" => null]);
|
||||
$table->update();
|
||||
|
||||
$table = $this->table("Building");
|
||||
$table->changeColumn("code", "string", ["length" => 64, "null" => true, "default" => null]);
|
||||
$table->changeColumn("oaid", "string", ["length" => 255, "null" => true, "default" => null]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user