333 lines
12 KiB
PHP
333 lines
12 KiB
PHP
|
|
<?php
|
|
|
|
class Payment extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
public function index()
|
|
{
|
|
echo "Doctor API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function get_order() {
|
|
$prm = $this->sys_input;
|
|
|
|
$rst = ["order_header"=>[], "order_detail"=>[], "order_delivery"=>[]];
|
|
|
|
$sql = "
|
|
select T_OrderHeaderID as order_id,
|
|
T_OrderHeaderLabNumber as order_no,
|
|
T_OrderHeaderDate as order_date,
|
|
T_OrderHeaderSubTotal as order_subtotal,
|
|
T_OrderHeaderRounding as order_rounding,
|
|
T_OrderHeaderTotal as order_total,
|
|
concat(if(M_TitleID is null, '', concat(M_TitleName, ' ')), M_PatientName) as patient_name,
|
|
M_PatientNoReg as patient_mr,
|
|
M_MouName as order_mou,
|
|
M_CompanyName as order_company,
|
|
fn_global_doctor_name(da.M_DoctorID) doctor_sender,
|
|
fn_global_doctor_name(db.M_DoctorID) doctor_pj,
|
|
fn_global_doctor_address(aa.M_DoctorAddressID, 1) doctor_sender_address,
|
|
M_MouIsBill M_CompanyIsBill, M_MouMinDP M_CompanyMinDP,
|
|
M_MouIsAgingOnHold M_CompanyIsAgingOnHold, M_MouIsAgingOnHoldNote M_CompanyIsAgingOnHoldNote
|
|
from t_orderheader
|
|
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
|
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID
|
|
join m_mou on T_OrderHeaderM_MouID = M_MouID
|
|
join m_doctor da on T_OrderHeaderSenderM_DoctorID = da.M_DoctorID
|
|
join m_doctoraddress aa on T_OrderHeaderSenderM_DoctorAddressID = aa.M_DoctorAddressID
|
|
join m_doctor db on T_OrderHeaderSenderM_DoctorID = db.M_DoctorID
|
|
left join m_title on m_patientm_titleid = m_titleid
|
|
where T_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, array($prm['id']));
|
|
if ($query) {
|
|
$rows = (array) $query->row();
|
|
$rst['order_header'] = $rows;
|
|
// $result = array("status" => "OK" , "data" => $rst);
|
|
// $this->sys_ok($result);
|
|
// exit;
|
|
} else {
|
|
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$sql = "CALL sp_fo_payment_get_delivery('{$prm['id']}')";
|
|
$query = $this->db_smartone->query($sql);
|
|
$this->clean_mysqli_connection($this->db_smartone->conn_id);
|
|
|
|
if ($query) {
|
|
$rows = $query->row();
|
|
$rst['order_delivery'] = json_decode($rows->delivery);
|
|
// $result = array("status" => "OK" , "data" => $rst);
|
|
// $this->sys_ok($result);
|
|
// exit;
|
|
} else {
|
|
$this->sys_error_db("m_doctoraddress delivery ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
// { n:1, d_id:1, t_id:1, t_name:'SGOT', t_price:80000, t_disctotal:7000, t_total:73000 },
|
|
// { n:2, d_id:2, t_id:2, t_name:'SGPT', t_price:75000, t_disctotal:8000, t_total:67000 }
|
|
// T_OrderDetailPrice double [0]
|
|
// T_OrderDetailPriceForDisc double [0]
|
|
// T_OrderDetailDisc double [0]
|
|
// T_OrderDetailDiscAmount double [0]
|
|
// T_OrderDetailTotal
|
|
|
|
$sql = "
|
|
select T_OrderDetailID as d_id,
|
|
T_OrderDetailT_TestID as t_id,
|
|
IFNULL(T_OrderDetailT_TestName, T_PacketName) as t_name,
|
|
T_OrderDetailPrice as t_price,
|
|
T_OrderDetailDiscTotal as t_disctotal,
|
|
T_OrderDetailTotal as t_total
|
|
from t_orderdetail
|
|
join t_orderdetailaddon on T_OrderDetailAddOnT_OrderDetailID = T_OrderDetailID
|
|
left join t_test on t_orderdetailt_testid = t_testid
|
|
left join t_packet on t_orderdetailaddonispacket = 'Y' and t_orderdetailaddont_packetid = t_packetid
|
|
where T_OrderDetailT_OrderHeaderID = ?
|
|
and T_ORderDetailIsActive = 'Y'
|
|
and ((T_ORderDetailAddOnIsPacket = 'N' AND T_TestIsPrintNota = 'Y' AND T_OrderDetailT_TestIsPanelChildren = 'N')
|
|
OR (T_OrderDetailT_TestIsPanelChildren = 'Y' AND T_OrderDetailT_TestIsPanelChildrenPrintNota = 'Y')
|
|
OR (T_ORderDetailAddOnIsPacket = 'Y' AND T_PacketIsNOta = 'Y'))";
|
|
|
|
$query = $this->db_smartone->query($sql, array($prm['id']));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$rst['order_detail'] = $rows;
|
|
|
|
$result = array("status" => "OK" , "data" => $rst);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} else {
|
|
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 100;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select count(*) total
|
|
from
|
|
m_paymenttype
|
|
where M_PaymentTypeIsActive = 'Y'
|
|
and M_PaymentTypeName like ?";
|
|
$query = $this->db_smartone->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_paymenttype count",$this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select M_PaymentTypeID payment_type_id, M_PaymentTypeName payment_type_name, M_PaymentTypeCode payment_type_code,
|
|
0 payment_amount, '' payment_note, 'Nomor Kartu' payment_note_label, 'N' payment_enable,
|
|
0 payment_change, 0 payment_actual, 0 payment_card_id, 0 payment_edc_id, 0 payment_account_id
|
|
from m_paymenttype
|
|
where M_PaymentTypeIsActive = 'Y'
|
|
and M_PaymentTypeName like ?";
|
|
$query = $this->db_smartone->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
foreach($rows as $k => $v) {
|
|
|
|
if ($v['payment_type_code'] == 'CASH')
|
|
$v['payment_note_label'] = 'Kembali';
|
|
if ($v['payment_type_code'] == 'VOUCHER')
|
|
$v['payment_note_label'] = 'Nomor Voucher';
|
|
|
|
$rows[$k] = $v;
|
|
}
|
|
|
|
$result = $rows;
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_paymenttype rows",$this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function save()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$payment_json = json_encode($prm['payments']);
|
|
|
|
//$sql = "CALL sp_fo_payment('{$prm['order_id']}', '{$payment_json}', '{$this->sys_user['M_UserID']}');";
|
|
$sql ="INSERT INTO future_downpayment (
|
|
FutureDownpaymentFutureOrderID,
|
|
FutureDownpaymentF_PaymentDate,
|
|
FutureDownpaymentNumber,
|
|
FutureDownpaymentUserID,
|
|
FutureDownpaymentLastUpdate
|
|
)
|
|
VALUES(
|
|
{$prm['order_id']},
|
|
CURDATE(),
|
|
fn_numbering_future('PFO'),
|
|
{$this->sys_user['M_UserID']},
|
|
NOW()
|
|
)";
|
|
$query = $this->db_smartone->query($sql);
|
|
|
|
if ($query)
|
|
{
|
|
$header_id = $this->db_smartone->insert_id();
|
|
$sql = "SELECT * FROM future_downpayment WHERE FutureDownpaymentID = {$header_id} ";
|
|
//echo $sql;
|
|
$data_header = $this->db_smartone->query($sql)->row_array();
|
|
|
|
if($prm['payments'] && count($prm['payments']) > 0){
|
|
foreach($prm['payments'] as $k => $v){
|
|
$sql = "INSERT INTO future_downpayment_detail (
|
|
FutureDownpaymentDetailFutureDownpaymentID,
|
|
FutureDownpaymentDetailM_PaymentTypeID,
|
|
FutureDownpaymentDetailEDCNat_BankID,
|
|
FutureDownpaymentDetailCardNat_BankID,
|
|
FutureDownpaymentDetailM_BankAccountID,
|
|
FutureDownpaymentDetailAmount,
|
|
FutureDownpaymentDetailActual,
|
|
FutureDownpaymentDetailChange,
|
|
FutureDownpaymentDetailLastUpdated,
|
|
FutureDownpaymentDetailUserID
|
|
)
|
|
VALUES(
|
|
{$header_id},
|
|
{$v['type']},
|
|
{$v['edc']},
|
|
{$v['card']},
|
|
{$v['account']},
|
|
{$v['amount']},
|
|
{$v['actual']},
|
|
{$v['changes']},
|
|
NOW(),
|
|
{$this->sys_user['M_UserID']}
|
|
)";
|
|
$this->db_smartone->query($sql);
|
|
}
|
|
}
|
|
|
|
$arr_dtx = array(
|
|
'order_id'=>$prm['order_id'],
|
|
'payment_id'=>$data_header['FutureDownpaymentID'],
|
|
'payment_number'=>$data_header['FutureDownpaymentNumber']
|
|
);
|
|
$rst['data'] = $arr_dtx;
|
|
echo json_encode($rst);
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error_db("save payment", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function endshowtime()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$sql = "UPDATE future_order SET
|
|
FutureOrderTimeStart = '{$prm['time_start']}',
|
|
FutureOrderFoTimeEnd = NOW()
|
|
WHERE
|
|
FutureOrderID = {$prm['order_id']}";
|
|
$query = $this->db_smartone->query($sql);
|
|
|
|
if ($query)
|
|
{
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array()
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error_db("save payment", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_bank()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
if (isset($prm['card']))
|
|
{
|
|
$sql = "SELECT Nat_BankID, Nat_BankName
|
|
FROM nat_bank WHERE Nat_BankIsCard = 'Y' ORDER BY Nat_BankName ASC";
|
|
$query = $this->db_smartone->query($sql);
|
|
}
|
|
else if (isset($prm['edc']))
|
|
{
|
|
$sql = "SELECT Nat_BankID, Nat_BankName
|
|
FROM nat_bank WHERE Nat_BankIsEDC = 'Y' ORDER BY Nat_BankName ASC";
|
|
$query = $this->db_smartone->query($sql);
|
|
}
|
|
else
|
|
{
|
|
$sql = "SELECT Nat_BankID, Nat_BankName
|
|
FROM nat_bank ORDER BY Nat_BankName ASC";
|
|
$query = $this->db_smartone->query($sql);
|
|
}
|
|
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
$this->sys_ok(["records"=>$rows, "total"=>sizeof($rows), "q"=>$this->db_smartone->last_query()]);
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error_db("NAT BANK",$this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/*function endshowtime()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$sql = "UPDATE t_orderheaderaddon SET
|
|
T_OrderHeaderAddonFoTimeStart = {$prm['time_start']},
|
|
T_OrderHeaderAddonFoTimeEnd = NOW()
|
|
WHERE
|
|
T_OrderHeaderAddOnT_OrderHeaderID = {$prm['order_id']}";
|
|
|
|
$query = $this->db_smartone->query($sql);
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
$this->sys_ok(["records"=>array(), "total"=>sizeof($rows), "q"=>'');
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error_db("NAT BANK",$this->db_smartone);
|
|
exit;
|
|
}
|
|
}*/
|
|
}
|