db_onedev = $this->load->database("onedev", true); } function lookupday(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select *, IF(isavailable = 'Y',M_ScheduleDayID,9000+dayofweek) as id, '{$id}' as paramid FROM (SELECT M_ScheduleDayID,M_DayOfWeekID as dayofweek, M_DayOfWeekName as dayofweekname, IF(IFNULL(M_ScheduleDayID,0) = 0 ,'N','Y') as isavailable from m_dayofweek LEFT JOIN m_schedule_day ON M_DayOfWeekID = M_ScheduleDayDayOfWeek AND M_ScheduleDayM_CourierID = {$id} AND M_ScheduleDayIsActive = 'Y' ORDER BY M_DayOfWeekID ASC) a ORDER BY dayofweek ASC"; $sql_param = array($orderid); $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_schedule_day 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_ScheduleID as id, CONCAT(M_ScheduleStartHourMinute,' - ',M_ScheduleEndHourMinute) as name, M_ScheduleDayOfWeek, M_DayOfWeekName as dayofweekname, M_ScheduleStartHourMinute as start_hm, M_ScheduleEndHourMinute as end_hm, M_ScheduleMonth as xmonth, M_ScheduleWeek as xweek, M_ScheduleDay as xday, M_ScheduleHour as xhour, M_ScheduleMinute as xmin, M_ScheduleAtTime as at_time, M_ScheduleFlagAtTime as flagattime, 'xxx' as action from m_schedule LEFT JOIN m_dayofweek ON M_ScheduleDayOfWeek = M_DayOfWeekID where M_ScheduleM_CourierID = {$id} AND M_ScheduleIsActive = 'Y' ORDER BY M_ScheduleDayOfWeek ASC, M_ScheduleStartHourMinute ASC, M_ScheduleEndHourMinute ASC,M_ScheduleID ASC"; //echo $sql; $query = $this->db_onedev->query($sql); if($query) { $rows = $query->result_array(); } else { $this->sys_error_db( $this->db_onedev->last_query() ); exit; } $result = array ("total" => count($rows), "records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selected_test() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql_param = array( $id ); $sql = "select distinct M_CourierTestNat_TestID Nat_TestID, Nat_TestName from m_couriertest join nat_test on Nat_TestID = M_CourierTestNat_TestID where M_CourierTestM_CourierID = ? and M_CourierTestIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db( $this->db_onedev->last_query() ); 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_courier where M_CourierIsActive = 'Y'"; $sql_param = array($search); $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $sql = "select M_CourierID as id, M_StaffID, M_StaffName as name, M_StafName as detail from m_courier JOIN m_staff ON M_CourierM_StaffID = M_StaffID where M_StaffName LIKE CONCAT('%',?,'%') AND M_CourierIsActive = '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_courier 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); } } function add_test($orderid){ $query =" SELECT m_couriertest.*, 'Y' as editable, M_CourierTestNat_TestID as xid, Nat_TestID, Nat_TestName FROM m_couriertest JOIN m_courier ON M_CourierTestM_CourierID = M_CourierID JOIN nat_test ON M_CourierTestNat_TestID = Nat_TestID WHERE M_CourierTestM_CourierID = {$orderid} AND M_CourierTestIsActive = 'Y' GROUP BY M_CourierTestID"; // echo $query; $rows = $this->db_onedev->query($query)->result_array(); if(!$rows) $rows = array(); return $rows; } public function addnewschedulegroup() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name = $prm['name']; $testid = $prm['testid']; $userid = $this->sys_user["M_UserID"]; $sql = "insert into m_courier( M_CourierName, M_CourierUserID, M_CourierCreated, M_CourierLastUpdated ) values( ?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $name, $userid ) ); //echo $query; $schedulegroup_id = $this->db_onedev->insert_id(); foreach($prm['ordertests'] as $k=>$v){ $query = "INSERT INTO m_couriertest ( M_CourierTestM_CourierID, M_CourierTestNat_TestID, M_CourierTestUserID, M_CourierTestCreated, M_CourierTestLastUpdated ) VALUE( ?,?,?,now(),now() )"; $insert_new_test = $this->db_onedev->query($query,array( $schedulegroup_id, $v['Nat_TestID'], $userid )); } if (!$query) { $this->sys_error_db("m_courier 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 editschedulegroup() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_schedulegroup = $prm['id']; $name_schedulegroup = $prm['name']; $userid = $this->sys_user["M_UserID"]; $query = "SELECT COUNT(*) as exist FROM m_courier WHERE M_CourierIsActive = 'Y' AND M_CourierName = '{$name_schedulegroup}' AND M_CourierID <> {$id_schedulegroup}"; $exist_name = $this->db_onedev->query($query)->row()->exist; if($exist_name == 0){ $sql = "update m_courier SET M_CourierName = ?, M_CourierUserID = ? where M_CourierID = ?"; $query = $this->db_onedev->query($sql, array( $name_schedulegroup, $userid, $id_schedulegroup ) ); // echo $query; if (!$query) { $this->sys_error_db("m_courier update"); exit; } $sql_param = $prm['id']; $sql = "select * from m_courier where M_CourierID= ?"; $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("nat_test select by schedulegroup"); exit; } foreach($prm['ordertests'] as $k=>$v){ if($v['xid'] == 0 || $v['xid'] == '0'){ $query = "INSERT INTO m_couriertest ( M_CourierTestM_CourierID, M_CourierTestUserID, M_CourierTestCreated, M_CourierTestLastUpdated ) VALUE( ?,?,now(),now() )"; $insert_new_test = $this->db_onedev->query($query,array( $id_schedulegroup, $userid )); } } if(isset($prm['deleted_ordertests'])){ foreach($prm['deleted_ordertests'] as $i=>$del){ $query = "UPDATE m_couriertest SET M_CourierTestIsActive = 'N', M_CourierTestUserID = '{$userid}', M_CourierTestLastUpdated = now() WHERE M_CourierTestID = ? "; $delete_exist_test = $this->db_onedev->query($query,array($del['M_CourierTestID'],)); } } $result = array ("total" => 1, "records" => array("xid" => $id_schedulegroup)); $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 addnewscheduleday() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $scheduleid = $prm['scheduleid']; $dayid = $prm['dayid']; $userid = $this->sys_user["M_UserID"]; $sql = "insert into m_schedule_day( M_ScheduleDayM_ScheduleID, M_ScheduleDayDayOfWeek, M_ScheduleDayUserID, M_ScheduleDayCreated, M_ScheduleDayLastUpdate ) values( ?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $scheduleid, $dayid, $userid ) ); //echo $query; if (!$query) { $this->sys_error_db("m_schedule_day insert"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function delete_day() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $dayid = $prm['dayid']; $scheduleid = $prm['scheduleid']; $sql_param = array( $dayid ,$scheduleid); $sql = "update m_schedule_day set M_ScheduleDayIsActive = 'N' where M_ScheduleDayDayOfWeek= ? and M_ScheduleDayM_ScheduleID=?"; $query = $this->db_onedev->query($sql,$sql_param); if (! $query) { $this->sys_error_db( $this->db_onedev->last_query() ); exit; } $sql = "select * from m_schedule_day where M_ScheduleDayDayOfWeek= ? and M_ScheduleDayM_ScheduleID=?"; $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("nat_test select by requirement"); exit; } $result = array ("status" => "OK"); $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_schedule( M_ScheduleDayOfWeek, M_ScheduleM_CourierID, M_ScheduleStartHourMinute, M_ScheduleEndHourMinute, M_ScheduleMonth, M_ScheduleWeek, M_ScheduleDay, M_ScheduleHour, M_ScheduleMinute, M_ScheduleAtTime, M_ScheduleFlagAtTime, M_ScheduleCreated, M_ScheduleLastUpdate ) values(?,?,?,?,?,?,?,?,?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $prm['dayofweek'], $prm['scheduleid'], $prm['starthm'], $prm['endhm'], $prm['xmonth'], $prm['xweek'], $prm['xday'], $prm['xhour'], $prm['xminute'], $prm['attime'], $prm['flagattime'] ) ); if (!$query) { $this->sys_error_db("m_schedule insert"); exit; } } else{ $sql = "update m_schedule SET M_ScheduleDayOfWeek = ?, M_ScheduleStartHourMinute = ?, M_ScheduleEndHourMinute = ?, M_ScheduleMonth = ?, M_ScheduleWeek = ?, M_ScheduleDay = ?, M_ScheduleHour = ?, M_ScheduleMinute = ?, M_ScheduleAtTime = ?, M_ScheduleFlagAtTime = ?, M_ScheduleLastUpdate = now() WHERE M_ScheduleID = ? "; $query = $this->db_onedev->query($sql, array( $prm['dayofweek'], $prm['starthm'], $prm['endhm'], $prm['xmonth'], $prm['xweek'], $prm['xday'], $prm['xhour'], $prm['xminute'], $prm['attime'], $prm['flagattime'], $prm['xid'] ) ); if (!$query) { $this->sys_error_db("m_schedule 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_schedule SET M_ScheduleIsActive = 'N', M_ScheduleLastUpdate = 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; } $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 addnewschedulenewtest() { 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_couriertest( M_CourierTestM_CourierID, M_CourierTestNat_TestID, M_CourierTestCreated, M_CourierTestLastUpdated ) values( ?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $scheduleid, $testid ) ); //echo $query; if (!$query) { $this->sys_error_db("m_couriertest insert"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function delete_test() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $scheduleid = $prm['scheduleid']; $sql_param = array( $id ,$scheduleid); $sql = "update m_couriertest set M_CourierTestIsActive = 'N' where M_CourierTestNat_TestID= ? and M_CourierTestM_CourierID=?"; $query = $this->db_onedev->query($sql,$sql_param); if (! $query) { $this->sys_error_db( $this->db_onedev->last_query() ); exit; } $sql = "select * from m_couriertest where M_CourierTestNat_TestID= ? and M_CourierTestM_CourierID=?"; $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("nat_test select by requirement"); exit; } $result = array ("status" => "OK"); $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_courier SET M_CourierIsActive = 'N', M_CourierLastUpdated = now() WHERE M_CourierID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_courier delete"); exit; } $sql = "update m_couriertest SET M_CourierTestIsActive = 'N', M_CourierLastUpdated = now() WHERE M_CourierTestM_CourierID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_couriertest delete"); exit; } $sql = "update m_schedule SET M_ScheduleIsActive = 'N', M_ScheduleLastUpdated = now() WHERE M_ScheduleM_CourierID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_schedule 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; $search = $prm['search']; $schedulegroup_id = $prm['schedulegroup_id']; $max_rst = 12; $tot_count =0; // QUERY TOTAL $sql = "SELECT count(*) as total FROM (SELECT Nat_TestID,Nat_TestCode,Nat_TestName,M_CourierTestID FROM nat_test LEFT JOIN m_couriertest ON Nat_TestID = M_CourierTestNat_TestID AND M_CourierTestM_CourierID = '{$schedulegroup_id}' AND M_CourierTestIsActive = 'Y' WHERE Nat_TestName LIKE '%$search%' AND Nat_TestIsActive = 'Y' AND Nat_TestIsResult = 'Y') a WHERE M_CourierTestID IS NULL ORDER BY Nat_TestName ASC"; $query = $this->db->query($sql); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("nat_test count",$this->db); exit; } $sql = "SELECT * FROM (SELECT Nat_TestID,Nat_TestCode,Nat_TestName,M_CourierTestID FROM nat_test LEFT JOIN m_couriertest ON Nat_TestID = M_CourierTestNat_TestID AND M_CourierTestM_CourierID = '{$schedulegroup_id}' AND M_CourierTestIsActive = 'Y' WHERE Nat_TestName LIKE '%$search%' AND Nat_TestIsActive = 'Y' AND Nat_TestIsResult = 'Y') a WHERE M_CourierTestID IS NULL ORDER BY Nat_TestName ASC "; $query = $this->db->query($sql); if ($query) { $rows = $query->result_array(); //echo $this->db->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); exit; } } public function searchtestx() { $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; } } }