1433 lines
48 KiB
PHP
1433 lines
48 KiB
PHP
<?php
|
|
|
|
class Schedulev3a extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "SCHEDULENEW API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->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_ScheduleGroupID = {$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_ScheduleGroupID = {$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_ScheduleGroupTestNat_TestID Nat_TestID, Nat_TestName
|
|
from m_schedulegrouptest
|
|
join nat_test on Nat_TestID = M_ScheduleGroupTestNat_TestID
|
|
where
|
|
M_ScheduleGroupTestM_ScheduleGroupID = ?
|
|
and
|
|
M_ScheduleGroupTestIsActive = '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);
|
|
}
|
|
}
|
|
function selected_notest() {
|
|
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 Nat_TestID, Nat_TestName
|
|
FROM (select Nat_TestID, Nat_TestName, M_ScheduleGroupTestID
|
|
from nat_test
|
|
left join m_schedulegrouptest on Nat_TestID = M_ScheduleGroupTestNat_TestID AND M_ScheduleGroupTestIsActive = 'Y'
|
|
where
|
|
Nat_TestIsActive = 'Y'
|
|
AND Nat_TestIsResult = 'Y'
|
|
) a
|
|
WHERE M_ScheduleGroupTestID IS NULL";
|
|
$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'];
|
|
$test = $prm['test'];
|
|
$all = $prm['all'];
|
|
$limit = '';
|
|
if($all == 'N'){
|
|
$limit = ' LIMIT 10';
|
|
}
|
|
$sql = "select COUNT(*) as total FROM
|
|
(SELECT M_ScheduleGroupID from m_schedulegroup
|
|
LEFT JOIN m_schedulegrouptest ON M_ScheduleGroupTestM_ScheduleGroupID = M_ScheduleGroupID AND M_ScheduleGroupTestIsActive = 'Y'
|
|
LEFT JOIN nat_test ON Nat_TestID = M_ScheduleGroupTestNat_TestID
|
|
where
|
|
(M_ScheduleGroupName LIKE CONCAT('%',?,'%') AND Nat_TestName LIKE CONCAT('%',?,'%')) AND
|
|
M_ScheduleGroupIsActive = 'Y'
|
|
GROUP BY M_ScheduleGroupID
|
|
) a";
|
|
$sql_param = array($search,$test);
|
|
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
$sql = "select M_ScheduleGroupID as id, M_ScheduleGroupName as name,
|
|
M_ScheduleGroupName as detail,
|
|
'xxx' as scheduledays, 'xxx' as scheduletests, 'xxx' as schedulepromise,
|
|
'xxx' as tests
|
|
from m_schedulegroup
|
|
LEFT JOIN m_schedulegrouptest ON M_ScheduleGroupTestM_ScheduleGroupID = M_ScheduleGroupID AND M_ScheduleGroupTestIsActive = 'Y'
|
|
LEFT JOIN nat_test ON Nat_TestID = M_ScheduleGroupTestNat_TestID
|
|
where
|
|
(M_ScheduleGroupName LIKE CONCAT('%',?,'%') AND Nat_TestName LIKE CONCAT('%',?,'%')) AND
|
|
M_ScheduleGroupIsActive = 'Y'
|
|
GROUP BY M_ScheduleGroupID
|
|
$limit";
|
|
$sql_param = array($search,$test);
|
|
$query = $this->db_onedev->query($sql,$sql_param);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){$rows[$k]['tests'] = $this->add_test($v['id']);
|
|
}
|
|
}
|
|
|
|
} else {
|
|
$this->sys_error_db("m_schedulegroup 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_schedulegrouptest.*, 'Y' as editable, M_ScheduleGroupTestNat_TestID as xid, Nat_TestID, Nat_TestName
|
|
|
|
FROM m_schedulegrouptest
|
|
JOIN m_schedulegroup ON M_ScheduleGroupTestM_ScheduleGroupID = M_ScheduleGroupID
|
|
JOIN nat_test ON M_ScheduleGroupTestNat_TestID = Nat_TestID
|
|
WHERE
|
|
M_ScheduleGroupTestM_ScheduleGroupID = {$orderid} AND M_ScheduleGroupTestIsActive = 'Y'
|
|
GROUP BY M_ScheduleGroupTestID";
|
|
// 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_schedulegroup(
|
|
M_ScheduleGroupName,
|
|
M_ScheduleGroupUserID,
|
|
M_ScheduleGroupCreated,
|
|
M_ScheduleGroupLastUpdated
|
|
)
|
|
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){
|
|
$nattestid = $v['Nat_TestID'];
|
|
$sql = $this->db_onedev->query("SELECT Nat_TestNat_TestTypeID as tipeid FROM nat_test
|
|
WHERE Nat_TestID = '{$nattestid}'")->row();
|
|
$tipeid = $sql->tipeid;
|
|
if($tipeid == 3 || $tipeid == 4){
|
|
$sql = $this->db_onedev->query("SELECT T_TestSasCode as tsascode FROM t_test
|
|
WHERE T_TestNat_TestID = '{$nattestid}'")->row();
|
|
$tsascode = $sql->tsascode;
|
|
|
|
$sql = $this->db_onedev->query("SELECT GROUP_CONCAT(DISTINCT T_TestNat_TestID SEPARATOR ',') as tchild FROM t_test
|
|
WHERE T_TestSasCode like concat('{$tsascode}','%') AND T_TestIsActive = 'Y'
|
|
and T_TestIsResult = 'Y'")->row();
|
|
$tchild = $sql->tchild;
|
|
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
|
|
$insertparent = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
VALUES($schedulegroup_id,$nattestid,$userid,now(),now())";
|
|
$insert_tparent= $this->db_onedev->query($insertparent);
|
|
|
|
|
|
|
|
$existchild = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID IN($tchild)";
|
|
$delete_exist_tchild= $this->db_onedev->query($existchild);
|
|
$insertchild = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
SELECT $schedulegroup_id as M_ScheduleGroupTestM_ScheduleGroupID,
|
|
Nat_TestID as M_ScheduleGroupTestNat_TestID,
|
|
$userid as M_ScheduleGroupTestUserID,
|
|
now() as M_ScheduleGroupTestCreated,
|
|
now() as M_ScheduleGroupTestLastUpdated
|
|
FROM nat_test
|
|
WHERE Nat_TestID IN($tchild) AND Nat_TestIsActive = 'Y'";
|
|
$insert_tchild= $this->db_onedev->query($insertchild);
|
|
|
|
}else{
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
|
|
$query = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,now(),now()
|
|
)";
|
|
$insert_new_test = $this->db_onedev->query($query,array(
|
|
$schedulegroup_id,
|
|
$v['Nat_TestID'],
|
|
$userid
|
|
));
|
|
}
|
|
|
|
}
|
|
|
|
$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_schedulegroup WHERE M_ScheduleGroupIsActive = 'Y' AND M_ScheduleGroupName = '{$name_schedulegroup}' AND M_ScheduleGroupID <> {$id_schedulegroup}";
|
|
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
|
|
|
if($exist_name == 0){
|
|
$sql = "update m_schedulegroup SET
|
|
M_ScheduleGroupName = ?,
|
|
M_ScheduleGroupUserID = ?
|
|
where
|
|
M_ScheduleGroupID = ?";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$name_schedulegroup,
|
|
$userid,
|
|
$id_schedulegroup
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_schedulegroup update");
|
|
exit;
|
|
}
|
|
$sql_param = $prm['id'];
|
|
$sql = "select * from m_schedulegroup
|
|
where M_ScheduleGroupID= ?";
|
|
$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'){
|
|
$nattestid = $v['Nat_TestID'];
|
|
$sql = $this->db_onedev->query("SELECT Nat_TestNat_TestTypeID as tipeid FROM nat_test
|
|
WHERE Nat_TestID = '{$nattestid}'")->row();
|
|
$tipeid = $sql->tipeid;
|
|
if($tipeid == 4){
|
|
$sql = $this->db_onedev->query("SELECT T_TestSasCode as tsascode FROM t_test
|
|
WHERE T_TestNat_TestID = '{$nattestid}'")->row();
|
|
$tsascode = $sql->tsascode;
|
|
|
|
$sql = $this->db_onedev->query("SELECT GROUP_CONCAT(DISTINCT T_TestNat_TestID SEPARATOR ',') as tchild FROM t_test
|
|
WHERE T_TestSasCode like concat('{$tsascode}','%') AND T_TestIsActive = 'Y'
|
|
and T_TestIsResult = 'Y'")->row();
|
|
$tchild = $sql->tchild;
|
|
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
|
|
$insertparent = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
VALUES($id_schedulegroup,$nattestid,$userid,now(),now())";
|
|
$insert_tparent= $this->db_onedev->query($insertparent);
|
|
|
|
|
|
|
|
$existchild = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID IN($tchild)";
|
|
$delete_exist_tchild= $this->db_onedev->query($existchild);
|
|
$insertchild = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
SELECT $id_schedulegroup as M_ScheduleGroupTestM_ScheduleGroupID,
|
|
Nat_TestID as M_ScheduleGroupTestNat_TestID,
|
|
$userid as M_ScheduleGroupTestUserID,
|
|
now() as M_ScheduleGroupTestCreated,
|
|
now() as M_ScheduleGroupTestLastUpdated
|
|
FROM nat_test
|
|
WHERE Nat_TestID IN($tchild) AND Nat_TestIsActive = 'Y'";
|
|
$insert_tchild= $this->db_onedev->query($insertchild);
|
|
|
|
}else{
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
|
|
$query = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,now(),now()
|
|
)";
|
|
$insert_new_test = $this->db_onedev->query($query,array(
|
|
$id_schedulegroup,
|
|
$v['Nat_TestID'],
|
|
$userid
|
|
));
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if(isset($prm['deleted_ordertests'])){
|
|
foreach($prm['deleted_ordertests'] as $i=>$del){
|
|
if($tipeid == 4){
|
|
$sql = $this->db_onedev->query("SELECT T_TestSasCode as tsascode FROM t_test
|
|
WHERE T_TestNat_TestID = '{$nattestid}'")->row();
|
|
$tsascode = $sql->tsascode;
|
|
|
|
$sql = $this->db_onedev->query("SELECT GROUP_CONCAT(DISTINCT T_TestNat_TestID SEPARATOR ',') as tchild FROM t_test
|
|
WHERE T_TestSasCode like concat('{$tsascode}','%') AND T_TestIsActive = 'Y'
|
|
and T_TestIsResult = 'Y'")->row();
|
|
$tchild = $sql->tchild;
|
|
|
|
|
|
$sqlparent = "update m_schedulegrouptest
|
|
set M_ScheduleGroupTestIsActive = 'N'
|
|
where M_ScheduleGroupTestNat_TestID= {$del['M_ScheduleGroupTestNat_TestID']}
|
|
and M_ScheduleGroupTestM_ScheduleGroupID = {$del['M_ScheduleGroupTestM_ScheduleGroupID']}";
|
|
$queryparent = $this->db_onedev->query($sqlparent);
|
|
|
|
$sqlchild = "update m_schedulegrouptest
|
|
set M_ScheduleGroupTestIsActive = 'N'
|
|
where M_ScheduleGroupTestNat_TestID IN($tchild)
|
|
and M_ScheduleGroupTestM_ScheduleGroupID = {$del['M_ScheduleGroupTestM_ScheduleGroupID']}";
|
|
|
|
$querychild = $this->db_onedev->query($sqlchild);
|
|
if (! $queryparent) {
|
|
$this->sys_error_db( $this->db_onedev->last_query() );
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "update m_schedulegrouptest
|
|
set M_ScheduleGroupTestIsActive = 'N'
|
|
where M_ScheduleGroupTestNat_TestID= ?
|
|
and M_ScheduleGroupTestM_ScheduleGroupID=?";
|
|
$query = $this->db_onedev->query($sql,$sql_param);
|
|
if (! $query) {
|
|
$this->sys_error_db( $this->db_onedev->last_query() );
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$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;
|
|
$xmonth = $prm['xmonth'];
|
|
$xweek = $prm['xweek'];
|
|
$xday = $prm['xday'];
|
|
$xhour = $prm['xhour'];
|
|
$xminute = $prm['xminute'];
|
|
if($prm['flagattime'] == 'Y' && ($prm['attime'] !== 'Invalid date')){
|
|
if($prm['xid'] == "0" || $prm['xid'] == 0){
|
|
$sql = "insert into m_schedule(
|
|
M_ScheduleDayOfWeek,
|
|
M_ScheduleM_ScheduleGroupID,
|
|
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'],
|
|
str_replace('.',':',$prm['starthm']),
|
|
str_replace('.',':',$prm['endhm']),
|
|
$xmonth,
|
|
$xweek,
|
|
$xday,
|
|
$xhour,
|
|
$xminute,
|
|
str_replace('.',':',$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'],
|
|
str_replace('.',':',$prm['starthm']),
|
|
str_replace('.',':',$prm['endhm']),
|
|
$xmonth,
|
|
$xweek,
|
|
$xday,
|
|
$xhour,
|
|
$xminute,
|
|
str_replace('.',':',$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);
|
|
}
|
|
elseif($prm['flagattime'] == 'N'){
|
|
if($prm['xid'] == "0" || $prm['xid'] == 0){
|
|
$sql = "insert into m_schedule(
|
|
M_ScheduleDayOfWeek,
|
|
M_ScheduleM_ScheduleGroupID,
|
|
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'],
|
|
str_replace('.',':',$prm['starthm']),
|
|
str_replace('.',':',$prm['endhm']),
|
|
$xmonth,
|
|
$xweek,
|
|
$xday,
|
|
$xhour,
|
|
$xminute,
|
|
'',
|
|
$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'],
|
|
str_replace('.',':',$prm['starthm']),
|
|
str_replace('.',':',$prm['endhm']),
|
|
$xmonth,
|
|
$xweek,
|
|
$xday,
|
|
$xhour,
|
|
$xminute,
|
|
'',
|
|
$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);
|
|
}else{
|
|
$errors = array();
|
|
array_push($errors,array('field'=>'attime','msg'=>'Pada jam (hh:mm) di isi dulu'));
|
|
$result = array ("total" => -1,"errors" => $errors, "records" => 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;
|
|
$schedulegroup_id = $prm['scheduleid'];
|
|
$nattestid = $prm['testid'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = $this->db_onedev->query("SELECT Nat_TestNat_TestTypeID as tipeid FROM nat_test
|
|
WHERE Nat_TestID = '{$nattestid}'")->row();
|
|
$tipeid = $sql->tipeid;
|
|
if($tipeid == 4){
|
|
$sql = $this->db_onedev->query("SELECT T_TestSasCode as tsascode FROM t_test
|
|
WHERE T_TestNat_TestID = '{$nattestid}'")->row();
|
|
$tsascode = $sql->tsascode;
|
|
|
|
$sql = $this->db_onedev->query("SELECT GROUP_CONCAT(DISTINCT T_TestNat_TestID SEPARATOR ',') as tchild FROM t_test
|
|
WHERE T_TestSasCode like concat('{$tsascode}','%') AND T_TestIsActive = 'Y'
|
|
and T_TestIsResult = 'Y'")->row();
|
|
$tchild = $sql->tchild;
|
|
//echo $tchild;
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
|
|
$insertparent = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
VALUES($schedulegroup_id,$nattestid,$userid,now(),now())";
|
|
$insert_tparent= $this->db_onedev->query($insertparent);
|
|
|
|
|
|
|
|
$existchild = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID IN($tchild)";
|
|
$delete_exist_tchild= $this->db_onedev->query($existchild);
|
|
$insertchild = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
SELECT $schedulegroup_id as M_ScheduleGroupTestM_ScheduleGroupID,
|
|
Nat_TestID as M_ScheduleGroupTestNat_TestID,
|
|
$userid as M_ScheduleGroupTestUserID,
|
|
now() as M_ScheduleGroupTestCreated,
|
|
now() as M_ScheduleGroupTestLastUpdated
|
|
FROM nat_test
|
|
WHERE Nat_TestID IN($tchild) AND Nat_TestIsActive = 'Y'";
|
|
$insert_tchild= $this->db_onedev->query($insertchild);
|
|
|
|
}else{
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
|
|
$insertparent = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestUserID,
|
|
M_ScheduleGroupTestCreated,
|
|
M_ScheduleGroupTestLastUpdated
|
|
)
|
|
VALUES($schedulegroup_id,$nattestid,$userid,now(),now())";
|
|
$insert_tparent= $this->db_onedev->query($insertparent);
|
|
}
|
|
|
|
|
|
$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'];
|
|
$nattestid = $prm['id'];
|
|
$scheduleid = $prm['scheduleid'];
|
|
$sql_param = array( $id ,$scheduleid);
|
|
|
|
$sql = $this->db_onedev->query("SELECT Nat_TestNat_TestTypeID as tipeid FROM nat_test
|
|
WHERE Nat_TestID = '{$nattestid}'")->row();
|
|
$tipeid = $sql->tipeid;
|
|
if($tipeid == 4){
|
|
$sql = $this->db_onedev->query("SELECT T_TestSasCode as tsascode FROM t_test
|
|
WHERE T_TestNat_TestID = '{$nattestid}'")->row();
|
|
$tsascode = $sql->tsascode;
|
|
|
|
$sql = $this->db_onedev->query("SELECT GROUP_CONCAT(DISTINCT T_TestNat_TestID SEPARATOR ',') as tchild FROM t_test
|
|
WHERE T_TestSasCode like concat('{$tsascode}','%') AND T_TestIsActive = 'Y'
|
|
and T_TestIsResult = 'Y'")->row();
|
|
$tchild = $sql->tchild;
|
|
|
|
|
|
$sqlparent = "update m_schedulegrouptest
|
|
set M_ScheduleGroupTestIsActive = 'N'
|
|
where M_ScheduleGroupTestNat_TestID= ?
|
|
and M_ScheduleGroupTestM_ScheduleGroupID=?";
|
|
$queryparent = $this->db_onedev->query($sqlparent,$sql_param);
|
|
|
|
$sqlchild = "update m_schedulegrouptest
|
|
set M_ScheduleGroupTestIsActive = 'N'
|
|
where M_ScheduleGroupTestNat_TestID IN($tchild)
|
|
and M_ScheduleGroupTestM_ScheduleGroupID = $scheduleid";
|
|
|
|
$querychild = $this->db_onedev->query($sqlchild);
|
|
if (! $queryparent) {
|
|
$this->sys_error_db( $this->db_onedev->last_query() );
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "update m_schedulegrouptest
|
|
set M_ScheduleGroupTestIsActive = 'N'
|
|
where M_ScheduleGroupTestNat_TestID= ?
|
|
and M_ScheduleGroupTestM_ScheduleGroupID=?";
|
|
$query = $this->db_onedev->query($sql,$sql_param);
|
|
if (! $query) {
|
|
$this->sys_error_db( $this->db_onedev->last_query() );
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql = "select * from m_schedulegrouptest
|
|
where M_ScheduleGroupTestNat_TestID= ?
|
|
and M_ScheduleGroupTestM_ScheduleGroupID=?";
|
|
$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_schedulegroup SET
|
|
M_ScheduleGroupIsActive = 'N',
|
|
M_ScheduleGroupLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_schedulegroup delete");
|
|
exit;
|
|
}
|
|
|
|
$sql = "update m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestM_ScheduleGroupID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_schedulegrouptest delete");
|
|
exit;
|
|
}
|
|
|
|
$sql = "update m_schedule SET
|
|
M_ScheduleIsActive = 'N',
|
|
M_ScheduleLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleM_ScheduleGroupID = ?
|
|
|
|
";
|
|
|
|
$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_ScheduleGroupTestID, 0 as xid
|
|
FROM nat_test
|
|
LEFT JOIN m_schedulegrouptest ON Nat_TestID = M_ScheduleGroupTestNat_TestID
|
|
AND M_ScheduleGroupTestM_ScheduleGroupID = '{$schedulegroup_id}'
|
|
AND M_ScheduleGroupTestIsActive = 'Y'
|
|
WHERE Nat_TestName LIKE '%$search%'
|
|
AND Nat_TestIsActive = 'Y'
|
|
-- AND Nat_TestIsResult = 'Y'
|
|
) a
|
|
WHERE M_ScheduleGroupTestID 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_ScheduleGroupTestID, 0 as xid
|
|
FROM nat_test
|
|
LEFT JOIN m_schedulegrouptest ON Nat_TestID = M_ScheduleGroupTestNat_TestID
|
|
AND M_ScheduleGroupTestM_ScheduleGroupID = '{$schedulegroup_id}'
|
|
AND M_ScheduleGroupTestIsActive = 'Y'
|
|
WHERE Nat_TestName LIKE '%$search%'
|
|
AND Nat_TestIsActive = 'Y'
|
|
-- AND Nat_TestIsResult = 'Y'
|
|
) a
|
|
WHERE M_ScheduleGroupTestID 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;
|
|
}
|
|
}
|
|
}
|