Files
be-accone/application/controllers/mockup/usergroup/Usergroupv6.php

1015 lines
32 KiB
PHP

<?php
class Usergroupv6 extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "USER GROUP API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupuser()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select M_UserID as id,
M_UserM_UserGroupID as usergroupid,
M_UserUsername as username,
IF(M_StaffIsActive = 'N','',M_StaffName) as staffname,
M_UserM_StaffID as xstaff,
M_UserS_RegionalID as xregional,
S_RegionalName,
M_UserM_ApproveLevelID as xapprovelevelid,
IFNULL(M_ApproveLevelName, '-') as xapprovelevelname,
M_UserDivisionID as xuserdivisonid,
DivisionID as xdivisonid,
IFNULL(DivisionCode, '-') as xuserdivisioncode,
IFNULL(DivisionName, '-') as xuserdivisionname,
M_UserM_BranchID as xbranch,
M_BranchName,
M_UserLocationFlag,
CASE
WHEN M_UserLocationFlag = 'R' THEN 'REGIONAL'
WHEN M_UserLocationFlag = 'B' THEN 'CABANG'
ELSE 'Unknown'
END as M_UserLocationFlagName,
M_UserDefaultT_SampleStationID as xsamplestation,
M_UserIsCoordinator as iscoordinator,
M_UserR_ReportGroupID as xreport,
R_ReportGroupName,
'xxx' as action
from m_user
join m_staff oN M_UserM_StaffID = M_StaffID
AND M_UserIsActive = 'Y'
AND M_UserM_UserGroupID = {$id}
left join m_userlocation on M_UserLocationM_UserID = M_UserID
and M_UserLocationIsActive = 'Y'
left join r_reportgroup on M_UserR_ReportGroupID = R_ReportGroupID
left join s_regional on M_UserS_RegionalID = S_RegionalID
left join m_branch on M_UserM_BranchID = M_BranchID
left join m_approve_level ON M_UserM_ApproveLevelID = M_ApproveLevelID
AND M_ApproveLevelIsActive = 'Y'
left join m_userdivision ON M_UserID = M_UserDivisionM_UserID
AND M_UserDivisionIsActive = 'Y'
left join division on M_UserDivisionDivisionID = DivisionID
AND DivisionIsActive = 'Y'
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result();
$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 m_usergroup
where
M_UserGroupIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_onedev->query($sql, $sql_param)->row()->total;
$sql = "select M_UserGroupID as id, M_UserGroupDashboard as dashboard,
M_UserGroupName as name, M_UserGroupIsClinic as clinic, M_UserGroupName as description , 'xxx' as usergrouptype
from m_usergroup
where
M_UserGroupName LIKE CONCAT('%','{$search}','%') AND
M_UserGroupIsActive = 'Y' $limit";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_usergroup select", $this->db_onedev);
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 getdashboards()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$group_id = $prm['group_id'];
$sql = "select menu.S_MenuID as id, CONCAT(menu.S_MenuName,' [ ',menuparent.S_MenuName,' ]') as name, CONCAT('one-ui/',menu.S_MenuUrl) as url, menuparent.S_MenuName as group_name
FROM s_menu menu
LEFT JOIN s_menu menuparent ON menu.S_MenuParentS_MenuID = menuparent.S_MenuID
WHERE
menu.S_MenuUrl <> '#' AND menu.S_MenuIsActive = 'Y'";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_usergroup select", $this->db_onedev);
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 addnewusergroup()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name_usergroup = $prm['name'];
$dashboard_usergroup = $prm['dashboard'];
$clinic_usergroup = $prm['clinic'];
$query = "SELECT COUNT(*) as exist FROM m_usergroup WHERE M_UserGroupIsActive = 'Y' AND M_UserGroupName = '{$name_usergroup}'";
$exist_name = $this->db_onedev->query($query)->row()->exist;
//echo $exist_name;
if ($exist_name == 0) {
$sql = "insert into m_usergroup(
M_UserGroupName,
M_UserGroupDashboard,
M_UserGroupIsClinic,
M_UserGroupCreated,
M_UserGroupLastUpdated
)
values( ?, ?, ?,now(), now())";
$query = $this->db_onedev->query(
$sql,
array(
$name_usergroup,
$dashboard_usergroup,
$clinic_usergroup
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("m_usergroup insert");
exit;
}
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$errors = array();
if ($exist_name != 0) {
array_push($errors, array('field' => 'name', 'msg' => 'Nama sudah ada yang pakai dong'));
}
$result = array("total" => -1, "errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editusergroup()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id_usergroup = $prm['id'];
$name_usergroup = $prm['name'];
$dashboard_usergroup = $prm['dashboard'];
$clinic_usergroup = $prm['clinic'];
$query = "SELECT COUNT(*) as exist FROM m_usergroup WHERE M_UserGroupIsActive = 'Y' AND M_UserGroupName = '{$name_usergroup}'
AND M_UserGroupID <> {$id_usergroup} ";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if ($exist_name == 0) {
$sql = "update m_usergroup SET
M_UserGroupName = ?,
M_UserGroupDashboard = ?,
M_UserGroupIsClinic = ?,
M_UserGroupLastUpdated = now()
where
M_UserGroupID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$name_usergroup,
$dashboard_usergroup,
$clinic_usergroup,
$id_usergroup
)
);
//file_put_contents("/tmp/adi-update-user.sql",$this->db_onedev->last_query());
//echo $query;
if (!$query) {
$this->sys_error_db("m_usergroup update");
exit;
}
$result = array("total" => 1, "records" => array("xid" => $id_usergroup));
$this->sys_ok($result);
} else {
$errors = array();
if ($exist_name != 0) {
array_push($errors, array('field' => 'name', 'msg' => 'Nama sudah ada yang pakai dong'));
}
$result = array("total" => -1, "errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getreportsample()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query = " SELECT *
FROM r_reportgroup
WHERE
R_ReportGroupIsActive = 'Y'
";
//echo $query;
$rows['reports'] = $this->db_onedev->query($query)->result_array();
// $query =" SELECT *
// FROM t_samplestation
// WHERE
// T_SampleStationIsActive = 'Y'
// ";
// //echo $query;
// $rows['samplestations'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM s_regional
WHERE
S_RegionalIsActive = 'Y'
";
//echo $query;
$rows['regionals'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_branch
WHERE
M_BranchIsActive = 'Y'
";
//echo $query;
$rows['branches'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_usergroup
WHERE
M_UserGroupIsActive = 'Y'
";
//echo $query;
$rows['usergroupnames'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_staff
WHERE
M_StaffIsActive = 'Y'
";
//echo $query;
$rows['staffs'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
public function edituser()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$xuserid = $this->sys_user['M_UserID'];
$userid = $prm['xid'];
$username = $prm['username'];
$password = $prm['password'];
$md5_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
$xstaff = $prm['xstaff'];
$xregional = $prm['xregional'];
$xuserdivision = isset($prm['xuserdivision']) ? (int) $prm['xuserdivision'] : 0;
$xdivision = isset($prm['xdivision']) ? (int) $prm['xdivision'] : 0;
$xbranch = isset($prm['xbranch']) ? (int) $prm['xbranch'] : 0;
$xapprovelevel = isset($prm['xapprovelevel']) ? (int) $prm['xapprovelevel'] : 0;
$xuserlocationflag = $prm['userlocationflag'];
$xsamplestation = $prm['xsamplestation'];
$xreport = $prm['xreport'];
$xusergroupname = $prm['xusergroupname'];
$iscoordinator = $prm['iscoordinator'];
$query = "SELECT COUNT(*) as exist FROM m_user WHERE M_UserIsActive = 'Y' AND M_UserUsername = '{$username}'
and M_UserID <> $userid ";
$exist_username = $this->db_onedev->query($query)->row()->exist;
if ($exist_username == 0) {
$sql = "update m_user SET
M_UserUsername = ?,
M_UserM_BranchID = ?,
M_UserS_RegionalID = ?,
M_UserM_ApproveLevelID = ?,
M_UserM_StaffID = ?,
M_UserDefaultT_SampleStationID = ?,
M_UserR_ReportGroupID = ?,
M_UserM_UserGroupID = ?,
M_UserIsCoordinator = ?,
M_UserLastUpdated = now()
where M_UserID = ? ";
$query = $this->db_onedev->query(
$sql,
array(
$username,
$xbranch,
$xregional,
$xapprovelevel,
$xstaff["M_StaffID"],
$xsamplestation["T_SampleStationID"],
$xreport["R_ReportGroupID"],
$xusergroupname["M_UserGroupID"],
$iscoordinator,
$userid
)
);
if (!$query) {
$this->sys_error_db("m_user update", $this->db_onedev);
exit;
}
$sql = "update m_userlocation SET
M_UserLocationFlag = ?,
M_UserLocationS_RegionalID = ?,
M_UserLocationM_BranchID = ?,
M_UserLocationLastUpdatedUserID = now()
where M_UserLocationM_UserID = ?";
$query = $this->db_onedev->query(
$sql,
array(
$xuserlocationflag,
$xregional,
$xbranch,
$userid,
)
);
if (!$query) {
$this->sys_error_db("m_userlocation update", $this->db_onedev);
exit;
}
$sql_searchdivision = "SELECT M_UserDivisionID FROM m_userdivision
WHERE M_UserDivisionM_UserID = ?
AND M_UserDivisionIsActive = 'Y'";
$query = $this->db_onedev->query(
$sql_searchdivision,
array(
$userid,
)
);
if (!$query) {
$this->sys_error_db("m_userdivision search", $this->db_onedev);
exit;
}
$row = $query->row();
$M_UserDivisionID = $row->M_UserDivisionID ?? 0;
if ($M_UserDivisionID == 0) {
$sql_insert = "INSERT INTO m_userdivision (
M_UserDivisionM_UserID,
M_UserDivisionDivisionID,
M_UserDivisionCreatedUserID,
M_UserDivisionLastUpdatedUserID,
M_UserDivisionCreated,
M_UserDivisionLastUpdated
)
values( ?,?,?,?,now(),now())";
$query = $this->db_onedev->query(
$sql_insert,
array(
$userid,
$xdivision,
$xuserid,
$xuserid,
)
);
if (!$query) {
$this->sys_error_db("m_userdivision insert", $this->db_onedev);
exit;
}
// $last_inserted_id = $this->db_onedev->insert_id();
}else{
$sql = "update m_userdivision SET
M_UserDivisionDivisionID = ?,
M_UserDivisionLastUpdatedUserID = ?,
M_UserDivisionLastUpdated = now()
where M_UserDivisionID = ?
and M_UserDivisionIsActive = 'Y'";
$query = $this->db_onedev->query(
$sql,
array(
$xdivision,
$xuserid,
$M_UserDivisionID
)
);
if (!$query) {
$this->sys_error_db("m_userdivision update", $this->db_onedev);
exit;
}
}
$result = array("total" => 1, "records" => array("xid" => $userid));
$this->sys_ok($result);
} else {
$errors = array();
$result = array("total" => -1, "errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewuser()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$usergroupid = $prm['usergroupid'];
$username = $prm['username'];
$password = $prm['password'];
$md5_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
$xregional = $prm['xregional'];
$xbranch = 0;
if ($prm['xbranch']) {
$xbranch = $prm['xbranch'];
}
$xapprovelevel = 0;
if ($prm['xapprovelevel']) {
$xapprovelevel = $prm['xapprovelevel'];
}
;
$xdivision = 0;
if ($prm['xdivision']) {
$xdivision = $prm['xdivision'];
}
;
$userlocationflag = $prm['userlocationflag'];
$xstaff = $prm['xstaff'];
$xsamplestation = $prm['xsamplestation'];
$xreport = $prm['xreport'];
$iscoordinator = $prm['iscoordinator'];
if ($prm['xid'] == 0) {
$query = "SELECT COUNT(*) as exist FROM m_user WHERE M_UserIsActive = 'Y' AND M_UserUsername = '{$username}'";
$exist_username = $this->db_onedev->query($query)->row()->exist;
if ($exist_username == 0) {
$sql = "insert into m_user(
M_UserM_UserGroupID,
M_UserUsername,
M_UserS_RegionalID,
M_UserM_BranchID,
M_UserM_ApproveLevelID,
M_UserPassword,
M_UserM_StaffID,
M_UserDefaultT_SampleStationID,
M_UserR_ReportGroupID,
M_UserIsCoordinator,
M_UserCreated,
M_UserLastUpdated
)
values( ?,?,?,?,?,?,?,?,?,?,now(),now())";
$query = $this->db_onedev->query(
$sql,
array(
$usergroupid,
$username,
$xregional,
$xbranch,
$xapprovelevel,
$md5_password,
$xstaff["M_StaffID"],
$xsamplestation["T_SampleStationID"],
$xreport["R_ReportGroupID"],
$iscoordinator
)
);
if (!$query) {
$this->sys_error_db("m_user insert", $this->db_onedev);
exit;
}
$last_inserted_id = $this->db_onedev->insert_id();
$sql = "insert into m_userlocation(
M_UserLocationM_UserID,
M_UserLocationFlag,
M_UserLocationS_RegionalID,
M_UserLocationM_BranchID,
M_UserLocationCreatedUserID,
M_UserLocationCreated,
M_UserLocationLastUpdated,
M_UserLocationLastUpdatedUserID
)
values( ?,?,?,?,?,now(),now(),now())";
$query = $this->db_onedev->query(
$sql,
array(
$last_inserted_id,
$userlocationflag,
$xregional,
$xbranch,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("m_user insert", $this->db_onedev);
exit;
}
$sql = "insert into m_userdivision(
M_UserDivisionM_UserID,
M_UserDivisionDivisionID,
M_UserDivisionCreatedUserID,
M_UserDivisionLastUpdatedUserID,
M_UserDivisionCreated,
M_UserDivisionLastUpdated
)
values( ?,?,?,?,now(),now())";
$query = $this->db_onedev->query(
$sql,
array(
$last_inserted_id,
$xdivision,
$xuserid,
$xuserid,
)
);
if (!$query) {
$this->sys_error_db("m_userdivision insert", $this->db_onedev);
exit;
}
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$errors = array();
if ($exist_username != 0) {
array_push($errors, array('field' => 'username', 'msg' => 'Nama User sudah ada yang pakai dong'));
}
$result = array("total" => -1, "errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} else {
$query = "SELECT COUNT(*) as exist FROM m_user WHERE M_UserIsActive = 'Y' AND M_UserUsername = '{$username}' AND M_UserID <> {$prm['xid']}";
$exist_username = $this->db_onedev->query($query)->row()->exist;
//echo $query;
//echo $query;
if ($exist_username == 0) {
$sql = "UPDATE m_user SET M_UserUsername = '{$username}', M_UserPassword = '{$password}', M_UserM_StaffID = '{$xstaff}', M_UserR_ReportGroupID = '{$xreport}', M_UserDefaultT_SampleStationID = '{$xsamplestation}', M_UserIsCoordinator = '{$iscoordinator}' WHERE M_UserID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$errors = array();
if ($exist_username != 0) {
array_push($errors, array('field' => 'username', 'msg' => 'Username sudah ada yang pakai dong'));
}
$result = array("total" => -1, "errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function generate_string($input, $strength = 4)
{
$input_length = strlen($input);
$random_string = '';
for ($i = 0; $i < $strength; $i++) {
$random_character = $input[mt_rand(0, $input_length - 1)];
$random_string .= $random_character;
}
return $random_string;
}
function reset_password()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$userid = $this->sys_user["M_UserID"];
$permitted_chars = 'wertyuioplkjhgfdsazxcvbnm0123456789';
$new_password = $this->generate_string($permitted_chars, 9);
$md5_password = md5($this->one_salt . $new_password . $this->one_salt);
//echo $new_password;
$sql = "UPDATE m_user SET M_UserPassword = '{$md5_password}', M_UserLastUpdated = NOW(), M_UserM_UserID = {$userid} WHERE M_UserID = {$id}";
//echo $sql;
$rows = $this->db_onedev->query($sql);
$sql = "SELECT * FROM m_user WHERE M_UserID = {$id}";
$data_user = $this->db_onedev->query($sql)->row_array();
$data_log = array(
"user_id" => $id,
"old_password" => $data_user['M_UserPassword'],
"new_password" => $md5_password,
"new_password_show" => $new_password,
"reason" => $prm['reason']
);
$data_log = json_encode($data_log);
$sql = "INSERT INTO log_user (
Log_UserDatetime,
Log_UserCode,
Log_UserXID,
Log_UserJson,
Log_UserM_UserID
)
VALUES(
NOW(),
'RESETPWD',
{$id},
'{$data_log}',
{$userid}
)";
$this->db_onedev->query($sql);
$result = array("password" => $new_password);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteuser()
{
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 m_user SET
M_UserUsername = CONCAT(M_UserUsername,'-DELETED'),
M_UserIsActive = 'N',
M_UserPassword = '1234567890XD3L3T3US312',
M_UserActiveToken = NULL,
M_UserIsLoggedIn = 'N',
M_UserLastUpdated = now()
WHERE
M_UserID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_user delete");
exit;
}
$sql = "update m_userdivision SET
M_UserDivisionIsActive = 'N',
M_UserDivisionDeletedUserID = ?,
M_UserDivisionDeleted = NOW(),
M_UserDivisionLastUpdated = NOW()
WHERE
M_UserDivisionM_UserID = ?
AND M_UserDivisionIsActive ='Y'
";
$query = $this->db_onedev->query(
$sql,
array(
$userid,
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_userdivision 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 deleteusergroup()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update m_usergroup SET
M_UserGroupIsActive = 'N',
M_UserGroupLastUpdated = now()
WHERE
M_UserGroupID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_usergroup delete");
exit;
}
$sql = "UPDATE m_user SET
M_UserIsActive = 'N',
M_UserLastUpdated = now()
WHERE
M_UserM_UserGroupID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_user 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 search_regional()
{
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$tot_count = 0;
$search = $prm['search'];
$sql = " SELECT *
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalName LIKE '%{$search}%'";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
} else {
$this->sys_error_db("regional rows", $this->db_onedev);
exit;
}
}
function search_branch()
{
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$tot_count = 0;
$search = $prm['search'];
$regionalid = $prm['regionalid'];
$sql = "SELECT *
FROM m_branch
WHERE M_BranchIsActive = 'Y'
AND M_BranchS_RegionalID = '{$regionalid}'";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
} else {
$this->sys_error_db("branch rows", $this->db_onedev);
exit;
}
}
function search_approvelevel()
{
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT M_ApproveLevelID, M_ApproveLevelName
FROM m_approve_level
WHERE M_ApproveLevelIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("total" => sizeof($rows), "records" => $rows);
$this->sys_ok($result);
} else {
$this->sys_error_db("aprrove level rows", $this->db_onedev);
exit;
}
}
function getdivision()
{
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT DivisionID, DivisionCode, DivisionName
FROM division
WHERE DivisionIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("total" => sizeof($rows), "records" => $rows);
$this->sys_ok($result);
} else {
$this->sys_error_db("division rows", $this->db_onedev);
exit;
}
}
}