Files
BE_CPONE/application/controllers/klinik/cashierklinik/Patient.php
2026-04-27 10:26:26 +07:00

214 lines
7.7 KiB
PHP

<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
//$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT PaymentOrderID as note_order_id,
PaymentID as note_id,
PaymentDate as note_date,
PaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(PaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
PaymentDetailIsActive as note_active
FROM one_klinik.`payment`
JOIN one_klinik.`paymentdetail` ON PaymentDetailPaymentID = PaymentID
JOIN `m_paymenttype` ON PaymentDetailM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN `m_user` ON PaymentDetailUserID = M_UserID
WHERE
PaymentOrderID = {$orderid}
GROUP BY PaymentID";
$query = $this->db_onedev->query($sql);
//echo $sql;
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$startdate = $prm['startdate'];
$enddate = $prm['enddate'] . " 23:59:59";
$search = $prm["search"];
$status = $prm["status"];
/*$company = $prm["company"];
$filter_company = '';
if($company != '0' || $company != 0)
$filter_company = " AND M_CompanyID = {$company}";
*/
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = " ( DATE(orderDate) = '{$startdate}' ) AND ";
if($search != ''){
$where = "( M_PatientName LIKE '%{$search}%' OR orderNumber LIKE '%{$search}%' ) AND ";
if(strlen($search) == 11){
$where = "orderNumber = '{$search}' AND ";
}
}
$sql = " SELECT count(*) as total
FROM one_klinik.`order`
JOIN m_patient ON orderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
WHERE
$where
( ('{$status}' = 'N' AND orderIsLunas = 'N') OR ('{$status}' = 'Y' AND orderIsLunas = 'Y') )";
$query = $this->db_onedev->query($sql, $sql_param);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$sql = "SELECT orderID,
orderDate,
orderNumber,
orderM_PatientID,
M_PatientNoReg,
orderKeluhan,
DATE_FORMAT(orderDate,'%d-%m-%Y %H:%i') as order_date,
CONCAT(M_TitleName,'. ',M_PatientName) as M_PatientName,
CONCAT(M_TitleLangName,'. ',M_PatientName) as M_PatientName_eng,
M_TitleName,
orderTotal as totalbill,
0 as paid,
0 as unpaid,
orderIsLunas as flaglunas,
'' as notes,
100 as mindp_percent,
settingPriceDefault as mindp_amount,
0 as F_BillDetailID
FROM one_klinik.`order`
JOIN m_patient ON orderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN one_klinik.`setting` ON settingIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND orderIsLunas = 'N') OR ('{$status}' = 'Y' AND orderIsLunas = 'Y') )
GROUP BY orderID
ORDER BY orderID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$sql = "SELECT IFNULL(SUM(PaymentTotal),0) as total
FROM one_klinik.payment
WHERE
PaymentOrderID = ? AND PaymentIsActive = 'Y'";
$data_payment = $this->db_onedev->query($sql, array($v['orderID']))->row();
$unpaid = $v['totalbill'] - $data_payment->total;
$rows[$k]['unpaid'] = $unpaid;
$rows[$k]['paid'] = $data_payment->total;
$rows[$k]['notes'] = $this->add_notes($v['orderID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
$rows = array('id'=>0,'name'=>'Semua');
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
array_push($rows,array('id'=>0,'name'=>'Semua'));
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
}