db_onedev = $this->load->database("onedev", true); } function lookupbahan(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select T_BahanID as id, T_BahanT_SampleStationID as usergroupid, T_BahanCode as code, T_BahanName As name, 'xxx' as action from t_bahan join t_samplestation oN T_BahanT_SampleStationID = T_SampleStationID where T_BahanT_SampleStationID = {$id} AND T_BahanIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result(); $result = array ("total" => count($rows), "records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function lookup() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = $prm['search']; $all = $prm['all']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $sql = "select COUNT(*) as total from t_samplestation where T_SampleStationIsActive = 'Y'"; $sql_param = array($search); $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $sql = "select T_SampleStationID as id, T_SampleStationCode as code, T_SampleStationName as name, T_SampleStationIsNonLab as isnonlab, T_SampleStationName as description , 'xxx' as usergrouptype from t_samplestation where T_SampleStationName LIKE CONCAT('%','{$search}','%') AND T_SampleStationIsActive = 'Y' $limit"; $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("t_samplestation select",$this->db_onedev); exit; } $result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewstation() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name_station = $prm['name']; $code_station = $prm['code']; $isnonlab_station = $prm['isnonlab']; $query = "SELECT COUNT(*) as exist FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' AND T_SampleStationName = '{$name_station}'"; $exist_name = $this->db_onedev->query($query)->row()->exist; //echo $exist_name; if($exist_name == 0 ){ $sql = "insert into t_samplestation( T_SampleStationCode, T_SampleStationName, T_SampleStationIsNonLab, T_SampleStationCreated, T_SampleStationLastUpdated ) values( ?, ?, ?,now(), now())"; $query = $this->db_onedev->query($sql, array( $name_station, $code_station, $isnonlab_station ) ); //echo $query; if (!$query) { $this->sys_error_db("t_samplestation insert"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } else{ $errors = array(); if($exist_name != 0){ array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada ')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function editstation() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_station = $prm['id']; $code_station = $prm['code']; $name_station = $prm['name']; $isnonlab_station = $prm['isnonlab']; $query = "SELECT COUNT(*) as exist FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' AND T_SampleStationName = '{$name_station}' AND T_SampleStationID <> {$id_station} "; $exist_name = $this->db_onedev->query($query)->row()->exist; if($exist_name == 0){ $sql = "update t_samplestation SET T_SampleStationCode = ?, T_SampleStationName = ?, T_SampleStationIsNonLab = ?, T_SampleStationLastUpdated = now() where T_SampleStationID = ? "; $query = $this->db_onedev->query($sql, array( $code_station, $name_station, $isnonlab_station, $id_station ) ); //file_put_contents("/tmp/adi-update-user.sql",$this->db_onedev->last_query()); //echo $query; if (!$query) { $this->sys_error_db("t_samplestation update"); exit; } $result = array ("total" => 1, "records" => array("xid" => $id_station)); $this->sys_ok($result); }else{ $errors = array(); if($exist_name != 0){ array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function editbahan() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $bahanid = $prm['xid']; $code = $prm['code']; $name = $prm['name']; $xstationname = $prm['xstationname']; $query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}' and T_BahanID <> $bahanid "; $exist_name = $this->db_onedev->query($query)->row()->exist; if($exist_name == 0){ $sql = "update m_user SET T_BahanCode = ?, T_BahanName = ?, T_BahanT_SampleStationID = ?, T_BahanLastUpdated = now() where T_BahanID = ? "; $query = $this->db_onedev->query($sql, array( $code, $name, $xstationname["T_SampleStationID"], $bahanid )); if (!$query) { $this->sys_error_db("t_bahan update",$this->db_onedev); exit; } $result = array ("total" => 1, "records" => array("xid" => $bahanid)); $this->sys_ok($result); } else { $errors = array(); if($exist_name != 0){ array_push($errors,array('field'=>'name','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 addnewbahan() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $stationid = $prm['stationid']; $code = $prm['code']; $name = $prm['name']; if($prm['xid'] == 0){ $query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}'"; $exist_name = $this->db_onedev->query($query)->row()->exist; if($exist_name == 0){ $sql = "insert into t_bahan( T_BahanT_SampleStationID, T_BahanCode, T_BahanName, T_BahanCreated, T_BahanLastUpdated ) values( ?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $stationid, $code, $name ) ); if (!$query) { $this->sys_error_db("t_bahan insert",$this->db_onedev); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $errors = array(); if($exist_name != 0){ array_push($errors,array('field'=>'name','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 t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}' AND T_BahanID <> {$prm['xid']}"; $exist_name = $this->db_onedev->query($query)->row()->exist; //echo $query; //echo $query; if($exist_name == 0 ){ $sql = "UPDATE t_bahan SET T_BahanName = '{$name}', T_BahanCode = '{$code}' WHERE T_BahanID = '{$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_name != 0){ array_push($errors,array('field'=>'name','msg'=>'name 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 deletebahan() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update t_bahan SET T_BahanIsActive = 'N', T_BahanLastUpdated = now() WHERE T_BahanID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("t_bahan 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 deleteselect() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update t_samplestation SET T_SampleStationIsActive = 'N', T_SampleStationLastUpdated = now() WHERE T_SampleStationID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("t_samplestation delete"); exit; } $sql = "UPDATE m_user SET M_UserIsActive = 'N', M_UserLastUpdated = now() WHERE M_UserM_UserGroupID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_user delete"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }