Files
BE_CPONE/application/controllers/mockup/cpone-bill/Bill.php
2026-04-27 10:31:17 +07:00

1349 lines
48 KiB
PHP

<?php
class Bill 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(CorporateName, ' [',CorporateCode,']') like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .= " and ";
}
$sql_where .= " concat(F_BillNo, ' ',F_BillRefNumber) like ? ";
$sql_param[] = "%$norm%";
}
$limit = '';
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = " SELECT count(*) as total
FROM f_bill
left join corporate on F_BillCorporateID = CorporateID
$sql_where
";
$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("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate ,
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
DATE_FORMAT(F_BillCreated,'%d-%m-%Y') as F_BillCreated,
DATE_FORMAT(F_BillReceiveDate,'%d-%m-%Y') as penerimaan,
CorporateID,
CONCAT(CorporateName, ' [',CorporateCode,']') as CorporateName,
'' as M_MouDesc,
DATE_FORMAT(F_BillReceiveDate,'%d-%m-%Y %H:%i') as F_BillReceiveDate,
DATE_FORMAT(F_BillReceiveDate,'%d-%m-%Y %H:%i') as receive_date,
DATE_FORMAT(F_BillNotifDate,'%d-%m-%Y %H:%i') as send_date,
0 M_BankAccountID,
'' as M_BankAccountName,
IFNULL(XEmailOutboxIsSent,'N') as statusnotif
FROM f_bill
left join corporate on F_BillCorporateID = CorporateID
left join x_email_outbox ON XEmailOutboxID = F_BillXEmailOutboxID
$sql_where
ORDER BY F_BillNo DESC
limit $number_limit offset $number_offset";
$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) {
/* if($v['F_BillImg']){
$rows[$k]['F_BillImg'] = "/one-media/one-photo/" . $v['F_BillImg']. "?d=" . date("YmdHis");
}
if($v['F_BillImgSend']){
$rows[$k]['F_BillImgSend'] = "/one-media/one-photo/" . $v['F_BillImgSend']. "?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) {
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM t_orderheader
join f_bill on F_BillID = '{$v['F_BillID']}'
left join corporate ON F_BillCorporateID = CorporateID
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
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderCorporateID = CorporateID AND
F_BILLDetailID 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
left join corporate ON T_OrderHeaderCorporateID = CorporateID
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" => $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 corporate
WHERE
CONCAT(CorporateName, ' [',CorporateCode,']') like ?
AND CorporateIsActive = '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("corporate count", $this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(CorporateName, ' [',CorporateCode,']') as CorporateName
FROM corporate
WHERE
CONCAT(CorporateName, ' [',CorporateCode,']') like ?
AND CorporateIsActive = 'Y'
ORDER BY CorporateName 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("corporate 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 <> 'N' AND M_MouCorporateID = ?
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_MouCorporateID = ?
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 '/birt/run?__report=report/one/fo/rpt_t_009.rptdesign' as t_url, 'DAFTAR SURAT PENAGIHAN' as t_name
UNION SELECT '/birt/run?__report=report/one/mcu/rpt_aplop_tagihan_001.rptdesign' as t_url, 'APLOP TAGIHAN' as t_name
UNION SELECT '/birt/run?__report=report/one/mcu/rpt_handover_tagihan_001.rptdesign' as t_url, 'TANDA TERIMA TAGIHAN' as t_name
UNION SELECT '/birt/run?__report=report/one/mcu/rpt_surat_tagihan_001.rptdesign' as t_url, 'INVOICE SURAT TAGIHAN' as t_name
UNION SELECT '/birt/run?__report=report/one/mcu/rpt_kwitansi_tagihan_001.rptdesign' as t_url, 'KWITANSI TAGIHAN' 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 getsexreg_old()
{
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_BillRefNumber,
F_BillCorporateID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillPIC,
F_BillPICHP,
F_BillPICEmail,
F_BillM_BankAccountID,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('INV'),
'{$prm['noref']}',
'{$prm['companyid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$prm['picname']}',
'{$prm['pichp']}',
'{$prm['picemail']}',
'{$prm['bankid']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
if ($rows) {
$result = array(
"total" => 1,
"records" => array('status' => 'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
} else {
$errors = array();
$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 SET F_BillImg = '{$filename}',
F_BillIsReceive = 'Y',
F_BillReceiveDate = '{$tanggal}',
F_BillReceiveUserID = {$userid}
WHERE F_BillID = {$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 SET
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}',
F_BillM_BankAccountID = '{$prm['bankid']}'
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;
$userid = $this->sys_user["M_UserID"];
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
foreach ($prm["data_insert"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql, array($billID, $orderID, $total, $total));
}
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
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"];
$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
'' as numberingx,
CorporateID, CorporateName,
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,
CONCAT(GROUP_CONCAT(T_OrderDetailOrderT_PacketName SEPARATOR ','),GROUP_CONCAT(T_OrderDetailOrderT_TestName SEPARATOR ',')) as packetname,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
left join t_orderdetailorder ON T_OrderDetailOrderT_OrderHeaderID = T_OrderHeaderID and T_OrderDetailOrderIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
left join corporate ON T_OrderHeaderCorporateID = CorporateID
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,
'' as numberingx,
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
CorporateID, CorporateName,
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,
0 as Temp_BillID,
CONCAT(GROUP_CONCAT(T_OrderDetailOrderT_PacketName SEPARATOR ','),GROUP_CONCAT(T_OrderDetailOrderT_TestName SEPARATOR ',')) as packetname,
Mgm_McuFlagTagihanSebagian,
Mgm_McuID,
IF(SUM(IFNULL(F_PaymentTotal,0)) > 0 AND Mgm_McuFlagTagihanSebagian = 'Y',0,SUM(IFNULL(F_PaymentTotal,0))) as xpay
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join t_orderdetailorder ON T_OrderDetailOrderT_OrderHeaderID = T_OrderHeaderID and T_OrderDetailOrderIsActive = 'Y'
left join corporate ON F_BillCorporateID = CorporateID
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
left join m_title on M_PatientM_TitleID = M_TitleID
JOIN mgm_mcu ON Mgm_McuID = T_OrderHeaderMgm_McuID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderCorporateID = CorporateID
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
AND (T_OrderHeaderLabNumber 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 AND xpay = 0 AND F_BillID IS NULL";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
$idx = 1;
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$rows[$key]['numberingx'] = $idx;
$idx++;
}
}
}
/* $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" => 0,
"ctotal" => 0
);
$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
));
}
$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 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);
$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"];
$pid = $prm['id'];
$XEmailOutboxSubject = 'Info Penagihan';
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$prm['id']}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxAttachment = array();
$rpt = 'https://devcpone.aplikasi.web.id/birt/run?__report=report/one/fo/rpt_t_009.rptdesign&__format=pdf&username=joko@gmail.com&PID=' . $pid;
$attachment = array(
"name" => 'invoice',
"url" => $rpt
);
$XEmailOutboxAttachment = json_encode(array($attachment));
$XEmailOutboxIsHtml = 'Y';
$body = $this->db_onedev->query("SELECT f_bill.*,DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo, CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal, CorporateName
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$prm['id']}'")->row();
$pname = $body->F_BillPIC;
$jatuhtempo = $body->jatuhtempo;
$nominal = $body->nominal;
$terbilang = $this->numberToWords($body->F_BillTotal) . ' rupiah';
$nomor = $body->F_BillNo;
$XEmailOutboxBody = "<h4>Info Penagihan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan dengan data sebagai berikut :</p>
<table>
<tbody>
<td>
<p>Jatuh Tempo</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$jatuhtempo}</p>
</td>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Bersama ini kami lampirkan detail tagihannya.</p>
<p>Demikian pemberitahuan dari kami. Terima kasih</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxAttachment,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?,?)";
$this->db_onedev->query($sql, array($XEmailOutboxSubject, $XEmailOutboxRecipients, $XEmailOutboxAttachment, $XEmailOutboxIsHtml, $XEmailOutboxBody, $XEmailOutboxType));
$last_id = $this->db_onedev->insert_id();
$query = "UPDATE f_bill SET
F_BillIsNotif = 'Y',
F_BillNotifUserID = '{$userid}',
F_BillNotifDate = now(),
F_BillXEmailOutboxID = '{$last_id}'
WHERE
F_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 SET
F_BillIsSend = 'Y',
F_BillNotifUserID = '{$userid}',
F_BillNotifDate = now()
WHERE
F_BillF_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 numberToWords($number)
{
$words = array(
'0' => 'nol',
'1' => 'satu',
'2' => 'dua',
'3' => 'tiga',
'4' => 'empat',
'5' => 'lima',
'6' => 'enam',
'7' => 'tujuh',
'8' => 'delapan',
'9' => 'sembilan',
'10' => 'sepuluh',
'11' => 'sebelas',
'12' => 'dua belas',
'13' => 'tiga belas',
'14' => 'empat belas',
'15' => 'lima belas',
'16' => 'enam belas',
'17' => 'tujuh belas',
'18' => 'delapan belas',
'19' => 'sembilan belas',
'20' => 'dua puluh',
'30' => 'tiga puluh',
'40' => 'empat puluh',
'50' => 'lima puluh',
'60' => 'enam puluh',
'70' => 'tujuh puluh',
'80' => 'delapan puluh',
'90' => 'sembilan puluh',
'100' => 'seratus',
'1000' => 'seribu'
);
if ($number < 21) {
return $words[$number];
} elseif ($number < 100) {
return $words[10 * floor($number / 10)] . (($number % 10 > 0) ? ' ' . $words[$number % 10] : '');
} elseif ($number < 200) {
return 'seratus' . (($number - 100 > 0) ? ' ' . $this->numberToWords($number - 100) : '');
} elseif ($number < 1000) {
return $words[floor($number / 100)] . ' ratus' . (($number % 100 > 0) ? ' ' . $this->numberToWords($number % 100) : '');
} elseif ($number < 2000) {
return 'seribu' . (($number - 1000 > 0) ? ' ' . $this->numberToWords($number - 1000) : '');
} elseif ($number < 1000000) {
return $this->numberToWords(floor($number / 1000)) . ' ribu' . (($number % 1000 > 0) ? ' ' . $this->numberToWords($number % 1000) : '');
} elseif ($number < 1000000000) {
return $this->numberToWords(floor($number / 1000000)) . ' juta' . (($number % 1000000 > 0) ? ' ' . $this->numberToWords($number % 1000000) : '');
} elseif ($number < 1000000000000) {
return $this->numberToWords(floor($number / 1000000000)) . ' miliar' . (($number % 1000000000 > 0) ? ' ' . $this->numberToWords($number % 1000000000) : '');
}
return $number;
}
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;
}
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 SET F_BillImg = '{$filename}',
F_BillIsReceive = 'Y',
F_BillReceiveDate = '{$inp['rtanggal']}',
F_BillReceiveUserID = {$userid}
WHERE F_BillID = {$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_BillID,
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 SET F_BillImgSend = '{$filename}',
F_BillNotifUserID = {$userid}
WHERE F_BillID = {$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;
}
}