Initial import
This commit is contained in:
349
one-api/application/controllers/one_mitra/Auth.php
Normal file
349
one-api/application/controllers/one_mitra/Auth.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
class Auth extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $db_log;
|
||||
var $db;
|
||||
var $load;
|
||||
public function index()
|
||||
{
|
||||
// echo "AUTH API";
|
||||
// $query = $this->db->query(
|
||||
// "show databases
|
||||
// ",
|
||||
// array()
|
||||
// );
|
||||
// // print_r($this->db_regional->last_query());
|
||||
// if (!$query) {
|
||||
// $message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
// exit;
|
||||
// }
|
||||
// $rows = $query->result_array();
|
||||
// echo json_encode($rows);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// $this->db_regional = $this->db->query("use one_mitra");
|
||||
// $this->db_log = $this->db->query("use mitra_log");
|
||||
}
|
||||
|
||||
function isLogin()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
} else {
|
||||
$prm = $this->sys_input;
|
||||
$data = array(
|
||||
"user" => $this->sys_user
|
||||
);
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
}
|
||||
|
||||
function login()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
//existing password enc
|
||||
// print_r($prm);
|
||||
$sm_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"SELECT M_UserID,
|
||||
M_UserUsername,
|
||||
M_UserM_CompanyID,
|
||||
M_UserM_MouID,
|
||||
M_CompanyName as company_name,
|
||||
M_UserS_RegionalID
|
||||
from one_mitra.m_user
|
||||
JOIN m_company ON M_UserM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
where M_UserUsername= ? and M_UserPassword= ?
|
||||
and M_UserIsActive = 'Y'
|
||||
",
|
||||
array($prm["username"], $sm_password)
|
||||
);
|
||||
// print_r($this->db_regional->last_query());
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message, $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$user = $rows[0];
|
||||
$user['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$token = JWT::encode($user, $this->SECRET_KEY);
|
||||
$data = array(
|
||||
"user" => $user,
|
||||
"token" => $token
|
||||
);
|
||||
|
||||
$query = $this->db->query("UPDATE one_mitra.m_user
|
||||
SET M_UserIsLoggedIn = 'Y',
|
||||
M_UserLastAccess = now(),
|
||||
M_UserActiveToken = '{$token}'
|
||||
WHERE M_UserID = ?
|
||||
", array($user['M_UserID']));
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $this->db->query("INSERT INTO mitra_log.log_login
|
||||
(Log_LoginDateTime,
|
||||
Log_LoginIP,
|
||||
Log_LoginType,
|
||||
Log_LoginStatus,
|
||||
Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGIN', 'SUCCESS', $prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($data);
|
||||
exit;
|
||||
}
|
||||
$query = $this->db->query("INSERT INTO mitra_log.log_login
|
||||
(Log_LoginDateTime,
|
||||
Log_LoginIP,
|
||||
Log_LoginType,
|
||||
Log_LoginStatus,
|
||||
Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $this->input->ip_address(), 'LOGIN', 'FAILED', $prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_log->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$this->sys_error_db("Invalid UserName / Password");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
|
||||
$query = $this->db->query(
|
||||
"UPDATE one_mitra.m_user
|
||||
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
|
||||
WHERE M_UserID = ?",
|
||||
array($prm['M_UserID'])
|
||||
);
|
||||
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->query("INSERT INTO mitra_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $prm['M_UserUsername']));
|
||||
$this->sys_ok("OK");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function changepassword()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Invalid Token")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$currPassword = $prm['current_password'];
|
||||
$newPassword = $prm['new_password'];
|
||||
$passwordConfirmation = $prm['password_confirmation'];
|
||||
if (!isset($prm['new_password']) || empty($prm['new_password'])) {
|
||||
$this->sys_error("Silahkan isi password baru");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['current_password']) || empty($prm['current_password'])) {
|
||||
$this->sys_error("Silahkan isi password lama");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['password_confirmation']) || empty($prm['password_confirmation'])) {
|
||||
$this->sys_error("Silahkan isi konfirmasi password");
|
||||
exit;
|
||||
}
|
||||
if ($newPassword != $passwordConfirmation) {
|
||||
$this->sys_error("Paswword baru dan konfirmasi password tidak sama !");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate password strength
|
||||
$uppercase = preg_match('@[A-Z]@', $prm['new_password']);
|
||||
$lowercase = preg_match('@[a-z]@', $prm['new_password']);
|
||||
$number = preg_match('@[0-9]@', $prm['new_password']);
|
||||
|
||||
if (strlen($prm['new_password']) < 8) {
|
||||
|
||||
$this->sys_error("Password minimal 8 digit");
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$uppercase) {
|
||||
$this->sys_error("Password minimal mengandung 1 huruf besar");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$lowercase) {
|
||||
$this->sys_error("Password minimal mengandung 1 huruf kecil");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$number) {
|
||||
$this->sys_error("Password minimal mengandung 1 angka");
|
||||
exit;
|
||||
}
|
||||
$sm_password = md5($this->one_salt . $currPassword . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"select * from one_mitra.m_user where M_UserID = ? and M_UserPassword = ?",
|
||||
array($userid, $sm_password)
|
||||
);
|
||||
if (!$query) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Query cek error")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Invalid Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$sql_json_before = "SELECT *
|
||||
FROM one_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query(
|
||||
$sql_json_before,
|
||||
[
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user select json before");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_before_by_id = $qry_json_before->row();
|
||||
|
||||
$json_before_log = json_encode($data_before_by_id);
|
||||
|
||||
$new_password_salt = md5($this->one_salt . $newPassword . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"UPDATE one_mitra.m_user set
|
||||
M_UserPassword= ?
|
||||
where M_UserID = ?
|
||||
AND M_UserIsActive = 'Y'",
|
||||
array(
|
||||
|
||||
$new_password_salt,
|
||||
// $userID
|
||||
$userid
|
||||
)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Error Change Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
// json after
|
||||
$sql_json_after = "SELECT *
|
||||
FROM one_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
|
||||
$qry_json_after = $this->db->query(
|
||||
$sql_json_after,
|
||||
[
|
||||
// $userID
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_after) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user select json after");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_after_by_id = $qry_json_after->row();
|
||||
|
||||
$json_after_log = json_encode($data_after_by_id);
|
||||
// json after
|
||||
|
||||
// proses insert log start
|
||||
$sql_insert_log = "INSERT INTO mitra_log.m_user_log(
|
||||
M_UserLogM_UserID,
|
||||
M_UserLogStatus,
|
||||
M_UserLogJSONBefore,
|
||||
M_UserLogJSONAfter,
|
||||
M_UserLogUserID,
|
||||
M_UserLogCreated
|
||||
) VALUES (
|
||||
?,
|
||||
'CHANGE PASSWORD',
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
now()
|
||||
)";
|
||||
|
||||
$qry_insert_log = $this->db->query(
|
||||
$sql_insert_log,
|
||||
[
|
||||
$userid,
|
||||
$json_before_log,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user insert log");
|
||||
exit;
|
||||
}
|
||||
// proses insert log end
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Berhasil Mengubah Password silahkan login ulang");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
211
one-api/application/controllers/one_mitra/Authchange.php
Normal file
211
one-api/application/controllers/one_mitra/Authchange.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
class Authchange extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $db_log;
|
||||
var $db;
|
||||
var $load;
|
||||
public function index() {
|
||||
echo "AUTH CHANGE";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
// if (!$this->isLogin) {
|
||||
// $this->sys_error("Invalid Token");
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $userID = $this->sys_user['M_UserID'];
|
||||
|
||||
// $sql_cek_token = "SELECT M_UserActiveToken
|
||||
// from one_mitra.m_user
|
||||
// WHERE M_UserID = ?
|
||||
// AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
// $qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
// if (!$qry_token) {
|
||||
// $this->sys_error('Invalid token');
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $rows_token = $qry_token->result_array();
|
||||
// if (count($rows_token) == 0) {
|
||||
// $this->sys_error('Invalid token');
|
||||
// exit;
|
||||
// }
|
||||
}
|
||||
|
||||
public function getUserAliases()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
M_UserAliasesID AS userAliasesID,
|
||||
M_UserAliasesM_UsersID AS userAliasesUserID,
|
||||
M_UserAliasesTargetIP AS userAliasesTargetIP,
|
||||
M_UserAliasesTargetM_UserID AS userAliasesTargetUserID,
|
||||
M_UserAliasesTargetM_Username AS userAliasesTargetUsername,
|
||||
M_UserAliasesTargetURL AS userAliasesTargetUrl,
|
||||
S_RegionalID AS userAliasesTargetRegionalID,
|
||||
S_RegionalName AS userAliasesTargetRegionalName
|
||||
FROM one_mitra.m_user_aliases
|
||||
JOIN s_regional
|
||||
ON M_UserAliasesTargetRegionalID = S_RegionalID
|
||||
WHERE M_UserAliasesM_UsersID = ?
|
||||
AND M_UserAliasesIsActive = 'Y';";
|
||||
$query = $this->db->query($sql, array($this->sys_user['M_UserID']));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("Error get user aliases");
|
||||
exit;
|
||||
}
|
||||
$data = $query->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
|
||||
public function encrypt($targetUrl, $username)
|
||||
{
|
||||
$str = $targetUrl . '.' . $username;
|
||||
return md5($str);
|
||||
}
|
||||
|
||||
public function autologin()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
// if (!$this->isLogin) {
|
||||
// $this->sys_error("Invalid Token");
|
||||
// exit;
|
||||
// }
|
||||
$userID = $prm['userID'];
|
||||
$username = $prm['username'];
|
||||
$targetUrl = $prm['targetUrl'];
|
||||
$xcode = $prm['xcode'];
|
||||
$xcode_encrypt = $this->encrypt($targetUrl, $username);
|
||||
if ($xcode_encrypt != $xcode) {
|
||||
$this->sys_error("Invalid xcode");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT * FROM one_mitra.m_user WHERE M_UserUsername = ? AND M_UserID = ? AND M_UserIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$username, $userID]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("Error update user");
|
||||
exit;
|
||||
}
|
||||
$data = $query->result_array();
|
||||
if (count($data) == 0) {
|
||||
$this->sys_error("User not found");
|
||||
exit;
|
||||
}
|
||||
$query = $this->db->query(
|
||||
"SELECT M_UserID,
|
||||
M_UserUsername,
|
||||
M_UserM_CompanyID,
|
||||
M_UserM_MouID,
|
||||
M_CompanyName as company_name,
|
||||
M_UserS_RegionalID
|
||||
from one_mitra.m_user
|
||||
JOIN m_company ON M_UserM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
where M_UserUsername= ? and M_UserID= ?
|
||||
and M_UserIsActive = 'Y'
|
||||
",
|
||||
array($prm["username"], $userID)
|
||||
);
|
||||
// print_r($this->db_regional->last_query());
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message, $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$user = $rows[0];
|
||||
$user['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$token = JWT::encode($user, $this->SECRET_KEY);
|
||||
$data = array(
|
||||
"user" => $user,
|
||||
"token" => $token
|
||||
);
|
||||
|
||||
$query = $this->db->query("UPDATE one_mitra.m_user
|
||||
SET M_UserIsLoggedIn = 'Y',
|
||||
M_UserLastAccess = now(),
|
||||
M_UserActiveToken = '{$token}'
|
||||
WHERE M_UserID = ?
|
||||
", array($user['M_UserID']));
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $this->db->query("INSERT INTO mitra_log.log_login
|
||||
(Log_LoginDateTime,
|
||||
Log_LoginIP,
|
||||
Log_LoginType,
|
||||
Log_LoginStatus,
|
||||
Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGIN', 'SUCCESS', $prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($data);
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
|
||||
public function request_mitra_token() {
|
||||
// userID , userName, targetUrl
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$username = $prm['username'];
|
||||
$targetUrl = $prm['targetUrl'];
|
||||
$xcode = $this->encrypt($targetUrl, $username);
|
||||
$fields = [
|
||||
'token' => $prm['token'],
|
||||
'userID' => $prm['userID'],
|
||||
'username' => $username,
|
||||
'targetUrl' => $targetUrl,
|
||||
'xcode' => $xcode
|
||||
];
|
||||
|
||||
$dest_url = $targetUrl . "/one-api/one_mitra/authchange/autologin";
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $dest_url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if ($response === false) {
|
||||
$this->sys_error("error get token from destination server");
|
||||
exit;
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$json_data = json_decode($response, true);
|
||||
$token = $json_data['data']['token'];
|
||||
$return = $targetUrl . "/" . "mitra-cb" ."/" . "?token=" . $token;
|
||||
|
||||
$this->sys_ok($return);
|
||||
}
|
||||
|
||||
}
|
||||
210
one-api/application/controllers/one_mitra/Dashboard.php
Normal file
210
one-api/application/controllers/one_mitra/Dashboard.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
class Dashboard extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function chartdata()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
//month/year
|
||||
$filter = 'month';
|
||||
if (isset($prm['filter'])) {
|
||||
$filter = $prm['filter'];
|
||||
}
|
||||
$company_id = $prm['company_id'];
|
||||
$filter_sql = "";
|
||||
$filter_sql2 = "";
|
||||
$filter_sql_total = "";
|
||||
$select_sql = "";
|
||||
if ($filter == 'month') {
|
||||
$select_sql = "DATE_FORMAT(T_OrderDate, '%d') AS day";
|
||||
$filter_sql2 = "AND MONTH(T_OrderDate) = MONTH(CURDATE())";
|
||||
$filter_sql = ", DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day";
|
||||
$filter_sql_total = " DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day";
|
||||
}
|
||||
if ($filter == 'year') {
|
||||
$select_sql = "DATE_FORMAT(T_OrderDate, '%m') AS month";
|
||||
|
||||
$filter_sql = ", DATE_FORMAT(T_OrderDate, '%Y-%m') ORDER BY month";
|
||||
$filter_sql_total = " DATE_FORMAT(T_OrderDate, '%Y-%m') ORDER BY month";
|
||||
}
|
||||
// SELECT COUNT(T_OrderID) AS total,
|
||||
// T_OrderStatus AS status,
|
||||
// DATE_FORMAT(T_OrderDate, '%d') AS day
|
||||
// from one_mitra.t_order
|
||||
// WHERE T_OrderIsActive = 'Y'
|
||||
// AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
// AND T_OrderM_CompanyID = 1222
|
||||
// GROUP BY T_OrderStatus
|
||||
// ,DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day
|
||||
|
||||
$sql = "SELECT COUNT(T_OrderID) AS total,
|
||||
T_OrderStatus AS status,
|
||||
$select_sql
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
$filter_sql2
|
||||
AND T_OrderM_CompanyID = ?
|
||||
GROUP BY T_OrderStatus
|
||||
$filter_sql";
|
||||
$query = $this->db->query($sql, [$company_id]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$data = $query->result_array();
|
||||
$sql_total = "SELECT COUNT(T_OrderID) AS total,
|
||||
T_OrderStatus AS status,
|
||||
$select_sql
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
$filter_sql2
|
||||
AND T_OrderM_CompanyID = ?
|
||||
GROUP BY
|
||||
$filter_sql_total";
|
||||
$query_total = $this->db->query($sql_total, [$company_id]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$data_total = $query_total->result_array();
|
||||
$result = array(
|
||||
"N" => [],
|
||||
"S" => [],
|
||||
"Y" => [],
|
||||
"T" => [],
|
||||
"last_query" => $this->db->last_query()
|
||||
);
|
||||
// N = New, S= Send, P= Parsial, D=Done,
|
||||
if ($filter == 'month') {
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if ($data[$i]['status'] == 'N') {
|
||||
$result['N'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'S') {
|
||||
$result['S'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'Y') {
|
||||
$result['Y'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($data_total); $i++) {
|
||||
$result['T'][] = "{$data_total[$i]['day']}|{$data_total[$i]['total']}";
|
||||
}
|
||||
}
|
||||
if ($filter == 'year') {
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if ($data[$i]['status'] == 'N') {
|
||||
$result['N'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'S') {
|
||||
$result['S'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'Y') {
|
||||
$result['Y'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($data_total); $i++) {
|
||||
$result['T'][] = "{$data_total[$i]['month']}|{$data_total[$i]['total']}";
|
||||
}
|
||||
}
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
|
||||
$companyID = $prm['company_id'];
|
||||
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS id,
|
||||
DATE_FORMAT(T_OrderDeliveryDate, '%d/%m/%Y') AS date,
|
||||
T_OrderDeliveryNumber AS order_number,
|
||||
M_UserUsername AS pic,
|
||||
T_DeliveryTypeName AS type,
|
||||
T_OrderDeliveryStatus AS status,
|
||||
M_BranchName AS destination
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN one_mitra.t_deliverytype
|
||||
ON T_OrderDeliveryT_DeliverytypeID = T_DeliveryTypeID
|
||||
AND T_DeliveryTypeIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON T_OrderDeliveryDestination = M_BranchID
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND T_OrderDeliveryStatus IN ('S', 'P')
|
||||
ORDER BY T_OrderDeliveryDate DESC
|
||||
";
|
||||
$query = $this->db->query($sql, [$companyID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
608
one-api/application/controllers/one_mitra/Deliveryorder.php
Normal file
608
one-api/application/controllers/one_mitra/Deliveryorder.php
Normal file
@@ -0,0 +1,608 @@
|
||||
<?php
|
||||
|
||||
class Deliveryorder extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function getdeliverytype()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_DeliveryTypeID AS id,
|
||||
T_DeliveryTypeName AS name,
|
||||
T_DeliveryTypeIsAgent AS isAgent
|
||||
FROM one_mitra.t_deliverytype
|
||||
WHERE T_DeliveryTypeIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
$company_id = 0;
|
||||
if (isset($prm['company_id'])) {
|
||||
$company_id = trim($prm["company_id"]);
|
||||
$company_id = $prm['company_id'];
|
||||
} else {
|
||||
$this->sys_error("company_id is mandatory");
|
||||
}
|
||||
$regional_id = 0;
|
||||
if (isset($prm['regional_id'])) {
|
||||
$regional_id = trim($prm["regional_id"]);
|
||||
$regional_id = $prm['regional_id'];
|
||||
} else {
|
||||
$this->sys_error("regional_id is mandatory");
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_OrderID AS order_id,
|
||||
T_OrderNumber AS order_number,
|
||||
M_PatientID AS patient_id,
|
||||
M_PatientName AS patient_name,
|
||||
T_OrderM_MouID AS mouID,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestName SEPARATOR '|') AS test,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketName SEPARATOR '|') AS packet
|
||||
FROM one_mitra.t_order
|
||||
JOIN one_mitra.m_patient ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderM_CompanyID = ?
|
||||
AND T_OrderIsActive = 'Y'
|
||||
AND T_OrderS_RegionalID = ?
|
||||
AND T_OrderID NOT IN (SELECT T_OrderDetailDeliveryT_OrderID FROM
|
||||
one_mitra.t_orderdetaildelivery WHERE T_OrderDetailDeliveryIsActive ='Y'
|
||||
AND T_OrderDetailDeliveryM_CompanyID = ?)
|
||||
GROUP BY T_OrderID";
|
||||
$query = $this->db->query($sql, [$company_id, $regional_id, $company_id]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$arrOrder = $query->result_array();
|
||||
$result = [];
|
||||
for ($i = 0; $i < count($arrOrder); $i++) {
|
||||
$test = explode('|', $arrOrder[$i]['test']);
|
||||
$packet = explode('|', $arrOrder[$i]['packet']);
|
||||
|
||||
$sql = "SELECT
|
||||
M_UserMouID as userMouID,
|
||||
M_UserMouM_MouID as userMouMouID,
|
||||
M_UserMouAliasName as userMouName,
|
||||
M_UserMouIsDefault as userMouIsDefault
|
||||
FROM one_mitra.m_user_mou
|
||||
WHERE M_UserMouM_UserID = ? AND M_UserMouM_MouID = ?";
|
||||
$qry = $this->db_regional->query($sql, [$userID, $arrOrder[$i]['mouID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error('Error get mou');
|
||||
exit;
|
||||
}
|
||||
$mou = $qry->result_array();
|
||||
$fnlMou = array();
|
||||
if (count($mou) > 0) {
|
||||
$fnlMou = $mou[0];
|
||||
} else {
|
||||
$fnlMou = array(
|
||||
"userMouID" => "0",
|
||||
"userMouMouID" => '0',
|
||||
"userMouName" => '',
|
||||
"userMouIsDefault" => ''
|
||||
);
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
"order_id" => $arrOrder[$i]['order_id'],
|
||||
"order_number" => $arrOrder[$i]['order_number'],
|
||||
"patient_id" => $arrOrder[$i]['patient_id'],
|
||||
"patient_name" => $arrOrder[$i]['patient_name'],
|
||||
"sample" => [],
|
||||
"mou" => $fnlMou,
|
||||
"bahan" => [],
|
||||
"tests" => array_merge($test, $packet)
|
||||
];
|
||||
};
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdestination()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName branch_name
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'";
|
||||
$query = $this->db_regional->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function addDelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$order = $prm['order'];
|
||||
$orderDetail = $prm['order_detail'];
|
||||
// T_OrderDeliveryID int(11) Auto Increment
|
||||
// T_OrderDeliveryNumber varchar(25)
|
||||
// T_OrderDeliveryStaffID int(11)
|
||||
// T_OrderDeliveryNoRef varchar(25)
|
||||
// T_OrderDeliveryDate date
|
||||
// T_OrderDeliveryDestination int(11) Branch ID
|
||||
// T_OrderDeliveryBoxTemperature varchar(25)
|
||||
// T_OrderDeliveryT_DeliverytypeID int(11)
|
||||
// T_OrderDeliveryReciptNumber varchar(40)
|
||||
// T_OrderDeliveryNote tinytext
|
||||
// T_OrderDeliveryIsActive char(1) [Y]
|
||||
// T_OrderDeliveryCreated datetime [current_timestamp()]
|
||||
// T_OrderDeliveryLastUpdated
|
||||
$this->db->trans_begin();
|
||||
$sql = "SELECT one_mitra.fn_numbering('SJ') as number";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$message = $this->db->error();
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$number = $qry->result_array()[0]['number'];
|
||||
$get2first = substr($number, 0, 2);
|
||||
$getDate = strval(date("ym"));
|
||||
$newNumber = $get2first . $order['branch_code'] . $getDate . substr($number, -3);
|
||||
$orderDelivery = [
|
||||
"T_OrderDeliveryStaffID" => $order['staff_id'],
|
||||
"T_OrderDeliveryNumber" => $newNumber,
|
||||
"T_OrderDeliveryNoRef" => $order['no_ref'],
|
||||
"T_OrderDeliveryDate" => date('Y-m-d', strtotime($order['date'])),
|
||||
"T_OrderDeliveryDestination" => $order['destination_id'],
|
||||
"T_OrderDeliveryRegionalID" => $order['regional_id'],
|
||||
"T_OrderDeliveryBoxTemperature" => $order['temperature'],
|
||||
"T_OrderDeliveryT_DeliverytypeID" => $order['type_id'],
|
||||
"T_OrderDeliveryReciptNumber" => $order['no_resi'],
|
||||
"T_OrderDeliveryNote" => $order['note'],
|
||||
"T_OrderDeliveryM_CompanyID" => $order['company_id'],
|
||||
];
|
||||
$this->db->insert('one_mitra.t_orderdelivery', $orderDelivery);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DELIVERY", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$deliveryID = $this->db->insert_id();
|
||||
|
||||
for ($i = 0; $i < count($orderDetail); $i++) {
|
||||
// Column Type Comment
|
||||
// T_OrderDetailDeliveryID int(11) Auto Increment
|
||||
// T_OrderDetailDeliveryT_OrderDeliveryID int(11)
|
||||
// T_OrderDetailDeliveryT_OrderID int(11)
|
||||
// T_OrderDetailDeliveryIsActive char(1) [Y]
|
||||
// T_OrderDetailDeliveryCreated datetime [current_timestamp()]
|
||||
// T_OrderDetailDeliveryLastUpdated
|
||||
|
||||
$deliveryDetail = [
|
||||
"T_OrderDetailDeliveryT_OrderDeliveryID" => $deliveryID,
|
||||
"T_OrderDetailDeliveryT_OrderID" => $orderDetail[$i]['order_id'],
|
||||
"T_OrderDetailDeliveryM_CompanyID" => $order['company_id'],
|
||||
];
|
||||
$this->db->insert('one_mitra.t_orderdetaildelivery', $deliveryDetail);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DELIVERY DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$result = [
|
||||
"deliveryID" => $deliveryID,
|
||||
"orderNumber" => $newNumber,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
$startDate = $prm['start_date'];
|
||||
$endDate = $prm['end_date'];
|
||||
// 1 => tanggal surat jalan
|
||||
// 2 => tanggal kedatangan
|
||||
$datetype = $prm['date_type'];
|
||||
$datetypeSql = "T_OrderDeliveryCreated";
|
||||
if (intval($datetype) == 1) {
|
||||
$datetypeSql = "T_OrderDeliveryCreated";
|
||||
} else if (intval($datetype) == 2) {
|
||||
$datetypeSql = "T_OrderDeliveryDate";
|
||||
}
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
$sql_total = "SELECT COUNT(T_OrderDeliveryID) AS total
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON T_OrderDeliveryDestination = M_BranchID
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND (T_OrderDeliveryNumber LIKE ?
|
||||
OR M_UserUsername LIKE ? OR M_BranchName LIKE ?)
|
||||
AND T_OrderDeliveryRegionalID = ?
|
||||
AND $datetypeSql >= ? AND $datetypeSql <= ?";
|
||||
$query_total = $this->db->query($sql_total, [$companyID, $keyword, $keyword, $keyword, $regionalID, $startDate, $endDate]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$last_qry = $this->db->last_query();
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
// print_r($totals);
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS id,
|
||||
DATE_FORMAT(T_OrderDeliveryDate, '%d/%m/%Y') AS date,
|
||||
DATE_FORMAT(T_OrderDeliveryCreated, '%d/%m/%Y') AS date_sj,
|
||||
T_OrderDeliveryNumber AS order_number,
|
||||
M_UserUsername AS pic,
|
||||
T_OrderDeliveryStatus AS status,
|
||||
M_BranchName AS destination
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON T_OrderDeliveryDestination = M_BranchID
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND (T_OrderDeliveryNumber LIKE ?
|
||||
OR M_UserUsername LIKE ? OR M_BranchName LIKE ?)
|
||||
AND T_OrderDeliveryRegionalID = ?
|
||||
AND DATE_FORMAT($datetypeSql, '%Y-%m-%d') >= ? AND DATE_FORMAT($datetypeSql, '%Y-%m-%d') <= ?
|
||||
ORDER BY $datetypeSql DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$query = $this->db->query($sql, [$companyID, $keyword, $keyword, $keyword, $regionalID, $startDate, $endDate, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage),
|
||||
"qry_total" => $this->db->last_query(),
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function detaildelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS delivery_id,
|
||||
T_OrderDeliveryNumber AS delivery_number,
|
||||
T_OrderNumber AS order_number,
|
||||
T_OrderDetailDeliveryID AS delivery_detail_id,
|
||||
T_OrderDetailDeliveryT_OrderID AS order_id,
|
||||
DATE_FORMAT(T_OrderDate, '%d/%m/%Y') AS date,
|
||||
M_PatientName AS patient_name,
|
||||
T_OrderStatus AS status,
|
||||
one_mitra.fn_get_acc_sample(T_OrderDetailDeliveryT_OrderID) AS accepted_sample,
|
||||
one_mitra.fn_get_rejct_sample(T_OrderDetailDeliveryT_OrderID) AS rejected_sample
|
||||
FROM
|
||||
one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDeliveryID = T_OrderDetailDeliveryT_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
JOIN one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderIsActive = 'Y'
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
WHERE T_OrderDeliveryID = ?
|
||||
AND T_OrderDeliveryIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function cancel()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_orderdelivery SET T_OrderDeliveryIsActive = 'N'
|
||||
WHERE T_OrderDeliveryID = ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_orderdetaildelivery SET T_OrderDetailDeliveryIsActive = 'N'
|
||||
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function send()
|
||||
{
|
||||
try {
|
||||
// $aql = "UPDATE t_orderdelivery SET T_OrderDeliveryStatus = 'S'
|
||||
// WHERE T_OrderDeliveryID = 1;
|
||||
|
||||
// UPDATE t_order SET T_OrderStatus = 'S'
|
||||
// WHERE T_OrderID IN (
|
||||
// SELECT T_OrderDetailDeliveryT_OrderID
|
||||
// FROM t_orderdetaildelivery
|
||||
// WHERE T_OrderDetailDeliveryT_OrderDeliveryID = 1)";
|
||||
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_orderdelivery SET T_OrderDeliveryStatus = 'S'
|
||||
WHERE T_OrderDeliveryID = ?;
|
||||
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_order SET T_OrderStatus = 'S'
|
||||
WHERE T_OrderID IN (
|
||||
SELECT T_OrderDetailDeliveryT_OrderID
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = ?)
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getregional()
|
||||
{
|
||||
try {
|
||||
|
||||
$sql_regional = "SELECT
|
||||
S_RegionalID AS regional_id,
|
||||
S_RegionalName AS regional_name
|
||||
FROM s_regional WHERE S_RegionalIsActive = 'Y'";
|
||||
$query_regional = $this->db->query($sql_regional, []);
|
||||
if (!$query_regional) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$regionals = $query_regional->result_array();
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName AS branch_name,
|
||||
M_BranchS_RegionalID AS regional_id
|
||||
FROM m_branch Where M_BranchIsActive = 'Y'";
|
||||
$query_branch = $this->db->query($sql_branch, []);
|
||||
if (!$query_branch) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$branchs = $query_branch->result_array();
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
$regionals[$i]['branch'] = [];
|
||||
}
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
for ($j = 0; $j < count($branchs); $j++) {
|
||||
if ($regionals[$i]['regional_id'] == $branchs[$j]['regional_id']) {
|
||||
$regionals[$i]['branch'][] = $branchs[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->sys_ok($regionals);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function sendqrcode()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$arr_order_id = 0;
|
||||
if (isset($prm['arr_order_id'])) {
|
||||
$arr_order_id = $prm['arr_order_id'];
|
||||
} else {
|
||||
$this->sys_error("arr_order_id is mandatory");
|
||||
}
|
||||
$arr_order_id = implode(",", $arr_order_id);
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderIsQRCode = 'Y'
|
||||
WHERE T_OrderID IN ($arr_order_id)
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
print_r($this->db->last_query());
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($this->db->last_query());
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
750
one-api/application/controllers/one_mitra/DownloadOrder.php
Normal file
750
one-api/application/controllers/one_mitra/DownloadOrder.php
Normal file
@@ -0,0 +1,750 @@
|
||||
<?php
|
||||
class DownloadOrder extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Api: Download Order Mitra DEVKEDUNGDORORAYA";
|
||||
}
|
||||
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
|
||||
function reply_gz($resp, $debug = "")
|
||||
{
|
||||
if ($debug != "") {
|
||||
echo json_encode($resp);
|
||||
} else {
|
||||
echo gzcompress(json_encode($resp));
|
||||
}
|
||||
}
|
||||
|
||||
function get_param()
|
||||
{
|
||||
$body = file_get_contents("php://input");
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
function get_param_z()
|
||||
{
|
||||
$body_z = file_get_contents("php://input");
|
||||
$body = gzuncompress($body_z);
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
// t_orderdelivery
|
||||
function getData_t_orderdelivery($wherein_T_OrderDeliveryID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdelivery
|
||||
WHERE T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryID IN ($wherein_T_OrderDeliveryID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery for get data | func getData_t_orderdelivery " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
// print_r($rows_fields);
|
||||
}
|
||||
|
||||
// t_orderdetaildelivery
|
||||
function getData_t_orderdetaildelivery($wherein_T_OrderDetailDeliveryID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDetailDeliveryID IN ($wherein_T_OrderDetailDeliveryID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetaildelivery for get data | func getData_t_orderdetaildelivery " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_order
|
||||
function getData_t_order($wherein_T_OrderID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID IN ($wherein_T_OrderID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_order for get data | func getData_t_order " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetail
|
||||
function getData_t_orderdetail($wherein_T_OrderDetailID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetail
|
||||
WHERE T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailID IN ($wherein_T_OrderDetailID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetail for get data | func getData_t_orderdetail " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetailbahan
|
||||
function getData_t_orderdetailbahan($wherein_T_OrderDetailBahanID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailbahan
|
||||
WHERE T_OrderDetailBahanIsActive = 'Y'
|
||||
AND T_OrderDetailBahanID IN ($wherein_T_OrderDetailBahanID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailbahan for get data | func getData_t_orderdetailbahan " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetailsample
|
||||
function getData_t_orderdetailsample($wherein_T_OrderDetailSampleID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailsample
|
||||
WHERE T_OrderDetailSampleIsActive = 'Y'
|
||||
AND T_OrderDetailSampleID IN ($wherein_T_OrderDetailSampleID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailsample for get data | func getData_t_orderdetailsample " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// m_patient
|
||||
function getData_m_patient($wherein_M_PatientID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientID IN ($wherein_M_PatientID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailsample for get data | func getData_t_orderdetailsample " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
function getData_t_orderdetailpacket($packetID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailpacket
|
||||
WHERE T_OrderDetailPacketID in ($packetID)
|
||||
AND T_OrderDetailPacketIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailpacket for get data | func getData_t_orderdetailpacket " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
function reg_download_old($debug = "")
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$limit = 2;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
$branchId = ($debug != "") ? 1 : $prm['branchId'];
|
||||
// $branchId = 1;
|
||||
$branchCode = $prm['branchCode'];
|
||||
|
||||
$sql_pivot = "SELECT T_OrderDeliveryNumber,
|
||||
T_OrderDeliveryID
|
||||
from one_mitra.t_orderdelivery
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId";
|
||||
// LIMIT $limit ";
|
||||
|
||||
$qry_pivot = $this->db_regional->query($sql_pivot);
|
||||
|
||||
if (!$qry_pivot) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot = $qry_pivot->result_array();
|
||||
// print_r($rows_pivot);
|
||||
// exit;
|
||||
|
||||
// T_Order
|
||||
$sql_pivot_t_order = "SELECT
|
||||
T_OrderID
|
||||
from one_mitra.t_orderdelivery
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId
|
||||
join one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
|
||||
$qry_pivot_t_order = $this->db_regional->query($sql_pivot_t_order);
|
||||
|
||||
if (!$qry_pivot_t_order) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot_t_order = $qry_pivot_t_order->result_array();
|
||||
|
||||
// print_r($rows_pivot_t_order);
|
||||
// exit;
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = "";
|
||||
$string_wherein_T_OrderID = "";
|
||||
|
||||
$T_OrderDeliveryID_arr = [];
|
||||
$T_OrderID_arr = [];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
foreach ($rows_pivot as $key => $vx) {
|
||||
$T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
// $T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
}
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
// $string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
}
|
||||
|
||||
// T_Order
|
||||
if (count($rows_pivot_t_order) > 0) {
|
||||
foreach ($rows_pivot_t_order as $key => $vx) {
|
||||
// $T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
$T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
}
|
||||
|
||||
// $string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
$string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
}
|
||||
|
||||
$result = [
|
||||
"t_orderdelivery" => [],
|
||||
"t_orderdetaildelivery" => [],
|
||||
"t_order" => [],
|
||||
"t_orderdetail" => [],
|
||||
"t_orderdetailbahan" => [],
|
||||
"t_orderdetailsample" => [],
|
||||
];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
// ambil all data sesuai pivot
|
||||
|
||||
// 1. t_orderdelivery
|
||||
$t_orderdelivery = $this->getData_t_orderdelivery($string_wherein_T_OrderDeliveryID);
|
||||
|
||||
// 2. t_orderdetaildelivery
|
||||
$t_orderdetaildelivery = $this->getData_t_orderdetaildelivery($string_wherein_T_OrderDeliveryID);
|
||||
}
|
||||
|
||||
if (count($rows_pivot_t_order) > 0) {
|
||||
// 3. t_order
|
||||
$t_order = $this->getData_t_order($string_wherein_T_OrderID);
|
||||
|
||||
// 4. t_orderdetail
|
||||
$t_orderdetail = $this->getData_t_orderdetail($string_wherein_T_OrderID);
|
||||
|
||||
// 5. t_orderdetailbahan
|
||||
$t_orderdetailbahan = $this->getData_t_orderdetailbahan($string_wherein_T_OrderID);
|
||||
|
||||
// 6. t_orderdetailsample
|
||||
$t_orderdetailsample = $this->getData_t_orderdetailsample($string_wherein_T_OrderID);
|
||||
|
||||
$result["t_orderdelivery"] = $t_orderdelivery;
|
||||
$result["t_orderdetaildelivery"] = $t_orderdetaildelivery;
|
||||
$result["t_order"] = $t_order;
|
||||
$result["t_orderdetail"] = $t_orderdetail;
|
||||
$result["t_orderdetailbahan"] = $t_orderdetailbahan;
|
||||
$result["t_orderdetailsample"] = $t_orderdetailsample;
|
||||
|
||||
if ($debug != "") {
|
||||
echo "<pre>";
|
||||
echo print_r($result);
|
||||
echo "</pre>";
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(
|
||||
[
|
||||
"status" => "OK",
|
||||
"message" => "Data Ditemukan",
|
||||
"data" => [$result]
|
||||
]
|
||||
);
|
||||
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
// $result_x = array(
|
||||
// 'status' => 'OK',
|
||||
// "message" => "Tidak ada data terbaru",
|
||||
// "data" => [$result]
|
||||
// );
|
||||
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
} else {
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
$result_x = array(
|
||||
'status' => 'ERR',
|
||||
"message" => "Tidak ada data terbaru",
|
||||
"data" => []
|
||||
);
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
|
||||
echo json_encode($result_x);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$result = array(
|
||||
'status' => 'err',
|
||||
"message" => $message,
|
||||
);
|
||||
$this->reply_gz($result);
|
||||
}
|
||||
}
|
||||
|
||||
function reg_download($debug = "")
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$limit = 2;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
$branchId = ($debug != "") ? 1 : $prm['branchId'];
|
||||
// $branchId = 1;
|
||||
$branchCode = $prm['branchCode'];
|
||||
|
||||
$pickup_status = ($debug != "") ? "S" : $prm['pickup_status'];
|
||||
|
||||
$sql_pivot = "SELECT T_OrderDeliveryNumber,
|
||||
T_OrderDeliveryID,
|
||||
T_OrderID,
|
||||
T_OrderDetailID,
|
||||
T_OrderDetailBahanID,
|
||||
T_OrderDetailSampleID,
|
||||
M_PatientID,
|
||||
T_OrderDetailDeliveryID,
|
||||
T_OrderDetailPacketID
|
||||
from one_mitra.t_orderdelivery
|
||||
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId
|
||||
|
||||
join one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderIsActive = 'Y'
|
||||
|
||||
join one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
|
||||
LEFT join one_mitra.t_orderdetail
|
||||
ON T_OrderDetailOrderID = T_OrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
|
||||
left join one_mitra.t_orderdetailbahan
|
||||
ON T_OrderDetailBahanT_OrderID = T_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
|
||||
left join one_mitra.t_orderdetailsample
|
||||
ON T_OrderDetailSampleT_OrderID = T_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderDetailPacketOrderID = T_OrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
";
|
||||
// LIMIT $limit ";
|
||||
|
||||
$qry_pivot = $this->db_regional->query($sql_pivot);
|
||||
|
||||
if (!$qry_pivot) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot = $qry_pivot->result_array();
|
||||
$last_qry_pivot = $this->db_regional->last_query();
|
||||
|
||||
// print_r($rows_pivot_t_order);
|
||||
// exit;
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = "";
|
||||
$string_wherein_T_OrderDetailDeliveryID = "";
|
||||
$string_wherein_T_OrderID = "";
|
||||
$string_wherein_T_OrderDetailID = "";
|
||||
$string_wherein_T_OrderDetailBahanID = "";
|
||||
$string_wherein_T_OrderDetailSampleID = "";
|
||||
$string_wherein_M_PatientID = "";
|
||||
$string_wherein_T_OrderDetailPacketID = "";
|
||||
|
||||
$T_OrderDeliveryID_arr = [];
|
||||
$T_OrderDetailDeliveryID_arr = [];
|
||||
$T_OrderID_arr = [];
|
||||
$T_OrderDetailID_arr = [];
|
||||
$T_OrderDetailBahanID_arr = [];
|
||||
$T_OrderDetailSampleID_arr = [];
|
||||
$M_PatientID_arr = [];
|
||||
$T_OrderDetailPacketID_arr = [];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
foreach ($rows_pivot as $key => $vx) {
|
||||
$T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
$T_OrderDetailDeliveryID_arr[] = intval($vx['T_OrderDetailDeliveryID']);
|
||||
$T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
$T_OrderDetailID_arr[] = intval($vx['T_OrderDetailID']);
|
||||
$T_OrderDetailBahanID_arr[] = intval($vx['T_OrderDetailBahanID']);
|
||||
$T_OrderDetailSampleID_arr[] = intval($vx['T_OrderDetailSampleID']);
|
||||
$M_PatientID_arr[] = intval($vx['M_PatientID']);
|
||||
$T_OrderDetailPacketID_arr[] = intval($vx['T_OrderDetailPacketID']);
|
||||
}
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
$string_wherein_T_OrderDetailDeliveryID = implode(",", $T_OrderDetailDeliveryID_arr);
|
||||
$string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
$string_wherein_T_OrderDetailID = implode(",", $T_OrderDetailID_arr);
|
||||
$string_wherein_T_OrderDetailBahanID = implode(",", $T_OrderDetailBahanID_arr);
|
||||
$string_wherein_T_OrderDetailSampleID = implode(",", $T_OrderDetailSampleID_arr);
|
||||
$string_wherein_M_PatientID = implode(",", $M_PatientID_arr);
|
||||
$string_wherein_T_OrderDetailPacketID = implode(",", $T_OrderDetailPacketID_arr);
|
||||
}
|
||||
|
||||
$result = [
|
||||
"t_orderdelivery" => [],
|
||||
"t_orderdetaildelivery" => [],
|
||||
"t_order" => [],
|
||||
"t_orderdetail" => [],
|
||||
"t_orderdetailbahan" => [],
|
||||
"t_orderdetailsample" => [],
|
||||
"m_patient" => [],
|
||||
"t_orderdetailpacket" => []
|
||||
];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
// ambil all data sesuai pivot
|
||||
|
||||
// 1. t_orderdelivery
|
||||
$t_orderdelivery = $this->getData_t_orderdelivery($string_wherein_T_OrderDeliveryID);
|
||||
|
||||
// 2. t_orderdetaildelivery
|
||||
$t_orderdetaildelivery = $this->getData_t_orderdetaildelivery($string_wherein_T_OrderDetailDeliveryID);
|
||||
|
||||
// 3. t_order
|
||||
$t_order = $this->getData_t_order($string_wherein_T_OrderID);
|
||||
|
||||
// 4. t_orderdetail
|
||||
$t_orderdetail = $this->getData_t_orderdetail($string_wherein_T_OrderDetailID);
|
||||
|
||||
// 5. t_orderdetailbahan
|
||||
$t_orderdetailbahan = $this->getData_t_orderdetailbahan($string_wherein_T_OrderDetailBahanID);
|
||||
|
||||
// 6. t_orderdetailsample
|
||||
$t_orderdetailsample = $this->getData_t_orderdetailsample($string_wherein_T_OrderDetailSampleID);
|
||||
|
||||
// 7. m_patient
|
||||
$m_patient = $this->getData_m_patient($string_wherein_M_PatientID);
|
||||
|
||||
// 7. getData_t_orderdetailpacket
|
||||
$t_orderdetailpacket = $this->getData_t_orderdetailpacket($string_wherein_T_OrderDetailPacketID);
|
||||
|
||||
$result["t_orderdelivery"] = $t_orderdelivery;
|
||||
$result["t_orderdetaildelivery"] = $t_orderdetaildelivery;
|
||||
$result["t_order"] = $t_order;
|
||||
$result["t_orderdetail"] = $t_orderdetail;
|
||||
$result["t_orderdetailbahan"] = $t_orderdetailbahan;
|
||||
$result["t_orderdetailsample"] = $t_orderdetailsample;
|
||||
$result["m_patient"] = $m_patient;
|
||||
$result["t_orderdetailpacket"] = $t_orderdetailpacket;
|
||||
|
||||
if ($debug != "") {
|
||||
echo "<pre>";
|
||||
echo print_r($result);
|
||||
echo "</pre>";
|
||||
exit;
|
||||
}
|
||||
$result = [
|
||||
"status" => "OK",
|
||||
"message" => "Data Ditemukan",
|
||||
"data" => [$result]
|
||||
];
|
||||
|
||||
// echo json_encode(
|
||||
// [
|
||||
// "status" => "OK",
|
||||
// "message" => "Data Ditemukan",
|
||||
// "data" => [$result]
|
||||
// ]
|
||||
// );
|
||||
$this->reply_gz($result, $debug);
|
||||
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
// $result_x = array(
|
||||
// 'status' => 'OK',
|
||||
// "message" => "Tidak ada data terbaru",
|
||||
// "data" => [$result]
|
||||
// );
|
||||
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
} else {
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
$result_x = array(
|
||||
'status' => 'ERR',
|
||||
"message" => "Tidak ada data terbaru",
|
||||
// "qry_pivot" => $last_qry_pivot,
|
||||
"data" => []
|
||||
);
|
||||
$this->reply_gz($result_x, $debug);
|
||||
|
||||
// echo json_encode($result_x);
|
||||
// $this->reply_gz($result, $debug);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$result = array(
|
||||
'status' => 'err',
|
||||
"message" => $message,
|
||||
);
|
||||
$this->reply_gz($result);
|
||||
}
|
||||
}
|
||||
|
||||
function reg_update_is_download()
|
||||
{
|
||||
try {
|
||||
// $prm = $this->get_param();
|
||||
$prm = $this->get_param_z();
|
||||
$branchId = $prm['branchId'];
|
||||
// $branchCde = $prm['branchCode'];
|
||||
$dataOrder = $prm['data'];
|
||||
|
||||
$result = [];
|
||||
|
||||
if (count($dataOrder[0]['t_orderdelivery']) > 0) {
|
||||
for ($i = 0; $i < count($dataOrder[0]['t_orderdelivery']); $i++) {
|
||||
$id = $dataOrder[0]['t_orderdelivery'][$i]['T_OrderDeliveryID'];
|
||||
|
||||
$sqlUpdate = "UPDATE one_mitra.t_orderdelivery
|
||||
SET T_OrderDeliveryIsDownloaded = 'Y'
|
||||
, T_OrderDeliveryDownloadedDate = NOW()
|
||||
WHERE T_OrderDeliveryID = $id
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryDestination = $branchId";
|
||||
|
||||
$qryUpdate = $this->db->query($sqlUpdate);
|
||||
if (!$qryUpdate) {
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "update one_mitra.t_orderdelivery | func reg_update_is_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"message" => 'Berhasil Di Proses',
|
||||
// "data" => $dataOrder,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"message" => 'Berhasil Di Proses',
|
||||
// "data" => $dataOrder,
|
||||
// "sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUpdatePatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$branchID = $prm['branchId'];
|
||||
$sql = "SELECT T_OrderID,
|
||||
T_OrderDeliveryID,
|
||||
T_OrderIsQRCode,
|
||||
one_mitra.m_patient.*
|
||||
FROM one_mitra.m_patient
|
||||
JOIN one_mitra.t_order
|
||||
ON M_PatientID = T_OrderM_PatientID
|
||||
AND T_OrderIsActive = 'Y'
|
||||
JOIN one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderID = T_OrderDetailDeliveryT_OrderID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
JOIN one_mitra.t_orderdelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryStatus IN ('S', 'P')
|
||||
AND T_OrderDeliveryDestination = $branchID
|
||||
WHERE M_PatientLastUpdated > T_OrderDeliveryDownloadedDate";
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "function get update patient data | " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
$this->reply_gz($response);
|
||||
// $this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$result = $qry->result_array();
|
||||
// $this->sys_ok($result);
|
||||
$this->reply_gz(["status" => "OK", "data" => $result]);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateIsDownloadedDate()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$arrDeliveryId = $prm['arrDeliveryID'];
|
||||
// $this->reply_gz(["status" => "OK", "data" => $arrDeliveryId]);
|
||||
// exit;
|
||||
for ($i = 0; $i < count($arrDeliveryId); $i++) {
|
||||
$sql = "UPDATE one_mitra.t_orderdelivery
|
||||
SET T_OrderDeliveryDownloadedDate = NOW()
|
||||
WHERE T_OrderDeliveryID = ?";
|
||||
$qry = $this->db_regional->query($sql, [$arrDeliveryId[$i]]);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "function updateIsDownloadedDate | " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
$this->reply_gz($response);
|
||||
// $this->reply($response);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// $this->reply(["status" => "OK", "data" => $arrDeliveryId]);
|
||||
$this->reply_gz(["status" => "OK", "data" => $arrDeliveryId]);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
194
one-api/application/controllers/one_mitra/Fpp.php
Normal file
194
one-api/application/controllers/one_mitra/Fpp.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
class Fpp extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function load()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$mou_id = 0;
|
||||
if (isset($prm['mou_id'])) {
|
||||
$mou_id = trim($prm["mou_id"]);
|
||||
$mou_id = $prm['mou_id'];
|
||||
} else {
|
||||
$this->sys_error("mou_id is mandatory");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
group_concat(distinct concat(t_test.T_TestID,'^',t_test.T_TestName,'^',T_PriceTotal,'^', t_test.T_TestSasCode) separator '|') TestList,
|
||||
Nat_SubGroupName,
|
||||
child_test
|
||||
from ss_price_mou
|
||||
join t_test on T_PriceIsCito= 'N' and is_packet = 'N'
|
||||
AND Ss_PriceMouM_MouID = ?
|
||||
and ss_price_mou.T_TestID = t_test.T_TestID
|
||||
join nat_subgroup on t_test.T_TestNat_SubGroupID = Nat_SubGroupID
|
||||
group by Nat_SubGroupName
|
||||
order by Nat_SubGroupNat_GroupID";
|
||||
$qry = $this->db_regional->query($sql, [
|
||||
$mou_id,
|
||||
]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db_regional->error()["message"] .
|
||||
"|" .
|
||||
$this->db_regional->last_query(),
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
$filters = ["Home Service", "Cetak", "Layanan"];
|
||||
foreach ($rows as $key => $r) {
|
||||
$tab = $r["Nat_SubGroupName"];
|
||||
$result[] = ["tab" => $tab, "tab_id" => $key + 1, "is_paket" => "N", "items" => []];
|
||||
$idx = count($result) - 1;
|
||||
$a_px = explode("|", $r["TestList"]);
|
||||
foreach ($a_px as $px) {
|
||||
list($testID, $testName, $testPrice, $sasCode) = explode("^", $px);
|
||||
if ($testPrice == 0 && $r["child_test"] != "[]") {
|
||||
$child_test = json_decode($r["child_test"], true);
|
||||
foreach ($child_test as $t) {
|
||||
$testPrice += $t["T_PriceTotal"];
|
||||
}
|
||||
}
|
||||
$is_skip = false;
|
||||
foreach ($filters as $ft) {
|
||||
if (stripos($testName, $ft) !== false) {
|
||||
$is_skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($is_skip) {
|
||||
continue;
|
||||
}
|
||||
$items = [
|
||||
"testID" => $testID,
|
||||
"testName" => $testName,
|
||||
"testPrice" => $testPrice,
|
||||
"is_paket" => "N",
|
||||
"sasCode" => $sasCode
|
||||
];
|
||||
$result[$idx]["items"][] = $items;
|
||||
}
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_PacketID,
|
||||
T_PacketName,
|
||||
T_PacketPrice,
|
||||
T_PacketType,
|
||||
GROUP_CONCAT(T_TestName SEPARATOR ', ') AS detail,
|
||||
GROUP_CONCAT(T_TestID SEPARATOR ', ') AS tests
|
||||
FROM t_packet
|
||||
JOIN t_packetdetail
|
||||
ON T_PacketID = T_PacketDetailT_PacketID
|
||||
AND T_PacketDetailIsActive = 'Y'
|
||||
JOIN t_test
|
||||
ON T_PacketDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
AND T_TestIsPrice = 'Y'
|
||||
WHERE T_PacketIsActive = 'Y'
|
||||
AND T_PacketM_MouID = ?
|
||||
GROUP BY T_PacketID";
|
||||
$qry = $this->db_regional->query($sql, [
|
||||
$mou_id,
|
||||
]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db_regional->error()["message"] .
|
||||
"|" .
|
||||
$this->db_regional->last_query(),
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$paket = $qry->result_array();
|
||||
|
||||
$paket_data = [];
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
$items = [
|
||||
"testID" => $paket[$i]['T_PacketID'],
|
||||
"testName" => $paket[$i]['T_PacketName'],
|
||||
"testPrice" => $paket[$i]['T_PacketPrice'],
|
||||
"arrTest" => $paket[$i]['tests'],
|
||||
"type" => $paket[$i]['T_PacketType'],
|
||||
"is_paket" => "Y",
|
||||
"sasCode" => $paket[$i]['detail']
|
||||
];
|
||||
$paket_data[] = $items;
|
||||
}
|
||||
// $result[] = ["tab" => "Paket", "tab_id" => count($result) + 1, "is_paket" => "Y", "items" => $paket_data];
|
||||
array_unshift($result, ["tab" => "Paket", "tab_id" => count($result) + 1, "is_paket" => "Y", "items" => $paket_data]);
|
||||
for ($i = 0; $i < count($result); $i++) {
|
||||
$result[$i]["tab_id"] = $i + 1;
|
||||
}
|
||||
echo json_encode(["status" => "OK", "data" => $result]);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getMou()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $prm['userID'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_UserMouID as userMouID,
|
||||
M_UserMouM_MouID as userMouMouID,
|
||||
M_UserMouAliasName as userMouName,
|
||||
M_UserMouIsDefault as userMouIsDefault
|
||||
FROM one_mitra.m_user_mou
|
||||
WHERE M_UserMouM_UserID = ? AND M_UserMouIsActive = 'Y'";
|
||||
$qry = $this->db_regional->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error('Error get mou');
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$this->sys_ok($rows);
|
||||
}
|
||||
}
|
||||
701
one-api/application/controllers/one_mitra/Order.php
Normal file
701
one-api/application/controllers/one_mitra/Order.php
Normal file
@@ -0,0 +1,701 @@
|
||||
<?php
|
||||
|
||||
class Order extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function getorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
$startDate = $prm['start_date'];
|
||||
$endDate = $prm['end_date'];
|
||||
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
$sql_total = "SELECT
|
||||
COUNT(T_OrderID) AS total
|
||||
FROM one_mitra.t_order
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderDate >= ? AND T_OrderDate <= ?
|
||||
AND (T_OrderNumber LIKE ? OR M_PatientName LIKE ?)
|
||||
AND T_OrderM_CompanyID = ?
|
||||
AND T_OrderS_RegionalID = ?";
|
||||
$query_total = $this->db->query($sql_total, [$startDate, $endDate, $keyword, $keyword, $companyID, $regionalID]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
// print_r($totals);
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderID AS order_id,
|
||||
T_OrderNumber AS order_number,
|
||||
T_OrderM_PatientID AS patient_id,
|
||||
M_PatientName AS patient_name,
|
||||
DATE_FORMAT(T_OrderDate, '%Y-%m-%d') AS date,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestName SEPARATOR '|') AS tests,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketName SEPARATOR '|' ) AS packetName,
|
||||
IFNULL(T_OrderDetailDeliveryID, 'N') AS status,
|
||||
T_OrderM_MouID AS mouID,
|
||||
T_OrderIsQRCode AS is_qr,
|
||||
T_OrderStatus AS status_pemeriksaan,
|
||||
T_OrderStatusQR AS status_qr,
|
||||
M_PatientPrefix AS prefix,
|
||||
M_PatientSuffix AS suffix,
|
||||
M_PatientDOB AS dob,
|
||||
M_PatientNIK AS NIK,
|
||||
M_PatientNIP AS NIP,
|
||||
M_PatientTitleID AS title,
|
||||
M_PatientM_SexID AS sexID,
|
||||
M_PatientHP AS hp,
|
||||
M_PatientJabatan AS jabatan,
|
||||
M_PatientKedudukan AS kedudukan,
|
||||
M_PatientLocation AS lokasi,
|
||||
M_PatientJob AS pekerjaan,
|
||||
M_PatientNoRM AS noRM,
|
||||
M_PatientAddress AS address,
|
||||
T_OrderNote AS note,
|
||||
T_OrderDiagnosis AS diagnosis,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestID) AS testsID,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailID,'|',T_OrderDetailTestID, '|', T_OrderDetailTestDate)) AS testDetail,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailBahanID ,'|',T_OrderDetailBahanNat_BahanID, '|', T_OrderDetailBahanName,'|',T_OrderDetailBahanQty)) AS bahan,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailSampleID,'|',T_OrderDetailSampleNat_SampleTypeID, '|',T_OrderDetailSampleName,'|', T_OrderDetailSampleQty)) AS sample,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketT_PacketID) AS packet,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailPacketID, '|', T_OrderDetailPacketT_PacketID )) AS packetDetail
|
||||
FROM one_mitra.t_order
|
||||
LEFT JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderID = T_OrderDetailDeliveryT_OrderID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailsample
|
||||
ON T_OrderID = T_OrderDetailSampleT_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailbahan
|
||||
ON T_OrderID = T_OrderDetailBahanT_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderDate >= ? AND T_OrderDate <= ?
|
||||
AND (T_OrderNumber LIKE ? OR M_PatientName LIKE ?)
|
||||
AND T_OrderM_CompanyID = ?
|
||||
AND T_OrderS_RegionalID = ?
|
||||
GROUP BY T_OrderID
|
||||
LIMIT ? OFFSET ?";
|
||||
$query = $this->db->query($sql, [$startDate, $endDate, $keyword, $keyword, $companyID, $regionalID, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
// packetName
|
||||
for ($i = 0; $i < count($search); $i++) {
|
||||
$tes = explode('|', $search[$i]['tests']);
|
||||
$bahan = explode(',', $search[$i]['bahan']);
|
||||
$paket = explode(',', $search[$i]['packet']);
|
||||
$paketName = explode('|', $search[$i]['packetName']);
|
||||
$sample = explode(',', $search[$i]['sample']);
|
||||
$testsID = explode(',', $search[$i]['testsID']);
|
||||
$testdetail = explode(',', $search[$i]['testDetail']);
|
||||
$packetDetail = explode(',', $search[$i]['packetDetail']);
|
||||
$search[$i]['tests'] = array_merge($tes, $paketName);
|
||||
$search[$i]['bahan'] = $bahan;
|
||||
$search[$i]['sample'] = $sample;
|
||||
$search[$i]['testsID'] = $testsID;
|
||||
$search[$i]['testDetail'] = $testdetail;
|
||||
$search[$i]['packet'] = $paket;
|
||||
$search[$i]['packetDetail'] = $packetDetail;
|
||||
|
||||
$sql = "SELECT
|
||||
M_UserMouID as userMouID,
|
||||
M_UserMouM_MouID as userMouMouID,
|
||||
M_UserMouAliasName as userMouName,
|
||||
M_UserMouIsDefault as userMouIsDefault
|
||||
FROM one_mitra.m_user_mou
|
||||
WHERE M_UserMouM_UserID = ? AND M_UserMouM_MouID = ?";
|
||||
$qry = $this->db_regional->query($sql, [$userID, $search[$i]['mouID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error('Error get mou');
|
||||
exit;
|
||||
}
|
||||
$mou = $qry->result_array();
|
||||
if (count($mou) > 0) {
|
||||
$search[$i]['mou'] = $mou[0];
|
||||
} else {
|
||||
$search[$i]['mou'] = array(
|
||||
"userMouID" => "0",
|
||||
"userMouMouID" => '0',
|
||||
"userMouName" => '',
|
||||
"userMouIsDefault" => ''
|
||||
);
|
||||
}
|
||||
// $tes = array_merge($tes, $paketName);
|
||||
}
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage)
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function editOrder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$tests = $prm['tests'];
|
||||
$specimens = $prm['specimens'];
|
||||
$bahan = $prm['bahan'];
|
||||
$orderID = $prm['orderID'];
|
||||
$patientID = $prm['patient_id'];
|
||||
$paket = $prm['paket'];
|
||||
$mouID = $prm['userMouID'];
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
// print_r($this->sys_user);
|
||||
// exit;
|
||||
$this->db->trans_begin();
|
||||
$sql_old = "SELECT DISTINCT
|
||||
T_OrderID AS id,
|
||||
T_OrderNote AS note,
|
||||
T_OrderDiagnosis AS diagnosis,
|
||||
T_OrderTotal AS total,
|
||||
T_OrderDetailID AS detailID,
|
||||
T_OrderDetailTestID AS testID,
|
||||
T_OrderDetailTotal AS detailTotal,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailID, '|',T_OrderDetailTestID , '|',T_OrderDetailTotal )SEPARATOR '^') AS detail,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailBahanID , '|',T_OrderDetailBahanNat_BahanID , '|',T_OrderDetailBahanQty ) SEPARATOR '^') AS bahan,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailSampleID , '|',T_OrderDetailSampleNat_SampleTypeID, '|',T_OrderDetailSampleQty)SEPARATOR '^') AS sample,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailPacketID, '|', T_OrderDetailPacketT_PacketID )) AS packet
|
||||
FROM
|
||||
one_mitra.t_order
|
||||
JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailsample
|
||||
ON T_OrderID = T_OrderDetailSampleT_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailbahan
|
||||
ON T_OrderID = T_OrderDetailBahanT_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query_old = $this->db->query($sql_old, [$orderID]);
|
||||
if (!$query_old) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$rst_old = $query_old->result_array()[0];
|
||||
//order detail old
|
||||
$detail_old = explode('^', $rst_old['detail']);
|
||||
$arr_detail = array();
|
||||
$arr_detailID = array();
|
||||
for ($i = 0; $i < count($detail_old); $i++) {
|
||||
$splitted = explode('|', $detail_old[$i]);
|
||||
$arr_detail[] = [
|
||||
"id" => $splitted[0],
|
||||
"testID" => $splitted[1],
|
||||
];
|
||||
$arr_detailID[] = $splitted[1];
|
||||
}
|
||||
$rst_old['detail'] = $arr_detail;
|
||||
//sample detail old
|
||||
$sample_old = explode('^', $rst_old['sample']);
|
||||
$arr_sample = array();
|
||||
for ($i = 0; $i < count($sample_old); $i++) {
|
||||
$splitted = explode('|', $sample_old[$i]);
|
||||
$arr_sample[] = [
|
||||
"id" => $splitted[0],
|
||||
"sampleID" => $splitted[1],
|
||||
"qty" => $splitted[2],
|
||||
];
|
||||
}
|
||||
$rst_old['sample'] = $arr_sample;
|
||||
//bahan detail old
|
||||
$bahan_old = explode('^', $rst_old['bahan']);
|
||||
$arr_bahan = array();
|
||||
for ($i = 0; $i < count($bahan_old); $i++) {
|
||||
$splitted = explode('|', $bahan_old[$i]);
|
||||
$arr_bahan[] = [
|
||||
"id" => $splitted[0],
|
||||
"bahanID" => $splitted[1],
|
||||
"qty" => $splitted[2],
|
||||
];
|
||||
}
|
||||
$rst_old['bahan'] = $arr_bahan;
|
||||
//paket detail old
|
||||
$paket_old = explode(',', $rst_old['packet']);
|
||||
$arr_paket = array();
|
||||
for ($i = 0; $i < count($paket_old); $i++) {
|
||||
$splitted = explode('|', $paket_old[$i]);
|
||||
$arr_paket[] = [
|
||||
"id" => $splitted[0],
|
||||
"paket_id" => $splitted[1],
|
||||
];
|
||||
}
|
||||
$rst_old['packet'] = $arr_paket;
|
||||
|
||||
|
||||
$this->db->set("T_OrderNote", $patient['note'])
|
||||
->set("T_OrderDiagnosis", $patient['diagnosis'])
|
||||
->set("T_OrderTotal", intval($prm['total']))
|
||||
->set("T_OrderUserID", $userid)
|
||||
->set("T_OrderM_MouID", $mouID)
|
||||
->where("T_OrderID", $orderID)->update('one_mitra.t_order');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("m_patient rows", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$arr_new_test = array();
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
$arr_new_test[] = $tests[$i]['id'];
|
||||
}
|
||||
$arr_sampleIdnew = array();
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
$arr_sampleIdnew[] = $specimens[$i]['id'];
|
||||
}
|
||||
$arr_bahanIdnew = array();
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
$arr_bahanIdnew[] = $bahan[$i]['id'];
|
||||
}
|
||||
$arr_paketIdnew = array();
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
$arr_paketIdnew[] = $paket[$i]['id'];
|
||||
}
|
||||
// $this->db->trans_commit();
|
||||
|
||||
// $this->sys_ok($rst_old);
|
||||
// $this->sys_ok(["new test" => $arr_new_test, "old_test" => $arr_detail]);
|
||||
// return;
|
||||
|
||||
//deleted test
|
||||
for ($i = 0; $i < count($arr_detail); $i++) {
|
||||
//deleted
|
||||
if (!in_array($arr_detail[$i]['testID'], $arr_new_test)) {
|
||||
$this->db->set("T_OrderDetailIsActive", 'N')
|
||||
->where("T_OrderDetailID", $arr_detail[$i]['id'])->update('one_mitra.t_orderdetail');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
//New test
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
//new
|
||||
if ($tests[$i]['detailID'] == 'new') {
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailOrderID" => $orderID,
|
||||
"T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
"T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
"T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
"T_OrderDetailTestDate" => $dt,
|
||||
"T_OrderDetailUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
$this->db->set("T_OrderDetailTestDate", $dt)
|
||||
->set("T_OrderDetailUserID", $userid)
|
||||
->where("T_OrderDetailID", $tests[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetail');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// if (!in_array($tests[$i]['id'], $arr_detailID)) {
|
||||
// $coba = strtotime($tests[$i]['date']);
|
||||
// $dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
// $order = [
|
||||
// "T_OrderDetailOrderID" => $orderID,
|
||||
// "T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
// "T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
// "T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
// "T_OrderDetailTestDate" => $dt,
|
||||
// "T_OrderDetailUserID" => $userid,
|
||||
|
||||
// ];
|
||||
|
||||
// $this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
// $err = $this->db->error();
|
||||
// if (
|
||||
// $err['message'] != ""
|
||||
// ) {
|
||||
// $this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
// $this->db->trans_rollback();
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// $this->sys_ok($rst_old);
|
||||
// $this->sys_ok(["new sample" => $arr_sampleIdnew, "old_sample" => $arr_sample]);
|
||||
// return;
|
||||
//deleted sample
|
||||
for ($i = 0; $i < count($arr_sample); $i++) {
|
||||
if (!in_array($arr_sample[$i]['sampleID'], $arr_sampleIdnew)) {
|
||||
$this->db->set("T_OrderDetailSampleIsActive", 'N')
|
||||
->where("T_OrderDetailSampleID", $arr_sample[$i]['id'])->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
//new & updated sample
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
if ($specimens[$i]['detailID'] == "new") {
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$order = [
|
||||
"T_OrderDetailSampleT_OrderID" => $orderID,
|
||||
"T_OrderDetailSampleNat_SampleTypeID" => $specimens[$i]['id'],
|
||||
"T_OrderDetailSampleName" => $specimens[$i]['name'],
|
||||
"T_OrderDetailSampleQty" => $specimens[$i]['amount'],
|
||||
"T_OrderDetailSampleUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailsample', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$this->db->set("T_OrderDetailSampleQty", $specimens[$i]['amount'])
|
||||
->set("T_OrderDetailSampleUserID", $userid)
|
||||
->where("T_OrderDetailSampleID", $specimens[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
if (!in_array($arr_sample[$i]['sampleID'], $arr_sampleIdnew)) {
|
||||
$this->db->set("T_OrderDetailSampleIsActive", 'N')
|
||||
->where("T_OrderDetailSampleID", $specimens[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//deleted bahan
|
||||
for ($i = 0; $i < count($arr_bahan); $i++) {
|
||||
if (!in_array($arr_bahan[$i]['bahanID'], $arr_bahanIdnew)) {
|
||||
$this->db->set("T_OrderDetailBahanIsActive", 'N')
|
||||
->where("T_OrderDetailBahanID", $arr_bahan[$i]['id'])->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//new and update bahan
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
if ($bahan[$i]['detailID'] == "new") {
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailBahanT_OrderID" => $orderID,
|
||||
"T_OrderDetailBahanNat_BahanID" => $bahan[$i]['id'],
|
||||
"T_OrderDetailBahanName" => $bahan[$i]['name'],
|
||||
"T_OrderDetailBahanQty" => $bahan[$i]['amount'],
|
||||
"T_OrderDetailBahanUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailbahan', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
$this->db->set("T_OrderDetailBahanQty", $bahan[$i]['amount'])
|
||||
->set("T_OrderDetailBahanUserID", $userid)
|
||||
->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$this->db->set("T_OrderDetailBahanIsActive", 'N')
|
||||
->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//deleted paket
|
||||
for ($i = 0; $i < count($arr_paket); $i++) {
|
||||
if (!in_array($arr_paket[$i]['paket_id'], $arr_paketIdnew)) {
|
||||
$this->db->set("T_OrderDetailPacketIsActive", 'N')
|
||||
->where("T_OrderDetailPacketID", $arr_paket[$i]['id'])->update('one_mitra.t_orderdetailpacket');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE PACKET DETAIL ", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//new and paket
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
if ($paket[$i]['detail_id'] == "new") {
|
||||
$order = [
|
||||
"T_OrderDetailPacketOrderID" => $orderID,
|
||||
"T_OrderDetailPacketT_PacketID" => $paket[$i]['id'],
|
||||
"T_OrderDetailPacketName" => $paket[$i]['name'],
|
||||
"T_OrderDetailPacketUserID" => $userid,
|
||||
"T_OrderDetailPacketPrice" => $paket[$i]['price'],
|
||||
"T_OrderDetailPacketT_PacketType" => $paket[$i]["type"],
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailpacket', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL PAKET", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// else {
|
||||
|
||||
// $this->db->set("T_OrderDetailBahanQty", $bahan[$i]['amount'])
|
||||
// ->set("T_OrderDetailBahanUserID", $userid)
|
||||
// ->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])
|
||||
// ->update('one_mitra.t_orderdetailbahan');
|
||||
// $err = $this->db->error();
|
||||
// if (
|
||||
// $err['message'] != ""
|
||||
// ) {
|
||||
// $this->sys_error_db("ERROR UPDATE ORDER DETAIL BAHAN", $this->db);
|
||||
// $this->db->trans_rollback();
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$this->sys_ok("OK");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function cancel()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT T_OrderDetailDeliveryID AS CEK
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryT_OrderID = ?
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $query->result_array();
|
||||
if (count($cek) == 0) {
|
||||
# code...
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_order SET T_OrderIsActive = 'N'
|
||||
WHERE T_OrderID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_orderdetail SET T_OrderDetailIsActive = 'N'
|
||||
WHERE T_OrderDetailOrderID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} else {
|
||||
$this->sys_ok("Sudah di buat surat jalan");
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
319
one-api/application/controllers/one_mitra/Patient.php
Normal file
319
one-api/application/controllers/one_mitra/Patient.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
class Patient extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
// hitung start_offset
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
|
||||
$sql_total = "SELECT
|
||||
COUNT(M_PatientID) AS total
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientM_CompanyID = ?
|
||||
AND (M_PatientName LIKE ? OR
|
||||
M_PatientNIK LIKE ? OR M_PatientHP LIKE ?)";
|
||||
$query_total = $this->db->query($sql_total, [$companyID, $keyword, $keyword, $keyword]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_PatientID AS id,
|
||||
M_PatientPrefix AS prefix,
|
||||
M_PatientName AS name,
|
||||
M_PatientSuffix AS suffix,
|
||||
M_PatientDOB AS dob,
|
||||
M_PatientNIK AS nik,
|
||||
M_PatientNIP AS nip,
|
||||
M_PatientTitleID AS title_id,
|
||||
M_PatientM_SexID AS sex_id,
|
||||
M_PatientHP AS hp,
|
||||
M_PatientAddress AS address,
|
||||
M_PatientNoRM AS noRM,
|
||||
M_PatientJabatan AS jabatan,
|
||||
M_PatientKedudukan AS kedudukan,
|
||||
M_PatientLocation AS lokasi,
|
||||
M_PatientJob AS pekerjaan,
|
||||
M_PatientM_CompanyID,
|
||||
one_mitra.fn_get_patient_status_del(M_PatientID) AS status_delete
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientM_CompanyID = ?
|
||||
AND (M_PatientName LIKE ? OR
|
||||
M_PatientNIK LIKE ? OR M_PatientHP LIKE ?)
|
||||
ORDER BY M_PatientName
|
||||
LIMIT ? OFFSET ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$companyID, $keyword, $keyword, $keyword, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage)
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function editpatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$patientID = $prm['patient_id'];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$patientDOB = date('Y-m-d', strtotime($patient['dob']));
|
||||
$withoutNIK = $patient['without_nik'];
|
||||
$nik = $patient['nik'];
|
||||
$isNIK = 'N';
|
||||
//JSON BEFORE
|
||||
$sql = "SELECT * FROM one_mitra.m_patient
|
||||
WHERE M_PatientID = ?";
|
||||
$query = $this->db->query($sql, [$patientID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$JSONBefore = json_encode($query->result_array()[0]);
|
||||
|
||||
|
||||
if ($withoutNIK == "N") {
|
||||
$isNIK = 'Y';
|
||||
}
|
||||
if ($isNIK == 'Y') {
|
||||
//sql cek kalau NIK sudah digunakan atau belum
|
||||
$sql = "SELECT * FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsNIK = 'Y'
|
||||
AND M_PatientNIK = ?
|
||||
AND M_PatientM_CompanyID = ?
|
||||
AND M_PatientID <> ?";
|
||||
$query = $this->db->query($sql, [$nik, $companyID, $patientID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$cekNik = $query->result_array();
|
||||
if (count($cekNik) > 0) {
|
||||
$this->sys_error("NIK sudah digunakan oleh pasien lain");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
//edit
|
||||
$sql = "UPDATE one_mitra.m_patient
|
||||
SET M_PatientPrefix = ?,
|
||||
M_PatientName = ?,
|
||||
M_PatientSuffix = ?,
|
||||
M_PatientDOB = ?,
|
||||
M_PatientNIK = ?,
|
||||
M_PatientNIP = ? ,
|
||||
M_PatientIsNIK = ?,
|
||||
M_PatientTitleID = ?,
|
||||
M_PatientM_SexID = ?,
|
||||
M_PatientHP = ? ,
|
||||
M_PatientNoRM = ?,
|
||||
M_PatientJabatan = ?,
|
||||
M_PatientKedudukan = ?,
|
||||
M_PatientLocation = ?,
|
||||
M_PatientJob = ?,
|
||||
M_PatientAddress = ?
|
||||
WHERE M_PatientID = ?
|
||||
AND M_PatientIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [
|
||||
$patient['prefix'],
|
||||
$patient['name'],
|
||||
$patient['suffix'],
|
||||
$patientDOB,
|
||||
$nik,
|
||||
$patient['nip'],
|
||||
$isNIK,
|
||||
$patient['saluation'],
|
||||
$patient['gender'],
|
||||
$patient['hp'],
|
||||
$patient['noRM'],
|
||||
$patient['jabatan'],
|
||||
$patient['kedudukan'],
|
||||
$patient['lokasi'],
|
||||
$patient['pekerjaan'],
|
||||
$patient['address'],
|
||||
$patientID
|
||||
]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
$this->sys_error_db($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
//JSON AFTER
|
||||
$sql = "SELECT * FROM one_mitra.m_patient
|
||||
WHERE M_PatientID = ?";
|
||||
$query = $this->db->query($sql, [$patientID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$JSONAfter = json_encode($query->result_array()[0]);
|
||||
//insert log
|
||||
$sql = "INSERT INTO mitra_log.m_patient_log(
|
||||
M_PatientLogM_PatientID,
|
||||
M_PatientLogStatus,
|
||||
M_PatientLogJSONBefore,
|
||||
M_PatientLogJSONAfter,
|
||||
M_patientLogUserID,
|
||||
M_PatientLogCreated)VALUES(?,'EDIT',?,?,?, NOW())";
|
||||
$query = $this->db->query($sql, [$patientID, $JSONBefore, $JSONAfter, $userid]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok("Berhasil Mengubah data");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function deletePatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
//cek bisa di delete atau tidak
|
||||
$sql = "SELECT one_mitra.fn_get_patient_status_del(?) AS status_delete;";
|
||||
$query = $this->db->query($sql, [$prm['patient_id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$cek = $query->result_array()[0]['status_delete'];
|
||||
if ($cek == 'Y') {
|
||||
//delete
|
||||
$sql = "UPDATE one_mitra.m_patient
|
||||
SET M_PatientIsActive = 'N'
|
||||
WHERE M_PatientID = ?";
|
||||
$query = $this->db->query($sql, [$prm['patient_id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
//JSON AFTER
|
||||
$sql = "SELECT * FROM one_mitra.m_patient
|
||||
WHERE M_PatientID = ?";
|
||||
$query = $this->db->query(
|
||||
$sql,
|
||||
[$prm['patient_id']]
|
||||
);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$JSONAfter = json_encode($query->result_array()[0]);
|
||||
//insert log
|
||||
$sql = "INSERT INTO mitra_log.m_patient_log(
|
||||
M_PatientLogM_PatientID,
|
||||
M_PatientLogStatus,
|
||||
M_PatientLogJSONAfter,
|
||||
M_patientLogUserID,
|
||||
M_PatientLogCreated)VALUES(?,'DELETE',?,?, NOW())";
|
||||
$query = $this->db->query(
|
||||
$sql,
|
||||
[$prm['patient_id'], $JSONAfter, $userid]
|
||||
);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok("berhasil menghapus data");
|
||||
} else {
|
||||
//tidak bisa di delete
|
||||
$this->sys_error("Gagal Menghapus data, order pasien sudah masuk kedalam surat jalan");
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
498
one-api/application/controllers/one_mitra/Registration.php
Normal file
498
one-api/application/controllers/one_mitra/Registration.php
Normal file
@@ -0,0 +1,498 @@
|
||||
<?php
|
||||
|
||||
class Registration extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function getfilter()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql_gender = "SELECT M_SexID AS id,
|
||||
m_sexname AS name
|
||||
FROM m_sex
|
||||
WHERE M_SexIsActive = 'Y'";
|
||||
$query_gender = $this->db->query($sql_gender, []);
|
||||
if (!$query_gender) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$genders = $query_gender->result_array();
|
||||
$sql_title = "SELECT M_TitleID AS id,
|
||||
M_TitleM_SexID AS type,
|
||||
M_TitleName AS name
|
||||
FROM m_title WHERE M_TitleIsActive = 'Y'";
|
||||
$query_title = $this->db->query($sql_title, []);
|
||||
if (!$query_title) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$titles = $query_title->result_array();
|
||||
|
||||
$sql_regional = "SELECT
|
||||
S_RegionalID AS regional_id,
|
||||
S_RegionalName AS regional_name
|
||||
FROM s_regional WHERE S_RegionalIsActive = 'Y'";
|
||||
$query_regional = $this->db->query($sql_regional, []);
|
||||
if (!$query_regional) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$regionals = $query_regional->result_array();
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName AS branch_name,
|
||||
M_BranchS_RegionalID AS regional_id
|
||||
FROM m_branch Where M_BranchIsActive = 'Y'";
|
||||
$query_branch = $this->db->query($sql_branch, []);
|
||||
if (!$query_branch) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$branchs = $query_branch->result_array();
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
$regionals[$i]['branch'] = [];
|
||||
}
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
for ($j = 0; $j < count($branchs); $j++) {
|
||||
if ($regionals[$i]['regional_id'] == $branchs[$j]['regional_id']) {
|
||||
$regionals[$i]['branch'][] = $branchs[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = array(
|
||||
"titles" => $titles,
|
||||
"gender" => $genders,
|
||||
"regional" => $regionals
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getsampletype()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$arr_test = 0;
|
||||
if (isset($prm['arr_test'])) {
|
||||
$arr_test = $prm['arr_test'];
|
||||
} else {
|
||||
$this->sys_error("arr_test is mandatory");
|
||||
}
|
||||
// print_r($arr_test);
|
||||
$result = array();
|
||||
for ($i = 0; $i < count($arr_test); $i++) {
|
||||
$test = $arr_test[$i];
|
||||
$sasCode = substr($test['sasCode'], 0, 8) . "%";
|
||||
$sql = "SELECT T_TestID AS id
|
||||
FROM t_test
|
||||
WHERE T_TestSasCode LIKE ?
|
||||
AND T_TestIsActive = 'Y'";
|
||||
$qry = $this->db_regional->query($sql, [$sasCode]);
|
||||
if (!$qry) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$allTest = $qry->result_array();
|
||||
$arr = [];
|
||||
for ($k = 0; $k < count($allTest); $k++) {
|
||||
$arr[] = $allTest[$k]['id'];
|
||||
}
|
||||
// print_r($arr);
|
||||
|
||||
$implodeTest = implode(",", $arr);
|
||||
|
||||
$sql_specimen = "SELECT Nat_TestID,
|
||||
Nat_TestName,
|
||||
T_TestID,
|
||||
T_TestName,
|
||||
Nat_SampleTypeID,
|
||||
Nat_SampleTypeNat_BahanID,
|
||||
Nat_SampleTypeName,
|
||||
Nat_BahanID,
|
||||
Nat_BahanName
|
||||
FROM nat_test
|
||||
JOIN t_test
|
||||
ON Nat_TestID = T_TestNat_TestID
|
||||
AND T_TestID IN ($implodeTest)
|
||||
AND T_TestIsActive = 'Y'
|
||||
JOIN nat_sampletype
|
||||
ON Nat_TestNat_SampleTypeID = Nat_SampleTypeID
|
||||
AND Nat_SampleTypeIsActive = 'Y'
|
||||
JOIN nat_bahan
|
||||
ON Nat_SampleTypeNat_BahanID = Nat_BahanID
|
||||
WHERE Nat_TestIsActive = 'Y'
|
||||
|
||||
";
|
||||
// GROUP_CONCAT(DISTINCT CONCAT(Nat_SampleTypeID, '^', Nat_SampleTypeName)) AS sampletype,
|
||||
// GROUP_CONCAT(DISTINCT CONCAT(Nat_BahanID, '^', Nat_BahanName)) AS nat_bahan
|
||||
// GROUP BY Nat_SampleTypeID, Nat_BahanID
|
||||
$qry_specimen = $this->db_regional->query($sql_specimen, []);
|
||||
// echo $this->db_regional->last_query();
|
||||
// exit;
|
||||
if (!$qry_specimen) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$specimen = $qry_specimen->result_array();
|
||||
// print_r($specimen);
|
||||
// exit;
|
||||
$data = array(
|
||||
"id" => $test['id'],
|
||||
"tab" => $test['tab'],
|
||||
"specimen" => [],
|
||||
"bahan" => []
|
||||
);
|
||||
// print_r($specimen);
|
||||
// if (count($specimen) > 0) {
|
||||
// if ($specimen[0]['sampletype'] != null && $specimen[0]['nat_bahan'] != null) {
|
||||
|
||||
// $sampleType = explode(',', $specimen[0]['sampletype']);
|
||||
// $natBahan = explode(',', $specimen[0]['nat_bahan']);
|
||||
// // print_r($sampleType);
|
||||
// // print_r($natBahan);
|
||||
|
||||
|
||||
// for ($i = 0; $i < count($sampleType); $i++) {
|
||||
// $temp = explode('^', $sampleType[$i]);
|
||||
// $data['specimen'][] = array(
|
||||
// "id" => $temp[0],
|
||||
// "name" => $temp[1]
|
||||
// );
|
||||
// }
|
||||
// for ($i = 0; $i < count($natBahan); $i++) {
|
||||
// $temp = explode('^', $natBahan[$i]);
|
||||
// $data['bahan'][] = array(
|
||||
// "id" => $temp[0],
|
||||
// "name" => $temp[1]
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for ($j = 0; $j < count($specimen); $j++) {
|
||||
$sp = $specimen[$j];
|
||||
$tempSp = array(
|
||||
"id" => $sp["Nat_SampleTypeID"],
|
||||
"name" => $sp['Nat_SampleTypeName']
|
||||
);
|
||||
$tempBhn = array(
|
||||
"id" => $sp["Nat_BahanID"],
|
||||
"name" => $sp['Nat_BahanName']
|
||||
);
|
||||
if (!in_array($tempSp, $data['specimen'])) {
|
||||
$data['specimen'][] = array(
|
||||
"id" => $sp["Nat_SampleTypeID"],
|
||||
"name" => $sp['Nat_SampleTypeName']
|
||||
);
|
||||
}
|
||||
if (!in_array($tempBhn, $data['bahan'])) {
|
||||
$data['bahan'][] = array(
|
||||
"id" => $sp["Nat_BahanID"],
|
||||
"name" => $sp['Nat_BahanName']
|
||||
);
|
||||
}
|
||||
}
|
||||
$result[] = $data;
|
||||
}
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function addpatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$paket = $prm['paket'];
|
||||
$patientDOB = date('Y-m-d', strtotime($patient['dob']));
|
||||
$withoutNIK = $patient['without_nik'];
|
||||
$nik = $patient['nik'];
|
||||
$tests = $prm['tests'];
|
||||
$specimens = $prm['specimens'];
|
||||
$bahan = $prm['bahan'];
|
||||
$userMou = $prm['userMouID'];
|
||||
$patientID = $prm['patient_id'];
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
// print_r($this->sys_user);
|
||||
// exit;
|
||||
$isNIK = 'N';
|
||||
|
||||
$this->db->trans_begin();
|
||||
if ($withoutNIK == 'Y') {
|
||||
$nik = "0";
|
||||
}
|
||||
if ($patientID == "new") {
|
||||
if ($withoutNIK == "N") {
|
||||
$isNIK = 'Y';
|
||||
}
|
||||
$ptn = [
|
||||
"M_PatientPrefix" => $patient['prefix'],
|
||||
"M_PatientTitleID" => $patient['saluation'],
|
||||
"M_PatientName" => $patient['name'],
|
||||
"M_PatientSuffix" => $patient['suffix'],
|
||||
"M_PatientDOB" => $patientDOB,
|
||||
"M_PatientNIK" => $nik,
|
||||
"M_PatientNIP" => $patient['nip'],
|
||||
"M_PatientIsNIK" => $isNIK,
|
||||
"M_PatientM_SexID" => $patient['gender'],
|
||||
"M_PatientHP" => $patient['hp'],
|
||||
"M_PatientAddress" => $patient['address'],
|
||||
"M_PatientNoRM" => $patient['noRM'],
|
||||
"M_PatientM_CompanyID" => $companyID,
|
||||
"M_PatientUserID" => $userid,
|
||||
"M_PatientJabatan" => $patient['jabatan'],
|
||||
"M_PatientKedudukan" => $patient['kedudukan'],
|
||||
"M_PatientLocation" => $patient['lokasi'],
|
||||
"M_PatientJob" => $patient['pekerjaan'],
|
||||
|
||||
];
|
||||
$this->db->insert('one_mitra.m_patient', $ptn);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT PATIENT", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$patientID = $this->db->insert_id();
|
||||
if ($withoutNIK == 'Y') {
|
||||
$awalan = sprintf("%05s", intval($companyID)) . $patientID;
|
||||
// print_r($awalan);
|
||||
$nik = str_pad($awalan, 16, "0");
|
||||
// print_r($nik);
|
||||
$this->db->set("M_PatientNIK", $nik)->where("M_PatientID", $patientID)->update('one_mitra.m_patient');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("m_patient rows", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT one_mitra.fn_numbering('MT') as number";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$message = $this->db->error();
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$number = $qry->result_array()[0]['number'];
|
||||
$total = intval($prm['total']);
|
||||
|
||||
$order = [
|
||||
"T_OrderNumber" => $number,
|
||||
"T_OrderM_PatientID" => $patientID,
|
||||
"T_OrderM_MouID" => $userMou,
|
||||
"T_OrderM_CompanyID" => $companyID,
|
||||
"T_OrderS_RegionalID" => $regionalID,
|
||||
"T_OrderNote" => $patient['note'],
|
||||
"T_OrderDiagnosis" => $patient['diagnosis'],
|
||||
"T_OrderUserID" => $userid,
|
||||
"T_OrderTotal" => $total,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_order', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$orderId = $this->db->insert_id();
|
||||
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
// T_OrderDetailID int(11) Auto Increment
|
||||
// T_OrderDetailOrderID int(11)
|
||||
// T_OrderDetailTestID int(11)
|
||||
// T_OrderDetailTestName varchar(30)
|
||||
// T_OrderDetailTotal int(11)
|
||||
// T_OrderDetailUserID
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailOrderID" => $orderId,
|
||||
"T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
"T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
"T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
"T_OrderDetailTestDate" => $dt,
|
||||
"T_OrderDetailUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
// T_OrderDetailSampleT_OrderID int(11)
|
||||
// T_OrderDetailSampleNat_SampleTypeID int(11)
|
||||
// T_OrderDetailSampleName varchar(200)
|
||||
// T_OrderDetailSampleQty varchar(200)
|
||||
// T_OrderDetailSampleUserID
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$order = [
|
||||
"T_OrderDetailSampleT_OrderID" => $orderId,
|
||||
"T_OrderDetailSampleNat_SampleTypeID" => $specimens[$i]['id'],
|
||||
"T_OrderDetailSampleName" => $specimens[$i]['name'],
|
||||
"T_OrderDetailSampleQty" => $specimens[$i]['amount'],
|
||||
"T_OrderDetailSampleUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailsample', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
// T_OrderDetailBahanT_OrderID int(11)
|
||||
// T_OrderDetailBahanNat_BahanID int(11)
|
||||
// T_OrderDetailBahanName int(11)
|
||||
// T_OrderDetailBahanQty varchar(200)
|
||||
// T_OrderDetailBahanUserID
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
# code...
|
||||
$order = [
|
||||
"T_OrderDetailBahanT_OrderID" => $orderId,
|
||||
"T_OrderDetailBahanNat_BahanID" => $bahan[$i]['id'],
|
||||
"T_OrderDetailBahanName" => $bahan[$i]['name'],
|
||||
"T_OrderDetailBahanQty" => $bahan[$i]['amount'],
|
||||
"T_OrderDetailBahanUserID" => $userid,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailbahan', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
//T_OrderDetailPacketID int(11) Auto Increment
|
||||
// T_OrderDetailPacketT_PacketID int(11)
|
||||
// T_OrderDetailPacketName varchar(250)
|
||||
// T_OrderDetailPacketIsActive char(1) [Y]
|
||||
// T_OrderDetailPacketUserID int(11)
|
||||
// T_OrderDetailPacketCreated datetime [current_timestamp()]
|
||||
// T_OrderDetailPacketLastUpdated
|
||||
|
||||
# code...
|
||||
$order = [
|
||||
"T_OrderDetailPacketOrderID" => $orderId,
|
||||
"T_OrderDetailPacketPrice" => $paket[$i]['price'],
|
||||
"T_OrderDetailPacketT_PacketType" => $paket[$i]["type"],
|
||||
"T_OrderDetailPacketT_PacketID" => $paket[$i]['id'],
|
||||
"T_OrderDetailPacketName" => $paket[$i]['name'],
|
||||
"T_OrderDetailPacketUserID" => $userid,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailpacket', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = [
|
||||
"patientID" => $patientID,
|
||||
"orderID" => $orderId,
|
||||
"orderNumber" => $number,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
class Updateprocessresult extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: UPDATE STATUS X/R";
|
||||
}
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
|
||||
function reply_gz($resp, $debug = "")
|
||||
{
|
||||
if ($debug != "") {
|
||||
echo json_encode($resp);
|
||||
} else {
|
||||
echo gzcompress(json_encode($resp));
|
||||
}
|
||||
}
|
||||
|
||||
function get_param()
|
||||
{
|
||||
$body = file_get_contents("php://input");
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
function get_param_z()
|
||||
{
|
||||
$body_z = file_get_contents("php://input");
|
||||
$body = gzuncompress($body_z);
|
||||
return json_decode($body, true);
|
||||
}
|
||||
function updateprocess()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param_z();
|
||||
|
||||
$orderList = $prm['order'];
|
||||
$success = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
for ($i = 0; $i < count($orderList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'P'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [$orderList[$i]]);
|
||||
if (!$qry_update) {
|
||||
$error[] = $orderList[$i];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} else {
|
||||
$success[] = $orderList[$i];
|
||||
}
|
||||
}
|
||||
$resultOrder = [
|
||||
"success" => $success,
|
||||
"error" => $error,
|
||||
"message" => $errorMsg,
|
||||
];
|
||||
|
||||
|
||||
$result = [
|
||||
"order" => $resultOrder
|
||||
];
|
||||
$this->reply_gz($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updateresult()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param_z();
|
||||
|
||||
$orderList = $prm['order'];
|
||||
$success = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
for ($i = 0; $i < count($orderList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'R'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [$orderList[$i]]);
|
||||
if (!$qry_update) {
|
||||
$error[] = $orderList[$i];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} else {
|
||||
$success[] = $orderList[$i];
|
||||
}
|
||||
}
|
||||
$resultOrder = [
|
||||
"success" => $success,
|
||||
"error" => $error,
|
||||
"message" => $errorMsg,
|
||||
];
|
||||
|
||||
|
||||
$result = [
|
||||
"order" => $resultOrder
|
||||
];
|
||||
$this->reply_gz($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
268
one-api/application/controllers/one_mitra/Updatestatusreg.php
Normal file
268
one-api/application/controllers/one_mitra/Updatestatusreg.php
Normal file
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
class Updatestatusreg extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: UPDATE STATUS X/R";
|
||||
}
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
|
||||
function reply_gz($resp, $debug = "")
|
||||
{
|
||||
if ($debug != "") {
|
||||
echo json_encode($resp);
|
||||
} else {
|
||||
echo gzcompress(json_encode($resp));
|
||||
}
|
||||
}
|
||||
|
||||
function get_param()
|
||||
{
|
||||
$body = file_get_contents("php://input");
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
function get_param_z()
|
||||
{
|
||||
$body_z = file_get_contents("php://input");
|
||||
$body = gzuncompress($body_z);
|
||||
return json_decode($body, true);
|
||||
}
|
||||
function updatestatusorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param_z();
|
||||
|
||||
$orderList = $prm['order'];
|
||||
$waList = $prm['wa'];
|
||||
$success = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
$successWa = [];
|
||||
$errorWa = [];
|
||||
$errorMsgWa = [];
|
||||
for ($i = 0; $i < count($orderList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [$orderList[$i]]);
|
||||
if (!$qry_update) {
|
||||
$error[] = $orderList[$i];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} else {
|
||||
$success[] = $orderList[$i];
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($waList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatusQR = 'S'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, $waList[$i]);
|
||||
if (!$qry_update) {
|
||||
$errorWa[] = $waList[$i];
|
||||
$errorMsgWa[] = $this->db->error();
|
||||
} else {
|
||||
$successWa[] = $waList[$i];
|
||||
}
|
||||
}
|
||||
$resultOrder = [
|
||||
"success" => $success,
|
||||
"error" => $error,
|
||||
"message" => $errorMsg,
|
||||
];
|
||||
$resultWa = [
|
||||
"success" => $successWa,
|
||||
"error" => $errorWa,
|
||||
"message" => $errorMsgWa,
|
||||
];
|
||||
|
||||
|
||||
$result = [
|
||||
"order" => $resultOrder,
|
||||
"wa" => $resultWa
|
||||
];
|
||||
$this->reply_gz($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updatestatus()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$successUpdate = array();
|
||||
$errorUpdate = array();
|
||||
$errorMsg = array();
|
||||
for ($i = 0; $i < count($prm); $i++) {
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = ?
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive ='Y'";
|
||||
$query = $this->db->query($sql, [$prm[$i]['T_OrderStatus'], $prm[$i]['T_OrderID']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorUpdate[] = $prm[$i]['T_OrderID'];
|
||||
$errorMsg[] = $message;
|
||||
} else {
|
||||
for ($j = 0; $j < count($prm[$i]['sample']); $j++) {
|
||||
if ($prm[$i]['sample'][$j]['type'] == "S") {
|
||||
$sql_update = "UPDATE one_mitra.t_orderdetailsample
|
||||
SET T_OrderDetailSampleStatus = ?
|
||||
WHERE T_OrderDetailSampleID = ?
|
||||
AND T_OrderDetailSampleIsActive = 'Y'";
|
||||
$query_update = $this->db->query($sql_update, [
|
||||
$prm[$i]['sample'][$j]['status'],
|
||||
$prm[$i]['sample'][$j]['id']
|
||||
]);
|
||||
if (!$query_update) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorMsg[] = $message;
|
||||
}
|
||||
} else if ($prm[$i]['sample'][$j]['type'] == "B") {
|
||||
$sql_update = "UPDATE one_mitra.t_orderdetailbahan
|
||||
SET T_OrderDetailBahanStatus = ?
|
||||
WHERE T_OrderDetailBahanID = ?
|
||||
AND T_OrderDetailBahanIsActive = 'Y'";
|
||||
$query_update = $this->db->query($sql_update, [
|
||||
$prm[$i]['sample'][$j]['status'],
|
||||
$prm[$i]['sample'][$j]['id']
|
||||
]);
|
||||
if (!$query_update) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorMsg[] = $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
$successUpdate[] = $prm[$i]['T_OrderID'];
|
||||
}
|
||||
}
|
||||
// $result = $query->result_array();
|
||||
// $z_param = gzcompress(json_encode($result));
|
||||
|
||||
$result = [
|
||||
"success" => $successUpdate,
|
||||
"error" => $errorUpdate,
|
||||
"msg" => $errorMsg,
|
||||
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updatestatuspq()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$successUpdate = array();
|
||||
$errorUpdate = array();
|
||||
$errorMsg = array();
|
||||
for ($i = 0; $i < count($prm); $i++) {
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = ?
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive ='Y'";
|
||||
$query = $this->db->query($sql, [$prm[$i]['status'], $prm[$i]['orderID']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorUpdate[] = $prm[$i]['orderID'];
|
||||
$errorMsg[] = $message;
|
||||
} else {
|
||||
$successUpdate[] = $prm[$i]['orderID'];
|
||||
}
|
||||
}
|
||||
// $result = $query->result_array();
|
||||
// $z_param = gzcompress(json_encode($result));
|
||||
|
||||
$result = [
|
||||
"success" => $successUpdate,
|
||||
"error" => $errorUpdate,
|
||||
"msg" => $errorMsg,
|
||||
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function checkorderdone()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT
|
||||
T_OrderID AS orderID,
|
||||
T_OrderNumber AS orderNumber,
|
||||
YEAR(T_OrderDate) AS year,
|
||||
T_OrderM_CompanyID AS company_id
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderStatus IN ('P', 'Q')
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rst = $query->result_array();
|
||||
// $a = glob("/data-s3/$companyID/$yearFull/$orderNum*pdf");
|
||||
// $rst[] = [
|
||||
// "company_id" => "1710",
|
||||
// "year" => "2023",
|
||||
// "orderNumber" => "MT231010001"
|
||||
// ];
|
||||
$orderList = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
$success = [];
|
||||
for ($i = 0; $i < count($rst); $i++) {
|
||||
$companyID = $rst[$i]["company_id"];
|
||||
$year = $rst[$i]["year"];
|
||||
$orderNumber = $rst[$i]["orderNumber"];
|
||||
$a = glob("/data-s3/$companyID/$year/$orderNumber*pdf");
|
||||
if (count($a) > 0) {
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'D'
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$rst[$i]["orderID"]]);
|
||||
if (!$query) {
|
||||
$error[] = $rst[$i]["orderNumber"];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} {
|
||||
$success[] = $rst[$i]["orderNumber"];
|
||||
}
|
||||
}
|
||||
$orderList[] = $orderNumber;
|
||||
}
|
||||
$result = [
|
||||
"list_order" => $orderList,
|
||||
"error" => $error,
|
||||
"success" => $success,
|
||||
"errorMsg" => $errorMsg
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
<?php
|
||||
class Auth extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $db_log;
|
||||
var $db;
|
||||
var $load;
|
||||
public function index()
|
||||
{
|
||||
// echo "AUTH API";
|
||||
// $query = $this->db->query(
|
||||
// "show databases
|
||||
// ",
|
||||
// array()
|
||||
// );
|
||||
// // print_r($this->db_regional->last_query());
|
||||
// if (!$query) {
|
||||
// $message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
// exit;
|
||||
// }
|
||||
// $rows = $query->result_array();
|
||||
// echo json_encode($rows);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// $this->db_regional = $this->db->query("use one_mitra");
|
||||
// $this->db_log = $this->db->query("use mitra_log");
|
||||
}
|
||||
|
||||
function isLogin()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
} else {
|
||||
$prm = $this->sys_input;
|
||||
$data = array(
|
||||
"user" => $this->sys_user
|
||||
);
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
}
|
||||
|
||||
function login()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
//existing password enc
|
||||
// print_r($prm);
|
||||
$sm_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"SELECT M_UserID,
|
||||
M_UserUsername,
|
||||
M_UserM_CompanyID,
|
||||
M_UserM_MouID,
|
||||
fn_get_company_name(M_UserM_CompanyID) as company_name,
|
||||
M_UserS_RegionalID
|
||||
from one_mitra.m_user
|
||||
where M_UserUsername= ? and M_UserPassword= ?
|
||||
and M_UserIsActive = 'Y'
|
||||
",
|
||||
array($prm["username"], $sm_password)
|
||||
);
|
||||
// print_r($this->db_regional->last_query());
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message, $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$user = $rows[0];
|
||||
$user['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$token = JWT::encode($user, $this->SECRET_KEY);
|
||||
$data = array(
|
||||
"user" => $user,
|
||||
"token" => $token
|
||||
);
|
||||
|
||||
$query = $this->db->query("UPDATE one_mitra.m_user
|
||||
SET M_UserIsLoggedIn = 'Y',
|
||||
M_UserLastAccess = now(),
|
||||
M_UserActiveToken = '{$token}'
|
||||
WHERE M_UserID = ?
|
||||
", array($user['M_UserID']));
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $this->db->query("INSERT INTO mitra_log.log_login
|
||||
(Log_LoginDateTime,
|
||||
Log_LoginIP,
|
||||
Log_LoginType,
|
||||
Log_LoginStatus,
|
||||
Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGIN', 'SUCCESS', $prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($data);
|
||||
exit;
|
||||
}
|
||||
$query = $this->db->query("INSERT INTO mitra_log.log_login
|
||||
(Log_LoginDateTime,
|
||||
Log_LoginIP,
|
||||
Log_LoginType,
|
||||
Log_LoginStatus,
|
||||
Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $this->input->ip_address(), 'LOGIN', 'FAILED', $prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_log->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$this->sys_error_db("Invalid UserName / Password");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
|
||||
$query = $this->db->query(
|
||||
"UPDATE one_mitra.m_user
|
||||
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
|
||||
WHERE M_UserID = ?",
|
||||
array($prm['M_UserID'])
|
||||
);
|
||||
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->query("INSERT INTO mitra_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $prm['M_UserUsername']));
|
||||
$this->sys_ok("OK");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function changepassword()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Invalid Token")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$currPassword = $prm['current_password'];
|
||||
$newPassword = $prm['new_password'];
|
||||
$passwordConfirmation = $prm['password_confirmation'];
|
||||
if (!isset($prm['new_password']) || empty($prm['new_password'])) {
|
||||
$this->sys_error("Silahkan isi password baru");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['current_password']) || empty($prm['current_password'])) {
|
||||
$this->sys_error("Silahkan isi password lama");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['password_confirmation']) || empty($prm['password_confirmation'])) {
|
||||
$this->sys_error("Silahkan isi konfirmasi password");
|
||||
exit;
|
||||
}
|
||||
if ($newPassword != $passwordConfirmation) {
|
||||
$this->sys_error("Paswword baru dan konfirmasi password tidak sama !");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate password strength
|
||||
$uppercase = preg_match('@[A-Z]@', $prm['new_password']);
|
||||
$lowercase = preg_match('@[a-z]@', $prm['new_password']);
|
||||
$number = preg_match('@[0-9]@', $prm['new_password']);
|
||||
|
||||
if (strlen($prm['new_password']) < 8) {
|
||||
|
||||
$this->sys_error("Password minimal 8 digit");
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$uppercase) {
|
||||
$this->sys_error("Password minimal mengandung 1 huruf besar");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$lowercase) {
|
||||
$this->sys_error("Password minimal mengandung 1 huruf kecil");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$number) {
|
||||
$this->sys_error("Password minimal mengandung 1 angka");
|
||||
exit;
|
||||
}
|
||||
$sm_password = md5($this->one_salt . $currPassword . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"select * from one_mitra.m_user where M_UserID = ? and M_UserPassword = ?",
|
||||
array($userid, $sm_password)
|
||||
);
|
||||
if (!$query) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Query cek error")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Invalid Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$sql_json_before = "SELECT *
|
||||
FROM one_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query(
|
||||
$sql_json_before,
|
||||
[
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user select json before");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_before_by_id = $qry_json_before->row();
|
||||
|
||||
$json_before_log = json_encode($data_before_by_id);
|
||||
|
||||
$new_password_salt = md5($this->one_salt . $newPassword . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"UPDATE one_mitra.m_user set
|
||||
M_UserPassword= ?
|
||||
where M_UserID = ?
|
||||
AND M_UserIsActive = 'Y'",
|
||||
array(
|
||||
|
||||
$new_password_salt,
|
||||
// $userID
|
||||
$userid
|
||||
)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Error Change Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
// json after
|
||||
$sql_json_after = "SELECT *
|
||||
FROM one_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
|
||||
$qry_json_after = $this->db->query(
|
||||
$sql_json_after,
|
||||
[
|
||||
// $userID
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_after) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user select json after");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_after_by_id = $qry_json_after->row();
|
||||
|
||||
$json_after_log = json_encode($data_after_by_id);
|
||||
// json after
|
||||
|
||||
// proses insert log start
|
||||
$sql_insert_log = "INSERT INTO mitra_log.m_user_log(
|
||||
M_UserLogM_UserID,
|
||||
M_UserLogStatus,
|
||||
M_UserLogJSONBefore,
|
||||
M_UserLogJSONAfter,
|
||||
M_UserLogUserID,
|
||||
M_UserLogCreated
|
||||
) VALUES (
|
||||
?,
|
||||
'CHANGE PASSWORD',
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
now()
|
||||
)";
|
||||
|
||||
$qry_insert_log = $this->db->query(
|
||||
$sql_insert_log,
|
||||
[
|
||||
$userid,
|
||||
$json_before_log,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user insert log");
|
||||
exit;
|
||||
}
|
||||
// proses insert log end
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Berhasil Mengubah Password silahkan login ulang");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
class Dashboard extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
function chartdata()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
//month/year
|
||||
$filter = 'month';
|
||||
if (isset($prm['filter'])) {
|
||||
$filter = $prm['filter'];
|
||||
}
|
||||
$company_id = $prm['company_id'];
|
||||
$filter_sql = "";
|
||||
$filter_sql2 = "";
|
||||
$filter_sql_total = "";
|
||||
$select_sql = "";
|
||||
if ($filter == 'month') {
|
||||
$select_sql = "DATE_FORMAT(T_OrderDate, '%d') AS day";
|
||||
$filter_sql2 = "AND MONTH(T_OrderDate) = MONTH(CURDATE())";
|
||||
$filter_sql = ", DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day";
|
||||
$filter_sql_total = " DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day";
|
||||
}
|
||||
if ($filter == 'year') {
|
||||
$select_sql = "DATE_FORMAT(T_OrderDate, '%m') AS month";
|
||||
|
||||
$filter_sql = ", DATE_FORMAT(T_OrderDate, '%Y-%m') ORDER BY month";
|
||||
$filter_sql_total = " DATE_FORMAT(T_OrderDate, '%Y-%m') ORDER BY month";
|
||||
}
|
||||
// SELECT COUNT(T_OrderID) AS total,
|
||||
// T_OrderStatus AS status,
|
||||
// DATE_FORMAT(T_OrderDate, '%d') AS day
|
||||
// from one_mitra.t_order
|
||||
// WHERE T_OrderIsActive = 'Y'
|
||||
// AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
// AND T_OrderM_CompanyID = 1222
|
||||
// GROUP BY T_OrderStatus
|
||||
// ,DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day
|
||||
|
||||
$sql = "SELECT COUNT(T_OrderID) AS total,
|
||||
T_OrderStatus AS status,
|
||||
$select_sql
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
$filter_sql2
|
||||
AND T_OrderM_CompanyID = ?
|
||||
GROUP BY T_OrderStatus
|
||||
$filter_sql";
|
||||
$query = $this->db->query($sql, [$company_id]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$data = $query->result_array();
|
||||
$sql_total = "SELECT COUNT(T_OrderID) AS total,
|
||||
T_OrderStatus AS status,
|
||||
$select_sql
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
$filter_sql2
|
||||
AND T_OrderM_CompanyID = ?
|
||||
GROUP BY
|
||||
$filter_sql_total";
|
||||
$query_total = $this->db->query($sql_total, [$company_id]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$data_total = $query_total->result_array();
|
||||
$result = array(
|
||||
"N" => [],
|
||||
"S" => [],
|
||||
"Y" => [],
|
||||
"T" => [],
|
||||
"last_query" => $this->db->last_query()
|
||||
);
|
||||
// N = New, S= Send, P= Parsial, D=Done,
|
||||
if ($filter == 'month') {
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if ($data[$i]['status'] == 'N') {
|
||||
$result['N'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'S') {
|
||||
$result['S'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'Y') {
|
||||
$result['Y'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($data_total); $i++) {
|
||||
$result['T'][] = "{$data_total[$i]['day']}|{$data_total[$i]['total']}";
|
||||
}
|
||||
}
|
||||
if ($filter == 'year') {
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if ($data[$i]['status'] == 'N') {
|
||||
$result['N'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'S') {
|
||||
$result['S'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'Y') {
|
||||
$result['Y'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($data_total); $i++) {
|
||||
$result['T'][] = "{$data_total[$i]['month']}|{$data_total[$i]['total']}";
|
||||
}
|
||||
}
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
|
||||
$companyID = $prm['company_id'];
|
||||
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS id,
|
||||
DATE_FORMAT(T_OrderDeliveryDate, '%d/%m/%Y') AS date,
|
||||
T_OrderDeliveryNumber AS order_number,
|
||||
M_UserUsername AS pic,
|
||||
T_DeliveryTypeName AS type,
|
||||
T_OrderDeliveryStatus AS status,
|
||||
M_BranchName AS destination
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN one_mitra.t_deliverytype
|
||||
ON T_OrderDeliveryT_DeliverytypeID = T_DeliveryTypeID
|
||||
AND T_DeliveryTypeIsActive = 'Y'
|
||||
JOIN one_mitra.m_branch
|
||||
ON T_OrderDeliveryDestination = M_BranchID
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND T_OrderDeliveryStatus IN ('S', 'P')
|
||||
ORDER BY T_OrderDeliveryDate DESC
|
||||
";
|
||||
$query = $this->db->query($sql, [$companyID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
<?php
|
||||
|
||||
class Deliveryorder extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
function getdeliverytype()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_DeliveryTypeID AS id,
|
||||
T_DeliveryTypeName AS name,
|
||||
T_DeliveryTypeIsAgent AS isAgent
|
||||
FROM one_mitra.t_deliverytype
|
||||
WHERE T_DeliveryTypeIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$company_id = 0;
|
||||
if (isset($prm['company_id'])) {
|
||||
$company_id = trim($prm["company_id"]);
|
||||
$company_id = $prm['company_id'];
|
||||
} else {
|
||||
$this->sys_error("company_id is mandatory");
|
||||
}
|
||||
$regional_id = 0;
|
||||
if (isset($prm['regional_id'])) {
|
||||
$regional_id = trim($prm["regional_id"]);
|
||||
$regional_id = $prm['regional_id'];
|
||||
} else {
|
||||
$this->sys_error("regional_id is mandatory");
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_OrderID AS order_id,
|
||||
T_OrderNumber AS order_number,
|
||||
M_PatientID AS patient_id,
|
||||
M_PatientName AS patient_name,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestName SEPARATOR '|') AS test,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketName SEPARATOR '|') AS packet
|
||||
FROM one_mitra.t_order
|
||||
JOIN one_mitra.m_patient ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderM_CompanyID = ?
|
||||
AND T_OrderIsActive = 'Y'
|
||||
AND T_OrderS_RegionalID = ?
|
||||
AND T_OrderID NOT IN (SELECT T_OrderDetailDeliveryT_OrderID FROM
|
||||
one_mitra.t_orderdetaildelivery WHERE T_OrderDetailDeliveryIsActive ='Y'
|
||||
AND T_OrderDetailDeliveryM_CompanyID = ?)
|
||||
GROUP BY T_OrderID";
|
||||
$query = $this->db->query($sql, [$company_id, $regional_id, $company_id]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$arrOrder = $query->result_array();
|
||||
$result = [];
|
||||
for ($i = 0; $i < count($arrOrder); $i++) {
|
||||
$test = explode('|', $arrOrder[$i]['test']);
|
||||
$packet = explode('|', $arrOrder[$i]['packet']);
|
||||
|
||||
$result[] = [
|
||||
"order_id" => $arrOrder[$i]['order_id'],
|
||||
"order_number" => $arrOrder[$i]['order_number'],
|
||||
"patient_id" => $arrOrder[$i]['patient_id'],
|
||||
"patient_name" => $arrOrder[$i]['patient_name'],
|
||||
"sample" => [],
|
||||
"bahan" => [],
|
||||
"tests" => array_merge($test, $packet)
|
||||
];
|
||||
};
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdestination()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName branch_name
|
||||
FROM one_mitra.m_branch
|
||||
WHERE M_BranchIsActive = 'Y'";
|
||||
$query = $this->db_regional->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function addDelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$order = $prm['order'];
|
||||
$orderDetail = $prm['order_detail'];
|
||||
// T_OrderDeliveryID int(11) Auto Increment
|
||||
// T_OrderDeliveryNumber varchar(25)
|
||||
// T_OrderDeliveryStaffID int(11)
|
||||
// T_OrderDeliveryNoRef varchar(25)
|
||||
// T_OrderDeliveryDate date
|
||||
// T_OrderDeliveryDestination int(11) Branch ID
|
||||
// T_OrderDeliveryBoxTemperature varchar(25)
|
||||
// T_OrderDeliveryT_DeliverytypeID int(11)
|
||||
// T_OrderDeliveryReciptNumber varchar(40)
|
||||
// T_OrderDeliveryNote tinytext
|
||||
// T_OrderDeliveryIsActive char(1) [Y]
|
||||
// T_OrderDeliveryCreated datetime [current_timestamp()]
|
||||
// T_OrderDeliveryLastUpdated
|
||||
$this->db->trans_begin();
|
||||
$sql = "SELECT one_mitra.fn_numbering('SJ') as number";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$message = $this->db->error();
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$number = $qry->result_array()[0]['number'];
|
||||
$get2first = substr($number, 0, 2);
|
||||
$newNumber = $get2first . $order['branch_code'] . substr($number, -5);
|
||||
$orderDelivery = [
|
||||
"T_OrderDeliveryStaffID" => $order['staff_id'],
|
||||
"T_OrderDeliveryNumber" => $newNumber,
|
||||
"T_OrderDeliveryNoRef" => $order['no_ref'],
|
||||
"T_OrderDeliveryDate" => date('Y-m-d', strtotime($order['date'])),
|
||||
"T_OrderDeliveryDestination" => $order['destination_id'],
|
||||
"T_OrderDeliveryRegionalID" => $order['regional_id'],
|
||||
"T_OrderDeliveryBoxTemperature" => $order['temperature'],
|
||||
"T_OrderDeliveryT_DeliverytypeID" => $order['type_id'],
|
||||
"T_OrderDeliveryReciptNumber" => $order['no_resi'],
|
||||
"T_OrderDeliveryNote" => $order['note'],
|
||||
"T_OrderDeliveryM_CompanyID" => $order['company_id'],
|
||||
];
|
||||
$this->db->insert('one_mitra.t_orderdelivery', $orderDelivery);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DELIVERY", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$deliveryID = $this->db->insert_id();
|
||||
|
||||
for ($i = 0; $i < count($orderDetail); $i++) {
|
||||
// Column Type Comment
|
||||
// T_OrderDetailDeliveryID int(11) Auto Increment
|
||||
// T_OrderDetailDeliveryT_OrderDeliveryID int(11)
|
||||
// T_OrderDetailDeliveryT_OrderID int(11)
|
||||
// T_OrderDetailDeliveryIsActive char(1) [Y]
|
||||
// T_OrderDetailDeliveryCreated datetime [current_timestamp()]
|
||||
// T_OrderDetailDeliveryLastUpdated
|
||||
|
||||
$deliveryDetail = [
|
||||
"T_OrderDetailDeliveryT_OrderDeliveryID" => $deliveryID,
|
||||
"T_OrderDetailDeliveryT_OrderID" => $orderDetail[$i]['order_id'],
|
||||
"T_OrderDetailDeliveryM_CompanyID" => $order['company_id'],
|
||||
];
|
||||
$this->db->insert('one_mitra.t_orderdetaildelivery', $deliveryDetail);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DELIVERY DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$result = [
|
||||
"deliveryID" => $deliveryID,
|
||||
"orderNumber" => $newNumber,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
$sql_total = "SELECT COUNT(T_OrderDeliveryID) AS total
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN one_mitra.t_deliverytype
|
||||
ON T_OrderDeliveryT_DeliverytypeID = T_DeliveryTypeID
|
||||
AND T_DeliveryTypeIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND T_OrderDeliveryNumber LIKE ?
|
||||
AND T_OrderDeliveryRegionalID = ?";
|
||||
$query_total = $this->db->query($sql_total, [$companyID, $keyword, $regionalID]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
// print_r($totals);
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS id,
|
||||
DATE_FORMAT(T_OrderDeliveryDate, '%d/%m/%Y') AS date,
|
||||
T_OrderDeliveryNumber AS order_number,
|
||||
M_UserUsername AS pic,
|
||||
T_OrderDeliveryStatus AS status,
|
||||
M_BranchName AS destination
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN one_mitra.m_branch
|
||||
ON T_OrderDeliveryDestination = M_BranchID
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND T_OrderDeliveryNumber LIKE ?
|
||||
AND T_OrderDeliveryRegionalID = ?
|
||||
ORDER BY T_OrderDeliveryDate
|
||||
LIMIT ? OFFSET ?";
|
||||
$query = $this->db->query($sql, [$companyID, $keyword, $regionalID, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage)
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function detaildelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS delivery_id,
|
||||
T_OrderDeliveryNumber AS delivery_number,
|
||||
T_OrderNumber AS order_number,
|
||||
T_OrderDetailDeliveryID AS delivery_detail_id,
|
||||
T_OrderDetailDeliveryT_OrderID AS order_id,
|
||||
DATE_FORMAT(T_OrderDate, '%d/%m/%Y') AS date,
|
||||
M_PatientName AS patient_name,
|
||||
T_OrderStatus AS status,
|
||||
one_mitra.fn_get_acc_sample(T_OrderDetailDeliveryT_OrderID) AS accepted_sample,
|
||||
one_mitra.fn_get_rejct_sample(T_OrderDetailDeliveryT_OrderID) AS rejected_sample
|
||||
FROM
|
||||
one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDeliveryID = T_OrderDetailDeliveryT_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
JOIN one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderIsActive = 'Y'
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
WHERE T_OrderDeliveryID = ?
|
||||
AND T_OrderDeliveryIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function cancel()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_orderdelivery SET T_OrderDeliveryIsActive = 'N'
|
||||
WHERE T_OrderDeliveryID = ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_orderdetaildelivery SET T_OrderDetailDeliveryIsActive = 'N'
|
||||
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function send()
|
||||
{
|
||||
try {
|
||||
// $aql = "UPDATE t_orderdelivery SET T_OrderDeliveryStatus = 'S'
|
||||
// WHERE T_OrderDeliveryID = 1;
|
||||
|
||||
// UPDATE t_order SET T_OrderStatus = 'S'
|
||||
// WHERE T_OrderID IN (
|
||||
// SELECT T_OrderDetailDeliveryT_OrderID
|
||||
// FROM t_orderdetaildelivery
|
||||
// WHERE T_OrderDetailDeliveryT_OrderDeliveryID = 1)";
|
||||
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_orderdelivery SET T_OrderDeliveryStatus = 'S'
|
||||
WHERE T_OrderDeliveryID = ?;
|
||||
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_order SET T_OrderStatus = 'S'
|
||||
WHERE T_OrderID IN (
|
||||
SELECT T_OrderDetailDeliveryT_OrderID
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = ?)
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getregional()
|
||||
{
|
||||
try {
|
||||
|
||||
$sql_regional = "SELECT
|
||||
S_RegionalID AS regional_id,
|
||||
S_RegionalName AS regional_name
|
||||
FROM one_mitra.s_regional WHERE S_RegionalIsActive = 'Y'";
|
||||
$query_regional = $this->db->query($sql_regional, []);
|
||||
if (!$query_regional) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$regionals = $query_regional->result_array();
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName AS branch_name,
|
||||
M_BranchS_RegionalID AS regional_id
|
||||
FROM one_mitra.m_branch Where M_BranchIsActive = 'Y'";
|
||||
$query_branch = $this->db->query($sql_branch, []);
|
||||
if (!$query_branch) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$branchs = $query_branch->result_array();
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
$regionals[$i]['branch'] = [];
|
||||
}
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
for ($j = 0; $j < count($branchs); $j++) {
|
||||
if ($regionals[$i]['regional_id'] == $branchs[$j]['regional_id']) {
|
||||
$regionals[$i]['branch'][] = $branchs[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->sys_ok($regionals);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function sendqrcode()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$arr_order_id = 0;
|
||||
if (isset($prm['arr_order_id'])) {
|
||||
$arr_order_id = $prm['arr_order_id'];
|
||||
} else {
|
||||
$this->sys_error("arr_order_id is mandatory");
|
||||
}
|
||||
$arr_order_id = implode(",", $arr_order_id);
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderIsQRCode = 'Y'
|
||||
WHERE T_OrderID IN ($arr_order_id)
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
print_r($this->db->last_query());
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($this->db->last_query());
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,680 @@
|
||||
<?php
|
||||
class DownloadOrder extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Api: Download Order Mitra DEVKEDUNGDORORAYA";
|
||||
}
|
||||
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
|
||||
function reply_gz($resp, $debug = "")
|
||||
{
|
||||
if ($debug != "") {
|
||||
echo json_encode($resp);
|
||||
} else {
|
||||
echo gzcompress(json_encode($resp));
|
||||
}
|
||||
}
|
||||
|
||||
function get_param()
|
||||
{
|
||||
$body = file_get_contents("php://input");
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
function get_param_z()
|
||||
{
|
||||
$body_z = file_get_contents("php://input");
|
||||
$body = gzuncompress($body_z);
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
// t_orderdelivery
|
||||
function getData_t_orderdelivery($wherein_T_OrderDeliveryID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdelivery
|
||||
WHERE T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryID IN ($wherein_T_OrderDeliveryID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery for get data | func getData_t_orderdelivery " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
// print_r($rows_fields);
|
||||
}
|
||||
|
||||
// t_orderdetaildelivery
|
||||
function getData_t_orderdetaildelivery($wherein_T_OrderDetailDeliveryID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDetailDeliveryID IN ($wherein_T_OrderDetailDeliveryID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetaildelivery for get data | func getData_t_orderdetaildelivery " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_order
|
||||
function getData_t_order($wherein_T_OrderID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID IN ($wherein_T_OrderID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_order for get data | func getData_t_order " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetail
|
||||
function getData_t_orderdetail($wherein_T_OrderDetailID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetail
|
||||
WHERE T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailID IN ($wherein_T_OrderDetailID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetail for get data | func getData_t_orderdetail " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetailbahan
|
||||
function getData_t_orderdetailbahan($wherein_T_OrderDetailBahanID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailbahan
|
||||
WHERE T_OrderDetailBahanIsActive = 'Y'
|
||||
AND T_OrderDetailBahanID IN ($wherein_T_OrderDetailBahanID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailbahan for get data | func getData_t_orderdetailbahan " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetailsample
|
||||
function getData_t_orderdetailsample($wherein_T_OrderDetailSampleID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailsample
|
||||
WHERE T_OrderDetailSampleIsActive = 'Y'
|
||||
AND T_OrderDetailSampleID IN ($wherein_T_OrderDetailSampleID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailsample for get data | func getData_t_orderdetailsample " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// m_patient
|
||||
function getData_m_patient($wherein_M_PatientID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientID IN ($wherein_M_PatientID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailsample for get data | func getData_t_orderdetailsample " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
function getData_t_orderdetailpacket($packetID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailpacket
|
||||
WHERE T_OrderDetailPacketID in ($packetID)
|
||||
AND T_OrderDetailPacketIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailpacket for get data | func getData_t_orderdetailpacket " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
function reg_download_old($debug = "")
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$limit = 2;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
$branchId = ($debug != "") ? 1 : $prm['branchId'];
|
||||
// $branchId = 1;
|
||||
$branchCode = $prm['branchCode'];
|
||||
|
||||
$sql_pivot = "SELECT T_OrderDeliveryNumber,
|
||||
T_OrderDeliveryID
|
||||
from one_mitra.t_orderdelivery
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId";
|
||||
// LIMIT $limit ";
|
||||
|
||||
$qry_pivot = $this->db_regional->query($sql_pivot);
|
||||
|
||||
if (!$qry_pivot) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot = $qry_pivot->result_array();
|
||||
// print_r($rows_pivot);
|
||||
// exit;
|
||||
|
||||
// T_Order
|
||||
$sql_pivot_t_order = "SELECT
|
||||
T_OrderID
|
||||
from one_mitra.t_orderdelivery
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId
|
||||
join one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
|
||||
$qry_pivot_t_order = $this->db_regional->query($sql_pivot_t_order);
|
||||
|
||||
if (!$qry_pivot_t_order) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot_t_order = $qry_pivot_t_order->result_array();
|
||||
|
||||
// print_r($rows_pivot_t_order);
|
||||
// exit;
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = "";
|
||||
$string_wherein_T_OrderID = "";
|
||||
|
||||
$T_OrderDeliveryID_arr = [];
|
||||
$T_OrderID_arr = [];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
foreach ($rows_pivot as $key => $vx) {
|
||||
$T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
// $T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
}
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
// $string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
}
|
||||
|
||||
// T_Order
|
||||
if (count($rows_pivot_t_order) > 0) {
|
||||
foreach ($rows_pivot_t_order as $key => $vx) {
|
||||
// $T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
$T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
}
|
||||
|
||||
// $string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
$string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
}
|
||||
|
||||
$result = [
|
||||
"t_orderdelivery" => [],
|
||||
"t_orderdetaildelivery" => [],
|
||||
"t_order" => [],
|
||||
"t_orderdetail" => [],
|
||||
"t_orderdetailbahan" => [],
|
||||
"t_orderdetailsample" => [],
|
||||
];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
// ambil all data sesuai pivot
|
||||
|
||||
// 1. t_orderdelivery
|
||||
$t_orderdelivery = $this->getData_t_orderdelivery($string_wherein_T_OrderDeliveryID);
|
||||
|
||||
// 2. t_orderdetaildelivery
|
||||
$t_orderdetaildelivery = $this->getData_t_orderdetaildelivery($string_wherein_T_OrderDeliveryID);
|
||||
}
|
||||
|
||||
if (count($rows_pivot_t_order) > 0) {
|
||||
// 3. t_order
|
||||
$t_order = $this->getData_t_order($string_wherein_T_OrderID);
|
||||
|
||||
// 4. t_orderdetail
|
||||
$t_orderdetail = $this->getData_t_orderdetail($string_wherein_T_OrderID);
|
||||
|
||||
// 5. t_orderdetailbahan
|
||||
$t_orderdetailbahan = $this->getData_t_orderdetailbahan($string_wherein_T_OrderID);
|
||||
|
||||
// 6. t_orderdetailsample
|
||||
$t_orderdetailsample = $this->getData_t_orderdetailsample($string_wherein_T_OrderID);
|
||||
|
||||
$result["t_orderdelivery"] = $t_orderdelivery;
|
||||
$result["t_orderdetaildelivery"] = $t_orderdetaildelivery;
|
||||
$result["t_order"] = $t_order;
|
||||
$result["t_orderdetail"] = $t_orderdetail;
|
||||
$result["t_orderdetailbahan"] = $t_orderdetailbahan;
|
||||
$result["t_orderdetailsample"] = $t_orderdetailsample;
|
||||
|
||||
if ($debug != "") {
|
||||
echo "<pre>";
|
||||
echo print_r($result);
|
||||
echo "</pre>";
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(
|
||||
[
|
||||
"status" => "OK",
|
||||
"message" => "Data Ditemukan",
|
||||
"data" => [$result]
|
||||
]
|
||||
);
|
||||
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
// $result_x = array(
|
||||
// 'status' => 'OK',
|
||||
// "message" => "Tidak ada data terbaru",
|
||||
// "data" => [$result]
|
||||
// );
|
||||
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
} else {
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
$result_x = array(
|
||||
'status' => 'ERR',
|
||||
"message" => "Tidak ada data terbaru",
|
||||
"data" => []
|
||||
);
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
|
||||
echo json_encode($result_x);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$result = array(
|
||||
'status' => 'err',
|
||||
"message" => $message,
|
||||
);
|
||||
$this->reply_gz($result);
|
||||
}
|
||||
}
|
||||
|
||||
function reg_download($debug = "")
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$limit = 2;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
$branchId = ($debug != "") ? 1 : $prm['branchId'];
|
||||
// $branchId = 1;
|
||||
$branchCode = $prm['branchCode'];
|
||||
|
||||
$pickup_status = ($debug != "") ? "S" : $prm['pickup_status'];
|
||||
|
||||
$sql_pivot = "SELECT T_OrderDeliveryNumber,
|
||||
T_OrderDeliveryID,
|
||||
T_OrderID,
|
||||
T_OrderDetailID,
|
||||
T_OrderDetailBahanID,
|
||||
T_OrderDetailSampleID,
|
||||
M_PatientID,
|
||||
T_OrderDetailDeliveryID,
|
||||
T_OrderDetailPacketID
|
||||
from one_mitra.t_orderdelivery
|
||||
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId
|
||||
|
||||
join one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderIsActive = 'Y'
|
||||
|
||||
join one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
|
||||
join one_mitra.t_orderdetail
|
||||
ON T_OrderDetailOrderID = T_OrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
|
||||
left join one_mitra.t_orderdetailbahan
|
||||
ON T_OrderDetailBahanT_OrderID = T_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
|
||||
left join one_mitra.t_orderdetailsample
|
||||
ON T_OrderDetailSampleT_OrderID = T_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderDetailPacketOrderID = T_OrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
";
|
||||
// LIMIT $limit ";
|
||||
|
||||
$qry_pivot = $this->db_regional->query($sql_pivot);
|
||||
|
||||
if (!$qry_pivot) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot = $qry_pivot->result_array();
|
||||
|
||||
// print_r($rows_pivot_t_order);
|
||||
// exit;
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = "";
|
||||
$string_wherein_T_OrderDetailDeliveryID = "";
|
||||
$string_wherein_T_OrderID = "";
|
||||
$string_wherein_T_OrderDetailID = "";
|
||||
$string_wherein_T_OrderDetailBahanID = "";
|
||||
$string_wherein_T_OrderDetailSampleID = "";
|
||||
$string_wherein_M_PatientID = "";
|
||||
$string_wherein_T_OrderDetailPacketID = "";
|
||||
|
||||
$T_OrderDeliveryID_arr = [];
|
||||
$T_OrderDetailDeliveryID_arr = [];
|
||||
$T_OrderID_arr = [];
|
||||
$T_OrderDetailID_arr = [];
|
||||
$T_OrderDetailBahanID_arr = [];
|
||||
$T_OrderDetailSampleID_arr = [];
|
||||
$M_PatientID_arr = [];
|
||||
$T_OrderDetailPacketID_arr = [];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
foreach ($rows_pivot as $key => $vx) {
|
||||
$T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
$T_OrderDetailDeliveryID_arr[] = intval($vx['T_OrderDetailDeliveryID']);
|
||||
$T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
$T_OrderDetailID_arr[] = intval($vx['T_OrderDetailID']);
|
||||
$T_OrderDetailBahanID_arr[] = intval($vx['T_OrderDetailBahanID']);
|
||||
$T_OrderDetailSampleID_arr[] = intval($vx['T_OrderDetailSampleID']);
|
||||
$M_PatientID_arr[] = intval($vx['M_PatientID']);
|
||||
$T_OrderDetailPacketID_arr[] = intval($vx['T_OrderDetailPacketID']);
|
||||
}
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
$string_wherein_T_OrderDetailDeliveryID = implode(",", $T_OrderDetailDeliveryID_arr);
|
||||
$string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
$string_wherein_T_OrderDetailID = implode(",", $T_OrderDetailID_arr);
|
||||
$string_wherein_T_OrderDetailBahanID = implode(",", $T_OrderDetailBahanID_arr);
|
||||
$string_wherein_T_OrderDetailSampleID = implode(",", $T_OrderDetailSampleID_arr);
|
||||
$string_wherein_M_PatientID = implode(",", $M_PatientID_arr);
|
||||
$string_wherein_T_OrderDetailPacketID = implode(",", $T_OrderDetailPacketID_arr);
|
||||
}
|
||||
|
||||
$result = [
|
||||
"t_orderdelivery" => [],
|
||||
"t_orderdetaildelivery" => [],
|
||||
"t_order" => [],
|
||||
"t_orderdetail" => [],
|
||||
"t_orderdetailbahan" => [],
|
||||
"t_orderdetailsample" => [],
|
||||
"m_patient" => [],
|
||||
"t_orderdetailpacket" => []
|
||||
];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
// ambil all data sesuai pivot
|
||||
|
||||
// 1. t_orderdelivery
|
||||
$t_orderdelivery = $this->getData_t_orderdelivery($string_wherein_T_OrderDeliveryID);
|
||||
|
||||
// 2. t_orderdetaildelivery
|
||||
$t_orderdetaildelivery = $this->getData_t_orderdetaildelivery($string_wherein_T_OrderDetailDeliveryID);
|
||||
|
||||
// 3. t_order
|
||||
$t_order = $this->getData_t_order($string_wherein_T_OrderID);
|
||||
|
||||
// 4. t_orderdetail
|
||||
$t_orderdetail = $this->getData_t_orderdetail($string_wherein_T_OrderDetailID);
|
||||
|
||||
// 5. t_orderdetailbahan
|
||||
$t_orderdetailbahan = $this->getData_t_orderdetailbahan($string_wherein_T_OrderDetailBahanID);
|
||||
|
||||
// 6. t_orderdetailsample
|
||||
$t_orderdetailsample = $this->getData_t_orderdetailsample($string_wherein_T_OrderDetailSampleID);
|
||||
|
||||
// 7. m_patient
|
||||
$m_patient = $this->getData_m_patient($string_wherein_M_PatientID);
|
||||
|
||||
// 7. getData_t_orderdetailpacket
|
||||
$t_orderdetailpacket = $this->getData_t_orderdetailpacket($string_wherein_T_OrderDetailPacketID);
|
||||
|
||||
$result["t_orderdelivery"] = $t_orderdelivery;
|
||||
$result["t_orderdetaildelivery"] = $t_orderdetaildelivery;
|
||||
$result["t_order"] = $t_order;
|
||||
$result["t_orderdetail"] = $t_orderdetail;
|
||||
$result["t_orderdetailbahan"] = $t_orderdetailbahan;
|
||||
$result["t_orderdetailsample"] = $t_orderdetailsample;
|
||||
$result["m_patient"] = $m_patient;
|
||||
$result["t_orderdetailpacket"] = $t_orderdetailpacket;
|
||||
|
||||
if ($debug != "") {
|
||||
echo "<pre>";
|
||||
echo print_r($result);
|
||||
echo "</pre>";
|
||||
exit;
|
||||
}
|
||||
$result = [
|
||||
"status" => "OK",
|
||||
"message" => "Data Ditemukan",
|
||||
"data" => [$result]
|
||||
];
|
||||
|
||||
// echo json_encode(
|
||||
// [
|
||||
// "status" => "OK",
|
||||
// "message" => "Data Ditemukan",
|
||||
// "data" => [$result]
|
||||
// ]
|
||||
// );
|
||||
$this->reply_gz($result, $debug);
|
||||
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
// $result_x = array(
|
||||
// 'status' => 'OK',
|
||||
// "message" => "Tidak ada data terbaru",
|
||||
// "data" => [$result]
|
||||
// );
|
||||
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
} else {
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
$result_x = array(
|
||||
'status' => 'ERR',
|
||||
"message" => "Tidak ada data terbaru",
|
||||
"data" => []
|
||||
);
|
||||
$this->reply_gz($result_x, $debug);
|
||||
|
||||
// echo json_encode($result_x);
|
||||
// $this->reply_gz($result, $debug);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$result = array(
|
||||
'status' => 'err',
|
||||
"message" => $message,
|
||||
);
|
||||
$this->reply_gz($result);
|
||||
}
|
||||
}
|
||||
|
||||
function reg_update_is_download()
|
||||
{
|
||||
try {
|
||||
// $prm = $this->get_param();
|
||||
$prm = $this->get_param_z();
|
||||
$branchId = $prm['branchId'];
|
||||
// $branchCde = $prm['branchCode'];
|
||||
$dataOrder = $prm['data'];
|
||||
|
||||
$result = [];
|
||||
|
||||
if (count($dataOrder[0]['t_orderdelivery']) > 0) {
|
||||
for ($i = 0; $i < count($dataOrder[0]['t_orderdelivery']); $i++) {
|
||||
$id = $dataOrder[0]['t_orderdelivery'][$i]['T_OrderDeliveryID'];
|
||||
|
||||
$sqlUpdate = "UPDATE one_mitra.t_orderdelivery
|
||||
SET T_OrderDeliveryIsDownloaded = 'Y'
|
||||
WHERE T_OrderDeliveryID = $id
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryDestination = $branchId";
|
||||
|
||||
$qryUpdate = $this->db->query($sqlUpdate);
|
||||
if (!$qryUpdate) {
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "update one_mitra.t_orderdelivery | func reg_update_is_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"message" => 'Berhasil Di Proses',
|
||||
// "data" => $dataOrder,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"message" => 'Berhasil Di Proses',
|
||||
// "data" => $dataOrder,
|
||||
// "sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
class Fpp extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
function load()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$mou_id = 0;
|
||||
if (isset($prm['mou_id'])) {
|
||||
$mou_id = trim($prm["mou_id"]);
|
||||
$mou_id = $prm['mou_id'];
|
||||
} else {
|
||||
$this->sys_error("mou_id is mandatory");
|
||||
}
|
||||
$sql = "SELECT
|
||||
group_concat(distinct concat(t_test.T_TestID,'^',t_test.T_TestName,'^',T_PriceTotal,'^', t_test.T_TestSasCode) separator '|') TestList,
|
||||
Nat_SubGroupName,
|
||||
child_test
|
||||
from one_mitra.ss_price_mou
|
||||
join one_mitra.t_test on T_PriceIsCito= 'N' and is_packet = 'N'
|
||||
AND Ss_PriceMouM_MouID = ?
|
||||
and ss_price_mou.T_TestID = t_test.T_TestID
|
||||
join one_mitra.nat_subgroup on t_test.T_TestNat_SubGroupID = Nat_SubGroupID
|
||||
group by Nat_SubGroupName
|
||||
order by Nat_SubGroupNat_GroupID";
|
||||
$qry = $this->db_regional->query($sql, [
|
||||
$mou_id,
|
||||
]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db_regional->error()["message"] .
|
||||
"|" .
|
||||
$this->db_regional->last_query(),
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
$filters = ["Home Service", "Cetak", "Layanan"];
|
||||
foreach ($rows as $key => $r) {
|
||||
$tab = $r["Nat_SubGroupName"];
|
||||
$result[] = ["tab" => $tab, "tab_id" => $key + 1, "is_paket" => "N", "items" => []];
|
||||
$idx = count($result) - 1;
|
||||
$a_px = explode("|", $r["TestList"]);
|
||||
foreach ($a_px as $px) {
|
||||
list($testID, $testName, $testPrice, $sasCode) = explode("^", $px);
|
||||
if ($testPrice == 0 && $r["child_test"] != "[]") {
|
||||
$child_test = json_decode($r["child_test"], true);
|
||||
foreach ($child_test as $t) {
|
||||
$testPrice += $t["T_PriceTotal"];
|
||||
}
|
||||
}
|
||||
$is_skip = false;
|
||||
foreach ($filters as $ft) {
|
||||
if (stripos($testName, $ft) !== false) {
|
||||
$is_skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($is_skip) {
|
||||
continue;
|
||||
}
|
||||
$items = [
|
||||
"testID" => $testID,
|
||||
"testName" => $testName,
|
||||
"testPrice" => $testPrice,
|
||||
"is_paket" => "N",
|
||||
"sasCode" => $sasCode
|
||||
];
|
||||
$result[$idx]["items"][] = $items;
|
||||
}
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_PacketID,
|
||||
T_PacketName,
|
||||
T_PacketPrice,
|
||||
T_PacketType,
|
||||
GROUP_CONCAT(T_TestName SEPARATOR ', ') AS detail,
|
||||
GROUP_CONCAT(T_TestID SEPARATOR ', ') AS tests
|
||||
FROM one_mitra.t_packet
|
||||
JOIN one_mitra.t_packetdetail
|
||||
ON T_PacketID = T_PacketDetailT_PacketID
|
||||
AND T_PacketDetailIsActive = 'Y'
|
||||
JOIN one_mitra.t_test
|
||||
ON T_PacketDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
AND T_TestIsPrice = 'Y'
|
||||
WHERE T_PacketIsActive = 'Y'
|
||||
AND T_PacketM_MouID = ?
|
||||
GROUP BY T_PacketID";
|
||||
$qry = $this->db_regional->query($sql, [
|
||||
$mou_id,
|
||||
]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db_regional->error()["message"] .
|
||||
"|" .
|
||||
$this->db_regional->last_query(),
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$paket = $qry->result_array();
|
||||
|
||||
$paket_data = [];
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
$items = [
|
||||
"testID" => $paket[$i]['T_PacketID'],
|
||||
"testName" => $paket[$i]['T_PacketName'],
|
||||
"testPrice" => $paket[$i]['T_PacketPrice'],
|
||||
"arrTest" => $paket[$i]['tests'],
|
||||
"type" => $paket[$i]['T_PacketType'],
|
||||
"is_paket" => "Y",
|
||||
"sasCode" => $paket[$i]['detail']
|
||||
];
|
||||
$paket_data[] = $items;
|
||||
}
|
||||
// $result[] = ["tab" => "Paket", "tab_id" => count($result) + 1, "is_paket" => "Y", "items" => $paket_data];
|
||||
array_unshift($result, ["tab" => "Paket", "tab_id" => count($result) + 1, "is_paket" => "Y", "items" => $paket_data]);
|
||||
for ($i = 0; $i < count($result); $i++) {
|
||||
$result[$i]["tab_id"] = $i + 1;
|
||||
}
|
||||
echo json_encode(["status" => "OK", "data" => $result]);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,644 @@
|
||||
<?php
|
||||
|
||||
class Order extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
function getorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
$startDate = $prm['start_date'];
|
||||
$endDate = $prm['end_date'];
|
||||
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
$sql_total = "SELECT
|
||||
COUNT(T_OrderID) AS total
|
||||
FROM one_mitra.t_order
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderDate >= ? AND T_OrderDate <= ?
|
||||
AND (T_OrderNumber LIKE ? OR M_PatientName LIKE ?)
|
||||
AND T_OrderM_CompanyID = ?
|
||||
AND T_OrderS_RegionalID = ?";
|
||||
$query_total = $this->db->query($sql_total, [$startDate, $endDate, $keyword, $keyword, $companyID, $regionalID]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
// print_r($totals);
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderID AS order_id,
|
||||
T_OrderNumber AS order_number,
|
||||
T_OrderM_PatientID AS patient_id,
|
||||
M_PatientName AS patient_name,
|
||||
DATE_FORMAT(T_OrderDate, '%Y-%m-%d') AS date,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestName SEPARATOR '|') AS tests,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketName SEPARATOR '|' ) AS packetName,
|
||||
IFNULL(T_OrderDetailDeliveryID, 'N') AS status,
|
||||
T_OrderStatus AS status_pemeriksaan,
|
||||
T_OrderStatusQR AS status_qr,
|
||||
M_PatientPrefix AS prefix,
|
||||
M_PatientSuffix AS suffix,
|
||||
M_PatientDOB AS dob,
|
||||
M_PatientNIK AS NIK,
|
||||
M_PatientNIP AS NIP,
|
||||
M_PatientTitleID AS title,
|
||||
M_PatientM_SexID AS sexID,
|
||||
M_PatientHP AS hp,
|
||||
M_PatientAddress AS address,
|
||||
T_OrderNote AS note,
|
||||
T_OrderDiagnosis AS diagnosis,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestID) AS testsID,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailID,'|',T_OrderDetailTestID, '|', T_OrderDetailTestDate)) AS testDetail,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailBahanID ,'|',T_OrderDetailBahanNat_BahanID, '|', T_OrderDetailBahanName,'|',T_OrderDetailBahanQty)) AS bahan,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailSampleID,'|',T_OrderDetailSampleNat_SampleTypeID, '|',T_OrderDetailSampleName,'|', T_OrderDetailSampleQty)) AS sample,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketT_PacketID) AS packet,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailPacketID, '|', T_OrderDetailPacketT_PacketID )) AS packetDetail
|
||||
FROM one_mitra.t_order
|
||||
LEFT JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderID = T_OrderDetailDeliveryT_OrderID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailsample
|
||||
ON T_OrderID = T_OrderDetailSampleT_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailbahan
|
||||
ON T_OrderID = T_OrderDetailBahanT_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderDate >= ? AND T_OrderDate <= ?
|
||||
AND (T_OrderNumber LIKE ? OR M_PatientName LIKE ?)
|
||||
AND T_OrderM_CompanyID = ?
|
||||
AND T_OrderS_RegionalID = ?
|
||||
GROUP BY T_OrderID
|
||||
LIMIT ? OFFSET ?";
|
||||
$query = $this->db->query($sql, [$startDate, $endDate, $keyword, $keyword, $companyID, $regionalID, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
// packetName
|
||||
for ($i = 0; $i < count($search); $i++) {
|
||||
$tes = explode('|', $search[$i]['tests']);
|
||||
$bahan = explode(',', $search[$i]['bahan']);
|
||||
$paket = explode(',', $search[$i]['packet']);
|
||||
$paketName = explode('|', $search[$i]['packetName']);
|
||||
$sample = explode(',', $search[$i]['sample']);
|
||||
$testsID = explode(',', $search[$i]['testsID']);
|
||||
$testdetail = explode(',', $search[$i]['testDetail']);
|
||||
$packetDetail = explode(',', $search[$i]['packetDetail']);
|
||||
$search[$i]['tests'] = array_merge($tes, $paketName);
|
||||
$search[$i]['bahan'] = $bahan;
|
||||
$search[$i]['sample'] = $sample;
|
||||
$search[$i]['testsID'] = $testsID;
|
||||
$search[$i]['testDetail'] = $testdetail;
|
||||
$search[$i]['packet'] = $paket;
|
||||
$search[$i]['packetDetail'] = $packetDetail;
|
||||
// $tes = array_merge($tes, $paketName);
|
||||
}
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage)
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function editOrder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$tests = $prm['tests'];
|
||||
$specimens = $prm['specimens'];
|
||||
$bahan = $prm['bahan'];
|
||||
$orderID = $prm['orderID'];
|
||||
$patientID = $prm['patient_id'];
|
||||
$paket = $prm['paket'];
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
// print_r($this->sys_user);
|
||||
// exit;
|
||||
$this->db->trans_begin();
|
||||
$sql_old = "SELECT DISTINCT
|
||||
T_OrderID AS id,
|
||||
T_OrderNote AS note,
|
||||
T_OrderDiagnosis AS diagnosis,
|
||||
T_OrderTotal AS total,
|
||||
T_OrderDetailID AS detailID,
|
||||
T_OrderDetailTestID AS testID,
|
||||
T_OrderDetailTotal AS detailTotal,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailID, '|',T_OrderDetailTestID , '|',T_OrderDetailTotal )SEPARATOR '^') AS detail,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailBahanID , '|',T_OrderDetailBahanNat_BahanID , '|',T_OrderDetailBahanQty ) SEPARATOR '^') AS bahan,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailSampleID , '|',T_OrderDetailSampleNat_SampleTypeID, '|',T_OrderDetailSampleQty)SEPARATOR '^') AS sample,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailPacketID, '|', T_OrderDetailPacketT_PacketID )) AS packet
|
||||
FROM
|
||||
one_mitra.t_order
|
||||
JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailsample
|
||||
ON T_OrderID = T_OrderDetailSampleT_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailbahan
|
||||
ON T_OrderID = T_OrderDetailBahanT_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query_old = $this->db->query($sql_old, [$orderID]);
|
||||
if (!$query_old) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$rst_old = $query_old->result_array()[0];
|
||||
//order detail old
|
||||
$detail_old = explode('^', $rst_old['detail']);
|
||||
$arr_detail = array();
|
||||
$arr_detailID = array();
|
||||
for ($i = 0; $i < count($detail_old); $i++) {
|
||||
$splitted = explode('|', $detail_old[$i]);
|
||||
$arr_detail[] = [
|
||||
"id" => $splitted[0],
|
||||
"testID" => $splitted[1],
|
||||
];
|
||||
$arr_detailID[] = $splitted[1];
|
||||
}
|
||||
$rst_old['detail'] = $arr_detail;
|
||||
//sample detail old
|
||||
$sample_old = explode('^', $rst_old['sample']);
|
||||
$arr_sample = array();
|
||||
for ($i = 0; $i < count($sample_old); $i++) {
|
||||
$splitted = explode('|', $sample_old[$i]);
|
||||
$arr_sample[] = [
|
||||
"id" => $splitted[0],
|
||||
"sampleID" => $splitted[1],
|
||||
"qty" => $splitted[2],
|
||||
];
|
||||
}
|
||||
$rst_old['sample'] = $arr_sample;
|
||||
//bahan detail old
|
||||
$bahan_old = explode('^', $rst_old['bahan']);
|
||||
$arr_bahan = array();
|
||||
for ($i = 0; $i < count($bahan_old); $i++) {
|
||||
$splitted = explode('|', $bahan_old[$i]);
|
||||
$arr_bahan[] = [
|
||||
"id" => $splitted[0],
|
||||
"bahanID" => $splitted[1],
|
||||
"qty" => $splitted[2],
|
||||
];
|
||||
}
|
||||
$rst_old['bahan'] = $arr_bahan;
|
||||
//paket detail old
|
||||
$paket_old = explode(',', $rst_old['packet']);
|
||||
$arr_paket = array();
|
||||
for ($i = 0; $i < count($paket_old); $i++) {
|
||||
$splitted = explode('|', $paket_old[$i]);
|
||||
$arr_paket[] = [
|
||||
"id" => $splitted[0],
|
||||
"paket_id" => $splitted[1],
|
||||
];
|
||||
}
|
||||
$rst_old['packet'] = $arr_paket;
|
||||
|
||||
|
||||
$this->db->set("T_OrderNote", $patient['note'])
|
||||
->set("T_OrderDiagnosis", $patient['diagnosis'])
|
||||
->set("T_OrderTotal", intval($prm['total']))
|
||||
->set("T_OrderUserID", $userid)
|
||||
->where("T_OrderID", $orderID)->update('one_mitra.t_order');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("m_patient rows", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$arr_new_test = array();
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
$arr_new_test[] = $tests[$i]['id'];
|
||||
}
|
||||
$arr_sampleIdnew = array();
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
$arr_sampleIdnew[] = $specimens[$i]['id'];
|
||||
}
|
||||
$arr_bahanIdnew = array();
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
$arr_bahanIdnew[] = $bahan[$i]['id'];
|
||||
}
|
||||
$arr_paketIdnew = array();
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
$arr_paketIdnew[] = $paket[$i]['id'];
|
||||
}
|
||||
// $this->db->trans_commit();
|
||||
|
||||
// $this->sys_ok($rst_old);
|
||||
// $this->sys_ok(["new test" => $arr_new_test, "old_test" => $arr_detail]);
|
||||
// return;
|
||||
|
||||
//deleted test
|
||||
for ($i = 0; $i < count($arr_detail); $i++) {
|
||||
//deleted
|
||||
if (!in_array($arr_detail[$i]['testID'], $arr_new_test)) {
|
||||
$this->db->set("T_OrderDetailIsActive", 'N')
|
||||
->where("T_OrderDetailID", $arr_detail[$i]['id'])->update('one_mitra.t_orderdetail');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
//New test
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
//new
|
||||
if ($tests[$i]['detailID'] == 'new') {
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailOrderID" => $orderID,
|
||||
"T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
"T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
"T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
"T_OrderDetailTestDate" => $dt,
|
||||
"T_OrderDetailUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
$this->db->set("T_OrderDetailTestDate", $dt)
|
||||
->set("T_OrderDetailUserID", $userid)
|
||||
->where("T_OrderDetailID", $tests[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetail');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// if (!in_array($tests[$i]['id'], $arr_detailID)) {
|
||||
// $coba = strtotime($tests[$i]['date']);
|
||||
// $dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
// $order = [
|
||||
// "T_OrderDetailOrderID" => $orderID,
|
||||
// "T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
// "T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
// "T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
// "T_OrderDetailTestDate" => $dt,
|
||||
// "T_OrderDetailUserID" => $userid,
|
||||
|
||||
// ];
|
||||
|
||||
// $this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
// $err = $this->db->error();
|
||||
// if (
|
||||
// $err['message'] != ""
|
||||
// ) {
|
||||
// $this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
// $this->db->trans_rollback();
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// $this->sys_ok($rst_old);
|
||||
// $this->sys_ok(["new sample" => $arr_sampleIdnew, "old_sample" => $arr_sample]);
|
||||
// return;
|
||||
//deleted sample
|
||||
for ($i = 0; $i < count($arr_sample); $i++) {
|
||||
if (!in_array($arr_sample[$i]['sampleID'], $arr_sampleIdnew)) {
|
||||
$this->db->set("T_OrderDetailSampleIsActive", 'N')
|
||||
->where("T_OrderDetailSampleID", $arr_sample[$i]['id'])->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
//new & updated sample
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
if ($specimens[$i]['detailID'] == "new") {
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$order = [
|
||||
"T_OrderDetailSampleT_OrderID" => $orderID,
|
||||
"T_OrderDetailSampleNat_SampleTypeID" => $specimens[$i]['id'],
|
||||
"T_OrderDetailSampleName" => $specimens[$i]['name'],
|
||||
"T_OrderDetailSampleQty" => $specimens[$i]['amount'],
|
||||
"T_OrderDetailSampleUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailsample', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$this->db->set("T_OrderDetailSampleQty", $specimens[$i]['amount'])
|
||||
->set("T_OrderDetailSampleUserID", $userid)
|
||||
->where("T_OrderDetailSampleID", $specimens[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
if (!in_array($arr_sample[$i]['sampleID'], $arr_sampleIdnew)) {
|
||||
$this->db->set("T_OrderDetailSampleIsActive", 'N')
|
||||
->where("T_OrderDetailSampleID", $specimens[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//deleted bahan
|
||||
for ($i = 0; $i < count($arr_bahan); $i++) {
|
||||
if (!in_array($arr_bahan[$i]['bahanID'], $arr_bahanIdnew)) {
|
||||
$this->db->set("T_OrderDetailBahanIsActive", 'N')
|
||||
->where("T_OrderDetailBahanID", $arr_bahan[$i]['id'])->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//new and update bahan
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
if ($bahan[$i]['detailID'] == "new") {
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailBahanT_OrderID" => $orderID,
|
||||
"T_OrderDetailBahanNat_BahanID" => $bahan[$i]['id'],
|
||||
"T_OrderDetailBahanName" => $bahan[$i]['name'],
|
||||
"T_OrderDetailBahanQty" => $bahan[$i]['amount'],
|
||||
"T_OrderDetailBahanUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailbahan', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
$this->db->set("T_OrderDetailBahanQty", $bahan[$i]['amount'])
|
||||
->set("T_OrderDetailBahanUserID", $userid)
|
||||
->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$this->db->set("T_OrderDetailBahanIsActive", 'N')
|
||||
->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//deleted paket
|
||||
for ($i = 0; $i < count($arr_paket); $i++) {
|
||||
if (!in_array($arr_paket[$i]['paket_id'], $arr_paketIdnew)) {
|
||||
$this->db->set("T_OrderDetailPacketIsActive", 'N')
|
||||
->where("T_OrderDetailPacketID", $arr_paket[$i]['id'])->update('one_mitra.t_orderdetailpacket');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE PACKET DETAIL ", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//new and paket
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
if ($paket[$i]['detail_id'] == "new") {
|
||||
$order = [
|
||||
"T_OrderDetailPacketOrderID" => $orderID,
|
||||
"T_OrderDetailPacketT_PacketID" => $paket[$i]['id'],
|
||||
"T_OrderDetailPacketName" => $paket[$i]['name'],
|
||||
"T_OrderDetailPacketUserID" => $userid,
|
||||
"T_OrderDetailPacketPrice" => $paket[$i]['price'],
|
||||
"T_OrderDetailPacketT_PacketType" => $paket[$i]["type"],
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailpacket', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL PAKET", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// else {
|
||||
|
||||
// $this->db->set("T_OrderDetailBahanQty", $bahan[$i]['amount'])
|
||||
// ->set("T_OrderDetailBahanUserID", $userid)
|
||||
// ->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])
|
||||
// ->update('one_mitra.t_orderdetailbahan');
|
||||
// $err = $this->db->error();
|
||||
// if (
|
||||
// $err['message'] != ""
|
||||
// ) {
|
||||
// $this->sys_error_db("ERROR UPDATE ORDER DETAIL BAHAN", $this->db);
|
||||
// $this->db->trans_rollback();
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$this->sys_ok("OK");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function cancel()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT T_OrderDetailDeliveryID AS CEK
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryT_OrderID = ?
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $query->result_array();
|
||||
if (count($cek) == 0) {
|
||||
# code...
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_order SET T_OrderIsActive = 'N'
|
||||
WHERE T_OrderID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_orderdetail SET T_OrderDetailIsActive = 'N'
|
||||
WHERE T_OrderDetailOrderID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} else {
|
||||
$this->sys_ok("Sudah di buat surat jalan");
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
class Patient extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
// hitung start_offset
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
|
||||
$sql_total = "SELECT
|
||||
COUNT(M_PatientID) AS total
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientM_CompanyID = ?
|
||||
AND (M_PatientName LIKE ? OR
|
||||
M_PatientNIK LIKE ? OR M_PatientHP LIKE ?)";
|
||||
$query_total = $this->db->query($sql_total, [$companyID, $keyword, $keyword, $keyword]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_PatientID AS id,
|
||||
M_PatientPrefix AS prefix,
|
||||
M_PatientName AS name,
|
||||
M_PatientSuffix AS suffix,
|
||||
M_PatientDOB AS dob,
|
||||
M_PatientNIK AS nik,
|
||||
M_PatientNIP AS nip,
|
||||
M_PatientTitleID AS title_id,
|
||||
M_PatientM_SexID AS sex_id,
|
||||
M_PatientHP AS hp,
|
||||
M_PatientAddress AS address,
|
||||
M_PatientNoRM AS noRM,
|
||||
M_PatientM_CompanyID
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientM_CompanyID = ?
|
||||
AND (M_PatientName LIKE ? OR
|
||||
M_PatientNIK LIKE ? OR M_PatientHP LIKE ?)
|
||||
ORDER BY M_PatientName
|
||||
LIMIT ? OFFSET ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$companyID, $keyword, $keyword, $keyword, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage)
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
<?php
|
||||
|
||||
class Registration extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
function getfilter()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql_gender = "SELECT M_SexID AS id,
|
||||
m_sexname AS name
|
||||
FROM one_mitra.m_sex
|
||||
WHERE M_SexIsActive = 'Y'";
|
||||
$query_gender = $this->db->query($sql_gender, []);
|
||||
if (!$query_gender) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$genders = $query_gender->result_array();
|
||||
$sql_title = "SELECT M_TitleID AS id,
|
||||
M_TitleM_SexID AS type,
|
||||
M_TitleName AS name
|
||||
FROM one_mitra.m_title WHERE M_TitleIsActive = 'Y'";
|
||||
$query_title = $this->db->query($sql_title, []);
|
||||
if (!$query_title) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$titles = $query_title->result_array();
|
||||
|
||||
$sql_regional = "SELECT
|
||||
S_RegionalID AS regional_id,
|
||||
S_RegionalName AS regional_name
|
||||
FROM one_mitra.s_regional WHERE S_RegionalIsActive = 'Y'";
|
||||
$query_regional = $this->db->query($sql_regional, []);
|
||||
if (!$query_regional) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$regionals = $query_regional->result_array();
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName AS branch_name,
|
||||
M_BranchS_RegionalID AS regional_id
|
||||
FROM one_mitra.m_branch Where M_BranchIsActive = 'Y'";
|
||||
$query_branch = $this->db->query($sql_branch, []);
|
||||
if (!$query_branch) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$branchs = $query_branch->result_array();
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
$regionals[$i]['branch'] = [];
|
||||
}
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
for ($j = 0; $j < count($branchs); $j++) {
|
||||
if ($regionals[$i]['regional_id'] == $branchs[$j]['regional_id']) {
|
||||
$regionals[$i]['branch'][] = $branchs[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = array(
|
||||
"titles" => $titles,
|
||||
"gender" => $genders,
|
||||
"regional" => $regionals
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getsampletype()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$arr_test = 0;
|
||||
if (isset($prm['arr_test'])) {
|
||||
$arr_test = $prm['arr_test'];
|
||||
} else {
|
||||
$this->sys_error("arr_test is mandatory");
|
||||
}
|
||||
// print_r($arr_test);
|
||||
$result = array();
|
||||
for ($i = 0; $i < count($arr_test); $i++) {
|
||||
$test = $arr_test[$i];
|
||||
$sasCode = substr($test['sasCode'], 0, 8) . "%";
|
||||
$sql = "SELECT T_TestID AS id
|
||||
FROM t_test
|
||||
WHERE T_TestSasCode LIKE ?
|
||||
AND T_TestIsActive = 'Y'";
|
||||
$qry = $this->db_regional->query($sql, [$sasCode]);
|
||||
if (!$qry) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$allTest = $qry->result_array();
|
||||
$arr = [];
|
||||
for ($k = 0; $k < count($allTest); $k++) {
|
||||
$arr[] = $allTest[$k]['id'];
|
||||
}
|
||||
// print_r($arr);
|
||||
|
||||
$implodeTest = implode(",", $arr);
|
||||
|
||||
$sql_specimen = "SELECT Nat_TestID,
|
||||
Nat_TestName,
|
||||
T_TestID,
|
||||
T_TestName,
|
||||
Nat_SampleTypeID,
|
||||
Nat_SampleTypeNat_BahanID,
|
||||
Nat_SampleTypeName,
|
||||
Nat_BahanID,
|
||||
Nat_BahanName
|
||||
FROM nat_test
|
||||
JOIN t_test
|
||||
ON Nat_TestID = T_TestNat_TestID
|
||||
AND T_TestID IN ($implodeTest)
|
||||
AND T_TestIsActive = 'Y'
|
||||
JOIN nat_sampletype
|
||||
ON Nat_TestNat_SampleTypeID = Nat_SampleTypeID
|
||||
AND Nat_SampleTypeIsActive = 'Y'
|
||||
JOIN nat_bahan
|
||||
ON Nat_SampleTypeNat_BahanID = Nat_BahanID
|
||||
WHERE Nat_TestIsActive = 'Y'
|
||||
|
||||
";
|
||||
// GROUP_CONCAT(DISTINCT CONCAT(Nat_SampleTypeID, '^', Nat_SampleTypeName)) AS sampletype,
|
||||
// GROUP_CONCAT(DISTINCT CONCAT(Nat_BahanID, '^', Nat_BahanName)) AS nat_bahan
|
||||
// GROUP BY Nat_SampleTypeID, Nat_BahanID
|
||||
$qry_specimen = $this->db_regional->query($sql_specimen, []);
|
||||
// echo $this->db_regional->last_query();
|
||||
// exit;
|
||||
if (!$qry_specimen) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$specimen = $qry_specimen->result_array();
|
||||
// print_r($specimen);
|
||||
// exit;
|
||||
$data = array(
|
||||
"id" => $test['id'],
|
||||
"tab" => $test['tab'],
|
||||
"specimen" => [],
|
||||
"bahan" => []
|
||||
);
|
||||
// print_r($specimen);
|
||||
// if (count($specimen) > 0) {
|
||||
// if ($specimen[0]['sampletype'] != null && $specimen[0]['nat_bahan'] != null) {
|
||||
|
||||
// $sampleType = explode(',', $specimen[0]['sampletype']);
|
||||
// $natBahan = explode(',', $specimen[0]['nat_bahan']);
|
||||
// // print_r($sampleType);
|
||||
// // print_r($natBahan);
|
||||
|
||||
|
||||
// for ($i = 0; $i < count($sampleType); $i++) {
|
||||
// $temp = explode('^', $sampleType[$i]);
|
||||
// $data['specimen'][] = array(
|
||||
// "id" => $temp[0],
|
||||
// "name" => $temp[1]
|
||||
// );
|
||||
// }
|
||||
// for ($i = 0; $i < count($natBahan); $i++) {
|
||||
// $temp = explode('^', $natBahan[$i]);
|
||||
// $data['bahan'][] = array(
|
||||
// "id" => $temp[0],
|
||||
// "name" => $temp[1]
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for ($j = 0; $j < count($specimen); $j++) {
|
||||
$sp = $specimen[$j];
|
||||
$tempSp = array(
|
||||
"id" => $sp["Nat_SampleTypeID"],
|
||||
"name" => $sp['Nat_SampleTypeName']
|
||||
);
|
||||
$tempBhn = array(
|
||||
"id" => $sp["Nat_BahanID"],
|
||||
"name" => $sp['Nat_BahanName']
|
||||
);
|
||||
if (!in_array($tempSp, $data['specimen'])) {
|
||||
$data['specimen'][] = array(
|
||||
"id" => $sp["Nat_SampleTypeID"],
|
||||
"name" => $sp['Nat_SampleTypeName']
|
||||
);
|
||||
}
|
||||
if (!in_array($tempBhn, $data['bahan'])) {
|
||||
$data['bahan'][] = array(
|
||||
"id" => $sp["Nat_BahanID"],
|
||||
"name" => $sp['Nat_BahanName']
|
||||
);
|
||||
}
|
||||
}
|
||||
$result[] = $data;
|
||||
}
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function addpatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$paket = $prm['paket'];
|
||||
$patientDOB = date('Y-m-d', strtotime($patient['dob']));
|
||||
$withoutNIK = $patient['without_nik'];
|
||||
$nik = $patient['nik'];
|
||||
$tests = $prm['tests'];
|
||||
$specimens = $prm['specimens'];
|
||||
$bahan = $prm['bahan'];
|
||||
$patientID = $prm['patient_id'];
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
// print_r($this->sys_user);
|
||||
// exit;
|
||||
$isNIK = 'N';
|
||||
|
||||
$this->db->trans_begin();
|
||||
if ($withoutNIK == 'Y') {
|
||||
$nik = "0";
|
||||
}
|
||||
if ($patientID == "new") {
|
||||
if ($withoutNIK == "N") {
|
||||
$isNIK = 'Y';
|
||||
}
|
||||
$ptn = [
|
||||
"M_PatientPrefix" => $patient['prefix'],
|
||||
"M_PatientTitleID" => $patient['saluation'],
|
||||
"M_PatientName" => $patient['name'],
|
||||
"M_PatientSuffix" => $patient['suffix'],
|
||||
"M_PatientDOB" => $patientDOB,
|
||||
"M_PatientNIK" => $nik,
|
||||
"M_PatientNIP" => $patient['nip'],
|
||||
"M_PatientIsNIK" => $isNIK,
|
||||
"M_PatientM_SexID" => $patient['gender'],
|
||||
"M_PatientHP" => $patient['hp'],
|
||||
"M_PatientAddress" => $patient['address'],
|
||||
"M_PatientNoRM" => $patient['noRM'],
|
||||
"M_PatientM_CompanyID" => $companyID,
|
||||
"M_PatientUserID" => $userid,
|
||||
|
||||
];
|
||||
$this->db->insert('one_mitra.m_patient', $ptn);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT PATIENT", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$patientID = $this->db->insert_id();
|
||||
if ($withoutNIK == 'Y') {
|
||||
$awalan = sprintf("%05s", intval($companyID)) . $patientID;
|
||||
// print_r($awalan);
|
||||
$nik = str_pad($awalan, 16, "0");
|
||||
// print_r($nik);
|
||||
$this->db->set("M_PatientNIK", $nik)->where("M_PatientID", $patientID)->update('one_mitra.m_patient');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("m_patient rows", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT one_mitra.fn_numbering('MT') as number";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$message = $this->db->error();
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$number = $qry->result_array()[0]['number'];
|
||||
$total = intval($prm['total']);
|
||||
|
||||
$order = [
|
||||
"T_OrderNumber" => $number,
|
||||
"T_OrderM_PatientID" => $patientID,
|
||||
"T_OrderM_MouID" => $mouID,
|
||||
"T_OrderM_CompanyID" => $companyID,
|
||||
"T_OrderS_RegionalID" => $regionalID,
|
||||
"T_OrderNote" => $patient['note'],
|
||||
"T_OrderDiagnosis" => $patient['diagnosis'],
|
||||
"T_OrderUserID" => $userid,
|
||||
"T_OrderTotal" => $total,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_order', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$orderId = $this->db->insert_id();
|
||||
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
// T_OrderDetailID int(11) Auto Increment
|
||||
// T_OrderDetailOrderID int(11)
|
||||
// T_OrderDetailTestID int(11)
|
||||
// T_OrderDetailTestName varchar(30)
|
||||
// T_OrderDetailTotal int(11)
|
||||
// T_OrderDetailUserID
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailOrderID" => $orderId,
|
||||
"T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
"T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
"T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
"T_OrderDetailTestDate" => $dt,
|
||||
"T_OrderDetailUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
// T_OrderDetailSampleT_OrderID int(11)
|
||||
// T_OrderDetailSampleNat_SampleTypeID int(11)
|
||||
// T_OrderDetailSampleName varchar(200)
|
||||
// T_OrderDetailSampleQty varchar(200)
|
||||
// T_OrderDetailSampleUserID
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$order = [
|
||||
"T_OrderDetailSampleT_OrderID" => $orderId,
|
||||
"T_OrderDetailSampleNat_SampleTypeID" => $specimens[$i]['id'],
|
||||
"T_OrderDetailSampleName" => $specimens[$i]['name'],
|
||||
"T_OrderDetailSampleQty" => $specimens[$i]['amount'],
|
||||
"T_OrderDetailSampleUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailsample', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
// T_OrderDetailBahanT_OrderID int(11)
|
||||
// T_OrderDetailBahanNat_BahanID int(11)
|
||||
// T_OrderDetailBahanName int(11)
|
||||
// T_OrderDetailBahanQty varchar(200)
|
||||
// T_OrderDetailBahanUserID
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
# code...
|
||||
$order = [
|
||||
"T_OrderDetailBahanT_OrderID" => $orderId,
|
||||
"T_OrderDetailBahanNat_BahanID" => $bahan[$i]['id'],
|
||||
"T_OrderDetailBahanName" => $bahan[$i]['name'],
|
||||
"T_OrderDetailBahanQty" => $bahan[$i]['amount'],
|
||||
"T_OrderDetailBahanUserID" => $userid,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailbahan', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
//T_OrderDetailPacketID int(11) Auto Increment
|
||||
// T_OrderDetailPacketT_PacketID int(11)
|
||||
// T_OrderDetailPacketName varchar(250)
|
||||
// T_OrderDetailPacketIsActive char(1) [Y]
|
||||
// T_OrderDetailPacketUserID int(11)
|
||||
// T_OrderDetailPacketCreated datetime [current_timestamp()]
|
||||
// T_OrderDetailPacketLastUpdated
|
||||
|
||||
# code...
|
||||
$order = [
|
||||
"T_OrderDetailPacketOrderID" => $orderId,
|
||||
"T_OrderDetailPacketPrice" => $paket[$i]['price'],
|
||||
"T_OrderDetailPacketT_PacketType" => $paket[$i]["type"],
|
||||
"T_OrderDetailPacketT_PacketID" => $paket[$i]['id'],
|
||||
"T_OrderDetailPacketName" => $paket[$i]['name'],
|
||||
"T_OrderDetailPacketUserID" => $userid,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailpacket', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = [
|
||||
"patientID" => $patientID,
|
||||
"orderID" => $orderId,
|
||||
"orderNumber" => $number,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
class Updatestatusreg extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: UPDATE STATUS X/R";
|
||||
}
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
|
||||
function reply_gz($resp, $debug = "")
|
||||
{
|
||||
if ($debug != "") {
|
||||
echo json_encode($resp);
|
||||
} else {
|
||||
echo gzcompress(json_encode($resp));
|
||||
}
|
||||
}
|
||||
|
||||
function get_param()
|
||||
{
|
||||
$body = file_get_contents("php://input");
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
function get_param_z()
|
||||
{
|
||||
$body_z = file_get_contents("php://input");
|
||||
$body = gzuncompress($body_z);
|
||||
return json_decode($body, true);
|
||||
}
|
||||
function updatestatusorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param_z();
|
||||
|
||||
$orderList = $prm['order'];
|
||||
$waList = $prm['wa'];
|
||||
$success = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
$successWa = [];
|
||||
$errorWa = [];
|
||||
$errorMsgWa = [];
|
||||
for ($i = 0; $i < count($orderList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [$orderList[$i]]);
|
||||
if (!$qry_update) {
|
||||
$error[] = $orderList[$i];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} else {
|
||||
$success[] = $orderList[$i];
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($waList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatusQR = 'S'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, $waList[$i]);
|
||||
if (!$qry_update) {
|
||||
$errorWa[] = $waList[$i];
|
||||
$errorMsgWa[] = $this->db->error();
|
||||
} else {
|
||||
$successWa[] = $waList[$i];
|
||||
}
|
||||
}
|
||||
$resultOrder = [
|
||||
"success" => $success,
|
||||
"error" => $error,
|
||||
"message" => $errorMsg,
|
||||
];
|
||||
$resultWa = [
|
||||
"success" => $successWa,
|
||||
"error" => $errorWa,
|
||||
"message" => $errorMsgWa,
|
||||
];
|
||||
|
||||
|
||||
$result = [
|
||||
"order" => $resultOrder,
|
||||
"wa" => $resultWa
|
||||
];
|
||||
$this->reply_gz($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updatestatus()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$successUpdate = array();
|
||||
$errorUpdate = array();
|
||||
$errorMsg = array();
|
||||
for ($i = 0; $i < count($prm); $i++) {
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = ?
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive ='Y'";
|
||||
$query = $this->db->query($sql, [$prm[$i]['T_OrderStatus'], $prm[$i]['T_OrderID']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorUpdate[] = $prm[$i]['T_OrderID'];
|
||||
$errorMsg[] = $message;
|
||||
} else {
|
||||
for ($j = 0; $j < count($prm[$i]['sample']); $j++) {
|
||||
if ($prm[$i]['sample'][$j]['type'] == "S") {
|
||||
$sql_update = "UPDATE one_mitra.t_orderdetailsample
|
||||
SET T_OrderDetailSampleStatus = ?
|
||||
WHERE T_OrderDetailSampleID = ?
|
||||
AND T_OrderDetailSampleIsActive = 'Y'";
|
||||
$query_update = $this->db->query($sql_update, [
|
||||
$prm[$i]['sample'][$j]['status'],
|
||||
$prm[$i]['sample'][$j]['id']
|
||||
]);
|
||||
if (!$query_update) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorMsg[] = $message;
|
||||
}
|
||||
} else if ($prm[$i]['sample'][$j]['type'] == "B") {
|
||||
$sql_update = "UPDATE one_mitra.t_orderdetailbahan
|
||||
SET T_OrderDetailBahanStatus = ?
|
||||
WHERE T_OrderDetailBahanID = ?
|
||||
AND T_OrderDetailBahanIsActive = 'Y'";
|
||||
$query_update = $this->db->query($sql_update, [
|
||||
$prm[$i]['sample'][$j]['status'],
|
||||
$prm[$i]['sample'][$j]['id']
|
||||
]);
|
||||
if (!$query_update) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorMsg[] = $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
$successUpdate[] = $prm[$i]['T_OrderID'];
|
||||
}
|
||||
}
|
||||
// $result = $query->result_array();
|
||||
// $z_param = gzcompress(json_encode($result));
|
||||
|
||||
$result = [
|
||||
"success" => $successUpdate,
|
||||
"error" => $errorUpdate,
|
||||
"msg" => $errorMsg,
|
||||
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updatestatuspq()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$successUpdate = array();
|
||||
$errorUpdate = array();
|
||||
$errorMsg = array();
|
||||
for ($i = 0; $i < count($prm); $i++) {
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = ?
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive ='Y'";
|
||||
$query = $this->db->query($sql, [$prm[$i]['status'], $prm[$i]['orderID']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorUpdate[] = $prm[$i]['orderID'];
|
||||
$errorMsg[] = $message;
|
||||
} else {
|
||||
$successUpdate[] = $prm[$i]['orderID'];
|
||||
}
|
||||
}
|
||||
// $result = $query->result_array();
|
||||
// $z_param = gzcompress(json_encode($result));
|
||||
|
||||
$result = [
|
||||
"success" => $successUpdate,
|
||||
"error" => $errorUpdate,
|
||||
"msg" => $errorMsg,
|
||||
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function checkorderdone()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT
|
||||
T_OrderID AS orderID,
|
||||
T_OrderNumber AS orderNumber,
|
||||
YEAR(T_OrderDate) AS year,
|
||||
T_OrderM_CompanyID AS company_id
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderStatus IN ('P', 'Q')
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rst = $query->result_array();
|
||||
// $a = glob("/data-s3/$companyID/$yearFull/$orderNum*pdf");
|
||||
// $rst[] = [
|
||||
// "company_id" => "1710",
|
||||
// "year" => "2023",
|
||||
// "orderNumber" => "MT231010001"
|
||||
// ];
|
||||
$orderList = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
$success = [];
|
||||
for ($i = 0; $i < count($rst); $i++) {
|
||||
$companyID = $rst[$i]["company_id"];
|
||||
$year = $rst[$i]["year"];
|
||||
$orderNumber = $rst[$i]["orderNumber"];
|
||||
$a = glob("/data-s3/$companyID/$year/$orderNumber*pdf");
|
||||
if (count($a) > 0) {
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'D'
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$rst[$i]["orderID"]]);
|
||||
if (!$query) {
|
||||
$error[] = $rst[$i]["orderNumber"];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} {
|
||||
$success[] = $rst[$i]["orderNumber"];
|
||||
}
|
||||
}
|
||||
$orderList[] = $orderNumber;
|
||||
}
|
||||
$result = [
|
||||
"list_order" => $orderList,
|
||||
"error" => $error,
|
||||
"success" => $success,
|
||||
"errorMsg" => $errorMsg
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
<?php
|
||||
class User extends MY_Controller
|
||||
{
|
||||
var $load;
|
||||
var $db_mitra;
|
||||
var $db_mitra_log;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
$this->db_mitra = "one_mitra";
|
||||
$this->db_mitra_log = "mitra_log";
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db_regional->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "MASTER USER";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM $this->db_mitra.m_user
|
||||
JOIN m_company ON M_UserM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
JOIN $this->db_mitra.s_regional ON M_UserS_RegionalID = S_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_mou ON M_UserM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND (M_UserUsername LIKE ?)";
|
||||
|
||||
$qry_filter = $this->db_regional->query($sql_filter, [$search]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("user total error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_UserID,
|
||||
M_CompanyID,
|
||||
M_CompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_MouID,
|
||||
M_MouName,
|
||||
M_UserUsername,
|
||||
M_UserPassword,
|
||||
M_UserLastAccess,
|
||||
M_UserIsLoggedIn,
|
||||
M_UserM_UserID
|
||||
FROM $this->db_mitra.m_user
|
||||
JOIN m_company ON M_UserM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
JOIN $this->db_mitra.s_regional ON M_UserS_RegionalID = S_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_mou ON M_UserM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
WHERE M_UserIsActive = 'Y' AND (M_UserUsername LIKE ?)
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$qry = $this->db_regional->query($sql, [$search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select user error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search_company()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM m_company
|
||||
WHERE M_CompanyIsActive = 'Y'
|
||||
AND (M_CompanyName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_filter = $this->db_regional->query($sql_filter, [$search, $number_limit]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("company count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_search = "SELECT M_CompanyID,
|
||||
M_CompanyName,
|
||||
M_CompanyNumber
|
||||
FROM m_company
|
||||
WHERE M_CompanyIsActive = 'Y'
|
||||
AND (M_CompanyName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_search = $this->db_regional->query($sql_search, [$search, $number_limit]);
|
||||
if ($qry_search) {
|
||||
$rows = $qry_search->result_array();
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("company select error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_count,
|
||||
"total_display" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function get_regional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "SELECT S_RegionalID,
|
||||
S_RegionalName
|
||||
FROM $this->db_mitra.s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'";
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("regional select error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db_regional->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search_mou()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM m_mou
|
||||
WHERE M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND (M_MouName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_filter = $this->db_regional->query($sql_filter, [$search, $number_limit]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("mou count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_search = "SELECT M_MouID,
|
||||
M_MouName,
|
||||
M_MouNumber
|
||||
FROM m_mou
|
||||
WHERE M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND (M_MouName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_search = $this->db_regional->query($sql_search, [$search, $number_limit]);
|
||||
if ($qry_search) {
|
||||
$rows = $qry_search->result_array();
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("mou select error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_count,
|
||||
"total_display" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function add()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db_regional->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$companyId = "";
|
||||
if (isset($prm["companyId"])) {
|
||||
$companyId = trim($prm["companyId"]);
|
||||
}
|
||||
|
||||
$regionalId = "";
|
||||
if (isset($prm["regionalId"])) {
|
||||
$regionalId = trim($prm["regionalId"]);
|
||||
}
|
||||
|
||||
$mouId = "";
|
||||
if (isset($prm["mouId"])) {
|
||||
$mouId = trim($prm["mouId"]);
|
||||
}
|
||||
|
||||
$username = "";
|
||||
if (isset($prm["username"])) {
|
||||
$username = trim($prm["username"]);
|
||||
}
|
||||
|
||||
$password = "";
|
||||
if (isset($prm["password"])) {
|
||||
$password = trim($prm["password"]);
|
||||
}
|
||||
|
||||
$confirm_password = "";
|
||||
if (isset($prm["confirm_password"])) {
|
||||
$confirm_password = trim($prm["confirm_password"]);
|
||||
}
|
||||
|
||||
if ($password !== $confirm_password) {
|
||||
$error = "password dan konfirmasi password harus sama";
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
// cek username tidak boleh sama
|
||||
$sql_cek_username = "SELECT count(*) as total_user
|
||||
FROM $this->db_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserUsername = ?";
|
||||
$qry_cek_username = $this->db_regional->query($sql_cek_username, [$username]);
|
||||
if ($qry_cek_username) {
|
||||
$get_count_username = $qry_cek_username->row_array();
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("ERROR, cek user", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($get_count_username["total_user"] == 0) {
|
||||
$sm_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
|
||||
|
||||
$sql_insert = "INSERT INTO $this->db_mitra.m_user(
|
||||
M_UserM_CompanyID,
|
||||
M_UserS_RegionalID,
|
||||
M_UserM_MouID,
|
||||
M_UserUsername,
|
||||
M_UserPassword,
|
||||
M_UserCreated,
|
||||
M_UserLastUpdated,
|
||||
M_UserLastAccess,
|
||||
M_UserM_UserID) VALUES(?,?,?,?,?,NOW(),NOW(),NOW(),?)";
|
||||
$qry_insert = $this->db_regional->query($sql_insert, [
|
||||
$companyId,
|
||||
$regionalId,
|
||||
$mouId,
|
||||
$username,
|
||||
$sm_password,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_insert) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("user insert error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$insert_id = $this->db_regional->insert_id();
|
||||
|
||||
$sql_json_before = "SELECT *
|
||||
FROM $this->db_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$qry_json_before = $this->db_regional->query($sql_json_before, [$insert_id]);
|
||||
if (!$qry_json_before) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user select json error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_by_id = $qry_json_before->row();
|
||||
|
||||
$json_after_log = json_encode($data_by_id);
|
||||
|
||||
$sql_insert_log = "INSERT INTO $this->db_mitra_log.m_user_log(
|
||||
M_UserLogM_UserID,
|
||||
M_UserLogStatus,
|
||||
M_UserLogJSONBefore,
|
||||
M_UserLogJSONAfter,
|
||||
M_UserLogUserID,
|
||||
M_UserLogCreated) VALUES(?,'ADD',null,?,?,NOW())";
|
||||
$qry_insert_log = $this->db_regional->query($sql_insert_log, [
|
||||
$insert_id,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_insert_log) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user_log insert error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("Username sudah digunakan. Silahkan masukkan username yang lain", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_regional->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$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;
|
||||
}
|
||||
$this->db_regional->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
class Auth extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $db_log;
|
||||
var $db;
|
||||
var $load;
|
||||
public function index()
|
||||
{
|
||||
// echo "AUTH API";
|
||||
// $query = $this->db->query(
|
||||
// "show databases
|
||||
// ",
|
||||
// array()
|
||||
// );
|
||||
// // print_r($this->db_regional->last_query());
|
||||
// if (!$query) {
|
||||
// $message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
// exit;
|
||||
// }
|
||||
// $rows = $query->result_array();
|
||||
// echo json_encode($rows);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// $this->db_regional = $this->db->query("use one_mitra");
|
||||
// $this->db_log = $this->db->query("use mitra_log");
|
||||
}
|
||||
|
||||
function isLogin()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
} else {
|
||||
$prm = $this->sys_input;
|
||||
$data = array(
|
||||
"user" => $this->sys_user
|
||||
);
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
}
|
||||
|
||||
function login()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
//existing password enc
|
||||
// print_r($prm);
|
||||
$sm_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"SELECT M_UserID,
|
||||
M_UserUsername,
|
||||
M_UserM_CompanyID,
|
||||
M_UserM_MouID,
|
||||
M_CompanyName as company_name,
|
||||
M_UserS_RegionalID
|
||||
from one_mitra.m_user
|
||||
JOIN m_company ON M_UserM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
where M_UserUsername= ? and M_UserPassword= ?
|
||||
and M_UserIsActive = 'Y'
|
||||
",
|
||||
array($prm["username"], $sm_password)
|
||||
);
|
||||
// print_r($this->db_regional->last_query());
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message, $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$user = $rows[0];
|
||||
$user['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$token = JWT::encode($user, $this->SECRET_KEY);
|
||||
$data = array(
|
||||
"user" => $user,
|
||||
"token" => $token
|
||||
);
|
||||
|
||||
$query = $this->db->query("UPDATE one_mitra.m_user
|
||||
SET M_UserIsLoggedIn = 'Y',
|
||||
M_UserLastAccess = now(),
|
||||
M_UserActiveToken = '{$token}'
|
||||
WHERE M_UserID = ?
|
||||
", array($user['M_UserID']));
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $this->db->query("INSERT INTO mitra_log.log_login
|
||||
(Log_LoginDateTime,
|
||||
Log_LoginIP,
|
||||
Log_LoginType,
|
||||
Log_LoginStatus,
|
||||
Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGIN', 'SUCCESS', $prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($data);
|
||||
exit;
|
||||
}
|
||||
$query = $this->db->query("INSERT INTO mitra_log.log_login
|
||||
(Log_LoginDateTime,
|
||||
Log_LoginIP,
|
||||
Log_LoginType,
|
||||
Log_LoginStatus,
|
||||
Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $this->input->ip_address(), 'LOGIN', 'FAILED', $prm["username"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_log->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$this->sys_error_db("Invalid UserName / Password");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
|
||||
$query = $this->db->query(
|
||||
"UPDATE one_mitra.m_user
|
||||
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
|
||||
WHERE M_UserID = ?",
|
||||
array($prm['M_UserID'])
|
||||
);
|
||||
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->query("INSERT INTO mitra_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
|
||||
", array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $prm['M_UserUsername']));
|
||||
$this->sys_ok("OK");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function changepassword()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Invalid Token")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$currPassword = $prm['current_password'];
|
||||
$newPassword = $prm['new_password'];
|
||||
$passwordConfirmation = $prm['password_confirmation'];
|
||||
if (!isset($prm['new_password']) || empty($prm['new_password'])) {
|
||||
$this->sys_error("Silahkan isi password baru");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['current_password']) || empty($prm['current_password'])) {
|
||||
$this->sys_error("Silahkan isi password lama");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['password_confirmation']) || empty($prm['password_confirmation'])) {
|
||||
$this->sys_error("Silahkan isi konfirmasi password");
|
||||
exit;
|
||||
}
|
||||
if ($newPassword != $passwordConfirmation) {
|
||||
$this->sys_error("Paswword baru dan konfirmasi password tidak sama !");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate password strength
|
||||
$uppercase = preg_match('@[A-Z]@', $prm['new_password']);
|
||||
$lowercase = preg_match('@[a-z]@', $prm['new_password']);
|
||||
$number = preg_match('@[0-9]@', $prm['new_password']);
|
||||
|
||||
if (strlen($prm['new_password']) < 8) {
|
||||
|
||||
$this->sys_error("Password minimal 8 digit");
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$uppercase) {
|
||||
$this->sys_error("Password minimal mengandung 1 huruf besar");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$lowercase) {
|
||||
$this->sys_error("Password minimal mengandung 1 huruf kecil");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$number) {
|
||||
$this->sys_error("Password minimal mengandung 1 angka");
|
||||
exit;
|
||||
}
|
||||
$sm_password = md5($this->one_salt . $currPassword . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"select * from one_mitra.m_user where M_UserID = ? and M_UserPassword = ?",
|
||||
array($userid, $sm_password)
|
||||
);
|
||||
if (!$query) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Query cek error")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Invalid Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$sql_json_before = "SELECT *
|
||||
FROM one_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query(
|
||||
$sql_json_before,
|
||||
[
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user select json before");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_before_by_id = $qry_json_before->row();
|
||||
|
||||
$json_before_log = json_encode($data_before_by_id);
|
||||
|
||||
$new_password_salt = md5($this->one_salt . $newPassword . $this->one_salt);
|
||||
$query = $this->db->query(
|
||||
"UPDATE one_mitra.m_user set
|
||||
M_UserPassword= ?
|
||||
where M_UserID = ?
|
||||
AND M_UserIsActive = 'Y'",
|
||||
array(
|
||||
|
||||
$new_password_salt,
|
||||
// $userID
|
||||
$userid
|
||||
)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => "Error Change Password")
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
// json after
|
||||
$sql_json_after = "SELECT *
|
||||
FROM one_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
|
||||
$qry_json_after = $this->db->query(
|
||||
$sql_json_after,
|
||||
[
|
||||
// $userID
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_after) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user select json after");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_after_by_id = $qry_json_after->row();
|
||||
|
||||
$json_after_log = json_encode($data_after_by_id);
|
||||
// json after
|
||||
|
||||
// proses insert log start
|
||||
$sql_insert_log = "INSERT INTO mitra_log.m_user_log(
|
||||
M_UserLogM_UserID,
|
||||
M_UserLogStatus,
|
||||
M_UserLogJSONBefore,
|
||||
M_UserLogJSONAfter,
|
||||
M_UserLogUserID,
|
||||
M_UserLogCreated
|
||||
) VALUES (
|
||||
?,
|
||||
'CHANGE PASSWORD',
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
now()
|
||||
)";
|
||||
|
||||
$qry_insert_log = $this->db->query(
|
||||
$sql_insert_log,
|
||||
[
|
||||
$userid,
|
||||
$json_before_log,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user insert log");
|
||||
exit;
|
||||
}
|
||||
// proses insert log end
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Berhasil Mengubah Password silahkan login ulang");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
class Dashboard extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function chartdata()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
//month/year
|
||||
$filter = 'month';
|
||||
if (isset($prm['filter'])) {
|
||||
$filter = $prm['filter'];
|
||||
}
|
||||
$company_id = $prm['company_id'];
|
||||
$filter_sql = "";
|
||||
$filter_sql2 = "";
|
||||
$filter_sql_total = "";
|
||||
$select_sql = "";
|
||||
if ($filter == 'month') {
|
||||
$select_sql = "DATE_FORMAT(T_OrderDate, '%d') AS day";
|
||||
$filter_sql2 = "AND MONTH(T_OrderDate) = MONTH(CURDATE())";
|
||||
$filter_sql = ", DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day";
|
||||
$filter_sql_total = " DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day";
|
||||
}
|
||||
if ($filter == 'year') {
|
||||
$select_sql = "DATE_FORMAT(T_OrderDate, '%m') AS month";
|
||||
|
||||
$filter_sql = ", DATE_FORMAT(T_OrderDate, '%Y-%m') ORDER BY month";
|
||||
$filter_sql_total = " DATE_FORMAT(T_OrderDate, '%Y-%m') ORDER BY month";
|
||||
}
|
||||
// SELECT COUNT(T_OrderID) AS total,
|
||||
// T_OrderStatus AS status,
|
||||
// DATE_FORMAT(T_OrderDate, '%d') AS day
|
||||
// from one_mitra.t_order
|
||||
// WHERE T_OrderIsActive = 'Y'
|
||||
// AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
// AND T_OrderM_CompanyID = 1222
|
||||
// GROUP BY T_OrderStatus
|
||||
// ,DATE_FORMAT(T_OrderDate, '%Y-%m-%d') ORDER BY day
|
||||
|
||||
$sql = "SELECT COUNT(T_OrderID) AS total,
|
||||
T_OrderStatus AS status,
|
||||
$select_sql
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
$filter_sql2
|
||||
AND T_OrderM_CompanyID = ?
|
||||
GROUP BY T_OrderStatus
|
||||
$filter_sql";
|
||||
$query = $this->db->query($sql, [$company_id]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$data = $query->result_array();
|
||||
$sql_total = "SELECT COUNT(T_OrderID) AS total,
|
||||
T_OrderStatus AS status,
|
||||
$select_sql
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND YEAR(T_OrderDate) = YEAR(CURDATE())
|
||||
$filter_sql2
|
||||
AND T_OrderM_CompanyID = ?
|
||||
GROUP BY
|
||||
$filter_sql_total";
|
||||
$query_total = $this->db->query($sql_total, [$company_id]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$data_total = $query_total->result_array();
|
||||
$result = array(
|
||||
"N" => [],
|
||||
"S" => [],
|
||||
"Y" => [],
|
||||
"T" => [],
|
||||
"last_query" => $this->db->last_query()
|
||||
);
|
||||
// N = New, S= Send, P= Parsial, D=Done,
|
||||
if ($filter == 'month') {
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if ($data[$i]['status'] == 'N') {
|
||||
$result['N'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'S') {
|
||||
$result['S'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'Y') {
|
||||
$result['Y'][] = "{$data[$i]['day']}|{$data[$i]['total']}";
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($data_total); $i++) {
|
||||
$result['T'][] = "{$data_total[$i]['day']}|{$data_total[$i]['total']}";
|
||||
}
|
||||
}
|
||||
if ($filter == 'year') {
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if ($data[$i]['status'] == 'N') {
|
||||
$result['N'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'S') {
|
||||
$result['S'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
if ($data[$i]['status'] == 'Y') {
|
||||
$result['Y'][] = "{$data[$i]['month']}|{$data[$i]['total']}";
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($data_total); $i++) {
|
||||
$result['T'][] = "{$data_total[$i]['month']}|{$data_total[$i]['total']}";
|
||||
}
|
||||
}
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
|
||||
$companyID = $prm['company_id'];
|
||||
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS id,
|
||||
DATE_FORMAT(T_OrderDeliveryDate, '%d/%m/%Y') AS date,
|
||||
T_OrderDeliveryNumber AS order_number,
|
||||
M_UserUsername AS pic,
|
||||
T_DeliveryTypeName AS type,
|
||||
T_OrderDeliveryStatus AS status,
|
||||
M_BranchName AS destination
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN one_mitra.t_deliverytype
|
||||
ON T_OrderDeliveryT_DeliverytypeID = T_DeliveryTypeID
|
||||
AND T_DeliveryTypeIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON T_OrderDeliveryDestination = M_BranchID
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND T_OrderDeliveryStatus IN ('S', 'P')
|
||||
ORDER BY T_OrderDeliveryDate DESC
|
||||
";
|
||||
$query = $this->db->query($sql, [$companyID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,580 @@
|
||||
<?php
|
||||
|
||||
class Deliveryorder extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function getdeliverytype()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_DeliveryTypeID AS id,
|
||||
T_DeliveryTypeName AS name,
|
||||
T_DeliveryTypeIsAgent AS isAgent
|
||||
FROM one_mitra.t_deliverytype
|
||||
WHERE T_DeliveryTypeIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$company_id = 0;
|
||||
if (isset($prm['company_id'])) {
|
||||
$company_id = trim($prm["company_id"]);
|
||||
$company_id = $prm['company_id'];
|
||||
} else {
|
||||
$this->sys_error("company_id is mandatory");
|
||||
}
|
||||
$regional_id = 0;
|
||||
if (isset($prm['regional_id'])) {
|
||||
$regional_id = trim($prm["regional_id"]);
|
||||
$regional_id = $prm['regional_id'];
|
||||
} else {
|
||||
$this->sys_error("regional_id is mandatory");
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_OrderID AS order_id,
|
||||
T_OrderNumber AS order_number,
|
||||
M_PatientID AS patient_id,
|
||||
M_PatientName AS patient_name,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestName SEPARATOR '|') AS test,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketName SEPARATOR '|') AS packet
|
||||
FROM one_mitra.t_order
|
||||
JOIN one_mitra.m_patient ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderM_CompanyID = ?
|
||||
AND T_OrderIsActive = 'Y'
|
||||
AND T_OrderS_RegionalID = ?
|
||||
AND T_OrderID NOT IN (SELECT T_OrderDetailDeliveryT_OrderID FROM
|
||||
one_mitra.t_orderdetaildelivery WHERE T_OrderDetailDeliveryIsActive ='Y'
|
||||
AND T_OrderDetailDeliveryM_CompanyID = ?)
|
||||
GROUP BY T_OrderID";
|
||||
$query = $this->db->query($sql, [$company_id, $regional_id, $company_id]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$arrOrder = $query->result_array();
|
||||
$result = [];
|
||||
for ($i = 0; $i < count($arrOrder); $i++) {
|
||||
$test = explode('|', $arrOrder[$i]['test']);
|
||||
$packet = explode('|', $arrOrder[$i]['packet']);
|
||||
|
||||
$result[] = [
|
||||
"order_id" => $arrOrder[$i]['order_id'],
|
||||
"order_number" => $arrOrder[$i]['order_number'],
|
||||
"patient_id" => $arrOrder[$i]['patient_id'],
|
||||
"patient_name" => $arrOrder[$i]['patient_name'],
|
||||
"sample" => [],
|
||||
"bahan" => [],
|
||||
"tests" => array_merge($test, $packet)
|
||||
];
|
||||
};
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdestination()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName branch_name
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'";
|
||||
$query = $this->db_regional->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function addDelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$order = $prm['order'];
|
||||
$orderDetail = $prm['order_detail'];
|
||||
// T_OrderDeliveryID int(11) Auto Increment
|
||||
// T_OrderDeliveryNumber varchar(25)
|
||||
// T_OrderDeliveryStaffID int(11)
|
||||
// T_OrderDeliveryNoRef varchar(25)
|
||||
// T_OrderDeliveryDate date
|
||||
// T_OrderDeliveryDestination int(11) Branch ID
|
||||
// T_OrderDeliveryBoxTemperature varchar(25)
|
||||
// T_OrderDeliveryT_DeliverytypeID int(11)
|
||||
// T_OrderDeliveryReciptNumber varchar(40)
|
||||
// T_OrderDeliveryNote tinytext
|
||||
// T_OrderDeliveryIsActive char(1) [Y]
|
||||
// T_OrderDeliveryCreated datetime [current_timestamp()]
|
||||
// T_OrderDeliveryLastUpdated
|
||||
$this->db->trans_begin();
|
||||
$sql = "SELECT one_mitra.fn_numbering('SJ') as number";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$message = $this->db->error();
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$number = $qry->result_array()[0]['number'];
|
||||
$get2first = substr($number, 0, 2);
|
||||
$getDate = strval(date("ym"));
|
||||
$newNumber = $get2first . $order['branch_code'] . $getDate . substr($number, -3);
|
||||
$orderDelivery = [
|
||||
"T_OrderDeliveryStaffID" => $order['staff_id'],
|
||||
"T_OrderDeliveryNumber" => $newNumber,
|
||||
"T_OrderDeliveryNoRef" => $order['no_ref'],
|
||||
"T_OrderDeliveryDate" => date('Y-m-d', strtotime($order['date'])),
|
||||
"T_OrderDeliveryDestination" => $order['destination_id'],
|
||||
"T_OrderDeliveryRegionalID" => $order['regional_id'],
|
||||
"T_OrderDeliveryBoxTemperature" => $order['temperature'],
|
||||
"T_OrderDeliveryT_DeliverytypeID" => $order['type_id'],
|
||||
"T_OrderDeliveryReciptNumber" => $order['no_resi'],
|
||||
"T_OrderDeliveryNote" => $order['note'],
|
||||
"T_OrderDeliveryM_CompanyID" => $order['company_id'],
|
||||
];
|
||||
$this->db->insert('one_mitra.t_orderdelivery', $orderDelivery);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DELIVERY", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$deliveryID = $this->db->insert_id();
|
||||
|
||||
for ($i = 0; $i < count($orderDetail); $i++) {
|
||||
// Column Type Comment
|
||||
// T_OrderDetailDeliveryID int(11) Auto Increment
|
||||
// T_OrderDetailDeliveryT_OrderDeliveryID int(11)
|
||||
// T_OrderDetailDeliveryT_OrderID int(11)
|
||||
// T_OrderDetailDeliveryIsActive char(1) [Y]
|
||||
// T_OrderDetailDeliveryCreated datetime [current_timestamp()]
|
||||
// T_OrderDetailDeliveryLastUpdated
|
||||
|
||||
$deliveryDetail = [
|
||||
"T_OrderDetailDeliveryT_OrderDeliveryID" => $deliveryID,
|
||||
"T_OrderDetailDeliveryT_OrderID" => $orderDetail[$i]['order_id'],
|
||||
"T_OrderDetailDeliveryM_CompanyID" => $order['company_id'],
|
||||
];
|
||||
$this->db->insert('one_mitra.t_orderdetaildelivery', $deliveryDetail);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DELIVERY DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$result = [
|
||||
"deliveryID" => $deliveryID,
|
||||
"orderNumber" => $newNumber,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getdelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
$startDate = $prm['start_date'];
|
||||
$endDate = $prm['end_date'];
|
||||
// 1 => tanggal surat jalan
|
||||
// 2 => tanggal kedatangan
|
||||
$datetype = $prm['date_type'];
|
||||
$datetypeSql = "T_OrderDeliveryCreated";
|
||||
if (intval($datetype) == 1) {
|
||||
$datetypeSql = "T_OrderDeliveryCreated";
|
||||
} else if (intval($datetype) == 2) {
|
||||
$datetypeSql = "T_OrderDeliveryDate";
|
||||
}
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
$sql_total = "SELECT COUNT(T_OrderDeliveryID) AS total
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON T_OrderDeliveryDestination = M_BranchID
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND (T_OrderDeliveryNumber LIKE ?
|
||||
OR M_UserUsername LIKE ? OR M_BranchName LIKE ?)
|
||||
AND T_OrderDeliveryRegionalID = ?
|
||||
AND $datetypeSql >= ? AND $datetypeSql <= ?";
|
||||
$query_total = $this->db->query($sql_total, [$companyID, $keyword, $keyword, $keyword, $regionalID, $startDate, $endDate]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$last_qry = $this->db->last_query();
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
// print_r($totals);
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS id,
|
||||
DATE_FORMAT(T_OrderDeliveryDate, '%d/%m/%Y') AS date,
|
||||
DATE_FORMAT(T_OrderDeliveryCreated, '%d/%m/%Y') AS date_sj,
|
||||
T_OrderDeliveryNumber AS order_number,
|
||||
M_UserUsername AS pic,
|
||||
T_OrderDeliveryStatus AS status,
|
||||
M_BranchName AS destination
|
||||
FROM one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.m_user
|
||||
ON T_OrderDeliveryStaffID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON T_OrderDeliveryDestination = M_BranchID
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDeliveryIsActive = 'Y' AND
|
||||
T_OrderDeliveryM_CompanyID = ?
|
||||
AND (T_OrderDeliveryNumber LIKE ?
|
||||
OR M_UserUsername LIKE ? OR M_BranchName LIKE ?)
|
||||
AND T_OrderDeliveryRegionalID = ?
|
||||
AND DATE_FORMAT($datetypeSql, '%Y-%m-%d') >= ? AND DATE_FORMAT($datetypeSql, '%Y-%m-%d') <= ?
|
||||
ORDER BY $datetypeSql DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$query = $this->db->query($sql, [$companyID, $keyword, $keyword, $keyword, $regionalID, $startDate, $endDate, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage),
|
||||
"qry_total" => $this->db->last_query(),
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function detaildelivery()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_OrderDeliveryID AS delivery_id,
|
||||
T_OrderDeliveryNumber AS delivery_number,
|
||||
T_OrderNumber AS order_number,
|
||||
T_OrderDetailDeliveryID AS delivery_detail_id,
|
||||
T_OrderDetailDeliveryT_OrderID AS order_id,
|
||||
DATE_FORMAT(T_OrderDate, '%d/%m/%Y') AS date,
|
||||
M_PatientName AS patient_name,
|
||||
T_OrderStatus AS status,
|
||||
one_mitra.fn_get_acc_sample(T_OrderDetailDeliveryT_OrderID) AS accepted_sample,
|
||||
one_mitra.fn_get_rejct_sample(T_OrderDetailDeliveryT_OrderID) AS rejected_sample
|
||||
FROM
|
||||
one_mitra.t_orderdelivery
|
||||
JOIN one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDeliveryID = T_OrderDetailDeliveryT_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
JOIN one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderIsActive = 'Y'
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
WHERE T_OrderDeliveryID = ?
|
||||
AND T_OrderDeliveryIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$this->sys_ok($search);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function cancel()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_orderdelivery SET T_OrderDeliveryIsActive = 'N'
|
||||
WHERE T_OrderDeliveryID = ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_orderdetaildelivery SET T_OrderDetailDeliveryIsActive = 'N'
|
||||
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function send()
|
||||
{
|
||||
try {
|
||||
// $aql = "UPDATE t_orderdelivery SET T_OrderDeliveryStatus = 'S'
|
||||
// WHERE T_OrderDeliveryID = 1;
|
||||
|
||||
// UPDATE t_order SET T_OrderStatus = 'S'
|
||||
// WHERE T_OrderID IN (
|
||||
// SELECT T_OrderDetailDeliveryT_OrderID
|
||||
// FROM t_orderdetaildelivery
|
||||
// WHERE T_OrderDetailDeliveryT_OrderDeliveryID = 1)";
|
||||
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_orderdelivery SET T_OrderDeliveryStatus = 'S'
|
||||
WHERE T_OrderDeliveryID = ?;
|
||||
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_order SET T_OrderStatus = 'S'
|
||||
WHERE T_OrderID IN (
|
||||
SELECT T_OrderDetailDeliveryT_OrderID
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = ?)
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getregional()
|
||||
{
|
||||
try {
|
||||
|
||||
$sql_regional = "SELECT
|
||||
S_RegionalID AS regional_id,
|
||||
S_RegionalName AS regional_name
|
||||
FROM s_regional WHERE S_RegionalIsActive = 'Y'";
|
||||
$query_regional = $this->db->query($sql_regional, []);
|
||||
if (!$query_regional) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$regionals = $query_regional->result_array();
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName AS branch_name,
|
||||
M_BranchS_RegionalID AS regional_id
|
||||
FROM m_branch Where M_BranchIsActive = 'Y'";
|
||||
$query_branch = $this->db->query($sql_branch, []);
|
||||
if (!$query_branch) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$branchs = $query_branch->result_array();
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
$regionals[$i]['branch'] = [];
|
||||
}
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
for ($j = 0; $j < count($branchs); $j++) {
|
||||
if ($regionals[$i]['regional_id'] == $branchs[$j]['regional_id']) {
|
||||
$regionals[$i]['branch'][] = $branchs[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->sys_ok($regionals);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function sendqrcode()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$arr_order_id = 0;
|
||||
if (isset($prm['arr_order_id'])) {
|
||||
$arr_order_id = $prm['arr_order_id'];
|
||||
} else {
|
||||
$this->sys_error("arr_order_id is mandatory");
|
||||
}
|
||||
$arr_order_id = implode(",", $arr_order_id);
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderIsQRCode = 'Y'
|
||||
WHERE T_OrderID IN ($arr_order_id)
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
print_r($this->db->last_query());
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($this->db->last_query());
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,750 @@
|
||||
<?php
|
||||
class DownloadOrder extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Api: Download Order Mitra DEVKEDUNGDORORAYA";
|
||||
}
|
||||
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
|
||||
function reply_gz($resp, $debug = "")
|
||||
{
|
||||
if ($debug != "") {
|
||||
echo json_encode($resp);
|
||||
} else {
|
||||
echo gzcompress(json_encode($resp));
|
||||
}
|
||||
}
|
||||
|
||||
function get_param()
|
||||
{
|
||||
$body = file_get_contents("php://input");
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
function get_param_z()
|
||||
{
|
||||
$body_z = file_get_contents("php://input");
|
||||
$body = gzuncompress($body_z);
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
// t_orderdelivery
|
||||
function getData_t_orderdelivery($wherein_T_OrderDeliveryID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdelivery
|
||||
WHERE T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryID IN ($wherein_T_OrderDeliveryID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery for get data | func getData_t_orderdelivery " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
// print_r($rows_fields);
|
||||
}
|
||||
|
||||
// t_orderdetaildelivery
|
||||
function getData_t_orderdetaildelivery($wherein_T_OrderDetailDeliveryID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDetailDeliveryID IN ($wherein_T_OrderDetailDeliveryID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetaildelivery for get data | func getData_t_orderdetaildelivery " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_order
|
||||
function getData_t_order($wherein_T_OrderID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID IN ($wherein_T_OrderID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_order for get data | func getData_t_order " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetail
|
||||
function getData_t_orderdetail($wherein_T_OrderDetailID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetail
|
||||
WHERE T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailID IN ($wherein_T_OrderDetailID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetail for get data | func getData_t_orderdetail " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetailbahan
|
||||
function getData_t_orderdetailbahan($wherein_T_OrderDetailBahanID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailbahan
|
||||
WHERE T_OrderDetailBahanIsActive = 'Y'
|
||||
AND T_OrderDetailBahanID IN ($wherein_T_OrderDetailBahanID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailbahan for get data | func getData_t_orderdetailbahan " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// t_orderdetailsample
|
||||
function getData_t_orderdetailsample($wherein_T_OrderDetailSampleID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailsample
|
||||
WHERE T_OrderDetailSampleIsActive = 'Y'
|
||||
AND T_OrderDetailSampleID IN ($wherein_T_OrderDetailSampleID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailsample for get data | func getData_t_orderdetailsample " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
// m_patient
|
||||
function getData_m_patient($wherein_M_PatientID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientID IN ($wherein_M_PatientID)";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailsample for get data | func getData_t_orderdetailsample " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
function getData_t_orderdetailpacket($packetID)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM one_mitra.t_orderdetailpacket
|
||||
WHERE T_OrderDetailPacketID in ($packetID)
|
||||
AND T_OrderDetailPacketIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdetailpacket for get data | func getData_t_orderdetailpacket " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_fields = $qry->result_array();
|
||||
if (count($rows_fields) > 0) {
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
return $rows_fields;
|
||||
}
|
||||
|
||||
function reg_download_old($debug = "")
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$limit = 2;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
$branchId = ($debug != "") ? 1 : $prm['branchId'];
|
||||
// $branchId = 1;
|
||||
$branchCode = $prm['branchCode'];
|
||||
|
||||
$sql_pivot = "SELECT T_OrderDeliveryNumber,
|
||||
T_OrderDeliveryID
|
||||
from one_mitra.t_orderdelivery
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId";
|
||||
// LIMIT $limit ";
|
||||
|
||||
$qry_pivot = $this->db_regional->query($sql_pivot);
|
||||
|
||||
if (!$qry_pivot) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot = $qry_pivot->result_array();
|
||||
// print_r($rows_pivot);
|
||||
// exit;
|
||||
|
||||
// T_Order
|
||||
$sql_pivot_t_order = "SELECT
|
||||
T_OrderID
|
||||
from one_mitra.t_orderdelivery
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId
|
||||
join one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
|
||||
$qry_pivot_t_order = $this->db_regional->query($sql_pivot_t_order);
|
||||
|
||||
if (!$qry_pivot_t_order) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot_t_order = $qry_pivot_t_order->result_array();
|
||||
|
||||
// print_r($rows_pivot_t_order);
|
||||
// exit;
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = "";
|
||||
$string_wherein_T_OrderID = "";
|
||||
|
||||
$T_OrderDeliveryID_arr = [];
|
||||
$T_OrderID_arr = [];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
foreach ($rows_pivot as $key => $vx) {
|
||||
$T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
// $T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
}
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
// $string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
}
|
||||
|
||||
// T_Order
|
||||
if (count($rows_pivot_t_order) > 0) {
|
||||
foreach ($rows_pivot_t_order as $key => $vx) {
|
||||
// $T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
$T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
}
|
||||
|
||||
// $string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
$string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
}
|
||||
|
||||
$result = [
|
||||
"t_orderdelivery" => [],
|
||||
"t_orderdetaildelivery" => [],
|
||||
"t_order" => [],
|
||||
"t_orderdetail" => [],
|
||||
"t_orderdetailbahan" => [],
|
||||
"t_orderdetailsample" => [],
|
||||
];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
// ambil all data sesuai pivot
|
||||
|
||||
// 1. t_orderdelivery
|
||||
$t_orderdelivery = $this->getData_t_orderdelivery($string_wherein_T_OrderDeliveryID);
|
||||
|
||||
// 2. t_orderdetaildelivery
|
||||
$t_orderdetaildelivery = $this->getData_t_orderdetaildelivery($string_wherein_T_OrderDeliveryID);
|
||||
}
|
||||
|
||||
if (count($rows_pivot_t_order) > 0) {
|
||||
// 3. t_order
|
||||
$t_order = $this->getData_t_order($string_wherein_T_OrderID);
|
||||
|
||||
// 4. t_orderdetail
|
||||
$t_orderdetail = $this->getData_t_orderdetail($string_wherein_T_OrderID);
|
||||
|
||||
// 5. t_orderdetailbahan
|
||||
$t_orderdetailbahan = $this->getData_t_orderdetailbahan($string_wherein_T_OrderID);
|
||||
|
||||
// 6. t_orderdetailsample
|
||||
$t_orderdetailsample = $this->getData_t_orderdetailsample($string_wherein_T_OrderID);
|
||||
|
||||
$result["t_orderdelivery"] = $t_orderdelivery;
|
||||
$result["t_orderdetaildelivery"] = $t_orderdetaildelivery;
|
||||
$result["t_order"] = $t_order;
|
||||
$result["t_orderdetail"] = $t_orderdetail;
|
||||
$result["t_orderdetailbahan"] = $t_orderdetailbahan;
|
||||
$result["t_orderdetailsample"] = $t_orderdetailsample;
|
||||
|
||||
if ($debug != "") {
|
||||
echo "<pre>";
|
||||
echo print_r($result);
|
||||
echo "</pre>";
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(
|
||||
[
|
||||
"status" => "OK",
|
||||
"message" => "Data Ditemukan",
|
||||
"data" => [$result]
|
||||
]
|
||||
);
|
||||
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
// $result_x = array(
|
||||
// 'status' => 'OK',
|
||||
// "message" => "Tidak ada data terbaru",
|
||||
// "data" => [$result]
|
||||
// );
|
||||
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
} else {
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
$result_x = array(
|
||||
'status' => 'ERR',
|
||||
"message" => "Tidak ada data terbaru",
|
||||
"data" => []
|
||||
);
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
|
||||
echo json_encode($result_x);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$result = array(
|
||||
'status' => 'err',
|
||||
"message" => $message,
|
||||
);
|
||||
$this->reply_gz($result);
|
||||
}
|
||||
}
|
||||
|
||||
function reg_download($debug = "")
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$limit = 2;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
$branchId = ($debug != "") ? 1 : $prm['branchId'];
|
||||
// $branchId = 1;
|
||||
$branchCode = $prm['branchCode'];
|
||||
|
||||
$pickup_status = ($debug != "") ? "S" : $prm['pickup_status'];
|
||||
|
||||
$sql_pivot = "SELECT T_OrderDeliveryNumber,
|
||||
T_OrderDeliveryID,
|
||||
T_OrderID,
|
||||
T_OrderDetailID,
|
||||
T_OrderDetailBahanID,
|
||||
T_OrderDetailSampleID,
|
||||
M_PatientID,
|
||||
T_OrderDetailDeliveryID,
|
||||
T_OrderDetailPacketID
|
||||
from one_mitra.t_orderdelivery
|
||||
|
||||
join one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryStatus = 'S'
|
||||
AND T_OrderDeliveryDestination = $branchId
|
||||
|
||||
join one_mitra.t_order
|
||||
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
|
||||
AND T_OrderIsActive = 'Y'
|
||||
|
||||
join one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
|
||||
LEFT join one_mitra.t_orderdetail
|
||||
ON T_OrderDetailOrderID = T_OrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
|
||||
left join one_mitra.t_orderdetailbahan
|
||||
ON T_OrderDetailBahanT_OrderID = T_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
|
||||
left join one_mitra.t_orderdetailsample
|
||||
ON T_OrderDetailSampleT_OrderID = T_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderDetailPacketOrderID = T_OrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
";
|
||||
// LIMIT $limit ";
|
||||
|
||||
$qry_pivot = $this->db_regional->query($sql_pivot);
|
||||
|
||||
if (!$qry_pivot) {
|
||||
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
// $this->reply_gz($response);
|
||||
$this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$rows_pivot = $qry_pivot->result_array();
|
||||
$last_qry_pivot = $this->db_regional->last_query();
|
||||
|
||||
// print_r($rows_pivot_t_order);
|
||||
// exit;
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = "";
|
||||
$string_wherein_T_OrderDetailDeliveryID = "";
|
||||
$string_wherein_T_OrderID = "";
|
||||
$string_wherein_T_OrderDetailID = "";
|
||||
$string_wherein_T_OrderDetailBahanID = "";
|
||||
$string_wherein_T_OrderDetailSampleID = "";
|
||||
$string_wherein_M_PatientID = "";
|
||||
$string_wherein_T_OrderDetailPacketID = "";
|
||||
|
||||
$T_OrderDeliveryID_arr = [];
|
||||
$T_OrderDetailDeliveryID_arr = [];
|
||||
$T_OrderID_arr = [];
|
||||
$T_OrderDetailID_arr = [];
|
||||
$T_OrderDetailBahanID_arr = [];
|
||||
$T_OrderDetailSampleID_arr = [];
|
||||
$M_PatientID_arr = [];
|
||||
$T_OrderDetailPacketID_arr = [];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
foreach ($rows_pivot as $key => $vx) {
|
||||
$T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
|
||||
$T_OrderDetailDeliveryID_arr[] = intval($vx['T_OrderDetailDeliveryID']);
|
||||
$T_OrderID_arr[] = intval($vx['T_OrderID']);
|
||||
$T_OrderDetailID_arr[] = intval($vx['T_OrderDetailID']);
|
||||
$T_OrderDetailBahanID_arr[] = intval($vx['T_OrderDetailBahanID']);
|
||||
$T_OrderDetailSampleID_arr[] = intval($vx['T_OrderDetailSampleID']);
|
||||
$M_PatientID_arr[] = intval($vx['M_PatientID']);
|
||||
$T_OrderDetailPacketID_arr[] = intval($vx['T_OrderDetailPacketID']);
|
||||
}
|
||||
|
||||
$string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
|
||||
$string_wherein_T_OrderDetailDeliveryID = implode(",", $T_OrderDetailDeliveryID_arr);
|
||||
$string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
|
||||
$string_wherein_T_OrderDetailID = implode(",", $T_OrderDetailID_arr);
|
||||
$string_wherein_T_OrderDetailBahanID = implode(",", $T_OrderDetailBahanID_arr);
|
||||
$string_wherein_T_OrderDetailSampleID = implode(",", $T_OrderDetailSampleID_arr);
|
||||
$string_wherein_M_PatientID = implode(",", $M_PatientID_arr);
|
||||
$string_wherein_T_OrderDetailPacketID = implode(",", $T_OrderDetailPacketID_arr);
|
||||
}
|
||||
|
||||
$result = [
|
||||
"t_orderdelivery" => [],
|
||||
"t_orderdetaildelivery" => [],
|
||||
"t_order" => [],
|
||||
"t_orderdetail" => [],
|
||||
"t_orderdetailbahan" => [],
|
||||
"t_orderdetailsample" => [],
|
||||
"m_patient" => [],
|
||||
"t_orderdetailpacket" => []
|
||||
];
|
||||
|
||||
if (count($rows_pivot) > 0) {
|
||||
// ambil all data sesuai pivot
|
||||
|
||||
// 1. t_orderdelivery
|
||||
$t_orderdelivery = $this->getData_t_orderdelivery($string_wherein_T_OrderDeliveryID);
|
||||
|
||||
// 2. t_orderdetaildelivery
|
||||
$t_orderdetaildelivery = $this->getData_t_orderdetaildelivery($string_wherein_T_OrderDetailDeliveryID);
|
||||
|
||||
// 3. t_order
|
||||
$t_order = $this->getData_t_order($string_wherein_T_OrderID);
|
||||
|
||||
// 4. t_orderdetail
|
||||
$t_orderdetail = $this->getData_t_orderdetail($string_wherein_T_OrderDetailID);
|
||||
|
||||
// 5. t_orderdetailbahan
|
||||
$t_orderdetailbahan = $this->getData_t_orderdetailbahan($string_wherein_T_OrderDetailBahanID);
|
||||
|
||||
// 6. t_orderdetailsample
|
||||
$t_orderdetailsample = $this->getData_t_orderdetailsample($string_wherein_T_OrderDetailSampleID);
|
||||
|
||||
// 7. m_patient
|
||||
$m_patient = $this->getData_m_patient($string_wherein_M_PatientID);
|
||||
|
||||
// 7. getData_t_orderdetailpacket
|
||||
$t_orderdetailpacket = $this->getData_t_orderdetailpacket($string_wherein_T_OrderDetailPacketID);
|
||||
|
||||
$result["t_orderdelivery"] = $t_orderdelivery;
|
||||
$result["t_orderdetaildelivery"] = $t_orderdetaildelivery;
|
||||
$result["t_order"] = $t_order;
|
||||
$result["t_orderdetail"] = $t_orderdetail;
|
||||
$result["t_orderdetailbahan"] = $t_orderdetailbahan;
|
||||
$result["t_orderdetailsample"] = $t_orderdetailsample;
|
||||
$result["m_patient"] = $m_patient;
|
||||
$result["t_orderdetailpacket"] = $t_orderdetailpacket;
|
||||
|
||||
if ($debug != "") {
|
||||
echo "<pre>";
|
||||
echo print_r($result);
|
||||
echo "</pre>";
|
||||
exit;
|
||||
}
|
||||
$result = [
|
||||
"status" => "OK",
|
||||
"message" => "Data Ditemukan",
|
||||
"data" => [$result]
|
||||
];
|
||||
|
||||
// echo json_encode(
|
||||
// [
|
||||
// "status" => "OK",
|
||||
// "message" => "Data Ditemukan",
|
||||
// "data" => [$result]
|
||||
// ]
|
||||
// );
|
||||
$this->reply_gz($result, $debug);
|
||||
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
// $result_x = array(
|
||||
// 'status' => 'OK',
|
||||
// "message" => "Tidak ada data terbaru",
|
||||
// "data" => [$result]
|
||||
// );
|
||||
|
||||
// $this->reply_gz($result_x, $debug);
|
||||
} else {
|
||||
// KLU SUDAH FIX BARU REPLY GZ
|
||||
$result_x = array(
|
||||
'status' => 'ERR',
|
||||
"message" => "Tidak ada data terbaru",
|
||||
// "qry_pivot" => $last_qry_pivot,
|
||||
"data" => []
|
||||
);
|
||||
$this->reply_gz($result_x, $debug);
|
||||
|
||||
// echo json_encode($result_x);
|
||||
// $this->reply_gz($result, $debug);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$result = array(
|
||||
'status' => 'err',
|
||||
"message" => $message,
|
||||
);
|
||||
$this->reply_gz($result);
|
||||
}
|
||||
}
|
||||
|
||||
function reg_update_is_download()
|
||||
{
|
||||
try {
|
||||
// $prm = $this->get_param();
|
||||
$prm = $this->get_param_z();
|
||||
$branchId = $prm['branchId'];
|
||||
// $branchCde = $prm['branchCode'];
|
||||
$dataOrder = $prm['data'];
|
||||
|
||||
$result = [];
|
||||
|
||||
if (count($dataOrder[0]['t_orderdelivery']) > 0) {
|
||||
for ($i = 0; $i < count($dataOrder[0]['t_orderdelivery']); $i++) {
|
||||
$id = $dataOrder[0]['t_orderdelivery'][$i]['T_OrderDeliveryID'];
|
||||
|
||||
$sqlUpdate = "UPDATE one_mitra.t_orderdelivery
|
||||
SET T_OrderDeliveryIsDownloaded = 'Y'
|
||||
, T_OrderDeliveryDownloadedDate = NOW()
|
||||
WHERE T_OrderDeliveryID = $id
|
||||
AND T_OrderDeliveryIsDownloaded = 'N'
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryDestination = $branchId";
|
||||
|
||||
$qryUpdate = $this->db->query($sqlUpdate);
|
||||
if (!$qryUpdate) {
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "update one_mitra.t_orderdelivery | func reg_update_is_download " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"message" => 'Berhasil Di Proses',
|
||||
// "data" => $dataOrder,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"message" => 'Berhasil Di Proses',
|
||||
// "data" => $dataOrder,
|
||||
// "sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUpdatePatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$branchID = $prm['branchId'];
|
||||
$sql = "SELECT T_OrderID,
|
||||
T_OrderDeliveryID,
|
||||
T_OrderIsQRCode,
|
||||
one_mitra.m_patient.*
|
||||
FROM one_mitra.m_patient
|
||||
JOIN one_mitra.t_order
|
||||
ON M_PatientID = T_OrderM_PatientID
|
||||
AND T_OrderIsActive = 'Y'
|
||||
JOIN one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderID = T_OrderDetailDeliveryT_OrderID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
JOIN one_mitra.t_orderdelivery
|
||||
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
|
||||
AND T_OrderDeliveryIsActive = 'Y'
|
||||
AND T_OrderDeliveryStatus IN ('S', 'P')
|
||||
AND T_OrderDeliveryDestination = $branchID
|
||||
WHERE M_PatientLastUpdated > T_OrderDeliveryDownloadedDate";
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "function get update patient data | " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
$this->reply_gz($response);
|
||||
// $this->reply($response);
|
||||
exit;
|
||||
}
|
||||
$result = $qry->result_array();
|
||||
// $this->sys_ok($result);
|
||||
$this->reply_gz(["status" => "OK", "data" => $result]);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateIsDownloadedDate()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param();
|
||||
$arrDeliveryId = $prm['arrDeliveryID'];
|
||||
// $this->reply_gz(["status" => "OK", "data" => $arrDeliveryId]);
|
||||
// exit;
|
||||
for ($i = 0; $i < count($arrDeliveryId); $i++) {
|
||||
$sql = "UPDATE one_mitra.t_orderdelivery
|
||||
SET T_OrderDeliveryDownloadedDate = NOW()
|
||||
WHERE T_OrderDeliveryID = ?";
|
||||
$qry = $this->db_regional->query($sql, [$arrDeliveryId[$i]]);
|
||||
if (!$qry) {
|
||||
$response = ["status" => "ERR", "message" => "function updateIsDownloadedDate | " .
|
||||
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
|
||||
$this->reply_gz($response);
|
||||
// $this->reply($response);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// $this->reply(["status" => "OK", "data" => $arrDeliveryId]);
|
||||
$this->reply_gz(["status" => "OK", "data" => $arrDeliveryId]);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
class Fpp extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function load()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$mou_id = 0;
|
||||
if (isset($prm['mou_id'])) {
|
||||
$mou_id = trim($prm["mou_id"]);
|
||||
$mou_id = $prm['mou_id'];
|
||||
} else {
|
||||
$this->sys_error("mou_id is mandatory");
|
||||
}
|
||||
$sql = "SELECT
|
||||
group_concat(distinct concat(t_test.T_TestID,'^',t_test.T_TestName,'^',T_PriceTotal,'^', t_test.T_TestSasCode) separator '|') TestList,
|
||||
Nat_SubGroupName,
|
||||
child_test
|
||||
from ss_price_mou
|
||||
join t_test on T_PriceIsCito= 'N' and is_packet = 'N'
|
||||
AND Ss_PriceMouM_MouID = ?
|
||||
and ss_price_mou.T_TestID = t_test.T_TestID
|
||||
join nat_subgroup on t_test.T_TestNat_SubGroupID = Nat_SubGroupID
|
||||
group by Nat_SubGroupName
|
||||
order by Nat_SubGroupNat_GroupID";
|
||||
$qry = $this->db_regional->query($sql, [
|
||||
$mou_id,
|
||||
]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db_regional->error()["message"] .
|
||||
"|" .
|
||||
$this->db_regional->last_query(),
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
$filters = ["Home Service", "Cetak", "Layanan"];
|
||||
foreach ($rows as $key => $r) {
|
||||
$tab = $r["Nat_SubGroupName"];
|
||||
$result[] = ["tab" => $tab, "tab_id" => $key + 1, "is_paket" => "N", "items" => []];
|
||||
$idx = count($result) - 1;
|
||||
$a_px = explode("|", $r["TestList"]);
|
||||
foreach ($a_px as $px) {
|
||||
list($testID, $testName, $testPrice, $sasCode) = explode("^", $px);
|
||||
if ($testPrice == 0 && $r["child_test"] != "[]") {
|
||||
$child_test = json_decode($r["child_test"], true);
|
||||
foreach ($child_test as $t) {
|
||||
$testPrice += $t["T_PriceTotal"];
|
||||
}
|
||||
}
|
||||
$is_skip = false;
|
||||
foreach ($filters as $ft) {
|
||||
if (stripos($testName, $ft) !== false) {
|
||||
$is_skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($is_skip) {
|
||||
continue;
|
||||
}
|
||||
$items = [
|
||||
"testID" => $testID,
|
||||
"testName" => $testName,
|
||||
"testPrice" => $testPrice,
|
||||
"is_paket" => "N",
|
||||
"sasCode" => $sasCode
|
||||
];
|
||||
$result[$idx]["items"][] = $items;
|
||||
}
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_PacketID,
|
||||
T_PacketName,
|
||||
T_PacketPrice,
|
||||
T_PacketType,
|
||||
GROUP_CONCAT(T_TestName SEPARATOR ', ') AS detail,
|
||||
GROUP_CONCAT(T_TestID SEPARATOR ', ') AS tests
|
||||
FROM t_packet
|
||||
JOIN t_packetdetail
|
||||
ON T_PacketID = T_PacketDetailT_PacketID
|
||||
AND T_PacketDetailIsActive = 'Y'
|
||||
JOIN t_test
|
||||
ON T_PacketDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
AND T_TestIsPrice = 'Y'
|
||||
WHERE T_PacketIsActive = 'Y'
|
||||
AND T_PacketM_MouID = ?
|
||||
GROUP BY T_PacketID";
|
||||
$qry = $this->db_regional->query($sql, [
|
||||
$mou_id,
|
||||
]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db_regional->error()["message"] .
|
||||
"|" .
|
||||
$this->db_regional->last_query(),
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$paket = $qry->result_array();
|
||||
|
||||
$paket_data = [];
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
$items = [
|
||||
"testID" => $paket[$i]['T_PacketID'],
|
||||
"testName" => $paket[$i]['T_PacketName'],
|
||||
"testPrice" => $paket[$i]['T_PacketPrice'],
|
||||
"arrTest" => $paket[$i]['tests'],
|
||||
"type" => $paket[$i]['T_PacketType'],
|
||||
"is_paket" => "Y",
|
||||
"sasCode" => $paket[$i]['detail']
|
||||
];
|
||||
$paket_data[] = $items;
|
||||
}
|
||||
// $result[] = ["tab" => "Paket", "tab_id" => count($result) + 1, "is_paket" => "Y", "items" => $paket_data];
|
||||
array_unshift($result, ["tab" => "Paket", "tab_id" => count($result) + 1, "is_paket" => "Y", "items" => $paket_data]);
|
||||
for ($i = 0; $i < count($result); $i++) {
|
||||
$result[$i]["tab_id"] = $i + 1;
|
||||
}
|
||||
echo json_encode(["status" => "OK", "data" => $result]);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,673 @@
|
||||
<?php
|
||||
|
||||
class Order extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function getorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
// print_r($prm);
|
||||
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
$startDate = $prm['start_date'];
|
||||
$endDate = $prm['end_date'];
|
||||
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
$sql_total = "SELECT
|
||||
COUNT(T_OrderID) AS total
|
||||
FROM one_mitra.t_order
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderDate >= ? AND T_OrderDate <= ?
|
||||
AND (T_OrderNumber LIKE ? OR M_PatientName LIKE ?)
|
||||
AND T_OrderM_CompanyID = ?
|
||||
AND T_OrderS_RegionalID = ?";
|
||||
$query_total = $this->db->query($sql_total, [$startDate, $endDate, $keyword, $keyword, $companyID, $regionalID]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
// print_r($totals);
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderID AS order_id,
|
||||
T_OrderNumber AS order_number,
|
||||
T_OrderM_PatientID AS patient_id,
|
||||
M_PatientName AS patient_name,
|
||||
DATE_FORMAT(T_OrderDate, '%Y-%m-%d') AS date,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestName SEPARATOR '|') AS tests,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketName SEPARATOR '|' ) AS packetName,
|
||||
IFNULL(T_OrderDetailDeliveryID, 'N') AS status,
|
||||
T_OrderIsQRCode AS is_qr,
|
||||
T_OrderStatus AS status_pemeriksaan,
|
||||
T_OrderStatusQR AS status_qr,
|
||||
M_PatientPrefix AS prefix,
|
||||
M_PatientSuffix AS suffix,
|
||||
M_PatientDOB AS dob,
|
||||
M_PatientNIK AS NIK,
|
||||
M_PatientNIP AS NIP,
|
||||
M_PatientTitleID AS title,
|
||||
M_PatientM_SexID AS sexID,
|
||||
M_PatientHP AS hp,
|
||||
M_PatientJabatan AS jabatan,
|
||||
M_PatientKedudukan AS kedudukan,
|
||||
M_PatientLocation AS lokasi,
|
||||
M_PatientJob AS pekerjaan,
|
||||
M_PatientNoRM AS noRM,
|
||||
M_PatientAddress AS address,
|
||||
T_OrderNote AS note,
|
||||
T_OrderDiagnosis AS diagnosis,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailTestID) AS testsID,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailID,'|',T_OrderDetailTestID, '|', T_OrderDetailTestDate)) AS testDetail,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailBahanID ,'|',T_OrderDetailBahanNat_BahanID, '|', T_OrderDetailBahanName,'|',T_OrderDetailBahanQty)) AS bahan,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailSampleID,'|',T_OrderDetailSampleNat_SampleTypeID, '|',T_OrderDetailSampleName,'|', T_OrderDetailSampleQty)) AS sample,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDetailPacketT_PacketID) AS packet,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailPacketID, '|', T_OrderDetailPacketT_PacketID )) AS packetDetail
|
||||
FROM one_mitra.t_order
|
||||
LEFT JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
JOIN one_mitra.m_patient
|
||||
ON T_OrderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetaildelivery
|
||||
ON T_OrderID = T_OrderDetailDeliveryT_OrderID
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailsample
|
||||
ON T_OrderID = T_OrderDetailSampleT_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailbahan
|
||||
ON T_OrderID = T_OrderDetailBahanT_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderDate >= ? AND T_OrderDate <= ?
|
||||
AND (T_OrderNumber LIKE ? OR M_PatientName LIKE ?)
|
||||
AND T_OrderM_CompanyID = ?
|
||||
AND T_OrderS_RegionalID = ?
|
||||
GROUP BY T_OrderID
|
||||
LIMIT ? OFFSET ?";
|
||||
$query = $this->db->query($sql, [$startDate, $endDate, $keyword, $keyword, $companyID, $regionalID, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
// print_r($search);
|
||||
// packetName
|
||||
for ($i = 0; $i < count($search); $i++) {
|
||||
$tes = explode('|', $search[$i]['tests']);
|
||||
$bahan = explode(',', $search[$i]['bahan']);
|
||||
$paket = explode(',', $search[$i]['packet']);
|
||||
$paketName = explode('|', $search[$i]['packetName']);
|
||||
$sample = explode(',', $search[$i]['sample']);
|
||||
$testsID = explode(',', $search[$i]['testsID']);
|
||||
$testdetail = explode(',', $search[$i]['testDetail']);
|
||||
$packetDetail = explode(',', $search[$i]['packetDetail']);
|
||||
$search[$i]['tests'] = array_merge($tes, $paketName);
|
||||
$search[$i]['bahan'] = $bahan;
|
||||
$search[$i]['sample'] = $sample;
|
||||
$search[$i]['testsID'] = $testsID;
|
||||
$search[$i]['testDetail'] = $testdetail;
|
||||
$search[$i]['packet'] = $paket;
|
||||
$search[$i]['packetDetail'] = $packetDetail;
|
||||
// $tes = array_merge($tes, $paketName);
|
||||
}
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage)
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function editOrder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$tests = $prm['tests'];
|
||||
$specimens = $prm['specimens'];
|
||||
$bahan = $prm['bahan'];
|
||||
$orderID = $prm['orderID'];
|
||||
$patientID = $prm['patient_id'];
|
||||
$paket = $prm['paket'];
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
// print_r($this->sys_user);
|
||||
// exit;
|
||||
$this->db->trans_begin();
|
||||
$sql_old = "SELECT DISTINCT
|
||||
T_OrderID AS id,
|
||||
T_OrderNote AS note,
|
||||
T_OrderDiagnosis AS diagnosis,
|
||||
T_OrderTotal AS total,
|
||||
T_OrderDetailID AS detailID,
|
||||
T_OrderDetailTestID AS testID,
|
||||
T_OrderDetailTotal AS detailTotal,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailID, '|',T_OrderDetailTestID , '|',T_OrderDetailTotal )SEPARATOR '^') AS detail,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailBahanID , '|',T_OrderDetailBahanNat_BahanID , '|',T_OrderDetailBahanQty ) SEPARATOR '^') AS bahan,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailSampleID , '|',T_OrderDetailSampleNat_SampleTypeID, '|',T_OrderDetailSampleQty)SEPARATOR '^') AS sample,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailPacketID, '|', T_OrderDetailPacketT_PacketID )) AS packet
|
||||
FROM
|
||||
one_mitra.t_order
|
||||
JOIN one_mitra.t_orderdetail
|
||||
ON T_OrderID = T_OrderDetailOrderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailsample
|
||||
ON T_OrderID = T_OrderDetailSampleT_OrderID
|
||||
AND T_OrderDetailSampleIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailbahan
|
||||
ON T_OrderID = T_OrderDetailBahanT_OrderID
|
||||
AND T_OrderDetailBahanIsActive = 'Y'
|
||||
LEFT JOIN one_mitra.t_orderdetailpacket
|
||||
ON T_OrderID = T_OrderDetailPacketOrderID
|
||||
AND T_OrderDetailPacketIsActive = 'Y'
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query_old = $this->db->query($sql_old, [$orderID]);
|
||||
if (!$query_old) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$rst_old = $query_old->result_array()[0];
|
||||
//order detail old
|
||||
$detail_old = explode('^', $rst_old['detail']);
|
||||
$arr_detail = array();
|
||||
$arr_detailID = array();
|
||||
for ($i = 0; $i < count($detail_old); $i++) {
|
||||
$splitted = explode('|', $detail_old[$i]);
|
||||
$arr_detail[] = [
|
||||
"id" => $splitted[0],
|
||||
"testID" => $splitted[1],
|
||||
];
|
||||
$arr_detailID[] = $splitted[1];
|
||||
}
|
||||
$rst_old['detail'] = $arr_detail;
|
||||
//sample detail old
|
||||
$sample_old = explode('^', $rst_old['sample']);
|
||||
$arr_sample = array();
|
||||
for ($i = 0; $i < count($sample_old); $i++) {
|
||||
$splitted = explode('|', $sample_old[$i]);
|
||||
$arr_sample[] = [
|
||||
"id" => $splitted[0],
|
||||
"sampleID" => $splitted[1],
|
||||
"qty" => $splitted[2],
|
||||
];
|
||||
}
|
||||
$rst_old['sample'] = $arr_sample;
|
||||
//bahan detail old
|
||||
$bahan_old = explode('^', $rst_old['bahan']);
|
||||
$arr_bahan = array();
|
||||
for ($i = 0; $i < count($bahan_old); $i++) {
|
||||
$splitted = explode('|', $bahan_old[$i]);
|
||||
$arr_bahan[] = [
|
||||
"id" => $splitted[0],
|
||||
"bahanID" => $splitted[1],
|
||||
"qty" => $splitted[2],
|
||||
];
|
||||
}
|
||||
$rst_old['bahan'] = $arr_bahan;
|
||||
//paket detail old
|
||||
$paket_old = explode(',', $rst_old['packet']);
|
||||
$arr_paket = array();
|
||||
for ($i = 0; $i < count($paket_old); $i++) {
|
||||
$splitted = explode('|', $paket_old[$i]);
|
||||
$arr_paket[] = [
|
||||
"id" => $splitted[0],
|
||||
"paket_id" => $splitted[1],
|
||||
];
|
||||
}
|
||||
$rst_old['packet'] = $arr_paket;
|
||||
|
||||
|
||||
$this->db->set("T_OrderNote", $patient['note'])
|
||||
->set("T_OrderDiagnosis", $patient['diagnosis'])
|
||||
->set("T_OrderTotal", intval($prm['total']))
|
||||
->set("T_OrderUserID", $userid)
|
||||
->where("T_OrderID", $orderID)->update('one_mitra.t_order');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("m_patient rows", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$arr_new_test = array();
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
$arr_new_test[] = $tests[$i]['id'];
|
||||
}
|
||||
$arr_sampleIdnew = array();
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
$arr_sampleIdnew[] = $specimens[$i]['id'];
|
||||
}
|
||||
$arr_bahanIdnew = array();
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
$arr_bahanIdnew[] = $bahan[$i]['id'];
|
||||
}
|
||||
$arr_paketIdnew = array();
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
$arr_paketIdnew[] = $paket[$i]['id'];
|
||||
}
|
||||
// $this->db->trans_commit();
|
||||
|
||||
// $this->sys_ok($rst_old);
|
||||
// $this->sys_ok(["new test" => $arr_new_test, "old_test" => $arr_detail]);
|
||||
// return;
|
||||
|
||||
//deleted test
|
||||
for ($i = 0; $i < count($arr_detail); $i++) {
|
||||
//deleted
|
||||
if (!in_array($arr_detail[$i]['testID'], $arr_new_test)) {
|
||||
$this->db->set("T_OrderDetailIsActive", 'N')
|
||||
->where("T_OrderDetailID", $arr_detail[$i]['id'])->update('one_mitra.t_orderdetail');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
//New test
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
//new
|
||||
if ($tests[$i]['detailID'] == 'new') {
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailOrderID" => $orderID,
|
||||
"T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
"T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
"T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
"T_OrderDetailTestDate" => $dt,
|
||||
"T_OrderDetailUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
$this->db->set("T_OrderDetailTestDate", $dt)
|
||||
->set("T_OrderDetailUserID", $userid)
|
||||
->where("T_OrderDetailID", $tests[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetail');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// if (!in_array($tests[$i]['id'], $arr_detailID)) {
|
||||
// $coba = strtotime($tests[$i]['date']);
|
||||
// $dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
// $order = [
|
||||
// "T_OrderDetailOrderID" => $orderID,
|
||||
// "T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
// "T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
// "T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
// "T_OrderDetailTestDate" => $dt,
|
||||
// "T_OrderDetailUserID" => $userid,
|
||||
|
||||
// ];
|
||||
|
||||
// $this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
// $err = $this->db->error();
|
||||
// if (
|
||||
// $err['message'] != ""
|
||||
// ) {
|
||||
// $this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
// $this->db->trans_rollback();
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// $this->sys_ok($rst_old);
|
||||
// $this->sys_ok(["new sample" => $arr_sampleIdnew, "old_sample" => $arr_sample]);
|
||||
// return;
|
||||
//deleted sample
|
||||
for ($i = 0; $i < count($arr_sample); $i++) {
|
||||
if (!in_array($arr_sample[$i]['sampleID'], $arr_sampleIdnew)) {
|
||||
$this->db->set("T_OrderDetailSampleIsActive", 'N')
|
||||
->where("T_OrderDetailSampleID", $arr_sample[$i]['id'])->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
//new & updated sample
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
if ($specimens[$i]['detailID'] == "new") {
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$order = [
|
||||
"T_OrderDetailSampleT_OrderID" => $orderID,
|
||||
"T_OrderDetailSampleNat_SampleTypeID" => $specimens[$i]['id'],
|
||||
"T_OrderDetailSampleName" => $specimens[$i]['name'],
|
||||
"T_OrderDetailSampleQty" => $specimens[$i]['amount'],
|
||||
"T_OrderDetailSampleUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailsample', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$this->db->set("T_OrderDetailSampleQty", $specimens[$i]['amount'])
|
||||
->set("T_OrderDetailSampleUserID", $userid)
|
||||
->where("T_OrderDetailSampleID", $specimens[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
if (!in_array($arr_sample[$i]['sampleID'], $arr_sampleIdnew)) {
|
||||
$this->db->set("T_OrderDetailSampleIsActive", 'N')
|
||||
->where("T_OrderDetailSampleID", $specimens[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailsample');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//deleted bahan
|
||||
for ($i = 0; $i < count($arr_bahan); $i++) {
|
||||
if (!in_array($arr_bahan[$i]['bahanID'], $arr_bahanIdnew)) {
|
||||
$this->db->set("T_OrderDetailBahanIsActive", 'N')
|
||||
->where("T_OrderDetailBahanID", $arr_bahan[$i]['id'])->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//new and update bahan
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
if ($bahan[$i]['detailID'] == "new") {
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailBahanT_OrderID" => $orderID,
|
||||
"T_OrderDetailBahanNat_BahanID" => $bahan[$i]['id'],
|
||||
"T_OrderDetailBahanName" => $bahan[$i]['name'],
|
||||
"T_OrderDetailBahanQty" => $bahan[$i]['amount'],
|
||||
"T_OrderDetailBahanUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailbahan', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
$this->db->set("T_OrderDetailBahanQty", $bahan[$i]['amount'])
|
||||
->set("T_OrderDetailBahanUserID", $userid)
|
||||
->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])
|
||||
->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR UPDATE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$this->db->set("T_OrderDetailBahanIsActive", 'N')
|
||||
->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])->update('one_mitra.t_orderdetailbahan');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//deleted paket
|
||||
for ($i = 0; $i < count($arr_paket); $i++) {
|
||||
if (!in_array($arr_paket[$i]['paket_id'], $arr_paketIdnew)) {
|
||||
$this->db->set("T_OrderDetailPacketIsActive", 'N')
|
||||
->where("T_OrderDetailPacketID", $arr_paket[$i]['id'])->update('one_mitra.t_orderdetailpacket');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR DELETE PACKET DETAIL ", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//new and paket
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
if ($paket[$i]['detail_id'] == "new") {
|
||||
$order = [
|
||||
"T_OrderDetailPacketOrderID" => $orderID,
|
||||
"T_OrderDetailPacketT_PacketID" => $paket[$i]['id'],
|
||||
"T_OrderDetailPacketName" => $paket[$i]['name'],
|
||||
"T_OrderDetailPacketUserID" => $userid,
|
||||
"T_OrderDetailPacketPrice" => $paket[$i]['price'],
|
||||
"T_OrderDetailPacketT_PacketType" => $paket[$i]["type"],
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailpacket', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL PAKET", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// else {
|
||||
|
||||
// $this->db->set("T_OrderDetailBahanQty", $bahan[$i]['amount'])
|
||||
// ->set("T_OrderDetailBahanUserID", $userid)
|
||||
// ->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])
|
||||
// ->update('one_mitra.t_orderdetailbahan');
|
||||
// $err = $this->db->error();
|
||||
// if (
|
||||
// $err['message'] != ""
|
||||
// ) {
|
||||
// $this->sys_error_db("ERROR UPDATE ORDER DETAIL BAHAN", $this->db);
|
||||
// $this->db->trans_rollback();
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$this->sys_ok("OK");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function cancel()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT T_OrderDetailDeliveryID AS CEK
|
||||
FROM one_mitra.t_orderdetaildelivery
|
||||
WHERE T_OrderDetailDeliveryT_OrderID = ?
|
||||
AND T_OrderDetailDeliveryIsActive = 'Y'
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $query->result_array();
|
||||
if (count($cek) == 0) {
|
||||
# code...
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE one_mitra.t_order SET T_OrderIsActive = 'N'
|
||||
WHERE T_OrderID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE one_mitra.t_orderdetail SET T_OrderDetailIsActive = 'N'
|
||||
WHERE T_OrderDetailOrderID = ?;
|
||||
";
|
||||
$query = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("ok");
|
||||
} else {
|
||||
$this->sys_ok("Sudah di buat surat jalan");
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
class Patient extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$keyword = '%%';
|
||||
if (isset($prm['keyword'])) {
|
||||
$keyword = '%' . $prm['keyword'] . '%';
|
||||
}
|
||||
$page = $prm['page'];
|
||||
$rowPerPage = $prm['rpp'];
|
||||
$companyID = $prm['company_id'];
|
||||
// hitung start_offset
|
||||
|
||||
$start_offset = 0;
|
||||
if (isset($prm['page'])) {
|
||||
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
||||
$start_offset = ($page - 1) * intval($rowPerPage);
|
||||
}
|
||||
}
|
||||
|
||||
$sql_total = "SELECT
|
||||
COUNT(M_PatientID) AS total
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientM_CompanyID = ?
|
||||
AND (M_PatientName LIKE ? OR
|
||||
M_PatientNIK LIKE ? OR M_PatientHP LIKE ?)";
|
||||
$query_total = $this->db->query($sql_total, [$companyID, $keyword, $keyword, $keyword]);
|
||||
if (!$query_total) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$totals = $query_total->result_array()[0]['total'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_PatientID AS id,
|
||||
M_PatientPrefix AS prefix,
|
||||
M_PatientName AS name,
|
||||
M_PatientSuffix AS suffix,
|
||||
M_PatientDOB AS dob,
|
||||
M_PatientNIK AS nik,
|
||||
M_PatientNIP AS nip,
|
||||
M_PatientTitleID AS title_id,
|
||||
M_PatientM_SexID AS sex_id,
|
||||
M_PatientHP AS hp,
|
||||
M_PatientAddress AS address,
|
||||
M_PatientNoRM AS noRM,
|
||||
M_PatientJabatan AS jabatan,
|
||||
M_PatientKedudukan AS kedudukan,
|
||||
M_PatientLocation AS lokasi,
|
||||
M_PatientJob AS pekerjaan,
|
||||
M_PatientM_CompanyID,
|
||||
one_mitra.fn_get_patient_status_del(M_PatientID) AS status_delete
|
||||
FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientM_CompanyID = ?
|
||||
AND (M_PatientName LIKE ? OR
|
||||
M_PatientNIK LIKE ? OR M_PatientHP LIKE ?)
|
||||
ORDER BY M_PatientName
|
||||
LIMIT ? OFFSET ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$companyID, $keyword, $keyword, $keyword, intval($rowPerPage), intval($start_offset)]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$search = $query->result_array();
|
||||
$result = [
|
||||
"data" => $search,
|
||||
"total" => $totals,
|
||||
"total_page" => ceil($totals / $rowPerPage)
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function editpatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$patientID = $prm['patient_id'];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$patientDOB = date('Y-m-d', strtotime($patient['dob']));
|
||||
$withoutNIK = $patient['without_nik'];
|
||||
$nik = $patient['nik'];
|
||||
$isNIK = 'N';
|
||||
//JSON BEFORE
|
||||
$sql = "SELECT * FROM one_mitra.m_patient
|
||||
WHERE M_PatientID = ?";
|
||||
$query = $this->db->query($sql, [$patientID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$JSONBefore = json_encode($query->result_array()[0]);
|
||||
|
||||
|
||||
if ($withoutNIK == "N") {
|
||||
$isNIK = 'Y';
|
||||
}
|
||||
if ($isNIK == 'Y') {
|
||||
//sql cek kalau NIK sudah digunakan atau belum
|
||||
$sql = "SELECT * FROM one_mitra.m_patient
|
||||
WHERE M_PatientIsNIK = 'Y'
|
||||
AND M_PatientNIK = ?
|
||||
AND M_PatientM_CompanyID = ?
|
||||
AND M_PatientID <> ?";
|
||||
$query = $this->db->query($sql, [$nik, $companyID, $patientID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$cekNik = $query->result_array();
|
||||
if (count($cekNik) > 0) {
|
||||
$this->sys_error("NIK sudah digunakan oleh pasien lain");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
//edit
|
||||
$sql = "UPDATE one_mitra.m_patient
|
||||
SET M_PatientPrefix = ?,
|
||||
M_PatientName = ?,
|
||||
M_PatientSuffix = ?,
|
||||
M_PatientDOB = ?,
|
||||
M_PatientNIK = ?,
|
||||
M_PatientNIP = ? ,
|
||||
M_PatientIsNIK = ?,
|
||||
M_PatientTitleID = ?,
|
||||
M_PatientM_SexID = ?,
|
||||
M_PatientHP = ? ,
|
||||
M_PatientNoRM = ?,
|
||||
M_PatientJabatan = ?,
|
||||
M_PatientKedudukan = ?,
|
||||
M_PatientLocation = ?,
|
||||
M_PatientJob = ?,
|
||||
M_PatientAddress = ?
|
||||
WHERE M_PatientID = ?
|
||||
AND M_PatientIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [
|
||||
$patient['prefix'],
|
||||
$patient['name'],
|
||||
$patient['suffix'],
|
||||
$patientDOB,
|
||||
$nik,
|
||||
$patient['nip'],
|
||||
$isNIK,
|
||||
$patient['saluation'],
|
||||
$patient['gender'],
|
||||
$patient['hp'],
|
||||
$patient['noRM'],
|
||||
$patient['jabatan'],
|
||||
$patient['kedudukan'],
|
||||
$patient['lokasi'],
|
||||
$patient['pekerjaan'],
|
||||
$patient['address'],
|
||||
$patientID
|
||||
]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
$this->sys_error_db($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
//JSON AFTER
|
||||
$sql = "SELECT * FROM one_mitra.m_patient
|
||||
WHERE M_PatientID = ?";
|
||||
$query = $this->db->query($sql, [$patientID]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$JSONAfter = json_encode($query->result_array()[0]);
|
||||
//insert log
|
||||
$sql = "INSERT INTO mitra_log.m_patient_log(
|
||||
M_PatientLogM_PatientID,
|
||||
M_PatientLogStatus,
|
||||
M_PatientLogJSONBefore,
|
||||
M_PatientLogJSONAfter,
|
||||
M_patientLogUserID,
|
||||
M_PatientLogCreated)VALUES(?,'EDIT',?,?,?, NOW())";
|
||||
$query = $this->db->query($sql, [$patientID, $JSONBefore, $JSONAfter, $userid]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok("Berhasil Mengubah data");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function deletePatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
//cek bisa di delete atau tidak
|
||||
$sql = "SELECT one_mitra.fn_get_patient_status_del(?) AS status_delete;";
|
||||
$query = $this->db->query($sql, [$prm['patient_id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$cek = $query->result_array()[0]['status_delete'];
|
||||
if ($cek == 'Y') {
|
||||
//delete
|
||||
$sql = "UPDATE one_mitra.m_patient
|
||||
SET M_PatientIsActive = 'N'
|
||||
WHERE M_PatientID = ?";
|
||||
$query = $this->db->query($sql, [$prm['patient_id']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
//JSON AFTER
|
||||
$sql = "SELECT * FROM one_mitra.m_patient
|
||||
WHERE M_PatientID = ?";
|
||||
$query = $this->db->query(
|
||||
$sql,
|
||||
[$prm['patient_id']]
|
||||
);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$JSONAfter = json_encode($query->result_array()[0]);
|
||||
//insert log
|
||||
$sql = "INSERT INTO mitra_log.m_patient_log(
|
||||
M_PatientLogM_PatientID,
|
||||
M_PatientLogStatus,
|
||||
M_PatientLogJSONAfter,
|
||||
M_patientLogUserID,
|
||||
M_PatientLogCreated)VALUES(?,'DELETE',?,?, NOW())";
|
||||
$query = $this->db->query(
|
||||
$sql,
|
||||
[$prm['patient_id'], $JSONAfter, $userid]
|
||||
);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok("berhasil menghapus data");
|
||||
} else {
|
||||
//tidak bisa di delete
|
||||
$this->sys_error("Gagal Menghapus data, order pasien sudah masuk kedalam surat jalan");
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,497 @@
|
||||
<?php
|
||||
|
||||
class Registration extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function getfilter()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql_gender = "SELECT M_SexID AS id,
|
||||
m_sexname AS name
|
||||
FROM m_sex
|
||||
WHERE M_SexIsActive = 'Y'";
|
||||
$query_gender = $this->db->query($sql_gender, []);
|
||||
if (!$query_gender) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$genders = $query_gender->result_array();
|
||||
$sql_title = "SELECT M_TitleID AS id,
|
||||
M_TitleM_SexID AS type,
|
||||
M_TitleName AS name
|
||||
FROM m_title WHERE M_TitleIsActive = 'Y'";
|
||||
$query_title = $this->db->query($sql_title, []);
|
||||
if (!$query_title) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$titles = $query_title->result_array();
|
||||
|
||||
$sql_regional = "SELECT
|
||||
S_RegionalID AS regional_id,
|
||||
S_RegionalName AS regional_name
|
||||
FROM s_regional WHERE S_RegionalIsActive = 'Y'";
|
||||
$query_regional = $this->db->query($sql_regional, []);
|
||||
if (!$query_regional) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$regionals = $query_regional->result_array();
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName AS branch_name,
|
||||
M_BranchS_RegionalID AS regional_id
|
||||
FROM m_branch Where M_BranchIsActive = 'Y'";
|
||||
$query_branch = $this->db->query($sql_branch, []);
|
||||
if (!$query_branch) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$branchs = $query_branch->result_array();
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
$regionals[$i]['branch'] = [];
|
||||
}
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
for ($j = 0; $j < count($branchs); $j++) {
|
||||
if ($regionals[$i]['regional_id'] == $branchs[$j]['regional_id']) {
|
||||
$regionals[$i]['branch'][] = $branchs[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = array(
|
||||
"titles" => $titles,
|
||||
"gender" => $genders,
|
||||
"regional" => $regionals
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getsampletype()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$arr_test = 0;
|
||||
if (isset($prm['arr_test'])) {
|
||||
$arr_test = $prm['arr_test'];
|
||||
} else {
|
||||
$this->sys_error("arr_test is mandatory");
|
||||
}
|
||||
// print_r($arr_test);
|
||||
$result = array();
|
||||
for ($i = 0; $i < count($arr_test); $i++) {
|
||||
$test = $arr_test[$i];
|
||||
$sasCode = substr($test['sasCode'], 0, 8) . "%";
|
||||
$sql = "SELECT T_TestID AS id
|
||||
FROM t_test
|
||||
WHERE T_TestSasCode LIKE ?
|
||||
AND T_TestIsActive = 'Y'";
|
||||
$qry = $this->db_regional->query($sql, [$sasCode]);
|
||||
if (!$qry) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$allTest = $qry->result_array();
|
||||
$arr = [];
|
||||
for ($k = 0; $k < count($allTest); $k++) {
|
||||
$arr[] = $allTest[$k]['id'];
|
||||
}
|
||||
// print_r($arr);
|
||||
|
||||
$implodeTest = implode(",", $arr);
|
||||
|
||||
$sql_specimen = "SELECT Nat_TestID,
|
||||
Nat_TestName,
|
||||
T_TestID,
|
||||
T_TestName,
|
||||
Nat_SampleTypeID,
|
||||
Nat_SampleTypeNat_BahanID,
|
||||
Nat_SampleTypeName,
|
||||
Nat_BahanID,
|
||||
Nat_BahanName
|
||||
FROM nat_test
|
||||
JOIN t_test
|
||||
ON Nat_TestID = T_TestNat_TestID
|
||||
AND T_TestID IN ($implodeTest)
|
||||
AND T_TestIsActive = 'Y'
|
||||
JOIN nat_sampletype
|
||||
ON Nat_TestNat_SampleTypeID = Nat_SampleTypeID
|
||||
AND Nat_SampleTypeIsActive = 'Y'
|
||||
JOIN nat_bahan
|
||||
ON Nat_SampleTypeNat_BahanID = Nat_BahanID
|
||||
WHERE Nat_TestIsActive = 'Y'
|
||||
|
||||
";
|
||||
// GROUP_CONCAT(DISTINCT CONCAT(Nat_SampleTypeID, '^', Nat_SampleTypeName)) AS sampletype,
|
||||
// GROUP_CONCAT(DISTINCT CONCAT(Nat_BahanID, '^', Nat_BahanName)) AS nat_bahan
|
||||
// GROUP BY Nat_SampleTypeID, Nat_BahanID
|
||||
$qry_specimen = $this->db_regional->query($sql_specimen, []);
|
||||
// echo $this->db_regional->last_query();
|
||||
// exit;
|
||||
if (!$qry_specimen) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$specimen = $qry_specimen->result_array();
|
||||
// print_r($specimen);
|
||||
// exit;
|
||||
$data = array(
|
||||
"id" => $test['id'],
|
||||
"tab" => $test['tab'],
|
||||
"specimen" => [],
|
||||
"bahan" => []
|
||||
);
|
||||
// print_r($specimen);
|
||||
// if (count($specimen) > 0) {
|
||||
// if ($specimen[0]['sampletype'] != null && $specimen[0]['nat_bahan'] != null) {
|
||||
|
||||
// $sampleType = explode(',', $specimen[0]['sampletype']);
|
||||
// $natBahan = explode(',', $specimen[0]['nat_bahan']);
|
||||
// // print_r($sampleType);
|
||||
// // print_r($natBahan);
|
||||
|
||||
|
||||
// for ($i = 0; $i < count($sampleType); $i++) {
|
||||
// $temp = explode('^', $sampleType[$i]);
|
||||
// $data['specimen'][] = array(
|
||||
// "id" => $temp[0],
|
||||
// "name" => $temp[1]
|
||||
// );
|
||||
// }
|
||||
// for ($i = 0; $i < count($natBahan); $i++) {
|
||||
// $temp = explode('^', $natBahan[$i]);
|
||||
// $data['bahan'][] = array(
|
||||
// "id" => $temp[0],
|
||||
// "name" => $temp[1]
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for ($j = 0; $j < count($specimen); $j++) {
|
||||
$sp = $specimen[$j];
|
||||
$tempSp = array(
|
||||
"id" => $sp["Nat_SampleTypeID"],
|
||||
"name" => $sp['Nat_SampleTypeName']
|
||||
);
|
||||
$tempBhn = array(
|
||||
"id" => $sp["Nat_BahanID"],
|
||||
"name" => $sp['Nat_BahanName']
|
||||
);
|
||||
if (!in_array($tempSp, $data['specimen'])) {
|
||||
$data['specimen'][] = array(
|
||||
"id" => $sp["Nat_SampleTypeID"],
|
||||
"name" => $sp['Nat_SampleTypeName']
|
||||
);
|
||||
}
|
||||
if (!in_array($tempBhn, $data['bahan'])) {
|
||||
$data['bahan'][] = array(
|
||||
"id" => $sp["Nat_BahanID"],
|
||||
"name" => $sp['Nat_BahanName']
|
||||
);
|
||||
}
|
||||
}
|
||||
$result[] = $data;
|
||||
}
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function addpatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$paket = $prm['paket'];
|
||||
$patientDOB = date('Y-m-d', strtotime($patient['dob']));
|
||||
$withoutNIK = $patient['without_nik'];
|
||||
$nik = $patient['nik'];
|
||||
$tests = $prm['tests'];
|
||||
$specimens = $prm['specimens'];
|
||||
$bahan = $prm['bahan'];
|
||||
$patientID = $prm['patient_id'];
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
// print_r($this->sys_user);
|
||||
// exit;
|
||||
$isNIK = 'N';
|
||||
|
||||
$this->db->trans_begin();
|
||||
if ($withoutNIK == 'Y') {
|
||||
$nik = "0";
|
||||
}
|
||||
if ($patientID == "new") {
|
||||
if ($withoutNIK == "N") {
|
||||
$isNIK = 'Y';
|
||||
}
|
||||
$ptn = [
|
||||
"M_PatientPrefix" => $patient['prefix'],
|
||||
"M_PatientTitleID" => $patient['saluation'],
|
||||
"M_PatientName" => $patient['name'],
|
||||
"M_PatientSuffix" => $patient['suffix'],
|
||||
"M_PatientDOB" => $patientDOB,
|
||||
"M_PatientNIK" => $nik,
|
||||
"M_PatientNIP" => $patient['nip'],
|
||||
"M_PatientIsNIK" => $isNIK,
|
||||
"M_PatientM_SexID" => $patient['gender'],
|
||||
"M_PatientHP" => $patient['hp'],
|
||||
"M_PatientAddress" => $patient['address'],
|
||||
"M_PatientNoRM" => $patient['noRM'],
|
||||
"M_PatientM_CompanyID" => $companyID,
|
||||
"M_PatientUserID" => $userid,
|
||||
"M_PatientJabatan" => $patient['jabatan'],
|
||||
"M_PatientKedudukan" => $patient['kedudukan'],
|
||||
"M_PatientLocation" => $patient['lokasi'],
|
||||
"M_PatientJob" => $patient['pekerjaan'],
|
||||
|
||||
];
|
||||
$this->db->insert('one_mitra.m_patient', $ptn);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT PATIENT", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$patientID = $this->db->insert_id();
|
||||
if ($withoutNIK == 'Y') {
|
||||
$awalan = sprintf("%05s", intval($companyID)) . $patientID;
|
||||
// print_r($awalan);
|
||||
$nik = str_pad($awalan, 16, "0");
|
||||
// print_r($nik);
|
||||
$this->db->set("M_PatientNIK", $nik)->where("M_PatientID", $patientID)->update('one_mitra.m_patient');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("m_patient rows", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT one_mitra.fn_numbering('MT') as number";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$message = $this->db->error();
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$number = $qry->result_array()[0]['number'];
|
||||
$total = intval($prm['total']);
|
||||
|
||||
$order = [
|
||||
"T_OrderNumber" => $number,
|
||||
"T_OrderM_PatientID" => $patientID,
|
||||
"T_OrderM_MouID" => $mouID,
|
||||
"T_OrderM_CompanyID" => $companyID,
|
||||
"T_OrderS_RegionalID" => $regionalID,
|
||||
"T_OrderNote" => $patient['note'],
|
||||
"T_OrderDiagnosis" => $patient['diagnosis'],
|
||||
"T_OrderUserID" => $userid,
|
||||
"T_OrderTotal" => $total,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_order', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$orderId = $this->db->insert_id();
|
||||
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
// T_OrderDetailID int(11) Auto Increment
|
||||
// T_OrderDetailOrderID int(11)
|
||||
// T_OrderDetailTestID int(11)
|
||||
// T_OrderDetailTestName varchar(30)
|
||||
// T_OrderDetailTotal int(11)
|
||||
// T_OrderDetailUserID
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailOrderID" => $orderId,
|
||||
"T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
"T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
"T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
"T_OrderDetailTestDate" => $dt,
|
||||
"T_OrderDetailUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
// T_OrderDetailSampleT_OrderID int(11)
|
||||
// T_OrderDetailSampleNat_SampleTypeID int(11)
|
||||
// T_OrderDetailSampleName varchar(200)
|
||||
// T_OrderDetailSampleQty varchar(200)
|
||||
// T_OrderDetailSampleUserID
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$order = [
|
||||
"T_OrderDetailSampleT_OrderID" => $orderId,
|
||||
"T_OrderDetailSampleNat_SampleTypeID" => $specimens[$i]['id'],
|
||||
"T_OrderDetailSampleName" => $specimens[$i]['name'],
|
||||
"T_OrderDetailSampleQty" => $specimens[$i]['amount'],
|
||||
"T_OrderDetailSampleUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailsample', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
// T_OrderDetailBahanT_OrderID int(11)
|
||||
// T_OrderDetailBahanNat_BahanID int(11)
|
||||
// T_OrderDetailBahanName int(11)
|
||||
// T_OrderDetailBahanQty varchar(200)
|
||||
// T_OrderDetailBahanUserID
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
# code...
|
||||
$order = [
|
||||
"T_OrderDetailBahanT_OrderID" => $orderId,
|
||||
"T_OrderDetailBahanNat_BahanID" => $bahan[$i]['id'],
|
||||
"T_OrderDetailBahanName" => $bahan[$i]['name'],
|
||||
"T_OrderDetailBahanQty" => $bahan[$i]['amount'],
|
||||
"T_OrderDetailBahanUserID" => $userid,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailbahan', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
//T_OrderDetailPacketID int(11) Auto Increment
|
||||
// T_OrderDetailPacketT_PacketID int(11)
|
||||
// T_OrderDetailPacketName varchar(250)
|
||||
// T_OrderDetailPacketIsActive char(1) [Y]
|
||||
// T_OrderDetailPacketUserID int(11)
|
||||
// T_OrderDetailPacketCreated datetime [current_timestamp()]
|
||||
// T_OrderDetailPacketLastUpdated
|
||||
|
||||
# code...
|
||||
$order = [
|
||||
"T_OrderDetailPacketOrderID" => $orderId,
|
||||
"T_OrderDetailPacketPrice" => $paket[$i]['price'],
|
||||
"T_OrderDetailPacketT_PacketType" => $paket[$i]["type"],
|
||||
"T_OrderDetailPacketT_PacketID" => $paket[$i]['id'],
|
||||
"T_OrderDetailPacketName" => $paket[$i]['name'],
|
||||
"T_OrderDetailPacketUserID" => $userid,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailpacket', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = [
|
||||
"patientID" => $patientID,
|
||||
"orderID" => $orderId,
|
||||
"orderNumber" => $number,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
class Updateprocessresult extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: UPDATE STATUS X/R";
|
||||
}
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
|
||||
function reply_gz($resp, $debug = "")
|
||||
{
|
||||
if ($debug != "") {
|
||||
echo json_encode($resp);
|
||||
} else {
|
||||
echo gzcompress(json_encode($resp));
|
||||
}
|
||||
}
|
||||
|
||||
function get_param()
|
||||
{
|
||||
$body = file_get_contents("php://input");
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
function get_param_z()
|
||||
{
|
||||
$body_z = file_get_contents("php://input");
|
||||
$body = gzuncompress($body_z);
|
||||
return json_decode($body, true);
|
||||
}
|
||||
function updateprocess()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param_z();
|
||||
|
||||
$orderList = $prm['order'];
|
||||
$success = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
for ($i = 0; $i < count($orderList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'P'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [$orderList[$i]]);
|
||||
if (!$qry_update) {
|
||||
$error[] = $orderList[$i];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} else {
|
||||
$success[] = $orderList[$i];
|
||||
}
|
||||
}
|
||||
$resultOrder = [
|
||||
"success" => $success,
|
||||
"error" => $error,
|
||||
"message" => $errorMsg,
|
||||
];
|
||||
|
||||
|
||||
$result = [
|
||||
"order" => $resultOrder
|
||||
];
|
||||
$this->reply_gz($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updateresult()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param_z();
|
||||
|
||||
$orderList = $prm['order'];
|
||||
$success = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
for ($i = 0; $i < count($orderList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'R'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [$orderList[$i]]);
|
||||
if (!$qry_update) {
|
||||
$error[] = $orderList[$i];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} else {
|
||||
$success[] = $orderList[$i];
|
||||
}
|
||||
}
|
||||
$resultOrder = [
|
||||
"success" => $success,
|
||||
"error" => $error,
|
||||
"message" => $errorMsg,
|
||||
];
|
||||
|
||||
|
||||
$result = [
|
||||
"order" => $resultOrder
|
||||
];
|
||||
$this->reply_gz($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
class Updatestatusreg extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: UPDATE STATUS X/R";
|
||||
}
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
|
||||
function reply_gz($resp, $debug = "")
|
||||
{
|
||||
if ($debug != "") {
|
||||
echo json_encode($resp);
|
||||
} else {
|
||||
echo gzcompress(json_encode($resp));
|
||||
}
|
||||
}
|
||||
|
||||
function get_param()
|
||||
{
|
||||
$body = file_get_contents("php://input");
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
function get_param_z()
|
||||
{
|
||||
$body_z = file_get_contents("php://input");
|
||||
$body = gzuncompress($body_z);
|
||||
return json_decode($body, true);
|
||||
}
|
||||
function updatestatusorder()
|
||||
{
|
||||
try {
|
||||
$prm = $this->get_param_z();
|
||||
|
||||
$orderList = $prm['order'];
|
||||
$waList = $prm['wa'];
|
||||
$success = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
$successWa = [];
|
||||
$errorWa = [];
|
||||
$errorMsgWa = [];
|
||||
for ($i = 0; $i < count($orderList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'Y'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [$orderList[$i]]);
|
||||
if (!$qry_update) {
|
||||
$error[] = $orderList[$i];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} else {
|
||||
$success[] = $orderList[$i];
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($waList); $i++) {
|
||||
$sql_update = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatusQR = 'S'
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderID = ?";
|
||||
$qry_update = $this->db->query($sql_update, $waList[$i]);
|
||||
if (!$qry_update) {
|
||||
$errorWa[] = $waList[$i];
|
||||
$errorMsgWa[] = $this->db->error();
|
||||
} else {
|
||||
$successWa[] = $waList[$i];
|
||||
}
|
||||
}
|
||||
$resultOrder = [
|
||||
"success" => $success,
|
||||
"error" => $error,
|
||||
"message" => $errorMsg,
|
||||
];
|
||||
$resultWa = [
|
||||
"success" => $successWa,
|
||||
"error" => $errorWa,
|
||||
"message" => $errorMsgWa,
|
||||
];
|
||||
|
||||
|
||||
$result = [
|
||||
"order" => $resultOrder,
|
||||
"wa" => $resultWa
|
||||
];
|
||||
$this->reply_gz($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updatestatus()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$successUpdate = array();
|
||||
$errorUpdate = array();
|
||||
$errorMsg = array();
|
||||
for ($i = 0; $i < count($prm); $i++) {
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = ?
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive ='Y'";
|
||||
$query = $this->db->query($sql, [$prm[$i]['T_OrderStatus'], $prm[$i]['T_OrderID']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorUpdate[] = $prm[$i]['T_OrderID'];
|
||||
$errorMsg[] = $message;
|
||||
} else {
|
||||
for ($j = 0; $j < count($prm[$i]['sample']); $j++) {
|
||||
if ($prm[$i]['sample'][$j]['type'] == "S") {
|
||||
$sql_update = "UPDATE one_mitra.t_orderdetailsample
|
||||
SET T_OrderDetailSampleStatus = ?
|
||||
WHERE T_OrderDetailSampleID = ?
|
||||
AND T_OrderDetailSampleIsActive = 'Y'";
|
||||
$query_update = $this->db->query($sql_update, [
|
||||
$prm[$i]['sample'][$j]['status'],
|
||||
$prm[$i]['sample'][$j]['id']
|
||||
]);
|
||||
if (!$query_update) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorMsg[] = $message;
|
||||
}
|
||||
} else if ($prm[$i]['sample'][$j]['type'] == "B") {
|
||||
$sql_update = "UPDATE one_mitra.t_orderdetailbahan
|
||||
SET T_OrderDetailBahanStatus = ?
|
||||
WHERE T_OrderDetailBahanID = ?
|
||||
AND T_OrderDetailBahanIsActive = 'Y'";
|
||||
$query_update = $this->db->query($sql_update, [
|
||||
$prm[$i]['sample'][$j]['status'],
|
||||
$prm[$i]['sample'][$j]['id']
|
||||
]);
|
||||
if (!$query_update) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorMsg[] = $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
$successUpdate[] = $prm[$i]['T_OrderID'];
|
||||
}
|
||||
}
|
||||
// $result = $query->result_array();
|
||||
// $z_param = gzcompress(json_encode($result));
|
||||
|
||||
$result = [
|
||||
"success" => $successUpdate,
|
||||
"error" => $errorUpdate,
|
||||
"msg" => $errorMsg,
|
||||
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updatestatuspq()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$successUpdate = array();
|
||||
$errorUpdate = array();
|
||||
$errorMsg = array();
|
||||
for ($i = 0; $i < count($prm); $i++) {
|
||||
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = ?
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive ='Y'";
|
||||
$query = $this->db->query($sql, [$prm[$i]['status'], $prm[$i]['orderID']]);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
// $this->sys_error($message);
|
||||
$errorUpdate[] = $prm[$i]['orderID'];
|
||||
$errorMsg[] = $message;
|
||||
} else {
|
||||
$successUpdate[] = $prm[$i]['orderID'];
|
||||
}
|
||||
}
|
||||
// $result = $query->result_array();
|
||||
// $z_param = gzcompress(json_encode($result));
|
||||
|
||||
$result = [
|
||||
"success" => $successUpdate,
|
||||
"error" => $errorUpdate,
|
||||
"msg" => $errorMsg,
|
||||
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function checkorderdone()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT
|
||||
T_OrderID AS orderID,
|
||||
T_OrderNumber AS orderNumber,
|
||||
YEAR(T_OrderDate) AS year,
|
||||
T_OrderM_CompanyID AS company_id
|
||||
FROM one_mitra.t_order
|
||||
WHERE T_OrderStatus IN ('P', 'Q')
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, []);
|
||||
if (!$query) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rst = $query->result_array();
|
||||
// $a = glob("/data-s3/$companyID/$yearFull/$orderNum*pdf");
|
||||
// $rst[] = [
|
||||
// "company_id" => "1710",
|
||||
// "year" => "2023",
|
||||
// "orderNumber" => "MT231010001"
|
||||
// ];
|
||||
$orderList = [];
|
||||
$error = [];
|
||||
$errorMsg = [];
|
||||
$success = [];
|
||||
for ($i = 0; $i < count($rst); $i++) {
|
||||
$companyID = $rst[$i]["company_id"];
|
||||
$year = $rst[$i]["year"];
|
||||
$orderNumber = $rst[$i]["orderNumber"];
|
||||
$a = glob("/data-s3/$companyID/$year/$orderNumber*pdf");
|
||||
if (count($a) > 0) {
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderStatus = 'D'
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$rst[$i]["orderID"]]);
|
||||
if (!$query) {
|
||||
$error[] = $rst[$i]["orderNumber"];
|
||||
$errorMsg[] = $this->db->error();
|
||||
} {
|
||||
$success[] = $rst[$i]["orderNumber"];
|
||||
}
|
||||
}
|
||||
$orderList[] = $orderNumber;
|
||||
}
|
||||
$result = [
|
||||
"list_order" => $orderList,
|
||||
"error" => $error,
|
||||
"success" => $success,
|
||||
"errorMsg" => $errorMsg
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
646
one-api/application/controllers/one_mitra/masterdata/User.php
Normal file
646
one-api/application/controllers/one_mitra/masterdata/User.php
Normal file
@@ -0,0 +1,646 @@
|
||||
<?php
|
||||
class User extends MY_Controller
|
||||
{
|
||||
var $load;
|
||||
var $db_mitra;
|
||||
var $db_mitra_log;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
$this->db_mitra = "one_mitra";
|
||||
$this->db_mitra_log = "mitra_log";
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db_regional->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "MASTER USER";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM $this->db_mitra.m_user
|
||||
JOIN m_company ON M_UserM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
JOIN s_regional ON M_UserS_RegionalID = S_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_mou ON M_UserM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND (M_UserUsername LIKE ?)";
|
||||
|
||||
$qry_filter = $this->db_regional->query($sql_filter, [$search]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("user total error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_UserID,
|
||||
M_CompanyID,
|
||||
M_CompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_MouID,
|
||||
M_MouName,
|
||||
M_UserUsername,
|
||||
M_UserPassword,
|
||||
M_UserLastAccess,
|
||||
M_UserIsLoggedIn,
|
||||
M_UserM_UserID
|
||||
FROM $this->db_mitra.m_user
|
||||
JOIN m_company ON M_UserM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
JOIN s_regional ON M_UserS_RegionalID = S_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_mou ON M_UserM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
WHERE M_UserIsActive = 'Y' AND (M_UserUsername LIKE ?)
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$qry = $this->db_regional->query($sql, [$search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select user error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search_company()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM m_company
|
||||
WHERE M_CompanyIsActive = 'Y'
|
||||
AND (M_CompanyName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_filter = $this->db_regional->query($sql_filter, [$search, $number_limit]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("company count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_search = "SELECT M_CompanyID,
|
||||
M_CompanyName,
|
||||
M_CompanyNumber
|
||||
FROM m_company
|
||||
WHERE M_CompanyIsActive = 'Y'
|
||||
AND (M_CompanyName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_search = $this->db_regional->query($sql_search, [$search, $number_limit]);
|
||||
if ($qry_search) {
|
||||
$rows = $qry_search->result_array();
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("company select error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_count,
|
||||
"total_display" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function get_regional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "SELECT S_RegionalID,
|
||||
S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalIsDefault = 'Y'";
|
||||
$qry = $this->db_regional->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("regional select error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db_regional->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search_mou()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$companyId = $prm['companyId'];
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM m_mou
|
||||
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
AND M_MouM_CompanyID = ?
|
||||
WHERE M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouEndDate >= NOW()
|
||||
AND (M_MouName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_filter = $this->db_regional->query($sql_filter, [$companyId, $search, $number_limit]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("mou count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_search = "SELECT M_CompanyID,
|
||||
M_MouID,
|
||||
M_MouName,
|
||||
M_MouNumber
|
||||
FROM m_mou
|
||||
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
AND M_MouM_CompanyID = ?
|
||||
WHERE M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouEndDate >= NOW()
|
||||
AND (M_MouName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_search = $this->db_regional->query($sql_search, [$companyId, $search, $number_limit]);
|
||||
if ($qry_search) {
|
||||
$rows = $qry_search->result_array();
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("mou select error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_count,
|
||||
"total_display" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function add()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db_regional->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$companyId = "";
|
||||
if (isset($prm["companyId"])) {
|
||||
$companyId = trim($prm["companyId"]);
|
||||
}
|
||||
|
||||
$regionalId = "";
|
||||
if (isset($prm["regionalId"])) {
|
||||
$regionalId = trim($prm["regionalId"]);
|
||||
}
|
||||
|
||||
$mouId = "";
|
||||
if (isset($prm["mouId"])) {
|
||||
$mouId = trim($prm["mouId"]);
|
||||
}
|
||||
|
||||
$username = "";
|
||||
if (isset($prm["username"])) {
|
||||
$username = trim($prm["username"]);
|
||||
}
|
||||
|
||||
$password = "";
|
||||
if (isset($prm["password"])) {
|
||||
$password = trim($prm["password"]);
|
||||
}
|
||||
|
||||
$confirm_password = "";
|
||||
if (isset($prm["confirm_password"])) {
|
||||
$confirm_password = trim($prm["confirm_password"]);
|
||||
}
|
||||
|
||||
if ($password !== $confirm_password) {
|
||||
$error = "password dan konfirmasi password harus sama";
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
// cek username tidak boleh sama
|
||||
$sql_cek_username = "SELECT count(*) as total_user
|
||||
FROM $this->db_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserUsername = ?";
|
||||
$qry_cek_username = $this->db_regional->query($sql_cek_username, [$username]);
|
||||
if ($qry_cek_username) {
|
||||
$get_count_username = $qry_cek_username->row_array();
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("ERROR, cek user", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($get_count_username["total_user"] == 0) {
|
||||
$sm_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
|
||||
|
||||
$sql_insert = "INSERT INTO $this->db_mitra.m_user(
|
||||
M_UserM_CompanyID,
|
||||
M_UserS_RegionalID,
|
||||
M_UserM_MouID,
|
||||
M_UserUsername,
|
||||
M_UserPassword,
|
||||
M_UserCreated,
|
||||
M_UserLastUpdated,
|
||||
M_UserLastAccess,
|
||||
M_UserM_UserID) VALUES(?,?,?,?,?,NOW(),NOW(),NOW(),?)";
|
||||
$qry_insert = $this->db_regional->query($sql_insert, [
|
||||
$companyId,
|
||||
$regionalId,
|
||||
$mouId,
|
||||
$username,
|
||||
$sm_password,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_insert) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("user insert error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$insert_id = $this->db_regional->insert_id();
|
||||
|
||||
$sql_json_before = "SELECT *
|
||||
FROM $this->db_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$qry_json_before = $this->db_regional->query($sql_json_before, [$insert_id]);
|
||||
if (!$qry_json_before) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user select json error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_by_id = $qry_json_before->row();
|
||||
|
||||
$json_after_log = json_encode($data_by_id);
|
||||
|
||||
$sql_insert_log = "INSERT INTO $this->db_mitra_log.m_user_log(
|
||||
M_UserLogM_UserID,
|
||||
M_UserLogStatus,
|
||||
M_UserLogJSONBefore,
|
||||
M_UserLogJSONAfter,
|
||||
M_UserLogUserID,
|
||||
M_UserLogCreated) VALUES(?,'ADD',null,?,?,NOW())";
|
||||
$qry_insert_log = $this->db_regional->query($sql_insert_log, [
|
||||
$insert_id,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_insert_log) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user_log insert error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("Username sudah digunakan. Silahkan masukkan username yang lain", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_regional->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$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;
|
||||
}
|
||||
$this->db_regional->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$Id = "";
|
||||
if (isset($prm["Id"])) {
|
||||
$Id = trim($prm["Id"]);
|
||||
}
|
||||
|
||||
$companyId = "";
|
||||
if (isset($prm["companyId"])) {
|
||||
$companyId = trim($prm["companyId"]);
|
||||
}
|
||||
|
||||
$regionalId = "";
|
||||
if (isset($prm["regionalId"])) {
|
||||
$regionalId = trim($prm["regionalId"]);
|
||||
}
|
||||
|
||||
$mouId = "";
|
||||
if (isset($prm["mouId"])) {
|
||||
$mouId = trim($prm["mouId"]);
|
||||
}
|
||||
|
||||
$username = "";
|
||||
if (isset($prm["username"])) {
|
||||
$username = trim($prm["username"]);
|
||||
}
|
||||
|
||||
// cek username tidak boleh sama
|
||||
$sql_cek_username = "SELECT count(*) as total_user,
|
||||
M_UserID
|
||||
M_UserUsername,
|
||||
M_UserIsActive
|
||||
FROM $this->db_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserUsername = '{$username}' AND M_UserID != '{$Id}' AND (
|
||||
M_UserM_MouID != '{$mouId}'
|
||||
)";
|
||||
$qry_cek_username = $this->db_regional->query($sql_cek_username);
|
||||
if ($qry_cek_username) {
|
||||
$get_rows_username = $qry_cek_username->row_array();
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("ERROR, cek user", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($get_rows_username["total_user"] == 0) {
|
||||
// json before
|
||||
$sql_json_before = "SELECT *
|
||||
FROM $this->db_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
|
||||
$qry_json_before = $this->db_regional->query($sql_json_before, [
|
||||
$Id
|
||||
]);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user select json before");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_before_by_id = $qry_json_before->row();
|
||||
|
||||
$json_before_log = json_encode($data_before_by_id);
|
||||
|
||||
$sql_insert = "UPDATE $this->db_mitra.m_user SET
|
||||
M_UserM_CompanyID = ?,
|
||||
M_UserS_RegionalID = ?,
|
||||
M_UserM_MouID = ?,
|
||||
M_UserUsername = ?,
|
||||
M_UserLastUpdated = NOW(),
|
||||
M_UserM_UserID = ?
|
||||
WHERE M_UserID = ?";
|
||||
$qry_insert = $this->db_regional->query($sql_insert, [
|
||||
$companyId,
|
||||
$regionalId,
|
||||
$mouId,
|
||||
$username,
|
||||
$userid,
|
||||
$Id
|
||||
]);
|
||||
if (!$qry_insert) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("update user error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
// json after
|
||||
$sql_json_after = "SELECT *
|
||||
FROM $this->db_mitra.m_user
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$qry_json_after = $this->db_regional->query($sql_json_after, [$Id]);
|
||||
if (!$qry_json_after) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user select json error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_by_id = $qry_json_after->row();
|
||||
|
||||
$json_after_log = json_encode($data_by_id);
|
||||
|
||||
$sql_insert_log = "INSERT INTO $this->db_mitra_log.m_user_log(
|
||||
M_UserLogM_UserID,
|
||||
M_UserLogStatus,
|
||||
M_UserLogJSONBefore,
|
||||
M_UserLogJSONAfter,
|
||||
M_UserLogUserID,
|
||||
M_UserLogCreated) VALUES(?,'EDIT',?,?,?,NOW())";
|
||||
$qry_insert_log = $this->db_regional->query($sql_insert_log, [
|
||||
$Id,
|
||||
$json_before_log,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_insert_log) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user_log insert error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("Username sudah digunakan. Silahkan masukkan username yang lain", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_regional->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleterow()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db_regional->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$Id = "";
|
||||
if (isset($prm["Id"])) {
|
||||
$Id = trim($prm["Id"]);
|
||||
}
|
||||
|
||||
$sql = "UPDATE $this->db_mitra.m_user SET
|
||||
M_UserIsActive = 'N',
|
||||
M_UserLastUpdated = NOW(),
|
||||
M_UserM_UserID = ?
|
||||
WHERE M_UserID = ?";
|
||||
$qry = $this->db_regional->query($sql, [$userid, $Id]);
|
||||
if (!$qry) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user delete error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_json_before = "SELECT *
|
||||
FROM $this->db_mitra.m_user
|
||||
WHERE M_UserIsActive = 'N'
|
||||
AND M_UserID = ?";
|
||||
|
||||
$qry_json_before = $this->db_regional->query($sql_json_before, [$Id]);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user select json");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_by_id = $qry_json_before->row();
|
||||
|
||||
$json_after_log = json_encode($data_by_id);
|
||||
|
||||
$sql_insert_log = "INSERT INTO $this->db_mitra_log.m_user_log(
|
||||
M_UserLogM_UserID,
|
||||
M_UserLogStatus,
|
||||
M_UserLogJSONBefore,
|
||||
M_UserLogJSONAfter,
|
||||
M_UserLogUserID,
|
||||
M_UserLogCreated) VALUES(?,'DELETE',null,?,?,NOW())";
|
||||
$qry_insert_log = $this->db_regional->query($sql_insert_log, [
|
||||
$Id,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_insert_log) {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("m_user_log insert error", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_regional->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
1594
one-api/application/controllers/one_mitra/masterdata/Userv2.php
Normal file
1594
one-api/application/controllers/one_mitra/masterdata/Userv2.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user