Initial import
This commit is contained in:
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
|
||||
class Resultflagused extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
public function index()
|
||||
{
|
||||
echo "RESULT FLAG USED API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
function searchtest()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search_resulttest_name'] != '') {
|
||||
$q['search'] = "%{$prm['search_resulttest_name']}%";
|
||||
}
|
||||
|
||||
$sql = "SELECT Nat_TestID, Nat_TestName,Nat_TestCode FROM nat_test
|
||||
WHERE Nat_TestIsActive = 'Y'
|
||||
AND Nat_TestIsQuantitative= 'N'
|
||||
AND Nat_TestIsResult = 'Y'
|
||||
AND Nat_TestName LIKE ?
|
||||
LIMIT 20;";
|
||||
$query = $this->db_regional->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//echo $this->db_regional->last_query();
|
||||
$result = array("last_query" => $this->db_regional->last_query(), "records" => $rows);
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$this->sys_error_db("Test rows", $this->db_regional, array(
|
||||
"last_query" => $this->db_regional->last_query()
|
||||
));
|
||||
exit;
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchresultflag()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if (!empty($prm['search_resulttest_name'])) {
|
||||
$q['search'] = "%{$prm['search_resulttest_name']}%";
|
||||
}
|
||||
|
||||
$resultname = $prm["resultname"] ?? '';
|
||||
$resultflag = $prm["resultflag"] ?? '';
|
||||
|
||||
$number_limit = 10;
|
||||
$curr_page = max(1, (int) $prm["current_page"]);
|
||||
$number_offset = ($curr_page - 1) * $number_limit;
|
||||
|
||||
$params = [$q['search']];
|
||||
$rstflg = "";
|
||||
$rstname = "";
|
||||
|
||||
if (!empty($resultflag)) {
|
||||
$rstflg = "AND M_ResultFlagFlag = ?";
|
||||
$params[] = strtoupper($resultflag);
|
||||
}
|
||||
|
||||
if (!empty($resultname)) {
|
||||
$rstname = "AND M_ResultFlagResult LIKE ?";
|
||||
$params[] = "%{$resultname}%";
|
||||
}
|
||||
|
||||
// hitung total
|
||||
$sql_count = "SELECT COUNT(*) as total
|
||||
FROM m_resultflag
|
||||
JOIN nat_test ON M_ResultFlagNat_TestID = Nat_TestID
|
||||
WHERE Nat_TestIsActive = 'Y'
|
||||
AND M_ResultFlagIsActive = 'Y'
|
||||
AND Nat_TestName LIKE ?
|
||||
$rstflg
|
||||
$rstname";
|
||||
|
||||
$query = $this->db_regional->query($sql_count, $params);
|
||||
$tot_count = $query ? $query->row()->total : 0;
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
|
||||
// ambil data
|
||||
$sql = "SELECT *
|
||||
FROM m_resultflag
|
||||
JOIN nat_test ON M_ResultFlagNat_TestID = Nat_TestID
|
||||
WHERE Nat_TestIsActive = 'Y'
|
||||
AND M_ResultFlagIsActive = 'Y'
|
||||
AND Nat_TestName LIKE ?
|
||||
$rstflg
|
||||
$rstname
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$params_data = array_merge($params, [$number_limit, $number_offset]);
|
||||
$query = $this->db_regional->query($sql, $params_data);
|
||||
|
||||
$rows = $query ? $query->result_array() : [];
|
||||
|
||||
$result = [
|
||||
"last_query" => $this->db_regional->last_query(),
|
||||
"message" => $rows ? "Data Ditemukan" : "Data Tidak Ditemukan",
|
||||
"total" => $tot_count,
|
||||
"total_page" => $tot_page,
|
||||
"records" => $rows
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function addresultflag()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$this->db_regional->trans_begin();
|
||||
|
||||
$resulttest = $prm["nattestid"];
|
||||
$resultname = $prm["resultname"];
|
||||
$resultflag = $prm["resultflag"];
|
||||
$description = $prm["description"];
|
||||
|
||||
|
||||
$sql = "SELECT * FROM m_resultflag WHERE
|
||||
M_ResultFlagNat_TestID = ?
|
||||
AND M_ResultFlagResult = ?
|
||||
AND M_ResultFlagIsActive = 'Y';";
|
||||
$query = $this->db_regional->query($sql, [$resulttest, $resultname]);
|
||||
|
||||
$rows = $query->result_array();
|
||||
if ($rows) {
|
||||
$result = [
|
||||
"message" => "Data Sudah Pernah Dibuat",
|
||||
"last_query" => $this->db_regional->last_query(),
|
||||
];
|
||||
$data = $this->sys_ok($result);
|
||||
return $data;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO m_resultflag
|
||||
(`M_ResultFlagNat_TestID`,
|
||||
`M_ResultFlagResult`,
|
||||
`M_ResultFlagFlag`,
|
||||
`M_ResultFlagNote`,
|
||||
`M_ResultFlagIsActive`,
|
||||
`M_ResultFlagCreated`,
|
||||
`M_ResultFlagLasUpdated`,
|
||||
`M_ResultFlagCreatedUserID`
|
||||
)
|
||||
VALUES
|
||||
(?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
'Y',
|
||||
now(),
|
||||
now(),
|
||||
?);";
|
||||
$query = $this->db_regional->query($sql, [$resulttest, $resultname, $resultflag, $description, $userid]);
|
||||
|
||||
if (!$query) {
|
||||
//echo $this->db_regional->last_query();
|
||||
$this->db_regional->trans_rollback();
|
||||
$result = [
|
||||
"message" => "Data gagal disimpan",
|
||||
"last_query" => $this->db_regional->last_query(),
|
||||
];
|
||||
$this->sys_error_db( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array("last_query" => $this->db_regional->last_query(), "message" => "Berhasil Insert");
|
||||
$this->db_regional->trans_commit();
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteresultflag()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$this->db_regional->trans_begin();
|
||||
$resultid = $prm["resultid"];
|
||||
|
||||
|
||||
$sql = "SELECT * FROM m_resultflag
|
||||
WHERE M_ResultFlagID = ?
|
||||
AND M_ResultFlagIsActive= 'Y'";
|
||||
$query = $this->db_regional->query($sql, [$resultid]);
|
||||
|
||||
$rows = $query->result_array();
|
||||
if (!$rows) {
|
||||
$data = $this->sys_ok("Tidak Ada yang Didelete");
|
||||
return $data;
|
||||
}
|
||||
|
||||
$row = $rows[0];
|
||||
|
||||
$message = [
|
||||
"Nat_ID" => $row['M_ResultFlagNat_TestID'],
|
||||
"Nama" => $row['M_ResultFlagResult'],
|
||||
"Flag" => $row['M_ResultFlagFlag']
|
||||
];
|
||||
|
||||
$sql = "UPDATE m_resultflag
|
||||
SET
|
||||
M_ResultFlagIsActive = 'N',
|
||||
M_ResultFlagLasUpdated = NOW(),
|
||||
M_ResultFlagLasUpdatedUserID = ?
|
||||
WHERE M_ResultFlagID = ?
|
||||
AND M_ResultFlagIsActive= 'Y'";
|
||||
$query = $this->db_regional->query($sql, [$userid, $resultid]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("Result Flag Delete | " . $this->db_regional->last_query());
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array("last_query" => $this->db_regional->last_query(), "message" => "Berhasil Delete");
|
||||
|
||||
$this->db_regional->trans_commit();
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updateresultflag()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$this->db_regional->trans_begin();
|
||||
$resultid = $prm["resultid"];
|
||||
$resulttest = $prm["nattestid"];
|
||||
$resultname = $prm["resultname"];
|
||||
$resultflag = $prm["resultflag"];
|
||||
|
||||
|
||||
$sql = "SELECT * FROM m_resultflag
|
||||
WHERE M_ResultFlagID = ?
|
||||
AND M_ResultFlagIsActive= 'Y'";
|
||||
$query = $this->db_regional->query($sql, [$resultid]);
|
||||
|
||||
$rows = $query->result_array();
|
||||
if (!$rows) {
|
||||
$data = $this->sys_ok("Tidak Ada yang Didelete");
|
||||
return $data;
|
||||
}
|
||||
|
||||
$row = $rows[0];
|
||||
|
||||
$message = [
|
||||
"Nat_ID" => $row['M_ResultFlagNat_TestID'],
|
||||
"Nama" => $row['M_ResultFlagResult'],
|
||||
"Flag" => $row['M_ResultFlagFlag']
|
||||
];
|
||||
|
||||
$sql = "UPDATE m_resultflag
|
||||
SET
|
||||
M_ResultFlagNat_TestID = ?,
|
||||
M_ResultFlagResult = ?,
|
||||
M_ResultFlagFlag = ?,
|
||||
M_ResultFlagLasUpdated = NOW()
|
||||
WHERE M_ResultFlagID = ?
|
||||
AND M_ResultFlagIsActive= 'Y'";
|
||||
$query = $this->db_regional->query($sql, [$resulttest,$resultname,$resultflag,$resultid]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$result = [
|
||||
"message" => "Data Gagal Diupdate",
|
||||
"last_query" => $this->db_regional->last_query(),
|
||||
];
|
||||
$this->sys_error_db($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array("last_query" => $this->db_regional->last_query(), "message" => "Berhasil Update");
|
||||
|
||||
$this->db_regional->trans_commit();
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user