db_regional = $this->load->database("regional", true); } function lookupattributebyname(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $attribute = $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 nat_ol_description JOIN nat_test ON Nat_TestID = NatOlDescriptionNat_TestID WHERE (Nat_TestName LIKE CONCAT('%','{$attribute}','%') OR Nat_TestCode LIKE CONCAT('%','{$attribute}','%') OR Nat_TestShortNameBarcode LIKE CONCAT('%','{$attribute}','%')) AND NatOlDescriptionIsActive = 'Y'"; // $total = $this->db_regional->query($sql,$sql_param)->row()->total; $query = $this->db_regional->query($sql); // echo $this->db_regional->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("nat_ol_description count", $this->db_regional); exit; } $sql = "select NatOlDescriptionID as id, Nat_TestID, Nat_TestName as testname, Nat_TestCode, CONCAT('[',Nat_TestCode,'] ',Nat_TestName) as Nat_TestName, Nat_TestShortNameBarcode, nat_ol_description.* from nat_ol_description JOIN nat_test ON Nat_TestID = NatOlDescriptionNat_TestID WHERE (Nat_TestName LIKE CONCAT('%','{$attribute}','%') OR Nat_TestCode LIKE CONCAT('%','{$attribute}','%') OR Nat_TestShortNameBarcode LIKE CONCAT('%','{$attribute}','%')) AND NatOlDescriptionIsActive = 'Y' GROUP BY NatOlDescriptionID ORDER BY Nat_TestCode ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_regional->query($sql); //echo $this->db_regional->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("nat_ol_description 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']; $attribute = $prm['attribute']; $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 s_regional LEFT JOIN nat_ol_description ON S_RegionalID = NatOlDescriptionS_RegionalID AND NatOlDescriptionIsActive = 'Y' where S_RegionalName LIKE CONCAT('%','{$regional}','%') AND IFNULL(NatOlDescriptionName,'') LIKE CONCAT('%','{$attribute}','%') AND S_RegionalIsActive = 'Y' GROUP BY S_RegionalID) a"; $sql_param = array($search); // $total = $this->db_regional->query($sql,$sql_param)->row()->total; $query = $this->db_regional->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("s_regional count", $this->db_regional); exit; } $sql = "select S_RegionalID as id, S_RegionalName as name, S_RegionalName as namex, s_regional.* from s_regional LEFT JOIN nat_ol_description ON S_RegionalID = NatOlDescriptionS_RegionalID AND NatOlDescriptionIsActive = 'Y' where S_RegionalName LIKE CONCAT('%','{$regional}','%') AND IFNULL(NatOlDescriptionName,'') LIKE CONCAT('%','{$attribute}','%') AND S_RegionalIsActive = 'Y' GROUP BY S_RegionalID ORDER BY S_RegionalName ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_regional->query($sql); //echo $this->db_regional->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("s_regional 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 s_regional( S_RegionalName, S_RegionalCreated, S_RegionalLastUpdated ) values( ?, now(), now())"; $query = $this->db_regional->query($sql, array( $name ) ); //echo $query; if (!$query) { $this->sys_error_db("s_regional insert"); exit; } $last_id = $this->db_regional->insert_id(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); $last_id = $this->db_regional->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 s_regional SET S_RegionalName = ?, S_RegionalLastUpdated = now() where S_RegionalID = ? "; $querycompany = $this->db_regional->query($sqlcompany, array( $name, $id ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("s_regional 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 addnewattribute() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $NatOlDescriptionNat_TestID = $prm['testid']; $NatOlDescriptionNote = $prm['note']; $userid = $this->sys_user["M_UserID"]; if($NatOlDescriptionNat_TestID == 0){ $errors = array(); if($NatOlDescriptionNat_TestID == 0){ array_push($errors,array('field'=>'regional','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 nat_ol_description( NatOlDescriptionNat_TestID, NatOlDescriptionNote, NatOlDescriptionCreated, NatOlDescriptionLastUpdated, NatOlDescriptionM_UserID) values(?,?,now(),now(),?)"; $query = $this->db_regional->query($sql, array( $NatOlDescriptionNat_TestID, $NatOlDescriptionNote, $userid) ); if (!$query) { $this->sys_error_db("nat_ol_description insert",$this->db_regional); exit; } $last_id = $this->db_regional->insert_id(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $sql = "UPDATE nat_ol_description SET NatOlDescriptionNat_TestID = '{$NatOlDescriptionNat_TestID}', NatOlDescriptionNote = '{$NatOlDescriptionNote}', NatOlDescriptionM_UserID = '{$userid}', NatOlDescriptionLastUpdated = now() WHERE NatOlDescriptionID = '{$prm['xid']}'"; //echo $sql; $query = $this->db_regional->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 deleteregional() { 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 s_regional SET S_RegionalIsActive = 'N', S_RegionalLastUpdated = now() WHERE S_RegionalID = ? "; $query = $this->db_regional->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("s_regional delete"); exit; } $sql = "update nat_ol_description SET NatOlDescriptionIsActive = 'N', NatOlDescriptionLastUpdated = now() WHERE NatOlDescriptionS_RegionalID = ? "; $query = $this->db_regional->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("nat_ol_description 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 deleteattribute() { 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 nat_ol_description SET NatOlDescriptionIsActive = 'N', NatOlDescriptionLastUpdated = now() WHERE NatOlDescriptionID = ? "; $query = $this->db_regional->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("nat_ol_description 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 searchtest(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['tes'] != '') { $q['search'] = "%{$prm['tes']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM nat_test WHERE CONCAT('[',Nat_TestCode,'] ',Nat_TestName) like ? AND Nat_TestIsActive = 'Y' AND Nat_TestIsPrice = 'Y' AND Nat_TestID not in ( select NatOlDescriptionNat_TestID from nat_ol_description where NatOlDescriptionIsActive = 'Y')"; $query = $this->db_regional->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("nat_test count",$this->db_regional); exit; } $sql = " SELECT Nat_TestID,CONCAT('[',Nat_TestCode,'] ',Nat_TestName) as Nat_TestName FROM nat_test WHERE CONCAT('[',Nat_TestCode,'] ',Nat_TestName) like ? AND Nat_TestIsActive = 'Y' AND Nat_TestIsPrice = 'Y' AND Nat_TestID not in ( select NatOlDescriptionNat_TestID from nat_ol_description where NatOlDescriptionIsActive = 'Y') ORDER BY Nat_TestCode ASC "; $query = $this->db_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); // echo $this->db_regional->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("nat_test rows",$this->db_regional); 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 s_regional WHERE S_RegionalName like ? AND S_RegionalIsActive = 'Y'"; $query = $this->db_regional->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("s_regional count",$this->db_regional); exit; } $sql = " SELECT S_RegionalID, S_RegionalName FROM s_regional WHERE S_RegionalName like ? AND S_RegionalIsActive = 'Y' ORDER BY S_RegionalName ASC "; $query = $this->db_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("s_regional rows",$this->db_regional); exit; } } function searchsubcategory(){ 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_subcategory WHERE T_SubCategoryName like ? AND T_SubCategoryIsActive = 'Y'"; $query = $this->db_regional->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("t_subcategory count",$this->db_regional); exit; } $sql = " SELECT T_CategoryID, T_CategoryName,T_SubCategoryID,CONCAT(T_SubCategoryName,'[',T_CategoryName,'] ') T_SubCategoryName FROM t_subcategory JOIN t_category ON T_CategoryID = T_SubCategoryT_CategoryID WHERE CONCAT(T_SubCategoryName,'[',T_CategoryName,'] ') like ? AND T_SubCategoryIsActive = 'Y' ORDER BY T_SubCategoryName ASC "; $query = $this->db_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("t_subcategory rows",$this->db_regional); 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_DistrictT_SubCategoryID = '{$id}' AND M_DistrictIsActive = 'Y'"; $query = $this->db_regional->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_regional); exit; } $sql = " SELECT * FROM m_district WHERE M_DistrictName like ? AND M_DistrictT_SubCategoryID = '{$id}' AND M_DistrictIsActive = 'Y' ORDER BY M_DistrictName ASC "; $query = $this->db_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->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_regional); 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_regional->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_regional); 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_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->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_regional); 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_regional->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_regional); exit; } $sql = " SELECT * FROM m_company WHERE M_CompanyName like ? AND M_CompanyIsActive = 'Y' ORDER BY M_CompanyName ASC "; $query = $this->db_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->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_regional); 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_regional->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_regional); 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_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); // echo $this->db_regional->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_regional); 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_regional->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_regional); 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_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->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_regional); 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_regional->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); } } }