Files
2026-04-27 10:31:17 +07:00

665 lines
22 KiB
PHP

<?php
class Groupresult extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "GROUP RESULT API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupdetailbyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$groupresult = $prm['groupresult'];
$detail = $prm['detail'];;
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
FROM(SELECT *
from group_resultdetail
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive = 'Y'
JOIN t_test ON Group_ResultDetailT_TestID = T_TestID
WHERE
Group_ResultName LIKE CONCAT('%','{$groupresult}','%') AND
T_TestName LIKE CONCAT('%','{$detail}','%') AND
Group_ResultDetailIsActive = 'Y' GROUP BY Group_ResultDetailID) a";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$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("group_resultdetail count", $this->db_onedev);
exit;
}
$sql = "select Group_ResultDetailID as id,
Group_ResultName,
T_TestName,
group_resultdetail.*
from group_resultdetail
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive = 'Y'
JOIN t_test ON Group_ResultDetailT_TestID = T_TestID
WHERE
Group_ResultName LIKE CONCAT('%','{$groupresult}','%') AND
T_TestName LIKE CONCAT('%','{$detail}','%') AND
Group_ResultDetailIsActive = 'Y'
GROUP BY Group_ResultDetailID
ORDER BY Group_ResultName ASC, T_TestName 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("group_resultdetail 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);
}
}
function lookupdetailbyid(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$groupresult = $prm['groupresult'];
$detail = $prm['detail'];;
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
FROM(SELECT *
from group_resultdetail
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive = 'Y'
JOIN t_test ON Group_ResultDetailT_TestID = T_TestID
WHERE
($groupresult = 0 or ($groupresult > 0 and Group_ResultDetailGroup_ResultID = $groupresult)) AND
T_TestName LIKE CONCAT('%','{$detail}','%') AND
Group_ResultDetailIsActive = 'Y' GROUP BY Group_ResultDetailID) a";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$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("group_resultdetail count", $this->db_onedev);
exit;
}
$sql = "select Group_ResultDetailID as id,
Group_ResultName,
T_TestName,
group_resultdetail.*
from group_resultdetail
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive = 'Y'
JOIN t_test ON Group_ResultDetailT_TestID = T_TestID
WHERE
($groupresult = 0 or ($groupresult > 0 and Group_ResultDetailGroup_ResultID = $groupresult)) AND
T_TestName LIKE CONCAT('%','{$detail}','%') AND
Group_ResultDetailIsActive = 'Y'
GROUP BY Group_ResultDetailID
ORDER BY Group_ResultName ASC, T_TestName 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("group_resultdetail 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 lookupgroupresultbyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$groupresult = $prm['groupresult'];
$detail = $prm['detail'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
FROM(SELECT *
from group_result
LEFT JOIN group_resultdetail ON Group_ResultID = Group_ResultDetailGroup_ResultID AND Group_ResultDetailIsActive = 'Y'
LEFT JOIN t_test ON Group_ResultDetailT_TestID = T_TestID
where
Group_ResultName LIKE CONCAT('%','{$groupresult}','%') AND
IFNULL(T_TestName,'') LIKE CONCAT('%','{$detail}','%') AND
Group_ResultIsActive = 'Y'
GROUP BY Group_ResultID) a";
$sql_param = array($search);
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$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("group_result count", $this->db_onedev);
exit;
}
$sql = "select Group_ResultID as id,
Group_ResultName as name,
Group_ResultName as namex,
IF(Group_ResultFlagPerTest = 'Y','Ya','Tidak') as ispertest,
IF(Group_ResultFlagNonLab = 'Y','Ya','Tidak') as isnonlab,
group_result.*
from group_result
LEFT JOIN group_resultdetail ON Group_ResultID = Group_ResultDetailGroup_ResultID AND Group_ResultDetailIsActive = 'Y'
LEFT JOIN t_test ON Group_ResultDetailT_TestID = T_TestID
where
Group_ResultName LIKE CONCAT('%','{$groupresult}','%') AND
IFNULL(T_TestName,'') LIKE CONCAT('%','{$detail}','%') AND
Group_ResultIsActive = 'Y'
GROUP BY Group_ResultID
ORDER BY Group_ResultName 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("group_result 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 addnewgroupresult()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$ispertest = $prm['ispertest'];
$isnonlab = $prm['isnonlab'];
$sql = "insert into group_result(
Group_ResultName,
Group_ResultFlagPerTest,
Group_ResultFlagNonLab
)
values( ?, ?, ?)";
$query = $this->db_onedev->query($sql,
array(
$name,
$ispertest,
$isnonlab
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("group_result insert");
exit;
}
$last_id = $this->db_onedev->insert_id();
$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 editgroupresult()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$name = $prm['name'];
$ispertest = $prm['ispertest'];
$isnonlab = $prm['isnonlab'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update group_result SET
Group_ResultName = ?,
Group_ResultFlagPerTest = ?,
Group_ResultFlagNonLab = ?
where
Group_ResultID = ?
";
$querycompany = $this->db_onedev->query($sqlcompany,
array(
$name,
$ispertest,
$isnonlab,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("group_result 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 addnewdetail()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$groupresultid = $prm['groupresultid'];
$testid = $prm['testid'];
$userid = $this->sys_user["M_UserID"];
if($groupresultid == 0 || $testid == 0){
$errors = array();
if($groupresultid == 0){
array_push($errors,array('field'=>'groupresult','msg'=>'Kelompok hasil dipilih dulu dong'));
}
if($testid == 0){
array_push($errors,array('field'=>'test','msg'=>'Pemeriksaan dipilih dulu dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}else{
if($prm['xid'] == 0){
$sql = "insert into group_resultdetail(
Group_ResultDetailGroup_ResultID,
Group_ResultDetailT_TestID)
values(?,?)";
$query = $this->db_onedev->query($sql,
array(
$groupresultid,
$testid
)
);
if (!$query) {
$this->sys_error_db("group_resultdetail insert",$this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$sql = "UPDATE group_resultdetail SET Group_ResultDetailGroup_ResultID = '{$groupresultid}',
Group_ResultDetailT_TestID = '{$testid}'
WHERE Group_ResultDetailID = '{$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 deletegroupresult()
{
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 group_result SET
Group_ResultIsActive = 'N'
WHERE
Group_ResultID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("group_result delete");
exit;
}
$sql = "update group_resultdetail SET
Group_ResultDetailIsActive = 'N'
WHERE
Group_ResultDetailGroup_ResultID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("group_resultdetail 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 deletedetail()
{
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 group_resultdetail SET
Group_ResultDetailIsActive = 'N'
WHERE
Group_ResultDetailID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("group_resultdetail 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 searchgroupresult(){
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 group_result
WHERE
Group_ResultName like ?
AND Group_ResultIsActive = '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("group_result count",$this->db_onedev);
exit;
}
$sql = "
SELECT Group_ResultID, Group_ResultName
FROM group_result
WHERE
Group_ResultName like ?
AND Group_ResultIsActive = 'Y'
ORDER BY Group_ResultName 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("group_result rows",$this->db_onedev);
exit;
}
}
function searchgroupresultbyname(){
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 group_result
WHERE
Group_ResultName like ?
AND Group_ResultIsActive = '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("group_result count",$this->db_onedev);
exit;
}
$sql = "
SELECT Group_ResultID, Group_ResultName
FROM group_result
WHERE
Group_ResultName like ?
AND Group_ResultIsActive = 'Y'
ORDER BY Group_ResultName 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("group_result 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 t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y' AND T_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("t_test count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'
ORDER BY T_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("t_test rows",$this->db_onedev);
exit;
}
}
}