Files
2026-04-27 10:26:26 +07:00

170 lines
5.7 KiB
PHP

<?php
class Result extends MY_Controller
{
var $db;
public function __construct()
{
parent::__construct();
// $this->db = $this->load->database("cpone", true);
}
public function index()
{
// $cek = $this->db->query("select database() as current_db")->result();
// print_r($cek);
echo "RESULT API";
}
function get_branch()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$sql = "SELECT M_BranchID as branchID,
M_BranchCode,
M_BranchName,
M_BranchAddress
FROM m_branch
WHERE M_BranchIsActive = 'Y'";
$qry = $this->db->query($sql);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("branch select error", $this->db);
exit;
}
$result = array(
"records" => $rows,
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
}
$test_name = "";
if (isset($prm['test_name'])) {
$test_name = trim($prm["test_name"]);
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_tot = "SELECT COUNT(*) AS total FROM(
SELECT api_result.*, IF(Nat_TestName IS NULL, 'Belum Mapping', Nat_TestName) AS Nat_TestName
FROM api_result
LEFT JOIN nat_testmap ON Nat_TestMapCode = api_ResultTestCode
LEFT JOIN nat_test ON Nat_TestMapNat_TestID = Nat_TestID
WHERE `api_ResultNolab` = ? AND (`api_ResultTestName` LIKE CONCAT('%', ?, '%') OR api_ResultTestCode LIKE CONCAT('%', ?, '%'))
) x";
$qry_tot = $this->db->query($sql_tot, [ $search, $test_name, $test_name]);
//echo $this->db->last_query();
//exit;
$tot_count = 0;
$tot_page = 0;
if ($qry_tot) {
$tot_count = $qry_tot->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("result count error", $this->db);
exit;
}
$sql = "SELECT api_result.*, IF(Nat_TestName IS NULL, 'Belum Mapping', Nat_TestName) AS Nat_TestName, IF(Nat_TestCode IS NULL, '', Nat_TestCode) AS Nat_TestCode
FROM api_result
LEFT JOIN nat_testmap ON Nat_TestMapCode = api_ResultTestCode
LEFT JOIN nat_test ON Nat_TestMapNat_TestID = Nat_TestID
WHERE `api_ResultNolab` = ? AND (`api_ResultTestName` LIKE CONCAT('%', ?, '%') OR api_ResultTestCode LIKE CONCAT('%', ?, '%'))
LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, [ $search, $test_name, $test_name,$number_limit, $number_offset]);
//echo $this->db->last_query();
//exit;
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select result error", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getlistlogapi()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$resultID = $prm["resultID"];
$sql = "SELECT log_ApiID,
log_ApiDate,
log_ApiM_BranchCode,
log_ApiEndpoint,
log_ApiParam,
log_ApiResponse,
log_ApiType,
log_ApiIsParsed
FROM cpone_log.log_api
JOIN api_result ON log_ApiID = api_ResultLog_ApiID
WHERE api_ResultID = ?";
$qry = $this->db->query($sql, [$resultID]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select log_api error", $this->db);
exit;
}
foreach ($rows as $key => $value) {
$rows[$key]["log_ApiParam"] = json_encode(json_decode($value["log_ApiParam"]), JSON_PRETTY_PRINT);
}
$result = array(
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}