374 lines
12 KiB
PHP
374 lines
12 KiB
PHP
<?php
|
|
class Ais extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Resultentry API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
function get_branchs(){
|
|
$sql = "SELECT M_BranchCode as branch_code, M_BranchName as branch_name FROM m_branch WHERE M_BranchIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
$rows = $query->result_array();
|
|
$this->sys_ok($rows);
|
|
exit;
|
|
}
|
|
|
|
function get_corporates(){
|
|
$prm = $this->sys_input;
|
|
|
|
if(isset($prm['search'])){
|
|
$search = $prm['search'];
|
|
}else{
|
|
$search = '';
|
|
}
|
|
if($prm['current_page']){
|
|
$current_page = intval($prm['current_page']);
|
|
}else{
|
|
$current_page = 1;
|
|
}
|
|
if($prm['limit']){
|
|
$limit = intval($prm['limit']);
|
|
}else{
|
|
$limit = 100;
|
|
}
|
|
|
|
$offset = ($current_page - 1) * $limit;
|
|
|
|
$total = 0;
|
|
|
|
$sql = "SELECT count(*) as total
|
|
FROM corporate
|
|
WHERE CorporateIsActive = 'Y' AND
|
|
(
|
|
CorporateName LIKE CONCAT('%',?,'%') OR
|
|
CorporateCode LIKE CONCAT('%',?,'%')
|
|
)";
|
|
$query = $this->db_onedev->query($sql, array(
|
|
$search,
|
|
$search));
|
|
if(!$query){
|
|
$message = $this->db_onedev->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$c_rows = $query->result_array();
|
|
$total = $c_rows[0]['total'];
|
|
|
|
|
|
$sql = "SELECT
|
|
CorporateID as corporate_id,
|
|
CorporateCode as corporate_code,
|
|
CorporateName as corporate_name
|
|
FROM corporate
|
|
WHERE CorporateIsActive = 'Y' AND
|
|
(
|
|
CorporateName LIKE CONCAT('%',?,'%') OR
|
|
CorporateCode LIKE CONCAT('%',?,'%')
|
|
)
|
|
|
|
ORDER BY CorporateName ASC
|
|
LIMIT ? OFFSET ?";
|
|
$query = $this->db_onedev->query($sql, array(
|
|
$search,
|
|
$search,
|
|
$limit,
|
|
$offset));
|
|
if(!$query){
|
|
$message = $this->db_onedev->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
$result = array(
|
|
"total" => $total,
|
|
"current_page" => $current_page,
|
|
"limit" => $limit,
|
|
"offset" => $offset,
|
|
"total_page" => ceil($total / $limit),
|
|
"data" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function get_mcus(){
|
|
$prm = $this->sys_input;
|
|
$start_date = $prm['start_date'];
|
|
$end_date = $prm['end_date'];
|
|
$branch_code = isset($prm['branch_code']) ? $prm['branch_code'] : null;
|
|
$corporate_code = isset($prm['corporate_code']) ? $prm['corporate_code'] : null;
|
|
$limit = intval($prm['limit']);
|
|
$current_page = intval($prm['current_page']);
|
|
$offset = ($current_page - 1) * $limit;
|
|
|
|
if(isset($prm['search'])){
|
|
$search = $prm['search'];
|
|
}else{
|
|
$search = '';
|
|
}
|
|
|
|
$sql = "SELECT count(*) as total
|
|
FROM mgm_mcu
|
|
JOIN m_branch ON Mgm_McuM_BranchID = M_BranchID
|
|
JOIN corporate ON Mgm_McuCorporateID = CorporateID
|
|
WHERE Mgm_McuIsActive = 'Y' AND
|
|
(
|
|
Mgm_McuNumber LIKE CONCAT('%',?,'%') OR
|
|
Mgm_McuLabel LIKE CONCAT('%',?,'%')
|
|
) AND
|
|
(M_BranchCode = ? OR ? IS NULL) AND
|
|
(CorporateCode = ? OR ? IS NULL) AND
|
|
date(Mgm_McuStartDate) between ? and ? AND
|
|
date(Mgm_McuEndDate) between ? and ?";
|
|
$query = $this->db_onedev->query($sql, array(
|
|
$search,
|
|
$search,
|
|
$branch_code,
|
|
$branch_code,
|
|
$corporate_code,
|
|
$corporate_code,
|
|
$start_date,
|
|
$end_date,
|
|
$start_date,
|
|
$end_date));
|
|
if(!$query){
|
|
$message = $this->db_onedev->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$c_rows = $query->result_array();
|
|
$total = $c_rows[0]['total'];
|
|
|
|
$sql = "SELECT
|
|
Mgm_McuID as mcu_id,
|
|
Mgm_McuNumber as mcu_number,
|
|
Mgm_McuLabel as mcu_label,
|
|
M_BranchCode as branch_code,
|
|
M_BranchName as branch_name,
|
|
CorporateCode as corporate_code,
|
|
CorporateName as corporate_name
|
|
FROM mgm_mcu
|
|
JOIN m_branch ON Mgm_McuM_BranchID = M_BranchID
|
|
JOIN corporate ON Mgm_McuCorporateID = CorporateID
|
|
WHERE Mgm_McuIsActive = 'Y' AND
|
|
(
|
|
Mgm_McuNumber LIKE CONCAT('%',?,'%') OR
|
|
Mgm_McuLabel LIKE CONCAT('%',?,'%')
|
|
) AND
|
|
(M_BranchCode = ? OR ? IS NULL) AND
|
|
(CorporateCode = ? OR ? IS NULL) AND
|
|
( `Mgm_McuStartDate` >= ? AND `Mgm_McuEndDate` <= ?)
|
|
ORDER BY Mgm_McuNumber ASC
|
|
LIMIT ? OFFSET ?";
|
|
$query = $this->db_onedev->query($sql, array(
|
|
$search,
|
|
$search,
|
|
$branch_code,
|
|
$branch_code,
|
|
$corporate_code,
|
|
$corporate_code,
|
|
$start_date,
|
|
$end_date,
|
|
$limit,
|
|
$offset));
|
|
|
|
if(!$query){
|
|
|
|
$message = $this->db_onedev->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
$result = array(
|
|
"total" => $total,
|
|
"current_page" => $current_page,
|
|
"limit" => $limit,
|
|
"offset" => $offset,
|
|
"total_page" => ceil($total / $limit),
|
|
"data" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function get_data(){
|
|
$prm = $this->sys_input;
|
|
|
|
if(isset($prm['start_date'])){
|
|
$start_date = $prm['start_date'];
|
|
}else{
|
|
$start_date = null;
|
|
}
|
|
|
|
if(isset($prm['end_date'])){
|
|
$end_date = $prm['end_date'];
|
|
}else{
|
|
$end_date = null;
|
|
}
|
|
|
|
if(isset($prm['branch_code'])){
|
|
$branch_code = $prm['branch_code'];
|
|
}else{
|
|
$branch_code = null;
|
|
}
|
|
|
|
if(isset($prm['mcu_number'])){
|
|
$mcu_number = $prm['mcu_number'];
|
|
}
|
|
else{
|
|
$mcu_number = null;
|
|
}
|
|
|
|
if(isset($prm['corporate_code'])){
|
|
$corporate_code = $prm['corporate_code'];
|
|
}else{
|
|
$corporate_code = null;
|
|
}
|
|
|
|
if(isset($prm['limit'])){
|
|
$limit = intval($prm['limit']);
|
|
}else{
|
|
$limit = 500;
|
|
}
|
|
|
|
if(isset($prm['current_page'])){
|
|
$current_page = intval($prm['current_page']);
|
|
}else{
|
|
$current_page = 1;
|
|
}
|
|
|
|
|
|
$offset = ($current_page - 1) * $limit;
|
|
|
|
|
|
|
|
$sql = "SELECT count(*) as total
|
|
FROM (
|
|
SELECT T_OrderHeaderID
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
|
JOIN corporate on T_OrderHeaderCorporateID = CorporateID
|
|
JOIN m_branch on T_OrderHeaderM_BranchID = M_BranchID
|
|
JOIN mgm_mcu on T_OrderHeaderMgm_McuID = Mgm_McuID
|
|
|
|
WHERE T_OrderHeaderIsActive = 'Y'
|
|
AND date(T_OrderHeaderDate) between ? and ?
|
|
AND (M_BranchCode = ? OR ? IS NULL)
|
|
AND (Mgm_McuNumber = ? OR ? IS NULL)
|
|
AND (CorporateCode = ? OR ? IS NULL)
|
|
group by T_OrderHeaderID
|
|
) as t
|
|
";
|
|
$query = $this->db_onedev->query($sql, array(
|
|
$start_date,
|
|
$end_date,
|
|
$branch_code,
|
|
$branch_code,
|
|
$mcu_number,
|
|
$mcu_number,
|
|
$corporate_code,
|
|
$corporate_code));
|
|
if(!$query){
|
|
$message = $this->db_onedev->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$rows = $query->result_array();
|
|
$total = $rows[0]['total'];
|
|
$result = array();
|
|
|
|
$sql = "SELECT
|
|
T_OrderHeaderID as order_id,
|
|
T_OrderHeaderDate as order_date,
|
|
T_OrderHeaderLabNumber as order_lab_number,
|
|
concat(IF(M_TitleName IS NULL, '',CONCAT(M_TitleName,'. ')), M_PatientName) as patient_name,
|
|
T_OrderHeaderTotal as order_total,
|
|
CorporateID as corporate_id,
|
|
CorporateCode as corporate_code,
|
|
CorporateName as corporate_name,
|
|
Mgm_McuID as mcu_id,
|
|
Mgm_McuLabel as mcu_label,
|
|
Mgm_McuNumber as mcu_number,
|
|
M_BranchCode as branch_code,
|
|
M_BranchName as branch_name,
|
|
T_OrderHeaderTotal as order_total,
|
|
IFNULL(F_PaymentTotal, 0) as payment_total,
|
|
IFNULL(F_PaymentNumber, '-') as payment_number,
|
|
IF(T_OrderHeaderTotal - IFNULL(F_PaymentTotal, 0) > 0, 'Belum Bayar', 'Lunas') as payment_status,
|
|
'' as details
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
|
JOIN corporate on T_OrderHeaderCorporateID = CorporateID
|
|
JOIN m_branch on T_OrderHeaderM_BranchID = M_BranchID
|
|
JOIN mgm_mcu on T_OrderHeaderMgm_McuID = Mgm_McuID
|
|
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
|
WHERE T_OrderHeaderIsActive = 'Y'
|
|
AND date(T_OrderHeaderDate) between ? and ?
|
|
AND (M_BranchCode = ? OR ? IS NULL)
|
|
AND (Mgm_McuNumber = ? OR ? IS NULL)
|
|
AND (CorporateCode = ? OR ? IS NULL)
|
|
group by T_OrderHeaderID
|
|
limit ? offset ?";
|
|
$query = $this->db_onedev->query($sql, array(
|
|
$start_date,
|
|
$end_date,
|
|
$branch_code,
|
|
$branch_code,
|
|
$mcu_number,
|
|
$mcu_number,
|
|
$corporate_code,
|
|
$corporate_code,
|
|
$limit, $offset));
|
|
//echo $this->db_onedev->last_query();
|
|
if(!$query){
|
|
$message = $this->db_onedev->error();
|
|
//$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
|
|
if(count($rows) > 0){
|
|
foreach($rows as $key => $row){
|
|
$sql = "SELECT
|
|
T_TestName as test_name,
|
|
T_TestCode as test_code_cpone,
|
|
IFNULL(Nat_TestMapCode,'') as test_code_lis,
|
|
T_OrderDetailPrice as test_price,
|
|
T_OrderDetailDisc as test_disc,
|
|
T_OrderDetailDiscAmount as test_disc_amount,
|
|
T_OrderDetailDiscTotal as test_disc_total,
|
|
T_OrderDetailTotal as test_total
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsPrice = 'Y'
|
|
LEFT JOIN nat_testmap ON Nat_TestMapNat_TestID = T_TestNat_TestID
|
|
WHERE T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, array($row['order_id']));
|
|
$rows_detail = $query->result_array();
|
|
$rows[$key]['details'] = $rows_detail;
|
|
}
|
|
}
|
|
$result = array(
|
|
"total" => $total,
|
|
"current_page" => $current_page,
|
|
"limit" => $limit,
|
|
"offset" => $offset,
|
|
"total_page" => ceil($total / $limit),
|
|
"data" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
}
|