1455 lines
57 KiB
PHP
1455 lines
57 KiB
PHP
<?php
|
|
class Billissuev5 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_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}'";
|
|
$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_BillIssueRefNumber) like ? ";
|
|
$sql_param[] = "%$norm%";
|
|
}
|
|
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
$sql = " SELECT count(*) as total
|
|
FROM f_bill
|
|
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
|
|
left join m_company on F_BillM_CompanyID = M_CompanyID
|
|
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID
|
|
$sql_where
|
|
";
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$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("order_patient count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT
|
|
F_BillID,
|
|
F_BillNo,
|
|
f_bill_issue.*,
|
|
F_BillM_MouID,
|
|
M_MouID,
|
|
M_MouName,
|
|
F_BillDueDateDay,
|
|
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate ,
|
|
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
|
|
F_BillTotal,
|
|
F_BillUnpaid,
|
|
F_BillReceive ,
|
|
F_BillIsLunas ,
|
|
F_BillIsClosed ,
|
|
DATE_FORMAT(F_BillCreated,'%d-%m-%Y') as F_BillCreated,
|
|
DATE_FORMAT(F_BillIssueReceiveDate,'%d-%m-%Y') as penerimaan,
|
|
F_BillUserID ,
|
|
F_BillNote,
|
|
M_CompanyID,
|
|
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
|
|
IF(F_BillIssueIsAllMou = 'Y', 'Semua',CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y'))) as descmou,
|
|
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
|
|
DATE_FORMAT(F_BillIssueReceiveDate,'%d-%m-%Y %H:%i') as F_BillIssueReceiveDate,
|
|
DATE_FORMAT(F_BillIssueReceiveDate,'%d-%m-%Y %H:%i') as receive_date,
|
|
DATE_FORMAT(F_BillIssueSendDate,'%d-%m-%Y %H:%i') as send_date,
|
|
M_BankAccountID,
|
|
CONCAT(Nat_BankName, ' [ ',M_BankAccountNo,' | ',IFNULL(M_BankAccountName,''),' ]') as M_BankAccountName,
|
|
DATE_FORMAT(F_BillIssueReceiveDate,'%Y-%m-%d') as r_date,
|
|
DATE_FORMAT(F_BillCreated,'%Y-%m-%d') as c_date
|
|
|
|
FROM f_bill
|
|
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
|
|
left join m_company on F_BillM_CompanyID = M_CompanyID
|
|
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID
|
|
LEFT JOIN m_bank_account ON M_BankAccountID = F_BillIssueM_BankAccountID
|
|
LEFT join nat_bank on Nat_BankID = M_BankAccountNat_BankID
|
|
$sql_where
|
|
ORDER BY F_BillNo DESC
|
|
limit $number_limit offset $number_offset ";
|
|
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
if($v['F_BillIssueImg']){
|
|
$rows[$k]['F_BillIssueImg'] = "/one-media/one-photo/" . $v['F_BillIssueImg']. "?d=" . date("YmdHis");
|
|
}
|
|
if($v['F_BillIssueImgSend']){
|
|
$rows[$k]['F_BillIssueImgSend'] = "/one-media/one-photo/" . $v['F_BillIssueImgSend']. "?d=" . date("YmdHis");
|
|
}
|
|
|
|
$x = $this->db_onedev->query("
|
|
select count(*) as tot
|
|
FROM f_bill_detail
|
|
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
|
|
if($x->tot == 0 ) {
|
|
if($v['F_BillIssueIsAllMou'] == 'Y'){
|
|
$mouID = 0;
|
|
}else{
|
|
$mouID = $v['F_BillM_MouID'];
|
|
}
|
|
|
|
$startdate = $this->db_onedev->query("
|
|
select MIN(date(T_OrderHeaderDate)) as startdate
|
|
FROM t_orderheader
|
|
join f_bill on F_BillID = '{$v['F_BillID']}'
|
|
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID
|
|
left join m_company ON F_BillM_CompanyID = M_CompanyID
|
|
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = '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();
|
|
$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_detail
|
|
join t_orderheader ON F_BillDetailT_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_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
|
|
$rows[$k]['haveDetail'] = "Y";
|
|
$rows[$k]['startdate'] = $startdate->startdate;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
$result = array("total" => $tot_page, "total_filter" => count($rows), "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 getpublicholiday(){
|
|
$prm = $this->sys_input;
|
|
$startdate = $prm['startdate'];
|
|
$enddate = $prm['enddate'];
|
|
$dueday = $prm['dueday'];
|
|
|
|
$query ="SELECT COUNT(*) as xtotal
|
|
FROM public_holidays
|
|
WHERE is_active = 'Y' AND
|
|
holiday_date BETWEEN '{$startdate}' AND '{$enddate}'
|
|
ORDER BY holiday_date ASC";
|
|
//echo $query;
|
|
$total = $this->db_onedev->query($query)->row()->xtotal;
|
|
|
|
$dueDate = new DateTime($enddate);
|
|
$dueDate->modify("+{$total} days");
|
|
|
|
while ($this->isHoliday($dueDate)) {
|
|
// Jika jatuh pada hari libur, tambahkan 1 hari
|
|
$dueDate->modify('+1 day');
|
|
}
|
|
|
|
$result = array("total" => $total,"duedate" => $dueDate->format('Y-m-d'));
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function getisholiday(){
|
|
$prm = $this->sys_input;
|
|
$startdate = $prm['startdate'];
|
|
$duedate = $prm['duedate'];
|
|
|
|
$isholiday = 0;
|
|
$isholiday = $this->isHoliday(new DateTime($duedate));
|
|
|
|
$query ="SELECT COUNT(*) as xtotal
|
|
FROM public_holidays
|
|
WHERE is_active = 'Y' AND
|
|
holiday_date BETWEEN '{$startdate}' AND '{$duedate}'";
|
|
//echo $query;
|
|
$total = $this->db_onedev->query($query)->row()->xtotal;
|
|
|
|
$result = array("total" => $total,"isholiday" => $isholiday,"duedate" => $duedate);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function getNonHolidayDueDate($startDate, $days) {
|
|
// Convert string start date to DateTime object
|
|
$dueDate = new DateTime($startDate);
|
|
// Tambahkan jumlah hari yang diminta
|
|
$dueDate->modify("+{$days} days");
|
|
|
|
// Cek apakah tanggal jatuh tempo ada di tabel public_holidays
|
|
while ($this->isHoliday($dueDate)) {
|
|
// Jika jatuh pada hari libur, tambahkan 1 hari
|
|
$dueDate->modify('+1 day');
|
|
}
|
|
|
|
// Kembalikan tanggal jatuh tempo yang valid
|
|
echo $dueDate->format('Y-m-d');
|
|
}
|
|
function isHoliday($date) {
|
|
// Formatkan tanggal ke string agar bisa dipakai di query SQL
|
|
$formattedDate = $date->format('Y-m-d');
|
|
|
|
// Query untuk cek apakah tanggal tersebut ada di tabel public_holidays
|
|
$sql ="SELECT *
|
|
FROM public_holidays
|
|
WHERE holiday_date = ?
|
|
AND is_active = 'Y'";
|
|
//echo $query;
|
|
$qry = $this->db_onedev->query($sql, array($formattedDate));
|
|
$rows = $qry->result_array();
|
|
|
|
// Jika ada hasil, maka tanggal tersebut adalah hari libur
|
|
return count($rows) > 0;
|
|
}
|
|
|
|
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 <> 'N' AND M_MouM_CompanyID = ?
|
|
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
|
|
AND M_MouM_BillTypeID = 3
|
|
";
|
|
//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 <> 'N' AND M_MouM_CompanyID = ?
|
|
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
|
|
AND M_MouM_BillTypeID = 3
|
|
";
|
|
//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 (
|
|
F_BillNo,
|
|
F_BillM_CompanyID,
|
|
F_BillM_MouID,
|
|
F_BillDueDateDay,
|
|
F_BillDueDate,
|
|
F_BillNote,
|
|
F_BillUserID,
|
|
F_BillCreated
|
|
)
|
|
VALUES(
|
|
`fn_numbering`('BL'),
|
|
'{$prm['companyid']}',
|
|
'{$prm['mouid']}',
|
|
'{$prm['day']}',
|
|
'{$pdate}',
|
|
'{$prm['note']}',
|
|
'{$userid}',
|
|
NOW()
|
|
)
|
|
";
|
|
// echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
$last_id = $this->db_onedev->insert_id();
|
|
$bquery = "SELECT M_BranchCode as branchcode FROM m_branch WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'";
|
|
$branchcode = $this->db_onedev->query($bquery)->row()->branchcode;
|
|
$query = "SELECT COUNT(*) as exist FROM f_bill_issue JOIN f_bill ON F_BillID = F_BillIssueF_BillID AND F_BillIsActive = 'Y' WHERE F_BillIssueIsActive = 'Y' AND F_BillIssueRefNumber = '{$prm['noref']}'";
|
|
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
|
if($exist_name == 0){
|
|
$queryissue ="INSERT INTO f_bill_issue (
|
|
F_BillIssueNumber,
|
|
F_BillIssueF_BillID,
|
|
F_BillIssueDate,
|
|
F_BillIssuePIC,
|
|
F_BillIssuePICHP,
|
|
F_BillIssuePICEmail,
|
|
F_BillIssueM_CompanyID,
|
|
F_BillIssueM_MouID,
|
|
F_BillIssueAgingDay,
|
|
F_BillIssueRefNumber,
|
|
F_BillIssueUserID,
|
|
F_BillIssueM_BankAccountID,
|
|
F_BillIssueIsAllMou,
|
|
F_BillIssueCreated
|
|
)
|
|
VALUES(
|
|
CONCAT('{$branchcode}','/',`fn_numbering`('BI')),
|
|
'{$last_id}',
|
|
date(now()),
|
|
'{$prm['picname']}',
|
|
'{$prm['pichp']}',
|
|
'{$prm['picemail']}',
|
|
'{$prm['companyid']}',
|
|
'{$prm['mouid']}',
|
|
'{$prm['day']}',
|
|
'{$prm['noref']}',
|
|
'{$userid}',
|
|
'{$prm['bankid']}',
|
|
'{$prm['isallmou']}',
|
|
NOW()
|
|
)
|
|
";
|
|
//echo $queryissue;
|
|
$rowsissue = $this->db_onedev->query($queryissue);
|
|
$lastissue_id = $this->db_onedev->insert_id();
|
|
|
|
$querylog ="
|
|
|
|
";
|
|
if ($prm['img'] !== "") {
|
|
$this->uploadnew($prm['img'],$prm['rtanggal'],$last_id,$lastissue_id,$pdate);
|
|
}
|
|
|
|
|
|
$insert_new_log = $this->db_onedev->query($querylog);
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK'),
|
|
"id" => $last_id
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}else{
|
|
$errors = array();
|
|
if($exist_name != 0){
|
|
array_push($errors,array('field'=>'name','msg'=>'Nomor sudah ada yang pakai dong'));
|
|
}
|
|
|
|
$result = array ("total" => -1,"errors" => $errors, "records" => array('status'=>'ERROR'));
|
|
$this->sys_ok($result);
|
|
}
|
|
}
|
|
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_BillID = $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_issue SET F_BillIssueImg = '{$filename}',
|
|
F_BillIssueIsReceive = 'Y',
|
|
F_BillIssueReceiveDate = '{$tanggal}',
|
|
F_BillIssueReceiveUserID = {$userid}
|
|
WHERE F_BillIssueID = {$idissue}";
|
|
//echo $sql;
|
|
$save = $this->db_onedev->query($sql);
|
|
|
|
$sqlbill = "UPDATE f_bill SET F_BillDueDate = '{$sdate}'
|
|
WHERE F_BillID = {$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_issue SET
|
|
F_BillIssueM_BankAccountID = '{$prm['bankid']}',
|
|
F_BillIssueUserID = '{$userid}'
|
|
WHERE F_BillIssueF_BillID = '{$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_BillID = '{$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_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
|
|
F_BillDetailTotal, F_BillDetailUnpaid) 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_BillID'];
|
|
if($status == 'Y' && $id == '0'){
|
|
|
|
$sql = "insert into temp_bill(
|
|
Temp_BillF_BillID,
|
|
Temp_BillM_MouID,
|
|
Temp_BillT_OrderHeaderID,
|
|
Temp_BillUserID,
|
|
Temp_BillTotal,
|
|
Temp_BillCreated,
|
|
Temp_BillLastUpdated)
|
|
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 insert",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
}elseif($status == 'N' && $id != '0'){
|
|
$sql = "UPDATE temp_bill SET
|
|
Temp_BillIsActive = 'N',
|
|
Temp_BillUserID = ?
|
|
WHERE Temp_BillID = ?";
|
|
$query = $this->db_onedev->query($sql,
|
|
array($userid,
|
|
$id
|
|
)
|
|
);
|
|
if (!$query) {
|
|
$this->sys_error_db("temp_bill update",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
$sqlsum = "select format(sum(IFNULL(Temp_BillTotal,0)),0) sumtot, count(Temp_BillID) as ctot from temp_bill
|
|
LEFT JOIN f_bill_detail ON F_BillDetailT_OrderHeaderID = Temp_BillT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
|
|
LEFT JOIN f_bill ON F_BillID=F_BillDetailF_BillID AND F_BillIsActive = 'Y'
|
|
where Temp_BillF_BillID=? AND Temp_BillIsActive = 'Y' AND F_BillDetailID 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(
|
|
Temp_BillF_BillID,
|
|
Temp_BillM_MouID,
|
|
Temp_BillT_OrderHeaderID,
|
|
Temp_BillUserID,
|
|
Temp_BillTotal,
|
|
Temp_BillCreated,
|
|
Temp_BillLastUpdated)
|
|
values(?,?,?,?,?,now(),now())";
|
|
$query = $this->db_onedev->query($sql,
|
|
array($billid,
|
|
$mouid,
|
|
$headerid,
|
|
$userid,
|
|
$total)
|
|
);
|
|
if (!$query) {
|
|
$this->sys_error_db("temp_bill insert",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$last_id = $this->db_onedev->insert_id();
|
|
$sqlsum = "select format(sum(IFNULL(Temp_BillTotal,0)),0) sumtot, count(Temp_BillID) as ctot from temp_bill
|
|
LEFT JOIN f_bill_detail ON F_BillDetailT_OrderHeaderID = Temp_BillT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
|
|
LEFT JOIN f_bill ON F_BillID=F_BillDetailF_BillID AND F_BillIsActive = 'Y'
|
|
where Temp_BillF_BillID=? AND Temp_BillIsActive = 'Y' AND F_BillDetailID 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 SET
|
|
Temp_BillIsActive = 'N',
|
|
Temp_BillUserID = ?
|
|
WHERE Temp_BillID = ?";
|
|
$query = $this->db_onedev->query($sql,
|
|
array($userid,
|
|
$id
|
|
)
|
|
);
|
|
if (!$query) {
|
|
$this->sys_error_db("temp_bill update",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$last_id = $this->db_onedev->insert_id();
|
|
$sqlsum = "select format(sum(IFNULL(Temp_BillTotal,0)),0) sumtot, count(Temp_BillID) as ctot from temp_bill
|
|
LEFT JOIN f_bill_detail ON F_BillDetailT_OrderHeaderID = Temp_BillT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
|
|
LEFT JOIN f_bill ON F_BillID=F_BillDetailF_BillID AND F_BillIsActive = 'Y'
|
|
where Temp_BillF_BillID=? AND Temp_BillIsActive = 'Y' AND F_BillDetailID 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_detail where F_BillDetailF_BillID=?";
|
|
$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,
|
|
F_BillDetailTotal 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_detail
|
|
join t_orderheader ON F_BillDetailT_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_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
|
|
GROUP BY F_BillDetailID
|
|
ORDER BY T_OrderHeaderID ASC";
|
|
} else {
|
|
$sql = "SELECT *, IF(F_BillNo IS NULL ,'N','Y') as isbill,
|
|
F_BillNo,
|
|
IF(Temp_BillID = 0 OR F_BillNo IS NOT NULL,'N','Y') as checx,
|
|
IF(Temp_BillID = 0 OR F_BillNo 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_BillID,0) as Temp_BillID
|
|
FROM t_orderheader
|
|
join f_bill on F_BillID = '{$billID}'
|
|
left join m_company ON F_BillM_CompanyID = M_CompanyID
|
|
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = '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 = 3
|
|
left join temp_bill ON Temp_BillF_BillID = F_BillID AND Temp_BillM_MouID = M_MouID AND Temp_BillT_OrderHeaderID = T_OrderHeaderID AND Temp_BillIsActive = '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_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
|
|
LEFT JOIN f_bill ON F_BillDetailF_BillID = F_BillID AND F_BillIsActive = '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_BillTotal,0)),0) sumtot, count(Temp_BillID) as ctot from temp_bill
|
|
LEFT JOIN f_bill_detail ON F_BillDetailT_OrderHeaderID = Temp_BillT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
|
|
LEFT JOIN f_bill ON F_BillID=F_BillDetailF_BillID AND F_BillIsActive = 'Y'
|
|
where Temp_BillF_BillID=? AND Temp_BillIsActive = 'Y' AND F_BillDetailID 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_detail
|
|
(F_BillDetailF_BillID,
|
|
F_BillDetailT_OrderHeaderID,
|
|
F_BillDetailTotal,
|
|
F_BillDetailUnpaid,
|
|
F_BillDetailUserID,
|
|
F_BillDetailCreated,
|
|
F_BillDetailLastUpdated)
|
|
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_BillID,F_BillMouM_MouID,F_BillMouUserID) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE
|
|
F_BillMouF_BillID=?, 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_BillID,
|
|
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_BillIsActive = 'N',
|
|
F_BillUserID = '{$userid}'
|
|
WHERE
|
|
F_BillID = '{$prm['id']}'";
|
|
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
$query ="UPDATE f_bill_detail SET
|
|
F_BillDetailIsActive = 'N',
|
|
F_BillDetailUserID = '{$userid}'
|
|
WHERE
|
|
F_BillDetailF_BillID = '{$prm['id']}'";
|
|
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$query ="UPDATE f_bill_issue SET
|
|
F_BillIssueIsActive = 'N',
|
|
F_BillIssueUserID = '{$userid}'
|
|
WHERE
|
|
F_BillIssueF_BillID = '{$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_issue SET
|
|
F_BillIssueIsNotif = 'Y',
|
|
F_BillIssueNotifUserID = '{$userid}',
|
|
F_BillIssueNotifDate = now()
|
|
WHERE
|
|
F_BillIssueF_BillID = '{$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_issue SET
|
|
F_BillIssueIsSend = 'Y',
|
|
F_BillIssueSendUserID = '{$userid}',
|
|
F_BillIssueSendDate = now()
|
|
WHERE
|
|
F_BillIssueF_BillID = '{$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_detail SET
|
|
F_BillDetailIsActive = 'N',
|
|
F_BillDetailUserID = '{$userid}'
|
|
WHERE
|
|
F_BillDetailID = '{$prm['F_BillDetailID']}'
|
|
";
|
|
//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_issue SET F_BillIssueImg = '{$filename}',
|
|
F_BillIssueIsReceive = 'Y',
|
|
F_BillIssueReceiveDate = '{$inp['rtanggal']}',
|
|
F_BillIssueReceiveUserID = {$userid}
|
|
WHERE F_BillIssueID = {$inp['idx']}";
|
|
//echo $sql;
|
|
$save = $this->db_onedev->query($sql);
|
|
|
|
$sqlbill = "UPDATE f_bill SET F_BillDueDate = '{$inp['sdate']}'
|
|
WHERE F_BillID = {$inp['idbill']}";
|
|
//echo $sqlbill;
|
|
$savebill = $this->db_onedev->query($sqlbill);
|
|
|
|
$sqllog = "INSERT INTO f_bill_receive_log (F_BillReceiveLogF_BillIssueID,
|
|
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_issue SET F_BillIssueImgSend = '{$filename}',
|
|
F_BillIssueSendUserID = {$userid}
|
|
WHERE F_BillIssueID = {$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;
|
|
}
|
|
|
|
}
|