443 lines
18 KiB
PHP
443 lines
18 KiB
PHP
<?php
|
|
class Mcu_officer extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// $this->db = $this->load->database("cpone", true);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
// $cek = $this->db->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
echo "MCU OFFICER API";
|
|
}
|
|
|
|
public 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"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
} else {
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
$startdate = $prm['startdate'];
|
|
$enddate = $prm['enddate'];
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
if ($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_where = "WHERE (DATE(Mcu_OfficerHeaderDate) BETWEEN ? AND ?) AND Mcu_OfficerHeaderIsActive = 'Y'";
|
|
if ($search != '') {
|
|
$sql_where .= " AND (Mcu_OfficerHeaderNumber LIKE '{$search}' OR Mgm_McuLabel LIKE '{$search}')";
|
|
}
|
|
|
|
$sql_param = array($startdate, $enddate);
|
|
|
|
$sql_tot = "SELECT count(*) as total
|
|
FROM mcu_officer_header
|
|
JOIN mgm_mcu ON Mcu_OfficerHeaderMgm_McuID = Mgm_McuID
|
|
AND Mgm_McuIsActive = 'Y'
|
|
$sql_where
|
|
";
|
|
$qry_tot = $this->db->query($sql_tot, $sql_param);
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry_tot) {
|
|
$tot_count = $qry_tot->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->sys_error_db("mcu_officer_header count", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Mcu_OfficerHeaderID as id,
|
|
Mcu_OfficerHeaderMgm_McuID as mgmmcu_id,
|
|
Mgm_McuLabel as mgmmcu_name,
|
|
DATE_FORMAT(Mcu_OfficerHeaderDate,'%d-%m-%Y') as trx_date,
|
|
Mcu_OfficerHeaderDate as xdate,
|
|
DATE_FORMAT(Mcu_OfficerHeaderDateMcu,'%d-%m-%Y') as trx_datemcu,
|
|
Mcu_OfficerHeaderDateMcu as xdatemcu,
|
|
Mcu_OfficerHeaderNumber as trx_number,
|
|
Mcu_OfficerHeaderNote as trx_note
|
|
FROM mcu_officer_header
|
|
JOIN mgm_mcu ON Mcu_OfficerHeaderMgm_McuID = Mgm_McuID
|
|
AND Mgm_McuIsActive = 'Y'
|
|
$sql_where
|
|
ORDER BY Mcu_OfficerHeaderID ASC
|
|
LIMIT $number_limit OFFSET $number_offset";
|
|
$qry = $this->db->query($sql, $sql_param);
|
|
// echo $this->db->last_query();
|
|
// exit;
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select mcu_officer_header", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_page,
|
|
"records" => $rows,
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getmgmmcu()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$rows = [];
|
|
$query = " SELECT Mgm_McuID as id,
|
|
Mgm_McuLabel as name,
|
|
Mgm_McuNumber
|
|
FROM mgm_mcu
|
|
WHERE Mgm_McuIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
"xdate" => date("Y-m-d H:i:s")
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getstaff()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = "";
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
} else {
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
$rows = [];
|
|
if ($prm['id']) {
|
|
$sql = "SELECT M_StaffID as id,
|
|
M_StaffName as name
|
|
FROM m_staff
|
|
WHERE M_StaffIsActive = 'Y'
|
|
AND (M_StaffName LIKE '{$search}')
|
|
AND M_StaffID NOT IN (
|
|
SELECT
|
|
M_StaffID
|
|
FROM mcu_officer_detail
|
|
JOIN mcu_officer_header ON Mcu_OfficerDetailMcu_OfficerHeaderID = Mcu_OfficerHeaderID
|
|
JOIN mgm_mcu ON Mcu_OfficerHeaderMgm_McuID = Mgm_McuID
|
|
JOIN m_staff ON Mcu_OfficerDetailIDM_StaffID = M_StaffID
|
|
AND M_StaffIsActive = 'Y'
|
|
WHERE Mcu_OfficerDetailMcu_OfficerHeaderID = {$prm['id']} AND Mcu_OfficerDetailIsActive = 'Y'
|
|
)
|
|
ORDER BY M_StaffName ASC";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db('select staff header error', $this->db);
|
|
exit;
|
|
}
|
|
} else {
|
|
$query = " SELECT M_StaffID as id,
|
|
M_StaffName as name
|
|
FROM m_staff
|
|
WHERE M_StaffIsActive = 'Y'
|
|
AND (M_StaffName LIKE '{$search}')
|
|
ORDER BY M_StaffName ASC
|
|
";
|
|
//echo $query;
|
|
$qry_hsl = $this->db->query($query);
|
|
if ($qry_hsl) {
|
|
$rows = $qry_hsl->result_array();
|
|
} else {
|
|
$this->sys_error_db('select staff error', $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
"xdate" => date("Y-m-d H:i:s")
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function save()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$last_id = $prm['trx_id'];
|
|
if ($last_id == 0 || $last_id == '0') {
|
|
$mgmmcunumber = $prm['mgmmcunumber'];
|
|
$numbering = $this->db->query("SELECT fn_numbering_berita_acara('{$mgmmcunumber}') as numbering")->row()->numbering;
|
|
$xdate = date('Y-m-d', strtotime($prm["date"]));
|
|
$xdatemcu = date('Y-m-d', strtotime($prm["datemcu"]));
|
|
$query = "INSERT INTO mcu_officer_header (
|
|
Mcu_OfficerHeaderMgm_McuID,
|
|
Mcu_OfficerHeaderDate,
|
|
Mcu_OfficerHeaderDateMcu,
|
|
Mcu_OfficerHeaderNumber,
|
|
Mcu_OfficerHeaderNote,
|
|
Mcu_OfficerHeaderCreated,
|
|
Mcu_OfficerHeaderCreatedUserID,
|
|
Mcu_OfficerHeaderLastUpdated,
|
|
Mcu_OfficerHeaderLastUpdatedUserID)
|
|
VALUES(
|
|
'{$prm['mgmmcuid']}',
|
|
'{$xdate}',
|
|
'{$xdatemcu}',
|
|
'{$numbering}',
|
|
'{$prm['note']}',
|
|
NOW(),
|
|
'{$userid}',
|
|
NOW(),
|
|
'{$userid}'
|
|
)";
|
|
$saveheader = $this->db->query($query);
|
|
if (!$saveheader) {
|
|
$this->sys_error_db("insert officer header error", $this->db);
|
|
exit;
|
|
}
|
|
$last_id = $this->db->insert_id();
|
|
} else {
|
|
$numbering = $this->db->query("SELECT * FROM mcu_officer_header WHERE Mcu_OfficerHeaderID = {$last_id}")->row()->Mcu_OfficerHeaderNumber;
|
|
$xdate = date('Y-m-d', strtotime($prm["date"]));
|
|
$xdatemcu = date('Y-m-d', strtotime($prm["datemcu"]));
|
|
$query = "UPDATE mcu_officer_header SET
|
|
Mcu_OfficerHeaderMgm_McuID = '{$prm['mgmmcuid']}',
|
|
Mcu_OfficerHeaderDate = '{$xdate}',
|
|
Mcu_OfficerHeaderDateMcu = '{$xdatemcu}',
|
|
Mcu_OfficerHeaderNumber = '{$numbering}',
|
|
Mcu_OfficerHeaderNote = '{$prm['note']}',
|
|
Mcu_OfficerHeaderLastUpdated = NOW(),
|
|
Mcu_OfficerHeaderLastUpdatedUserID = {$userid}
|
|
WHERE Mcu_OfficerHeaderID = {$last_id}";
|
|
$saveheader = $this->db->query($query);
|
|
if (!$saveheader) {
|
|
$this->sys_error_db("update officer header error", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
if ($saveheader) {
|
|
if ($prm['details']) {
|
|
foreach ($prm['details'] as $key => $v) {
|
|
|
|
if ($v['trx_id'] == '0' || $v['trx_id'] == 0) {
|
|
// print_r($v);
|
|
// exit;
|
|
$query = "INSERT INTO mcu_officer_detail(
|
|
Mcu_OfficerDetailMcu_OfficerHeaderID,
|
|
Mcu_OfficerDetailIDM_StaffID,
|
|
Mcu_OfficerDetailType,
|
|
Mcu_OfficerDetailCreated,
|
|
Mcu_OfficerDetailCreatedUserID,
|
|
Mcu_OfficerDetailLastUpdated,
|
|
Mcu_OfficerDetailLastUpdatedUserID
|
|
) VALUES(
|
|
'{$last_id}',
|
|
'{$v['staffid']}',
|
|
'{$v['typeid']}',
|
|
NOW(),
|
|
{$userid},
|
|
NOW(),
|
|
{$userid}
|
|
)
|
|
ON DUPLICATE KEY UPDATE
|
|
Mcu_OfficerDetailIsActive = 'Y',
|
|
Mcu_OfficerDetailCreatedUserID = {$userid},
|
|
Mcu_OfficerDetailLastUpdatedUserID = {$userid}";
|
|
$savedetail = $this->db->query($query);
|
|
|
|
// echo $this->db->last_query();
|
|
// exit;
|
|
if (!$savedetail) {
|
|
$this->sys_error_db("insert detail officer error", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($prm['deleted_details']) {
|
|
foreach ($prm['deleted_details'] as $k => $v) {
|
|
$sql = "UPDATE mcu_officer_detail SET Mcu_OfficerDetailIsActive = 'N' WHERE Mcu_OfficerDetailID = {$v['trx_id']}";
|
|
//echo $sql;
|
|
$this->db->query($sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK'),
|
|
"number" => $numbering,
|
|
"id" => $last_id
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getdetails()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$sql = "SELECT
|
|
Mcu_OfficerDetailID as trx_id,
|
|
CASE
|
|
WHEN Mcu_OfficerDetailType = 'D' THEN 'Driver'
|
|
WHEN Mcu_OfficerDetailType = 'PU' THEN 'Petugas Umum'
|
|
WHEN Mcu_OfficerDetailType = 'CS' THEN 'Atur Pasien'
|
|
WHEN Mcu_OfficerDetailType = 'IT' THEN 'IT Support'
|
|
WHEN Mcu_OfficerDetailType = 'R' THEN 'Registrasi LIS'
|
|
WHEN Mcu_OfficerDetailType = 'RR' THEN 'Registrasi Rontgen'
|
|
WHEN Mcu_OfficerDetailType = 'PA' THEN 'Pendaftaran Akhir'
|
|
ELSE ''
|
|
END as typename,
|
|
M_StaffID as staffid,
|
|
M_StaffName as staffname,
|
|
DATE_FORMAT(Mcu_OfficerHeaderDate, '%d-%m-%Y') as date,
|
|
Mcu_OfficerHeaderNumber as number,
|
|
Mcu_OfficerHeaderNote as note,
|
|
Mgm_McuID as mgmmcuid,
|
|
Mgm_McuLabel as mgmmcuname,
|
|
'N' as chex
|
|
FROM mcu_officer_detail
|
|
JOIN mcu_officer_header ON Mcu_OfficerDetailMcu_OfficerHeaderID = Mcu_OfficerHeaderID
|
|
JOIN mgm_mcu ON Mcu_OfficerHeaderMgm_McuID = Mgm_McuID
|
|
JOIN m_staff ON Mcu_OfficerDetailIDM_StaffID = M_StaffID
|
|
AND M_StaffIsActive = 'Y'
|
|
WHERE Mcu_OfficerDetailMcu_OfficerHeaderID = {$prm['id']} AND Mcu_OfficerDetailIsActive = 'Y'
|
|
ORDER BY Mcu_OfficerDetailID ASC";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select officer detail", $this->db);
|
|
exit;
|
|
}
|
|
|
|
if ($rows) {
|
|
foreach ($rows as $k => $v) {
|
|
$rows[$k]['chex'] = $v['chex'] == 'N' ? false : true;
|
|
}
|
|
}
|
|
|
|
$result = array("total" => 1, "records" => $rows, "sql" => $this->db->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function deleteall()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$sql = "UPDATE mcu_officer_header SET
|
|
Mcu_OfficerHeaderIsActive = 'N',
|
|
Mcu_OfficerHeaderDeleted = NOW(),
|
|
Mcu_OfficerHeaderDeletedUserID = {$userid}
|
|
WHERE Mcu_OfficerHeaderID = {$prm['id']}";
|
|
$rst = $this->db->query($sql);
|
|
if (!$rst) {
|
|
$this->sys_error_db("delete officer header", $this->db);
|
|
exit;
|
|
}
|
|
|
|
if ($rst) {
|
|
$sql_detail = "UPDATE mcu_officer_detail SET
|
|
Mcu_OfficerDetailIsActive = 'N',
|
|
Mcu_OfficerDetailDeleted = NOW(),
|
|
Mcu_OfficerDetailDeletedUserID = {$userid}
|
|
WHERE Mcu_OfficerDetailMcu_OfficerHeaderID = {$prm['id']}";
|
|
$rstq = $this->db->query($sql_detail);
|
|
if (!$rstq) {
|
|
$this->sys_error_db("delete officer detail", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$result = array("total" => 1, "sql" => "");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|