add api file from used in s_menu fe accone

This commit is contained in:
2026-07-06 16:44:35 +07:00
parent f3dba31445
commit 5ecf65a820
30 changed files with 23347 additions and 32 deletions

View File

@@ -0,0 +1,712 @@
<?php
class Expedition extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
}
function index()
{
echo "Api: Expedition";
}
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"]);
$search = '%' . $prm['search'] . '%';
}
$order_by = "ExpeditionName";
if (isset($prm['order_by'])) {
$order_by = trim($prm["order_by"]);
}
$order_type = "asc";
if (isset($prm['order_type'])) {
$order_type = trim($prm["order_type"]);
}
$order = $order_by . ' ' . $order_type;
$perpage = 10;
$offset = ($prm['current_page'] - 1) * $perpage;
$count = "SELECT count(ExpeditionID) as total
FROM expedition
WHERE
ExpeditionIsActive = 'Y'
AND ExpeditionName like ?";
$qry_count = $this->db->query($count, array($search));
$total_count = 0;
$total_page = 0;
if ($qry_count) {
$total_count = $qry_count->row()->total;
$total_page = ceil($total_count / $perpage);
} else {
$this->sys_error_db("Expedition count error", $this->db->last_query());
exit;
}
$rows = [];
$sql = "SELECT ExpeditionID as id,
ExpeditionName as name,
ExpeditionIsInternal as internal
FROM expedition
WHERE
ExpeditionIsActive = 'Y'
AND ExpeditionName like ?
ORDER BY $order LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, array($search, $perpage, $offset));
$lst_qryyy = $this->db->last_query();
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0) {
foreach ($rows as $key => $value) {
$sql = "SELECT ExpeditionStaffID as id ,
ExpeditionStaffName as staffName,
ExpeditionStaffMobile as staffMobile,
ExpeditionStaffM_StaffID as staffId
FROM expeditionstaff
WHERE ExpeditionStaffIsActive = 'Y'
AND ExpeditionStaffExpeditionID = ?";
$qry = $this->db->query($sql, array($value['id']));
if ($qry) {
$rows[$key]['staff'] =
$qry->result_array();
}
}
}
} else {
$this->sys_error_db("Expedition data error", $this->db->last_query());
exit;
}
$result = array(
"total" => $total_page,
"total_filter" => $total_count,
"records" => $rows,
"qry" => $lst_qryyy
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function get_staff()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$count = "SELECT count(M_StaffID) as total
FROM m_staff
WHERE M_StaffIsActive = 'Y'
AND M_StaffIsCourier = 'Y' ;";
$qry_count = $this->db->query($count);
$total_count = 0;
if ($qry_count) {
$total_count = $qry_count->row()->total;
} else {
$this->sys_error_db("Expedition count error", $this->db->last_query());
exit;
}
$sql = "SELECT M_StaffID as staffId,
M_StaffName as staffName,
M_StaffHP as staffMobile
FROM m_staff
WHERE M_StaffIsActive = 'Y'
AND M_StaffIsCourier = 'Y' ORDER BY M_StaffName asc ";
$qry = $this->db->query($sql);
$staff = $qry->result_array();
$result = array(
"total_filter" => $total_count,
"records" => $staff,
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function add()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm['name'])) {
$name = trim($prm["name"]);
}
$isInternal = "";
if (isset($prm['isInternal'])) {
$isInternal = trim($prm["isInternal"]);
}
$this->db->trans_start();
$this->db->trans_strict(FALSE);
$last_id = 0;
$staff_log = array();
$sql = "INSERT INTO expedition
(ExpeditionName,
ExpeditionIsInternal,
ExpeditionIsActive,
ExpeditionCreated,
ExpeditionLastUpdated,
ExpeditionUserID)
VALUES
(?,
?,
'Y',
NOW(),
NOW(),
?)";
$qry = $this->db->query($sql, array($name, $isInternal, $userid));
if ($qry) {
$last_id = $this->db->insert_id();
} else {
$this->sys_error_db("save expedition error", $this->db->last_query());
exit;
}
if (count($prm['staff']) > 0) {
foreach ($prm['staff'] as $key => $value) {
$stafName = trim($value['staffName']);
$stafMobile = trim($value['staffMobile']);
$staffId = trim($value['staffId']);
$sql = "INSERT INTO expeditionstaff
(ExpeditionStaffExpeditionID,
ExpeditionStaffName,
ExpeditionStaffMobile,
ExpeditionStaffM_StaffID,
ExpeditionStaffIsActive,
ExpeditionStaffUserID,
ExpeditionStaffCreated,
ExpeditionStaffLastUpdated)
VALUES
(?,
?,
?,
?,
'Y',
?,
NOW(),
NOW()
)";
$qry = $this->db->query($sql, array($last_id, $stafName, $stafMobile, $staffId, $userid));
$insert_id = $this->db->insert_id();
if (!$qry) {
$this->sys_error_db("save expedition error", $this->db->last_query());
exit;
}
$sql_json_after = "SELECT * FROM
expeditionstaff
WHERE
ExpeditionStaffID = ?";
$qry_json_after = $this->db->query($sql_json_after, [$insert_id]);
$json_after = $qry_json_after->row_array();
array_push($staff_log, $qry_json_after->row_array());
if (!$qry_json_after) {
$error = array(
"message" => $this->db->error()["message"],
"qry" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$sql_insert_log = "INSERT INTO acc_one_log.expeditionstaff_log
(ExpeditionStaffLogExpeditionStaffID,
ExpeditionStaffLogStatus,
ExpeditionStaffLogJSONAfter,
ExpeditionStaffLogUserID ,
ExpeditionStaffLogCreated)
VALUES(?,'ADD', ?,?, now() )";
$qry_insert_log = $this->db->query($sql_insert_log, [$insert_id, json_encode($json_after), $userid]);
if (!$qry_insert_log) {
$error = array(
"message" => $this->db->error()["message"],
"qry" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
}
}
$sql_json_after = "SELECT * FROM
expedition
WHERE ExpeditionID = ?";
$affected_rows = $this->db->affected_rows();
$qry_json_after = $this->db->query($sql_json_after, [$last_id]);
$json_after = $qry_json_after->row_array();
if (!$qry_json_after) {
$error = array(
"message" => $this->db->error()["message"],
"qry" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_after['expeditionstaff'] = $staff_log;
$sql_insert_log = "INSERT INTO acc_one_log.expedition_log
(ExpeditionLogStatus,
ExpeditionLogExpeditionID,
ExpeditionLogJSONAfter,
ExpeditionLogUserID,
ExpeditionLogCreated)
VALUES('ADD',?, ?,?, NOW() )";
$qry_insert_log = $this->db->query($sql_insert_log, [$last_id, json_encode($json_after), $userid]);
if (!$qry_insert_log) {
$error = array(
"msg" => "failed insert expedition log",
"message" => $this->db->error()["message"],
"qry" => $this->db->last_query(),
"json_after" => $json_after
);
$this->sys_error_db($error);
exit;
}
$this->db->trans_complete();
$result = array(
"affected_rows" => $affected_rows,
"inserted_id" => $last_id,
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function edit()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm['name'])) {
$name = trim($prm["name"]);
}
$isInternal = "";
if (isset($prm['isInternal'])) {
$isInternal = trim($prm["isInternal"]);
}
$id = $prm['id'];
$sql_json_before = "SELECT * FROM
expedition
WHERE ExpeditionID = ?";
$affected_rows = $this->db->affected_rows();
$qry_json_before = $this->db->query($sql_json_before, [$id]);
if (!$qry_json_before) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_expedition_before = $qry_json_before->row_array();
$sql_json_before = "SELECT * FROM
expeditionstaff
WHERE ExpeditionStaffExpeditionID = ?";
$qry_json_before = $this->db->query($sql_json_before, [$id]);
if (!$qry_json_before) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_expedition_before['expeditionstaff'] = $qry_json_before->result_array();
$isInternalBefore = $json_expedition_before['ExpeditionIsInternal'];
$this->db->trans_start();
$this->db->trans_strict(FALSE);
$sql = "UPDATE expedition SET
ExpeditionName = ? ,
ExpeditionIsInternal = ?,
ExpeditionLastUpdated = now()
WHERE ExpeditionID = ?";
$qry = $this->db->query($sql, [$name, $isInternal, $id]);
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$last_qry = "";
//ISINTERNAL SAMA DENGAN KONDISI SEBELUMNYA
if ($isInternalBefore == $isInternal) {
// APABILA STAFF LEBIH DARI 0
if (count($prm['staff']) > 0) {
$sql = "UPDATE expeditionstaff SET
ExpeditionStaffIsActive = 'N'
WHERE ExpeditionStaffExpeditionID = ?";
$qry = $this->db->query($sql, [$id]);
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
//PERULANGAN SETIAP STAFF
foreach ($prm['staff'] as $key => $value) {
$staffName = trim($value['staffName']);
$staffMobile = trim($value['staffMobile']);
$staffId = trim($value['id']);
$mStaffId = trim($value['staffId']);
//APABILA STAFFID YANG AKAN DI UBAH LEBIH DARI 0
if (intval($staffId) > 0) {
$sql_before = "SELECT * FROM
expeditionstaff
where ExpeditionStaffID = ?";
$qry_before = $this->db->query($sql_before, [$staffId]);
if (!$qry_before) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_before = json_encode($qry_before->row_array());
$sql = "UPDATE expeditionstaff SET
ExpeditionStaffName = ?,
ExpeditionStaffMobile =?,
ExpeditionStaffM_StaffID= ?,
ExpeditionStaffIsActive= 'Y',
ExpeditionStaffLastUpdated= now()
WHERE ExpeditionStaffID = ?";
$qry = $this->db->query($sql, [$staffName, $staffMobile, $mStaffId, $staffId]);
$last_qry = $this->db->last_query();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$sql_after = "SELECT * FROM
expeditionstaff
where ExpeditionStaffID = ?";
$qry_after = $this->db->query($sql_after, [$staffId]);
if (!$qry_after) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_after = json_encode($qry_after->row_array());
$sql_insert_log = "INSERT INTO acc_one_log.expeditionstaff_log
VALUES(null,?,'EDIT', ?, ?,?, now() )";
$qry_insert_log = $this->db->query($sql_insert_log, [$id, $json_before, $json_after, $userid]);
if (!$qry) {
$this->sys_error_db("save expedition error", $this->db->last_query());
exit;
}
if (!$qry_insert_log) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
//APABILA STAFF ID == 0
} else {
$sql = "INSERT INTO expeditionstaff
VALUES(null, ?, ?, ?,?,'Y',?, now(), now())";
$qry = $this->db->query($sql, array($id, $staffName, $staffMobile, $mStaffId, $userid));
$last_qry = $this->db->last_query();
$insert_id = $this->db->insert_id();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$sql_after = "SELECT * FROM
expeditionstaff
where ExpeditionStaffID = ?";
$qry_after = $this->db->query($sql_after, [$insert_id]);
if (!$qry_after) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_after = json_encode($qry_after->row_array());
$sql_insert_log = "INSERT INTO acc_one_log.expeditionstaff_log
VALUES(null,?,'ADD', null, ?,?, now() )";
$qry_insert_log = $this->db->query($sql_insert_log, [$insert_id, $json_after, $userid]);
if (!$qry_insert_log) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
}
}
}
//ISINTERNAL TIDAK SAMA DENGAN KONDISI SEBELUMNYA
} else {
if (count($prm['staff']) > 0) {
$sql = "UPDATE expeditionstaff SET
ExpeditionStaffIsActive = 'N'
WHERE ExpeditionStaffExpeditionID = ?";
$qry = $this->db->query($sql, [$id]);
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
foreach ($prm['staff'] as $key => $value) {
$staffName = trim($value['staffName']);
$staffMobile = trim($value['staffMobile']);
$staffId = trim($value['id']);
$mStaffId = trim($value['staffId']);
$sql = "INSERT INTO expeditionstaff
VALUES(null, ?, ?, ?,?,'Y',?, now(), now())";
$qry = $this->db->query($sql, array($id, $staffName, $staffMobile, $mStaffId, $userid));
$last_qry = $this->db->last_query();
$insert_id = $this->db->insert_id();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$sql_after = "SELECT * FROM
expeditionstaff
where ExpeditionStaffID = ?";
$qry_after = $this->db->query($sql_after, [$insert_id]);
if (!$qry_after) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_after = json_encode($qry_after->row_array());
$sql_insert_log = "INSERT INTO acc_one_log.expeditionstaff_log
VALUES(null,?,'ADD', null, ?,?, now() )";
$qry_insert_log = $this->db->query($sql_insert_log, [$insert_id, $json_after, $userid]);
if (!$qry_insert_log) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
}
}
}
$this->db->trans_complete();
$sql_json_after = "SELECT expedition.* FROM
expedition
WHERE ExpeditionID = ?";
$qry_json_after = $this->db->query($sql_json_after, [$id]);
if (!$qry_json_after) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_after = $qry_json_after->row_array();
$sql_json_after = "SELECT * FROM
expeditionstaff
WHERE ExpeditionStaffExpeditionID = ?";
$qry_json_after = $this->db->query($sql_json_after, [$id]);
$json_after['expeditionstaff'] = $qry_json_after->result_array();
if (!$qry_json_after) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$sql_insert_log = "INSERT INTO acc_one_log.expedition_log
VALUES(null,'EDIT',?, ?, ?,?, now() )";
$qry_insert_log = $this->db->query(
$sql_insert_log,
[$id, json_encode($json_expedition_before), json_encode($json_after), $userid]
);
if (!$qry_insert_log) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$result = array(
"message" => '',
"sql_log" => $this->db->last_query(),
"sql" => $this->db->last_query(),
"last_qry" => $last_qry
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function delete()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm['id'])) {
$id = trim($prm["id"]);
}
if ($id == "" || !$id) {
$error = array(
"message" => "id is mandatory",
);
$this->sys_error_db($error);
exit;
}
$this->db->trans_start();
$this->db->trans_strict(FALSE);
$sql = "UPDATE expedition
SET ExpeditionIsActive = 'N',
ExpeditionLastUpdated = NOW(),
ExpeditionUserID = ?
WHERE ExpeditionID = ?";
$qry = $this->db->query($sql, [$userid, $id]);
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
} else {
$sql = "UPDATE expeditionstaff SET
ExpeditionStaffIsActive = 'N',
ExpeditionStaffUserID = ?,
ExpeditionStaffLastUpdated = NOW()
WHERE ExpeditionStaffExpeditionID = ?";
$qry = $this->db->query($sql, [$userid, $id]);
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
}
$this->db->trans_complete();
$sql_json_after = "SELECT * FROM
expedition
WHERE ExpeditionID = ?";
$qry_json_after = $this->db->query($sql_json_after, [$id]);
if (!$qry_json_after) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$json_after = $qry_json_after->row_array();
$sql_json_after = "SELECT * FROM
expeditionstaff
WHERE ExpeditionStaffExpeditionID = ?";
$qry_json_after = $this->db->query($sql_json_after, [$id]);
$json_after['expeditionstaff'] = $qry_json_after->result_array();
if (!$qry_json_after) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$sql_insert_log = "INSERT INTO acc_one_log.expedition_log
VALUES(null,'DELETE',?, NULL, ?,?, now() )";
$qry_insert_log = $this->db->query(
$sql_insert_log,
[$id, json_encode($json_after), $userid]
);
if (!$qry_insert_log) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $this->db->last_query()
);
$this->sys_error_db($error);
exit;
}
$result = array(
"message" => '',
"sql_log" => $this->db->last_query(),
"sql" => $this->db->last_query(),
"json_after" => $json_after
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,241 @@
<?php
class Priviledge extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "USERGROUP PRIVILEDGE API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function lookupusergroup()
{
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");
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 lookuppriviledge()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT S_MenuID as id, S_MenuUrl, S_MenuName as name, '' as childs FROM s_menu WHERE S_MenuParentS_MenuID = 0 AND S_MenuIsActive = 'Y' ORDER BY S_MenuOrder ASC";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
if ($prm['code'] == 'R') {
foreach ($rows as $k => $v) {
if ($v['S_MenuUrl'] == '#') {
$sql = " SELECT S_MenuID as id, S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
FROM s_menu
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
WHERE
S_MenuIsActive = 'Y' AND S_MenuParentS_MenuID = '{$v['id']}'
ORDER BY S_MenuOrder ASC";
$rows[$k]['childs'] = $this->db_onedev->query($sql)->result_array();
if ($rows[$k]['childs']) {
foreach ($rows[$k]['childs'] as $kx => $vx) {
if ($vx['S_MenuUrl'] == '#') {
$sql = " SELECT S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
FROM s_menu
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
WHERE
S_MenuIsActive = 'Y' AND S_MenuParentS_MenuID = '{$vx['id']}'
ORDER BY S_MenuOrder ASC";
$rows[$k]['childs'][$kx]['childs'] = $this->db_onedev->query($sql)->result_array();
}
}
}
} else {
$sql = " SELECT S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
FROM s_menu
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
WHERE
S_MenuIsActive = 'Y' AND S_MenuID = '{$v['id']}'
ORDER BY S_MenuOrder ASC";
$rows[$k]['childs'] = $this->db_onedev->query($sql)->result_array();
}
}
} else {
foreach ($rows as $k => $v) {
if ($v['S_MenuUrl'] == '#') {
$sql = " SELECT S_MenuID as id, S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
FROM s_menu
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
WHERE
S_MenuIsActive = 'Y' AND S_MenuParentS_MenuID = '{$v['id']}' AND S_MenuRegional = '{$prm['code']}'
ORDER BY S_MenuOrder ASC";
$rows[$k]['childs'] = $this->db_onedev->query($sql)->result_array();
if ($rows[$k]['childs']) {
foreach ($rows[$k]['childs'] as $kx => $vx) {
if ($vx['S_MenuUrl'] == '#') {
$sql = " SELECT S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
FROM s_menu
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
WHERE
S_MenuIsActive = 'Y' AND S_MenuParentS_MenuID = '{$vx['id']}' AND S_MenuRegional = '{$prm['code']}'
ORDER BY S_MenuOrder ASC";
$rows[$k]['childs'][$kx]['childs'] = $this->db_onedev->query($sql)->result_array();
}
}
}
} else {
$sql = " SELECT S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
FROM s_menu
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
WHERE
S_MenuIsActive = 'Y' AND S_MenuID = '{$v['id']}' AND S_MenuRegional = '{$prm['code']}'
ORDER BY S_MenuOrder ASC";
$rows[$k]['childs'] = $this->db_onedev->query($sql)->result_array();
}
}
}
} else {
$this->sys_error_db("m_usergroup select");
exit;
}
$result = array("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function save()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$datas = $prm['datas'];
foreach ($datas as $k => $v) {
foreach ($v['childs'] as $kx => $vx) {
if ($vx['active'] == 'Y') {
if (is_null($vx['S_PrivilegeID']) && $vx['status'] == 'Y') {
$sql = "INSERT INTO s_privilege (
S_PrivilegeM_UserGroupID,
S_PrivilegeS_MenuID,
S_PrivilegeCreated
)
VALUES(
{$vx['usergroupid']},
{$vx['S_MenuID']},
NOW()
)";
$this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
}
if (!is_null($vx['S_PrivilegeID'])) {
$sql = "UPDATE s_privilege SET
S_PrivilegeIsActive = '{$vx['status']}'
WHERE
S_PrivilegeID = '{$vx['S_PrivilegeID']}'
";
$this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
}
}
if ($vx['childs']) {
foreach ($vx['childs'] as $kxz => $vxz) {
if ($vxz['active'] == 'Y') {
if (is_null($vxz['S_PrivilegeID']) && $vxz['status'] == 'Y') {
$sql = "INSERT INTO s_privilege (
S_PrivilegeM_UserGroupID,
S_PrivilegeS_MenuID,
S_PrivilegeCreated
)
VALUES(
{$vxz['usergroupid']},
{$vxz['S_MenuID']},
NOW()
)";
$this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
}
if (!is_null($vxz['S_PrivilegeID'])) {
$sql = "UPDATE s_privilege SET
S_PrivilegeIsActive = '{$vxz['status']}'
WHERE
S_PrivilegeID = '{$vxz['S_PrivilegeID']}'
";
$this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
}
}
}
}
}
}
$result = array("total" => 1, "records" => array());
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,722 @@
<?php
class Staffv2 extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Staff API";
}
public function __construct()
{
parent::__construct();
// $this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nik = str_replace("'", "\\'", $prm["snik"]);
$nama = str_replace("'", "\\'", $prm["nama"]);
$status = str_replace("'", "\\'", $prm["status"]);
// echo $nik;
$sql_where = "WHERE M_StaffIsActive = 'Y' ";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .= " and ";
}
$sql_where .= " M_StaffName like ? ";
$sql_param[] = "%$nama%";
}
if ($nik != "") {
if ($sql_where != "") {
$sql_where .= " and ";
}
$sql_where .= " M_StaffNIK like ? ";
$sql_param[] = "%$nik%";
}
//if ($sql_where != "") $sql_where .= " and ";
// Order masih dalam status registrasi
//$sql_where .= " M_StaffIsActive = 'Y' ";
$sql = " SELECT count(*) as total
FROM m_staff
LEFT JOIN m_sex ON M_StaffM_SexID = M_SexID
LEFT JOIN m_position ON M_StaffM_PositionID = M_PositionID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_staff count", $this->db_onedev);
exit;
}
$sql = "SELECT
m_staff.*,
DATE_FORMAT(M_StaffDOB,'%d-%m-%Y') as M_StaffDOBx,
M_StaffM_SexID,
M_SexID,
m_sexname,
0 M_ReligionID,
0 M_StaffM_ReligionID,
0 M_ReligionName,
'' M_BranchID,
0 M_StaffM_BranchID,
'' M_BranchName,
0 M_StaffM_PositionID,
M_PositionID,
M_PositionName,
'' M_CityName,
'' M_SubareaName,
M_StaffIsCourier as iskurir,
'' OHStaffMapIhsNumber
FROM m_staff
LEFT JOIN m_sex ON M_StaffM_SexID = M_SexID
LEFT JOIN m_position ON M_StaffM_PositionID = M_PositionID
$sql_where
ORDER BY M_StaffName ASC
";
// echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
// echo $this->db_onedev->last_query();
$rows = $query->result_array();
if ($rows) {
foreach ($rows as $k => $v) {
$$rows[$k]['M_StaffName'] = stripslashes($rows[$k]['M_StaffName']);
//$rows[$k]['verification_px'] = $this->add_verification_test($v['M_StaffID']);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql" => $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function getsexreg()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$rows['branchs'] = [];
$query = " SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$rows['religions'] = [];
$query = " SELECT *, COUNT(M_StaffID) as used
FROM (SELECT m_position.*,M_StaffID
FROM
m_position
LEFT JOIN m_staff ON M_PositionID = M_StaffM_PositionID AND M_StaffIsActive = 'Y'
WHERE M_PositionIsActive = 'Y') a
GROUP BY M_PositionID
";
//echo $query;
$rows['positions'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
public function addnewposition()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name_position = $prm['name'];
$userid = $this->sys_user["M_UserID"];
$sql = "insert into m_position(
M_PositionName,
M_PositionUserID,
M_PositionCreated,
M_PositionLastUpdated
)
values(?,?,now(),now())";
$query = $this->db_onedev->query(
$sql,
array(
$name_position,
$userid
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("m_position insert");
exit;
}
$rows = [];
$query = " SELECT *, COUNT(M_StaffID) as used
FROM (SELECT m_position.*,M_StaffID
FROM
m_position
LEFT JOIN m_staff ON M_PositionID = M_StaffM_PositionID AND M_StaffIsActive = 'Y'
WHERE M_PositionIsActive = 'Y') a
GROUP BY M_PositionID
";
//echo $query;
$rows['positions'] = $this->db_onedev->query($query)->result_array();
$result = array("total" => 1, "records" => $rows);
$this->sys_ok($result);
$last_id = $this->db_onedev->insert_id();
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editposition()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id_staff = $prm['id'];
$name_staff = $prm['name'];
$userid = $this->sys_user["M_UserID"];
$sqlstaff = "update m_position SET
M_PositionName = ?,
M_PositionUserID = ?,
M_PositionLastUpdated = now()
where
M_PositionID = ?
";
$querystaff = $this->db_onedev->query(
$sqlstaff,
array(
$name_staff,
$userid,
$id_staff
)
);
// echo $query;
if (!$querystaff) {
$this->sys_error_db("m_position update");
exit;
}
$rows = [];
$query = " SELECT *, COUNT(M_StaffID) as used
FROM (SELECT m_position.*,M_StaffID
FROM
m_position
LEFT JOIN m_staff ON M_PositionID = M_StaffM_PositionID AND M_StaffIsActive = 'Y'
WHERE M_PositionIsActive = 'Y') a
GROUP BY M_PositionID";
//echo $query;
$rows['positions'] = $this->db_onedev->query($query)->result_array();
$result = array("total" => 1, "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteposition()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id_staff = $prm['id'];
$userid = $this->sys_user["M_UserID"];
$sqlstaff = "update m_position SET
M_PositionIsActive = 'N',
M_PositionUserID = ?,
M_PositionLastUpdated = now()
where
M_PositionID = ?
";
$querystaff = $this->db_onedev->query(
$sqlstaff,
array(
$userid,
$id_staff
)
);
// echo $query;
if (!$querystaff) {
$this->sys_error_db("m_position update");
exit;
}
$rows = [];
$query = " SELECT *
FROM m_position
WHERE
M_PositionIsActive = 'Y'
";
//echo $query;
$rows['positions'] = $this->db_onedev->query($query)->result_array();
$result = array("total" => 1, "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
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_onedev->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_onedev);
exit;
}
$sql = "
SELECT *
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'
ORDER BY M_CityName DESC
";
$query = $this->db_onedev->query($sql, array($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("m_city rows", $this->db_onedev);
exit;
}
}
function getsubarea()
{
$prm = $this->sys_input;
$query = " SELECT *
FROM m_subarea
WHERE
M_SubareaIsActive = 'Y' AND M_SubareaM_CityID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d', strtotime($prm['M_StaffDOB']));
$iscourier = $prm['M_StaffIsCourier'];
$userid = $this->sys_user["M_UserID"];
$prm['M_StaffName'] = str_replace("'", "\\'", $prm['M_StaffName']);
$query = "UPDATE m_staff SET
M_StaffM_BranchID = '{$prm['M_StaffM_BranchID']}',
M_StaffName = '{$prm['M_StaffName']}',
M_StaffDOB = '{$pdob}',
M_StaffM_SexID = '{$prm['M_StaffM_SexID']}',
M_StaffM_ReligionID = '{$prm['M_StaffM_ReligionID']}',
M_StaffAddress = '{$prm['M_StaffAddress']}',
M_StaffM_CityID = '{$prm['M_StaffM_CityID']}',
M_StaffM_SubareaID = '{$prm['M_StaffM_SubareaID']}',
M_StaffHP = '{$prm['M_StaffHP']}',
M_StaffPhone = '{$prm['M_StaffPhone']}',
M_StaffM_PositionID = '{$prm['M_StaffM_PositionID']}',
M_StaffNIK = '{$prm['M_StaffNIK']}',
M_StaffBlood = '{$prm['M_StaffBlood']}',
M_StaffStudy = '{$prm['M_StaffStudy']}',
M_StaffStartDate = '{$prm['M_StaffStartDate']}',
M_StaffEndDate = '{$prm['M_StaffEndDate']}',
M_StaffTimeWork = '{$prm['M_StaffTimeWork']}',
M_StaffTimeWorkSaturday = '{$prm['M_StaffTimeWorkSaturday']}',
M_StaffIsCourier = '{$iscourier}',
M_StaffUserID = '{$userid}'
WHERE
M_StaffID = '{$prm['M_StaffID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
if (!$rows) {
$this->sys_error_db("update m_staff", $this->db_onedev);
exit;
}
// if ($rows) {
// $sql = "SELECT OHStaffMapID,
// OHStaffMapM_StaffNIK,
// OHStaffMapIhsNumber
// FROM one_health.oh_staff_map
// WHERE OHStaffMapM_StaffNIK = '{$prm['M_StaffNIK']}'";
// $qry = $this->db_onedev->query($sql);
// if ($qry) {
// $rows_oh = $qry->result_array();
// } else {
// $this->sys_error_db("select oh_staff_map", $this->db_onedev);
// exit;
// }
// if (count($rows_oh) > 0) {
// $sql_oh_staff = "UPDATE one_health.oh_staff_map SET
// OHStaffMapM_StaffNIK = '{$prm['M_StaffNIK']}',
// OHStaffMapIhsNumber = '{$prm['OHStaffMapIhsNumber']}',
// OHStaffMapUserID = '{$userid}',
// OHStaffMapLastUpdated = NOW()
// WHERE OHStaffMapM_StaffNIK = '{$prm['M_StaffNIK']}'";
// $rows = $this->db_onedev->query($sql_oh_staff);
// // $last_qry = $this->db_onedev->last_query();
// // print_r($last_qry);
// // exit;
// if (!$rows) {
// $this->db_onedev->trans_rollback();
// $this->sys_error_db("update oh_staff_map error", $this->db_onedev);
// exit;
// }
// } else {
// if ($prm['M_StaffNIK'] != "" && $prm['OHStaffMapIhsNumber'] != "") {
// $sql_oh_staff = "INSERT INTO one_health.oh_staff_map(
// OHStaffMapM_StaffNIK,
// OHStaffMapIhsNumber,
// OHStaffMapUserID,
// OHStaffMapCreated,
// OHStaffMapLastUpdated
// ) VALUES('{$prm['M_StaffNIK']}','{$prm['OHStaffMapIhsNumber']}','{$userid}',NOW(),NOW())";
// $rows = $this->db_onedev->query($sql_oh_staff);
// if (!$rows) {
// $this->db_onedev->trans_rollback();
// $this->sys_error_db("save oh_staff_map error", $this->db_onedev);
// exit;
// }
// }
// }
// }
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
function newstaff()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d', strtotime($prm['M_StaffDOB']));
$iscourier = $prm['M_StaffIsCourier'];
$userid = $this->sys_user["M_UserID"];
$query = "INSERT INTO m_staff (
M_StaffM_BranchID,
M_StaffName,
M_StaffDOB,
M_StaffM_SexID,
M_StaffM_ReligionID,
M_StaffAddress,
M_StaffM_CityID,
M_StaffM_SubareaID,
M_StaffHP,
M_StaffPhone,
M_StaffM_PositionID,
M_StaffNIK,
M_StaffBlood,
M_StaffStudy,
M_StaffStartDate ,
M_StaffEndDate,
M_StaffTimeWork,
M_StaffTimeWorkSaturday,
M_StaffIsCourier,
M_StaffUserID
)
VALUES(
'{$prm['M_StaffM_BranchID']}',
'{$prm['M_StaffName']}',
'{$pdob}',
'{$prm['M_StaffM_SexID']}',
'{$prm['M_StaffM_ReligionID']}',
'{$prm['M_StaffAddress']}',
'{$prm['M_StaffM_CityID']}',
'{$prm['M_StaffM_SubareaID']}',
'{$prm['M_StaffHP']}',
'{$prm['M_StaffPhone']}',
'{$prm['M_StaffM_PositionID']}',
'{$prm['M_StaffNIK']}',
'{$prm['M_StaffBlood']}',
'{$prm['M_StaffStudy']}',
'{$prm['M_StaffStartDate']}',
'{$prm['M_StaffEndDate']}',
'{$prm['M_StaffTimeWork']}',
'{$prm['M_StaffTimeWorkSaturday']}',
'{$iscourier}',
'{$userid}'
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
if ($rows) {
if ($iscourier == 'Y') {
$querycourier = "INSERT INTO m_courier(M_CourierM_StaffID,M_CourierCreated,M_CourierLastUpdated,M_CourierUserID)
VALUES('{$last_id}',now(),now(),'{$userid}')
";
$rows = $this->db_onedev->query($querycourier);
}
}
// if ($rows) {
// if ($prm['M_StaffNIK'] !== "" && $prm['OHStaffMapIhsNumber'] !== "") {
// $sql_oh_staff = "INSERT INTO one_health.oh_staff_map(
// OHStaffMapM_StaffNIK,
// OHStaffMapIhsNumber,
// OHStaffMapUserID,
// OHStaffMapCreated,
// OHStaffMapLastUpdated
// ) VALUES('{$prm['M_StaffNIK']}','{$prm['OHStaffMapIhsNumber']}','{$userid}',NOW(),NOW())";
// $rows = $this->db_onedev->query($sql_oh_staff);
// if (!$rows) {
// $this->db_onedev->trans_rollback();
// $this->sys_error_db("save oh_staff_map error", $this->db_onedev);
// exit;
// }
// }
// }
$result = array(
"total" => 1,
"records" => array('status' => 'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function deletestaff()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query = "UPDATE m_staff SET
M_StaffIsActive = 'N'
WHERE
M_StaffID = '{$prm['M_StaffID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
function getaddress()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query = " SELECT m_staffaddress.*,
M_KelurahanName,
M_DistrictID,
M_DistrictName,
M_CityID,
M_CityName,
'' as action
FROM m_staffaddress
JOIN m_kelurahan ON M_StaffAddressM_KelurahanID = M_KelurahanID
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
WHERE
M_StaffAddressIsActive = 'Y' AND M_StaffAddressM_StaffID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
if ($rows) {
foreach ($rows as $k => $v) {
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savenewaddress()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_staffaddress WHERE M_StaffAddressM_StaffID = '{$prm['M_StaffAddressM_StaffID']}' AND M_StaffAddressIsActive = 'Y'")->row()->countx;
//echo $this->db_onedev->last_query();
if ($count_addrs == 0) {
$prm['M_StaffAddressNote'] = 'Utama';
} else {
$count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_staffaddress WHERE M_StaffAddressM_StaffID = '{$prm['M_StaffAddressM_StaffID']}' AND M_StaffAddressNote = 'Utama' AND M_StaffAddressIsActive = 'Y'")->row()->countx;
if ($count_addrs_utama > 0 && strtolower($prm['M_StaffAddressNote']) == 'utama') {
$rx = date('YmdHis');
$prm['M_StaffAddressNote'] = 'Utama_' . $rx;
}
}
$query = "INSERT INTO m_staffaddress (
M_StaffAddressM_StaffID,
M_StaffAddressNote,
M_StaffAddressDescription,
M_StaffAddressM_KelurahanID,
M_StaffAddressCreated
)
VALUES(
'{$prm['M_StaffAddressM_StaffID']}',
'{$prm['M_StaffAddressNote']}',
'{$prm['M_StaffAddressDescription']}',
'{$prm['M_StaffAddressM_KelurahanID']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditaddress()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query = "UPDATE m_staffaddress SET
M_StaffAddressM_StaffID = '{$prm['M_StaffAddressM_StaffID']}',
M_StaffAddressNote = '{$prm['M_StaffAddressNote']}',
M_StaffAddressDescription = '{$prm['M_StaffAddressDescription']}',
M_StaffAddressM_KelurahanID = '{$prm['M_StaffAddressM_KelurahanID']}'
WHERE
M_StaffAddressID = '{$prm['M_StaffAddressID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
function deleteaddress()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query = "UPDATE m_staffaddress SET
M_StaffAddressIsActive = 'N'
WHERE
M_StaffAddressID = '{$prm['M_StaffAddressID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -139,7 +139,9 @@ class Journalcashv2 extends MY_Controller
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
WHERE $where_sql
GROUP BY jurnalID
ORDER BY jurnalID DESC";
ORDER BY jurnalID DESC
";
// Ambil total count
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
$qry_total = $this->db->query($sql_total, $params);
@@ -163,6 +165,7 @@ class Journalcashv2 extends MY_Controller
// Tambahkan LIMIT OFFSET
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
$qry = $this->db->query($sql_paginated, $params_paginated);
if ($qry) {
@@ -361,7 +364,6 @@ class Journalcashv2 extends MY_Controller
$this->sys_error($message);
}
}
function getUserApproveLevel()
{
try {

View File

@@ -118,6 +118,19 @@ class Journalgoodreceive extends MY_Controller
exit;
}
// if ($loginLevel == "branch") {
// $where_conditions[] = "jurnalM_BranchCode = ?";
// $params[] = $branchCode;
// } elseif ($loginLevel == "regional") {
// $where_conditions[] = "jurnalS_RegionalID = ?";
// $params[] = $regionalId;
// if (!empty($branchCode)) {
// $where_conditions[] = "jurnalM_BranchCode = ?";
// $params[] = $branchCode;
// }
// }
// Gabungkan WHERE SQL
$where_sql = implode(" AND ", $where_conditions);

View File

@@ -12,6 +12,77 @@ class Ruangan extends MY_Controller
echo "API Ruangan";
}
function listingRegional()
{
try {
if (!$this->isLogin) {
throw new Exception('Invalid token');
}
$sql = "SELECT
S_RegionalID,
S_RegionalName
FROM s_regional
WHERE S_RegionalIsActive = 'Y'";
$que = $this->db->query($sql);
if (!$que) {
throw new Exception('failed to query list regional', 1);
}
$data = $que->result_array();
$this->sys_ok([
"records" => $data,
"total" => count($data)
]);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
function listingCabang()
{
try {
if (!$this->isLogin) {
throw new Exception('Invalid token');
}
$para = $this->sys_input;
$sql = "SELECT
M_BranchID,
M_BranchName
FROM m_branch
WHERE M_BranchS_RegionalID = ?
AND M_BranchIsActive = 'Y'";
$que = $this->db->query($sql, [$para['regionalID']]);
if (!$que) {
throw new Exception('failed to query list cabang', 1);
}
$data = $que->result_array();
$this->sys_ok([
"records" => $data,
"total" => count($data)
]);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
function lookupRuangan()
{
try {
@@ -39,9 +110,8 @@ class Ruangan extends MY_Controller
b.M_BranchCode AS branch_code,
r.M_RuanganCode AS code,
r.M_RuanganName AS name,
r.M_RuanganUserID AS user_id,
r.M_RuanganCreated AS created,
r.M_RuanganLastUpdated AS last_updated
s.S_RegionalID AS regional_id,
s.S_RegionalName AS regional_name
FROM m_ruangan r
JOIN m_branch b
ON b.M_BranchID = r.M_RuanganM_BranchID