745 lines
35 KiB
PHP
745 lines
35 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"] = [];
|
|
}
|
|
|
|
if ($this->request->resetFilter) {
|
|
unset($_SESSION[MFAPPNAME . '-Address-filter']);
|
|
}
|
|
|
|
$filter = [];
|
|
if (is_array($this->request->filter)) {
|
|
$filter = $this->request->filter;
|
|
$_SESSION[MFAPPNAME . '-Address-filter'] = $filter;
|
|
} else {
|
|
if (array_key_exists(MFAPPNAME . '-Address-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-Address-filter'])) {
|
|
$filter = $_SESSION[MFAPPNAME . '-Address-filter'];
|
|
}
|
|
}
|
|
|
|
$this->layout->set("filter", $filter);
|
|
$filter = $this->getPreparedFilter($filter);
|
|
|
|
// 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;
|
|
}
|
|
|
|
|
|
private function getPreparedFilter($filter) {
|
|
$new_filter = [];
|
|
|
|
if (is_array($filter)) {
|
|
|
|
$new_filter['add-where'] = "";
|
|
|
|
if (array_key_exists("kunde", $filter) && $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 (strpos($kunde, "ß") !== false || strpos($kunde, "ss") !== false) {
|
|
$kundeWithSS = str_replace("ß", "ss", $kunde);
|
|
$kundeWithoutSS = str_replace("ss", "ß", $kunde);
|
|
$new_filter['add-where'] .= " AND (company like '%$kundeWithoutSS%' OR firstname like '%$kundeWithoutSS%' OR lastname like '%$kundeWithoutSS%' OR concat(firstname, ' ', lastname) like '%$kundeWithoutSS%' OR concat(lastname, ' ', firstname) like '%$kundeWithoutSS%')";
|
|
$new_filter['add-where'] .= " OR (company like '%$kundeWithSS%' OR firstname like '%$kundeWithSS%' OR lastname like '%$kundeWithSS%' OR concat(firstname, ' ', lastname) like '%$kundeWithSS%' OR concat(lastname, ' ', firstname) like '%$kundeWithSS%')";
|
|
} else {
|
|
$new_filter['add-where'] .= " AND (company like '%$kunde%' OR firstname like '%$kunde%' OR lastname like '%$kunde%' OR concat(firstname, ' ', lastname) like '%$kunde%' OR concat(lastname, ' ', firstname) like '%$kunde%')";
|
|
}
|
|
}
|
|
|
|
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_or_supplier_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"] == "systemowner") {
|
|
$new_filter["customer_or_fibu_numbers"] = true;
|
|
} elseif ($filter["type"] == "others") {
|
|
$new_filter["customer_or_fibu_numbers"] = false;
|
|
}
|
|
} else {
|
|
if (defined("TT_ADDRESS_FILTER_DEFAULT_SYSOWNER") && TT_ADDRESS_FILTER_DEFAULT_SYSOWNER) {
|
|
$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);
|
|
|
|
//var_dump($address->links_to);exit;
|
|
|
|
if (!$address->id) {
|
|
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
}
|
|
|
|
protected function invoiceAction() {
|
|
$this->layout()->setTemplate("Address/invoice");
|
|
|
|
$address_id = $this->request->address_id;
|
|
if (!is_numeric($address_id) || $address_id < 1) {
|
|
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
$address = new Address($address_id);
|
|
if (!$address->id) {
|
|
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
$invoices = InvoiceModel::search(["owner_or_billingaddress_id" => $address->id], false, "invoice_date DESC");
|
|
$this->layout()->set("invoices", $invoices);
|
|
$this->layout()->set("address", $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 exportBmdAction() {
|
|
if (!$this->me->can("Fibu")) {
|
|
$this->layout()->setFlash("Sicha ned!", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
$return = Address::runBmdExport($this->request->type);
|
|
|
|
if ($return === 10) {
|
|
$this->layout()->setFlash("Export Pfad (" . TT_ADDRESS_BMD_EXPORT_PATH . ") nicht gefunden!", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
if ($return === 11) {
|
|
$this->layout()->setFlash("Keine geänderten Adressdatensätze gefunden. Export abgebrochen.", "warn");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
if ($return === 19) {
|
|
$this->layout()->setFlash("Datei " . TT_ADDRESS_BMD_EXPORT_PATH . "/" . TT_ADDRESS_BMD_EXPORT_FILENAME . " konnte nicht gespeichert werden!", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
if ($return === true) {
|
|
$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'] = trim($r->company);
|
|
$data['firstname'] = trim($r->firstname);
|
|
$data['lastname'] = trim($r->lastname);
|
|
$data['street'] = trim($r->street);
|
|
$data['zip'] = trim($r->zip);
|
|
$data['city'] = trim($r->city);
|
|
$data['country_id'] = $r->country_id;
|
|
$data['phone'] = trim($r->phone);
|
|
$data['fax'] = trim($r->fax);
|
|
$data['mobile'] = trim($r->mobile);
|
|
$data['email'] = trim($r->email);
|
|
$data['note'] = trim($r->note);
|
|
$data['uid'] = trim($r->uid);
|
|
|
|
if (trim($r->birthdate)) {
|
|
try {
|
|
$data["birthdate"] = (DateTime::createFromFormat("d.m.Y", trim($r->birthdate)))->format("Y-m-d");
|
|
} catch (Exception $e) {
|
|
$this->layout()->setFlash("Ungültiges Geburtsdaum", "warning");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if ($this->me->can("Fibu")) {
|
|
$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_supplier_number'] = ($r->fibu_supplier_number) ? trim($r->fibu_supplier_number) : null;
|
|
if ($r->fibu_primary_account) {
|
|
$data['fibu_primary_account'] = 1;
|
|
} else {
|
|
$data['fibu_primary_account'] = 0;
|
|
}
|
|
|
|
if ($r->fibu_supplier_paymentblock) {
|
|
$data['fibu_supplier_paymentblock'] = 1;
|
|
} else {
|
|
$data['fibu_supplier_paymentblock'] = 0;
|
|
}
|
|
|
|
$data['fibu_payment_due'] = ($r->fibu_payment_due) ? trim($r->fibu_payment_due) : null;
|
|
$data['fibu_payment_skonto'] = ($r->fibu_payment_skonto) ? trim($r->fibu_payment_skonto) : null;
|
|
$data['fibu_payment_skonto_rate'] = ($r->fibu_payment_skonto_rate) ? trim($r->fibu_payment_skonto_rate) : null;
|
|
|
|
$data['fibu_supplier_due'] = ($r->fibu_supplier_due) ? trim($r->fibu_supplier_due) : null;
|
|
$data['fibu_supplier_skonto'] = ($r->fibu_supplier_skonto) ? trim($r->fibu_supplier_skonto) : null;
|
|
$data['fibu_supplier_skonto_rate'] = ($r->fibu_supplier_skonto_rate) ? trim($r->fibu_supplier_skonto_rate) : 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";
|
|
if (!$r->sepa_date) {
|
|
if ($mode == "add" || ($mode == "edit" && !$address->sepa_date)) {
|
|
$data['sepa_date'] = date('U');
|
|
}
|
|
} else {
|
|
$data['sepa_date'] = Layout::dateToInt($r->sepa_date);
|
|
}
|
|
} else {
|
|
$data['billing_type'] = "invoice";
|
|
}
|
|
|
|
if ($r->billing_delivery == "paper") {
|
|
$data['billing_delivery'] = "paper";
|
|
} else {
|
|
$data['billing_delivery'] = "email";
|
|
}
|
|
|
|
|
|
$data['bank_account_bank'] = trim($r->bank_account_bank);
|
|
$data['bank_account_owner'] = trim($r->bank_account_owner);
|
|
$data['bank_account_iban'] = strtoupper(trim($r->bank_account_iban));
|
|
$data['bank_account_bic'] = strtoupper(trim($r->bank_account_bic));
|
|
$data['allow_contact'] = ($r->allow_contact) ? 1 : 0;
|
|
$data['allow_spin'] = ($r->allow_spin) ? 1 : 0;
|
|
|
|
if ($mode == "add") {
|
|
$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();
|
|
|
|
}
|
|
}
|
|
|
|
// run afterSave() again in case anything importand has changed
|
|
$address->afterSave();
|
|
|
|
$sq = "";
|
|
$query = [];
|
|
if ($r->s) {
|
|
$query['s'] = $r->s;
|
|
}
|
|
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();
|
|
$a['name'] = $address->getCompanyOrName();
|
|
|
|
return ['address' => $a];
|
|
}
|
|
|
|
private function findAddressApi() {
|
|
$search = trim($this->request->q);
|
|
$autocomplete = $this->request->autocomplete;
|
|
|
|
if ($autocomplete && $this->request->searchedID) {
|
|
$address = new Address($this->request->searchedID);
|
|
if ($address->id) {
|
|
$result = [
|
|
'value' => $address->id,
|
|
'text' => str_replace("'", "\\'", str_replace(["\n",
|
|
"\r"], " ", $address->getCompanyOrName())) . " (" . $address->zip . " " . $address->city . ", " . $address->street . ")" . (($address->customer_number) ? " [" . $address->customer_number . "]" : "")
|
|
];
|
|
$results[] = $result;
|
|
$this->returnJson($results);
|
|
die();
|
|
}
|
|
}
|
|
|
|
$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);
|
|
}
|
|
}
|
|
|
|
|
|
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,
|
|
"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 {
|
|
$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;
|
|
|
|
}
|
|
|
|
public function createTicketAction() {
|
|
// die('{"derivedStartDate":null,"derivedDueDate":null,"spentTime":"PT0S","laborCosts":"0,00 EUR","materialCosts":"0,00 EUR","overallCosts":"0,00 EUR","_embedded":{"attachments":{"_type":"Collection","total":0,"count":0,"_embedded":{"elements":[]},"_links":{"self":{"href":"/api/v3/work_packages/6664/attachments"}}},"relations":{"_type":"Collection","total":0,"count":0,"_embedded":{"elements":[]},"_links":{"self":{"href":"/api/v3/work_packages/6664/relations"}}},"type":{"_type":"Type","id":12,"name":"Störung","color":"#FF3300","position":4,"isDefault":true,"isMilestone":false,"createdAt":"2023-02-22T20:19:25Z","updatedAt":"2023-02-23T11:59:16Z","_links":{"self":{"href":"/api/v3/types/12","title":"Störung"}}},"priority":{"_type":"Priority","id":8,"name":"Residential","position":2,"color":"#74C0FC","isDefault":true,"isActive":true,"_links":{"self":{"href":"/api/v3/priorities/8","title":"Residential"}}},"project":{"_type":"Project","id":10,"identifier":"storungen-and-support","name":"Störungen & Support","active":true,"public":false,"description":{"format":"markdown","raw":"","html":""},"createdAt":"2023-02-22T19:45:24Z","updatedAt":"2024-01-19T19:56:27Z","statusExplanation":{"format":"markdown","raw":"","html":""},"_links":{"self":{"href":"/api/v3/projects/10","title":"Störungen & Support"},"createWorkPackage":{"href":"/api/v3/projects/10/work_packages/form","method":"post"},"createWorkPackageImmediately":{"href":"/api/v3/projects/10/work_packages","method":"post"},"workPackages":{"href":"/api/v3/projects/10/work_packages"},"categories":{"href":"/api/v3/projects/10/categories"},"versions":{"href":"/api/v3/projects/10/versions"},"memberships":{"href":"/api/v3/memberships?filters=%5B%7B%22project%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%2210%22%5D%7D%7D%5D"},"types":{"href":"/api/v3/projects/10/types"},"schema":{"href":"/api/v3/projects/schema"},"status":{"href":null},"ancestors":[{"href":"/api/v3/projects/5","title":"XINON"}],"parent":{"href":"/api/v3/projects/5","title":"XINON"}}},"status":{"_type":"Status","id":1,"name":"Neu","isClosed":false,"color":"#1098AD","isDefault":true,"isReadonly":false,"defaultDoneRatio":null,"position":1,"_links":{"self":{"href":"/api/v3/statuses/1","title":"Neu"}}},"author":{"_type":"User","id":30,"name":"Luca Haid","createdAt":"2024-02-05T11:35:52Z","updatedAt":"2024-10-21T06:32:44Z","login":"luca.haid@xinon.eu","firstName":"Luca","lastName":"Haid","email":"luca.haid@xinon.eu","avatar":"https://secure.gravatar.com/avatar/37a35a87af3c506c1ce722826834ce38?default=404&secure=true","status":"active","identityUrl":null,"language":"de","_links":{"self":{"href":"/api/v3/users/30","title":"Luca Haid"},"memberships":{"href":"/api/v3/memberships?filters=%5B%7B%22principal%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%2230%22%5D%7D%7D%5D","title":"Mitglieder"},"showUser":{"href":"/users/30","type":"text/html"}}},"customActions":[],"costsByType":{"_type":"Collection","total":0,"count":0,"_embedded":{"elements":[]},"_links":{"self":{"href":"/api/v3/work_packages/6664/summarized_costs_by_type"}}}},"_type":"WorkPackage","id":6664,"lockVersion":1,"subject":"tes","description":{"format":"markdown","raw":"ttest","html":"<p class=\"op-uc-p\">ttest</p>"},"scheduleManually":false,"startDate":null,"dueDate":null,"estimatedTime":null,"derivedEstimatedTime":null,"duration":null,"ignoreNonWorkingDays":false,"percentageDone":0,"createdAt":"2024-10-31T12:48:27Z","updatedAt":"2024-10-31T12:48:27Z","readonly":false,"remainingTime":null,"customField1":null,"customField2":"4 Quality GmbH & Co KG","customField3":"Grazerstraße 87, 8111 Judendorf-Straßengel","customField4":"test","customField5":"office@4quality.at","customField6":"2215","customField7":"ZE4889","_links":{"attachments":{"href":"/api/v3/work_packages/6664/attachments"},"addAttachment":{"href":"/api/v3/work_packages/6664/attachments","method":"post"},"self":{"href":"/api/v3/work_packages/6664","title":"tes"},"update":{"href":"/api/v3/work_packages/6664/form","method":"post"},"schema":{"href":"/api/v3/work_packages/schemas/10-12"},"updateImmediately":{"href":"/api/v3/work_packages/6664","method":"patch"},"logTime":{"href":"/api/v3/time_entries","title":"Log time on tes"},"move":{"href":"/work_packages/6664/move/new","type":"text/html","title":"Move tes"},"copy":{"href":"/work_packages/6664/copy","title":"Copy tes"},"pdf":{"href":"/work_packages/6664.pdf","type":"application/pdf","title":"Export as PDF"},"atom":{"href":"/work_packages/6664.atom","type":"application/rss+xml","title":"Atom feed"},"availableRelationCandidates":{"href":"/api/v3/work_packages/6664/available_relation_candidates","title":"Potential work packages to relate to"},"activities":{"href":"/api/v3/work_packages/6664/activities"},"availableWatchers":{"href":"/api/v3/work_packages/6664/available_watchers"},"relations":{"href":"/api/v3/work_packages/6664/relations"},"revisions":{"href":"/api/v3/work_packages/6664/revisions"},"watchers":{"href":"/api/v3/work_packages/6664/watchers"},"addWatcher":{"href":"/api/v3/work_packages/6664/watchers","method":"post","payload":{"user":{"href":"/api/v3/users/{user_id}"}},"templated":true},"removeWatcher":{"href":"/api/v3/work_packages/6664/watchers/{user_id}","method":"delete","templated":true},"addRelation":{"href":"/api/v3/work_packages/6664/relations","method":"post","title":"Add relation"},"addChild":{"href":"/api/v3/projects/storungen-and-support/work_packages","method":"post","title":"Add child of tes"},"changeParent":{"href":"/api/v3/work_packages/6664","method":"patch","title":"Change parent of tes"},"addComment":{"href":"/api/v3/work_packages/6664/activities","method":"post","title":"Add comment"},"previewMarkup":{"href":"/api/v3/render/markdown?context=/api/v3/work_packages/6664","method":"post"},"timeEntries":{"href":"/api/v3/time_entries?filters=%5B%7B%22work_package_id%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%226664%22%5D%7D%7D%5D","title":"Time entries"},"category":{"href":null},"type":{"href":"/api/v3/types/12","title":"Störung"},"priority":{"href":"/api/v3/priorities/8","title":"Residential"},"project":{"href":"/api/v3/projects/10","title":"Störungen & Support"},"status":{"href":"/api/v3/statuses/1","title":"Neu"},"author":{"href":"/api/v3/users/30","title":"Luca Haid"},"responsible":{"href":null},"assignee":{"href":null},"version":{"href":null},"logCosts":{"href":"/work_packages/6664/cost_entries/new","type":"text/html","title":"Log costs on tes"},"showCosts":{"href":"/projects/10/cost_reports?fields%5B%5D=WorkPackageId&operators%5BWorkPackageId%5D=%3D&set_filter=1&values%5BWorkPackageId%5D=6664","type":"text/html","title":"Show cost entries"},"costsByType":{"href":"/api/v3/work_packages/6664/summarized_costs_by_type"},"github_pull_requests":{"href":"/api/v3/work_packages/6664/github_pull_requests","title":"GitHub pull requests"},"unwatch":{"href":"/api/v3/work_packages/6664/watchers/30","method":"delete"},"ancestors":[],"parent":{"href":null,"title":null},"customActions":[]}}');
|
|
// subject: test
|
|
//description: test
|
|
//customer_name: 4 Quality GmbH & Co KG
|
|
//customer_number: 2215
|
|
//customer_address: Grazerstraße 87, 8111 Judendorf-Straßengel
|
|
//customer_phone_number: 0664
|
|
//customer_email: office@4quality.at
|
|
//customer_service_pin: ZE4889
|
|
|
|
$subject = $this->request->subject;
|
|
$description = $this->request->description;
|
|
$customer_name = $this->request->customer_name;
|
|
$customer_number = $this->request->customer_number;
|
|
$customer_address = $this->request->customer_address;
|
|
$customer_phone_number = $this->request->customer_phone_number;
|
|
$customer_email = $this->request->customer_email;
|
|
$customer_service_pin = $this->request->customer_service_pin;
|
|
$user_api_key = (string) $this->me->getFlag('project_api_key');
|
|
|
|
$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);
|
|
|
|
die($response);
|
|
|
|
}
|
|
|
|
protected function ticketsAndShippingNoteAction() {
|
|
$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]]]])]);
|
|
|
|
$shippingNotes = array_map(function ($shippingNote) {
|
|
$shippingNote->createByName = (new User($shippingNote->createBy))->getAbbrName();
|
|
return $shippingNote;
|
|
}, WarehouseShippingNoteModel::getAll(['billingAddressId' => $address->id]));
|
|
|
|
Helper::renderVue($this,"AddressTickets",
|
|
"Tickets und Lieferscheine von Kunden: " . $address->getCompanyOrName() . '(' . $address->customer_number . ')', ["TICKETS" => $tickets,"SHIPPING_NOTES" => $shippingNotes,"ADDRESS" => $address]);
|
|
}
|
|
|
|
protected function sendServicePinAction() {
|
|
$address_id = $this->request->id;
|
|
if(!is_numeric($address_id) || !$address_id) {
|
|
$this->layout->setFlash("Adresse nicht gefunden!", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
$address = new Address($address_id);
|
|
if(!$address->id) {
|
|
$this->layout->setFlash("Adresse nicht gefunden!", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
if(!$address->customer_number || !$address->spin) {
|
|
$this->layout->setFlash("Kunde hat keine Kundennummer oder keinen Service PIN!", "error");
|
|
$this->redirect("Address");
|
|
}
|
|
|
|
if($address->sendSpinEmail()) {
|
|
$this->layout()->setFlash("Service PIN wurde erfolgreich versendet.", "success");
|
|
} else {
|
|
$this->layout()->setFlash("Fehler beim SPIN Versand!", "success");
|
|
}
|
|
|
|
$this->redirect("Address");
|
|
}
|
|
}
|