93 lines
3.5 KiB
PHP
93 lines
3.5 KiB
PHP
<?php
|
|
|
|
class WorkorderTenantConfigController extends TTCrud {
|
|
protected string $headerTitle = 'Mandanten & Firmen Konfiguration';
|
|
protected bool $createText = false;
|
|
protected array $columns = [];
|
|
|
|
protected function indexAction() {
|
|
Helper::renderVue($this, 'WorkorderTenantConfig', $this->headerTitle, []);
|
|
}
|
|
|
|
protected function getTenantConfigsAction() {
|
|
$configs = WorkorderTenantConfigModel::getAll([], null, 0, ['key' => 'name', 'order' => 'ASC']);
|
|
self::returnJson($configs);
|
|
}
|
|
|
|
protected function saveTenantConfigAction() {
|
|
$data = $this->postData;
|
|
$data['documentationTypes'] = json_encode($data['documentationTypes'] ?? []);
|
|
$data['interventionTypes'] = json_encode($data['interventionTypes'] ?? []);
|
|
$data['workorderCreationFilters'] ??= '{}';
|
|
|
|
if (empty($data['id'])) {
|
|
$data['create'] = time();
|
|
$data['createBy'] = $this->user->id;
|
|
WorkorderTenantConfigModel::create($data);
|
|
} else {
|
|
WorkorderTenantConfigModel::update($data);
|
|
}
|
|
self::returnJson(['success' => true, 'message' => 'Mandanten-Konfiguration gespeichert.']);
|
|
}
|
|
|
|
protected function deleteTenantConfigAction() {
|
|
if (empty($this->postData['id'])) self::sendError("ID fehlt.");
|
|
|
|
WorkorderTenantConfigModel::delete($this->postData['id']);
|
|
self::returnJson(['success' => true, 'message' => 'Mandanten-Konfiguration gelöscht.']);
|
|
}
|
|
|
|
protected function getCompaniesAction() {
|
|
$companies = WorkorderCompanyModel::getAll([], null, 0, ['key' => 'name', 'order' => 'ASC']);
|
|
foreach ($companies as $company) {
|
|
$company->workers = WorkorderCompanyModel::getCompanyWorkers($company->id);
|
|
}
|
|
self::returnJson($companies);
|
|
}
|
|
|
|
protected function saveCompanyAction() {
|
|
$data = $this->postData;
|
|
if (empty($data['name']) || empty($data['addressId'])) self::sendError("Name und Adresse sind erforderlich.");
|
|
|
|
unset($data['workers']);
|
|
$data['visibleForAddressId'] = json_encode($data['visibleForAddressId'] ?? []);
|
|
|
|
if (empty($data['id'])) {
|
|
$data['create'] = time();
|
|
$data['createBy'] = $this->user->id;
|
|
WorkorderCompanyModel::create($data);
|
|
} else {
|
|
WorkorderCompanyModel::update($data);
|
|
}
|
|
self::returnJson(['success' => true, 'message' => 'Firma gespeichert.']);
|
|
}
|
|
|
|
protected function deleteCompanyAction() {
|
|
if (empty($this->postData['id'])) self::sendError("ID fehlt.");
|
|
|
|
WorkorderCompanyModel::delete($this->postData['id']);
|
|
self::returnJson(['success' => true, 'message' => 'Firma gelöscht.']);
|
|
}
|
|
|
|
protected function addressAutocompleteAction() {
|
|
$search = trim($this->request->q ?? '');
|
|
$searchedID = $this->request->searchedID ?? null;
|
|
$addresses = [];
|
|
|
|
if ($searchedID) {
|
|
$ids = array_filter(explode(',', $searchedID));
|
|
if ($ids) $addresses = AddressModel::search(['id' => $ids]);
|
|
} elseif (strlen($search) >= 2) {
|
|
$addresses = array_slice(AddressModel::search(["company" => $search]), 0, 15);
|
|
}
|
|
|
|
$results = array_map(function($address) {
|
|
return [
|
|
'value' => $address->id,
|
|
'text' => "{$address->getCompanyOrName()} ({$address->zip} {$address->city})"
|
|
];
|
|
}, $addresses);
|
|
|
|
self::returnJson($results);
|
|
}
|
|
} |