511 lines
21 KiB
PHP
511 lines
21 KiB
PHP
<?php
|
|
class Confirmeformx extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
var $load;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo "API CONFIRM EFORM";
|
|
// $cek = $this->db_onedev->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
}
|
|
|
|
function search_company()
|
|
{
|
|
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$qry = "%" . $prm["search"] . '%';
|
|
|
|
$sql = "SELECT M_CompanyID, M_CompanyName
|
|
FROM m_company
|
|
WHERE M_CompanyName LIKE ?
|
|
AND M_CompanyIsActive = 'Y'
|
|
ORDER BY M_CompanyName DESC";
|
|
$query = $this->db_onedev->query($sql, array($qry));
|
|
if (!$query) {
|
|
$this->sys_error_db("select company error", $this->db_onedev);
|
|
exit;
|
|
} else {
|
|
$rows = $query->result_array();
|
|
$rows[] = array("M_CompanyID" => 0, "M_CompanyName" => "Semua");
|
|
}
|
|
|
|
$result = array(
|
|
"data" => $rows
|
|
);
|
|
$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;
|
|
|
|
$qry = "%" . $prm["search"] . '%';
|
|
$companyID = $prm["company_id"];
|
|
|
|
$sql = "SELECT
|
|
M_MouID,
|
|
M_MouName,
|
|
M_MouM_CompanyID
|
|
FROM m_mou
|
|
WHERE
|
|
M_MouM_CompanyID = ?
|
|
AND M_MouName LIKE ?
|
|
AND M_MouIsActive = 'Y'
|
|
AND M_MouIsMcu = 'Y'";
|
|
$query = $this->db_onedev->query($sql, array($companyID, $qry));
|
|
if (!$query) {
|
|
$this->sys_error_db("select mou error", $this->db_onedev);
|
|
exit;
|
|
} else {
|
|
$rows = $query->result_array();
|
|
$rows[] = array("M_MouID" => 0, "M_MouName" => "Semua", "M_MouM_CompanyID" => 0);
|
|
}
|
|
|
|
$result = array(
|
|
"data" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function lookup()
|
|
{
|
|
try {
|
|
# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$search = $prm["search"];
|
|
$mouID = $prm["mou_id"];
|
|
|
|
$where_company = "";
|
|
|
|
$companyid = $prm['companyid'];
|
|
if ($companyid != "" || $companyid != 0 || $companyid != "0") {
|
|
$companyid = $prm['companyid'];
|
|
$where_company = "AND M_MouM_CompanyID = $companyid";
|
|
}
|
|
if (isset($prm['mou_id'])) {
|
|
# code...
|
|
if (
|
|
$mouID != "" || $mouID != 0 || $mouID != "0"
|
|
) {
|
|
$mouID = $prm['mou_id'];
|
|
$where_company .= " AND M_MouID = $mouID";
|
|
}
|
|
}
|
|
|
|
$where = "";
|
|
$date = $prm['date'];
|
|
|
|
$start_date = $date . " 00:00:00";
|
|
$end_date = $date . " 23:59:59";
|
|
|
|
// $filter_date = " DATE(T_OrderHeaderDate) = '{$date}'";
|
|
// if ($date != '') {
|
|
// $where = "$filter_date ";
|
|
// }
|
|
|
|
if ($search != '') {
|
|
$where .= " WHERE ( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' OR T_OrderHeaderLabNumberExt LIKE '%{$search}%' ) ";
|
|
}
|
|
|
|
$number_limit = 20;
|
|
// $number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$number_offset = 0;
|
|
if ($prm['current_page'] > 0) {
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_filter = "SELECT count(*) as total
|
|
FROM (
|
|
SELECT
|
|
LogConfirmEformID,
|
|
IFNULL(LogConfirmEformStatus,'-') as LogConfirmEformStatus,
|
|
LogConfirmEformRetry,
|
|
DATE_FORMAT(LogConfirmEformCreated, '%d-%m-%Y %H:%i:%s') AS LogConfirmEformCreated,
|
|
DATE_FORMAT(LogConfirmEformLastUpdated, '%d-%m-%Y %H:%i:%s') AS LogConfirmEformLastUpdated,
|
|
T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber as no_reg,
|
|
T_OrderHeaderDate,
|
|
concat(M_TitleName, ' ', ifnull(M_PatientPrefix,' '),M_PatientName, ifnull(M_PatientSuffix,'')) as nama_pasien,
|
|
M_PatientHP,
|
|
'' as test,
|
|
M_MouName
|
|
FROM t_orderheader
|
|
join t_orderdetail
|
|
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
-- AND T_OrderHeaderDate >= '{$start_date}'
|
|
-- AND T_OrderHeaderDate <= '{$end_date}'
|
|
AND DATE(T_OrderHeaderDate) = '{$date}'
|
|
join so_testtemplate
|
|
ON T_OrderDetailT_TestID = So_TestTemplateT_TestID
|
|
AND So_TestTemplateIsActive = 'Y'
|
|
join so_template
|
|
ON So_TestTemplateSo_TemplateID = So_TemplateID
|
|
AND So_TemplateIsActive = 'Y'
|
|
AND So_TemplateID IN (6,8,9)
|
|
join m_mou
|
|
ON T_OrderHeaderM_MouID = M_MouID
|
|
AND M_MouIsActive = 'Y'
|
|
AND M_MouIsReleased = 'Y'
|
|
AND M_MouIsMcu = 'Y'
|
|
$where_company
|
|
AND M_MouIsBill = 'Y'
|
|
join m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
join m_title
|
|
on M_PatientM_TitleID = M_TitleID
|
|
left join log_confirm_eform
|
|
ON T_OrderHeaderID = LogConfirmEformT_OrderHeaderID
|
|
AND LogConfirmEformIsActive = 'Y'
|
|
$where
|
|
group by T_OrderHeaderID
|
|
|
|
UNION
|
|
|
|
select
|
|
LogConfirmEformID,
|
|
IFNULL(LogConfirmEformStatus,'-') as LogConfirmEformStatus,
|
|
LogConfirmEformRetry,
|
|
DATE_FORMAT(LogConfirmEformCreated, '%d-%m-%Y %H:%i:%s') AS LogConfirmEformCreated,
|
|
DATE_FORMAT(LogConfirmEformLastUpdated, '%d-%m-%Y %H:%i:%s') AS LogConfirmEformLastUpdated,
|
|
T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber as no_reg,
|
|
T_OrderHeaderDate,
|
|
concat(M_TitleName, ' ', ifnull(M_PatientPrefix,' '), M_PatientName, ifnull(M_PatientSuffix,'')) as nama_pasien,
|
|
M_PatientHP,
|
|
'' as test,
|
|
M_MouName
|
|
from t_orderheader
|
|
join t_orderdetail
|
|
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
-- AND T_OrderHeaderDate >= '{$start_date}'
|
|
-- AND T_OrderHeaderDate <= '{$end_date}'
|
|
AND DATE(T_OrderHeaderDate) = '{$date}'
|
|
join so_testtemplate
|
|
ON T_OrderDetailT_TestID = So_TestTemplateT_TestID
|
|
AND So_TestTemplateIsActive = 'Y'
|
|
join so_template
|
|
ON So_TestTemplateSo_TemplateID = So_TemplateID
|
|
AND So_TemplateIsActive = 'Y'
|
|
AND So_TemplateID IN (6,8,9)
|
|
join m_mou
|
|
ON T_OrderHeaderM_MouID = M_MouID
|
|
AND M_MouIsActive = 'Y'
|
|
AND M_MouIsReleased = 'Y'
|
|
AND M_MouIsMcu = 'Y'
|
|
$where_company
|
|
join m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
join m_title
|
|
on M_PatientM_TitleID = M_TitleID
|
|
join f_payment
|
|
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
|
AND F_PaymentIsActive = 'Y'
|
|
join f_payment_orderheader
|
|
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
|
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
|
left join log_confirm_eform
|
|
ON T_OrderHeaderID = LogConfirmEformT_OrderHeaderID
|
|
AND LogConfirmEformIsActive = 'Y'
|
|
$where
|
|
group by T_OrderHeaderID
|
|
) x";
|
|
|
|
$query_filter = $this->db_onedev->query($sql_filter);
|
|
// $last_qry = $this->db_onedev->last_query();
|
|
// print_r($last_qry);
|
|
// exit;
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query_filter) {
|
|
$tot_count = $query_filter->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("eform count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql_data = "SELECT
|
|
LogConfirmEformID,
|
|
IFNULL(LogConfirmEformStatus,'-') as LogConfirmEformStatus,
|
|
LogConfirmEformRetry,
|
|
DATE_FORMAT(LogConfirmEformCreated, '%d-%m-%Y %H:%i:%s') AS LogConfirmEformCreated,
|
|
DATE_FORMAT(LogConfirmEformLastUpdated, '%d-%m-%Y %H:%i:%s') AS LogConfirmEformLastUpdated,
|
|
T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber as no_reg,
|
|
T_OrderHeaderDate,
|
|
concat(M_TitleName, ' ', ifnull(M_PatientPrefix,' '), M_PatientName, ifnull(M_PatientSuffix,'')) as nama_pasien,
|
|
IFNULL(NULLIF(M_PatientHP, ''), '-') as M_PatientHP,
|
|
IFNULL(NULLIF(M_PatientIDNumber,''),'-') as M_PatientIDNumber,
|
|
'' as test,
|
|
M_MouName
|
|
FROM t_orderheader
|
|
join t_orderdetail
|
|
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
-- AND T_OrderHeaderDate >= '{$start_date}'
|
|
-- AND T_OrderHeaderDate <= '{$end_date}'
|
|
AND DATE(T_OrderHeaderDate) = '{$date}'
|
|
join so_testtemplate
|
|
ON T_OrderDetailT_TestID = So_TestTemplateT_TestID
|
|
AND So_TestTemplateIsActive = 'Y'
|
|
join so_template
|
|
ON So_TestTemplateSo_TemplateID = So_TemplateID
|
|
AND So_TemplateIsActive = 'Y'
|
|
AND So_TemplateID IN (6,8,9)
|
|
join m_mou
|
|
ON T_OrderHeaderM_MouID = M_MouID
|
|
AND M_MouIsActive = 'Y'
|
|
AND M_MouIsReleased = 'Y'
|
|
AND M_MouIsMcu = 'Y'
|
|
$where_company
|
|
AND M_MouIsBill = 'Y'
|
|
join m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
join m_title
|
|
on M_PatientM_TitleID = M_TitleID
|
|
left join log_confirm_eform
|
|
ON T_OrderHeaderID = LogConfirmEformT_OrderHeaderID
|
|
AND LogConfirmEformIsActive = 'Y'
|
|
$where
|
|
group by T_OrderHeaderID
|
|
|
|
UNION
|
|
|
|
SELECT
|
|
LogConfirmEformID,
|
|
IFNULL(LogConfirmEformStatus,'-') as LogConfirmEformStatus,
|
|
LogConfirmEformRetry,
|
|
DATE_FORMAT(LogConfirmEformCreated, '%d-%m-%Y %H:%i:%s') AS LogConfirmEformCreated,
|
|
DATE_FORMAT(LogConfirmEformLastUpdated, '%d-%m-%Y %H:%i:%s') AS LogConfirmEformLastUpdated,
|
|
T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber as no_reg,
|
|
T_OrderHeaderDate,
|
|
concat(M_TitleName, ' ', ifnull(M_PatientPrefix,' '), M_PatientName, ifnull(M_PatientSuffix,'')) as nama_pasien,
|
|
IFNULL(NULLIF(M_PatientHP, ''), '-') as M_PatientHP,
|
|
IFNULL(NULLIF(M_PatientIDNumber,''),'-') as M_PatientIDNumber,
|
|
'' as test,
|
|
M_MouName
|
|
from t_orderheader
|
|
join t_orderdetail
|
|
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
-- AND T_OrderHeaderDate >= '{$start_date}'
|
|
-- AND T_OrderHeaderDate <= '{$end_date}'
|
|
AND DATE(T_OrderHeaderDate) = '{$date}'
|
|
join so_testtemplate
|
|
ON T_OrderDetailT_TestID = So_TestTemplateT_TestID
|
|
AND So_TestTemplateIsActive = 'Y'
|
|
join so_template
|
|
ON So_TestTemplateSo_TemplateID = So_TemplateID
|
|
AND So_TemplateIsActive = 'Y'
|
|
AND So_TemplateID IN (6,8,9)
|
|
join m_mou
|
|
ON T_OrderHeaderM_MouID = M_MouID
|
|
AND M_MouIsActive = 'Y'
|
|
AND M_MouIsReleased = 'Y'
|
|
AND M_MouIsMcu = 'Y'
|
|
$where_company
|
|
join m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
join m_title
|
|
on M_PatientM_TitleID = M_TitleID
|
|
join f_payment
|
|
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
|
AND F_PaymentIsActive = 'Y'
|
|
join f_payment_orderheader
|
|
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
|
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
|
left join log_confirm_eform
|
|
ON T_OrderHeaderID = LogConfirmEformT_OrderHeaderID
|
|
AND LogConfirmEformIsActive = 'Y'
|
|
$where
|
|
group by T_OrderHeaderID
|
|
limit $number_limit offset $number_offset";
|
|
|
|
// $sql_param = array($search);
|
|
$query_data = $this->db_onedev->query($sql_data);
|
|
|
|
if ($query_data) {
|
|
$rows = $query_data->result_array();
|
|
if (count($rows) > 0) {
|
|
$sql_dt = "";
|
|
foreach ($rows as $k => $v) {
|
|
$order_id = $v['T_OrderHeaderID'];
|
|
$dt_test = [];
|
|
$sql_dt = "SELECT T_OrderDetailT_TestName as x_test,
|
|
So_TemplateName
|
|
from t_orderdetail
|
|
join t_test
|
|
ON T_OrderDetailT_TestID = T_TestID
|
|
AND T_TestIsActive = 'Y'
|
|
join so_testtemplate
|
|
ON T_TestID = So_TestTemplateT_TestID
|
|
AND So_TestTemplateIsActive = 'Y'
|
|
join so_template
|
|
ON So_TestTemplateSo_TemplateID = So_TemplateID
|
|
AND So_TemplateIsActive = 'Y'
|
|
AND So_TemplateID IN (6,8,9)
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = $order_id
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND T_TestIsPrice = 'Y'
|
|
";
|
|
|
|
// echo $sql_dt;
|
|
$xdt_test = $this->db_onedev->query($sql_dt);
|
|
// print_r($xdt_test);
|
|
if (!$xdt_test) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("order detail");
|
|
exit;
|
|
} else {
|
|
$testArr = $xdt_test->result_array();
|
|
$rows[$k]['test'] = $testArr;
|
|
$xno = ($k + 1) + $number_offset;
|
|
$rows[$k]['rownumber'] = $xno;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("eform select");
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total_page" => $tot_page,
|
|
"total_all" => $tot_count,
|
|
"total_filter" => count($rows),
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query(),
|
|
"sql_data" => ($sql_data),
|
|
"sql_filter" => ($sql_filter)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function confirm()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db_onedev->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userID = $this->sys_user['M_UserID'];
|
|
$orderheaderID = $prm["orderheaderID"];
|
|
|
|
$sql = "INSERT INTO log_confirm_eform(
|
|
LogConfirmEformT_OrderHeaderID,
|
|
LogConfirmEformStatus,
|
|
LogConfirmEformRetry,
|
|
LogConfirmEformCreated,
|
|
LogConfirmEformLastUpdated,
|
|
LogConfirmEformUserID) VALUES(?,?,?,NOW(),NOW(),?)";
|
|
$qry = $this->db_onedev->query($sql, array($orderheaderID, "C", "0", $userID));
|
|
|
|
if (!$qry) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "insert log_confirm_eform | " .
|
|
$this->db_onedev->error()["message"], "debug" => $this->db_onedev->last_query()]);
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $prm
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function reupload()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db_onedev->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userID = $this->sys_user['M_UserID'];
|
|
$logconfirmeformID = $prm["logconfirmeformID"];
|
|
|
|
$sql = "UPDATE log_confirm_eform
|
|
SET LogConfirmEformStatus = ?,
|
|
LogConfirmEformRetry = ?,
|
|
LogConfirmEformLastUpdated = NOW(),
|
|
LogConfirmEformUserID = ?
|
|
WHERE LogConfirmEformID = ?";
|
|
$qry = $this->db_onedev->query($sql, array("R", "0", $userID, $logconfirmeformID));
|
|
|
|
if (!$qry) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "update log_confirm_eform | " .
|
|
$this->db_onedev->error()["message"], "debug" => $this->db_onedev->last_query()]);
|
|
exit;
|
|
}
|
|
|
|
|
|
$this->db_onedev->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $prm
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|