Merge branch 'preorder-improve-map' into 'master'

Added Tickets View for Customers

See merge request fronk/thetool!999
This commit is contained in:
Luca Haid
2025-02-06 10:24:32 +00:00
4 changed files with 708 additions and 617 deletions
+1
View File
@@ -27,6 +27,7 @@
<a href="<?=self::getUrl("Address","edit", ['id' => $address->id, 's' => $s, 'f' => "view"])?>" class="btn btn-outline-success"><i class="fas fa-edit"></i> Adresse bearbeiten</a> <a href="<?=self::getUrl("Address","edit", ['id' => $address->id, 's' => $s, 'f' => "view"])?>" class="btn btn-outline-success"><i class="fas fa-edit"></i> Adresse bearbeiten</a>
</div> </div>
<div class="float-right"> <div class="float-right">
<a href="<?=self::getUrl("Address","tickets", ["address_id" => $address->id])?>" class="btn btn-purple mr-1"><i class="far fa-user-headset"></i> Tickets</a>
<a href="<?=self::getUrl("Address","invoice", ["address_id" => $address->id])?>" class="btn btn-purple mr-1"><i class="far fa-file-invoice-dollar"></i> Rechungsübersicht</a> <a href="<?=self::getUrl("Address","invoice", ["address_id" => $address->id])?>" class="btn btn-purple mr-1"><i class="far fa-file-invoice-dollar"></i> Rechungsübersicht</a>
</div> </div>
</div> </div>
+144 -108
View File
@@ -4,13 +4,13 @@ class AddressController extends mfBaseController {
private $filter; private $filter;
protected function init() { protected function init() {
$this->needlogin=true; $this->needlogin = true;
$me = new User(); $me = new User();
$me->loadMe(); $me->loadMe();
$this->me = $me; $this->me = $me;
$this->layout()->set("me",$me); $this->layout()->set("me", $me);
if(!$me->is(["Admin", "salespartner"])) { if (!$me->is(["Admin", "salespartner"])) {
$this->redirect("Dashboard"); $this->redirect("Dashboard");
} }
} }
@@ -20,21 +20,21 @@ class AddressController extends mfBaseController {
iF(!is_array($rfilter)) { iF(!is_array($rfilter)) {
$rfilter = []; $rfilter = [];
} }
if(!array_key_exists("addresstype", $rfilter)) { if (!array_key_exists("addresstype", $rfilter)) {
$rfilter["addresstype"] = []; $rfilter["addresstype"] = [];
} }
if($this->request->resetFilter) { if ($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME.'-Address-filter']); unset($_SESSION[MFAPPNAME . '-Address-filter']);
} }
$filter = []; $filter = [];
if(is_array($this->request->filter)) { if (is_array($this->request->filter)) {
$filter = $this->request->filter; $filter = $this->request->filter;
$_SESSION[MFAPPNAME.'-Address-filter'] = $filter; $_SESSION[MFAPPNAME . '-Address-filter'] = $filter;
} else { } else {
if(array_key_exists(MFAPPNAME.'-Address-filter', $_SESSION) && count($_SESSION[MFAPPNAME.'-Address-filter'])) { if (array_key_exists(MFAPPNAME . '-Address-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-Address-filter'])) {
$filter = $_SESSION[MFAPPNAME.'-Address-filter']; $filter = $_SESSION[MFAPPNAME . '-Address-filter'];
} }
} }
@@ -47,7 +47,7 @@ class AddressController extends mfBaseController {
$pagination['count'] = 25; $pagination['count'] = 25;
$pagination['maxItems'] = 0; $pagination['maxItems'] = 0;
if(is_numeric($this->request->s)) { if (is_numeric($this->request->s)) {
$pagination['start'] = intval($this->request->s); $pagination['start'] = intval($this->request->s);
} }
//var_dump($filter);exit; //var_dump($filter);exit;
@@ -61,7 +61,7 @@ class AddressController extends mfBaseController {
$last_export = false; $last_export = false;
$bmd_export_ts = new mfConfig("bmd.export.ts"); $bmd_export_ts = new mfConfig("bmd.export.ts");
if($bmd_export_ts->value()) { if ($bmd_export_ts->value()) {
$last_export = $bmd_export_ts->value(); $last_export = $bmd_export_ts->value();
} }
$this->layout()->set("last_bmd_export", $last_export); $this->layout()->set("last_bmd_export", $last_export);
@@ -73,11 +73,11 @@ class AddressController extends mfBaseController {
private function getPreparedFilter($filter) { private function getPreparedFilter($filter) {
$new_filter = []; $new_filter = [];
if(is_array($filter) && count($filter)) { if (is_array($filter) && count($filter)) {
$new_filter['add-where'] = ""; $new_filter['add-where'] = "";
if(array_key_exists("kunde", $filter) && $filter["kunde"]) { if (array_key_exists("kunde", $filter) && $filter["kunde"]) {
$kunde = $this->db()->escape($filter['kunde']); $kunde = $this->db()->escape($filter['kunde']);
// if kunde contains ß or ss we want to search both cases but not with % because it can lead to wrong results // if kunde contains ß or ss we want to search both cases but not with % because it can lead to wrong results
if (strpos($kunde, "ß") !== false || strpos($kunde, "ss") !== false) { if (strpos($kunde, "ß") !== false || strpos($kunde, "ss") !== false) {
@@ -90,25 +90,25 @@ class AddressController extends mfBaseController {
} }
} }
if(!array_key_exists("parents_only", $filter)) { if (!array_key_exists("parents_only", $filter)) {
$new_filter["parents_only"] = 1; $new_filter["parents_only"] = 1;
} }
if(array_key_exists("fibu_account_number", $filter) && $filter['fibu_account_number']) { if (array_key_exists("fibu_account_number", $filter) && $filter['fibu_account_number']) {
$new_filter['fibu_or_supplier_account_number'] = $filter['fibu_account_number']."%"; $new_filter['fibu_or_supplier_account_number'] = $filter['fibu_account_number'] . "%";
unset($filter['fibu_account_number']); unset($filter['fibu_account_number']);
} }
if(!array_key_exists("customer_number", $filter) || !$filter["customer_number"]) { if (!array_key_exists("customer_number", $filter) || !$filter["customer_number"]) {
if(array_key_exists("type", $filter)) { if (array_key_exists("type", $filter)) {
if($filter["type"] == "systemowner") { if ($filter["type"] == "systemowner") {
$new_filter["customer_or_fibu_numbers"] = true; $new_filter["customer_or_fibu_numbers"] = true;
} elseif($filter["type"] == "others") { } elseif ($filter["type"] == "others") {
$new_filter["customer_or_fibu_numbers"] = false; $new_filter["customer_or_fibu_numbers"] = false;
} }
} else { } else {
if(defined("TT_ADDRESS_FILTER_DEFAULT_SYSOWNER") && TT_ADDRESS_FILTER_DEFAULT_SYSOWNER) { if (defined("TT_ADDRESS_FILTER_DEFAULT_SYSOWNER") && TT_ADDRESS_FILTER_DEFAULT_SYSOWNER) {
$new_filter["customer_or_fibu_numbers"] = true; // default $new_filter["customer_or_fibu_numbers"] = true; // default
} }
} }
@@ -116,7 +116,7 @@ class AddressController extends mfBaseController {
unset($filter["customer_number"]); unset($filter["customer_number"]);
} }
foreach($filter as $name => $value) { foreach ($filter as $name => $value) {
$new_filter[$name] = $value; $new_filter[$name] = $value;
} }
} }
@@ -145,7 +145,7 @@ class AddressController extends mfBaseController {
//var_dump($address->links_to);exit; //var_dump($address->links_to);exit;
if(!$address->id) { if (!$address->id) {
$this->layout()->setFlash("Addresse nicht gefunden", "error"); $this->layout()->setFlash("Addresse nicht gefunden", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
@@ -156,13 +156,13 @@ class AddressController extends mfBaseController {
$this->layout()->setTemplate("Address/invoice"); $this->layout()->setTemplate("Address/invoice");
$address_id = $this->request->address_id; $address_id = $this->request->address_id;
if(!is_numeric($address_id) || $address_id < 1) { if (!is_numeric($address_id) || $address_id < 1) {
$this->layout()->setFlash("Addresse nicht gefunden", "error"); $this->layout()->setFlash("Addresse nicht gefunden", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
$address = new Address($address_id); $address = new Address($address_id);
if(!$address->id) { if (!$address->id) {
$this->layout()->setFlash("Addresse nicht gefunden", "error"); $this->layout()->setFlash("Addresse nicht gefunden", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
@@ -172,7 +172,6 @@ class AddressController extends mfBaseController {
$this->layout()->set("address", $address); $this->layout()->set("address", $address);
} }
protected function editAction() { protected function editAction() {
@@ -184,7 +183,7 @@ class AddressController extends mfBaseController {
$this->layout()->set("address", $address); $this->layout()->set("address", $address);
if(!$address->id) { if (!$address->id) {
$this->layout()->setFlash("Addresse nicht gefunden", "error"); $this->layout()->setFlash("Addresse nicht gefunden", "error");
return $this->addAction(); return $this->addAction();
} }
@@ -195,13 +194,13 @@ class AddressController extends mfBaseController {
protected function deleteLink() { protected function deleteLink() {
$id = $this->request->id; $id = $this->request->id;
if(!is_numeric($id) || !$id) { if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Addresse nicht gefunden", "error"); $this->layout()->setFlash("Addresse nicht gefunden", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
$link = new AddressLink($id); $link = new AddressLink($id);
if(!$link->id) { if (!$link->id) {
$this->layout()->setFlash("Addresse nicht gefunden", "error"); $this->layout()->setFlash("Addresse nicht gefunden", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
@@ -214,29 +213,29 @@ class AddressController extends mfBaseController {
} }
protected function exportBmdAction() { protected function exportBmdAction() {
if(!$this->me->can("Fibu")) { if (!$this->me->can("Fibu")) {
$this->layout()->setFlash("Sicha ned!", "error"); $this->layout()->setFlash("Sicha ned!", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
$return = Address::runBmdExport($this->request->type); $return = Address::runBmdExport($this->request->type);
if($return === 10) { if ($return === 10) {
$this->layout()->setFlash("Export Pfad (".TT_ADDRESS_BMD_EXPORT_PATH.") nicht gefunden!", "error"); $this->layout()->setFlash("Export Pfad (" . TT_ADDRESS_BMD_EXPORT_PATH . ") nicht gefunden!", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
if($return === 11) { if ($return === 11) {
$this->layout()->setFlash("Keine geänderten Adressdatensätze gefunden. Export abgebrochen.", "warn"); $this->layout()->setFlash("Keine geänderten Adressdatensätze gefunden. Export abgebrochen.", "warn");
$this->redirect("Address"); $this->redirect("Address");
} }
if($return === 19) { if ($return === 19) {
$this->layout()->setFlash("Datei ".TT_ADDRESS_BMD_EXPORT_PATH."/".TT_ADDRESS_BMD_EXPORT_FILENAME." konnte nicht gespeichert werden!", "error"); $this->layout()->setFlash("Datei " . TT_ADDRESS_BMD_EXPORT_PATH . "/" . TT_ADDRESS_BMD_EXPORT_FILENAME . " konnte nicht gespeichert werden!", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
if($return === true) { if ($return === true) {
$this->layout()->setFlash("Adressen erfolgreich exportiert", "success"); $this->layout()->setFlash("Adressen erfolgreich exportiert", "success");
$this->redirect("Address"); $this->redirect("Address");
} }
@@ -248,10 +247,10 @@ class AddressController extends mfBaseController {
$r = $this->request; $r = $this->request;
$id = $r->id; $id = $r->id;
//var_dump($r->get());exit; //var_dump($r->get());exit;
if(is_numeric($id) && $id > 0) { if (is_numeric($id) && $id > 0) {
$mode = "edit"; $mode = "edit";
$address = new Address($id); $address = new Address($id);
if(!$address->id) { if (!$address->id) {
$this->layout()->setFlash("Addresse nicht gefunden", "error"); $this->layout()->setFlash("Addresse nicht gefunden", "error");
$this->redirect("Address"); $this->redirect("Address");
} }
@@ -277,28 +276,28 @@ class AddressController extends mfBaseController {
$data['note'] = trim($r->note); $data['note'] = trim($r->note);
$data['uid'] = trim($r->uid); $data['uid'] = trim($r->uid);
if(trim($r->birthdate)) { if (trim($r->birthdate)) {
try { try {
$data["birthdate"] = (DateTime::createFromFormat("d.m.Y", trim($r->birthdate)))->format("Y-m-d"); $data["birthdate"] = (DateTime::createFromFormat("d.m.Y", trim($r->birthdate)))->format("Y-m-d");
} catch(Exception $e) { } catch (Exception $e) {
$this->layout()->setFlash("Ungültiges Geburtsdaum", "warning"); $this->layout()->setFlash("Ungültiges Geburtsdaum", "warning");
} }
} }
if($this->me->can("Fibu")) { if ($this->me->can("Fibu")) {
$data["sepa_date"] = ($r->sepa_date) ? Layout::dateToInt($r->sepa_date) : null; $data["sepa_date"] = ($r->sepa_date) ? Layout::dateToInt($r->sepa_date) : null;
$data['fibu_account_number'] = ($r->fibu_account_number) ? trim($r->fibu_account_number) : null; $data['fibu_account_number'] = ($r->fibu_account_number) ? trim($r->fibu_account_number) : null;
$data['fibu_supplier_number'] = ($r->fibu_supplier_number) ? trim($r->fibu_supplier_number) : null; $data['fibu_supplier_number'] = ($r->fibu_supplier_number) ? trim($r->fibu_supplier_number) : null;
if($r->fibu_primary_account) { if ($r->fibu_primary_account) {
$data['fibu_primary_account'] = 1; $data['fibu_primary_account'] = 1;
} else { } else {
$data['fibu_primary_account'] = 0; $data['fibu_primary_account'] = 0;
} }
if($r->fibu_supplier_paymentblock) { if ($r->fibu_supplier_paymentblock) {
$data['fibu_supplier_paymentblock'] = 1; $data['fibu_supplier_paymentblock'] = 1;
} else { } else {
$data['fibu_supplier_paymentblock'] = 0; $data['fibu_supplier_paymentblock'] = 0;
@@ -312,15 +311,15 @@ class AddressController extends mfBaseController {
// billing data // billing data
// validate sepa // validate sepa
if(!$r->billing_type) { if (!$r->billing_type) {
$this->layout()->setFlash("Ungültige Verrechnungsart."); $this->layout()->setFlash("Ungültige Verrechnungsart.");
$this->layout()->set("order", $r); $this->layout()->set("order", $r);
return $this->add(); return $this->add();
} }
if($r->billing_type == "sepa") { if ($r->billing_type == "sepa") {
foreach(['owner', 'iban', 'bic'] as $required) { foreach (['owner', 'iban', 'bic'] as $required) {
if(!$r->{"bank_account_$required"}) { if (!$r->{"bank_account_$required"}) {
$this->layout()->setFlash("Bitte Bankdaten für SEPA ausfüllen.", "warn"); $this->layout()->setFlash("Bitte Bankdaten für SEPA ausfüllen.", "warn");
$this->layout()->set("address", $r); $this->layout()->set("address", $r);
return $this->add(); return $this->add();
@@ -328,10 +327,10 @@ class AddressController extends mfBaseController {
} }
} }
if($r->billing_type == "sepa") { if ($r->billing_type == "sepa") {
$data['billing_type'] = "sepa"; $data['billing_type'] = "sepa";
if(!$r->sepa_date) { if (!$r->sepa_date) {
if($mode == "add" || ($mode == "edit" && !$address->sepa_date)) { if ($mode == "add" || ($mode == "edit" && !$address->sepa_date)) {
$data['sepa_date'] = date('U'); $data['sepa_date'] = date('U');
} }
} else { } else {
@@ -341,7 +340,7 @@ class AddressController extends mfBaseController {
$data['billing_type'] = "invoice"; $data['billing_type'] = "invoice";
} }
if($r->billing_delivery == "paper") { if ($r->billing_delivery == "paper") {
$data['billing_delivery'] = "paper"; $data['billing_delivery'] = "paper";
} else { } else {
$data['billing_delivery'] = "email"; $data['billing_delivery'] = "email";
@@ -355,7 +354,7 @@ class AddressController extends mfBaseController {
$data['allow_contact'] = ($r->allow_contact) ? 1 : 0; $data['allow_contact'] = ($r->allow_contact) ? 1 : 0;
$data['allow_spin'] = ($r->allow_spin) ? 1 : 0; $data['allow_spin'] = ($r->allow_spin) ? 1 : 0;
if($mode == "add") { if ($mode == "add") {
$address = AddressModel::create($data); $address = AddressModel::create($data);
} else { } else {
$address->update($data); $address->update($data);
@@ -364,16 +363,16 @@ class AddressController extends mfBaseController {
//var_dump($address);exit; //var_dump($address);exit;
$new_id = $address->save(); $new_id = $address->save();
if(!$new_id) { if (!$new_id) {
$this->layout()->setFlash("Fehler beim Speichern", "error"); $this->layout()->setFlash("Fehler beim Speichern", "error");
$this->layout()->set("address", $address); $this->layout()->set("address", $address);
return $this->add(); return $this->add();
} }
// check for multiple primary fibu accounts, and remove from any other than this one // check for multiple primary fibu accounts, and remove from any other than this one
if($address->fibu_primary_account && $address->fibu_account_number) { if ($address->fibu_primary_account && $address->fibu_account_number) {
foreach(AddressModel::search(["fibu_primary_account" => true, "fibu_account_number" => $address->fibu_account_number]) as $fibu_primary) { foreach (AddressModel::search(["fibu_primary_account" => true, "fibu_account_number" => $address->fibu_account_number]) as $fibu_primary) {
if($fibu_primary->id == $address->id) continue; if ($fibu_primary->id == $address->id) continue;
$fibu_primary->fibu_primary_account = 0; $fibu_primary->fibu_primary_account = 0;
$fibu_primary->save(); $fibu_primary->save();
} }
@@ -382,12 +381,12 @@ class AddressController extends mfBaseController {
// save address types // save address types
$new_types = $r->addresstypes; $new_types = $r->addresstypes;
if(is_array($new_types)) { if (is_array($new_types)) {
foreach($address->types as $existing_type) { foreach ($address->types as $existing_type) {
//var_dump($existing_type); //var_dump($existing_type);
//var_dump($new_types); //var_dump($new_types);
//echo $existing_type->type; //echo $existing_type->type;
if(!in_array($existing_type->type, $new_types)) { if (!in_array($existing_type->type, $new_types)) {
$existing_type->delete(); $existing_type->delete();
} else { } else {
// remove existing type from new_types array (dont need to create again) // remove existing type from new_types array (dont need to create again)
@@ -396,7 +395,7 @@ class AddressController extends mfBaseController {
} }
} }
//exit; //exit;
foreach($new_types as $type) { foreach ($new_types as $type) {
$type_object = AddresstypeModel::create(['address_id' => $address->id, 'type' => $type]); $type_object = AddresstypeModel::create(['address_id' => $address->id, 'type' => $type]);
$type_object->save(); $type_object->save();
$address->types[$type] = $type_object; $address->types[$type] = $type_object;
@@ -405,12 +404,12 @@ class AddressController extends mfBaseController {
// generate new supplier account number if is supplier and supplier num empty // generate new supplier account number if is supplier and supplier num empty
//var_dump($mode, $address->fibu_supplier_number, $address->types);exit; //var_dump($mode, $address->fibu_supplier_number, $address->types);exit;
if(!$address->fibu_supplier_number && array_key_exists("supplier", $address->types)) { if (!$address->fibu_supplier_number && array_key_exists("supplier", $address->types)) {
$supplier_num = Address::getNextSupplierNumber(); $supplier_num = Address::getNextSupplierNumber();
if(!$supplier_num) { if (!$supplier_num) {
$this->layout()->setFlash("Lieferantennummer konnte nicht generiert werden."); $this->layout()->setFlash("Lieferantennummer konnte nicht generiert werden.");
} else { } else {
$this->log->debug("new supplier number: ". $supplier_num); $this->log->debug("new supplier number: " . $supplier_num);
$address->fibu_supplier_number = $supplier_num; $address->fibu_supplier_number = $supplier_num;
$address->save(); $address->save();
} }
@@ -418,11 +417,11 @@ class AddressController extends mfBaseController {
$attribs = $r->attributes; $attribs = $r->attributes;
//var_dump($attribs);exit; //var_dump($attribs);exit;
if(is_array($attribs) && count($attribs)) { if (is_array($attribs) && count($attribs)) {
foreach($attribs as $attrib => $value) { foreach ($attribs as $attrib => $value) {
$aa = AddressattributeModel::getFirst(["address_id" => $new_id, "name" => $attrib]); $aa = AddressattributeModel::getFirst(["address_id" => $new_id, "name" => $attrib]);
if(!$aa) { if (!$aa) {
$aa = AddressattributeModel::create(["address_id" => $new_id, "name" => $attrib]); $aa = AddressattributeModel::create(["address_id" => $new_id, "name" => $attrib]);
} }
$aa->value = $value; $aa->value = $value;
@@ -434,18 +433,18 @@ class AddressController extends mfBaseController {
//$address->deleteLinks(); //$address->deleteLinks();
$existing_links = []; $existing_links = [];
foreach(AddressLinkModel::search(['origin_address_id', $new_id]) as $elink) { foreach (AddressLinkModel::search(['origin_address_id', $new_id]) as $elink) {
$existing_links[$elink->address_id] = $elink; $existing_links[$elink->address_id] = $elink;
} }
//var_dump($r->links);exit; //var_dump($r->links);exit;
if(is_array($r->links) && count($r->links)) { if (is_array($r->links) && count($r->links)) {
//var_dump($r->links);exit; //var_dump($r->links);exit;
foreach($r->links as $linknum => $link) { foreach ($r->links as $linknum => $link) {
if(!$link['type'] || !$link['address_id']) { if (!$link['type'] || !$link['address_id']) {
continue; continue;
} }
if(array_key_exists($link['address_id'], $existing_links)) { if (array_key_exists($link['address_id'], $existing_links)) {
continue; continue;
} }
$l = AddressLinkModel::create([ $l = AddressLinkModel::create([
@@ -463,20 +462,20 @@ class AddressController extends mfBaseController {
$sq = ""; $sq = "";
$query = []; $query = [];
if($r->s) { if ($r->s) {
$query['s'] = $r->s; $query['s'] = $r->s;
} }
if($r->return != "index") { if ($r->return != "index") {
$query['id'] = $new_id; $query['id'] = $new_id;
} }
$qs = http_build_query($query); $qs = http_build_query($query);
$this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success"); $this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success");
if($r->return == "index") { if ($r->return == "index") {
$this->redirect("Address", "Index", $qs); $this->redirect("Address", "Index", $qs);
} }
if($r->f == "view") { if ($r->f == "view") {
$this->redirect("Address", "View", $qs); $this->redirect("Address", "View", $qs);
} }
$this->redirect("Address", "Edit", $qs); $this->redirect("Address", "Edit", $qs);
@@ -484,13 +483,13 @@ class AddressController extends mfBaseController {
protected function apiAction() { protected function apiAction() {
if(!$this->me->is(["Admin","salespartner"])) { if (!$this->me->is(["Admin", "salespartner"])) {
$this->redirect("Dashboard"); $this->redirect("Dashboard");
} }
$do = $this->request->do; $do = $this->request->do;
$data = []; $data = [];
switch($do) { switch ($do) {
case "getAddress": case "getAddress":
$return = $this->getAddressApi(); $return = $this->getAddressApi();
break; break;
@@ -504,7 +503,7 @@ class AddressController extends mfBaseController {
$return = false; $return = false;
} }
if(!is_array($return) || !count($return)) { if (!is_array($return) || !count($return)) {
$data = ["status" => "error"]; $data = ["status" => "error"];
$this->returnJson($data); $this->returnJson($data);
} }
@@ -515,12 +514,12 @@ class AddressController extends mfBaseController {
private function getAddressApi() { private function getAddressApi() {
$id = trim($this->request->id); $id = trim($this->request->id);
if(!is_numeric($id) || !$id) { if (!is_numeric($id) || !$id) {
return false; return false;
} }
$address = new Address($id); $address = new Address($id);
if(!$address->id) { if (!$address->id) {
return false; return false;
} }
@@ -534,12 +533,13 @@ class AddressController extends mfBaseController {
$search = trim($this->request->q); $search = trim($this->request->q);
$autocomplete = $this->request->autocomplete; $autocomplete = $this->request->autocomplete;
if($autocomplete && $this->request->searchedID) { if ($autocomplete && $this->request->searchedID) {
$address = new Address($this->request->searchedID); $address = new Address($this->request->searchedID);
if($address->id) { if ($address->id) {
$result = [ $result = [
'value' => $address->id, 'value' => $address->id,
'text' => str_replace("'", "\\'", str_replace(["\n", "\r"], " ",$address->getCompanyOrName()))." (".$address->zip." ".$address->city.", ".$address->street.")".(($address->customer_number) ? " [".$address->customer_number."]" : "") 'text' => str_replace("'", "\\'", str_replace(["\n",
"\r"], " ", $address->getCompanyOrName())) . " (" . $address->zip . " " . $address->city . ", " . $address->street . ")" . (($address->customer_number) ? " [" . $address->customer_number . "]" : "")
]; ];
$results[] = $result; $results[] = $result;
$this->returnJson($results); $this->returnJson($results);
@@ -550,33 +550,48 @@ class AddressController extends mfBaseController {
$po = 1; $po = 1;
$role = false; $role = false;
// if searching for billingaddress, set role and parents_only to 0 // if searching for billingaddress, set role and parents_only to 0
if($this->request->role == "billingaddress") { if ($this->request->role == "billingaddress") {
$role = "billing"; $role = "billing";
$po = 0; $po = 0;
} }
if($this->request->role == "techcontact") { if ($this->request->role == "techcontact") {
$role = "techcontact"; $role = "techcontact";
$po = 0; $po = 0;
} }
$this->log->debug(print_r($this->request->get(),true)); $this->log->debug(print_r($this->request->get(), true));
$addresses = []; $addresses = [];
if(is_numeric($search)) { if (is_numeric($search)) {
$cnumbers = AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "customer_number" => $search]); $cnumbers = AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "customer_number" => $search]);
if($cnumbers) { if ($cnumbers) {
$addresses = array_merge($addresses, $cnumbers); $addresses = array_merge($addresses, $cnumbers);
} }
} }
if (isset($_GET['fibu_primary_account'])) { if (isset($_GET['fibu_primary_account'])) {
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "mergedName" => $search, "fibu_primary_account" => true])); $addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po,
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "company" => $search, "fibu_primary_account" => true])); "addresstype" => [$role],
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "firstname" => $search, "fibu_primary_account" => true])); "mergedName" => $search,
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "lastname" => $search, "fibu_primary_account" => true])); "fibu_primary_account" => true]));
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "street" => $search, "fibu_primary_account" => true])); $addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po,
"addresstype" => [$role],
"company" => $search,
"fibu_primary_account" => true]));
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po,
"addresstype" => [$role],
"firstname" => $search,
"fibu_primary_account" => true]));
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po,
"addresstype" => [$role],
"lastname" => $search,
"fibu_primary_account" => true]));
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po,
"addresstype" => [$role],
"street" => $search,
"fibu_primary_account" => true]));
} else { } else {
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "mergedName" => $search])); $addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "mergedName" => $search]));
@@ -585,25 +600,26 @@ class AddressController extends mfBaseController {
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "lastname" => $search])); $addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "lastname" => $search]));
} }
if(!is_array($addresses) || !count($addresses)) { if (!is_array($addresses) || !count($addresses)) {
return false; return false;
} }
$all_addresses = []; $all_addresses = [];
// remove duplicates // remove duplicates
foreach($addresses as $address) { foreach ($addresses as $address) {
if(!array_key_exists($address->id, $all_addresses)) { if (!array_key_exists($address->id, $all_addresses)) {
$all_addresses[$address->id] = $address; $all_addresses[$address->id] = $address;
} }
} }
$results = []; $results = [];
if(!$autocomplete) { if (!$autocomplete) {
foreach($all_addresses as $id => $address) { foreach ($all_addresses as $id => $address) {
$results[$id] = str_replace("'", "\\'", str_replace(["\n", "\r"], " ",$address->getCompanyOrName()))." (".$address->zip." ".$address->city.", ".$address->street.")".(($address->customer_number) ? " [".$address->customer_number."]" : ""); $results[$id] = str_replace("'", "\\'", str_replace(["\n",
if(count($results) > 15) { "\r"], " ", $address->getCompanyOrName())) . " (" . $address->zip . " " . $address->city . ", " . $address->street . ")" . (($address->customer_number) ? " [" . $address->customer_number . "]" : "");
if (count($results) > 15) {
$results["more"] = "..."; $results["more"] = "...";
break; break;
} }
@@ -613,11 +629,14 @@ class AddressController extends mfBaseController {
} }
// return bootstrap-autocomplete format // return bootstrap-autocomplete format
foreach($all_addresses as $id => $address) { foreach ($all_addresses as $id => $address) {
$result = ['value' => $id, 'text' => str_replace("'", "\\'", str_replace(["\n", "\r"], " ",$address->getCompanyOrName()))." (".$address->zip." ".$address->city.", ".$address->street.")".(($address->customer_number) ? " [".$address->customer_number."]" : "")]; $result = ['value' => $id,
'text' => str_replace("'", "\\'", str_replace(["\n",
"\r"], " ", $address->getCompanyOrName())) . " (" . $address->zip . " " . $address->city . ", " . $address->street . ")" . (($address->customer_number) ? " [" . $address->customer_number . "]" : "")];
$results[] = $result; $results[] = $result;
if(count($results) > 15) { if (count($results) > 15) {
$results[] = ['value' => 0, 'text' => "&nbsp;&nbsp;--> &nbsp;&nbsp;Mehr Suchergebnisse vorhanden. Bitte Suchbegriff genauer definieren &nbsp;&nbsp;<--"]; $results[] = ['value' => 0,
'text' => "&nbsp;&nbsp;--> &nbsp;&nbsp;Mehr Suchergebnisse vorhanden. Bitte Suchbegriff genauer definieren &nbsp;&nbsp;<--"];
break; break;
} }
} }
@@ -629,12 +648,12 @@ class AddressController extends mfBaseController {
$iban = trim($this->request->iban); $iban = trim($this->request->iban);
$bic = trim($this->request->bic); $bic = trim($this->request->bic);
if(!$iban) { if (!$iban) {
return false; return false;
} }
$result = IbanValidator::validate($iban, $bic); $result = IbanValidator::validate($iban, $bic);
if(is_array($result) && $result) { if (is_array($result) && $result) {
return $result; return $result;
} }
@@ -661,7 +680,7 @@ class AddressController extends mfBaseController {
$customer_phone_number = $this->request->customer_phone_number; $customer_phone_number = $this->request->customer_phone_number;
$customer_email = $this->request->customer_email; $customer_email = $this->request->customer_email;
$customer_service_pin = $this->request->customer_service_pin; $customer_service_pin = $this->request->customer_service_pin;
$user_api_key = (string)$this->me->getFlag('project_api_key'); $user_api_key = (string) $this->me->getFlag('project_api_key');
$xinon_project = new XinonProject(); $xinon_project = new XinonProject();
$response = $xinon_project->createNewFaultTicket($subject, $description, $customer_name, $customer_number, $customer_address, $customer_phone_number, $customer_email, $customer_service_pin, $user_api_key); $response = $xinon_project->createNewFaultTicket($subject, $description, $customer_name, $customer_number, $customer_address, $customer_phone_number, $customer_email, $customer_service_pin, $user_api_key);
@@ -669,4 +688,21 @@ class AddressController extends mfBaseController {
die($response); die($response);
} }
protected function ticketsAction() {
$address_id = $this->request->address_id;
$address = new Address($address_id);
if (!$address->id) {
$this->layout()->setFlash("Addresse nicht gefunden", "error");
$this->redirect("Address");
}
$xinon_project = new XinonProject();
$tickets = $xinon_project->searchSupportTickets('', 0, ['pageSize' => 100,
'filters' => json_encode([['customField6' => ['operator' => '=', 'values' => [$address->customer_number]]]])]);
Helper::renderVue($this,"AddressTickets",
"Tickets von Kunden: " . $address->getCompanyOrName() . '(' . $address->customer_number . ')', ["TICKETS" => $tickets]);
}
} }
+4 -5
View File
@@ -58,14 +58,13 @@ class XinonProject {
* @param int $pageSize - The number of results to return. * @param int $pageSize - The number of results to return.
* @return array - The search results. * @return array - The search results.
*/ */
public function searchSupportTickets(string $search, int $pageSize = 25): array { public function searchSupportTickets(string $search, int $pageSize = 25, $overrideQueryParams = null): array {
$curl = curl_init(); $curl = curl_init();
$baseUrl = 'https://project.xinon.at/api/v3/projects/10/work_packages'; $baseUrl = 'https://project.xinon.at/api/v3/projects/10/work_packages';
$queryParams = [ $queryParams = ['pageSize' => $pageSize, 'filters' => json_encode([['search' => ['operator' => '**', 'values' => [$search]]]])];
'pageSize' => 25,
'filters' => json_encode([['search' => ['operator' => '**', 'values' => [$search]]]]) if (!is_null($overrideQueryParams)) $queryParams = $overrideQueryParams;
];
curl_setopt_array($curl, array( curl_setopt_array($curl, array(
CURLOPT_URL => $baseUrl . '?' . http_build_query($queryParams), CURLOPT_URL => $baseUrl . '?' . http_build_query($queryParams),
@@ -0,0 +1,55 @@
Vue.component('AddressTickets', {
template: `
<tt-card>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-light">
<tr>
<th>Kundennummer</th>
<th>Erstellt am</th>
<th>Betreff</th>
<th>Letztes Update</th>
<th>Aktion</th>
</tr>
</thead>
<tbody>
<tr v-for="ticket in parsedTickets" :key="ticket.id">
<td>{{ ticket.customField7 }}</td>
<td>{{ formatDate(ticket.createdAt) }}</td>
<td>{{ ticket.subject }}</td>
<td>{{ formatDate(ticket.updatedAt) }}</td>
<td>
<a :href="'https://project.xinon.at' + ticket.activitiesHref.replace('api/v3', 'projects/storungen-and-support').replace('activities', 'activity')" class="btn btn-primary btn-sm" target="_blank">
<i class="fas fa-external-link-alt mr-1"></i>
Ticket anzeigen
</a>
</td>
</tr>
</tbody>
</table>
</div>
</tt-card>
`,
data() {
return {
window: window,
}
},
computed: {
parsedTickets() {
return this.window.TT_CONFIG.TICKETS.map(ticket => ({
id: ticket.id,
customField7: ticket.customField7,
createdAt: ticket.createdAt,
subject: ticket.subject,
updatedAt: ticket.updatedAt,
activitiesHref: ticket._links.activities.href
}));
}
},
methods: {
formatDate(dateString) {
return this.window.moment(dateString).format('DD.MM.YYYY HH:mm');
}
}
});