db_onedev = $this->load->database("onedev", true); } function lookuptrendanalys(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select nat_trend_analysis.*,Nat_TestID as testid from nat_trend_analysis JOIN nat_test ON Nat_TrendAnalysisNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y' where Nat_TrendAnalysisNat_TestID = {$id} AND Nat_TrendAnalysisIsActive = 'Y'"; $sql_param = array($orderid); $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("nat_trend_analysis select"); exit; } $result = array ("total" => count($rows), "records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function lookuphasil(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select Nat_MultiruleID as id, M_ValueName as name, Nat_MultiruleM_ValueID as hasilid, Nat_MultiruleNat_TestID as testid from nat_multirule JOIN m_value ON Nat_MultiruleM_ValueID = M_ValueID AND M_ValueIsActive = 'Y' where Nat_MultiruleNat_TestID = {$id} AND Nat_MultiruleIsActive = 'Y'"; $sql_param = array($orderid); $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("nat_multirule"); exit; } $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 nat_test LEFT JOIN nat_trend_analysis ON Nat_TestID = Nat_TrendAnalysisNat_TestID LEFT JOIN nat_delta_check ON Nat_TestID = Nat_DeltaCheckNat_TestID where Nat_TestIsActive = 'Y' AND Nat_TestIsQuantitative = 'Y' AND Nat_TestIsResult = 'Y'"; $sql_param = array($search); $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $sql = "select Nat_TestID as id, CONCAT(Nat_TestName,' ' ,'[ ',Nat_TestCode,' ]') as name, Nat_TrendAnalysisNat_TestID,Nat_TrendAnalysisMinCount,Nat_TrendAnalysisLow, Nat_TrendAnalysisHigh, nat_delta_check.*, M_TimeName as xtime, Nat_DeltaTypeName as xdif,Nat_TestIsDeltaCheck,Nat_TestIsTrendAnalysis from nat_test LEFT JOIN nat_trend_analysis ON Nat_TestID = Nat_TrendAnalysisNat_TestID LEFT JOIN nat_delta_check ON Nat_TestID = Nat_DeltaCheckNat_TestID LEFT JOIN m_time ON Nat_DeltaCheckM_TimeID = M_TimeID LEFT JOIN nat_delta_type ON Nat_DeltaCheckNat_DeltaTypeID = Nat_DeltaTypeID where (Nat_TestName LIKE CONCAT('%','{$search}','%') OR Nat_TestCode LIKE CONCAT('%','{$search}','%')) AND Nat_TestIsActive = 'Y' AND Nat_TestIsQuantitative = 'Y' AND (Nat_TestIsDeltaCheck = 'Y' OR Nat_TestIsTrendAnalysis = 'Y') $limit"; // echo $sql; $sql_param = array($search); $query = $this->db_onedev->query($sql,$sql_param); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("nat_test select"); 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 addnewschedule() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name_schedule = $prm['name']; $query = "SELECT COUNT(*) as exist FROM m_schedule WHERE M_ScheduleIsActive = 'Y' AND M_ScheduleName = '{$name_schedule}'"; $exist_name = $this->db_onedev->query($query)->row()->exist; if($exist_name == 0){ $sql = "insert into m_schedule( M_ScheduleName, M_ScheduleCreated, M_ScheduleLastUpdated ) values( ?,now(),now())"; $query = $this->db_onedev->query($sql, array( $name_schedule ) ); //echo $query; if (!$query) { $this->sys_error_db("m_schedule insert"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $result = array ("total" => -1, "records" => 0); $this->sys_ok($result); } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function editschedule() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_schedule = $prm['id']; $name_schedule = $prm['name']; $query = "SELECT COUNT(*) as exist FROM m_schedule WHERE M_ScheduleIsActive = 'Y' AND M_ScheduleName = '{$name_schedule}' AND M_ScheduleID <> {$id_schedule}"; $exist_name = $this->db_onedev->query($query)->row()->exist; if($exist_name == 0){ $sql = "update m_schedule SET M_ScheduleName = ?, M_ScheduleLastUpdated = now() where M_ScheduleID = ? "; $query = $this->db_onedev->query($sql, array( $name_schedule, $id_schedule ) ); //echo $query; if (!$query) { $this->sys_error_db("m_schedule update"); exit; } $result = array ("total" => 1, "records" => array("xid" => $id_schedule)); $this->sys_ok($result); }else{ $result = array ("total" => -1, "records" => 0); $this->sys_ok($result); } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function savetrendanalys() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $testid = $prm['testid']; $mintest = $prm['mintest']; $islow = $prm['islow']; $ishigh = $prm['ishigh']; $query = "SELECT COUNT(*) as exist FROM nat_trend_analysis WHERE Nat_TrendAnalysisIsActive = 'Y' AND Nat_TrendAnalysisNat_TestID = '{$testid}'"; $exisnat_test = $this->db_onedev->query($query)->row()->exist; if($exisnat_test == 0){ $sql = "insert into nat_trend_analysis( Nat_TrendAnalysisNat_TestID, Nat_TrendAnalysisMinCount, Nat_TrendAnalysisLow, Nat_TrendAnalysisHigh, Nat_TrendAnalysisCreated, Nat_TrendAnalysisLastUpdated ) values( ?,?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $testid, $mintest, $islow, $ishigh ) ); //echo $query; if (!$query) { $this->sys_error_db("nat_trend_analysis insert"); exit; } } else { $sql = "update nat_trend_analysis SET Nat_TrendAnalysisMinCount = ?, Nat_TrendAnalysisLow = ?, Nat_TrendAnalysisHigh = ?, Nat_TrendAnalysisLastUpdated = now() WHERE Nat_TrendAnalysisIsActive = 'Y' AND Nat_TrendAnalysisNat_TestID = ? "; $query = $this->db_onedev->query($sql, array( $mintest, $islow, $ishigh, $testid ) ); if (!$query) { $this->sys_error_db("nat_trend_analysis update"); 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 savedeltacheck() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $testid = $prm['testid']; $differenceid = $prm['differenceid']; $validinterval = $prm['validinterval']; $timeid = $prm['timeid']; $minvalue = $prm['minvalue']; $maxvalue = $prm['maxvalue']; $query = "SELECT COUNT(*) as exist FROM nat_delta_check WHERE Nat_DeltaCheckIsActive = 'Y' AND Nat_DeltaCheckNat_TestID = '{$testid}'"; $exisnat_test = $this->db_onedev->query($query)->row()->exist; if($exisnat_test == 0){ $sql = "insert into nat_delta_check( Nat_DeltaCheckNat_TestID, Nat_DeltaCheckNat_DeltaTypeID, Nat_DeltaCheckInterval, Nat_DeltaCheckM_TimeID, Nat_DeltaCheckMinValue, Nat_DeltaCheckMaxValue, Nat_DeltaCheckCreated, Nat_DeltaCheckLastUpdated ) values( ?,?,?,?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $testid, $differenceid, $validinterval, $timeid, $minvalue, $maxvalue ) ); //echo $query; if (!$query) { $this->sys_error_db("nat_delta_check insert"); exit; } } else { $sql = "update nat_delta_check SET Nat_DeltaCheckNat_DeltaTypeID = ?, Nat_DeltaCheckInterval = ?, Nat_DeltaCheckM_TimeID = ?, Nat_DeltaCheckMinValue = ?, Nat_DeltaCheckMaxValue = ?, Nat_DeltaCheckLastUpdated = now() WHERE Nat_DeltaCheckIsActive = 'Y' AND Nat_DeltaCheckNat_TestID = ? "; $query = $this->db_onedev->query($sql, array( $differenceid, $validinterval, $timeid, $minvalue, $maxvalue, $testid ) ); if (!$query) { $this->sys_error_db("nat_delta_check update"); exit; } } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectvaluex(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM m_value WHERE M_ValueIsActive = 'Y' "; //echo $query; $rows['valuexs'] = $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); } } function selecttime(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM m_time WHERE M_TimeIsActive = 'Y' "; //echo $query; $rows['times'] = $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); } } function selectdif(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM nat_delta_type WHERE Nat_DeltaTypeIsActive = 'Y' "; //echo $query; $rows['difs'] = $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); } } public function savemultirule() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $testid = $prm['testid']; $hasilid = $prm['hasilid']; $sql = "insert into nat_multirule( Nat_MultiruleNat_TestID, Nat_MultiruleM_ValueID, Nat_MultiruleCreated, Nat_MultiruleLastUpdated ) values( ?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $testid, $hasilid ) ); //echo $query; if (!$query) { $this->sys_error_db("nat_multirule insert"); 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 deleteschedulepromise() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update m_schedulepromise SET M_SchedulePromiseIsActive = 'N', M_SchedulePromiseLastUpdate = now() WHERE M_SchedulePromiseID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_schedulepromise 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 deletescheduletest() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update m_scheduletest SET M_ScheduleTestIsActive = 'N', M_ScheduleTestLastUpdated = now() WHERE M_ScheduleTestID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_scheduletest 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 deleteschedule() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update m_schedule SET M_ScheduleIsActive = 'N', M_ScheduleLastUpdated = now() WHERE M_ScheduleID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_schedule delete"); exit; } $sql = "update m_scheduletest SET M_ScheduleTestIsActive = 'N', M_ScheduleTestLastUpdated = now() WHERE M_ScheduleTestM_ScheduleID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_scheduletest delete"); exit; } $sql = "update m_schedulepromise SET M_SchedulePromiseIsActive = 'N', M_SchedulePromiseLastUpdate = now() WHERE M_SchedulePromiseM_ScheduleID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_schedulepromise 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 searchtest() { $prm = $this->sys_input; $scheduleid = $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 nat_test LEFT JOIN m_scheduletest ON M_ScheduleTestNat_TestID = Nat_TestID AND M_ScheduleTestM_ScheduleID = ? AND M_ScheduleTestIsActive = 'Y' WHERE ISNULL(M_ScheduleTestID) AND Nat_TestIsActive = 'Y' AND Nat_TestName like ?"; $query = $this->db_onedev->query($sql,array($scheduleid,$q['search'])); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("nat_test count",$this->db_onedev); exit; } $sql = " SELECT Nat_TestID as id, Nat_TestName as name FROM nat_test LEFT JOIN m_scheduletest ON M_ScheduleTestNat_TestID = Nat_TestID AND M_ScheduleTestM_ScheduleID = ? AND M_ScheduleTestIsActive = 'Y' WHERE ISNULL(M_ScheduleTestID) AND Nat_TestIsActive = 'Y' AND Nat_TestName like ? ORDER BY Nat_TestCode ASC "; $query = $this->db_onedev->query($sql, array($scheduleid,$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("nat_test rows",$this->db_onedev); exit; } } }