Switched Preorder building source to AddressDB

This commit is contained in:
Frank Schubert
2022-09-08 14:58:18 +02:00
parent 490e729f69
commit c7bd7ea8f3
13 changed files with 724 additions and 243 deletions

View File

@@ -45,72 +45,27 @@
</div>
</div>
<div id="building-search">
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="building_id_search">Gebäude suchen *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="building_id_search" id="building_id_search" />
</div>
</div>
<div class="form-group row" id="building-search-results-section">
<label class="col-lg-2 col-form-label" for="building_units">Gebäude auswählen *</label>
<div class="col-lg-10">
<a href="#" class="text-success" onclick="refreshBuildingSearch()"><i class="fas fa-refresh"></i> Aktualisieren</a>
<table class="table table-sm table-striped table-hover mb-0" id="building-search-results">
<tr>
<th></th>
<th>Straße</th>
<th>PLZ</th>
<th>Ort</th>
<th>Wohneinheiten belegt</th>
<th>Code</th>
<th>OAN ID</th>
</tr>
</table>
<a href="#" class="text-success" onclick="refreshBuildingSearch()"><i class="fas fa-refresh"></i> Aktualisieren</a>
<p class="mt-2"><a class="btn btn-sm btn-outline-primary" href="<?=self::getUrl("Building", "add", ["network_id" => $campaign->network_id])?>" target="_blank"><i class="fas fa-plus"></i> Neues Gebäude anlegen</a></p>
</div>
</div>
<div class="form-group row" id="building-search-selected">
<input type="hidden" name="building_id" id="building_id" value="<?=$preorder->building_id?>" />
<label class="col-lg-2 col-form-label" for="">Ausgewähltes Gebäude</label>
<div class="col-lg-10">
<div class="card">
<div class="card-body">
<?php if(!$preorder->building_id): ?>
<table>
<tr>
<td class="check-mark align-top" style="font-size: 2.5em; width:40px;"><i class="fas fa-question text-warning"></i></td>
<td class="label">Bitte auswählen...</td>
</tr>
</table>
<?php else: ?>
<table>
<tr>
<td class="check-mark align-top" style="font-size: 2.5em; width:40px;"><i class="fas fa-check text-success"></i></td>
<td class="label">
<strong><?=$preorder->building->street?></strong><br />
<strong><?=$preorder->building->zip?> <?=$preorder->building->city?></strong><br />
Belegte Wohneinheiten: <?=$preorder->building->getUsedTerminationCount(true)?> von <?=($preorder->building->units) ? $preorder->building->units : 1?>
<?php if($preorder->building->code): ?>
<br /><?=$preorder->building->code?>
<?php endif; ?>
<?php if($preorder->building->oan_id): ?>
<br /><?=$preorder->building->oan_id?>
<?php endif; ?>
</td>
</tr>
</table>
<?php endif; ?>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price">Adresse *</label>
<div class="col-lg-10">
<select class="form-control" name="adb_hausnummer_id" id="adb_hausnummer_id" />
<?php if($preorder->adb_hausnummer_id): ?>
<option value="<?=$preorder->adb_hausnummer_id?>" selected="selected"><?=$preorder->adb_hausnummer->plz->plz?> <?=$preorder->adb_hausnummer->strasse->ortschaft->name?>, <?=$preorder->adb_hausnummer->strasse->name?> <?=$preorder->adb_hausnummer->hausnummer?></option>
<?php endif; ?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price">Wohneinheit *</label>
<div class="col-lg-10">
<select class="form-control" name="adb_wohneinheit_id" id="adb_wohneinheit_id" />
<?php if($preorder->adb_wohneinheit_id): ?>
<option value="<?=$preorder->adb_wohneinheit_id?>" selected="selected"><?=$preorder->adb_hausnummer->strasse->name?> <?=$preorder->adb_hausnummer->hausnummer?> <?=$preorder->adb_wohneinheit?></option>
<?php endif; ?>
</select>
</div>
</div>
@@ -198,35 +153,36 @@
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price">Netto Preis Periodisch *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price" id="price" value="<?=$preorder->price?>" />
<?php if($campaign->product_type != "setup_only"): ?>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price">Netto Preis Periodisch *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price" id="price" value="<?=$preorder->price?>" />
</div>
</div>
</div>
<?php if($me->isAdmin()): ?>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_nne">Preis NNE *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_nne" id="price_nne" value="<?=$preorder->price_nne?>" />
<?php if($me->isAdmin()): ?>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_nne">Preis NNE *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_nne" id="price_nne" value="<?=$preorder->price_nne?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_nbe">Preis NBE *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_nbe" id="price_nbe" value="<?=$preorder->price_nbe?>" />
</div>
</div>
<?php endif; ?>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="billing_delay">Verzögerter Verrechnungsstart *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="billing_delay" id="billing_delay" placeholder="Freimonate" value="<?=$preorder->billing_delay?>" />
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_nbe">Preis NBE *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_nbe" id="price_nbe" value="<?=$preorder->price_nbe?>" />
</div>
</div>
<?php endif; ?>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="billing_delay">Verzögerter Verrechnungsstart *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="billing_delay" id="billing_delay" placeholder="Freimonate" value="<?=$preorder->billing_delay?>" />
</div>
</div>
<h4 class="mt-4">Kundendaten</h4>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="company">Firma</label>
@@ -315,11 +271,7 @@
<script type="text/javascript">
$(document).ready(function() {
$('#building-search-results-section').hide();
<?php if(!$preorder->building_id): ?>
$('#building-search-selected').hide();
<?php endif; ?>
<?php if($preorder->type != "provision"): ?>
$('#setup-provision').hide();
<?php endif; ?>
@@ -374,32 +326,93 @@
}
});
$('#building_id_search').keyup(function() {
var search = $('#building_id_search').val();
var network_id = $('#network_id').val();
if(!network_id || search.length < 3) {
return;
}
$.post('<?=self::getUrl('Building','api')?>',
{
do: 'findBuildings',
network_id: network_id,
search: search
},
function(success) {
if(success.status == "OK") {
listSearchresults(success.result);
}
},
'json');
$('#adb_hausnummer_id').select2({
ajax: {
url: '<?=self::getUrl("AddressDB", "api", ["do" => "findAddress"])?>',
delay: 250,
dataType: 'json'
},
minimumInputLength: 3,
placeholder: "Suche nach Straße, Hausnummer, Ort"
});
$('#building_id_search').keydown(function() {
if(event.keyCode == 9 || event.keyCode == 13) {
event.preventDefault();
return false;
$('#adb_hausnummer_id').change(function() {
var hausnummer_id = $('#adb_hausnummer_id').val();
if(!hausnummer_id) return;
$.get('<?=self::getUrl("AddressDB", "Api")?>',
{
do: "getUnits",
hausnummer_id: hausnummer_id
},
function(success) {
if(success.status != "OK") {
return;
}
$('#adb_wohneinheit_id').empty();
$('#adb_wohneinheit_id').append("<option></option>")
success.result.units.forEach(function(unit) {
let opt = "<option value='" + unit.id + "'>";
opt += unit.zip + " " + unit.city + ", " + unit.street + " " + unit.housenumber;
if(unit.extra) {
opt += " " + unit.extra;
}
/*let extras = new Array();
if(unit.block) extras.push("Block " + unit.block);
if(unit.stiege) extras.push("Stiege " + unit.stiege);
if(unit.stock) extras.push("Stock " + unit.stock);
if(unit.tuer) extras.push("Tür " + unit.tuer);
if(unit.zusatz) extras.push(unit.zusatz);
if(extras.length) {
opt += " " + extras.join(", ");
}*/
if(unit.nutzung) {
opt += " " + unit.nutzung;
}
opt += "</option>";
$('#adb_wohneinheit_id').append(opt);
$('#adb_wohneinheit_id').addClass("is-invalid");
$('#adb_wohneinheit_id')
.data("zip", unit.zip)
.data("city", unit.city)
.data("street", unit.street)
.data("housenumber", unit.housenumber)
.data("block", unit.block)
.data("stiege", unit.stiege)
.data("stock", unit.stock)
.data("tuer", unit.tuer)
.data("zusatz", unit.zusatz);
});
},
"json");
});
$('#adb_wohneinheit_id').change(function() {
val = $('#adb_wohneinheit_id').val();
if($('#adb_wohneinheit_id option').length < 2) return;
if(val) {
$('#adb_wohneinheit_id').removeClass("is-invalid");
$('input[name=street]').val($('#adb_wohneinheit_id').data("street"));
$('input[name=zip]').val($('#adb_wohneinheit_id').data("zip"));
$('input[name=city]').val($('#adb_wohneinheit_id').data("city"));
} else {
$('#adb_wohneinheit_id').addClass("is-invalid");
}
});
@@ -441,6 +454,8 @@
});
});
function updateSetupProduct(type) {
if(type == "provision") {
@@ -456,98 +471,6 @@
}
}
function listSearchresults(data) {
resetSearchresults();
var count = data.buildings.length;
var count_total = data.count;
if(!("buildings" in data) || !count) {
$('#building-search-results-section').hide();
return false;
}
$('#building-search-results-section').show();
data.buildings.forEach(function(b) {
var line = '<tr class="result result-' + b.id + ' pointer" onclick="selectBuilding(' + b.id + ')">';
line += '<td><input type="checkbox" readonly="readonly" onclick="selectBuilding(' + b.id + ')" name="building_result_check" value="' + b.id + '"';
line += 'data-zip="' + b.zip + '" data-city="' + b.city + '" data-street="' + b.street + '" data-code="' + b.code + '" data-oanid="' + b.oan_id + '" data-units="' + b.units + '" data-units-used="' + b.units_used + '" /></td>';
line += "<td>" + b.street + "</td>";
line += "<td>" + b.zip + "</td>";
line += "<td>" + b.city + "</td>";
line += "<td>" + b.units_used + " / " + b.units + "</td>";
line += "<td>" + b.code + "</td>";
line += "<td>" + b.oan_id + "</td>";
$('#building-search-results').append(line);
});
console.log(count);
console.log(count_total);
if(count < count_total) {
$('#building-search-results').append('<tr class="results-more bg-warning"><td><i class="fas fa-warning"></i></td><td colspan="5">Es wurden ' + (count_total - count) + ' weitere Suchergebnisse gefunden. Bitte verfeinern Sie die Suche!</td></tr>');
} else {
$('#building-search-results .results-more').remove();
}
}
function resetSearchresults() {
$('#building-search-results .result').each(function() {
this.remove();
});
$('#building-search-results .results-more').remove();
}
function selectBuilding(id) {
if($('input[name=building_result_check][value=' + id + ']').prop('checked')) {
$('input[name=building_result_check][value=' + id + ']').prop('checked', false);
$('#building-search-selected .label').removeClass("font-weight-bold").text("Bitte auswählen...");
$('#building-search-selected .check-mark i').removeClass().addClass("fas fa-question text-warning");
} else {
// check selected checkbox and uncheck all others
$('input[name=building_result_check][value=' + id + ']').prop('checked', true);
$('input[name=building_result_check]').each(function() {
if($(this).val() != id) {
$(this).prop('checked', false);
}
});
// write selected buildings address
var street = $('input[name=building_result_check][value=' + id + ']').data("street");
var zip = $('input[name=building_result_check][value=' + id + ']').data("zip");
var city = $('input[name=building_result_check][value=' + id + ']').data("city");
var code = $('input[name=building_result_check][value=' + id + ']').data("code");
var oan_id = $('input[name=building_result_check][value=' + id + ']').data("oanid");
var units = $('input[name=building_result_check][value=' + id + ']').data("units");
var units_used = $('input[name=building_result_check][value=' + id + ']').data("units-used");
$('input[name=street]').val(street);
$('input[name=zip]').val(zip);
$('input[name=city]').val(city);
var label = street + "<br />" + zip + " " + city;
label += "<br /><div style='font-weight: normal;'>Belegte Wohneinheiten: " + units_used + " von " + units;
if(code || oan_id) {
if(code) {
label += "<br />Code: " + code;
}
if(oan_id) {
label += "<br />OAN ID: " + oan_id;
}
}
label += "</div>";
$('#building-search-selected .label').addClass("font-weight-bold").html(label);
$('#building-search-selected .check-mark i').removeClass().addClass("fas fa-check text-success");
$('#building-search-selected').show();
$('#building_id').val(id);
showPreorderForm();
}
}
function showPreorderForm() {
@@ -557,18 +480,6 @@
}
function resetBuildingSearch() {
resetSearchresults();
$('#building-search-selected').hide();
$('#building-search-selected .label').removeClass("font-weight-bold").text("Bitte auswählen...");
$('#building-search-selected .check-mark i').removeClass().addClass("fas fa-question text-warning");
}
function refreshBuildingSearch() {
resetBuildingSearch();
$('#building_id_search').keyup();
}
function updateProduct() {
var pid = $('#product_id').val();

View File

@@ -45,10 +45,32 @@
</div>
</div>
<div id="building-search">
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="city_search">Ort *</label>
<div class="col-lg-10">
<input type="hidden" name="adb_ortschaft_id" value="" />
<input type="text" class="form-control" name="city_search" id="city_search" placeholder="Suche nach PLZ oder Ort" />
</div>
</div>
<div id="city-search-results-section" class="form-group row">
<label class="col-lg-2 col-form-label" for="building_units">Ortschaft auswählen *</label>
<div class="col-lg-10">
<table class="table table-sm table-striped table-hover mb-0" id="city-search-results">
<tr>
<th></th>
<th>Ortschaft</th>
<th>Gemeinde</th>
</tr>
</table>
</div>
</div>
<div id="building-search" class="hidden">
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="building_id_search">Gebäude suchen *</label>
<label class="col-lg-2 col-form-label" for="building_id_search">Adresse suchen *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="building_id_search" id="building_id_search" />
</div>
@@ -56,7 +78,7 @@
<div class="form-group row" id="building-search-results-section">
<label class="col-lg-2 col-form-label" for="building_units">Gebäude auswählen *</label>
<label class="col-lg-2 col-form-label" for="building_units">Adresse auswählen *</label>
<div class="col-lg-10">
<a href="#" class="text-success" onclick="refreshBuildingSearch()"><i class="fas fa-refresh"></i> Aktualisieren</a>
<table class="table table-sm table-striped table-hover mb-0" id="building-search-results">
@@ -316,6 +338,7 @@
$(document).ready(function() {
$('#building-search-results-section').hide();
$('#city-search-results-section').hide();
<?php if(!$preorder->building_id): ?>
$('#building-search-selected').hide();
<?php endif; ?>
@@ -374,15 +397,49 @@
}
});
$('#city_search').keyup(function() {
var search = $('#city_search').val();
if(search.length < 3) {
return;
}
$.post('<?=self::getUrl('AddressDB','api')?>',
{
do: 'findCities',
search: search
},
function(success) {
if(success.status == "OK") {
listCitySearchresults(success.result);
}
},
'json'
);
});
$('#building_id_search').keyup(function() {
var search = $('#building_id_search').val();
var network_id = $('#network_id').val();
var city_id = $("input[name=city_result_check]:checked").val();
console.log(city_id);
if(!city_id) {
return;
}
if(!network_id || search.length < 3) {
return;
}
$.post('<?=self::getUrl('Building','api')?>',
/*$.post('<?=self::getUrl('Building','api')?>',
{
do: 'findBuildings',
network_id: network_id,
@@ -393,7 +450,31 @@
listSearchresults(success.result);
}
},
'json');
'json'
);*/
$.post('<?=self::getUrl('AddressDB','api')?>',
{
do: 'findBuildings',
city_id: city_id,
search: search
},
function(success) {
if(success.status == "OK") {
listSearchresults(success.result);
}
},
'json'
);
});
$('#city_search').keydown(function() {
if(event.keyCode == 9 || event.keyCode == 13) {
event.preventDefault();
return false;
}
});
$('#building_id_search').keydown(function() {
@@ -441,6 +522,8 @@
});
});
function updateSetupProduct(type) {
if(type == "provision") {
@@ -456,6 +539,57 @@
}
}
function listCitySearchresults(data) {
resetCitySearchresults();
var count = data.cities.length;
if(!("cities" in data) || !count) {
$('#city-search-results-section').hide();
return false;
}
$('#city-search-results-section').show();
data.cities.forEach(function(b) {
console.log(b);
var line = '<tr class="result result-' + b.id + ' pointer" onclick="selectCity(' + b.id + ')">';
line += '<td><input type="checkbox" readonly="readonly" onclick="selectCity(' + b.id + ')" name="city_result_check" value="' + b.id + '" ';
line += ' data-city="' + b.name + '" data-gemeinde_id="' + b.gemeinde_id + '" data-gemeinde="' + b.gemeinde +'" data-kennziffer="' + b.kennziffer + '" /></td>';
line += "<td>" + b.name + "</td>";
line += "<td>" + b.gemeinde + "</td>";
line += "</tr>";
$('#city-search-results').append(line);
});
}
function resetCitySearchresults() {
$('#city-search-results .result').each(function() {
this.remove();
});
}
function selectCity(id) {
console.log("in selectCity");
if($('input[name=city_result_check][value=' + id + ']').prop('checked')) {
$('input[name=city_result_check][value=' + id + ']').prop('checked', false);
$('#city-search-selected .label').removeClass("font-weight-bold").text("Bitte auswählen...");
$('#city-search-selected .check-mark i').removeClass().addClass("fas fa-question text-warning");
$('#city-search').hide();
} else {
// check selected checkbox and uncheck all others
$('input[name=city_result_check][value=' + id + ']').prop('checked', true);
$('input[name=city_result_check]').each(function() {
if($(this).val() != id) {
$(this).prop('checked', false);
}
});
$('#building-search').show();
}
}
function listSearchresults(data) {
resetSearchresults();
var count = data.buildings.length;
@@ -479,6 +613,7 @@
line += "<td>" + b.units_used + " / " + b.units + "</td>";
line += "<td>" + b.code + "</td>";
line += "<td>" + b.oan_id + "</td>";
line += "</tr>";
$('#building-search-results').append(line);
});
@@ -549,6 +684,8 @@
}
}
function showPreorderForm() {
}

View File

@@ -49,7 +49,19 @@
<td><?=$preorder->campaign->name?></td>
<td><?=__($preorder->type, "preorder")?></td>
<td><?=($preorder->company) ? $preorder->company : $preorder->firstname." ".$preorder->lastname?></td>
<?php if($preorder->building_id): ?>
<td><?=$preorder->building->street?><br /><?=$preorder->building->zip?> <?=$preorder->building->city?></td>
<?php elseif($preorder->adb_hausnummer_id): ?>
<td>
<?=$preorder->adb_hausnummer->strasse->name?>
<?=$preorder->adb_hausnummer->hausnummer?><br />
<?=($preorder->adb_wohneinheit_id) ? $preorder->adb_wohneinheit."<br />" : ""?>
<?=$preorder->adb_hausnummer->plz->plz?>
<?=$preorder->adb_hausnummer->strasse->ortschaft->name?>
</td>
<?php else: ?>
<td></td>
<?php endif; ?>
<td><?=($preorder->partner_id) ? $preorder->partner->getCompanyOrName() : ""?></td>
<td><?=($preorder->termination) ? $preorder->termination->code : ""?></td>
<td><?=date('d.m.Y H:i', $preorder->create)?></td>