1875 lines
67 KiB
PHP
1875 lines
67 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 lookup_branches(){
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$sql = "select M_BranchID as id, M_BranchName as name from m_branch where M_BranchIsActive = 'Y' ORDER BY M_BranchName ASC";
|
|
$query = $this->db_onedev->query($sql);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
} else {
|
|
$this->sys_error_db("m_branch select");
|
|
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'];
|
|
$search = isset($prm['search']) ? $prm['search'] : '';
|
|
$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 Nat_TestName LIKE CONCAT('%','$search','%')
|
|
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'];
|
|
$search = $prm['search'];
|
|
$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_total = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db( $this->db_onedev->last_query() );
|
|
exit;
|
|
}
|
|
|
|
$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' AND
|
|
M_ScheduleGroupTestM_ScheduleGroupID = {$id}
|
|
where
|
|
Nat_TestIsActive = 'Y'
|
|
AND Nat_TestName LIKE CONCAT('%','$search','%') AND M_ScheduleGroupTestID IS NULL
|
|
) a" ;
|
|
$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_total), "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 = isset($prm['search']) ? $prm['search'] : '';
|
|
$test = isset($prm['test']) ? $prm['test'] : '';
|
|
$all = $prm['all'];
|
|
|
|
$filter = "";
|
|
if($search != ''){
|
|
$filter = " AND M_ScheduleGroupName LIKE CONCAT('%','{$search}','%')";
|
|
}
|
|
|
|
if($test != ''){
|
|
$filter = " AND Nat_TestCode = '{$test}'";
|
|
}
|
|
|
|
$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_ScheduleGroupIsActive = 'Y'
|
|
$filter
|
|
GROUP BY M_ScheduleGroupID
|
|
) a";
|
|
|
|
$total = $this->db_onedev->query($sql)->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,
|
|
GROUP_CONCAT(DISTINCT CONCAT(M_BranchID,'|',M_BranchName) SEPARATOR ',') as branches
|
|
from m_schedulegroup
|
|
LEFT JOIN m_schedulegroup_branches ON M_ScheduleGroupBranchesM_ScheduleGroupID = M_ScheduleGroupID AND M_ScheduleGroupBranchesIsActive = 'Y'
|
|
LEFT JOIN m_branch ON M_ScheduleGroupBranchesM_BranchID = M_BranchID AND M_BranchIsActive = 'Y'
|
|
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_ScheduleGroupIsActive = 'Y'
|
|
$filter
|
|
GROUP BY M_ScheduleGroupID
|
|
$limit";
|
|
$sql_param = array($search,$test);
|
|
$query = $this->db_onedev->query($sql);
|
|
//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']);
|
|
$branches = explode(',', $v['branches']);
|
|
$rows[$k]['branches'] = [];
|
|
if(count($branches) > 0){
|
|
foreach($branches as $branch){
|
|
$branch = explode('|', $branch);
|
|
if($branch[0] != '' || $branch[0] != null){
|
|
$rows[$k]['branches'][] = array(
|
|
'id' => $branch[0],
|
|
'name' => $branch[1]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} 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;
|
|
}
|
|
|
|
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'];
|
|
|
|
$sql = "SELECT COUNT(*) as total FROM m_schedulegroup WHERE M_ScheduleGroupName = '{$name}' AND M_ScheduleGroupIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
$total = $query->row()->total;
|
|
if($total > 0){
|
|
$this->sys_error("Nama Schedule sudah ada");
|
|
exit;
|
|
}
|
|
|
|
if(count($prm['selected_branch']) == 0){
|
|
$this->sys_error("Silahkan pilih cabang");
|
|
exit;
|
|
}
|
|
|
|
if(count($prm['ordertests']) == 0){
|
|
$this->sys_error("Silahkan pilih pemeriksaan");
|
|
exit;
|
|
}
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$this->db_onedev->trans_start();
|
|
|
|
$sql = "insert into m_schedulegroup(
|
|
M_ScheduleGroupName,
|
|
M_ScheduleGroupCreatedUserID,
|
|
M_ScheduleGroupCreated
|
|
)
|
|
values( ?,?,now())";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$name,
|
|
$userid
|
|
)
|
|
);
|
|
if(!$query){
|
|
$this->sys_error_db("m_schedulegroup insert");
|
|
exit;
|
|
}
|
|
//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_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
if(!$delete_exist_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_test delete exist parent");
|
|
exit;
|
|
}
|
|
|
|
$insertparent = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
VALUES($schedulegroup_id,$nattestid,$userid,now())";
|
|
$insert_tparent= $this->db_onedev->query($insertparent);
|
|
if(!$insert_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_test update parent");
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
$existchild = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID IN($tchild)";
|
|
$delete_exist_tchild= $this->db_onedev->query($existchild);
|
|
if(!$delete_exist_tchild){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_test delete exist child");
|
|
exit;
|
|
}
|
|
$insertchild = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
SELECT $schedulegroup_id as M_ScheduleGroupTestM_ScheduleGroupID,
|
|
Nat_TestID as M_ScheduleGroupTestNat_TestID,
|
|
$userid as M_ScheduleGroupTestUserID,
|
|
now() as M_ScheduleGroupTestCreated
|
|
FROM nat_test
|
|
WHERE Nat_TestID IN($tchild) AND Nat_TestIsActive = 'Y'";
|
|
$insert_tchild= $this->db_onedev->query($insertchild);
|
|
if(!$insert_tchild){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_test insert child");
|
|
exit;
|
|
}
|
|
|
|
}else{
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
if(!$delete_exist_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_test delete exist parent");
|
|
exit;
|
|
}
|
|
|
|
$query = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,now()
|
|
)";
|
|
$insert_new_test = $this->db_onedev->query($query,array(
|
|
$schedulegroup_id,
|
|
$v['Nat_TestID'],
|
|
$userid
|
|
));
|
|
if(!$insert_new_test){
|
|
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_test insert");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} */
|
|
|
|
if(isset($prm['selected_branch']) && count($prm['selected_branch']) > 0){
|
|
foreach($prm['selected_branch'] as $k=>$v){
|
|
$sql = "INSERT INTO m_schedulegroup_branches (
|
|
M_ScheduleGroupBranchesM_ScheduleGroupID,
|
|
M_ScheduleGroupBranchesM_BranchID,
|
|
M_ScheduleGroupBranchesCreatedUserID,
|
|
M_ScheduleGroupBranchesCreated
|
|
) VALUES ({$schedulegroup_id},{$v['id']},{$userid},now())";
|
|
$query = $this->db_onedev->query($sql);
|
|
if(!$query){
|
|
echo $this->db_onedev->last_query();
|
|
exit;
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_branches insert");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
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'];
|
|
$branches = $prm['branches'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$this->db_onedev->trans_start();
|
|
|
|
$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_ScheduleGroupLastUpdatedUserID = ?,
|
|
M_ScheduleGroupLastUpdated = NOW()
|
|
WHERE
|
|
M_ScheduleGroupID = ?";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$name_schedulegroup,
|
|
$userid,
|
|
$id_schedulegroup
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup update");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql_param = $prm['id'];
|
|
$sql = "SELECT * FROM m_schedulegroup WHERE M_ScheduleGroupID = ? AND M_ScheduleGroupIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$sql_param);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("nat_test select by schedulegroup");
|
|
exit;
|
|
}
|
|
|
|
if(count($rows) == 0){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error("Schedule group not found");
|
|
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_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = NOW()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = {$nattestid}";
|
|
$delete_exist_tparent = $this->db_onedev->query($existparent);
|
|
if(!$delete_exist_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest delete exist parent");
|
|
exit;
|
|
}
|
|
|
|
$insertparent = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
VALUES({$id_schedulegroup},{$nattestid},{$userid},NOW())";
|
|
$insert_tparent= $this->db_onedev->query($insertparent);
|
|
if(!$insert_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest insert parent");
|
|
exit;
|
|
}
|
|
|
|
$existchild = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID IN ($tchild)";
|
|
$delete_exist_tchild= $this->db_onedev->query($existchild);
|
|
if(!$delete_exist_tchild){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest delete exist child");
|
|
exit;
|
|
}
|
|
|
|
$insertchild = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
SELECT $id_schedulegroup as M_ScheduleGroupTestM_ScheduleGroupID,
|
|
Nat_TestID as M_ScheduleGroupTestNat_TestID,
|
|
{$userid} as M_ScheduleGroupTestCreatedUserID,
|
|
NOW() as M_ScheduleGroupTestCreated
|
|
FROM nat_test
|
|
WHERE Nat_TestID IN({$tchild}) AND Nat_TestIsActive = 'Y'";
|
|
$insert_tchild= $this->db_onedev->query($insertchild);
|
|
if(!$insert_tchild){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest insert child");
|
|
exit;
|
|
}
|
|
|
|
}else{
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = NOW()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = {$nattestid}";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
if(!$delete_exist_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest delete exist parent");
|
|
exit;
|
|
}
|
|
|
|
$query = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,NOW()
|
|
)";
|
|
$insert_new_test = $this->db_onedev->query($query,array(
|
|
$id_schedulegroup,
|
|
$v['Nat_TestID'],
|
|
$userid
|
|
));
|
|
if(!$insert_new_test){
|
|
$this->db_onedev->trans_rollback();
|
|
// echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("m_schedulegrouptest insert");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = NOW()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = {$del['M_ScheduleGroupTestNat_TestID']} AND
|
|
M_ScheduleGroupTestM_ScheduleGroupID = {$del['M_ScheduleGroupTestM_ScheduleGroupID']}";
|
|
$queryparent = $this->db_onedev->query($sqlparent);
|
|
if(!$queryparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest delete exist parent");
|
|
exit;
|
|
}
|
|
|
|
$sqlchild = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = NOW()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID IN ({$tchild}) AND
|
|
M_ScheduleGroupTestM_ScheduleGroupID = {$del['M_ScheduleGroupTestM_ScheduleGroupID']}";
|
|
|
|
$querychild = $this->db_onedev->query($sqlchild);
|
|
if (! $querychild) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest delete exist child");
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = NOW()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = ? AND
|
|
M_ScheduleGroupTestM_ScheduleGroupID = ?";
|
|
$query = $this->db_onedev->query($sql,array(
|
|
$del['M_ScheduleGroupTestNat_TestID'],
|
|
$del['M_ScheduleGroupTestM_ScheduleGroupID']
|
|
));
|
|
if (! $query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest delete exist test");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$sql = "UPDATE m_schedulegroup_branches SET
|
|
M_ScheduleGroupBranchesIsActive = 'X'
|
|
WHERE
|
|
M_ScheduleGroupBranchesM_ScheduleGroupID = {$id_schedulegroup} AND
|
|
M_ScheduleGroupBranchesIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if(!$query){
|
|
echo $this->db_onedev->last_query();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_branches delete exist branch X");
|
|
exit;
|
|
}
|
|
|
|
if(count($branches) > 0){
|
|
foreach($branches as $b){
|
|
$sql = "SELECT COUNT(*) as exist FROM m_schedulegroup_branches
|
|
WHERE M_ScheduleGroupBranchesM_ScheduleGroupID = {$id_schedulegroup} AND
|
|
M_ScheduleGroupBranchesM_BranchID = {$b['id']} AND M_ScheduleGroupBranchesIsActive = 'X'";
|
|
$query = $this->db_onedev->query($sql);
|
|
$exist = $query->row()->exist;
|
|
if($exist == 0){
|
|
$sql = "INSERT INTO m_schedulegroup_branches (
|
|
M_ScheduleGroupBranchesM_ScheduleGroupID,
|
|
M_ScheduleGroupBranchesM_BranchID,
|
|
M_ScheduleGroupBranchesCreatedUserID,
|
|
M_ScheduleGroupBranchesCreated)
|
|
VALUES ({$id_schedulegroup}, {$b['id']}, {$userid}, NOW())";
|
|
$query = $this->db_onedev->query($sql);
|
|
if(!$query){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_branches insert branch");
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "UPDATE m_schedulegroup_branches SET
|
|
M_ScheduleGroupBranchesIsActive = 'Y'
|
|
WHERE M_ScheduleGroupBranchesM_ScheduleGroupID = {$id_schedulegroup} AND
|
|
M_ScheduleGroupBranchesM_BranchID = {$b['id']} AND M_ScheduleGroupBranchesIsActive = 'X'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if(!$query){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_branches update branch");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$sql = "UPDATE m_schedulegroup_branches SET
|
|
M_ScheduleGroupBranchesIsActive = 'N',
|
|
M_ScheduleGroupBranchesDeletedUserID = '{$userid}',
|
|
M_ScheduleGroupBranchesDeleted = NOW()
|
|
WHERE
|
|
M_ScheduleGroupBranchesM_ScheduleGroupID = {$id_schedulegroup} AND
|
|
M_ScheduleGroupBranchesIsActive = 'X'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if(!$query){
|
|
//echo $this->db_onedev->last_query();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_branches update branch N");
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => $id_schedulegroup));
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$this->db_onedev->trans_rollback();
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
|
|
function addnewscheduleday()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$errors = array();
|
|
$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);
|
|
}
|
|
|
|
}
|
|
|
|
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'];
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$this->db_onedev->trans_start();
|
|
|
|
if($prm['flagattime'] == 'Y' && ($prm['attime'] !== 'Invalid date')){
|
|
// echo "flagattime = Y and attime is not Invalid date";
|
|
if($prm['xid'] == "0" || $prm['xid'] == 0){
|
|
//echo "xid = 0 or 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_ScheduleCreatedUserID
|
|
)
|
|
VALUES(?,?,?,?,?,?,?,?,?,?,?,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'],
|
|
$userid
|
|
)
|
|
);
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedule insert");
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
//echo "else : xid is not 0 or xid is not 0";
|
|
$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(),
|
|
M_ScheduleLastUpdateUserID = ?
|
|
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'],
|
|
$userid,
|
|
$prm['xid']
|
|
)
|
|
);
|
|
//echo $this->db_onedev->last_query();
|
|
//exit;
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedule update");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
elseif($prm['flagattime'] == 'N'){
|
|
//echo "flagattime = N";
|
|
if($prm['xid'] == "0" || $prm['xid'] == 0){
|
|
//echo "xid = 0 or 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_ScheduleCreatedUserID
|
|
)
|
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,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'],
|
|
$userid
|
|
)
|
|
);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedule insert");
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
//echo "else B : xid is not 0 or xid is not 0";
|
|
$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(),
|
|
M_ScheduleLastUpdateUserID = ?
|
|
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'],
|
|
$userid,
|
|
$prm['xid']
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedule update");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
//echo "else C : flagattime is not Y or N";
|
|
|
|
array_push($errors,array('field'=>'attime','msg'=>'Pada jam (hh:mm) di isi dulu'));
|
|
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0), );
|
|
if(count($errors) > 0){
|
|
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
|
}
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
function deleteschedulepromise()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$this->db_onedev->trans_start();
|
|
|
|
$sql = "UPDATE m_schedule SET
|
|
M_ScheduleIsActive = 'N',
|
|
M_ScheduleLastUpdate = NOW(),
|
|
M_ScheduleLastUpdateUserID = ?
|
|
WHERE
|
|
M_ScheduleID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$userid,
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedule delete");
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
|
|
|
|
|
|
$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->isogin) {
|
|
$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);
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
$this->db_onedev->trans_start();
|
|
|
|
$tchild = '';
|
|
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;
|
|
}
|
|
|
|
$testsToCheck = array((int) $nattestid);
|
|
if($tipeid == 4 && !empty($tchild)){
|
|
$childIds = array_filter(array_map('intval', explode(',', $tchild)));
|
|
$testsToCheck = array_merge($testsToCheck, $childIds);
|
|
}
|
|
|
|
if(!$this->isNatTestAvailableForBranches($schedulegroup_id, $testsToCheck)){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error("Nat test sudah terdaftar pada cabang terkait");
|
|
exit;
|
|
}
|
|
|
|
if($tipeid == 4){
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid
|
|
AND M_ScheduleGroupTestM_ScheduleGroupID = {$schedulegroup_id}";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
if(!$delete_exist_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest update parent");
|
|
exit;
|
|
}
|
|
|
|
$insertparent = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
VALUES($schedulegroup_id,$nattestid,$userid,now())";
|
|
$insert_tparent= $this->db_onedev->query($insertparent);
|
|
if(!$insert_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest insert parent");
|
|
exit;
|
|
}
|
|
|
|
$existchild = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID IN($tchild)
|
|
AND M_ScheduleGroupTestM_ScheduleGroupID = {$schedulegroup_id}";
|
|
$delete_exist_tchild= $this->db_onedev->query($existchild);
|
|
if(empty($tchild)){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error("Tidak ditemukan turunan test untuk Nat Test {$nattestid}");
|
|
exit;
|
|
}
|
|
|
|
$insertchild = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
SELECT $schedulegroup_id as M_ScheduleGroupTestM_ScheduleGroupID,
|
|
Nat_TestID as M_ScheduleGroupTestNat_TestID,
|
|
$userid as M_ScheduleGroupTestUserID,
|
|
now() as M_ScheduleGroupTestCreated
|
|
FROM nat_test
|
|
WHERE Nat_TestID IN ($tchild) AND Nat_TestIsActive = 'Y'";
|
|
$insert_tchild= $this->db_onedev->query($insertchild);
|
|
if(!$insert_tchild){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest insert child");
|
|
exit;
|
|
}
|
|
|
|
}else{
|
|
$existparent = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdatedUserID = '{$userid}',
|
|
M_ScheduleGroupTestLastUpdated = now()
|
|
WHERE
|
|
M_ScheduleGroupTestNat_TestID = $nattestid
|
|
AND M_ScheduleGroupTestM_ScheduleGroupID = {$schedulegroup_id}";
|
|
$delete_exist_tparent= $this->db_onedev->query($existparent);
|
|
if(!$delete_exist_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest update parent");
|
|
exit;
|
|
}
|
|
|
|
$insertparent = "INSERT INTO m_schedulegrouptest (
|
|
M_ScheduleGroupTestM_ScheduleGroupID,
|
|
M_ScheduleGroupTestNat_TestID,
|
|
M_ScheduleGroupTestCreatedUserID,
|
|
M_ScheduleGroupTestCreated
|
|
)
|
|
VALUES($schedulegroup_id,$nattestid,$userid,NOW())";
|
|
$insert_tparent= $this->db_onedev->query($insertparent);
|
|
if(!$insert_tparent){
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest insert parent");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$this->db_onedev->trans_commit();
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function isNatTestAvailableForBranches($schedulegroup_id, $testsToCheck){
|
|
$testsToCheck = array_unique(array_filter(array_map('intval', (array) $testsToCheck)));
|
|
if(empty($testsToCheck)){
|
|
return true;
|
|
}
|
|
|
|
$branchRows = $this->db_onedev->query("SELECT M_ScheduleGroupBranchesM_BranchID as branch_id
|
|
FROM m_schedulegroup_branches
|
|
WHERE M_ScheduleGroupBranchesIsActive = 'Y'
|
|
AND M_ScheduleGroupBranchesM_ScheduleGroupID = {$schedulegroup_id}")->result_array();
|
|
$branchIds = array_unique(array_filter(array_map('intval', array_column($branchRows, 'branch_id'))));
|
|
|
|
if(empty($branchIds)){
|
|
return true;
|
|
}
|
|
|
|
$testsSql = implode(',', $testsToCheck);
|
|
$existingBranchSql = "SELECT DISTINCT sgb.M_ScheduleGroupBranchesM_BranchID as branch_id
|
|
FROM m_schedulegrouptest sgp
|
|
INNER JOIN m_schedulegroup_branches sgb
|
|
ON sgb.M_ScheduleGroupBranchesM_ScheduleGroupID = sgp.M_ScheduleGroupTestM_ScheduleGroupID
|
|
WHERE sgp.M_ScheduleGroupTestIsActive = 'Y'
|
|
AND sgb.M_ScheduleGroupBranchesIsActive = 'Y'
|
|
AND sgp.M_ScheduleGroupTestNat_TestID IN ($testsSql)
|
|
AND sgp.M_ScheduleGroupTestM_ScheduleGroupID <> {$schedulegroup_id}";
|
|
|
|
$existingBranchRows = $this->db_onedev->query($existingBranchSql)->result_array();
|
|
$existingBranches = array_unique(array_filter(array_map('intval', array_column($existingBranchRows, 'branch_id'))));
|
|
|
|
if(empty($existingBranches)){
|
|
return true;
|
|
}
|
|
|
|
$conflictedBranches = array_intersect($branchIds, $existingBranches);
|
|
return empty($conflictedBranches);
|
|
}
|
|
|
|
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);
|
|
$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;
|
|
|
|
|
|
$sqlparent = "update m_schedulegrouptest
|
|
set M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdated = NOW(),
|
|
M_ScheduleGroupTestLastUpdatedUserID = {$userid}
|
|
where M_ScheduleGroupTestNat_TestID= ?
|
|
and M_ScheduleGroupTestM_ScheduleGroupID=?";
|
|
$queryparent = $this->db_onedev->query($sqlparent,$sql_param);
|
|
|
|
$sqlchild = "update m_schedulegrouptest
|
|
set M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdated = NOW(),
|
|
M_ScheduleGroupTestLastUpdatedUserID = {$userid}
|
|
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',
|
|
M_ScheduleGroupTestLastUpdated = NOW(),
|
|
M_ScheduleGroupTestLastUpdatedUserID = {$userid}
|
|
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;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$this->db_onedev->trans_begin();
|
|
|
|
$sql = "UPDATE m_scheduletest SET
|
|
M_ScheduleTestIsActive = 'N',
|
|
M_ScheduleTestLastUpdated = now(),
|
|
M_ScheduleTestLastUpdatedUserID = {$userid}
|
|
WHERE
|
|
M_ScheduleTestID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("m_scheduletest delete");
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
|
|
|
|
|
|
$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;
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$this->db_onedev->trans_begin();
|
|
|
|
$sql = "UPDATE m_schedulegroup SET
|
|
M_ScheduleGroupIsActive = 'N',
|
|
M_ScheduleGroupLastUpdated = now(),
|
|
M_ScheduleGroupLastUpdatedUserID = {$userid}
|
|
WHERE
|
|
M_ScheduleGroupID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup delete");
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE m_schedulegrouptest SET
|
|
M_ScheduleGroupTestIsActive = 'N',
|
|
M_ScheduleGroupTestLastUpdated = NOW(),
|
|
M_ScheduleGroupTestLastUpdatedUserID = {$userid}
|
|
WHERE
|
|
M_ScheduleGroupTestM_ScheduleGroupID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegrouptest delete");
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE m_schedule SET
|
|
M_ScheduleIsActive = 'N',
|
|
M_ScheduleLastUpdate = NOW(),
|
|
M_ScheduleLastUpdateUserID = {$userid}
|
|
WHERE
|
|
M_ScheduleM_ScheduleGroupID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedule delete");
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE m_schedulegroup_branches SET
|
|
M_ScheduleGroupBranchIsActive = 'N',
|
|
M_ScheduleGroupBranchLastUpdated = NOW(),
|
|
M_ScheduleGroupBranchLastUpdatedUserID = {$userid}
|
|
WHERE M_ScheduleGroupBranchM_ScheduleGroupID = ?
|
|
";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_schedulegroup_branches delete");
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
|
|
$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
|
|
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;
|
|
}
|
|
}
|
|
}
|