Batch 6a: application controllers base
This commit is contained in:
206
application/controllers/training/Worklisttest.php
Normal file
206
application/controllers/training/Worklisttest.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
class Worklisttest extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "API WORKLIST TEST";
|
||||
}
|
||||
|
||||
function lookup()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = "";
|
||||
if(isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
}else{
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sortBy = $prm["sortBy"];
|
||||
$sortStatus = $prm["sortStatus"];
|
||||
if($sortBy){
|
||||
$q_sort = "ORDER BY ".$sortBy." ".$sortStatus;
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT
|
||||
COUNT(DISTINCT T_WorklistID,
|
||||
T_WorklistName,
|
||||
T_TestID,
|
||||
T_TestSasCode,
|
||||
test_parent,
|
||||
T_TestName) as total
|
||||
|
||||
FROM (SELECT T_TestName as test_parent, T_TestSasCode as sascode
|
||||
FROM nat_test
|
||||
JOIN t_test ON T_TestNat_TestID = Nat_TestID AND T_TestIsActive = 'Y'
|
||||
WHERE
|
||||
Nat_TestIsActive = 'Y' AND
|
||||
Nat_TestIsPrice = 'Y' AND
|
||||
Nat_TestNat_TestTypeID = 4) a
|
||||
JOIN t_test ON T_TestSasCode like concat(sascode,'%') AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'
|
||||
JOIN t_worklistdetailv2 ON T_WorklistDetailNat_TestID = T_TestNat_TestID AND T_WorklistDetailIsActive = 'Y'
|
||||
JOIN t_worklist ON T_WorklistID = T_WorklistDetailT_WorklistID AND T_WorklistIsActive = 'Y' AND T_WorklistIsRujukan = 'Y'
|
||||
LEFT JOIN t_price_rujukan ON T_TestID = T_PriceRujukanT_TestID AND T_PriceRujukanIsActive = 'Y'
|
||||
WHERE T_WorklistName like ? OR test_parent like ? OR T_TestName like ?";
|
||||
|
||||
$qry_filter = $this->db->query($sql_filter, [$search, $search, $search]);
|
||||
// $last_qry = $this->db->last_query();
|
||||
// print_r($last_qry);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
}else{
|
||||
$this->sys_error_db("worklist select count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
T_WorklistID as worklistId,
|
||||
T_WorklistName,
|
||||
T_TestID as testId,
|
||||
T_TestSasCode,
|
||||
test_parent,
|
||||
T_TestName,
|
||||
T_PriceRujukanAmount as amount
|
||||
|
||||
FROM (SELECT T_TestName as test_parent, T_TestSasCode as sascode
|
||||
FROM nat_test
|
||||
JOIN t_test ON T_TestNat_TestID = Nat_TestID AND T_TestIsActive = 'Y'
|
||||
WHERE
|
||||
Nat_TestIsActive = 'Y' AND
|
||||
Nat_TestIsPrice = 'Y' AND
|
||||
Nat_TestNat_TestTypeID = 4) a
|
||||
JOIN t_test ON T_TestSasCode like concat(sascode,'%') AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'
|
||||
JOIN t_worklistdetailv2 ON T_WorklistDetailNat_TestID = T_TestNat_TestID AND T_WorklistDetailIsActive = 'Y'
|
||||
JOIN t_worklist ON T_WorklistID = T_WorklistDetailT_WorklistID AND T_WorklistIsActive = 'Y' AND T_WorklistIsRujukan = 'Y'
|
||||
LEFT JOIN t_price_rujukan ON T_TestID = T_PriceRujukanT_TestID AND T_PriceRujukanIsActive = 'Y'
|
||||
WHERE T_WorklistName like ? OR test_parent like ? OR T_TestName like ? $q_sort
|
||||
limit ? offset ?";
|
||||
|
||||
$qry = $this->db->query($sql, [$search, $search, $search, $number_limit, $number_offset]);
|
||||
// $last_qry = $this->db->last_query();
|
||||
// print_r($last_qry);
|
||||
if($qry) {
|
||||
$rows = $qry->result_array();
|
||||
}else{
|
||||
$this->sys_error_db("worklist select", $this->db);
|
||||
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 saveeditamount()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$testid = $prm["testid"];
|
||||
$worklistid = $prm["worklistid"];
|
||||
$amount = 0;
|
||||
if (isset($prm['amount'])) {
|
||||
$amount = trim($prm["amount"]);
|
||||
}
|
||||
// cari test id
|
||||
$sql_search = "SELECT T_PriceRujukanID as priceId, T_PriceRujukanT_TestID as testId
|
||||
FROM t_price_rujukan
|
||||
WHERE T_PriceRujukanIsActive = 'Y'
|
||||
AND T_PriceRujukanT_TestID = ?";
|
||||
$qry_search = $this->db->query($sql_search, array($testid));
|
||||
if($qry_search){
|
||||
$rows = $qry_search->result_array();
|
||||
}else{
|
||||
$this->sys_error_db("price rujukan select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
// sudah ada
|
||||
// print_r($rows);
|
||||
$testidarray = $rows[0]["testId"];
|
||||
$sql_update = "UPDATE t_price_rujukan SET
|
||||
T_PriceRujukanAmount = ?,
|
||||
T_PriceRujukanUserID = ?,
|
||||
T_PriceRujukanCreated = NOW(),
|
||||
T_PriceRujukanLastUpdated = NOW()
|
||||
WHERE T_PriceRujukanT_TestID = ?";
|
||||
$qry_update = $this->db->query($sql_update, array($amount, $userid, $testidarray));
|
||||
if(!$qry_update) {
|
||||
$this->sys_error_db("price rujukan update", $this->db);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
// belum ada
|
||||
$sql = "INSERT INTO t_price_rujukan(
|
||||
T_PriceRujukanT_TestID,
|
||||
T_PriceRujukanT_WorklistID,
|
||||
T_PriceRujukanAmount,
|
||||
T_PriceRujukanUserID,
|
||||
T_PriceRujukanCreated,
|
||||
T_PriceRujukanLastUpdated) VALUES(?, ?, ?, ?, NOW(), NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$testid,
|
||||
$worklistid,
|
||||
$amount,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if(!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("price rujukan insert", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"inserted_id" => $this->db->insert_id()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user