630 lines
18 KiB
PHP
630 lines
18 KiB
PHP
<?php
|
|
|
|
class Payment extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
public function index()
|
|
{
|
|
echo "API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
function getlanguages()
|
|
{
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$query = "SELECT Nat_LangID as id,
|
|
Nat_LangCode as code,
|
|
Nat_LangName as name
|
|
FROM nat_lang WHERE Nat_LangIsActive = 'Y'";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
$this->sys_ok($rows);
|
|
exit;
|
|
}
|
|
|
|
function lookup_type()
|
|
{
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$query = "SELECT M_PaymentTypeID as id,
|
|
M_PaymentTypeCode as code,
|
|
'N' as chex,
|
|
M_PaymentTypeName as chexlabel,
|
|
'Jumlah' as leftlabel,
|
|
'' as selected_card,
|
|
'' as selected_edc,
|
|
'' as selected_account,
|
|
CASE
|
|
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
|
|
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
|
|
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
|
|
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'No. Rekening'
|
|
ELSE 'Nomor Voucher'
|
|
END as rightlabel,
|
|
0 as leftvalue,
|
|
0 as rightvalue
|
|
FROM m_paymenttype WHERE
|
|
M_PaymentTypeIsActive = 'Y' AND
|
|
M_PaymentTypeCode NOT IN ('REGONLINE','DP','RK')";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach ($rows as $k => $v) {
|
|
$rows[$k]['selected_card'] = array('id' => 0, 'name' => '');
|
|
$rows[$k]['selected_edc'] = array('id' => 0, 'name' => '');
|
|
if ($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function lookup_banks()
|
|
{
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$query = "SELECT Nat_BankID as id, Nat_BankCode as name
|
|
FROM nat_bank
|
|
WHERE
|
|
Nat_BankIsActive = 'Y'
|
|
ORDER BY Nat_BankCode DESC";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function lookup_accounts()
|
|
{
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$query = "SELECT M_BankAccountID as id, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name
|
|
FROM m_bank_account
|
|
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
|
|
WHERE
|
|
M_BankAccountIsActive = 'Y'
|
|
ORDER BY Nat_BankCode DESC";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
function searchcard()
|
|
{
|
|
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
|
|
if ($prm['search'] != '') {
|
|
$sql = "
|
|
SELECT count(*) as total
|
|
FROM nat_bank
|
|
WHERE
|
|
Nat_BankName like ?
|
|
AND Nat_BankIsActive = 'Y'
|
|
ORDER BY Nat_BankName DESC
|
|
";
|
|
} else {
|
|
$sql = "
|
|
SELECT count(*) as total
|
|
FROM nat_bank
|
|
WHERE
|
|
Nat_BankIsActive = 'Y'
|
|
ORDER BY Nat_BankName DESC
|
|
";
|
|
}
|
|
$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_city count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
if ($prm['search'] != '') {
|
|
$sql = "
|
|
SELECT Nat_BankID as id, Nat_BankName as name
|
|
FROM nat_bank
|
|
WHERE
|
|
Nat_BankName like ?
|
|
AND Nat_BankIsActive = 'Y'
|
|
ORDER BY Nat_BankName DESC
|
|
";
|
|
} else {
|
|
$sql = "
|
|
SELECT Nat_BankID as id, Nat_BankName as name
|
|
FROM nat_bank
|
|
WHERE
|
|
Nat_BankIsActive = 'Y'
|
|
ORDER BY Nat_BankName 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_city rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
function pay()
|
|
{
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$patient = $prm['patient'];
|
|
$payments = $prm['payment'];
|
|
|
|
$sql_sel_m = "SELECT MemberID,
|
|
MemberNumber,
|
|
MemberNIK
|
|
FROM one_pointreward.member
|
|
WHERE (MemberIsActive = 'Y' OR MemberIsActive = 'P')
|
|
AND MemberNIK = ?";
|
|
$qry_sel_m = $this->db_onedev->query($sql_sel_m, [$patient['M_PatientIDNumber']]);
|
|
if (!$qry_sel_m) {
|
|
$this->sys_error_db("select member", $this->db_onedev);
|
|
exit;
|
|
}
|
|
$row_member = $qry_sel_m->result_array();
|
|
if (count($row_member) > 0) {
|
|
$this->sys_error("Pasien dengan NIK : [" . $patient['M_PatientIDNumber'] . "] sudah terdaftar di member");
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql_check_pat = "SELECT M_PatientNatVerifID,
|
|
M_PatientNatVerifDate,
|
|
M_PatientNatVerifM_PatientID,
|
|
M_PatientNatVerifUsername,
|
|
M_PatientNatVerifBranchCode
|
|
FROM m_patient_nat_verif
|
|
WHERE M_PatientNatVerifIsActive = 'Y'
|
|
AND M_PatientNatVerifM_PatientID = ?";
|
|
$qry_check_pat = $this->db_onedev->query($sql_check_pat, [$patient['M_PatientID']]);
|
|
if ($qry_check_pat) {
|
|
$row = $qry_check_pat->result_array();
|
|
} else {
|
|
$this->sys_error_db("select m_patient_nat_verif", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
// print_r(count($row));
|
|
// exit;
|
|
|
|
if (count($row) > 0) {
|
|
$sql_national = "SELECT
|
|
MemberID,
|
|
MemberNumber,
|
|
MemberM_BrachCode,
|
|
MemberNIK,
|
|
MemberTransactionType,
|
|
MemberType
|
|
FROM one_pointreward.member_national
|
|
WHERE MemberIsActive = 'Y'
|
|
AND MemberNIK = ?";
|
|
$qry_national = $this->db_onedev->query($sql_national, [$patient['M_PatientIDNumber']]);
|
|
if ($qry_national) {
|
|
$data = $qry_national->result_array();
|
|
} else {
|
|
$this->sys_error_db("select member_national", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
// print_r(count($data));
|
|
// exit;
|
|
|
|
if (count($data) == 0) {
|
|
$sql_branch = "SELECT M_BranchID, M_BranchCode, M_BranchName
|
|
FROM m_branch
|
|
WHERE M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
|
$qry_branch = $this->db_onedev->query($sql_branch);
|
|
if ($qry_branch) {
|
|
$branchcode = $qry_branch->row()->M_BranchCode;
|
|
$branchname = $qry_branch->row()->M_BranchName;
|
|
} else {
|
|
$this->sys_error_db("select m_branch", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$dateYear = date('y');
|
|
$xnumber = $branchcode . $dateYear . '-' . $patient['M_PatientNoReg'];
|
|
|
|
// $xnumber = $this->db_onedev->query("SELECT one_pointreward.`fn_numbering_member`('M','{$patient['M_PatientIDNumber']}', '{$branchcode}') as numberx")->row()->numberx;
|
|
// $membername = $this->db_onedev->query("SELECT JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute({$patient['M_PatientID']}),'$.patient_fullname')) as membername")->row()->membername;
|
|
|
|
|
|
$sql = "INSERT INTO one_pointreward.member(
|
|
MemberNumber,
|
|
MemberName,
|
|
MemberM_PatientID,
|
|
MemberM_BrachCode,
|
|
MemberM_BrachName,
|
|
MemberNIK,
|
|
MemberHp,
|
|
MemberTransactionType,
|
|
MemberType,
|
|
MemberStartDate,
|
|
MemberEndDate,
|
|
MemberDateCountVisit,
|
|
MemberDateCountPoint,
|
|
MemberNote,
|
|
MemberIsActive,
|
|
MemberUserID,
|
|
MemberCreated)
|
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
|
$query = $this->db_onedev->query(
|
|
$sql,
|
|
array(
|
|
$xnumber,
|
|
$patient['M_PatientName'],
|
|
$patient['M_PatientID'],
|
|
$branchcode,
|
|
$branchname,
|
|
$patient['M_PatientIDNumber'],
|
|
$patient['M_PatientHP'],
|
|
$prm['type_trx'],
|
|
$prm['type_member'],
|
|
$prm['startdate'],
|
|
$prm['enddate'],
|
|
$prm['startkedatangan'],
|
|
$prm['startpoint'],
|
|
$prm['note_member_exist'],
|
|
$prm['status_approve'],
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("member insert");
|
|
exit;
|
|
}
|
|
|
|
$memberID = $this->db_onedev->insert_id();
|
|
|
|
$paynumber = $this->db_onedev->query("SELECT one_pointreward.`fn_numbering_pointreward`('PM') as numberx")->row()->numberx;
|
|
|
|
$sql = "INSERT INTO one_pointreward.member_payment(
|
|
MemberPaymentMemberID,
|
|
MemberPaymentDate,
|
|
MemberPaymentNumber,
|
|
MemberPaymentNote,
|
|
MemberPaymentTotal,
|
|
MemberPaymentUserID,
|
|
MemberPaymentCreated
|
|
) VALUES
|
|
(?,NOW(),?,?,?,?,NOW())";
|
|
$query = $this->db_onedev->query(
|
|
$sql,
|
|
array(
|
|
$memberID,
|
|
$paynumber,
|
|
'',
|
|
$prm['total_payment'],
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("member_payment insert");
|
|
exit;
|
|
}
|
|
|
|
$headerid = $this->db_onedev->insert_id();
|
|
$total = 0;
|
|
foreach ($payments as $k => $v) {
|
|
if ($v['chex']) {
|
|
$actual = 0;
|
|
$change = 0;
|
|
$amount = $v['leftvalue'];
|
|
if ($v['code'] == 'CASH') {
|
|
$actual = $v['leftvalue'];
|
|
$change = $v['rightvalue'];
|
|
if ($actual > 0) {
|
|
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
|
|
} else {
|
|
$amount = $actual;
|
|
}
|
|
$total = $total + $amount;
|
|
$sql = "INSERT INTO one_pointreward.member_paymentdetail(
|
|
MemberPaymentDetailMemberPaymentID,
|
|
MemberPaymentDetailM_PaymentTypeID,
|
|
MemberPaymentDetailAmount,
|
|
MemberPaymentDetailActual,
|
|
MemberPaymentDetailChange,
|
|
MemberPaymentDetailCreated,
|
|
MemberPaymentDetailLastUpdated,
|
|
MemberPaymentDetailUserID)
|
|
VALUES (
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
now(),
|
|
now(),
|
|
?
|
|
)";
|
|
//echo $sql;
|
|
|
|
$query = $this->db_onedev->query(
|
|
$sql,
|
|
array(
|
|
$headerid,
|
|
$v['id'],
|
|
$amount,
|
|
$actual,
|
|
$change,
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("member_paymentdetail cash insert");
|
|
echo $this->db_onedev->last_query();
|
|
exit;
|
|
}
|
|
} else {
|
|
//if(intval($v['leftvalue']) > 0){
|
|
$actual = 0;
|
|
$change = 0;
|
|
$amount = $v['leftvalue'];
|
|
$selected_card = 0;
|
|
$selected_edc = 0;
|
|
$selected_account = 0;
|
|
if ($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER') {
|
|
$selected_card = $v['selected_card']['id'];
|
|
$selected_edc = $v['selected_edc']['id'];
|
|
if ($v['code'] == 'TRANSFER')
|
|
$selected_edc = $v['selected_account']['id'];
|
|
}
|
|
$total = $total + $amount;
|
|
$sql = "INSERT INTO one_pointreward.member_paymentdetail(
|
|
MemberPaymentDetailMemberPaymentID,
|
|
MemberPaymentDetailM_PaymentTypeID,
|
|
MemberPaymentDetailAmount,
|
|
MemberPaymentDetailActual,
|
|
MemberPaymentDetailChange,
|
|
MemberPaymentDetailCardNat_BankID,
|
|
MemberPaymentDetailEDCNat_BankID,
|
|
MemberPaymentDetailM_BankAccountID,
|
|
MemberPaymentDetailCreated,
|
|
MemberPaymentDetailLastUpdated,
|
|
MemberPaymentDetailUserID)
|
|
VALUES (
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
now(),
|
|
now(),
|
|
?
|
|
)";
|
|
//echo $sql;
|
|
|
|
$query = $this->db_onedev->query(
|
|
$sql,
|
|
array(
|
|
$headerid,
|
|
$v['id'],
|
|
$amount,
|
|
$actual,
|
|
$change,
|
|
$selected_card,
|
|
0,
|
|
$selected_edc,
|
|
$xuserid
|
|
)
|
|
);
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$this->sys_error_db("member_paymentdetail non cash insert");
|
|
exit;
|
|
}
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$this->sys_error("Pasien dengan NIK : [" . $patient['M_PatientIDNumber'] . "] sudah terdaftar di member nasional");
|
|
exit;
|
|
}
|
|
} else {
|
|
$this->sys_error("<p>Pasien <b>" . $patient['M_PatientName'] . "</b> belum di verif nasional...</p><p>Silahkan verif pasien dulu</p>");
|
|
exit;
|
|
}
|
|
|
|
/*$sql = "UPDATE one_pointreward.member_payment SET MemberPaymentTotal = ? WHERE MemberPaymentID = ?";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,array($total,$headerid));
|
|
if (!$query) {
|
|
$this->sys_error_db("f_payment update total");
|
|
exit;
|
|
} */
|
|
|
|
$result = array(
|
|
"records" => array("data" => array("numberx" => $xnumber))
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function delete_note()
|
|
{
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$prmnota = $prm['nota'];
|
|
$catatan = $prm['catatan'];
|
|
$sql = "UPDATE f_payment SET F_PaymentIsActive = 'N', F_PaymentNote = '{$catatan}' WHERE F_PaymentID = {$prmnota['note_id']}";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("f_payment delete");
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE f_paymentdetail SET F_PaymentDetailIsActive = 'N' WHERE F_PaymentDetailF_PaymentID = {$prmnota['note_id']}";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("f_paymentdetail delete");
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('prm' => $prm)
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function getLocations()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$station_location = [];
|
|
$locations = [];
|
|
$sql = "SELECT T_OrderDetailT_OrderHeaderID as order_id, T_SampleStationID as station_id, T_SampleStationName as station_name,
|
|
fn_get_location(T_SampleStationID,T_OrderDetailT_OrderHeaderID) as location_id, '' locations
|
|
FROM (
|
|
SELECT distinct T_OrderDetailT_OrderHeaderID,T_SampleStationID, T_SampleStationName
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_SampleTypeID = T_TestT_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID
|
|
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
|
|
|
|
) x";
|
|
$query = $this->db_onedev->query($sql, array($prm['order_id']));
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$datas = $query->result_array();
|
|
foreach ($datas as $key => $value) {
|
|
$sql = "SELECT M_LocationID as location_id, M_LocationName as location_name FROM m_location WHERE M_LocationT_SampleStationID = ? AND M_LocationIsActive = 'Y' ";
|
|
$query = $this->db_onedev->query($sql, array($value['station_id']));
|
|
if ($query) {
|
|
$datas[$key]['locations'] = $query->result_array();
|
|
} else {
|
|
$datas[$key]['locations'] = [];
|
|
}
|
|
}
|
|
$this->sys_ok(["datas" => $datas]);
|
|
} else {
|
|
echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("gagal ambil data", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function save_control()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
if ($prm['data'] && count($prm['data']) > 0) {
|
|
foreach ($prm['data'] as $key => $value) {
|
|
$sql = "INSERT INTO t_order_location (
|
|
T_OrderLocationT_OrderHeaderID,
|
|
T_OrderLocationM_LocationID,
|
|
T_OrderLocationT_SampleStationID,
|
|
T_OrderLocationCreated,
|
|
T_OrderLocationLastUpdated,
|
|
T_OrderLocationUserID
|
|
)
|
|
VALUES (?,?,?,NOW(),NOW(),?)
|
|
ON DUPLICATE KEY
|
|
UPDATE T_OrderLocationT_OrderHeaderID = ?,
|
|
T_OrderLocationM_LocationID = ?,
|
|
T_OrderLocationT_SampleStationID = ?,
|
|
T_OrderLocationLastUpdated = NOW(),
|
|
T_OrderLocationUserID = ?";
|
|
$query = $this->db_onedev->query($sql, array($value['order_id'], $value['location_id'], $value['station_id'], $userid, $value['order_id'], $value['location_id'], $value['station_id'], $userid));
|
|
}
|
|
$this->sys_ok(["datas" => '']);
|
|
} else {
|
|
$this->sys_error_db("data not valid", $this->db_onedev);
|
|
exit;
|
|
}
|
|
//echo $sql;
|
|
|
|
|
|
}
|
|
}
|