700 lines
21 KiB
PHP
700 lines
21 KiB
PHP
<?php
|
|
|
|
class AddressController extends mfBaseController {
|
|
private $filter;
|
|
|
|
protected function init() {
|
|
$this->needlogin=true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me",$me);
|
|
|
|
if(!$me->is(["Admin", "salespartner"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function indexAction() {
|
|
$rfilter = $this->request->filter;
|
|
iF(!is_array($rfilter)) {
|
|
$rfilter = [];
|
|
}
|
|
if(!array_key_exists("addresstype", $rfilter)) {
|
|
$rfilter["addresstype"] = [];
|
|
}
|
|
|
|
$this->layout->set("filter", $rfilter);
|
|
|
|
$filter = $this->getPreparedFilter($rfilter);
|
|
|
|
// pagination defaults
|
|
$pagination = [];
|
|
$pagination['start'] = 0;
|
|
$pagination['count'] = 25;
|
|
$pagination['maxItems'] = 0;
|
|
|
|
if(is_numeric($this->request->s)) {
|
|
$pagination['start'] = intval($this->request->s);
|
|
}
|
|
//var_dump($filter);exit;
|
|
$pagination['maxItems'] = AddressModel::count($filter);
|
|
$addresses = AddressModel::search($filter, $pagination);
|
|
|
|
$this->layout()->set("addresses", $addresses);
|
|
$this->layout()->set("request", $this->request);
|
|
$this->layout()->set("pagination", $pagination);
|
|
|
|
|
|
$last_export = false;
|
|
$bmd_export_ts = new mfConfig("bmd.export.ts");
|
|
if($bmd_export_ts->value()) {
|
|
$last_export = $bmd_export_ts->value();
|
|
}
|
|
$this->layout()->set("last_bmd_export", $last_export);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
//var_dump($this->request->filter);
|
|
$default_filter = ['parents_only' => 1];
|
|
if(is_array($this->request->filter) && count($this->request->filter)) {
|
|
$filter = array_merge($default_filter, $this->request->filter);
|
|
} else {
|
|
$filter = $default_filter;
|
|
}
|
|
//var_dump($filter);exit;
|
|
$addresses = AddressModel::search($filter);
|
|
|
|
$this->layout()->set("addresses", $addresses);
|
|
$this->layout()->set("filter", $filter);
|
|
$this->layout()->set("request", $this->request);
|
|
}
|
|
|
|
|
|
private function getPreparedFilter($filter) {
|
|
$new_filter = [];
|
|
|
|
if(is_array($filter) && count($filter)) {
|
|
if(!array_key_exists("parents_only", $filter)) {
|
|
$new_filter["parents_only"] = 1;
|
|
}
|
|
|
|
if(array_key_exists("fibu_account_number", $filter) && $filter['fibu_account_number']) {
|
|
$new_filter['fibu_account_number'] = $filter['fibu_account_number']."%";
|
|
unset($filter['fibu_account_number']);
|
|
}
|
|
|
|
|
|
if(!array_key_exists("customer_number", $filter) || !$filter["customer_number"]) {
|
|
if(array_key_exists("type", $filter)) {
|
|
if($filter["type"] == "xinon") {
|
|
$new_filter["customer_or_fibu_numbers"] = true;
|
|
} elseif($filter["type"] == "others") {
|
|
$new_filter["customer_or_fibu_numbers"] = false;
|
|
}
|
|
} else {
|
|
$new_filter["customer_or_fibu_numbers"] = true; // default
|
|
}
|
|
unset($filter["type"]);
|
|
unset($filter["customer_number"]);
|
|
}
|
|
|
|
foreach($filter as $name => $value) {
|
|
$new_filter[$name] = $value;
|
|
}
|
|
}
|
|
|
|
return $new_filter;
|
|
}
|
|
|
|
protected function addAction() {
|
|
$this->layout()->setTemplate("Address/Form");
|
|
|
|
$this->layout->set("filter", $this->request->filter);
|
|
|
|
$parents = AddressModel::search(['parent_id' => null]);
|
|
$this->layout()->set("parents", $parents);
|
|
}
|
|
|
|
protected function viewAction() {
|
|
$this->layout()->setTemplate("Address/View");
|
|
|
|
$this->layout->set("filter", $this->request->filter);
|
|
$this->layout->set("f", $this->request->f);
|
|
$this->layout->set("s", $this->request->s);
|
|
|
|
$address = new Address($this->request->id);
|
|
$this->layout()->set("address", $address);
|
|
|
|
if(!$address->id) {
|
|
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
}
|
|
|
|
protected function editAction() {
|
|
$address = new Address($this->request->id);
|
|
|
|
$this->layout->set("filter", $this->request->filter);
|
|
$this->layout->set("f", $this->request->f);
|
|
$this->layout->set("s", $this->request->s);
|
|
|
|
$this->layout()->set("address", $address);
|
|
|
|
if(!$address->id) {
|
|
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
|
return $this->addAction();
|
|
}
|
|
|
|
return $this->addAction();
|
|
}
|
|
|
|
protected function deleteLink() {
|
|
$id = $this->request->id;
|
|
|
|
if(!is_numeric($id) || !$id) {
|
|
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
$link = new AddressLink($id);
|
|
if(!$link->id) {
|
|
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
$address_id = $link->origin_address_id;
|
|
$link->delete();
|
|
$this->layout()->setFlash("Verknüpfung erfolgreich entfernt", "success");
|
|
$this->redirect("Address", "edit", ['id' => $address_id]);
|
|
|
|
}
|
|
|
|
protected function exportBmd() {
|
|
/*$last_export = new mfConfig("bmd.export.ts");
|
|
$last_export->type("int");
|
|
$last_export->value(date("U"));
|
|
$last_export->save();
|
|
*/
|
|
|
|
if(!$this->me->can("Fibu")) {
|
|
$this->layout()->setFlash("Sicha ned!", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
$last_export = 0;
|
|
|
|
$export_ts = new mfConfig("bmd.export.ts");
|
|
if($export_ts->value()) {
|
|
$last_export = $export_ts->value();
|
|
}
|
|
|
|
$type = "inc";
|
|
|
|
if($this->request->type == "full") {
|
|
$last_export = 0;
|
|
$type = "full";
|
|
}
|
|
|
|
if(!file_exists(TT_ADDRESS_BMD_EXPORT_PATH)) {
|
|
$this->layout()->setFlash("Export Pfad (".TT_ADDRESS_BMD_EXPORT_PATH.") nicht gefunden!", "error");
|
|
}
|
|
|
|
$export_ts->value(date('U'));
|
|
|
|
$search = ["edit>" => $last_export, "customer_or_fibu_numbers" => true];
|
|
|
|
if(!AddressModel::count($search)) {
|
|
$this->layout()->setFlash("Keine geänderten Adressdatensätze gefunden. Export abgebrochen.", "warn");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
$addresses = [];
|
|
|
|
foreach(AddressModel::search($search) as $address) {
|
|
|
|
|
|
// if is primary -> use it
|
|
if($address->fibu_account_number && $address->fibu_primary_account) {
|
|
$addresses[$address->fibu_account_number] = $address;
|
|
continue;
|
|
}
|
|
|
|
// if only address with fibu_account_num -> make primary
|
|
if($address->fibu_account_number && !$address->fibu_primary_account) {
|
|
// look up other addresses with same account num
|
|
$address_count = AddressModel::count(["fibu_account_number" => $address->fibu_account_number]);
|
|
if($address_count === 1) {
|
|
$address->fibu_primary_account = 1;
|
|
$address->save();
|
|
$addresses[$address->fibu_account_number] = $address;
|
|
continue;
|
|
}
|
|
|
|
// if more addresses with fibu_account_num -> find primary
|
|
if($address_count > 1) {
|
|
// find primary
|
|
$primary = AddressModel::getFirst(["fibu_account_number" => $address->fibu_account_number, "fibu_primary_account" => true]);
|
|
if($primary) {
|
|
// use single primary
|
|
$addresses[$primary->fibu_account_number] = $primary;
|
|
continue;
|
|
} else {
|
|
// if no primary -> make last one primary
|
|
$new_primary = false;
|
|
foreach(AddressModel::search(["fibu_account_number" => $address->fibu_account_number]) as $primary) {
|
|
$new_primary = $primary;
|
|
}
|
|
if(!$new_primary) {
|
|
var_dump($address);exit;
|
|
}
|
|
$new_primary->fibu_primary_account = 1;
|
|
$new_primary->save();
|
|
$addresses[$new_primary->fibu_account_number] = $new_primary;
|
|
continue;
|
|
}
|
|
}
|
|
var_dump($address);exit;
|
|
}
|
|
|
|
// if no fibu account number but customer number -> create fibu account number
|
|
if($address->customer_number && !$address->fibu_account_number) {
|
|
// Address::afterSave() generates new fibu account number
|
|
$address->save();
|
|
if(!$address->fibu_account_number) {
|
|
var_dump($address);exit;
|
|
}
|
|
$addresses[$address->fibu_account_number] = $address;
|
|
continue;
|
|
}
|
|
|
|
// if supplier -> use it
|
|
if($address->fibu_supplier_number) {
|
|
$addresses[$address->fibu_supplier_number] = $address;
|
|
continue;
|
|
}
|
|
|
|
}
|
|
|
|
$export_addresses = [];
|
|
|
|
foreach($addresses as $address) {
|
|
$a = [];
|
|
$a["id"] = $address->id;
|
|
$a["is_supplier"] = (array_key_exists("supplier", $address->types) && $address->types['supplier']) ? "1" : "0";
|
|
$a["is_customer"] = "1";
|
|
$a["customer_number"] = $address->customer_number;
|
|
$a["fibu_account_number"] = $address->fibu_account_number;
|
|
$a["fibu_supplier_number"] = $address->fibu_supplier_number;
|
|
$a["fibu_supplier_due"] = (is_numeric($address->fibu_supplier_due)) ? $address->fibu_supplier_due : TT_ADDRESS_DEFAULT_SUPPLIER_DUE;
|
|
$a["company"] = $address->company;
|
|
$a["firstname"] = $address->firstname;
|
|
$a["lastname"] = $address->lastname;
|
|
$a["street"] = $address->street;
|
|
$a["zip"] = $address->zip;
|
|
$a["city"] = $address->city;
|
|
$a["country"] = $address->country;
|
|
$a["phone"] = $address->phone;
|
|
$a["mobile"] = $address->mobile;
|
|
$a["email"] = $address->email;
|
|
$a["uid"] = $address->uid;
|
|
$a["billing_type"] = $address->billing_type;
|
|
$a["billing_delivery"] = $address->billing_delivery;
|
|
if(array_key_exists("billing", $address->links) && $address->links["billing"]) {
|
|
$a["bank"] = $address->links["billing"]->bank_account_bank;
|
|
$a["bank_owner"] = $address->links["billing"]->bank_account_owner;
|
|
$a["iban"] = $address->links["billing"]->bank_account_iban;
|
|
$a["bic"] = $address->links["billing"]->bank_account_bic;
|
|
} else {
|
|
$a["bank"] = $address->bank_account_bank;
|
|
$a["bank_owner"] = $address->bank_account_owner;
|
|
$a["iban"] = $address->bank_account_iban;
|
|
$a["bic"] = $address->bank_account_bic;
|
|
}
|
|
|
|
$export_addresses[] = $a;
|
|
}
|
|
|
|
|
|
|
|
|
|
$tpl = new Layout();
|
|
$tpl->setTemplate("Address/bmd_export.csv");
|
|
$tpl->set("addresses", $export_addresses);
|
|
$csv_content = $tpl->render();
|
|
|
|
$filename = "thetool_address_export_".$type."_".date("Y-m-d-H-i-s").".csv";
|
|
|
|
// save to TT_ADDRESS_BMD_EXPORT_PATH
|
|
$filepath = TT_ADDRESS_BMD_EXPORT_PATH."/".$filename;
|
|
|
|
if(!file_put_contents($filepath, $csv_content)) {
|
|
$this->layout()->setFlash("Datei $filepath konnte nicht gespeichert werden!", "error");
|
|
} else {
|
|
$export_ts->save();
|
|
$this->layout()->setFlash("Adressen erfolgreich exportiert", "success");
|
|
}
|
|
|
|
$this->redirect("Address");
|
|
|
|
|
|
}
|
|
|
|
protected function saveAction() {
|
|
$r = $this->request;
|
|
$id = $r->id;
|
|
//var_dump($r->get());exit;
|
|
if(is_numeric($id) && $id > 0) {
|
|
$mode = "edit";
|
|
$address = new Address($id);
|
|
if(!$address->id) {
|
|
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
|
|
//var_dump($r->addresstypes);exit;
|
|
|
|
$data = [];
|
|
$data['parent_id'] = (!$r->parent_id) ? null : $r->parent_id;
|
|
$data['company'] = $r->company;
|
|
$data['firstname'] = $r->firstname;
|
|
$data['lastname'] = $r->lastname;
|
|
$data['street'] = $r->street;
|
|
$data['zip'] = $r->zip;
|
|
$data['city'] = $r->city;
|
|
$data['country'] = $r->country;
|
|
$data['phone'] = $r->phone;
|
|
$data['fax'] = $r->fax;
|
|
$data['mobile'] = $r->mobile;
|
|
$data['email'] = $r->email;
|
|
$data['note'] = $r->note;
|
|
$data['uid'] = $r->uid;
|
|
|
|
if($this->me->can("Fibu")) {
|
|
$data['fibu_account_number'] = ($r->fibu_account_number) ? $r->fibu_account_number : null;
|
|
$data['fibu_supplier_number'] = ($r->fibu_supplier_number) ? $r->fibu_supplier_number : null;
|
|
if($r->fibu_primary_account) {
|
|
$data['fibu_primary_account'] = 1;
|
|
} else {
|
|
$data['fibu_primary_account'] = 0;
|
|
}
|
|
$data['fibu_supplier_due'] = ($r->fibu_supplier_due) ? $r->fibu_supplier_due : null;
|
|
}
|
|
|
|
|
|
// billing data
|
|
// validate sepa
|
|
if(!$r->billing_type) {
|
|
$this->layout()->setFlash("Ungültige Verrechnungsart.");
|
|
$this->layout()->set("order", $r);
|
|
return $this->add();
|
|
}
|
|
|
|
if($r->billing_type == "sepa") {
|
|
foreach(['owner', 'iban', 'bic'] as $required) {
|
|
if(!$r->{"bank_account_$required"}) {
|
|
$this->layout()->setFlash("Bitte Bankdaten für SEPA ausfüllen.", "warn");
|
|
$this->layout()->set("address", $r);
|
|
return $this->add();
|
|
}
|
|
}
|
|
}
|
|
|
|
if($r->billing_type == "sepa") {
|
|
$data['billing_type'] = "sepa";
|
|
} else {
|
|
$data['billing_type'] = "invoice";
|
|
}
|
|
|
|
if($r->billing_delivery == "paper") {
|
|
$data['billing_delivery'] = "paper";
|
|
} else {
|
|
$data['billing_delivery'] = "email";
|
|
}
|
|
|
|
|
|
$data['bank_account_bank'] = $r->bank_account_bank;
|
|
$data['bank_account_owner'] = $r->bank_account_owner;
|
|
$data['bank_account_iban'] = $r->bank_account_iban;
|
|
$data['bank_account_bic'] = $r->bank_account_bic;
|
|
$data['allow_contact'] = ($r->allow_contact) ? 1 : 0;
|
|
$data['allow_spin'] = ($r->allow_spin) ? 1 : 0;
|
|
|
|
|
|
$data['edit_by'] = 1;
|
|
|
|
if($mode == "add") {
|
|
$data['create_by'] = 1;
|
|
$address = AddressModel::create($data);
|
|
} else {
|
|
$address->update($data);
|
|
}
|
|
|
|
//var_dump($address);exit;
|
|
|
|
$new_id = $address->save();
|
|
if(!$new_id) {
|
|
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
|
$this->layout()->set("address", $address);
|
|
return $this->add();
|
|
}
|
|
|
|
// check for multiple primary fibu accounts, and remove from any other than this one
|
|
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) {
|
|
if($fibu_primary->id == $address->id) continue;
|
|
$fibu_primary->fibu_primary_account = 0;
|
|
$fibu_primary->save();
|
|
}
|
|
}
|
|
|
|
|
|
// save address types
|
|
$new_types = $r->addresstypes;
|
|
if(is_array($new_types)) {
|
|
foreach($address->types as $existing_type) {
|
|
//var_dump($existing_type);
|
|
//var_dump($new_types);
|
|
//echo $existing_type->type;
|
|
if(!in_array($existing_type->type, $new_types)) {
|
|
$existing_type->delete();
|
|
} else {
|
|
// remove existing type from new_types array (dont need to create again)
|
|
$new_types = array_diff($new_types, [$existing_type->type]);
|
|
//unset($new_types[$existing_type]);
|
|
}
|
|
}
|
|
//exit;
|
|
foreach($new_types as $type) {
|
|
$type_object = AddresstypeModel::create(['address_id' => $address->id, 'type' => $type]);
|
|
$type_object->save();
|
|
$address->types[$type] = $type_object;
|
|
}
|
|
}
|
|
|
|
// generate new supplier account number if is supplier and supplier num empty
|
|
//var_dump($mode, $address->fibu_supplier_number, $address->types);exit;
|
|
if(!$address->fibu_supplier_number && array_key_exists("supplier", $address->types)) {
|
|
$supplier_num = Address::getNextSupplierNumber();
|
|
if(!$supplier_num) {
|
|
$this->layout()->setFlash("Lieferantennummer konnte nicht generiert werden.");
|
|
} else {
|
|
$this->log->debug("new supplier number: ". $supplier_num);
|
|
$address->fibu_supplier_number = $supplier_num;
|
|
$address->save();
|
|
}
|
|
}
|
|
|
|
$attribs = $r->attributes;
|
|
//var_dump($attribs);exit;
|
|
if(is_array($attribs) && count($attribs)) {
|
|
foreach($attribs as $attrib => $value) {
|
|
$aa = AddressattributeModel::getFirst(["address_id" => $new_id, "name" => $attrib]);
|
|
|
|
if(!$aa) {
|
|
$aa = AddressattributeModel::create(["address_id" => $new_id, "name" => $attrib]);
|
|
}
|
|
$aa->value = $value;
|
|
$aa->save();
|
|
}
|
|
}
|
|
|
|
|
|
//$address->deleteLinks();
|
|
|
|
$existing_links = [];
|
|
foreach(AddressLinkModel::search(['origin_address_id', $new_id]) as $elink) {
|
|
$existing_links[$elink->address_id] = $elink;
|
|
}
|
|
|
|
//var_dump($r->links);exit;
|
|
if(is_array($r->links) && count($r->links)) {
|
|
//var_dump($r->links);exit;
|
|
foreach($r->links as $linknum => $link) {
|
|
if(!$link['type'] || !$link['address_id']) {
|
|
continue;
|
|
}
|
|
if(array_key_exists($link['address_id'], $existing_links)) {
|
|
continue;
|
|
}
|
|
$l = AddressLinkModel::create([
|
|
'origin_address_id' => $new_id,
|
|
'type' => $link['type'],
|
|
'address_id' => $link['address_id']
|
|
]);
|
|
$l->save();
|
|
|
|
}
|
|
}
|
|
|
|
$sq = "";
|
|
$query = [];
|
|
if($r->s) {
|
|
$query['s'] = $r->s;
|
|
}
|
|
if($r->filter) {
|
|
$query["filter"] = $r->filter;
|
|
}
|
|
if($r->return != "index") {
|
|
$query['id'] = $new_id;
|
|
}
|
|
|
|
$qs = http_build_query($query);
|
|
|
|
|
|
$this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success");
|
|
if($r->return == "index") {
|
|
$this->redirect("Address", "Index", $qs);
|
|
}
|
|
if($r->f == "view") {
|
|
$this->redirect("Address", "View", $qs);
|
|
}
|
|
$this->redirect("Address", "Edit", $qs);
|
|
}
|
|
|
|
|
|
protected function apiAction() {
|
|
if(!$this->me->is(["Admin","salespartner"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
$do = $this->request->do;
|
|
$data = [];
|
|
|
|
switch($do) {
|
|
case "getAddress":
|
|
$return = $this->getAddressApi();
|
|
break;
|
|
case "findAddress":
|
|
$return = $this->findAddressApi();
|
|
break;
|
|
case "validateIbanBic":
|
|
$return = $this->validateIbanBicApi();
|
|
break;
|
|
default:
|
|
$return = false;
|
|
}
|
|
|
|
if(!is_array($return) || !count($return)) {
|
|
$data = ["status" => "error"];
|
|
$this->returnJson($data);
|
|
}
|
|
$data['status'] = "OK";
|
|
$data['result'] = $return;
|
|
$this->returnJson($data);
|
|
}
|
|
|
|
private function getAddressApi() {
|
|
$id = trim($this->request->id);
|
|
if(!is_numeric($id) || !$id) {
|
|
return false;
|
|
}
|
|
|
|
$address = new Address($id);
|
|
if(!$address->id) {
|
|
return false;
|
|
}
|
|
|
|
$a = $address->toArray();
|
|
|
|
return ['address' => $a];
|
|
}
|
|
|
|
private function findAddressApi() {
|
|
$search = trim($this->request->q);
|
|
$autocomplete = $this->request->autocomplete;
|
|
|
|
$po = 1;
|
|
$role = false;
|
|
// if searching for billingaddress, set role and parents_only to 0
|
|
if($this->request->role == "billingaddress") {
|
|
$role = "billing";
|
|
$po = 0;
|
|
}
|
|
if($this->request->role == "techcontact") {
|
|
$role = "techcontact";
|
|
$po = 0;
|
|
}
|
|
|
|
$this->log->debug(print_r($this->request->get(),true));
|
|
|
|
$addresses = [];
|
|
|
|
if(is_numeric($search)) {
|
|
$cnumbers = AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "customer_number" => $search]);
|
|
if($cnumbers) {
|
|
$addresses = array_merge($addresses, $cnumbers);
|
|
}
|
|
}
|
|
|
|
|
|
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "mergedName" => $search]));
|
|
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "company" => $search]));
|
|
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "firstname" => $search]));
|
|
$addresses = array_merge($addresses, AddressModel::search(["parents_only" => $po, "addresstype" => [$role], "lastname" => $search]));
|
|
|
|
if(!is_array($addresses) || !count($addresses)) {
|
|
return false;
|
|
}
|
|
|
|
$all_addresses = [];
|
|
|
|
// remove duplicates
|
|
foreach($addresses as $address) {
|
|
if(!array_key_exists($address->id, $all_addresses)) {
|
|
$all_addresses[$address->id] = $address;
|
|
}
|
|
}
|
|
|
|
$results = [];
|
|
|
|
if(!$autocomplete) {
|
|
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."]" : "");
|
|
if(count($results) > 15) {
|
|
$results["more"] = "...";
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ["addresses" => $results];
|
|
}
|
|
|
|
// return bootstrap-autocomplete format
|
|
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."]" : "")];
|
|
$results[] = $result;
|
|
if(count($results) > 15) {
|
|
$results[] = ['value' => 0, 'text' => " --> Mehr Suchergebnisse vorhanden. Bitte Suchbegriff genauer definieren <--"];
|
|
break;
|
|
}
|
|
}
|
|
|
|
$this->returnJson($results);
|
|
}
|
|
|
|
private function validateIbanBicApi() {
|
|
$iban = trim($this->request->iban);
|
|
$bic = trim($this->request->bic);
|
|
|
|
if(!$iban) {
|
|
return false;
|
|
}
|
|
|
|
$result = IbanValidator::validate($iban, $bic);
|
|
if(is_array($result) && $result) {
|
|
return $result;
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
}
|