Files
BE_IBL/application/controllers/v1/masterdata/multirulev3/Multirule.php
2026-04-15 15:23:57 +07:00

1745 lines
58 KiB
PHP

<?php
class Multirule extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "MULTI RULE API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupreflextest(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select Nat_ReflexTestID as id,
h.Nat_ConditionID as kondisiheaderid,
h.Nat_ConditionName as kondisiheader,
mut.Nat_TestIsQuantitative as headerIsQuantitative,
t.Nat_ConditionID as Nat_ConditionID,
t.Nat_ConditionName as Nat_ConditionName,
nt.Nat_TestIsQuantitative as testIsQuantitative,
nat_reflextest.*,
GROUP_CONCAT(CONCAT(mt.Nat_TestName , ' | ', mc.Nat_ConditionName) SEPARATOR '<br>') as grupmandatory,
nt.Nat_TestID as Nat_TestID,
nt.Nat_TestName as Nat_TestName,
'xxx' as mandatorys
from nat_reflextest
LEFT JOIN nat_multirule ON Nat_ReflexTestNatMultiruleID = NatMultiruleID
JOIN nat_test mut ON NatMultiruleNat_TestID = mut.Nat_TestID
JOIN nat_test nt ON Nat_ReflexTestNat_TestID = nt.Nat_TestID
JOIN nat_condition h ON NatMultiruleNat_ConditionID = h.Nat_ConditionID
JOIN nat_condition t ON Nat_ReflexTestNat_ConditionID = t.Nat_ConditionID
LEFT JOIN nat_reflexmandatory ON Nat_ReflexMandatoryNat_ReflexTestID = Nat_ReflexTestID AND Nat_ReflexMandatoryIsActive = 'Y'
LEFT JOIN nat_test mt ON Nat_ReflexMandatoryNat_TestID = mt.Nat_TestID
LEFT JOIN nat_condition mc ON Nat_ReflexMandatoryNat_ConditionID = mc.Nat_ConditionID
WHERE
Nat_ReflexTestNatMultiruleID = {$id} AND Nat_ReflexTestIsActive = 'Y'
GROUP BY Nat_ReflexTestID";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['tesx'] = json_decode($x->n);
$rows[$k]['mandatorys'] = $this->add_mandatory($v['Nat_ReflexTestID']);
}
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function add_mandatory($orderid){
$query ="SELECT Nat_ReflexMandatoryID,
Nat_ReflexMandatoryNat_ReflexTestID,
Nat_ReflexMandatoryNat_TestID,
Nat_ReflexMandatoryNat_ConditionID,
Nat_TestID,
Nat_TestName,
Nat_ConditionID,
Nat_ConditionName,
Nat_TestIsQuantitative,
'Y' as editable
FROM nat_reflexmandatory
LEFT JOIN nat_test ON Nat_ReflexMandatoryNat_TestID = Nat_TestID
LEFT JOIN nat_condition ON Nat_ReflexMandatoryNat_ConditionID = Nat_ConditionID
WHERE
Nat_ReflexMandatoryNat_ReflexTestID = '{$orderid}'
AND
Nat_ReflexMandatoryIsActive = 'Y'
ORDER BY Nat_ReflexMandatoryID DESC";
// echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
public function lookup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$nattestid = $prm['nattestid'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$sql = "select COUNT(*) as total
from nat_multirule
where
NatMultiruleIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$sqlinfo ="SELECT *, IFNULL(Nat_NormalValueValue,'') as Nat_NormalValueValue FROM (SELECT Nat_NormalValueMinValue,
Nat_NormalValueMaxValue,
Nat_NormalValueMinValueInclusive,
Nat_NormalValueMaxValueInclusive,
Nat_NormalValueNote,
CASE
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' - ',' Tinggi: ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'N' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' > ',' Tinggi: ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'N' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' < ','Tinggi : ',Nat_NormalValueMaxValue)
ELSE '-'
END as Nat_NormalValueValue
FROM nat_normalvalue
JOIN nat_methode ON Nat_NormalValueNat_MethodeID = Nat_MethodeID
WHERE Nat_NormalValueIsActive = 'Y' AND
Nat_NormalValueNat_TestID = '{$nattestid}'
ORDER BY Nat_MethodePriority DESC
LIMIT 1) a";
$info = $this->db_onedev->query($sqlinfo)->row()->Nat_NormalValueValue;
$sql = "SELECT *, IFNULL(IF(NatMultiruleIsAllMethode = 'Y', '{$info}', Nat_NormalValueValue),'') as Nat_NormalValueValue FROM(select NatMultiruleID as id,
Nat_TestID,
Nat_TestName,
IF(NatMultiruleIsAllMethode = 'Y', 0 ,Nat_MethodeID) as Nat_MethodeID,
IF(NatMultiruleIsAllMethode = 'Y', 'Semua Metode',Nat_MethodeName) as Nat_MethodeName,
Nat_NormalValueMinValue,
Nat_NormalValueMaxValue,
Nat_NormalValueMinValueInclusive,
Nat_NormalValueMaxValueInclusive,
Nat_NormalValueNote,
CASE
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' - ',' Tinggi: ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'N' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' > ',' Tinggi: ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'N' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' < ','Tinggi : ',Nat_NormalValueMaxValue)
ELSE '-'
END as Nat_NormalValueValue,
Nat_ConditionID,
Nat_ConditionName,
nat_multirule.*
from nat_multirule
LEFT JOIN nat_methode ON NatMultiruleNat_MethodeID = Nat_MethodeID
JOIN nat_condition ON NatMultiruleNat_ConditionID = Nat_ConditionID
JOIN nat_test ON NatMultiruleNat_TestID = Nat_TestID
LEFT JOIN nat_normalvalue ON NatMultiruleNat_MethodeID = Nat_NormalValueNat_MethodeID AND NatMultiruleNat_TestID = Nat_NormalValueNat_TestID
where
NatMultiruleIsActive = 'Y' AND
NatMultiruleNat_TestID = '{$nattestid}'
GROUP BY NatMultiruleID
ORDER BY NatMultiruleID DESC $limit) a";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_multirule 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 lookuptest()
{
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 100';
}
$number_limit = 100;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
from nat_test
where
Nat_TestIsActive = 'Y' AND Nat_TestIsResult = 'Y'";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("nat_test count", $this->db_onedev);
exit;
}
$sql = "select Nat_TestID as id,
Nat_TestCode as code,
Nat_TestName as name,nat_test.*
from nat_test
where
( Nat_TestName LIKE CONCAT('%','{$search}','%') OR
Nat_TestCode LIKE CONCAT('%','{$search}','%'))AND
Nat_TestIsActive = 'Y' AND Nat_TestIsResult = 'Y'
GROUP BY Nat_TestID
ORDER BY Nat_TestCode ASC limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_test select");
exit;
}
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewmultirule()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$nattestid = $prm['nattestid'];
$methodeid = $prm['methodeid'];
$conditionid = $prm['conditionid'];
$isallmethode = $prm['isallmethode'];
$extralow = $prm['extralow'];
$extrahigh = $prm['extrahigh'];
$limitdetection = $prm['limitdetection'];
$linear = $prm['linear'];
$userid = $this->sys_user["M_UserID"];
$query = "SELECT COUNT(*) as exist FROM nat_multirule WHERE NatMultiruleIsActive = 'Y' AND NatMultiruleNat_ConditionID = '{$conditionid}'";
$exist_condition = $this->db_onedev->query($query)->row()->exist;
$sql = "insert into nat_multirule(
NatMultiruleNat_TestID,
NatMultiruleNat_MethodeID,
NatMultiruleNat_ConditionID,
NatMultiruleIsAllMethode,
NatMultiruleExtraLow,
NatMultiruleExtraHigh,
NatMultiruleLimitDetection,
NatMultiruleLinearity,
NatMultiruleUserID,
NatMultiruleCreated,
NatMultiruleLastUpdated
)
values( ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now())";
$query = $this->db_onedev->query($sql,
array(
$nattestid,
$methodeid,
$conditionid,
$isallmethode,
$extralow,
$extrahigh,
$limitdetection,
$linear,
$userid,
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_multirule insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
$last_id = $this->db_onedev->insert_id();
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editmultirule()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$nattestid = $prm['nattestid'];
$methodeid = $prm['methodeid'];
$conditionid = $prm['conditionid'];
$isallmethode = $prm['isallmethode'];
$extralow = $prm['extralow'];
$extrahigh = $prm['extrahigh'];
$limitdetection = $prm['limitdetection'];
$linear = $prm['linear'];
$userid = $this->sys_user["M_UserID"];
$query = "SELECT COUNT(*) as exist FROM nat_multirule WHERE NatMultiruleIsActive = 'Y' AND NatMultiruleNat_ConditionID = '{$conditionid}' AND NatMultiruleID <> '{$id}'";
$exist_condition = $this->db_onedev->query($query)->row()->exist;
$sqlmultirule = "update nat_multirule SET
NatMultiruleNat_MethodeID = ?,
NatMultiruleNat_ConditionID = ?,
NatMultiruleIsAllMethode = ?,
NatMultiruleExtraLow = ?,
NatMultiruleExtraHigh = ?,
NatMultiruleLimitDetection = ?,
NatMultiruleLinearity = ?,
NatMultiruleUserID = ?,
NatMultiruleLastUpdated = now()
where
NatMultiruleID = ?
";
$querymultirule = $this->db_onedev->query($sqlmultirule,
array(
$methodeid,
$conditionid,
$isallmethode,
$extralow,
$extrahigh,
$limitdetection,
$linear,
$userid,
$id
)
);
// echo $query;
if (!$querymultirule) {
$this->sys_error_db("nat_multirule update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewreflextest()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['xid'];
$multiruleid = $prm['multiruleid'];
$nattestid = $prm['nattestid'];
$conditionid = $prm['conditionid'];
$relationid = $prm['relationid'];
$userid = $this->sys_user["M_UserID"];
//echo $query;
if($prm['xid'] == "0" || $prm['xid'] == 0){
$sql = "INSERT into nat_reflextest
(Nat_ReflexTestNatMultiruleID,
Nat_ReflexTestNat_TestID,
Nat_ReflexTestNat_ConditionID,
Nat_ReflexTestNat_RelationID,
Nat_ReflexTestUserID,
Nat_ReflexTestCreated,
Nat_ReflexTestLastUpdated)
VALUES
('{$multiruleid}',
'{$nattestid}',
'{$conditionid}',
'{$relationid}',
'{$userid}',
now(),
now())";
//echo $sql;
$query = $this->db_onedev->query($sql);
$reflextest_id = $this->db_onedev->insert_id();
foreach($prm['ordertests'] as $k=>$v){
$query = "INSERT INTO nat_reflexmandatory (
Nat_ReflexMandatoryNat_ReflexTestID,
Nat_ReflexMandatoryNat_TestID,
Nat_ReflexMandatoryNat_ConditionID,
Nat_ReflexMandatoryUserID,
Nat_ReflexMandatoryCreated,
Nat_ReflexMandatoryLastUpdated)
VALUES(
?,?,?,?,now(),now()
)";
$insert_new_mandatory = $this->db_onedev->query($query,array(
$reflextest_id,
$v['Nat_TestID'],
$v['Nat_ConditionID'],
$userid
));
}
if (!$query) {
$this->sys_error_db("nat_reflexmandatory insert");
exit;
}
}else{
$sql = "UPDATE nat_reflextest SET Nat_ReflexTestNat_TestID = '{$nattestid}',
Nat_ReflexTestNat_ConditionID = '{$conditionid}',
Nat_ReflexTestNat_RelationID = '{$relationid}',
Nat_ReflexTestUserID = '{$userid}',
Nat_ReflexTestLastUpdated = now()
WHERE Nat_ReflexTestID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
foreach($prm['ordertests'] as $k=>$v){
if($v['Nat_ReflexMandatoryID'] == 0 || $v['Nat_ReflexMandatoryID'] == '0'){
$query = "INSERT INTO nat_reflexmandatory (
Nat_ReflexMandatoryNat_ReflexTestID,
Nat_ReflexMandatoryNat_TestID,
Nat_ReflexMandatoryNat_ConditionID,
Nat_ReflexMandatoryUserID,
Nat_ReflexMandatoryCreated,
Nat_ReflexMandatoryLastUpdated)
VALUES(
?,?,?,?,now(),now()
)";
$insert_new_mandatory = $this->db_onedev->query($query,array(
$prm['xid'],
$v['Nat_TestID'],
$v['Nat_ConditionID'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE nat_reflexmandatory SET
Nat_ReflexMandatoryIsActive = 'N',
Nat_ReflexMandatoryUserID = '{$userid}',
Nat_ReflexMandatoryLastUpdated = now()
WHERE
Nat_ReflexMandatoryID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['Nat_ReflexMandatoryID']));
}
}
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewconvert()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$instrumentid = $prm['instrumentid'];
$resultorigin = $prm['resultorigin'];
$resultconvert = $prm['resultconvert'];
$userid = $this->sys_user["M_UserID"];
if($prm['xid'] == 0){
$sql = "insert into m_instrumentconvert(
M_InstrumentConvertNat_InstrumentID,
M_InstrumentConvertResultOrigin,
M_InstrumentConvertResultConvert,
M_InstrumentConvertUserID,
M_InstrumentConvertCreated,
M_InstrumentConvertLastUpdated
)
values( ?,?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$instrumentid,
$resultorigin,
$resultconvert,
$userid
)
);
if (!$query) {
$this->sys_error_db("m_instrumentconvert insert",$this->db_onedev);
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
//echo $query;
$sql = "UPDATE m_instrumentconvert SET M_InstrumentConvertResultOrigin = '{$resultorigin}',
M_InstrumentConvertResultConvert = '{$resultconvert}',
M_InstrumentConvertUserID = '{$userid}' WHERE M_InstrumentConvertID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteuser()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update m_user SET
M_UserIsActive = 'N',
M_UserLastUpdated = now()
WHERE
M_UserID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_user 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 confirmmou()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update m_mou SET
M_MouIsApproved = 'Y',
M_MouLastUpdated = now()
WHERE
M_MouID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_mou 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 verifymou()
{
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"];
$id = $prm['id'];
$sql = "update m_mou SET
M_MouIsVerified = 'Y',
M_MouVerifyDate = now(),
M_MouStatus = 'V',
M_MouVerifyUserID = '{$userid}',
M_MouLastUpdated = now()
WHERE
M_MouID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_mou update");
exit;
}
$querystatus ="INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$id}',
'V',
'{$userid}',
now(),
now())
";
$rows = $this->db_onedev->query($querystatus);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function unverifymou()
{
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"];
$id = $prm['id'];
$sql = "update m_mou SET
M_MouIsVerified = 'N',
M_MouStatus = 'UV',
M_MouVerifyDate = now(),
M_MouVerifyUserID = '{$userid}',
M_MouLastUpdated = now()
WHERE
M_MouID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_mou update");
exit;
}
$querystatus ="INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$id}',
'UV',
'{$userid}',
now(),
now())
";
$rows = $this->db_onedev->query($querystatus);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function releasemou()
{
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"];
$id = $prm['id'];
$sql = "update m_mou SET
M_MouIsReleased = 'Y',
M_MouStatus = 'R',
M_MouReleaseDate = now(),
M_MouReleaseUserID = '{$userid}',
M_MouIsApproved = 'Y',
M_MouLastUpdated = now()
WHERE
M_MouID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_mou update");
exit;
}
$querystatus ="INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$id}',
'R',
'{$userid}',
now(),
now())
";
$rows = $this->db_onedev->query($querystatus);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function unreleasemou()
{
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"];
$id = $prm['id'];
$sql = "update m_mou SET
M_MouIsReleased = 'N',
M_MouStatus = 'UR',
M_MouReleaseDate = now(),
M_MouReleaseUserID = '{$userid}',
M_MouIsApproved = 'N',
M_MouLastUpdated = now()
WHERE
M_MouID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_mou update");
exit;
}
$querystatus ="INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$id}',
'UR',
'{$userid}',
now(),
now())
";
$rows = $this->db_onedev->query($querystatus);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletemultirule()
{
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"];
$sql = "update nat_multirule SET
NatMultiruleIsActive = 'N',
NatMultiruleLastUpdated = now()
WHERE
NatMultiruleID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_multirule delete");
exit;
}
$sql = "update nat_reflextest SET
Nat_ReflexTestIsActive = 'N',
Nat_ReflexTestLastUpdated = now()
WHERE
Nat_ReflexTestNatMultiruleID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_reflextest 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 deletereflextest()
{
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"];
$sql = "update nat_reflextest SET
Nat_ReflexTestIsActive = 'N',
Nat_ReflexTestLastUpdated = now()
WHERE
Nat_ReflexTestID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_reflextest 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 selectmethode(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$nattestid = $prm['nattestid'];
$rows = [];
$query ="SELECT Nat_MethodeID, Nat_MethodeName
FROM nat_normalvalue
JOIN nat_methode ON Nat_NormalValueNat_MethodeID = Nat_MethodeID
WHERE Nat_NormalValueIsActive = 'Y' AND
Nat_NormalValueNat_TestID = '{$nattestid}'";
//echo $query;
$rows['methodes'] = $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 selectinfo(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$nattestid = $prm['nattestid'];
$methodeid = $prm['methodeid'];
$rows = [];
if($methodeid == 0){
$query ="SELECT *,IFNULL(Nat_NormalValueValue,'') as Nat_NormalValueValue FROM (SELECT Nat_NormalValueMinValue,
Nat_NormalValueMaxValue,
Nat_NormalValueMinValueInclusive,
Nat_NormalValueMaxValueInclusive,
Nat_NormalValueNote,
CASE
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' - ',' Tinggi: ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'N' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' > ',' Tinggi: ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'N' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' < ','Tinggi : ',Nat_NormalValueMaxValue)
ELSE '-'
END as Nat_NormalValueValue
FROM nat_normalvalue
JOIN nat_methode ON Nat_NormalValueNat_MethodeID = Nat_MethodeID
WHERE Nat_NormalValueIsActive = 'Y' AND
Nat_NormalValueNat_TestID = '{$nattestid}'
ORDER BY Nat_MethodePriority DESC
LIMIT 1) a";
//echo $query;
$rows['infos'] = $this->db_onedev->query($query)->result_array();
}else{
$query ="SELECT *, IFNULL(Nat_NormalValueValue,'') as Nat_NormalValueValue
FROM(SELECT Nat_NormalValueMinValue,
Nat_NormalValueMaxValue,
Nat_NormalValueMinValueInclusive,
Nat_NormalValueMaxValueInclusive,
Nat_NormalValueNote,
CASE
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' - ',' Tinggi: ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'N' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' > ',' Tinggi: ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'N' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT('Rendah : ',Nat_NormalValueMinValue,' < ','Tinggi : ',Nat_NormalValueMaxValue)
ELSE '-'
END as Nat_NormalValueValue
FROM nat_normalvalue
WHERE Nat_NormalValueIsActive = 'Y' AND
Nat_NormalValueNat_TestID = '{$nattestid}' AND
Nat_NormalValueNat_MethodeID = '{$methodeid}'
LIMIT 1) a";
//echo $query;
$rows['infos'] = $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 selectcondition(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$isquantitative = $prm['isquantitative'];
$rows = [];
$query ="SELECT Nat_ConditionID, Nat_ConditionName
FROM nat_condition
WHERE Nat_ConditionIsActive = 'Y' AND Nat_ConditionIsQuantitative = '{$isquantitative}'";
//echo $query;
$rows['conditions'] = $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 selectconditionheader(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$isquantitative = $prm['isquantitative'];
$rows = [];
$query ="SELECT Nat_ConditionID, Nat_ConditionName
FROM nat_condition
WHERE Nat_ConditionIsActive = 'Y' AND Nat_ConditionIsQuantitative = '{$isquantitative}'";
//echo $query;
$rows['conditions'] = $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 selectconditiontest(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$isquantitative = $prm['isquantitative'];
$rows = [];
$query ="SELECT Nat_ConditionID, Nat_ConditionName
FROM nat_condition
WHERE Nat_ConditionIsActive = 'Y' AND Nat_ConditionIsQuantitative = '{$isquantitative}'";
//echo $query;
$rows['conditions'] = $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 selectconditionmandatory(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$isquantitative = $prm['isquantitative'];
$rows = [];
$query ="SELECT Nat_ConditionID, Nat_ConditionName
FROM nat_condition
WHERE Nat_ConditionIsActive = 'Y' AND Nat_ConditionIsQuantitative = '{$isquantitative}'";
//echo $query;
$rows['conditions'] = $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 selectrelation(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query ="SELECT Nat_RelationID, Nat_RelationName
FROM nat_relation
WHERE Nat_RelationIsActive = 'Y'";
//echo $query;
$rows['relations'] = $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 selectmultirulebusiness(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *, COUNT(M_CompanyID) as used
FROM (SELECT m_multirulebusiness.*,M_CompanyID
FROM
m_multirulebusiness
LEFT JOIN m_multirule ON M_CompanyBusinessID = M_CompanyM_CompanyBusinessID AND M_CompanyIsActive = 'Y'
WHERE M_CompanyBusinessIsActive = 'Y') a
GROUP BY M_CompanyBusinessID
";
//echo $query;
$rows['multirulebusinesss'] = $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 selectmultirulelevel(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$rows = [];
$query =" SELECT *,CONCAT(Nat_CompanyLevelName,' [',M_CompanyName,']') as Nat_CompanyLevelName, COUNT(M_CompanyID) as used
FROM (SELECT nat_multirulelevel.*,M_CompanyID,M_CompanyName
FROM
nat_multirulelevel
LEFT JOIN m_multirule ON Nat_CompanyLevelNat_CompanyID = M_CompanyID AND M_CompanyIsActive = 'Y'
WHERE Nat_CompanyLevelIsActive = 'Y') a
GROUP BY Nat_CompanyLevelID
";
//echo $query;
$rows['multirulelevels'] = $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 selecthierarchy(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *, COUNT(M_CompanyID) as used
FROM (SELECT nat_hierarchy.*,M_CompanyID
FROM
nat_hierarchy
LEFT JOIN m_multirule ON Nat_HierarchyID = M_CompanyNat_HierarchyID AND M_CompanyIsActive = 'Y'
WHERE Nat_HierarchyIsActive = 'Y') a
GROUP BY Nat_HierarchyID
";
//echo $query;
$rows['hierarchys'] = $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 selectdoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_doctor
WHERE
M_DoctorIsActive = 'Y'
";
//echo $query;
$rows['doctors'] = $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 searchreflextest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM nat_test
WHERE
Nat_TestName like ?
AND Nat_TestIsActive = 'Y' AND Nat_TestIsResult = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("nat_test count",$this->db_onedev);
exit;
}
$sql = "
SELECT Nat_TestID, Nat_TestName, Nat_TestIsQuantitative
FROM nat_test
WHERE
Nat_TestName like ?
AND Nat_TestIsActive = 'Y' AND Nat_TestIsResult = 'Y'
GROUP BY Nat_TestID
ORDER BY Nat_TestName ASC
";
$query = $this->db_onedev->query($sql, array($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("nat_test rows",$this->db_onedev);
exit;
}
}
function searchmandatorytest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM nat_test
WHERE
Nat_TestName like ?
AND Nat_TestIsActive = 'Y' AND Nat_TestIsResult = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("nat_test count",$this->db_onedev);
exit;
}
$sql = "
SELECT Nat_TestID, Nat_TestName,Nat_TestIsQuantitative
FROM nat_test
WHERE
Nat_TestName like ?
AND Nat_TestIsActive = 'Y' AND Nat_TestIsResult = 'Y'
GROUP BY Nat_TestID
ORDER BY Nat_TestName ASC
";
$query = $this->db_onedev->query($sql, array($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("nat_test rows",$this->db_onedev);
exit;
}
}
function searchtest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM nat_test
WHERE
Nat_TestName like ?
AND Nat_TestIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("nat_test count",$this->db_onedev);
exit;
}
$sql = "
SELECT Nat_TestID, Nat_TestName,Nat_TestIsQuantitative
FROM nat_test
WHERE
Nat_TestName like ?
AND Nat_TestIsActive = 'Y'
GROUP BY Nat_TestID
ORDER BY Nat_TestName ASC
";
$query = $this->db_onedev->query($sql, array($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("nat_test rows",$this->db_onedev);
exit;
}
}
function getstaff(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_staff
WHERE
M_StaffIsActive = 'Y' AND M_StaffM_PositionID = 2";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getprovince(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_province
WHERE
M_ProvinceIsActive = 'Y'";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getcity(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_city
WHERE
M_CityIsActive = 'Y' AND M_CityM_ProvinceID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdistrict(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_district
WHERE
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getkelurahan(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_kelurahan
WHERE
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function selectbase(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT 'SPK' as baseid, 'SPK' as basename
UNION SELECT 'MOU' as baseid, 'MOU' as basename
";
//echo $query;
$rows['bases'] = $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 selectomzettype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_omzettype
WHERE
M_OmzetTypeIsActive = 'Y'
";
//echo $query;
$rows['omzettypes'] = $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 selectmoutype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_moutype
WHERE
M_MouTypeIsActive = 'Y'
";
//echo $query;
$rows['moutypes'] = $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 selectagingtype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_agingtype
WHERE
M_AgingIsActive = 'Y'
";
//echo $query;
$rows['agingtypes'] = $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);
}
}
}