Batch 6a: application controllers base
This commit is contained in:
486
application/controllers/cpone/masterdata/Nonlabtemplate.php
Normal file
486
application/controllers/cpone/masterdata/Nonlabtemplate.php
Normal file
@@ -0,0 +1,486 @@
|
||||
<?php
|
||||
class Nonlabtemplate extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "NON LAN TEMPLATE API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
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 = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$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 nonlab_template
|
||||
WHERE NonlabTemplateIsActive = 'Y'
|
||||
AND (NonlabTemplateName LIKE ?)";
|
||||
$qry_tot = $this->db->query($sql_tot, [$search]);
|
||||
$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("nonlab template count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
NonlabTemplateID,
|
||||
NonlabTemplateName,
|
||||
NonlabTemplateFlagOther,
|
||||
NonlabTemplateIsActive,
|
||||
NonlabTemplateCreated,
|
||||
NonlabTemplateLastUpdated
|
||||
FROM nonlab_template
|
||||
WHERE NonlabTemplateIsActive = 'Y'
|
||||
AND (NonlabTemplateName LIKE ?)
|
||||
ORDER BY NonlabTemplateID ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [$search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select nonlab template", $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 addnonlab()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$isfisik = "";
|
||||
if (isset($prm["isfisik"])) {
|
||||
$isfisik = trim($prm["isfisik"]);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO nonlab_template(
|
||||
NonlabTemplateName,
|
||||
NonlabTemplateFlagOther,
|
||||
NonlabTemplateCreated,
|
||||
NonlabTemplateCreatedUserID,
|
||||
NonlabTemplateLastUpdated,
|
||||
NonlabTemplateLastUpdatedUserID
|
||||
) VALUES(?,?,NOW(),?,NOW(),?)";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$name,
|
||||
$isfisik,
|
||||
$userid,
|
||||
$userid
|
||||
));
|
||||
$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();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function editnonlab()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$isfisik = "";
|
||||
if (isset($prm["isfisik"])) {
|
||||
$isfisik = trim($prm["isfisik"]);
|
||||
}
|
||||
$id = "";
|
||||
if (isset($prm["id"])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
|
||||
$sql = "UPDATE nonlab_template
|
||||
SET NonlabTemplateName = ?,
|
||||
NonlabTemplateFlagOther = ?,
|
||||
NonlabTemplateLastUpdated = NOW(),
|
||||
NonlabTemplateLastUpdatedUserID = ?
|
||||
WHERE NonlabTemplateID = ?";
|
||||
$qry = $this->db->query($sql, array($name, $isfisik, $userid, $id));
|
||||
$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();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletenonlab()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$id = "";
|
||||
if (isset($prm["id"])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
|
||||
$sql = "UPDATE nonlab_template
|
||||
SET NonlabTemplateIsActive = 'N',
|
||||
NonlabTemplateDelete = NOW(),
|
||||
NonlabTemplateDeleteUserID = ?
|
||||
WHERE NonlabTemplateID = ?";
|
||||
$qry = $this->db->query($sql, array($userid, $id));
|
||||
$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();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$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;
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$nonlabID = $prm["nonlabID"];
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_total = "SELECT COUNT(*) as total
|
||||
FROM nonlab_template_detail
|
||||
WHERE NonlabTemplateDetailNonlabTemplateID = ?
|
||||
AND NonlabTemplateDetailIsActive = 'Y'
|
||||
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)";
|
||||
$qry_total = $this->db->query($sql_total, [$nonlabID, $search, $search]);
|
||||
$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->sys_error_db("nonlab template detail count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
NonlabTemplateDetailID,
|
||||
NonlabTemplateDetailNonlabTemplateID,
|
||||
NonlabTemplateDetailCode,
|
||||
NonlabTemplateDetailName,
|
||||
NonlabTemplateDetaiNat_UnitID,
|
||||
NonlabTemplateDetailFlagActive,
|
||||
NonlabTemplateDetaiM_LangID,
|
||||
NonlabTemplateDetailIsActive
|
||||
FROM nonlab_template_detail
|
||||
WHERE NonlabTemplateDetailNonlabTemplateID = ?
|
||||
AND NonlabTemplateDetailIsActive = 'Y'
|
||||
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)
|
||||
limit ? offset ?";
|
||||
$qry = $this->db->query($sql, [$nonlabID, $search, $search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select nonlab template detail", $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 adddetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$code = "";
|
||||
if (isset($prm["code"])) {
|
||||
$code = trim($prm["code"]);
|
||||
}
|
||||
$nonlabid = "";
|
||||
if (isset($prm["nonlabid"])) {
|
||||
$nonlabid = trim($prm["nonlabid"]);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO nonlab_template_detail(
|
||||
NonlabTemplateDetailNonlabTemplateID,
|
||||
NonlabTemplateDetailCode,
|
||||
NonlabTemplateDetailName,
|
||||
NonlabTemplateDetailCreated,
|
||||
NonlabTemplateDetailCreatedUserID,
|
||||
NonlabTemplateDetailLastUpdated,
|
||||
NonlabTemplateDetailLastUpdatedUserID
|
||||
) VALUES(?,?,?,NOW(),?,NOW(),?)";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$nonlabid,
|
||||
$code,
|
||||
$name,
|
||||
$userid,
|
||||
$userid
|
||||
));
|
||||
$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();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletedetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$id = "";
|
||||
if (isset($prm["id"])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
|
||||
$sql = "UPDATE nonlab_template_detail
|
||||
SET NonlabTemplateDetailIsActive = 'N',
|
||||
NonlabTemplateDetailDelete = NOW(),
|
||||
NonlabTemplateDetailDeleteUserID = ?
|
||||
WHERE NonlabTemplateDetailID = ?";
|
||||
$qry = $this->db->query($sql, array($userid, $id));
|
||||
$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();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveeditflag()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$flagstatus = $prm['flagstatus'];
|
||||
$templatedetailid = $prm['templatedetailid'];
|
||||
|
||||
if ($flagstatus == "Y") {
|
||||
$sql = "UPDATE nonlab_template_detail
|
||||
SET NonlabTemplateDetailFlagActive = 'Y',
|
||||
NonlabTemplateDetailLastUpdated = NOW(),
|
||||
NonlabTemplateDetailLastUpdatedUserID = ?
|
||||
WHERE NonlabTemplateDetailID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$userid,
|
||||
$templatedetailid
|
||||
));
|
||||
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("nonlab template detail avtive", $this->db);
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$sql = "UPDATE nonlab_template_detail
|
||||
SET NonlabTemplateDetailFlagActive = 'N',
|
||||
NonlabTemplateDetailLastUpdated = NOW(),
|
||||
NonlabTemplateDetailLastUpdatedUserID = ?
|
||||
WHERE NonlabTemplateDetailID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$userid,
|
||||
$templatedetailid
|
||||
));
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("nonlab template detail no avtive", $this->db);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user