1422 lines
54 KiB
PHP
1422 lines
54 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;
|
|
}
|
|
$corporate = $prm["corporate"];
|
|
$pasien = $prm["pasien"];
|
|
$bill = $prm["bill"];
|
|
|
|
$sql_where = "WHERE T_OrderHeaderIsActive = 'Y'";
|
|
$sql_param = array();
|
|
if ($pasien != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " concat(T_OrderHeaderLabNumber, ' ',M_PatientName) like ? ";
|
|
$sql_param[] = "%$pasien%";
|
|
}
|
|
if ($corporate != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " CONCAT(CorporateName, ' [',CorporateCode,']') like ? ";
|
|
$sql_param[] = "%$corporate%";
|
|
}
|
|
if ($bill != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " F_BillNo like ? ";
|
|
$sql_param[] = "%$bill%";
|
|
}
|
|
$limit = '';
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
$sql = " SELECT count(*) as total
|
|
FROM(SELECT T_OrderHeaderID
|
|
FROM t_orderheader
|
|
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
|
|
left join corporate on T_OrderHeaderCorporateID = CorporateID
|
|
left join f_bill_detail ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID AND F_BillDetailIsActive = 'Y'
|
|
left join f_bill ON F_BillID = F_BillDetailF_BillID AND F_BillIsActive = 'Y'
|
|
left join f_bill_payment ON F_BillID = F_BillPaymentF_BillID AND F_BillPaymentIsActive = 'Y'
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID) a
|
|
";
|
|
$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 T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber,
|
|
T_OrderHeaderM_PatientID,
|
|
M_PatientName,
|
|
JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.patient_fullname')) as pasienname,
|
|
T_OrderHeaderCorporateID,
|
|
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as tgl_order,
|
|
CONCAT(CorporateName, ' [',CorporateCode,']') as CorporateName,
|
|
IFNULL(F_BillNo,'') as no_tagihan,
|
|
GROUP_CONCAT(F_BillPaymentNumber SEPARATOR ',') as no_pelunasan,
|
|
F_BillDetailTotal,
|
|
F_BillDetailUnpaid,
|
|
'N' as haveDetail
|
|
|
|
FROM t_orderheader
|
|
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
|
|
left join corporate on T_OrderHeaderCorporateID = CorporateID
|
|
left join f_bill_detail ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID AND F_BillDetailIsActive = 'Y'
|
|
left join f_bill ON F_BillID = F_BillDetailF_BillID AND F_BillIsActive = 'Y'
|
|
left join f_bill_payment ON F_BillID = F_BillPaymentF_BillID AND F_BillPaymentIsActive = 'Y'
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID
|
|
ORDER BY T_OrderHeaderID 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){
|
|
|
|
}
|
|
}
|
|
|
|
$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 *
|
|
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_BillUserID,
|
|
F_BillCreated
|
|
)
|
|
VALUES(
|
|
`fn_numbering`('INV'),
|
|
'{$prm['noref']}',
|
|
'{$prm['companyid']}',
|
|
'{$prm['day']}',
|
|
'{$pdate}',
|
|
'{$prm['note']}',
|
|
'{$prm['picname']}',
|
|
'{$prm['pichp']}',
|
|
'{$prm['picemail']}',
|
|
'{$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}'
|
|
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"];
|
|
$data_log = [];
|
|
$data_delete_details = [];
|
|
$data_delete_orders = [];
|
|
$headerid = $prm['billID'];
|
|
|
|
$sql = "SELECT * FROM f_bill_detail WHERE F_BillDetailT_OrderHeaderID = {$headerid} AND F_BillDetailIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("f_bill_detail select error",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$data_bill_details = $query->result_array();
|
|
|
|
if(count($data_bill_details) > 0){
|
|
$this->sys_error("Nomor lab sudah dibuat tagihan, tidak bisa dihapus");
|
|
exit;
|
|
}
|
|
|
|
// Batch update approach for better performance
|
|
$test_details_PR_PN = [];
|
|
$test_details_PX = [];
|
|
$order_details_PX = [];
|
|
|
|
$this->db_onedev->trans_begin();
|
|
|
|
foreach($prm["data_delete"] as $p) {
|
|
$sql = "UPDATE t_orderdetail SET
|
|
T_OrderDetailIsActive = 'N',
|
|
T_OrderDetailDeletedUserID = $userid,
|
|
T_OrderDetailDeleted = now()
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$headerid} AND
|
|
T_OrderDetailT_TestSasCode LIKE '{$p["testcode"]}%' AND
|
|
T_OrderDetailIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_orderdetail update",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$data_delete_details[] = $p;
|
|
//echo $sql;
|
|
if($p["tipe"] === 'PX'){
|
|
$sql = "UPDATE t_orderdetailorder SET
|
|
T_OrderDetailOrderIsActive = 'N',
|
|
T_OrderDetailOrderDeletedUserID = $userid,
|
|
T_OrderDetailOrderDeleted = now()
|
|
WHERE
|
|
T_OrderDetailOrderT_OrderHeaderID = {$headerid} AND
|
|
T_OrderDetailOrderT_TestID = {$p['testid']} AND
|
|
T_OrderDetailOrderIsActive = 'Y'";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_orderdetailorder update",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$data_delete_orders[] = $p;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM t_orderdetailorder
|
|
WHERE T_OrderDetailOrderT_OrderHeaderID = {$headerid} AND
|
|
T_OrderDetailOrderIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_orderdetailorder select error",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$data_orders = $query->result_array();
|
|
if(count($data_orders) > 0){
|
|
foreach($data_orders as $key => $v){
|
|
$sql = "SELECT *
|
|
FROM t_orderdetail
|
|
WHERE T_OrderDetailT_OrderHeaderID = {$headerid} AND
|
|
T_OrderDetailT_OrderDetailOrderID = {$v['T_OrderDetailOrderID']} AND
|
|
T_OrderDetailIsActive = 'Y'";
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_orderdetail select error",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$existing_details = $query->result_array();
|
|
if(count($existing_details) == 0){
|
|
$sql = "UPDATE t_orderdetailorder SET
|
|
T_OrderDetailOrderIsActive = 'N',
|
|
T_OrderDetailOrderDeletedUserID = $userid,
|
|
T_OrderDetailOrderDeleted = now()
|
|
WHERE T_OrderDetailOrderID = {$v['T_OrderDetailOrderID']} AND
|
|
T_OrderDetailOrderIsActive = 'Y'";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_orderdetailorder update error",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$data_delete_orders[] = $v;
|
|
}
|
|
}
|
|
}
|
|
$data_log = array(
|
|
"data_delete_details" => $data_delete_details,
|
|
"data_delete_orders" => $data_delete_orders
|
|
);
|
|
|
|
$json_data = json_encode($data_log);
|
|
$sql = "INSERT INTO log_delete_test(
|
|
Log_DeletedTestT_OrderHeaderID,
|
|
Log_DeletedTestJson,
|
|
Log_DeletedTestCreated,
|
|
Log_DeletedTestUserID
|
|
) VALUES (
|
|
{$headerid},
|
|
'$json_data',
|
|
NOW(),
|
|
$userid
|
|
)";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("log_delete_test insert error",$this->db_onedev);
|
|
exit;
|
|
}
|
|
//echo $sql;
|
|
|
|
$sql = "SELECT SUM(T_OrderDetailTotal) as total
|
|
FROM t_orderdetail
|
|
WHERE T_OrderDetailT_OrderHeaderID = {$headerid} AND
|
|
T_OrderDetailIsActive = 'Y' and
|
|
T_OrderDetailT_TestIsPrice = 'Y'
|
|
";
|
|
// echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_orderdetail select error",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$total = $query->row()->total;
|
|
|
|
$sql = "UPDATE t_orderheader SET T_OrderHeaderSubTotal = {$total}, T_OrderHeaderTotal = {$total} WHERE T_OrderHeaderID = {$headerid}";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_orderheader update error",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
|
|
$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;
|
|
$headerid = $prm["id"];
|
|
$sql = "select count(*) tot from t_orderdetailorder where T_OrderDetailOrderT_OrderHeaderID=?";
|
|
$rst = $this->db_onedev->query($sql,array($headerid))->row();
|
|
|
|
|
|
$sql = "SELECT
|
|
'Y' as checx,
|
|
'' as numberingx,
|
|
T_OrderDetailT_TestID as testid,
|
|
T_OrderDetailT_TestName as testname,
|
|
T_OrderDetailT_TestSasCode as testcode,
|
|
T_OrderDetailPrice bruto,
|
|
T_OrderDetailDiscTotal diskon,
|
|
T_OrderDetailTotal total,
|
|
'Y' ispacket,
|
|
'PN' tipe,
|
|
T_OrderDetailID detailid,
|
|
T_OrderDetailOrderID as orderid
|
|
|
|
FROM t_orderdetailorder
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = $headerid AND
|
|
T_OrderDetailT_OrderDetailOrderID = T_OrderDetailOrderID AND T_OrderDetailIsActive = 'Y'
|
|
WHERE T_OrderDetailOrderT_OrderHeaderID = $headerid AND
|
|
T_OrderDetailOrderIsPacket = 'Y' AND
|
|
T_OrderDetailOrderPacketType = 'PN'
|
|
|
|
UNION
|
|
SELECT
|
|
'Y' as checx,
|
|
'' as numberingx,
|
|
T_OrderDetailT_TestID as testid,
|
|
T_OrderDetailT_TestName as testname,
|
|
T_OrderDetailT_TestSasCode as testcode,
|
|
T_OrderDetailPrice bruto,
|
|
T_OrderDetailDiscTotal diskon,
|
|
T_OrderDetailTotal total,
|
|
'Y' ispacket,
|
|
'PR' tipe,
|
|
T_OrderDetailID detailid,
|
|
T_OrderDetailOrderID as orderid
|
|
|
|
FROM t_orderdetailorder
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = $headerid AND
|
|
T_OrderDetailT_OrderDetailOrderID = T_OrderDetailOrderID AND T_OrderDetailT_TestIsPrice = 'Y' AND T_OrderDetailIsActive = 'Y'
|
|
WHERE T_OrderDetailOrderT_OrderHeaderID = $headerid AND
|
|
T_OrderDetailOrderIsPacket = 'Y' AND
|
|
T_OrderDetailOrderPacketType = 'PR'
|
|
|
|
UNION
|
|
SELECT
|
|
'Y' as checx,
|
|
'' as numberingx,
|
|
T_OrderDetailT_TestID as testid,
|
|
T_OrderDetailT_TestName as testname,
|
|
T_OrderDetailT_TestSasCode as testcode,
|
|
T_OrderDetailPrice bruto,
|
|
T_OrderDetailDiscTotal diskon,
|
|
T_OrderDetailTotal total,
|
|
'N' ispacket,
|
|
'PX' tipe,
|
|
T_OrderDetailID detailid,
|
|
T_OrderDetailOrderID as orderid
|
|
|
|
FROM t_orderdetailorder
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = $headerid AND
|
|
T_OrderDetailT_OrderDetailOrderID = T_OrderDetailOrderID AND T_OrderDetailT_TestIsPrice = 'Y' AND T_OrderDetailIsActive = 'Y'
|
|
WHERE T_OrderDetailOrderT_OrderHeaderID = $headerid AND
|
|
T_OrderDetailOrderIsPacket = 'N';
|
|
";
|
|
|
|
//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> </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;
|
|
}
|
|
|
|
}
|