Contract WIP
This commit is contained in:
@@ -65,4 +65,105 @@ class ContractController extends mfBaseController {
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "getContract":
|
||||
$return = $this->getContractApi();
|
||||
break;
|
||||
case "findContract":
|
||||
$return = $this->findContractApi();
|
||||
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 getContractApi() {
|
||||
$contract_id = $this->request->contract_id;
|
||||
if(!is_numeric($contract_id) || $contract_id < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$form_id = false;
|
||||
if($this->request->form_id) {
|
||||
$form_id = $this->request->form_id;
|
||||
}
|
||||
|
||||
$contract = new Contract($contract_id);
|
||||
if(!$contract->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $contract->toArray();
|
||||
|
||||
return ["contract" => $data, "form_id" => $form_id];
|
||||
}
|
||||
|
||||
private function findContractApi() {
|
||||
$search = trim($this->request->q);
|
||||
$autocomplete = $this->request->autocomplete;
|
||||
|
||||
$contracts = [];
|
||||
|
||||
if(is_numeric($search)) {
|
||||
$c = new Contract($search);
|
||||
if($c->id) {
|
||||
if(!array_key_exists($c->id, $contracts)) {
|
||||
$contracts[$c->id] = $c;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(["id", "owner_id", "product_id"] as $search_key) {
|
||||
foreach(ContractModel::search([$search_key => $search]) as $c) {
|
||||
if(!array_key_exists($c->id, $contracts)) {
|
||||
$contracts[$c->id] = $c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(["product_name", "matchcode", "owner"] as $search_key) {
|
||||
foreach(ContractModel::search([$search_key => $search]) as $c) {
|
||||
if(!array_key_exists($c->id, $contracts)) {
|
||||
$contracts[$c->id] = $c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!is_array($contracts) && !count($contracts)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
// return bootstrap-autocomplete format
|
||||
foreach($contracts as $contract) {
|
||||
//$result = ['value' => $contract->id, 'text' => str_replace("'", "\\'", str_replace(["\n", "\r"], " ",$contract->name))];
|
||||
$result = ['value' => $contract->id, 'text' => $contract->id.": ".$contract->product_name." [".$contract->matchcode."] (".$contract->owner->getCompanyOrName().", ".$contract->owner->street.", ".$contract->owner->zip." ".$contract->owner->city.")"];
|
||||
|
||||
$results[] = $result;
|
||||
if(count($results) > 15) {
|
||||
$results[] = ['value' => 0, 'text' => " --> Mehr Suchergebnisse vorhanden. Bitte Suchbegriff genauer definieren <--"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->returnJson($results);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user