array('invoices','customers','id','nama',null),'item'=>array('items','items','id','nama_barang','kode_barang'),'account'=>array('jurnal','accounts','id','nama_akun','kode_akun'),'employee'=>array('employees','k_employees','id','full_name','employee_code'),'supplier'=>array('purchases','suppliers','id','name','supplier_code')); if(!isset($map[$type]))show_404();list($feature,$table,$id,$label,$code)=$map[$type];$this->requirePermission($feature);$term=trim((string)$this->input->get('q',true));$page=max(1,(int)$this->input->get('page'));$limit=min(30,max(10,(int)$this->input->get('limit')?:20));$hasCode=$code&&$this->db->field_exists($code,$table);$this->db->select("$id id,$label label".($hasCode?",$code code":''))->from($table);if($this->db->field_exists('company_id',$table))$this->db->where('company_id',$this->companycontext->id());if($this->db->field_exists('is_active',$table))$this->db->where('is_active',1);if($type==='account'&&$this->db->field_exists('allow_posting','accounts'))$this->db->where('allow_posting',1);if($term!==''){$this->db->group_start()->like($label,$term);if($hasCode)$this->db->or_like($code,$term);$this->db->group_end();}$rows=$this->db->order_by($label)->limit($limit+1,($page-1)*$limit)->get()->result_array();$more=count($rows)>$limit;if($more)array_pop($rows);$results=array_map(function($r){return array('id'=>$r['id'],'text'=>(isset($r['code'])&&$r['code']!==''?$r['code'].' ยท ':'').$r['label']);},$rows);$this->output->set_content_type('application/json')->set_output(json_encode(array('results'=>$results,'pagination'=>array('more'=>$more)))); } }