Files
thetool/Layout/default/ConstructionConsent/Form.php
2025-03-25 10:38:20 +01:00

449 lines
21 KiB
PHP

<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/header.php"); ?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?= self::getUrl("Dashboard") ?>"><?= MFAPPNAME_SLUG ?></a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("ConstructionConsentProject")?>">Zustimmungserklärungsprojekte</a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("ConstructionConsent")?>">Zustimmungserklärungen</a></li>
<?php if(isset($item)): ?>
<li class="breadcrumb-item"><a href="<?=self::getUrl("ConstructionConsent", "View", ["id" => $item->id])?>"><?=htmlentities($item->name)?></a></li>
<?php endif; ?>
<li class="breadcrumb-item active">
<?= ($Action == "add") ? "Neue " : "" ?>Zustimmungserklärung <?= ($Action == "edit") ? "bearbeiten " : "" ?>
</li>
</ol>
</div>
<h4 class="page-title">Zustimmungserklärung</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card bg-light">
<div class="card-body">
<h4 class="header-title mb-2">
<?= ($Action == "add") ? "Neue " : "" ?>Zustimmungserklärung <?= ($Action == "edit") ? "bearbeiten " : "" ?>
</h4>
<form class="form-horizontal" method="post" action="<?= self::getUrl("ConstructionConsent", "save") ?>" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?=isset($item) ? $item->id : ""?>"/>
<div class="card">
<div class="card-body">
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="constructionconsentproject_id">Projekt *</label>
<div class="col-lg-10">
<select class="form-control" name="constructionconsentproject_id" id="constructionconsentproject_id">
<?php foreach(ConstructionConsentProject::search(['id' => $allowed_projects]) as $project): ?>
<option value="<?=$project->id?>" <?=(isset($project_id) && $project_id == $project->id || isset($item) && $item->constructionconsentproject_id == $project->id) ? "selected='selected'" : ""?>><?=$project->name?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="object_type">Objekttyp *</label>
<div class="col-lg-10">
<select class="form-control" name="object_type" id="object_type">
<option value="building" <?=(isset($item) && $item->object_type == "building" ? "selected='selected'" : "")?>>Gebäude</option>
<option value="street" <?=(isset($item) && $item->object_type == "street" ? "selected='selected'" : "")?>>Straße/Grundstück</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="name">Name*</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="name" id="name" value="<?=(isset($item)) ? $item->name : ""?>" placeholder="z.B. Straße oder Adresse" data-toggle="popover" data-trigger="focus" data-placement="left" data-content="Wird in der Zustimmungserklärung in der Objektanschrift verwendet." />
</div>
</div>
<div id="address-search" class="<?=(!isset($item) || (isset($item) && $item->object_type == "building")) ? "" : "hidden"?>">
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="adb_hausnummer_id">Gebäude *</label>
<div class="col-lg-10">
<select class="form-control" name="adb_hausnummer_id" id="adb_hausnummer_id">
<?php if(isset($item) && $item->adb_hausnummer_id): ?>
<option value="<?=$item->adb_hausnummer_id?>" selected="selected"><?=$item->adb_hausnummer->gemeinde->name?>, <?=$item->adb_hausnummer->strasse->name?> <?=$item->adb_hausnummer->hausnummer?></option>
<?php endif; ?>
</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>
<div class="col-lg-10">
<select class="form-control" name="adb_strasse_id" id="adb_strasse_id">
<?php if(isset($item) && $item->adb_strasse_id): ?>
<option value="<?=$item->adb_strasse_id?>" selected="selected"><?=$item->adb_strasse->gemeinde->name?>, <?=$item->adb_strasse->name?></option>
<?php endif; ?>
</select>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="kg">KG</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="kg" id="kg" value="<?=(isset($item)) ? $item->kg : ""?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="gst">GST</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="gst" id="gst" value="<?=(isset($item)) ? $item->gst : ""?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="gstnr">GSTNR</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="gstnr" id="gstnr" value="<?=(isset($item)) ? $item->gstnr : ""?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="ez">Grundbuch Einlagezahl EZ</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="ez" id="ez" value="<?=(isset($item)) ? $item->ez : ""?>" />
</div>
</div>
<hr />
<div id="usage-container">
<h4>Nutzung</h4>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="usage_length">Länge auf Grundstück (in m)</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="usage_length" id="usage_length" value="<?=(isset($item)) ? $item->usage_length : ""?>" />
</div>
</div>
<div id="usage-checkbox-container" class="<?=(isset($item) && $item->object_type == "building") ? "hidden": ""?>">
<div class="form-group row mt-3">
<div class="col-lg-2"></div>
<div class="col-lg-10">
<label>
<input type="checkbox" name="usage_pipe_on_plot" id="usage_pipe_on_plot" value="1" <?=(isset($item) && $item->usage_pipe_on_plot ? "checked='checked'" : "")?> />
Verlegung von Rohren und Lichtwellenleitern am Grundstück
</label>
</div>
</div>
<div class="form-group row">
<div class="col-lg-2"></div>
<div class="col-lg-10">
<label>
<input type="checkbox" name="usage_pipe_in_building" id="usage_pipe_in_building" value="1" <?=(isset($item) && $item->usage_pipe_in_building ? "checked='checked'" : "")?> />
Verlegung von Rohren und Lichtwellenleitern in den darauf befindlichen Gebäuden
</label>
</div>
</div>
<div class="form-group row">
<div class="col-lg-2"></div>
<div class="col-lg-10">
<label>
<input type="checkbox" name="usage_manhole" id="usage_manhole" value="1" <?=(isset($item) && $item->usage_manhole ? "checked='checked'" : "")?> />
Errichtung eines Schachtes/einer Kabelmontagegrube und/oder eines LWL-Verteilschrankes/einer LWL-Abschlussbox
</label>
</div>
</div>
<div class="form-group row">
<div class="col-lg-2"></div>
<div class="col-lg-10">
<label>
<input type="checkbox" name="usage_owner" id="usage_owner" value="1" <?=(isset($item) && $item->usage_owner ? "checked='checked'" : "")?> />
Die Nutzung der Liegenschaft seitens BB dient der Eigenversorgung der GE und/oder dessen Nutzer(in) und wird dieser entgeltlos zugestimmt
</label>
</div>
</div>
</div>
<hr />
<h4>Planskizze / Bilddatei</h4>
<div class="form-group row">
<label class="col-lg-2 col-form-label"></label>
<div class="col-lg-10">
<div class="card">
<h5 class="card-header">Plan aus Rimo laden</h5>
<div class="card-body">
<select class="form-control" name="plan_adb_hausnummer_id" id="plan_adb_hausnummer_id">
<?php if(isset($item) && $item->plan_adb_hausnummer_id): ?>
<option value="<?=$item->plan_adb_hausnummer_id?>" selected="selected"><?=$item->plan_adb_hausnummer->street->name?> <?=$item->plan_adb_hausnummer->hausnummer?>, <?=$item->plan_adb_hausnummer->street->gemeinde->name?></option>
<?php endif; ?>
</select>
</div>
</div>
<div class="card">
<h5 class="card-header">Oder Plan hochladen</h5>
<div class="card-body">
<input type="file" class="form-control" name="consent_plan_image" id="consent_plan_image" />
</div>
</div>
<div class="card">
<h5 class="card-header">Plan Vorschau <button type='button' id="delete-rimo-plan" class='ml-2 btn btn-sm btn-outline-danger pointer <?=($item->file && $item->file->file && $item->file->file->fileExists()) ? "" : "hidden" ?>' onclick='deletePlan()'><i class='fas fa-fw fa-trash'></i> Plan löschen</button></h5>
<div class="card-body" id="rimo-plan-container">
<input type="hidden" name="submit_plan_file_id" id="submit_plan_file_id" value="" />
<img id="plan_preview" style="max-width: 1200px;" <?=(isset($item) && $item->file && $item->file->file && $item->file->file->fileExists()) ? "src=".$item->file->file->asDataUrl()."" : "" ?> />
</div>
</div>
</div>
</div>
<hr />
<div class="form-group row mt-3">
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
<div class="col-lg-10">
<textarea id="note" class="form-control" name="note" rows="5"><?=(isset($item)) ? $item->note : ""?></textarea>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2"></label>
<div class="col-lg-10">
<button type="submit" class="btn btn-primary">Speichern</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
/*$('#adb_hausnummer_id').select2({
ajax: {
url: '<?=self::getUrl("AddressDB", "api", ["do" => "findAddress", "include_gst" => 1])?>',
delay: 250,
dataType: 'json'
},
minimumInputLength: 3,
placeholder: "Suche nach Straße / Hausnummer / Ort / Grundstücksnummer",
allowClear: true
});
$('#adb_hausnummer_id').on('select2:close', function(e) {
if(!$('#adb_hausnummer_id').val()) {
$('#new-address-toggle').show();
}
});
*/
$("#object_type").change(() => {
var type = $("#object_type").val();
if(type == "street") {
$("#address-search").hide();
$("#adb_hausnummer_id").val("").change();
$("#street-search").show();
$("#usage-checkbox-container").show();
} else {
$("#street-search").hide();
$("#adb_strasse_id").val("").change();
$("#address-search").show();
$("#usage-checkbox-container").hide();
}
});
$('#adb_strasse_id').select2({
ajax: {
url: '<?=self::getUrl("ConstructionConsent", "api")?>',
data: (params) => {
return {
q: params.term,
do: "findStreet",
project_id: $("#constructionconsentproject_id :selected").val()
}
},
delay: 250,
dataType: 'json'
},
minimumInputLength: 2,
placeholder: "Suche nach Straße",
allowClear: true
});
$('#adb_hausnummer_id').select2({
ajax: {
url: '<?=self::getUrl("ConstructionConsent", "api")?>',
data: (params) => {
return {
q: params.term,
do: "findAddress",
project_id: $("#constructionconsentproject_id :selected").val()
}
},
delay: 250,
dataType: 'json'
},
minimumInputLength: 2,
placeholder: "Suche nach Adresse",
allowClear: true
});
$('#plan_adb_hausnummer_id').select2({
ajax: {
url: '<?=self::getUrl("ConstructionConsent", "api")?>',
data: (params) => {
return {
q: params.term,
do: "findAddress",
project_id: $("#constructionconsentproject_id :selected").val()
}
},
delay: 250,
dataType: 'json'
},
minimumInputLength: 2,
placeholder: "Suche nach Adresse",
allowClear: true
});
$('#plan_adb_hausnummer_id').change( async () => {
if(!$("#plan_adb_hausnummer_id").val()) return;
var building_id = $('#plan_adb_hausnummer_id').val();
var type = $("#object_type").val();
// get plan image preview
try {
var response;
if(type == "building" ) {
response = await fetch('<?=self::getUrl("ConstructionConsent", "Api", ["do" => "getRimoPlanPreview"])?>&building_id=' + building_id + '&include_home_trench=1');
} else {
response = await fetch('<?=self::getUrl("ConstructionConsent", "Api", ["do" => "getRimoPlanPreview"])?>&building_id=' + building_id);
}
if (!response.ok) {
return false;
}
var resp_json = await response.json();
var plan_data = resp_json.result;
var img_mimetype = plan_data.image_mimetype;
var img_base64 = plan_data.image_base64;
var file_id = plan_data.file_id;
$("#plan_preview").attr("src" ,"data:" + img_mimetype + ";base64," + img_base64);
$("#submit_plan_file_id").val(file_id);
$("#delete-rimo-plan").show();
} catch (error) {
console.log("Exception fetching plan preview:");
console.log(error);
return false;
}
});
$("#consent_plan_image").change(() => {
var [file] = $("#consent_plan_image").prop("files");
if(file) {
$("#plan_preview").attr("src", URL.createObjectURL(file));
$("#delete-rimo-plan").show();
}
});
$("#constructionconsentproject_id").change(() => {
$("#adb_strasse_id").val("").change();
});
function deletePlan() {
$('#plan_adb_hausnummer_id').val("").change();
$("#submit_plan_file_id").val("");
$("#plan_preview").attr("src", "");
$("#delete-rimo-plan").hide();
$("#consent_plan_image").val("");
<?php if(isset($item) && $item->id): ?>
$.post("<?=self::getUrl("ConstructionConsent", "api")?>", {
do: "deleteRimoPlan",
id: <?=$item->id?>
});
<?php endif; ?>
}
$("#kg").on("input", updateGstnr);
$("#gst").on("input", updateGstnr);
async function updateGstnr() {
let kg = $("#kg").val();
let gst = $("#gst").val();
if(!kg || !gst) return;
$("#gstnr").val(kg + gst);
// update EZ
$("#ez").prop("readonly", true);
var response = await fetch('<?=self::getUrl("ConstructionConsent", "Api", ["do" => "getEz"])?>&kg=' + kg + '&gst=' + gst);
if (!response.ok) {
return false;
}
var resp_json = await response.json();
if (resp_json.status == "OK" && resp_json.result.ez) {
$("#ez").val(resp_json.result.ez);
}
$("#ez").prop("readonly", false);
}
$(window).bind("paste", (e) => {
var files = e.originalEvent.clipboardData.files;
if(files.length > 0) {
$("#consent_plan_image").prop("files", files);
$("#consent_plan_image").change();
window.notify("info", "Plan aus Zwischenablage übernommen.");
}
});
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
<style>
.popover {
background-color: #ffff99;
}
.popover .arrow::after {
border-top-color: #ffff99;
}
</style>
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>