459 lines
16 KiB
PHP
459 lines
16 KiB
PHP
<?php
|
|
class Mcunote extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function index()
|
|
{
|
|
// $cek = $this->db->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
echo "ADMIN MCU API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$search = "";
|
|
if (isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
} else {
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$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 one_etl.mcu_note_header
|
|
WHERE Mcu_Note_HeaderIsActive = 'Y'
|
|
AND (Mcu_Note_HeaderName LIKE ?)";
|
|
$qry_tot = $this->db->query($sql_tot, [$search]);
|
|
$last_qry = $this->db->last_query();
|
|
$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->db->trans_rollback();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error_db("mcu header note count error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Mcu_Note_HeaderID as id,
|
|
Mcu_Note_HeaderCode as code,
|
|
Mcu_Note_HeaderName as name,
|
|
Mcu_Note_HeaderNote as note
|
|
FROM one_etl.mcu_note_header
|
|
WHERE Mcu_Note_HeaderIsActive = 'Y'
|
|
AND (Mcu_Note_HeaderName LIKE ?)
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db->query($sql, [$search, $number_limit, $number_offset]);;
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error_db("mcu header note select error", $this->db);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"total_page" => $tot_page,
|
|
"total" => $tot_count,
|
|
"records" => $rows,
|
|
"last_qry" => $last_qry
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function addnewheader()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$code = $prm['code'];
|
|
$name = $prm['name'];
|
|
$note = $prm['note'];
|
|
|
|
if ($prm['xid'] == 0) {
|
|
$sql = "INSERT INTO one_etl.mcu_note_header(
|
|
Mcu_Note_HeaderCode,
|
|
Mcu_Note_HeaderName,
|
|
Mcu_Note_HeaderNote,
|
|
Mcu_Note_HeaderIsActive,
|
|
Mcu_Note_HeaderLastUpdated) VALUES(?,?,?,'Y',NOW())";
|
|
$qry = $this->db->query($sql, array(
|
|
$code,
|
|
$name,
|
|
$note
|
|
));
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("mcu header note insert", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$rst = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($rst);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function updateheadernote()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$code = $prm['code'];
|
|
$name = $prm['name'];
|
|
$note = $prm['note'];
|
|
|
|
if ($prm['xid'] != 0) {
|
|
$sql = "UPDATE one_etl.mcu_note_header SET
|
|
Mcu_Note_HeaderCode = ?,
|
|
Mcu_Note_HeaderName = ?,
|
|
Mcu_Note_HeaderNote = ?,
|
|
Mcu_Note_HeaderLastUpdated = NOW()
|
|
WHERE Mcu_Note_HeaderID = ?";
|
|
$qry = $this->db->query($sql, array(
|
|
$code,
|
|
$name,
|
|
$note,
|
|
$prm['xid']
|
|
));
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("mcu header note update", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$rst = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($rst);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function deleteheadernote()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$sql = "UPDATE one_etl.mcu_note_header SET
|
|
Mcu_Note_HeaderIsActive = 'N',
|
|
Mcu_Note_HeaderLastUpdated = NOW()
|
|
WHERE Mcu_Note_HeaderID = ?";
|
|
$qry = $this->db->query($sql, array(
|
|
$prm['id']
|
|
));
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("header note delete");
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function searchdetail()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$search = "";
|
|
if (isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
} else {
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 15;
|
|
|
|
if ($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$headerId = $prm["headerId"];
|
|
|
|
if ($headerId != 0) {
|
|
$filter = " AND Mcu_Note_DetailMcu_Note_HeaderID = {$headerId}";
|
|
}
|
|
|
|
$sql_total = "SELECT count(*) as total FROM one_etl.mcu_note_detail
|
|
JOIN nat_test ON Mcu_Note_DetailNat_TestID = Nat_TestID
|
|
AND Nat_TestIsActive = 'Y'
|
|
WHERE Mcu_Note_DetailIsActive = 'Y'
|
|
$filter
|
|
AND (Nat_TestCode LIKE ? OR Nat_TestShortName LIKE ?)";
|
|
$qry_total = $this->db->query($sql_total, [$search, $search]);
|
|
$last_qry = $this->db->last_query();
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry_total) {
|
|
$tot_count = $qry_total->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error_db("mcu detail note count error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Mcu_Note_DetailID as detailId,
|
|
Mcu_Note_DetailMcu_Note_HeaderID as headerId,
|
|
Mcu_Note_DetailNat_TestID as testId,
|
|
Nat_TestCode as testCode,
|
|
Nat_TestShortName as testName
|
|
FROM one_etl.mcu_note_detail
|
|
JOIN nat_test ON Mcu_Note_DetailNat_TestID = Nat_TestID
|
|
AND Nat_TestIsActive = 'Y'
|
|
WHERE Mcu_Note_DetailIsActive = 'Y'
|
|
$filter
|
|
AND (Nat_TestCode LIKE ? OR Nat_TestShortName LIKE ?)
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db->query($sql, [$search, $search, $number_limit, $number_offset]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error_db("mcu note detail select error", $this->db);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$result = [
|
|
"total_page" => $tot_page,
|
|
"total" => $tot_count,
|
|
"records" => $rows,
|
|
"last_qry" => $last_qry
|
|
];
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_test_multiple()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$search = "";
|
|
if (isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
} else {
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$sql_filter = "SELECT count(*) as total
|
|
FROM nat_test
|
|
WHERE Nat_TestIsActive = 'Y'
|
|
AND Nat_TestIsPrice = 'Y'
|
|
AND Nat_TestID NOT IN (SELECT Mcu_Note_DetailNat_TestID FROM one_etl.mcu_note_detail
|
|
WHERE Mcu_Note_DetailMcu_Note_HeaderID = {$prm['headerId']} AND Mcu_Note_DetailIsActive = 'Y')";
|
|
$qry_filter = $this->db->query($sql_filter);
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("nat test count");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Nat_TestID as testId,
|
|
Nat_TestCode as testCode,
|
|
Nat_TestShortName as testName
|
|
FROM nat_test
|
|
WHERE Nat_TestIsActive = 'Y'
|
|
AND Nat_TestIsPrice = 'Y'
|
|
AND Nat_TestID NOT IN (SELECT Mcu_Note_DetailNat_TestID FROM one_etl.mcu_note_detail
|
|
WHERE Mcu_Note_DetailMcu_Note_HeaderID = {$prm['headerId']} AND Mcu_Note_DetailIsActive = 'Y')";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("test select error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_count,
|
|
"total_display" => sizeof($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function addnewdetail()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$headerId = $prm["headerId"];
|
|
$selectedTestId = $prm["selectedTestId"];
|
|
|
|
if ($headerId == 0) {
|
|
$errors = array();
|
|
if ($headerId == 0) {
|
|
array_push($errors, array('field' => 'note detail', 'msg' => 'Anda belum memilih catatan header'));
|
|
}
|
|
$result = array("total" => -1, "errors" => $errors, "records" => 0);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
foreach ($selectedTestId as $key => $value) {
|
|
$sql = "INSERT INTO one_etl.mcu_note_detail(
|
|
Mcu_Note_DetailMcu_Note_HeaderID,
|
|
Mcu_Note_DetailNat_TestID,
|
|
Mcu_Note_DetailIsActive,
|
|
Mcu_Note_DetailLastUpdated) VALUES(?,?,'Y',NOW())";
|
|
$qry = $this->db->query($sql, array(
|
|
$headerId,
|
|
$value,
|
|
));
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$rst = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($rst);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function deletedetailnote()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$sql = "UPDATE one_etl.mcu_note_detail SET
|
|
Mcu_Note_DetailIsActive = 'N',
|
|
Mcu_Note_DetailLastUpdated = NOW()
|
|
WHERE Mcu_Note_DetailID = ?";
|
|
$qry = $this->db->query($sql, array(
|
|
$prm['id']
|
|
));
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("detail note delete");
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|