Merge branch 'ConstructionConsent/add-netzgebiet-id' into 'master'
- See merge request fronk/thetool!1297
This commit is contained in:
@@ -78,6 +78,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="network-id-search" class="<?=(!isset($item) || (isset($item) && $item->object_type == "street")) ? "" : "hidden"?>">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="netzgebiet_id">Netzgebiet</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="form-control" name="netzgebiet_id" id="netzgebiet_id">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="street-search" class="<?=(!isset($item) || $item->object_type != "street") ? "hidden" : ""?>">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="adb_strasse_id">Straße *</label>
|
||||
@@ -303,6 +313,46 @@
|
||||
allowClear: true
|
||||
});
|
||||
|
||||
const netzgebietId = <?=isset($item) && $item->data->netzgebiet_id ? $item->data->netzgebiet_id : "null"?>;
|
||||
console.log("netzgebietId", netzgebietId);
|
||||
const netzgebietSelect = $('#netzgebiet_id');
|
||||
const apiUrl = '<?=self::getUrl("ConstructionConsent", "api")?>';
|
||||
|
||||
function fetchNetzgebiete(projectId, searchTerm = '') {
|
||||
$.ajax({
|
||||
url: apiUrl,
|
||||
data: { q: searchTerm, do: "getNetzgebieteApi", project_id: projectId },
|
||||
dataType: 'json',
|
||||
success: (data) => {
|
||||
netzgebietSelect.empty();
|
||||
netzgebietSelect.append($('<option>', { value: '', text: 'Netzgebiet auswählen' }));
|
||||
if (data?.results) {
|
||||
data.results.forEach(item =>
|
||||
netzgebietSelect.append($('<option>', { value: item.value, text: item.text }))
|
||||
);
|
||||
if (netzgebietId) netzgebietSelect.val(netzgebietId).trigger('change');
|
||||
}
|
||||
netzgebietSelect.trigger('change');
|
||||
},
|
||||
error: (jqXHR, textStatus, errorThrown) => {
|
||||
console.error("Error fetching Netzgebiete:", textStatus, errorThrown);
|
||||
netzgebietSelect.empty()
|
||||
.append($('<option>', { value: '', text: 'Error loading Netzgebiete' }))
|
||||
.trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("#constructionconsentproject_id").on('change', () => {
|
||||
fetchNetzgebiete($(this).val());
|
||||
});
|
||||
|
||||
// Initial fetch
|
||||
fetchNetzgebiete($("#constructionconsentproject_id :selected").val());
|
||||
|
||||
if (netzgebietId) {
|
||||
netzgebietSelect.val(netzgebietId).trigger('change');
|
||||
}
|
||||
$('#adb_hausnummer_id').select2({
|
||||
ajax: {
|
||||
url: '<?=self::getUrl("ConstructionConsent", "api")?>',
|
||||
|
||||
@@ -49,7 +49,16 @@ $pagination_entity_name = "Adressen";
|
||||
<tr>
|
||||
<th>Projekt</th>
|
||||
<td><?=$item->project->name?></td>
|
||||
</tr><tr>
|
||||
</tr>
|
||||
|
||||
<?php if ($item->object_type == 'street' && isset($item->data->netzgebiet_id)): ?>
|
||||
<tr>
|
||||
<th>Netzgebiet</th>
|
||||
<td><?=$item->netzgebiet->name?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<tr>
|
||||
<th>Objekttyp</th>
|
||||
<td><?=__($item->object_type, "consent")?></td>
|
||||
</tr>
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
class ConstructionConsent extends mfBaseModel {
|
||||
protected $forcestr = ["name", "ez", "kg", "gst", "gstnr", "usage_length"];
|
||||
private $project;
|
||||
private $netzgebiet;
|
||||
private $netzgebiet_id;
|
||||
private $termnination;
|
||||
private $adb_hausnummer;
|
||||
private $adb_strasse;
|
||||
@@ -138,6 +140,15 @@ class ConstructionConsent extends mfBaseModel {
|
||||
return $this->project;
|
||||
}
|
||||
|
||||
if($name == 'netzgebiet') {
|
||||
if(!$this->data->netzgebiet_id) return null;
|
||||
$netzgebiet = new ADBNetzgebiet($this->data->netzgebiet_id);
|
||||
if($netzgebiet->id) {
|
||||
$this->netzgebiet = $netzgebiet;
|
||||
}
|
||||
return $this->netzgebiet;
|
||||
}
|
||||
|
||||
if($name == "adb_hausnummer") {
|
||||
if(!$this->adb_hausnummer_id) return null;
|
||||
$hausnummer = new ADBHausnummer($this->adb_hausnummer_id);
|
||||
@@ -597,7 +608,7 @@ FROM ConstructionConsent
|
||||
if(array_key_exists("network", $filter)) {
|
||||
$network = FronkDB::singleton()->escape($filter["network"]);
|
||||
if($network) {
|
||||
$where .= " AND vh.netzgebiet_id=$network";
|
||||
$where .= " AND (vh.netzgebiet_id=$network OR ConstructionConsent.netzgebiet_id=$network)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -257,6 +257,7 @@ class ConstructionConsentController extends mfBaseController {
|
||||
|
||||
$data = [];
|
||||
$data["constructionconsentproject_id"] = $r->constructionconsentproject_id;
|
||||
$data["netzgebiet_id"] = $r->netzgebiet_id;
|
||||
$data["object_type"] = $r->object_type;
|
||||
$data["name"] = $r->name;
|
||||
$data["adb_hausnummer_id"] = $r->adb_hausnummer_id;
|
||||
@@ -531,6 +532,9 @@ class ConstructionConsentController extends mfBaseController {
|
||||
case "findAddress":
|
||||
$return = $this->findAddressApi();
|
||||
break;
|
||||
case "getNetzgebieteApi":
|
||||
$return = $this->getNetzgebieteApi();
|
||||
break;
|
||||
case "getRimoPlanPreview":
|
||||
$return = $this->getRimoPlanPreviewApi();
|
||||
break;
|
||||
@@ -1112,4 +1116,21 @@ class ConstructionConsentController extends mfBaseController {
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getNetzgebieteApi() {
|
||||
$project_id = $this->request->project_id;
|
||||
if(!is_numeric($project_id) || $project_id < 1) self::sendError("Invalid project id");
|
||||
|
||||
$project = new ConstructionConsentProject($project_id);
|
||||
if(!$project->id) self::sendError("Project not found");
|
||||
|
||||
$parsedNetworks = array_map(function($network) {
|
||||
return [
|
||||
"value" => $network->id,
|
||||
"text" => $network->name,
|
||||
];
|
||||
}, array_values($project->adb_networks));
|
||||
|
||||
self::returnJson(["results" => $parsedNetworks]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class ConstructionConsentAddNetzgebietId extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if ($this->getEnvironment() === 'thetool') {
|
||||
$this->table('ConstructionConsent');
|
||||
$this->addColumn('netzgebiet_id', 'integer', ['limit' => 11, 'null' => true, 'default' => null, 'after' => 'rimo_gn']);
|
||||
$this->update();
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if ($this->getEnvironment() === 'thetool') {
|
||||
$this->table('ConstructionConsent');
|
||||
$this->removeColumn('netzgebiet_id');
|
||||
$this->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user