diff --git a/ci4/app/Controllers/Clientes/Cliente.php b/ci4/app/Controllers/Clientes/Cliente.php index 44c7e8f4..ec271292 100755 --- a/ci4/app/Controllers/Clientes/Cliente.php +++ b/ci4/app/Controllers/Clientes/Cliente.php @@ -333,21 +333,21 @@ class Cliente extends \App\Controllers\BaseResourceController public function getSelect2() { if ($this->request->isAJAX()) { - $searchStr = goSanitize($this->request->getGet('searchTerm'))[0]; - $reqId = goSanitize($this->request->getGet('id'))[0]; - $reqText = goSanitize($this->request->getGet('text'))[0]; - $onlyActiveOnes = false; - $columns2select = [$reqId ?? 'id', $reqText ?? 'nombre']; - $onlyActiveOnes = false; - try{ - $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); + $query = $this->model->builder()->select( + [ + "id", + "nombre as name" + ] + )->where("deleted_at", null); + + if ($this->request->getGet("q")) { + $query->groupStart() + ->orLike("clientes.nombre", $this->request->getGet("q")) + ->groupEnd(); } - catch(Exception $e){ - $menu = []; - } - - $menu, - return $this->respond($menu); + + return $this->response->setJSON($query->get()->getResultObject()); + // return $this->respond($menu); } else { return $this->failUnauthorized('Invalid request', 403); }