diff --git a/app/Controllers/Api/ControlApiController.php b/app/Controllers/Api/ControlApiController.php index 89389bb..e375076 100644 --- a/app/Controllers/Api/ControlApiController.php +++ b/app/Controllers/Api/ControlApiController.php @@ -24,8 +24,10 @@ class ControlApiController extends BaseController public function index() { + $keyword = $this->request->getGet('keyword'); + $deptId = $this->request->getGet('deptId'); try { - $rows = $this->dictControlModel->getWithDept(); + $rows = $this->dictControlModel->getWithDept($keyword, $deptId); return $this->respond([ 'status' => 'success', 'message' => 'fetch success', diff --git a/app/Models/DictControlModel.php b/app/Models/DictControlModel.php index ac56d3d..52c3461 100644 --- a/app/Models/DictControlModel.php +++ b/app/Models/DictControlModel.php @@ -19,11 +19,23 @@ class DictControlModel extends BaseModel return $this->where('dept_ref_id', $deptId)->findAll(); } - public function getWithDept() + public function getWithDept($keyword = null, $deptId = null) { $builder = $this->db->table('dict_controls c'); $builder->select('c.*, d.name as dept_name'); $builder->join('dict_depts d', 'd.dept_id = c.dept_ref_id', 'left'); + + if ($keyword) { + $builder->groupStart(); + $builder->like('c.name', $keyword); + $builder->orLike('c.lot', $keyword); + $builder->groupEnd(); + } + + if ($deptId) { + $builder->where('c.dept_ref_id', $deptId); + } + return $builder->get()->getResultArray(); } diff --git a/app/Views/control/index.php b/app/Views/control/index.php index 4ccc8f4..85cb763 100644 --- a/app/Views/control/index.php +++ b/app/Views/control/index.php @@ -27,6 +27,12 @@ + @@ -66,6 +72,7 @@ Name Lot Department + Status Expiry Date Actions @@ -79,6 +86,9 @@ + + +