1034 lines
32 KiB
PHP
1034 lines
32 KiB
PHP
<?php
|
|
|
|
class Sigma extends MY_Controller
|
|
{
|
|
var $db_regional;
|
|
public function index()
|
|
{
|
|
echo "BRANCH API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_regional = $this->load->database("onedev", true);
|
|
}
|
|
|
|
function lookupbranchbyname(){
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$regional = $prm['regional'];
|
|
$branch = $prm['branch'];;
|
|
$all = $prm['all'];
|
|
$limit = '';
|
|
if($all == 'N'){
|
|
$limit = ' LIMIT 10';
|
|
}
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
$sql = "select COUNT(*) as total
|
|
FROM(SELECT *
|
|
from nat_sigmadetail
|
|
JOIN nat_sigma ON Nat_SigmaDetailNat_SigmaID = Nat_SigmaID AND Nat_SigmaIsActive = 'Y'
|
|
LEFT JOIN nat_qc_rule ON Nat_SigmaDetailNat_QcRuleID = Nat_QcRuleID
|
|
WHERE
|
|
Nat_SigmaName LIKE CONCAT('%','{$regional}','%') AND
|
|
Nat_QcRuleCode LIKE CONCAT('%','{$branch}','%') AND
|
|
Nat_SigmaDetailIsActive = 'Y' GROUP BY Nat_SigmaDetailID) a";
|
|
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
|
|
$query = $this->db_regional->query($sql);
|
|
//echo $this->db_regional->last_query();
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("nat_sigmadetail count", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select Nat_SigmaDetailID as id,
|
|
Nat_SigmaName as name,
|
|
Nat_SigmaTotalControl as kontrol,
|
|
Nat_SigmaTotalFrequency as frekuensi,
|
|
Nat_SigmaMin as min,
|
|
Nat_SigmaMax as max,
|
|
Nat_SigmaID,
|
|
Nat_SigmaName,
|
|
Nat_QcRuleID,
|
|
Nat_QcRuleCode,
|
|
nat_sigmadetail.*
|
|
from nat_sigmadetail
|
|
JOIN nat_sigma ON Nat_SigmaDetailNat_SigmaID = Nat_SigmaID AND Nat_SigmaIsActive = 'Y'
|
|
LEFT JOIN nat_qc_rule ON Nat_SigmaDetailNat_QcRuleID = Nat_QcRuleID
|
|
WHERE
|
|
Nat_SigmaName LIKE CONCAT('%','{$regional}','%') AND
|
|
Nat_QcRuleCode LIKE CONCAT('%','{$branch}','%') AND
|
|
Nat_SigmaDetailIsActive = 'Y'
|
|
GROUP BY Nat_SigmaDetailID
|
|
ORDER BY Nat_SigmaName ASC, Nat_QcRuleCode ASC
|
|
limit $number_limit offset $number_offset";
|
|
$sql_param = array($search);
|
|
$query = $this->db_regional->query($sql);
|
|
//echo $this->db_regional->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
|
|
} else {
|
|
$this->sys_error_db("nat_sigmadetail select");
|
|
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);
|
|
}
|
|
}
|
|
public function lookupregionalbyname()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$regional = $prm['regional'];
|
|
$branch = $prm['branch'];
|
|
$limit = '';
|
|
if($all == 'N'){
|
|
$limit = ' LIMIT 10';
|
|
}
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
$sql = "select COUNT(*) as total
|
|
FROM(SELECT *
|
|
from nat_sigma
|
|
LEFT JOIN nat_sigmadetail ON Nat_SigmaID = Nat_SigmaDetailNat_SigmaID AND Nat_SigmaDetailIsActive = 'Y'
|
|
LEFT JOIN nat_qc_rule ON Nat_SigmaDetailNat_QcRuleID = Nat_QcRuleID
|
|
where
|
|
Nat_SigmaName LIKE CONCAT('%','{$regional}','%') AND
|
|
IFNULL(Nat_QcRuleCode,'') LIKE CONCAT('%','{$branch}','%') AND
|
|
Nat_SigmaIsActive = 'Y'
|
|
GROUP BY Nat_SigmaID) a";
|
|
$sql_param = array($search);
|
|
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
|
|
$query = $this->db_regional->query($sql);
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("nat_sigma count", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select IFNULL(Nat_SigmaID,0) as id,
|
|
Nat_SigmaName as name,
|
|
Nat_SigmaName as namex,
|
|
Nat_SigmaTotalControl as kontrol,
|
|
Nat_SigmaTotalFrequency as frekuensi,
|
|
Nat_SigmaMin as min,
|
|
Nat_SigmaMax as max,
|
|
nat_sigma.*,
|
|
'xxx' as rules,
|
|
IFNULL(GROUP_CONCAT(DISTINCT Nat_QcRuleCode ORDER BY Nat_QcRuleID ASC SEPARATOR ', '),'Belum Ada Rule') as Nat_QcRuleCode,
|
|
'' as action
|
|
from nat_sigma
|
|
LEFT JOIN nat_sigmadetail ON Nat_SigmaID = Nat_SigmaDetailNat_SigmaID AND Nat_SigmaDetailIsActive = 'Y'
|
|
LEFT JOIN nat_qc_rule ON Nat_SigmaDetailNat_QcRuleID = Nat_QcRuleID
|
|
where
|
|
Nat_SigmaName LIKE CONCAT('%','{$regional}','%') AND
|
|
IFNULL(Nat_QcRuleCode,'') LIKE CONCAT('%','{$branch}','%') AND
|
|
Nat_SigmaIsActive = 'Y'
|
|
GROUP BY Nat_SigmaID
|
|
ORDER BY Nat_SigmaName ASC
|
|
limit $number_limit offset $number_offset";
|
|
$sql_param = array($search);
|
|
$query = $this->db_regional->query($sql);
|
|
//echo $this->db_regional->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
|
|
foreach($rows as $k => $v){
|
|
$d = $v['id'];
|
|
$x = $this->db_regional->query("select concat( '[', group_concat( json_object('id',IFNULL(Nat_SigmaDetailID,Nat_QcRuleID), 'rulename', Nat_QcRuleCode,'status', IF(IFNULL(Nat_SigmaDetailID,0) = 0 , 'N','Y')) separator ',' ), ']' )
|
|
as n FROM
|
|
(SELECT Nat_SigmaDetailID,Nat_QcRuleID,Nat_QcRuleCode
|
|
FROM nat_qc_rule
|
|
JOIN nat_sigma ON Nat_SigmaID = $d
|
|
JOIN nat_sigmadetail ON Nat_SigmaDetailNat_SigmaID = Nat_SigmaID AND Nat_SigmaDetailNat_QcRuleID = Nat_QcRuleID AND Nat_SigmaDetailIsActive = 'Y'
|
|
WHERE Nat_QcRuleIsActive = 'Y'
|
|
GROUP BY Nat_QcRuleID) a")->row();
|
|
$rows[$k]['rulex'] = json_decode($x->n);
|
|
$rows[$k]['rules'] = $this->add_rule($d);
|
|
}
|
|
}
|
|
|
|
} else {
|
|
$this->sys_error_db("nat_sigma select");
|
|
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 add_rule($sigmaid){
|
|
$query =" SELECT nat_sigmadetail.*, nat_qc_rule.*,IF(Nat_SigmaDetailID IS NULL,'N','Y') as isrule, IFNULL(Nat_SigmaDetailID,0) as xid
|
|
FROM nat_qc_rule
|
|
LEFT JOIN nat_sigma ON Nat_SigmaID = $sigmaid
|
|
LEFT JOIN nat_sigmadetail ON Nat_SigmaDetailNat_QcRuleID = Nat_QcRuleID AND Nat_SigmaDetailNat_SigmaID = Nat_SigmaID AND Nat_SigmaDetailIsActive = 'Y'
|
|
WHERE Nat_QcRuleIsActive = 'Y'
|
|
GROUP BY Nat_QcRuleID";
|
|
//echo $query;
|
|
$rows = $this->db_regional->query($query)->result_array();
|
|
if(!$rows)
|
|
$rows = array();
|
|
return $rows;
|
|
}
|
|
function getrulex(){
|
|
$sql =" SELECT nat_sigmadetail.*, nat_qc_rule.*,IF(Nat_SigmaDetailID IS NULL,'N','Y') as isrule, IFNULL(Nat_SigmaDetailID,0) as xid
|
|
FROM nat_qc_rule
|
|
LEFT JOIN nat_sigma ON Nat_SigmaID = 0
|
|
LEFT JOIN nat_sigmadetail ON Nat_SigmaDetailNat_QcRuleID = Nat_QcRuleID AND Nat_SigmaDetailNat_SigmaID = Nat_SigmaID AND Nat_SigmaDetailIsActive = 'Y'
|
|
WHERE Nat_QcRuleIsActive = 'Y'
|
|
GROUP BY Nat_QcRuleID";
|
|
//echo $query;
|
|
$query = $this->db_regional->query($sql);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_regional->last_query();
|
|
$result = array("total" => 0, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_district rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
public function addnewregional()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$name = $prm['name'];
|
|
$kontrol = $prm['kontrol'];
|
|
$frekuensi = $prm['frekuensi'];
|
|
$min = $prm['min'];
|
|
$max = $prm['max'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "insert into nat_sigma(
|
|
Nat_SigmaName,
|
|
Nat_SigmaTotalControl,
|
|
Nat_SigmaTotalFrequency,
|
|
Nat_SigmaMin,
|
|
Nat_SigmaMax,
|
|
Nat_SigmaUserID,
|
|
Nat_SigmaCreated,
|
|
Nat_SigmaLastUpdated
|
|
)
|
|
values( ?, ?, ?, ?, ?, ?, now(), now())";
|
|
$query = $this->db_regional->query($sql,
|
|
array(
|
|
$name,
|
|
$kontrol,
|
|
$frekuensi,
|
|
$min,
|
|
$max,
|
|
$userid
|
|
)
|
|
);
|
|
//echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("nat_sigma insert");
|
|
exit;
|
|
}
|
|
$last_id = $this->db_regional->insert_id();
|
|
foreach($prm['orderregtimes'] as $k=>$v){
|
|
if($v['isrule'] === 'Y'){
|
|
$xtime = $v['Nat_QcRuleID'];
|
|
$query = "INSERT INTO nat_sigmadetail(
|
|
Nat_SigmaDetailNat_SigmaID,
|
|
Nat_SigmaDetailNat_QcRuleID,
|
|
Nat_SigmaDetailUserID,
|
|
Nat_SigmaDetailLastUpdated
|
|
)
|
|
VALUES(?,?,?,now())";
|
|
$insert_detail = $this->db_regional->query($query,array($last_id,$xtime,$userid));
|
|
// echo $this->db_regional->last_query();
|
|
}
|
|
}
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
$last_id = $this->db_regional->insert_id();
|
|
|
|
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function editregional()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$name = $prm['name'];
|
|
$kontrol = $prm['kontrol'];
|
|
$frekuensi = $prm['frekuensi'];
|
|
$min = $prm['min'];
|
|
$max = $prm['max'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sqlcompany = "update nat_sigma SET
|
|
Nat_SigmaName = ?,
|
|
Nat_SigmaTotalControl = ?,
|
|
Nat_SigmaTotalFrequency = ?,
|
|
Nat_SigmaMin = ?,
|
|
Nat_SigmaMax = ?,
|
|
Nat_SigmaLastUpdated = now()
|
|
where
|
|
Nat_SigmaID = ?
|
|
";
|
|
$querycompany = $this->db_regional->query($sqlcompany,
|
|
array(
|
|
$name,
|
|
$kontrol,
|
|
$frekuensi,
|
|
$min,
|
|
$max,
|
|
$id
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$querycompany) {
|
|
$this->sys_error_db("nat_sigma update");
|
|
exit;
|
|
}
|
|
foreach($prm['orderregtimes'] as $k=>$v){
|
|
if($v['isrule'] === 'Y' && $v['xid'] == 0){
|
|
$xtime = $v['Nat_QcRuleID'];
|
|
$query = "INSERT INTO nat_sigmadetail(
|
|
Nat_SigmaDetailNat_SigmaID,
|
|
Nat_SigmaDetailNat_QcRuleID,
|
|
Nat_SigmaDetailUserID,
|
|
Nat_SigmaDetailCreated,
|
|
Nat_SigmaDetailLastUpdated
|
|
)
|
|
VALUES(?,?,?,now(),now())";
|
|
$insert_detail = $this->db_regional->query($query,array($id,$xtime,$userid));
|
|
}else if($v['isrule'] === 'N'){
|
|
$queryupdate ="UPDATE nat_sigmadetail SET
|
|
Nat_SigmaDetailIsActive = 'N',
|
|
Nat_SigmaDetailUserID = '{$userid}',
|
|
Nat_SigmaDetailLastUpdated = now()
|
|
WHERE
|
|
Nat_SigmaDetailID = ?";
|
|
$update_detail = $this->db_regional->query($queryupdate,array($v['Nat_SigmaDetailID']));
|
|
}
|
|
}
|
|
$result = array ("total" => 1, "records" => array("xid" => $id));
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function addnewbranch()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$sigmaid = $prm['sigmaid'];
|
|
$ruleid = $prm['ruleid'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
if($sigmaid == 0 || $sigmaid == 0){
|
|
$errors = array();
|
|
if($sigmaid == 0){
|
|
array_push($errors,array('field'=>'sigma','msg'=>'Sigma dipilih dulu dong'));
|
|
}
|
|
if($ruleid == 0){
|
|
array_push($errors,array('field'=>'rule','msg'=>'Kota dipilih dulu dong'));
|
|
}
|
|
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
|
$this->sys_ok($result);
|
|
}else{
|
|
if($prm['xid'] == 0){
|
|
$sql = "insert into nat_sigmadetail(
|
|
Nat_SigmaDetailNat_SigmaID,
|
|
Nat_SigmaDetailUserID,
|
|
Nat_SigmaDetailNat_QcRuleID,
|
|
Nat_SigmaDetailLastUpdated,
|
|
Nat_SigmaDetailCreated)
|
|
values(?,?,?,now(),now())";
|
|
$query = $this->db_regional->query($sql,
|
|
array(
|
|
$sigmaid,
|
|
$userid,
|
|
$ruleid
|
|
)
|
|
);
|
|
if (!$query) {
|
|
$this->sys_error_db("nat_sigmadetail insert",$this->db_regional);
|
|
exit;
|
|
}
|
|
$last_id = $this->db_regional->insert_id();
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
|
|
}else{
|
|
$sql = "UPDATE nat_sigmadetail SET Nat_SigmaDetailNat_SigmaID = '{$sigmaid}',
|
|
Nat_SigmaDetailUserID = '{$userid}',
|
|
Nat_SigmaDetailNat_QcRuleID = '{$ruleid}'
|
|
WHERE Nat_SigmaDetailID = '{$prm['xid']}'";
|
|
//echo $sql;
|
|
$query = $this->db_regional->query($sql);
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function deleteregional()
|
|
{
|
|
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"];
|
|
$sql = "update nat_sigma SET
|
|
Nat_SigmaIsActive = 'N',
|
|
Nat_SigmaLastUpdated = now()
|
|
WHERE
|
|
Nat_SigmaID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_regional->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("nat_sigma delete");
|
|
exit;
|
|
}
|
|
$sql = "update nat_sigmadetail SET
|
|
Nat_SigmaDetailIsActive = 'N',
|
|
Nat_SigmaDetailLastUpdated = now()
|
|
WHERE
|
|
Nat_SigmaDetailNat_SigmaID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_regional->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("nat_sigmadetail 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 deletebranch()
|
|
{
|
|
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"];
|
|
$sql = "update nat_sigmadetail SET
|
|
Nat_SigmaDetailIsActive = 'N',
|
|
Nat_SigmaDetailLastUpdated = now()
|
|
WHERE
|
|
Nat_SigmaDetailID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_regional->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("nat_sigmadetail delete");
|
|
exit;
|
|
}
|
|
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function searchregional(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM nat_sigma
|
|
WHERE
|
|
Nat_SigmaName like ?
|
|
AND Nat_SigmaIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("nat_sigma count",$this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT Nat_SigmaID, Nat_SigmaName
|
|
FROM nat_sigma
|
|
WHERE
|
|
Nat_SigmaName like ?
|
|
AND Nat_SigmaIsActive = 'Y'
|
|
ORDER BY Nat_SigmaName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_regional->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("nat_sigma rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
function searchregionalbyname(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM nat_sigma
|
|
WHERE
|
|
Nat_SigmaName like ?
|
|
AND Nat_SigmaIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("nat_sigma count",$this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT Nat_SigmaID, Nat_SigmaName
|
|
FROM nat_sigma
|
|
WHERE
|
|
Nat_SigmaName like ?
|
|
AND Nat_SigmaIsActive = 'Y'
|
|
ORDER BY Nat_SigmaName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_regional->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("nat_sigma rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
function searchcity(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'
|
|
ORDER BY M_CityName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_regional->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function searchdistrict(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $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 m_district
|
|
WHERE
|
|
M_DistrictName like ?
|
|
AND M_DistrictM_CityID = '{$id}'
|
|
AND M_DistrictIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_district count",$this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictName like ?
|
|
AND M_DistrictM_CityID = '{$id}'
|
|
AND M_DistrictIsActive = 'Y'
|
|
ORDER BY M_DistrictName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_regional->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_district rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
function searchkelurahan(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $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 m_kelurahan
|
|
WHERE
|
|
M_KelurahanName like ?
|
|
AND M_KelurahanM_DistrictID = '{$id}'
|
|
AND M_KelurahanIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_district count",$this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanName like ?
|
|
AND M_KelurahanM_DistrictID = '{$id}'
|
|
AND M_KelurahanIsActive = 'Y'
|
|
ORDER BY M_KelurahanName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_regional->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_district rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
function searchcompany(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_company
|
|
WHERE
|
|
M_CompanyName like ?
|
|
AND M_CompanyIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_company count",$this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_company
|
|
WHERE
|
|
M_CompanyName like ?
|
|
AND M_CompanyIsActive = 'Y'
|
|
ORDER BY M_CompanyName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_regional->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_company rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
function searchmou(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $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 m_mou
|
|
WHERE
|
|
M_MouName like ?
|
|
AND M_MouM_CompanyID = '{$id}'
|
|
AND M_MouIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_mou count",$this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM m_mou
|
|
WHERE
|
|
M_MouName like ?
|
|
AND M_MouM_CompanyID = '{$id}'
|
|
AND M_MouIsActive = 'Y'
|
|
ORDER BY M_MouName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
// echo $this->db_regional->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_mou rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
function searchdoctor(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
|
|
FROM m_doctor
|
|
WHERE M_DoctorIsActive = 'Y') a
|
|
WHERE
|
|
M_DoctorName like ?";
|
|
$query = $this->db_regional->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_doctor count",$this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
|
|
FROM m_doctor
|
|
WHERE M_DoctorIsActive = 'Y') a
|
|
WHERE
|
|
M_DoctorName like ?
|
|
ORDER BY M_DoctorName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_regional->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_doctor rows",$this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
function selectrule(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$rows = [];
|
|
$query ="SELECT Nat_QcRuleID,
|
|
Nat_QcRuleCode
|
|
FROM
|
|
nat_qc_rule
|
|
WHERE Nat_QcRuleIsActive = 'Y'";
|
|
//echo $query;
|
|
$rows['rules'] = $this->db_regional->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);
|
|
}
|
|
|
|
}
|
|
} |