db_onedev = $this->load->database("onedev", true); } function lookuplabrefbyname(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $branch = $prm['branch'];; $all = $prm['all']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = "select COUNT(*) as total FROM(SELECT * from m_labreference WHERE M_LabReferenceName LIKE CONCAT('%','{$branch}','%') AND M_LabReferenceIsActive = 'Y' GROUP BY M_LabReferenceID) a"; // $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("m_labreference count", $this->db_onedev); exit; } $sql = "select M_LabReferenceID as id, M_LabReferenceName as name, M_LabReferenceCode as code, CONCAT(M_LabReferenceAddress, ', Telp: ',IF(M_LabReferencePhone = '','-',M_LabReferencePhone),', Kota: ', M_CityName, ' ,Kecamatan: ', M_DistrictName, ' ,Kelurahan: ', M_KelurahanName) as address, M_CityID, M_CityName, M_DistrictID, M_DistrictName, M_KelurahanID, M_KelurahanName, m_labreference.* from m_labreference LEFT JOIN m_city ON M_LabReferenceM_CityID = M_CityID LEFT JOIN m_district ON M_LabReferenceM_DistrictID = M_DistrictID LEFT JOIN m_kelurahan ON M_LabReferenceM_KelurahanID = M_KelurahanID WHERE M_LabReferenceName LIKE CONCAT('%','{$branch}','%') AND M_LabReferenceIsActive = 'Y' GROUP BY M_LabReferenceID ORDER BY M_LabReferenceName ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_labreference select"); exit; } $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function lookupbranchbyname(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $regional = $prm['regional']; $branch = $prm['branch']; $all = $prm['all']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = "select COUNT(*) as total FROM(SELECT * from m_labreference LEFT JOIN t_labref_price ON M_LabReferenceID = T_LabRefPriceM_LabReferenceID AND T_LabRefPriceIsActive = 'Y' LEFT JOIN t_test ON T_LabRefPriceT_TestID = T_TestID WHERE M_LabReferenceName LIKE CONCAT('%','{$regional}','%') AND T_TestName LIKE CONCAT('%','{$branch}','%') AND M_LabReferenceIsActive = 'Y' GROUP BY M_LabReferenceID) a"; // $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("m_labreference count", $this->db_onedev); exit; } $sql = "select T_LabRefPriceID as id, M_LabReferenceID, M_LabReferenceName, t_labref_price.*, DATE_FORMAT(T_LabRefPriceStartDate,'%d-%m-%Y') as sdate, DATE_FORMAT(T_LabRefPriceEndDate,'%d-%m-%Y') as edate, T_TestID, T_TestName, CONCAT(DATE_FORMAT(T_LabRefPriceStartDate,'%d-%m-%Y'), ' s/d ', DATE_FORMAT(T_LabRefPriceEndDate,'%d-%m-%Y')) as periode, FORMAT(T_LabRefPriceAmount,0) as harga from m_labreference LEFT JOIN t_labref_price ON M_LabReferenceID = T_LabRefPriceM_LabReferenceID AND T_LabRefPriceIsActive = 'Y' LEFT JOIN t_test ON T_LabRefPriceT_TestID = T_TestID WHERE M_LabReferenceName LIKE CONCAT('%','{$regional}','%') AND T_TestName LIKE CONCAT('%','{$branch}','%') AND M_LabReferenceIsActive = 'Y' GROUP BY M_LabReferenceID ORDER BY M_LabReferenceName ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_labreference select"); exit; } $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function lookupbranchbyid(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['regional']; $branch = $prm['branch']; $all = $prm['all']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = "select COUNT(*) as total FROM(SELECT * from m_labreference LEFT JOIN t_labref_price ON M_LabReferenceID = T_LabRefPriceM_LabReferenceID AND T_LabRefPriceIsActive = 'Y' LEFT JOIN t_test ON T_LabRefPriceT_TestID = T_TestID WHERE M_LabReferenceID = $id AND T_TestName LIKE CONCAT('%','{$branch}','%') AND M_LabReferenceIsActive = 'Y' GROUP BY M_LabReferenceID) a"; // $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("m_labreference count", $this->db_onedev); exit; } $sql = "select T_LabRefPriceID as id, M_LabReferenceID, M_LabReferenceName, t_labref_price.*, DATE_FORMAT(T_LabRefPriceStartDate,'%d-%m-%Y') as sdate, DATE_FORMAT(T_LabRefPriceEndDate,'%d-%m-%Y') as edate, T_TestID, T_TestName, CONCAT(DATE_FORMAT(T_LabRefPriceStartDate,'%d-%m-%Y'), ' s/d ', DATE_FORMAT(T_LabRefPriceEndDate,'%d-%m-%Y')) as periode, FORMAT(T_LabRefPriceAmount,0) as harga from m_labreference LEFT JOIN t_labref_price ON M_LabReferenceID = T_LabRefPriceM_LabReferenceID AND T_LabRefPriceIsActive = 'Y' LEFT JOIN t_test ON T_LabRefPriceT_TestID = T_TestID WHERE M_LabReferenceID = $id AND T_TestName LIKE CONCAT('%','{$branch}','%') AND M_LabReferenceIsActive = 'Y' GROUP BY M_LabReferenceID ORDER BY M_LabReferenceName ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_labreference select"); exit; } $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function lookupregionalbyname() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $regional = $prm['regional']; $branch = $prm['branch']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = "select COUNT(*) as total FROM(SELECT * from m_labreference LEFT JOIN m_labreference ON M_LabReferenceID = M_LabReferenceM_LabReferenceID AND M_LabReferenceIsActive = 'Y' where M_LabReferenceName LIKE CONCAT('%','{$regional}','%') AND IFNULL(M_LabReferenceName,'') LIKE CONCAT('%','{$branch}','%') AND M_LabReferenceIsActive = 'Y' GROUP BY M_LabReferenceID) a"; $sql_param = array($search); // $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $query = $this->db_onedev->query($sql); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("m_labreference count", $this->db_onedev); exit; } $sql = "select M_LabReferenceID as id, M_LabReferenceName as name, M_LabReferenceName as namex, m_labreference.* from m_labreference LEFT JOIN m_labreference ON M_LabReferenceID = M_LabReferenceM_LabReferenceID AND M_LabReferenceIsActive = 'Y' where M_LabReferenceName LIKE CONCAT('%','{$regional}','%') AND IFNULL(M_LabReferenceName,'') LIKE CONCAT('%','{$branch}','%') AND M_LabReferenceIsActive = 'Y' GROUP BY M_LabReferenceID ORDER BY M_LabReferenceName ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_labreference select"); exit; } $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewregional() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name = $prm['name']; $sql = "insert into m_labreference( M_LabReferenceName, M_LabReferenceCreated, M_LabReferenceLastUpdated ) values( ?, now(), now())"; $query = $this->db_onedev->query($sql, array( $name ) ); //echo $query; if (!$query) { $this->sys_error_db("m_labreference insert"); exit; } $last_id = $this->db_onedev->insert_id(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); $last_id = $this->db_onedev->insert_id(); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function editregional() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id = $prm['id']; $name = $prm['name']; $userid = $this->sys_user["M_UserID"]; $sqlcompany = "update m_labreference SET M_LabReferenceName = ?, M_LabReferenceLastUpdated = now() where M_LabReferenceID = ? "; $querycompany = $this->db_onedev->query($sqlcompany, array( $name, $id ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("m_labreference update"); exit; } $result = array ("total" => 1, "records" => array("xid" => $id)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewprice() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $labid = $prm['labid']; $sdate = $prm['sdate']; $edate = $prm['edate']; $testid = $prm['testid']; $price = $prm['price']; $userid = $this->sys_user["M_UserID"]; if($labid == 0 || $testid == 0){ $errors = array(); if($labid == 0){ array_push($errors,array('field'=>'lab','msg'=>'Lab Rujukan dipilih dulu dong')); } if($testid == 0){ array_push($errors,array('field'=>'test','msg'=>'Pemeriksaan dipilih dulu dong')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); }else{ if($prm['xid'] == 0){ $sql = "insert into t_labref_price( T_LabRefPriceM_LabReferenceID, T_LabRefPriceT_TestID, T_LabRefPriceStartDate, T_LabRefPriceEndDate, T_LabRefPriceAmount, T_LabRefPriceUserID, T_LabRefPriceCreated, T_LabRefPriceLastUpdated) values(?,?,?,?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $labid, $testid, $sdate, $edate, $price, $userid ) ); if (!$query) { $this->sys_error_db("t_labref_price insert",$this->db_onedev); exit; } $last_id = $this->db_onedev->insert_id(); //echo $this->db_onedev->last_query(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $sql = "UPDATE t_labref_price SET T_LabRefPriceT_TestID = '{$testid}', T_LabRefPriceStartDate = '{$sdate}', T_LabRefPriceEndDate = '{$edate}', T_LabRefPriceAmount = '{$price}', T_LabRefPriceUserID = '{$userid}' WHERE T_LabRefPriceID = '{$prm['xid']}'"; //echo $sql; $query = $this->db_onedev->query($sql); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewlabref() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $pic = $prm['pic']; $name = $prm['name']; $address = $prm['address']; $phone = $prm['phone']; $cityid = $prm['cityid']; $districtid = $prm['districtid']; $kelurahanid = $prm['kelurahanid']; $userid = $this->sys_user["M_UserID"]; $numbering = $this->db_onedev->query("SELECT fn_numbering('LREF') as numbering")->row()->numbering; if($cityid == 0 || $districtid == 0 || $kelurahanid == 0){ $errors = array(); if($cityid == 0){ array_push($errors,array('field'=>'city','msg'=>'Kota dipilih dulu dong')); } if($districtid == 0){ array_push($errors,array('field'=>'district','msg'=>'Kecamatan dipilih dulu dong')); } if($kelurahanid == 0){ array_push($errors,array('field'=>'kelurahan','msg'=>'Kelurahan dipilih dulu dong')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); }else{ if($prm['xid'] == 0){ $query = "SELECT COUNT(*) as exist FROM m_labreference WHERE M_LabReferenceIsActive = 'Y' AND M_LabReferenceName = '{$name}'"; $exist_code = $this->db_onedev->query($query)->row()->exist; if($exist_code == 0){ $sql = "insert into m_labreference( M_LabReferenceName, M_LabReferenceCode, M_LabReferenceAddress, M_LabReferencePhone, M_LabReferenceM_CityID, M_LabReferenceM_DistrictID, M_LabReferenceM_KelurahanID, M_LabReferenceUp, M_LabReferenceUserID, M_LabReferenceLastUpdated, M_LabReferenceCreated) values(?,?,?,?,?,?,?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $name, $numbering, $address, $phone, $cityid, $districtid, $kelurahanid, $pic, $userid ) ); if (!$query) { $this->sys_error_db("m_labreference insert",$this->db_onedev); exit; } $last_id = $this->db_onedev->insert_id(); //echo $this->db_onedev->last_query(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $errors = array(); if($exist_code != 0){ array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); } }else{ $query = "SELECT COUNT(*) as exist FROM m_labreference WHERE M_LabReferenceIsActive = 'Y' AND M_LabReferenceName = '{$name}' AND M_LabReferenceID <> {$prm['xid']}"; //echo $query; $exist_code = $this->db_onedev->query($query)->row()->exist; // echo $exist_code; if($exist_code == 0){ $sql = "UPDATE m_labreference SET M_LabReferenceName = '{$name}', M_LabReferenceAddress = '{$address}', M_LabReferencePhone = '{$phone}', M_LabReferenceM_CityID = '{$cityid}', M_LabReferenceM_DistrictID = '{$districtid}', M_LabReferenceM_KelurahanID = '{$kelurahanid}', M_LabReferenceUserID = '{$userid}', M_LabReferenceUp = '{$pic}' WHERE M_LabReferenceID = '{$prm['xid']}'"; //echo $sql; $query = $this->db_onedev->query($sql); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $errors = array(); if($exist_code != 0){ array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); } } } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletelabref() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $sql = "update m_labreference SET M_LabReferenceIsActive = 'N', M_LabReferenceUserID = ?, M_LabReferenceLastUpdated = now() WHERE M_LabReferenceID = ? "; $query = $this->db_onedev->query($sql, array( $userid, $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_labreference delete"); exit; } $sql = "update t_labref_price SET T_LabRefPriceIsActive = 'N', T_LabRefPriceUserID = ?, T_LabRefPriceLastUpdated = now() WHERE T_LabRefPriceM_LabReferenceID = ? "; $query = $this->db_onedev->query($sql, array($userid, $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("t_labref_price delete"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletebranch() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $sql = "update t_labref_price SET T_LabRefPriceIsActive = 'N', T_LabRefPriceUserID = ?, T_LabRefPriceLastUpdated = now() WHERE T_LabRefPriceID = ? "; $query = $this->db_onedev->query($sql, array($userid, $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_labreference delete"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function searchlabref(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_labreference WHERE M_LabReferenceName like ? AND M_LabReferenceIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_labreference count",$this->db_onedev); exit; } $sql = " SELECT M_LabReferenceID, M_LabReferenceName FROM m_labreference WHERE M_LabReferenceName like ? AND M_LabReferenceIsActive = 'Y' ORDER BY M_LabReferenceName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_labreference rows",$this->db_onedev); exit; } } function searchregionalbyname(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_labreference WHERE M_LabReferenceName like ? AND M_LabReferenceIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_labreference count",$this->db_onedev); exit; } $sql = " SELECT M_LabReferenceID, M_LabReferenceName FROM m_labreference WHERE M_LabReferenceName like ? AND M_LabReferenceIsActive = 'Y' ORDER BY M_LabReferenceName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_labreference rows",$this->db_onedev); exit; } } function searchtest(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM t_test WHERE T_TestName like ? AND T_TestIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("t_test count",$this->db_onedev); exit; } $sql = " SELECT * FROM t_test WHERE T_TestName like ? AND T_TestIsActive = 'Y' ORDER BY T_TestName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("t_test rows",$this->db_onedev); exit; } } function searchcity(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_city count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y' ORDER BY M_CityName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_city rows",$this->db_onedev); exit; } } function searchdistrict(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_district WHERE M_DistrictName like ? AND M_DistrictM_CityID = '{$id}' AND M_DistrictIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_district count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_district WHERE M_DistrictName like ? AND M_DistrictM_CityID = '{$id}' AND M_DistrictIsActive = 'Y' ORDER BY M_DistrictName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_district rows",$this->db_onedev); exit; } } function searchkelurahan(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_kelurahan WHERE M_KelurahanName like ? AND M_KelurahanM_DistrictID = '{$id}' AND M_KelurahanIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_district count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_kelurahan WHERE M_KelurahanName like ? AND M_KelurahanM_DistrictID = '{$id}' AND M_KelurahanIsActive = 'Y' ORDER BY M_KelurahanName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_district rows",$this->db_onedev); exit; } } function searchcompany(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_company WHERE M_CompanyName like ? AND M_CompanyIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_company count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_company WHERE M_CompanyName like ? AND M_CompanyIsActive = 'Y' ORDER BY M_CompanyName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_company rows",$this->db_onedev); exit; } } function searchmou(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_mou WHERE M_MouName like ? AND M_MouM_CompanyID = '{$id}' AND M_MouIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_mou count",$this->db_onedev); exit; } $sql = "SELECT * FROM m_mou WHERE M_MouName like ? AND M_MouM_CompanyID = '{$id}' AND M_MouIsActive = 'Y' ORDER BY M_MouName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); // echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_mou rows",$this->db_onedev); exit; } } function searchdoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName FROM m_doctor WHERE M_DoctorIsActive = 'Y') a WHERE M_DoctorName like ?"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_doctor count",$this->db_onedev); exit; } $sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName FROM m_doctor WHERE M_DoctorIsActive = 'Y') a WHERE M_DoctorName like ? GROUP BY M_DoctorID ORDER BY M_DoctorName ASC"; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_doctor rows",$this->db_onedev); exit; } } function selectaddressdoctor(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $rows = []; $query ="SELECT M_DoctorAddressID, CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote FROM m_doctoraddress WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'"; //echo $query; $rows['addressdoctors'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }