db_onedev = $this->load->database("onedev", true); } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $nama = $prm["nama"]; $status = $prm["status"]; // echo $norm; $sql_where = "WHERE M_StaffIsActive = 'Y' "; $sql_param = array(); if ($nama != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_StaffName like ? "; $sql_param[] = "%$nama%"; } $sql = " SELECT count(*) as total FROM one.m_staff LEFT JOIN one_preorder_dev.m_staffhomeservice ON M_StaffID = M_StaffHomeServiceM_StaffID AND M_StaffHomeServiceIsActive = 'Y' $sql_where "; $query = $this->db_onedev->query($sql, $sql_param); $tot_count = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_doctor count", $this->db_onedev); exit; } $sql = "SELECT one.m_staff.*,IFNULL(M_StaffHomeServiceID,0) as status FROM one.m_staff LEFT JOIN one_preorder_dev.m_staffhomeservice ON M_StaffID = M_StaffHomeServiceM_StaffID AND M_StaffHomeServiceIsActive = 'Y' $sql_where ORDER BY M_StaffName ASC limit 0,20"; $query = $this->db_onedev->query($sql, $sql_param); //echo $this->db_onedev->last_query(); $rows['all'] = $query->result_array(); $sql = "SELECT one.m_staff.* FROM one.m_staff JOIN one_preorder_dev.m_staffhomeservice ON M_StaffID = M_StaffHomeServiceM_StaffID AND M_StaffHomeServiceIsActive = 'Y' WHERE M_StaffIsActive = 'Y' ORDER BY M_StaffName ASC"; $query = $this->db_onedev->query($sql, $sql_param); //echo $this->db_onedev->last_query(); $rows['homeservice'] = $query->result_array(); //$this->_add_address($rows); $result = array("total_all" => $tot_count,"total_homeservice" => count($rows['homeservice']), "records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } function getsexreg(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM m_sex WHERE M_SexIsActive = 'Y' "; //echo $query; $rows['sexes'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT * FROM m_religion WHERE M_ReligionIsActive = 'Y' "; //echo $query; $rows['religions'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); 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 DESC "; $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 getdistrict(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT * FROM m_district WHERE M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getkelurahan(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT * FROM m_kelurahan WHERE M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function save(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query ="UPDATE m_doctor SET M_DoctorPrefix = '{$prm['M_DoctorPrefix']}', M_DoctorName = '{$prm['M_DoctorName']}', M_DoctorSufix = '{$prm['M_DoctorSufix']}', M_DoctorM_SexID = '{$prm['M_DoctorM_SexID']}', M_DoctorM_ReligionID = '{$prm['M_DoctorM_ReligionID']}', M_DoctorEmail = '{$prm['M_DoctorEmail']}', M_DoctorHP = '{$prm['M_DoctorHP']}', M_DoctorPhone = '{$prm['M_DoctorPhone']}', M_DoctorIsMarketingConfirm = '{$prm['M_DoctorIsMarketingConfirm']}', M_DoctorIsPJ = '{$prm['M_DoctorIsPJ']}', M_DoctorIsDefaultPJ = '{$prm['M_DoctorIsDefaultPJ']}', M_DoctorIsClinic = '{$prm['M_DoctorIsClinic']}', M_DoctorIsDefault = '{$prm['M_DoctorIsDefault']}' WHERE M_DoctorID = '{$prm['M_DoctorID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function newdoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query ="INSERT INTO m_doctor ( M_DoctorPrefix, M_DoctorName, M_DoctorSufix, M_DoctorM_SexID, M_DoctorM_ReligionID, M_DoctorEmail, M_DoctorHP, M_DoctorPhone, M_DoctorIsMarketingConfirm, M_DoctorIsPJ, M_DoctorIsDefaultPJ, M_DoctorIsClinic, M_DoctorIsDefault, M_DoctorCreated ) VALUES( '{$prm['M_DoctorPrefix']}', '{$prm['M_DoctorName']}', '{$prm['M_DoctorSufix']}', '{$prm['M_DoctorM_SexID']}', '{$prm['M_DoctorM_ReligionID']}', '{$prm['M_DoctorEmail']}', '{$prm['M_DoctorHP']}', '{$prm['M_DoctorPhone']}', '{$prm['M_DoctorIsMarketingConfirm']}', '{$prm['M_DoctorIsPJ']}', '{$prm['M_DoctorIsDefaultPJ']}', '{$prm['M_DoctorIsClinic']}', '{$prm['M_DoctorIsDefault']}', NOW() ) "; //echo $query; $rows = $this->db_onedev->query($query); $last_id = $this->db_onedev->insert_id(); $result = array( "total" => 1 , "records" => array('status'=>'OK'), "id" => $last_id ); $this->sys_ok($result); exit; } function deletedoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query ="UPDATE m_doctor SET M_DoctorIsActive = 'N' WHERE M_DoctorID = '{$prm['M_DoctorID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function getaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT m_doctoraddress.*, M_KelurahanName, M_DistrictID, M_DistrictName, M_CityID, M_CityName, '' as action FROM m_doctoraddress JOIN m_kelurahan ON M_DoctorAddressM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); if($rows){ foreach($rows as $k => $v){ $rows[$k]['action'] = 'delete'; $rows[$k]['action'] .= 'edit'; } } $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function savenewaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}' AND M_DoctorAddressIsActive = 'Y'")->row()->countx; //echo $this->db_onedev->last_query(); if($count_addrs == 0){ $prm['M_DoctorAddressNote'] = 'Utama'; } else{ $count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}' AND M_DoctorAddressNote = 'Utama' AND M_DoctorAddressIsActive = 'Y'")->row()->countx; if($count_addrs_utama > 0 && strtolower($prm['M_DoctorAddressNote']) == 'utama'){ $rx = date('YmdHis'); $prm['M_DoctorAddressNote'] = 'Utama_'.$rx; } } $query ="INSERT INTO m_doctoraddress ( M_DoctorAddressM_DoctorID, M_DoctorAddressNote, M_DoctorAddressDescription, M_DoctorAddressM_KelurahanID, M_DoctorAddressCreated ) VALUES( '{$prm['M_DoctorAddressM_DoctorID']}', '{$prm['M_DoctorAddressNote']}', '{$prm['M_DoctorAddressDescription']}', '{$prm['M_DoctorAddressM_KelurahanID']}', NOW() ) "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function saveeditaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query ="UPDATE m_doctoraddress SET M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}', M_DoctorAddressNote = '{$prm['M_DoctorAddressNote']}', M_DoctorAddressDescription = '{$prm['M_DoctorAddressDescription']}', M_DoctorAddressM_KelurahanID = '{$prm['M_DoctorAddressM_KelurahanID']}' WHERE M_DoctorAddressID = '{$prm['M_DoctorAddressID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function deleteaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query ="UPDATE m_doctoraddress SET M_DoctorAddressIsActive = 'N' WHERE M_DoctorAddressID = '{$prm['M_DoctorAddressID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function settohomeservice(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $query = "SELECT COUNT(*) as xcount FROM one_preorder_dev.m_staffhomeservice WHERE M_StaffHomeServiceM_StaffID = '{$prm['M_StaffID']}' AND M_StaffHomeServiceIsActive = 'Y'"; $check_exist = $this->db_onedev->query($query)->row()->xcount; if($check_exist == 0){ $query = "INSERT INTO one_preorder_dev.m_staffhomeservice (M_StaffHomeServiceM_StaffID,M_StaffHomeServiceIsActive,M_StaffHomeServiceUserID) VALUES({$prm['M_StaffID']},'Y',{$userid})"; $this->db_onedev->query($query); } else{ $query ="UPDATE one_preorder_dev.m_staffhomeservice SET M_StaffHomeServiceIsActive = 'N', M_StaffHomeServiceUserID = {$userid} WHERE M_StaffHomeServiceM_StaffID = '{$prm['M_StaffID']}' "; //echo $query; $rows = $this->db_onedev->query($query); } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } }