Files
2026-04-27 10:31:17 +07:00

1277 lines
52 KiB
PHP

<?php
class Billconfirm extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillConfirmIsActive = 'Y'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ? ";
$sql_param[] = "%$nama%";
}
/* if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " concat(F_BillNo, ' ',F_BillConfirmRefNumber) like ? ";
$sql_param[] = "%$norm%";
}
*/
$sql = " SELECT count(*) as total
FROM f_bill_confirm
LEFT JOIN m_mou ON F_BillConfirmM_MouID = M_MouID
left join m_company on F_BillConfirmM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
f_bill_confirm.*,
F_BillConfirmM_MouID,
M_MouID,
M_MouName,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
DATE_FORMAT(F_BillConfirmCreated,'%d-%m-%Y') as billdate,
DATE_FORMAT(F_BillConfirmDateConfirm,'%d-%m-%Y') as confirmdate,
DATE_FORMAT(F_BillConfirmDateDownload,'%d-%m-%Y') as downloaddate
FROM f_bill_confirm
LEFT JOIN m_mou ON F_BillConfirmM_MouID = M_MouID
left join m_company on F_BillConfirmM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillConfirmID DESC
limit 0,$tot_count ";
echo $this->db_onedev->last_query();
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_confirm_detail
where F_BillConfirmDetailF_BillConfirmID = '{$v['F_BillConfirmID']}'")->row();
if($x->tot == 0 ) {
$mouID = $v['F_BillConfirmM_MouID'];
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM t_orderheader
JOIN f_bill_confirm ON F_BillConfirmF_BillConfirmID = '{$v['F_BillConfirmID']}'
left join m_company ON F_BillConfirmM_CompanyID = M_CompanyID
LEFT JOIN f_bill_confirm_detail ON T_OrderHeaderID = F_BillConfirmDetailT_OrderHeaderID AND F_BillConfirmDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_PaymentID IS NULL")->row();
echo $this->db_onedev->last_query();
$rows[$k]['haveDetail'] = "N";
$rows[$k]['startdate'] = $startdate->startdate;
} else {
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM f_bill_confirm_detail
join t_orderheader ON F_BillConfirmDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillConfirmDetailIsActive = 'Y' and F_BillConfirmDetailF_BillConfirmID = '{$v['F_BillConfirmID']}'")->row();
$rows[$k]['haveDetail'] = "Y";
$rows[$k]['startdate'] = $startdate->startdate;
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchbank(){
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_bank_account
join nat_bank on Nat_BankID = M_BankAccountNat_BankID
WHERE
CONCAT(Nat_BankName, ' [ ',M_BankAccountNo,' | ',IFNULL(M_BankAccountName,''),' ]') like ?
AND M_BankAccountIsActive = '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_bank_account count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(Nat_BankName, ' [ ',M_BankAccountNo,' | ',IFNULL(M_BankAccountName,''),' ]') as M_BankAccountName
FROM m_bank_account
join nat_bank on Nat_BankID = M_BankAccountNat_BankID
WHERE
CONCAT(Nat_BankName, ' [ ',M_BankAccountNo,' | ',IFNULL(M_BankAccountName,''),' ]') like ?
AND M_BankAccountIsActive = 'Y'
ORDER BY M_BankAccountIsDefault desc, Nat_BankName asc
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//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_bank_account rows",$this->db_onedev);
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
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') 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_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') 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();
//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;
}
}
function getmou(){
$prm = $this->sys_input;
$query ="SELECT M_MouID,
M_MouName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
M_MouAgingDay,
M_MouPicBillName,
M_MouPicBillHandphone,
M_MouPicBillEmail,
CONCAT(M_MouPicBillName,' , ', M_MouFinanceName) as M_MouFinanceName,
CONCAT(M_MouPicBillHandphone,' , ', M_MouFinanceHandphone) as M_MouFinanceHandphone,
CONCAT(M_MouPicBillEmail,' , ', M_MouFinanceEmail) as M_MouFinanceEmail
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
AND M_MouM_BillTypeID = 2
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function listmou(){
$prm = $this->sys_input;
$query ="SELECT M_MouID,
M_MouName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
M_MouAgingDay,
M_MouPicBillName,
M_MouPicBillHandphone,
M_MouPicBillEmail,
CONCAT(M_MouPicBillName,' , ', M_MouFinanceName) as M_MouFinanceName,
CONCAT(M_MouPicBillHandphone,' , ', M_MouFinanceHandphone) as M_MouFinanceHandphone,
CONCAT(M_MouPicBillEmail,' , ', M_MouFinanceEmail) as M_MouFinanceEmail,
DATE_FORMAT(DATE_ADD(date(now()), INTERVAL M_MouAgingDay DAY),'%d-%m-%Y') as duedateina,
DATE_FORMAT(DATE_ADD(date(now()), INTERVAL M_MouAgingDay DAY),'%Y-%m-%d') as duedate
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
AND M_MouM_BillTypeID = 2
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getnomor(){
$prm = $this->sys_input;
$query ="SELECT M_No_FormRev
FROM m_no_form
WHERE
M_No_FormIsActive = 'Y' AND M_No_FormName = 'BILL'";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array()[0]["M_No_FormRev"];
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT *, CONCAT(R_ReportCode,' | ',R_ReportName) as rname
FROM r_report
WHERE
R_ReportCode IN('KEU09','KEU10','KEU11','KEU12','KEU13','KEU14','KEU15','KEU16','KEU17') AND `R_ReportIsActive` = 'Y'
ORDER BY R_ReportCode ASC
";
//echo $query;
$rows['reports'] = $this->db_onedev->query($query)->result_array();
$query ="SELECT '/birt/run?__report=report/one/fo/rpt_t_009.rptdesign' as t_url, 'PENAGIHAN' as t_name
UNION SELECT '/birt/run?__report=report/one/fo/rpt_bill_issue_inv.rptdesign' as t_url, 'LAMPIRAN TAGIHAN (PERIODE BULAN)' as t_name
UNION SELECT '/birt/run?__report=report/one/fo/rpt_bill_issue_inv_tanggal.rptdesign' as t_url, 'LAMPIRAN TAGIHAN (PERIODE TANGGAL)' as t_name
UNION SELECT '/birt/run?__report=report/one/fo/rpt_bill_issue_kwitansi.rptdesign' as t_url, 'KWITANSI (PERIODE BULAN)' as t_name
UNION SELECT '/birt/run?__report=report/one/fo/rpt_bill_issue_kwitansi_tanggal.rptdesign' as t_url, 'KWITANSI (PERIODE TANGGAL)' as t_name
UNION SELECT '/birt/run?__report=report/one/fo/rpt_bill_issue_tandaterima.rptdesign' as t_url, 'TANDA TERIMA (PERIODE BULAN)' as t_name
UNION SELECT '/birt/run?__report=report/one/fo/rpt_bill_issue_tandaterima_tanggal.rptdesign' as t_url, 'TANDA TERIMA (PERIODE TANGGAL)' as t_name
";
//echo $query;
$rows['cetaks'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill_confirm (
F_BillConfirmM_CompanyID,
F_BillConfirmM_MouID,
F_BillConfirmUserID,
F_BillConfirmCreated
)
VALUES(
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
public function uploadnew($img,$tanggal,$idbill,$idissue,$sdate)
{
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$home_dir = "/home/one/project/one/";
$target_dir = $home_dir . "one-media/one-photo/";
$sqlsum = "select F_BillNo as billNo from f_bill
where F_BillConfirmID = $idbill";
$billNo = $this->db_onedev->query($sqlsum)->row()->billNo;
if (!file_exists($target_dir)) {
mkdir($target_dir, 0755, true);
}
$filename = date("YmdHis")."_".$billNo . ".jpg";
$target_path = $target_dir . $filename;
$this->base64_to_jpeg($img, $target_path);
$sql = "UPDATE f_bill_confirm SET F_BillConfirmImg = '{$filename}',
F_BillConfirmIsReceive = 'Y',
F_BillConfirmReceiveDate = '{$tanggal}',
F_BillConfirmReceiveUserID = {$userid}
WHERE F_BillConfirmID = {$idissue}";
//echo $sql;
$save = $this->db_onedev->query($sql);
$sqlbill = "UPDATE f_bill SET F_BillDueDate = '{$sdate}'
WHERE F_BillConfirmID = {$idbill}";
//echo $sqlbill;
$savebill = $this->db_onedev->query($sqlbill);
$result = array("url" => "http://" . $_SERVER['SERVER_NAME'] . "/one-media/one-photo/" . $filename. "?d=" . date("YmdHis"));
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_confirm SET
F_BillConfirmM_BankAccountID = '{$prm['bankid']}',
F_BillConfirmUserID = '{$userid}'
WHERE F_BillConfirmF_BillConfirmID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$query ="UPDATE f_bill SET
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}'
WHERE F_BillConfirmID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_confirm_detail(F_BillConfirmDetailF_BillConfirmID, F_BillConfirmDetailT_OrderHeaderID,
F_BillConfirmDetailTotal, F_BillConfirmDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function saveall_tempbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billid = $prm['billID'];
$status = $prm['status'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$id = $v['Temp_BillConfirmID'];
if($status == 'Y' && $id == '0'){
$sql = "insert into temp_bill_confirm(
Temp_BillConfirmF_BillConfirmID,
Temp_BillConfirmM_MouID,
Temp_BillConfirmT_OrderHeaderID,
Temp_BillConfirmUserID,
Temp_BillConfirmTotal,
Temp_BillConfirmCreated,
Temp_BillConfirmLastUpdated)
values(?,?,?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array($billid,
$v['M_MouID'],
$v['T_OrderHeaderID'],
$userid,
$v['total'],)
);
if (!$query) {
$this->sys_error_db("temp_bill_confirm insert",$this->db_onedev);
exit;
}
}elseif($status == 'N' && $id != '0'){
$sql = "UPDATE temp_bill_confirm SET
Temp_BillConfirmIsActive = 'N',
Temp_BillConfirmUserID = ?
WHERE Temp_BillConfirmID = ?";
$query = $this->db_onedev->query($sql,
array($userid,
$id
)
);
if (!$query) {
$this->sys_error_db("temp_bill_confirm update",$this->db_onedev);
exit;
}
}
}
$sqlsum = "select format(sum(IFNULL(Temp_BillConfirmTotal,0)),0) sumtot, count(Temp_BillConfirmID) as ctot from temp_bill_confirm
LEFT JOIN f_bill_confirm_detail ON F_BillConfirmDetailT_OrderHeaderID = Temp_BillConfirmT_OrderHeaderID AND F_BillConfirmDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillConfirmID=F_BillConfirmDetailF_BillConfirmID AND F_BillConfirmIsActive = 'Y'
where Temp_BillConfirmF_BillConfirmID=? AND Temp_BillConfirmIsActive = 'Y' AND F_BillConfirmDetailID is null";
$rstsum = $this->db_onedev->query($sqlsum,array($billid))->row();
$sumtotal = $rstsum->sumtot;
$ctotal = $rstsum->ctot;
$result = array ("total" => 1, "ctotal" => $ctotal,"sumtotal" => $sumtotal,"records" => array("xid" => 0));
$this->sys_ok($result);
}
function save_tempbill(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$mouid = $prm['mouid'];
$billid = $prm['billid'];
$headerid = $prm['headerid'];
$status = $prm['checx'];
$total = $prm['total'];
$userid = $this->sys_user["M_UserID"];
if($status == 'Y' && $id == '0'){
$sql = "insert into temp_bill_confirm(
Temp_BillConfirmF_BillConfirmID,
Temp_BillConfirmM_MouID,
Temp_BillConfirmT_OrderHeaderID,
Temp_BillConfirmUserID,
Temp_BillConfirmTotal,
Temp_BillConfirmCreated,
Temp_BillConfirmLastUpdated)
values(?,?,?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array($billid,
$mouid,
$headerid,
$userid,
$total)
);
if (!$query) {
$this->sys_error_db("temp_bill_confirm insert",$this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$sqlsum = "select format(sum(IFNULL(Temp_BillConfirmTotal,0)),0) sumtot, count(Temp_BillConfirmID) as ctot from temp_bill_confirm
LEFT JOIN f_bill_confirm_detail ON F_BillConfirmDetailT_OrderHeaderID = Temp_BillConfirmT_OrderHeaderID AND F_BillConfirmDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillConfirmID=F_BillConfirmDetailF_BillConfirmID AND F_BillConfirmIsActive = 'Y'
where Temp_BillConfirmF_BillConfirmID=? AND Temp_BillConfirmIsActive = 'Y' AND F_BillConfirmDetailID is null";
$rstsum = $this->db_onedev->query($sqlsum,array($billid))->row();
$sumtotal = $rstsum->sumtot;
$ctotal = $rstsum->ctot;
$result = array ("total" => 1, "ctotal" => $ctotal,"sumtotal" => $sumtotal,"records" => array("xid" => 0));
$this->sys_ok($result);
}elseif($status == 'N' && $id != '0'){
$sql = "UPDATE temp_bill_confirm SET
Temp_BillConfirmIsActive = 'N',
Temp_BillConfirmUserID = ?
WHERE Temp_BillConfirmID = ?";
$query = $this->db_onedev->query($sql,
array($userid,
$id
)
);
if (!$query) {
$this->sys_error_db("temp_bill_confirm update",$this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$sqlsum = "select format(sum(IFNULL(Temp_BillConfirmTotal,0)),0) sumtot, count(Temp_BillConfirmID) as ctot from temp_bill_confirm
LEFT JOIN f_bill_confirm_detail ON F_BillConfirmDetailT_OrderHeaderID = Temp_BillConfirmT_OrderHeaderID AND F_BillConfirmDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillConfirmID=F_BillConfirmDetailF_BillConfirmID AND F_BillConfirmIsActive = 'Y'
where Temp_BillConfirmF_BillConfirmID=? AND Temp_BillConfirmIsActive = 'Y' AND F_BillConfirmDetailID is null";
$rstsum = $this->db_onedev->query($sqlsum,array($billid))->row();
$sumtotal = $rstsum->sumtot;
$ctotal = $rstsum->ctot;
$result = array ("total" => 1, "ctotal" => $ctotal,"records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$search = $prm["search"];
$sql = "select count(*) tot from f_bill_confirm_detail where F_BillConfirmDetailF_BillConfirmID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_confirm_detail
join t_orderheader ON F_BillConfirmDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillConfirmDetailIsActive = 'Y' and F_BillConfirmDetailF_BillConfirmID = '{$billID}'
GROUP BY F_BillConfirmDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "SELECT *, IF(F_BillConfirmID IS NULL ,'N','Y') as isbill,
'' as F_BillNo,
IF(Temp_BillConfirmID = 0 OR F_BillConfirmID IS NOT NULL,'N','Y') as checx,
IF(Temp_BillConfirmID = 0 OR F_BillConfirmID IS NOT NULL,'false','true') as chex FROM (select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
SUM(IFNULL(F_PaymentTotal,0)) as bayar,
T_OrderHeaderTotal - SUM(IFNULL(F_PaymentTotal,0)) as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID,
IFNULL(Temp_BillConfirmID,0) as Temp_BillConfirmID
FROM t_orderheader
join f_bill_confirm on F_BillConfirmID = '{$billID}'
left join m_company ON F_BillConfirmM_CompanyID = M_CompanyID
LEFT JOIN f_bill_confirm_detail ON T_OrderHeaderID = F_BillConfirmDetailT_OrderHeaderID AND F_BillConfirmDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0 AND M_MouM_BillTypeID = 2
left join temp_bill_confirm ON Temp_BillConfirmF_BillConfirmID = F_BillConfirmID AND Temp_BillConfirmM_MouID = M_MouID AND Temp_BillConfirmT_OrderHeaderID = T_OrderHeaderID AND Temp_BillConfirmIsActive = 'Y'
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID))
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
AND (T_OrderHeaderLabNumber like concat('%','{$search}','%')
OR T_OrderHeaderLabNumberExt like concat('%','{$search}','%')
OR M_PatientName like concat('%','{$search}','%'))
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC) a
LEFT JOIN f_bill_confirm_detail ON T_OrderHeaderID = F_BillConfirmDetailT_OrderHeaderID AND F_BillConfirmDetailIsActive = 'Y'
LEFT JOIN f_bill_confirm ON F_BillConfirmDetailF_BillConfirmID = F_BillConfirmID AND F_BillConfirmIsActive = 'Y'
WHERE total > 1";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$sqlsum = "select format(sum(IFNULL(Temp_BillConfirmTotal,0)),0) sumtot, count(Temp_BillConfirmID) as ctot from temp_bill_confirm
LEFT JOIN f_bill_confirm_detail ON F_BillConfirmDetailT_OrderHeaderID = Temp_BillConfirmT_OrderHeaderID AND F_BillConfirmDetailIsActive = 'Y'
LEFT JOIN f_bill_confirm ON F_BillConfirmID=F_BillConfirmDetailF_BillConfirmID AND F_BillConfirmIsActive = 'Y'
where Temp_BillConfirmF_BillConfirmID=? AND Temp_BillConfirmIsActive = 'Y' AND F_BillConfirmDetailID is null";
$rstsum = $this->db_onedev->query($sqlsum,array($billID))->row();
$sumtotal = $rstsum->sumtot;
$ctotal = $rstsum->ctot;
$result = array(
"total" => count($rows) ,
"records" => $rows,
"sumtotal" => $sumtotal,
"ctotal" => $ctotal
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_confirm_detail
(F_BillConfirmDetailF_BillConfirmID,
F_BillConfirmDetailT_OrderHeaderID,
F_BillConfirmDetailTotal,
F_BillConfirmDetailUnpaid,
F_BillConfirmDetailUserID,
F_BillConfirmDetailCreated,
F_BillConfirmDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
$querymou = "INSERT INTO f_bill_mou (F_BillMouF_BillConfirmID,F_BillMouM_MouID,F_BillMouUserID) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE
F_BillMouF_BillConfirmID=?, F_BillMouM_MouID=?";
$insert_mou = $this->db_onedev->query($querymou,array(
$billID,
$v['M_MouID'],
$userid,
$billID,
$v['M_MouID']
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function savebillmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_mou
(F_BillMouF_BillConfirmID,
F_BillMouM_MouID,
F_BillMouUserID,
F_BillMouCreated,
F_BillMouLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['M_MouID'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillConfirmIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillConfirmID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_confirm_detail SET
F_BillConfirmDetailIsActive = 'N',
F_BillConfirmDetailUserID = '{$userid}'
WHERE
F_BillConfirmDetailF_BillConfirmID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_confirm SET
F_BillConfirmIsActive = 'N',
F_BillConfirmUserID = '{$userid}'
WHERE
F_BillConfirmF_BillConfirmID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function notifbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_confirm SET
F_BillConfirmIsNotif = 'Y',
F_BillConfirmNotifUserID = '{$userid}',
F_BillConfirmNotifDate = now()
WHERE
F_BillConfirmF_BillConfirmID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function sendbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_confirm SET
F_BillConfirmIsSend = 'Y',
F_BillConfirmSendUserID = '{$userid}',
F_BillConfirmSendDate = now()
WHERE
F_BillConfirmF_BillConfirmID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_confirm_detail SET
F_BillConfirmDetailIsActive = 'N',
F_BillConfirmDetailUserID = '{$userid}'
WHERE
F_BillConfirmDetailID = '{$prm['F_BillConfirmDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//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("test rows",$this->db_onedev);
exit;
}
}
public function upload()
{
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$inp = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$receive_date = date('Y-m-d H:i:s',strtotime($prm['rdate']));
$home_dir = "/home/one/project/one/";
$target_dir = $home_dir . "one-media/one-photo/";
if (!file_exists($target_dir)) {
mkdir($target_dir, 0755, true);
}
$filename = date("YmdHis")."_".$inp['billNo'] . ".jpg";
$target_path = $target_dir . $filename;
$this->base64_to_jpeg($inp['img'], $target_path);
$sql = "UPDATE f_bill_confirm SET F_BillConfirmImg = '{$filename}',
F_BillConfirmIsReceive = 'Y',
F_BillConfirmReceiveDate = '{$inp['rtanggal']}',
F_BillConfirmReceiveUserID = {$userid}
WHERE F_BillConfirmID = {$inp['idx']}";
//echo $sql;
$save = $this->db_onedev->query($sql);
$sqlbill = "UPDATE f_bill SET F_BillDueDate = '{$inp['sdate']}'
WHERE F_BillConfirmID = {$inp['idbill']}";
//echo $sqlbill;
$savebill = $this->db_onedev->query($sqlbill);
$sqllog = "INSERT INTO f_bill_receive_log (F_BillReceiveLogF_BillConfirmID,
F_BillReceiveLogDate,
F_BillReceiveLogImg,
F_BillReceiveLogUserID,
F_BillReceiveLogCreated,
F_BillReceiveLogLastUpdated)
VALUES
({$inp['idx']},
'{$inp['rtanggal']}',
'{$filename}',
{$userid},
now(),
now())";
//echo $sqllog;
$savelog = $this->db_onedev->query($sqllog);
$result = array("url" => "http://" . $_SERVER['SERVER_NAME'] . "/one-media/one-photo/" . $filename. "?d=" . date("YmdHis"));
$this->sys_ok($result);
exit;
}
public function uploadsend()
{
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$inp = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$receive_date = date('Y-m-d H:i:s',strtotime($prm['rdate']));
$home_dir = "/home/one/project/one/";
$target_dir = $home_dir . "one-media/one-photo/";
if (!file_exists($target_dir)) {
mkdir($target_dir, 0755, true);
}
$filename = date("YmdHis")."_".$inp['billNo'] . "_send.jpg";
$target_path = $target_dir . $filename;
$this->base64_to_jpeg($inp['img'], $target_path);
$sql = "UPDATE f_bill_confirm SET F_BillConfirmImgSend = '{$filename}',
F_BillConfirmSendUserID = {$userid}
WHERE F_BillConfirmID = {$inp['idx']}";
//echo $sql;
$save = $this->db_onedev->query($sql);
$result = array("url" => "http://" . $_SERVER['SERVER_NAME'] . "/one-media/one-photo/" . $filename. "?d=" . date("YmdHis"));
$this->sys_ok($result);
exit;
}
function base64_to_jpeg($base64_string, $output_file) {
// open the output file for writing
$ifp = fopen( $output_file, 'wb' );
// split the string on commas
// $data[ 0 ] == "data:image/png;base64"
// $data[ 1 ] == <actual base64 string>
$data = explode( ',', $base64_string );
// we could add validation here with ensuring count( $data ) > 1
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
// clean up the file resource
fclose( $ifp );
return $output_file;
}
}