Files
BE_IBL/application/controllers/mockup/masterdata/so_template/Sotemplate.php
2026-04-15 15:24:12 +07:00

679 lines
18 KiB
PHP

<?php
class Sotemplate extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SO TEMPLATE API";
}
public function __construct()
{
parent::__construct();
//$this->db_onedev = $this->load->database("one", true);
}
function lookuptest(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select So_TestTemplateID as id, T_TestShortName as name, So_TestTemplateT_TestID as testid
from so_testtemplate
JOIN t_test ON So_TestTemplateT_TestID = T_TestID AND T_TestIsActive = 'Y'
where
So_TestTemplateSo_TemplateID = {$id} AND So_TestTemplateIsActive = 'Y'";
$sql_param = array($orderid);
$query = $this->db_onedev->query($sql,$sql_param);
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("so_testtemplate select by sotemplate");
exit;
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookupdetail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select So_TemplateDetailID as id,
So_TemplateDetailSo_TemplateID as sotemplateid,
So_TemplateDetailM_LangID,
M_LangID,
M_LangName,
So_TemplateDetailName as name,
So_TemplateDetailUnit as unit,
So_TemplateDetailPriority as xorder,
'xxx' as action
from so_templatedetail
JOIN m_lang ON So_TemplateDetailM_LangID = M_LangID
where
So_TemplateDetailSo_TemplateID = {$id} AND So_TemplateDetailIsActive = 'Y'
ORDER BY So_TemplateDetailPriority ASC";
$sql_param = array($orderid);
$query = $this->db_onedev->query($sql,$sql_param);
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("so_testtemplatedetail select by sotemplate");
exit;
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function lookup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$search_test = $prm['search_test'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
if($search_test == ''){
$sql = "SELECT COUNT(*) as total
FROM
(
select So_TemplateID
from so_template
where
So_TemplateName LIKE CONCAT('%','{$search}','%') AND
So_TemplateIsActive = 'Y'
GROUP BY So_TemplateID
) x";
}
else{
$sql = "SELECT COUNT(*) as total
FROM
(
select So_TemplateID
from so_template
JOIN so_testtemplate ON So_TestTemplateSo_TemplateID = So_TemplateID
JOIN t_test ON So_TestTemplateT_TestID = T_TestID
AND T_TestName LIKE CONCAT('%','{$search_test}','%')
where
So_TemplateName LIKE CONCAT('%','{$search}','%') AND So_TemplateIsActive = 'Y'
GROUP BY So_TemplateID
) x";
}
//echo $sql;
$total = $this->db_onedev->query($sql)->row()->total;
if($search_test == ''){
$sql = "select So_TemplateID as id,
So_TemplateName as name,
So_TemplateName as detail,
'xxx' as sotemplatetests, 'xxx' as sotemplatedetail
from so_template
where
So_TemplateName LIKE CONCAT('%','{$search}','%') AND
So_TemplateIsActive = 'Y'
GROUP BY So_TemplateID
$limit";
//$sql_param = array($search);
$query = $this->db_onedev->query($sql);
}
else{
$sql = "select So_TemplateID as id,
So_TemplateName as name,
So_TemplateName as detail,
'xxx' as sotemplatetests, 'xxx' as sotemplatedetail
from so_template
JOIN so_testtemplate ON So_TestTemplateSo_TemplateID = So_TemplateID AND So_TestTemplateIsActive = 'Y'
JOIN t_test ON So_TestTemplateT_TestID = T_TestID AND T_TestIsActive = 'Y'
AND T_TestName LIKE CONCAT('%','{$search_test}','%')
WHERE
So_TemplateName LIKE CONCAT('%','{$search}','%') AND So_TemplateIsActive = 'Y'
GROUP BY So_TemplateID
$limit";
//$sql_param = array($search_test);
$query = $this->db_onedev->query($sql);
}
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("so_template select");
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewsotemplate()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name_sotemplate = $prm['name'];
$query = "SELECT COUNT(*) as exist FROM so_template WHERE So_TemplateIsActive = 'Y' AND So_TemplateName = '{$name_sotemplate}'";
$exist_name = $this->db_onedev->query($query)->row()->exist;
/*if($exist_name == 0){
$sql = "insert into so_template(
So_TemplateName,
So_TemplateCreated,
So_TemplateLastUpdated
)
values( ?, now(),now())";
$query = $this->db_onedev->query($sql,
array(
$name_sotemplate
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("so_template insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
*/
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editsotemplate()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id_sotemplate = $prm['id'];
$name_sotemplate = $prm['name'];
$query = "SELECT COUNT(*) as exist FROM so_template WHERE So_TemplateIsActive = 'Y' AND So_TemplateName = '{$name_sotemplate}' AND So_TemplateID <> {$id_sotemplate}";
$exist_name = $this->db_onedev->query($query)->row()->exist;
/*if($exist_name == 0){
$sql = "update so_template SET
So_TemplateName = ?,
So_TemplateLastUpdated = now()
where
So_TemplateID = ?
";
$query = $this->db_onedev->query($sql,
array(
$name_sotemplate,
$id_sotemplate
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("so_template update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id_sotemplate));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}*/
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewsotemplatetest()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sotemplateid = $prm['sotemplateid'];
$testid = $prm['testid'];
/*$sql = "insert into so_testtemplate(
So_TestTemplateSo_TemplateID,
So_TestTemplateT_TestID,
So_TestTemplateCreated,
So_TestTemplateLastUpdated,
So_TestTemplateUserID
)
values( ?,?,now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$sotemplateid,
$testid,
$userid
)
);
//echo $query;
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("so_testtemplate insert");
exit;
} */
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewsotemplatedetail()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
/*if($prm['xid'] == "0" || $prm['xid'] == 0){
$sql = "insert into so_templatedetail(
So_TemplateDetailSo_TemplateID,
So_TemplateDetailM_LangID,
So_TemplateDetailName,
So_TemplateDetailUnit,
So_TemplateDetailPriority,
So_TemplateDetailCreated,
So_TemplateDetailLastUpdate
)
values( ?,?,?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$prm['sotemplateid'],
$prm['langid'],
$prm['name'],
$prm['unit'],
$prm['order']
)
);
if (!$query) {
$this->sys_error_db("so_templatedetail insert");
exit;
}
//echo $this->db_onedev->last_query();
}
else{
$sql = "update so_templatedetail SET
So_TemplateDetailM_LangID = ?,
So_TemplateDetailName = ?,
So_TemplateDetailUnit = ?,
So_TemplateDetailPriority = ?,
So_TemplateDetailLastUpdate = now()
WHERE
So_TemplateDetailID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['langid'],
$prm['name'],
$prm['unit'],
$prm['order'],
$prm['xid']
)
);
if (!$query) {
$this->sys_error_db("so_templatedetail update");
exit;
}
}
*/
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletesotemplatedetail()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
/*
$sql = "update so_templatedetail SET
So_TemplateDetailIsActive = 'N',
So_TemplateDetailLastUpdate = now()
WHERE
So_TemplateDetailID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("so_templatedetail delete");
exit;
}
*/
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletesotemplatetest()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
/*
$sql = "update so_testtemplate SET
So_TestTemplateIsActive = 'N',
So_TestTemplateLastUpdated = now()
WHERE
So_TestTemplateID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("so_testtemplate delete");
exit;
}
*/
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletesotemplate()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
/*
$sql = "update so_template SET
So_TemplateIsActive = 'N',
So_TemplateLastUpdated = now()
WHERE
So_TemplateID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("so_template delete");
exit;
}
$sql = "update so_testtemplate SET
So_TestTemplateIsActive = 'N',
So_TestTemplateLastUpdated = now()
WHERE
So_TestTemplateSo_TemplateID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("so_testtemplate delete");
exit;
}
$sql = "update so_templatedetail SET
So_TemplateDetailIsActive = 'N',
So_TemplateDetailLastUpdate = now()
WHERE
So_TemplateDetailSo_TemplateID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("so_templatedetail delete");
exit;
}
*/
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function searchtest()
{
$prm = $this->sys_input;
$sotemplateid = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
LEFT JOIN so_testtemplate ON So_TestTemplateT_TestID = T_TestID AND So_TestTemplateSo_TemplateID = ? AND So_TestTemplateIsActive = 'Y'
WHERE
ISNULL(So_TestTemplateID) AND
T_TestIsActive = 'Y'
AND T_TestName like ?";
$query = $this->db_onedev->query($sql,array($sotemplateid,$q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_test count",$this->db_onedev);
exit;
}
$sql = "
SELECT T_TestID as id,
T_TestName as name
FROM t_test
JOIN nat_test ON T_TestNat_TestID = Nat_TestID AND Nat_TestNat_GroupID IN (2,3,4)
LEFT JOIN so_testtemplate ON So_TestTemplateT_TestID = T_TestID AND So_TestTemplateSo_TemplateID = ? AND So_TestTemplateIsActive = 'Y'
WHERE
ISNULL(So_TestTemplateID) AND
T_TestIsActive = 'Y'
AND T_TestName like ?
ORDER BY T_TestCode ASC
";
$query = $this->db_onedev->query($sql, array($sotemplateid,$q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_test rows",$this->db_onedev);
exit;
}
}
function selectlang(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_lang
WHERE
M_LangIsActive = 'Y'
";
//echo $query;
$rows['langs'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}