Initial import
This commit is contained in:
614
one-api/application/controllers/mockup/masterdata/Sotemplate.php
Normal file
614
one-api/application/controllers/mockup/masterdata/Sotemplate.php
Normal file
@@ -0,0 +1,614 @@
|
||||
<?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("onedev", 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,
|
||||
'xxx' as action
|
||||
from so_templatedetail
|
||||
JOIN m_lang ON So_TemplateDetailM_LangID = M_LangID
|
||||
where
|
||||
So_TemplateDetailSo_TemplateID = {$id} AND So_TemplateDetailIsActive = '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_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'];
|
||||
$all = $prm['all'];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$sql = "select COUNT(*) as total
|
||||
from so_template
|
||||
where
|
||||
So_TemplateIsActive = 'Y'";
|
||||
$sql_param = array($search);
|
||||
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||
|
||||
|
||||
$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('%',?,'%') AND
|
||||
So_TemplateIsActive = 'Y' $limit";
|
||||
$sql_param = array($search);
|
||||
$query = $this->db_onedev->query($sql,$sql_param);
|
||||
//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;
|
||||
$sotemplateid = $prm['sotemplateid'];
|
||||
$testid = $prm['testid'];
|
||||
|
||||
$sql = "insert into so_testtemplate(
|
||||
So_TestTemplateSo_TemplateID,
|
||||
So_TestTemplateT_TestID,
|
||||
So_TestTemplateCreated,
|
||||
So_TestTemplateLastUpdated
|
||||
)
|
||||
values( ?,?,now(),now())";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$sotemplateid,
|
||||
$testid
|
||||
)
|
||||
);
|
||||
//echo $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_TemplateDetailCreated,
|
||||
So_TemplateDetailLastUpdate
|
||||
)
|
||||
values( ?,?,?,now(),now())";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['sotemplateid'],
|
||||
$prm['langid'],
|
||||
$prm['name']
|
||||
)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("so_templatedetail insert");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$sql = "update so_templatedetail SET
|
||||
So_TemplateDetailM_LangID = ?,
|
||||
So_TemplateDetailName = ?,
|
||||
So_TemplateDetailLastUpdate = now()
|
||||
WHERE
|
||||
So_TemplateDetailID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['langid'],
|
||||
$prm['name'],
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user