Files
REG_IBL/one-api/application/controllers/mockup/masterdata/Autoverification.php
2026-05-25 20:01:37 +07:00

772 lines
22 KiB
PHP

<?php
class Autoverification extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "AUTO VERIFICATION API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookuptrendanalys(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select nat_trend_analysis.*,T_TestID as testid
from nat_trend_analysis
JOIN t_test ON Nat_TrendAnalysisT_TestID = T_TestID AND T_TestIsActive = 'Y'
where
Nat_TrendAnalysisT_TestID = {$id} AND Nat_TrendAnalysisIsActive = 'Y'";
$sql_param = array($orderid);
$query = $this->db_onedev->query($sql,$sql_param);
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_trend_analysis select");
exit;
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookuphasil(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select Nat_MultiruleID as id, M_ValueName as name, Nat_MultiruleM_ValueID as hasilid, Nat_MultiruleT_TestID as testid
from nat_multirule
JOIN m_value ON Nat_MultiruleM_ValueID = M_ValueID AND M_ValueIsActive = 'Y'
where
Nat_MultiruleT_TestID = {$id} AND Nat_MultiruleIsActive = 'Y'";
$sql_param = array($orderid);
$query = $this->db_onedev->query($sql,$sql_param);
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_multirule");
exit;
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function lookup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$sql = "select COUNT(*) as total
from t_test
LEFT JOIN nat_trend_analysis ON T_TestID = Nat_TrendAnalysisT_TestID
LEFT JOIN nat_delta_check ON T_TestID = Nat_DeltaCheckT_TestID
where
T_TestIsActive = 'Y' AND
T_TestIsQuantitative = 'Y' AND
T_TestIsResult = 'Y'";
$sql_param = array($search);
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$sql = "select T_TestID as id, CONCAT(T_TestName,' ' ,'[ ',T_TestCode,' ]') as name,
Nat_TrendAnalysisT_TestID,Nat_TrendAnalysisMinimunTest,Nat_TrendAnalysisValue,
nat_delta_check.*, M_TimeName as xtime, M_DifferenceName as xdif,T_TestIsDeltaCheck,T_TestIsTrendAnalysis
from t_test
LEFT JOIN nat_trend_analysis ON T_TestID = Nat_TrendAnalysisT_TestID
LEFT JOIN nat_delta_check ON T_TestID = Nat_DeltaCheckT_TestID
LEFT JOIN m_time ON Nat_DeltaCheckM_TimeID = M_TimeID
LEFT JOIN m_difference ON Nat_DeltaCheckM_DifferenceID = M_DifferenceID
where
(T_TestName LIKE CONCAT('%','{$search}','%') OR T_TestCode LIKE CONCAT('%','{$search}','%')) AND
T_TestIsActive = 'Y' AND
T_TestIsQuantitative = 'Y' AND
(T_TestIsDeltaCheck = 'Y' OR T_TestIsTrendAnalysis = 'Y') $limit";
// echo $sql;
$sql_param = array($search);
$query = $this->db_onedev->query($sql,$sql_param);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("t_test select");
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewschedule()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name_schedule = $prm['name'];
$query = "SELECT COUNT(*) as exist FROM m_schedule WHERE M_ScheduleIsActive = 'Y' AND M_ScheduleName = '{$name_schedule}'";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "insert into m_schedule(
M_ScheduleName,
M_ScheduleCreated,
M_ScheduleLastUpdated
)
values( ?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$name_schedule
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("m_schedule insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editschedule()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id_schedule = $prm['id'];
$name_schedule = $prm['name'];
$query = "SELECT COUNT(*) as exist FROM m_schedule WHERE M_ScheduleIsActive = 'Y' AND M_ScheduleName = '{$name_schedule}' AND M_ScheduleID <> {$id_schedule}";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "update m_schedule SET
M_ScheduleName = ?,
M_ScheduleLastUpdated = now()
where
M_ScheduleID = ?
";
$query = $this->db_onedev->query($sql,
array(
$name_schedule,
$id_schedule
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("m_schedule update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id_schedule));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function savetrendanalys()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$testid = $prm['testid'];
$mintest = $prm['mintest'];
$trendvalue = $prm['trendvalue'];
$query = "SELECT COUNT(*) as exist FROM nat_trend_analysis WHERE Nat_TrendAnalysisIsActive = 'Y' AND Nat_TrendAnalysisT_TestID = '{$testid}'";
$exist_test = $this->db_onedev->query($query)->row()->exist;
if($exist_test == 0){
$sql = "insert into nat_trend_analysis(
Nat_TrendAnalysisT_TestID,
Nat_TrendAnalysisMinimunTest,
Nat_TrendAnalysisValue,
Nat_TrendAnalysisCreated,
Nat_TrendAnalysisLastUpdated
)
values( ?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$testid,
$mintest,
$trendvalue
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_trend_analysis insert");
exit;
}
} else {
$sql = "update nat_trend_analysis SET
Nat_TrendAnalysisMinimunTest = ?,
Nat_TrendAnalysisValue = ?,
Nat_TrendAnalysisLastUpdated = now()
WHERE
Nat_TrendAnalysisIsActive = 'Y' AND
Nat_TrendAnalysisT_TestID = ?
";
$query = $this->db_onedev->query($sql,
array(
$mintest,
$trendvalue,
$testid
)
);
if (!$query) {
$this->sys_error_db("nat_trend_analysis update");
exit;
}
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function savedeltacheck()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$testid = $prm['testid'];
$differenceid = $prm['differenceid'];
$validinterval = $prm['validinterval'];
$timeid = $prm['timeid'];
$upperlimit = $prm['upperlimit'];
$lowerlimit = $prm['lowerlimit'];
$query = "SELECT COUNT(*) as exist FROM nat_delta_check WHERE Nat_DeltaCheckIsActive = 'Y' AND Nat_DeltaCheckT_TestID = '{$testid}'";
$exist_test = $this->db_onedev->query($query)->row()->exist;
if($exist_test == 0){
$sql = "insert into nat_delta_check(
Nat_DeltaCheckT_TestID,
Nat_DeltaCheckM_DifferenceID,
Nat_DeltaCheckValidInterval,
Nat_DeltaCheckM_TimeID,
Nat_DeltaCheckUpperLimit,
Nat_DeltaCheckLowerLimit,
Nat_DeltaCheckCreated,
Nat_DeltaCheckLastUpdated
)
values( ?,?,?,?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$testid,
$differenceid,
$validinterval,
$timeid,
$upperlimit,
$lowerlimit
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_delta_check insert");
exit;
}
} else {
$sql = "update nat_delta_check SET
Nat_DeltaCheckM_DifferenceID = ?,
Nat_DeltaCheckValidInterval = ?,
Nat_DeltaCheckM_TimeID = ?,
Nat_DeltaCheckUpperLimit = ?,
Nat_DeltaCheckLowerLimit = ?,
Nat_DeltaCheckLastUpdated = now()
WHERE
Nat_DeltaCheckIsActive = 'Y' AND
Nat_DeltaCheckT_TestID = ?
";
$query = $this->db_onedev->query($sql,
array(
$differenceid,
$validinterval,
$timeid,
$upperlimit,
$lowerlimit,
$testid
)
);
if (!$query) {
$this->sys_error_db("nat_delta_check update");
exit;
}
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectvaluex(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_value
WHERE
M_ValueIsActive = 'Y'
";
//echo $query;
$rows['valuexs'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selecttime(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_time
WHERE
M_TimeIsActive = 'Y'
";
//echo $query;
$rows['times'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectdif(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_difference
WHERE
M_DifferenceIsActive = 'Y'
";
//echo $query;
$rows['difs'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function savemultirule()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$testid = $prm['testid'];
$hasilid = $prm['hasilid'];
$sql = "insert into nat_multirule(
Nat_MultiruleT_TestID,
Nat_MultiruleM_ValueID,
Nat_MultiruleCreated,
Nat_MultiruleLastUpdated
)
values( ?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$testid,
$hasilid
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_multirule insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteschedulepromise()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update m_schedulepromise SET
M_SchedulePromiseIsActive = 'N',
M_SchedulePromiseLastUpdate = now()
WHERE
M_SchedulePromiseID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_schedulepromise delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletescheduletest()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update m_scheduletest SET
M_ScheduleTestIsActive = 'N',
M_ScheduleTestLastUpdated = now()
WHERE
M_ScheduleTestID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_scheduletest delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteschedule()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update m_schedule SET
M_ScheduleIsActive = 'N',
M_ScheduleLastUpdated = now()
WHERE
M_ScheduleID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_schedule delete");
exit;
}
$sql = "update m_scheduletest SET
M_ScheduleTestIsActive = 'N',
M_ScheduleTestLastUpdated = now()
WHERE
M_ScheduleTestM_ScheduleID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_scheduletest delete");
exit;
}
$sql = "update m_schedulepromise SET
M_SchedulePromiseIsActive = 'N',
M_SchedulePromiseLastUpdate = now()
WHERE
M_SchedulePromiseM_ScheduleID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_schedulepromise delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function searchtest()
{
$prm = $this->sys_input;
$scheduleid = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM 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;
}
}
}