Added cluster_id to preorder API endpoints

This commit is contained in:
Frank Schubert
2022-12-19 14:10:29 +01:00
parent 33a5475d91
commit 9b8bde77ec
11 changed files with 215 additions and 49 deletions

View File

@@ -0,0 +1,7 @@
<?php
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/EmptyPHP.php to edit this template
*/

View File

@@ -0,0 +1,108 @@
<?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("Contract")?>">Aktive Produkte</a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Contract", "view", ['id' => $contract->id])?>"><?=$contract->product_name?> [<?=$contract->matchcode?>]</a></li>
<li class="breadcrumb-item active">Konfiguration</li>
</ol>
</div>
<h4 class="page-title">Aktives Produkt</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<a href="<?=self::getUrl("Contract","View", ['id' => $contract->id, 'filter' => $filter, 's' => $s])?>" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Vertragsansicht</a>
</div>
</div>
<div class="card">
<div class="card-body">
<h3 class="text-center mb-3"><?=$contract->product_name?> (<?=$contract->id?>)</h3>
<table class="table table-sm table-striped view-table">
<tr>
<th style="max-width: 50vw;">Matchcode:</th>
<td style="width: 50vw;"><?=$contract->matchcode?></td>
</tr>
<tr>
<th>Vertragsinhaber:</th>
<td><a href="<?=self::getUrl("Address", "View", ["id" => $contract->owner->id])?>"><?=$contract->owner->getCompanyOrName()?> (<?=$contract->owner->customer_number?>)</a></td>
</tr>
<tr>
<th>Produkt:</th>
<td><?=$contract->product_name?></td>
</tr><tr>
<th>Produkt Info:</th>
<td><?=$contract->product_info?></td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-body">
<h4 class="text-center mb-3">Konfiguration bearbeiten</h4>
<?php if(is_array($groups) && count($groups)): ?>
<form method="post" action="<?=self::getUrl("Contractconfig", "Save")?>">
<input type="hidden" name="contract_id" value="<?=$contract->id?>" />
<table class="table table-sm table-borderless view-table">
<?php foreach($groups as $group): ?>
<tr class="bg-light">
<th><h4><u><?=$group->name?></u></h4></td>
<td></td>
</tr>
<?php foreach($group->items as $item): ?>
<tr>
<th style="max-width: 50vw;"><?=$item->displayname?>:</th>
<td style="width: 50vw;">
<?php if($item->type == "enum"): ?>
<select class="form-control" name="itemvalues[<?=$item->id?>]">
<?php foreach($item->getTypedataArray() as $option): ?>
<option value="<?=$option?>" <?=($item->getValue() == $option) ? "selected='selected'" : ""?>><?=$option?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<input type="text" class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>" name="itemvalues[<?=$item->id?>]" value="<?=(isset($request)) ? $request->itemvalues[$item->id] : $item->getValue()?>" />
<?php endif; ?>
<small><?=$item->description?></small>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</table>
<div class="row">
<div class="col text-center">
<input type="submit" class="btn btn-primary" value="Konfiguration speichern" />
</div>
</div>
</form>
<?php endif; ?>
</div>
</div>
<div class="card">
<div class="card-body">
<a href="<?=self::getUrl("Contract","View", ['id' => $contract->id, 'filter' => $filter, 's' => $s])?>" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Vertragsansicht</a>
</div>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -8,7 +8,8 @@
<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("Contract")?>">Aktive Produkte</a></li>
<li class="breadcrumb-item active"><?=$contract->product_name?> [<?=$contract->matchcode?>]</li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Contract", "view", ['id' => $contract->id])?>"><?=$contract->product_name?> [<?=$contract->matchcode?>]</a></li>
<li class="breadcrumb-item active">Konfiguration</li>
</ol>
</div>
<h4 class="page-title">Aktives Produkt</h4>
@@ -77,6 +78,7 @@
<?php else: ?>
<input type="text" class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>" name="itemvalues[<?=$item->id?>]" value="<?=(isset($request)) ? $request->itemvalues[$item->id] : $item->getValue()?>" />
<?php endif; ?>
<small><?=$item->description?></small>
</td>
</tr>
<?php endforeach; ?>

View File

@@ -130,6 +130,13 @@ class ADBGemeindeModel {
}
}
if(array_key_exists("netzgebiet_extref", $filter)) {
$netzgebiet_extref = FronkDB::singleton()->escape($filter['netzgebiet_extref']);
if($netzgebiet_extref) {
$where .= " AND Netzgebiet.extref = '$netzgebiet_extref'";
}
}
if(array_key_exists("code", $filter)) {
$code = $filter['code'];
if(is_numeric($code)) {

View File

@@ -1,6 +1,7 @@
<?php
class ADBHausnummer extends mfBaseModel {
private $netzgebiet;
private $ortschaft;
private $strasse;
private $plz;
@@ -79,6 +80,11 @@ class ADBHausnummer extends mfBaseModel {
return $this->freigaben;
}
if($name == "netzgebiet") {
$this->netzgebiet = new ADBNetzgebiet($this->netzgebiet_id);
return $this->netzgebiet;
}
if($name == "ortschaft") {
$this->ortschaft = new ADBOrtschaft($this->ortschaft_id);
return $this->ortschaft;

View File

@@ -129,6 +129,13 @@ class ADBOrtschaftModel {
}
}
if(array_key_exists("netzgebiet_extref", $filter)) {
$netzgebiet_extref = FronkDB::singleton()->escape($filter['netzgebiet_extref']);
if($netzgebiet_extref) {
$where .= " AND Netzgebiet.extref = '$netzgebiet_extref'";
}
}
if(array_key_exists("gemeinde_id", $filter)) {
$gemeinde_id = $filter['gemeinde_id'];
if(is_numeric($gemeinde_id)) {

View File

@@ -128,6 +128,13 @@ class ADBPlzModel {
}
}
if(array_key_exists("netzgebiet_extref", $filter)) {
$netzgebiet_extref = FronkDB::singleton()->escape($filter['netzgebiet_extref']);
if($netzgebiet_extref) {
$where .= " AND Netzgebiet.extref = '$netzgebiet_extref'";
}
}
if(array_key_exists("gemeinde_id", $filter)) {
$gemeinde_id = $filter['gemeinde_id'];
if(is_numeric($gemeinde_id)) {

View File

@@ -80,12 +80,13 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$city = trim($get['city']);
$district = trim($get['district']);
$zip = trim($get['zip']);
$search_cluster_id = trim($get['cluster_id']);
if(!$city) {
$city = $search;
}
if(!$city && !$zip) {
if(!$city && !$zip && !$search_cluster_id) {
return mfResponse::BadRequest(['message' => "No search parameters"]);
}
@@ -101,6 +102,10 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$city_search['netzgebiet_id'] = $this->filter_salescluster_ids;
}
if($search_cluster_id) {
$city_search['netzgebiet_extref'] = $search_cluster_id;
}
if($this->district_is_city) {
$results = ADBOrtschaftModel::search($city_search);
} else {
@@ -122,10 +127,11 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$get = array_merge($this->post, $this->get);
// search parameter is unofficially deprecated but still supported
$search = trim($get['search']);
$city = trim($get['city']);
$district = trim($get['district']);
$zip = trim($get['zip']);
$search = $this->db()->escape(trim($get['search']));
$city = $this->db()->escape(trim($get['city']));
$district = $this->db()->escape(trim($get['district']));
$zip = $this->db()->escape(trim($get['zip']));
$search_cluster_id = $this->db()->escape(trim($get['cluster_id']));
if(!$district) {
$district = $search;
@@ -138,23 +144,23 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$where = "1=1";
if($district && $district != "%") {
$city_search = ['ortschaft%' => $district];
$where .= " AND ortschaft like '$district%'";
}
if($city && $city != "%") {
$city_search = ['name%' => $city];
$where .= " AND gemeinde like '$city%'";
}
if($zip && $zip != "%") {
$city_search['plz%'] = $zip;
$where .= " AND plz like '$zip%'";
}
if(count($this->filter_salescluster_ids)) {
$city_search['netzgebiet_id'] = $this->filter_salescluster_ids;
$where .= " AND netzgebiet_id IN (".join(", ", $this->filter_salescluster_ids).")";
}
if($search_cluster_id) {
$where .= " AND netzgebiet_extref='$search_cluster_id'";
}
$cities = [];
$sql = "SELECT gemeinde, ortschaft FROM view_hausnummer WHERE $where GROUP BY gemeinde,ortschaft_id ORDER BY gemeinde, ortschaft";
@@ -169,22 +175,6 @@ class AddressdbApicontroller extends mfBaseApicontroller {
}
}
/*foreach(ADBGemeindeModel::search($city_search) as $gem) {
$districts = [];
if($district) {
foreach(ADBOrtschaftModel::search(["gemeinde_id" => $gem->id, "name%" => $district]) as $ort) {
$districts[] = $ort->name;
}
} else {
foreach($gem->ortschaften as $ort) {
$districts[] = $ort->name;
}
}
$cities[$gem->name] = $districts;
}*/
return mfResponse::Ok(['cities' => $cities]);
}
@@ -195,8 +185,9 @@ class AddressdbApicontroller extends mfBaseApicontroller {
// search parameter is unofficially deprecated but still supported
$search = trim($get['search']);
$zip = trim($get['zip']);
$search_cluster_id = trim($get['cluster_id']);
if(!$search && !$zip) {
if(!$search && !$zip && !$search_cluster_id) {
return mfResponse::BadRequest(['message' => "Searchstring cannot be empty!"]);
}
@@ -209,6 +200,11 @@ class AddressdbApicontroller extends mfBaseApicontroller {
if(count($this->filter_salescluster_ids)) {
$zip_search['netzgebiet_id'] = $this->filter_salescluster_ids;
}
if($search_cluster_id) {
$zip_search['netzgebiet_extref'] = $search_cluster_id;
}
//var_dump($zip_search);exit;
$results = ADBPlzModel::search($zip_search);
@@ -227,12 +223,13 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$get = array_merge($this->post, $this->get);
// search parameter is unofficially deprecated but still supported
$search = trim($get['search']);
$street = trim($get['street']);
$city = trim($get['city']);
$zip = trim($get['zip']);
$search = $this->db()->escape(trim($get['search']));
$street = $this->db()->escape(trim($get['street']));
$city = $this->db()->escape(trim($get['city']));
$zip = $this->db()->escape(trim($get['zip']));
$search_cluster_id = $this->db()->escape(trim($get['cluster_id']));
if(!$search && !$street && !$city && !$zip) {
if(!$search && !$street && !$city && !$zip && !$search_cluster_id) {
return mfResponse::BadRequest(['message' => "No search parameters"]);
}
@@ -241,31 +238,26 @@ class AddressdbApicontroller extends mfBaseApicontroller {
}
$where = "1=1";
$street_search = ["name%" => $street];
$street = $this->db()->escape($street);
$where .= " AND strasse like '$street%'";
if($city) {
if($this->district_is_city) {
$street_search['ortschaft%'] = $city;
$city = $this->db()->escape($city);
$where .= " AND ortschaft like '$city%'";
} else {
$street_search['gemeinde%'] = $city;
$city = $this->db()->escape($city);
$where .= " AND gemeinde like '$city%'";
}
}
if($zip) {
$street_search['plz%'] = $zip;
$zip = $this->db()->escape($zip);
$where .= " AND plz like '$zip%'";
}
if(count($this->filter_salescluster_ids)) {
$street_search['netzgebiet_id'] = $this->filter_salescluster_ids;
$where .= " AND netzgebiet_id IN (".join(", ", $this->filter_salescluster_ids).")";
}
if($search_cluster_id) {
$where .= " AND netzgebiet_extref='$search_cluster_id'";
}
$streets = [];
$sql = "SELECT strasse FROM view_hausnummer WHERE $where GROUP BY strasse ORDER BY strasse";
@@ -277,13 +269,6 @@ class AddressdbApicontroller extends mfBaseApicontroller {
}
}
/*$results = ADBStrasseModel::search($street_search);
foreach($results as $result) {
$streets[] = $result->name;
}*/
$streets = array_unique($streets);
sort($streets);
@@ -373,6 +358,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$tmp_addresses[$address_key] = [
'sort_key' => $sort_key,
'oaid' => $data->hausnummer_oaid,
'cluster_id' => $data->netzgebiet_extref,
'zip' => $data->plz,
'city' => ($this->district_is_city) ? $data->ortschaft : $data->gemeinde,
'district' => $data->ortschaft,
@@ -473,6 +459,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$new_address = [];
$new_address['oaid'] = $u['oaid'];
$new_address['building_oaid'] = $ta['oaid'];
$new_address['cluster_id'] = $ta['cluster_id'];
$new_address['street'] = $ta['street'];
$new_address['housenumber'] = $ta['housenumber'];
$new_address['zip'] = $ta['zip'];
@@ -507,6 +494,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
// unofficially supporting GET and POST in v1
$get = array_merge($this->post, $this->get);
$search_cluster_id = $this->db()->escape(trim($get['cluster_id']));
$search_street = $this->db()->escape(trim($get['street']));
$search_zip = $this->db()->escape(trim($get['zip']));
$search_district = $this->db()->escape(trim($get['district']));
@@ -549,11 +537,14 @@ class AddressdbApicontroller extends mfBaseApicontroller {
if(count($this->filter_salescluster_ids)) {
$where .= " AND Hausnummer.netzgebiet_id IN (".implode(",", $this->filter_salescluster_ids).")";
}
if($search_cluster_id) {
$where .= " AND netzgebiet_extref='$search_cluster_idh'";
}
//echo $where;
//var_dump($this->filter_salescluster_ids);exit;
$sql = AddressDB::$wohneinheit_query;
$sql .= " WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(num), num, LENGTH(tuer), tuer";
$sql .= "\n WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(num), num, LENGTH(tuer), tuer";
//$sql = "SELECT * FROM view_wohneinheit WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(num), num, LENGTH(tuer), tuer";
$this->log->debug($sql);
@@ -590,6 +581,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$tmp_addresses[$address_key] = [
'oaid' => $data->hausnummer_oaid,
'cluster_id' => $data->netzgebiet_extref,
'zip' => $data->plz,
'city' => ($this->district_is_city) ? $data->ortschaft : $data->gemeinde,
'district' => $data->ortschaft,
@@ -629,6 +621,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$new_address = [];
$new_address['oaid'] = $u['oaid'];
$new_address['building_oaid'] = $ta['oaid'];
$new_address['cluster_id'] = $ta['cluster_id'];
$new_address['street'] = $ta['street'];
$new_address['housenumber'] = $ta['housenumber'];
$new_address['zip'] = $ta['zip'];

View File

@@ -60,6 +60,7 @@ class Preorder extends mfBaseModel {
$a['address_info'] = ($this->address_info) ? $this->address_info : null;
$address = [];
$address['cluster_id'] = $hausnummer->netzgebiet->extref;
$address['street'] = $hausnummer->strasse->name;
$address['housenumber'] = $hausnummer->hausnummer;
$address['zip'] = $hausnummer->plz->plz;

View File

@@ -101,6 +101,11 @@ paths:
in: query
schema:
type: string
- name: cluster_id
description: Cluster ID
in: query
schema:
type: string
- name: street
description: Straße Suchbegriff
in: query
@@ -188,6 +193,11 @@ paths:
description: Sucht nach Straßen
operationId: findStreets
parameters:
- name: cluster_id
description: Cluster ID
in: query
schema:
type: string
- name: street
description: Straße Suchbegriff
in: query
@@ -235,6 +245,11 @@ paths:
description: Sucht nach Postleitzahlen
operationId: findZips
parameters:
- name: cluster_id
description: Cluster ID
in: query
schema:
type: string
- name: zip
description: Postleitzahl Suchbegriff
in: query
@@ -272,6 +287,11 @@ paths:
description: Sucht nach Gemeinden
operationId: findCity
parameters:
- name: cluster_id
description: Cluster ID
in: query
schema:
type: string
- name: zip
description: Postleitzahl Suchbegriff
in: query
@@ -314,6 +334,11 @@ paths:
description: Sucht nach Ortsteilen
operationId: findDistrict
parameters:
- name: cluster_id
description: Cluster ID
in: query
schema:
type: string
- name: zip
description: Postleitzahl Suchbegriff
in: query
@@ -793,6 +818,9 @@ components:
addressResponse:
type: object
properties:
cluster_id:
type: string
description: Cluster ID
street:
type: string
description: Strasse der Anschlussadresse