db_onedev = $this->load->database("onedev", true); } function lookuptest(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select M_ScheduleTestID as id, T_TestShortName as name, M_ScheduleTestT_TestID as testid from m_scheduletest JOIN t_test ON M_ScheduleTestT_TestID = T_TestID AND T_TestIsActive = 'Y' where M_ScheduleTestM_ScheduleID = {$id} AND M_ScheduleTestIsActive = 'Y'"; $sql_param = array($orderid); $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_scheduletest select by schedule"); exit; } $result = array ("total" => count($rows), "records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function lookuppromise(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select M_SchedulePromiseID as id, M_SchedulePromiseDayOfWeek as dayofweek, 'xxx' as dayofweekname, M_SchedulePromiseStartHourMinute as start_hm, M_SchedulePromiseEndHourMinute as end_hm, M_SchedulePromiseDay as xday, M_SchedulePromiseHour as xhour, M_SchedulePromiseMin as xmin, M_SchedulePromiseAtTime as at_time, M_SchedulePromiseFlagAtTime as flagattime, 'xxx' as action from m_schedulepromise where M_SchedulePromiseM_ScheduleID = {$id} AND M_SchedulePromiseIsActive = 'Y'"; $sql_param = array($orderid); $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); foreach($rows as $k=>$v){ if(intval($v['dayofweek']) == 1){ $rows[$k]['dayofweekname'] = 'Minggu'; }elseif(intval($v['dayofweek']) == 2){ $rows[$k]['dayofweekname'] = 'Senin'; }elseif(intval($v['dayofweek']) == 3){ $rows[$k]['dayofweekname'] = 'Selasa'; }elseif(intval($v['dayofweek']) == 4){ $rows[$k]['dayofweekname'] = 'Rabu'; }elseif(intval($v['dayofweek']) == 5){ $rows[$k]['dayofweekname'] = 'Kamis'; }elseif(intval($v['dayofweek']) == 6){ $rows[$k]['dayofweekname'] = 'Jumat'; }elseif(intval($v['dayofweek']) == 7){ $rows[$k]['dayofweekname'] = 'Sabtu'; } } } else { $this->sys_error_db("m_scheduletestpromise select by schedule"); exit; } $result = array ("total" => count($rows), "records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function lookuppreschedulepromise(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select M_PreSchedulePromiseID as id, M_PreSchedulePromiseDayOfWeek as dayofweek, 'xxx' as dayofweekname, M_PreSchedulePromiseHour as xhour, 'xxx' as action from m_preschedulepromise where M_PreSchedulePromiseM_ScheduleID = {$id} AND M_PreSchedulePromiseIsActive = 'Y'"; $sql_param = array($orderid); $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); foreach($rows as $k=>$v){ if(intval($v['dayofweek']) == 1){ $rows[$k]['dayofweekname'] = 'Minggu'; }elseif(intval($v['dayofweek']) == 2){ $rows[$k]['dayofweekname'] = 'Senin'; }elseif(intval($v['dayofweek']) == 3){ $rows[$k]['dayofweekname'] = 'Selasa'; }elseif(intval($v['dayofweek']) == 4){ $rows[$k]['dayofweekname'] = 'Rabu'; }elseif(intval($v['dayofweek']) == 5){ $rows[$k]['dayofweekname'] = 'Kamis'; }elseif(intval($v['dayofweek']) == 6){ $rows[$k]['dayofweekname'] = 'Jumat'; }elseif(intval($v['dayofweek']) == 7){ $rows[$k]['dayofweekname'] = 'Sabtu'; } } } else { $this->sys_error_db("m_preschedulepromise select by schedule"); 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 m_schedule where M_ScheduleIsActive = 'Y'"; $sql_param = array($search); $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $sql = "select M_ScheduleID as id, M_ScheduleName as name, M_ScheduleFlagPreSchedule as flagpreschedule, M_SchedulePreScheduleMaxHour as preschedulemaxhour, M_ScheduleName as detail, IF(M_ScheduleFlagPreSchedule = 'Y', 'Pre Schedule', ' - ') as ispreschedule, 'xxx' as scheduletests, 'xxx' as schedulepromise, 'xxx' as preschedulepromise from m_schedule where M_ScheduleName LIKE CONCAT('%',?,'%') AND M_ScheduleIsActive = 'Y' $limit"; $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("m_schedule 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']; $flagpreschedule = $prm['flagpreschedule']; $preschedulemaxhour = $prm['preschedulemaxhour']; $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_ScheduleFlagPreSchedule, M_SchedulePreScheduleMaxHour, M_ScheduleCreated, M_ScheduleLastUpdated ) values( ?, ?, ?, now(),now())"; $query = $this->db_onedev->query($sql, array( $name_schedule, $flagpreschedule, $preschedulemaxhour ) ); //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']; $flagpreschedule = $prm['flagpreschedule']; $preschedulemaxhour = $prm['preschedulemaxhour']; $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_ScheduleFlagPreSchedule = ?, M_SchedulePreScheduleMaxHour = ?, M_ScheduleLastUpdated = now() where M_ScheduleID = ? "; $query = $this->db_onedev->query($sql, array( $name_schedule, $flagpreschedule, $preschedulemaxhour, $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 addnewscheduletest() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $scheduleid = $prm['scheduleid']; $testid = $prm['testid']; $sql = "insert into m_scheduletest( M_ScheduleTestM_ScheduleID, M_ScheduleTestT_TestID, M_ScheduleTestCreated, M_ScheduleTestLastUpdated ) values( ?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $scheduleid, $testid ) ); //echo $query; if (!$query) { $this->sys_error_db("m_scheduletest 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 addnewschedulepromise() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; if($prm['xid'] == "0" || $prm['xid'] == 0){ $sql = "insert into m_schedulepromise( M_SchedulePromiseM_ScheduleID, M_SchedulePromiseDayOfWeek, M_SchedulePromiseStartHourMinute, M_SchedulePromiseEndHourMinute, M_SchedulePromiseDay, M_SchedulePromiseHour, M_SchedulePromiseMin, M_SchedulePromiseAtTime, M_SchedulePromiseFlagAtTime, M_SchedulePromiseCreated, M_SchedulePromiseLastUpdate ) values( ?,?,?,?,?,?,?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $prm['scheduleid'], $prm['dayofweek'], $prm['starthm'], $prm['endhm'], $prm['xday'], $prm['xhour'], $prm['xminute'], $prm['attime'], $prm['flagattime'] ) ); if (!$query) { $this->sys_error_db("m_schedulepromise insert"); exit; } } else{ $sql = "update m_schedulepromise SET M_SchedulePromiseDayOfWeek = ?, M_SchedulePromiseStartHourMinute = ?, M_SchedulePromiseEndHourMinute = ?, M_SchedulePromiseDay = ?, M_SchedulePromiseHour = ?, M_SchedulePromiseMin = ?, M_SchedulePromiseAtTime = ?, M_SchedulePromiseFlagAtTime = ?, M_SchedulePromiseLastUpdate = now() WHERE M_SchedulePromiseID = ? "; $query = $this->db_onedev->query($sql, array( $prm['dayofweek'], $prm['starthm'], $prm['endhm'], $prm['xday'], $prm['xhour'], $prm['xminute'], $prm['attime'], $prm['flagattime'], $prm['xid'] ) ); if (!$query) { $this->sys_error_db("m_schedulepromise 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 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 addnewpreschedulepromise() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $dayofweek = $prm['dayofweek']; $query = "SELECT COUNT(*) as exist FROM m_preschedulepromise WHERE M_PreSchedulePromiseIsActive = 'Y' AND M_PreSchedulePromiseDayOfWeek = '{$dayofweek}'"; $exist_name = $this->db_onedev->query($query)->row()->exist; if($prm['xid'] == "0" || $prm['xid'] == 0){ if($exist_name == 0){ $sql = "insert into m_preschedulepromise( M_PreSchedulePromiseM_ScheduleID, M_PreSchedulePromiseDayOfWeek, M_PreSchedulePromiseHour, M_PreSchedulePromiseCreated, M_PreSchedulePromiseLastUpdated ) values( ?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $prm['scheduleid'], $prm['dayofweek'], $prm['xhour'] ) ); if (!$query) { $this->sys_error_db("m_preschedulepromise 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); } } else{ $idx = $prm['xid']; $dayofweek = $prm['dayofweek']; $query = "SELECT COUNT(*) as exist FROM m_preschedulepromise WHERE M_PreSchedulePromiseIsActive = 'Y' AND M_PreSchedulePromiseDayOfWeek = '{$dayofweek}' AND M_PreSchedulePromiseID <> {$idx}"; $exist_name = $this->db_onedev->query($query)->row()->exist; if($exist_name == 0){ $sql = "update m_preschedulepromise SET M_PreSchedulePromiseDayOfWeek = ?, M_PreSchedulePromiseHour = ?, M_PreSchedulePromiseLastUpdated = now() WHERE M_PreSchedulePromiseID = ? "; $query = $this->db_onedev->query($sql, array( $prm['dayofweek'], $prm['xhour'], $prm['xid'] ) ); if (!$query) { $this->sys_error_db("m_preschedulepromise update"); 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 deletepreschedulepromise() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update m_preschedulepromise SET M_PreSchedulePromiseIsActive = 'N', M_PreSchedulePromiseLastUpdated = now() WHERE M_PreSchedulePromiseID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_preschedulepromise 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 t_test LEFT JOIN m_scheduletest ON M_ScheduleTestT_TestID = T_TestID AND M_ScheduleTestM_ScheduleID = ? AND M_ScheduleTestIsActive = 'Y' WHERE ISNULL(M_ScheduleTestID) AND T_TestIsActive = 'Y' AND T_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("t_test count",$this->db_onedev); exit; } $sql = " SELECT T_TestID as id, T_TestName as name FROM t_test LEFT JOIN m_scheduletest ON M_ScheduleTestT_TestID = T_TestID AND M_ScheduleTestM_ScheduleID = ? AND M_ScheduleTestIsActive = 'Y' WHERE ISNULL(M_ScheduleTestID) AND T_TestIsActive = 'Y' AND T_TestName like ? ORDER BY T_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("t_test rows",$this->db_onedev); exit; } } }