1101 lines
29 KiB
PHP
1101 lines
29 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'";
|
|
$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;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$EDC = 'X';
|
|
|
|
if ($prm['edc'] == 'Y') {
|
|
$EDC = 'N';
|
|
} else if ($prm['edc'] == 'N') {
|
|
$EDC = 'Y';
|
|
} else {
|
|
$EDC = 'Y';
|
|
}
|
|
|
|
$query = "SELECT
|
|
M_BankAccountID as id,
|
|
CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name,
|
|
Nat_BankIsEDC
|
|
FROM m_bank_account
|
|
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
|
|
WHERE
|
|
Nat_BankIsEDC <> ?
|
|
AND
|
|
M_BankAccountIsActive = 'Y'
|
|
ORDER BY Nat_BankCode DESC";
|
|
$rows = $this->db_onedev->query($query, $EDC)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function lookup_point()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT
|
|
MemberInfoNasionalNIK,
|
|
MemberInfoNasionalPoint
|
|
FROM one_pointreward.member_infonational
|
|
WHERE MemberInfoNasionalNIK = ?";
|
|
$query = $this->db_onedev->query($sql, array($prm['nik']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$data = array(
|
|
"nik" => $rows[0]['MemberInfoNasionalNIK'] ?? 0,
|
|
"amount" => $rows[0]['MemberInfoNasionalPoint'] ?? 0
|
|
);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $data
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} else {
|
|
$this->sys_error_db("lookup point", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function update_point()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("invalid token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$nik = $prm['nik'];
|
|
$amount_left = $prm['amount_left'];
|
|
|
|
$sql = "UPDATE one_pointreward.member_infonational
|
|
SET MemberInfoNasionalPoint = ?
|
|
WHERE MemberInfoNasionalNIK = ?";
|
|
$query = $this->db_onedev->query($sql, array($amount_left, $nik));
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db('update point', $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$this->lookup_point();
|
|
}
|
|
|
|
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;
|
|
$orderid = $prm['orderid'];
|
|
$payments = $prm['payments'];
|
|
$companyID = $prm['companyid'];
|
|
$mouID = $prm['mouid'];
|
|
|
|
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
|
|
$sql = "INSERT INTO f_payment(F_PaymentT_OrderHeaderID,F_PaymentDate,F_PaymentCreated,F_PaymentM_UserID) VALUES (?,CURDATE(),NOW(),?)";
|
|
$query = $this->db_onedev->query(
|
|
$sql,
|
|
array(
|
|
$orderid,
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("f_payment insert");
|
|
exit;
|
|
}
|
|
$headerid = $this->db_onedev->insert_id();
|
|
|
|
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;
|
|
}
|
|
|
|
$sql = "INSERT INTO f_paymentdetail(
|
|
F_PaymentDetailF_PaymentID,
|
|
F_PaymentDetailM_PaymentTypeID,
|
|
F_PaymentDetailAmount,
|
|
F_PaymentDetailActual,
|
|
F_PaymentDetailChange,
|
|
F_PaymentDetailCreated,
|
|
F_PaymentDetailLastUpdated,
|
|
F_PaymentDetailUserID)
|
|
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("f_paymentdetail cash insert");
|
|
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'];
|
|
}
|
|
$sql = "INSERT INTO f_paymentdetail(
|
|
F_PaymentDetailF_PaymentID,
|
|
F_PaymentDetailM_PaymentTypeID,
|
|
F_PaymentDetailAmount,
|
|
F_PaymentDetailActual,
|
|
F_PaymentDetailChange,
|
|
F_PaymentDetailCardNat_BankID,
|
|
F_PaymentDetailEDCNat_BankID,
|
|
F_PaymentDetailM_BankAccountID,
|
|
F_PaymentDetailCreated,
|
|
F_PaymentDetailLastUpdated,
|
|
F_PaymentDetailUserID)
|
|
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("f_paymentdetail non cash insert");
|
|
exit;
|
|
}
|
|
|
|
// insert f payment voucher
|
|
if ($v['code'] == 'VOUCHER') {
|
|
$this->insert_voucher_payment($orderid, $headerid, $companyID, $mouID, $xuserid);
|
|
}
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
$query = "SELECT M_PaymentTypeID as id,
|
|
M_PaymentTypeCode as code,
|
|
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
|
|
M_PaymentTypeName as chexlabel,
|
|
'Jumlah' as leftlabel,
|
|
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 'Nomor Rekening'
|
|
ELSE 'Nomor Voucher'
|
|
END as rightlabel,
|
|
0 as leftvalue,
|
|
0 as rightvalue
|
|
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
foreach ($rows as $k => $v) {
|
|
if ($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
$xdata = $this->db_onedev->query("SELECT F_PaymentID as idx, F_PaymentNumber as numberx FROM f_payment WHERE F_PaymentID = {$headerid}")->row();
|
|
|
|
// get discount member
|
|
$sqldisc = "SELECT
|
|
T_OrderMemberDiscountID,
|
|
T_OrderMemberDiscountT_OrderHeaderID,
|
|
T_OrderMemberDiscountBruto,
|
|
T_OrderMemberDiscountNetto,
|
|
T_OrderMemberDiscountPercent
|
|
FROM t_ordermemberdiscount
|
|
WHERE T_OrderMemberDiscountT_OrderHeaderID = ?";
|
|
$discdata = $this->db_onedev->query($sqldisc, array($orderid));
|
|
if (!$discdata) {
|
|
$this->sys_error_db("t_ordermemberdiscount get");
|
|
exit;
|
|
}
|
|
$discount = $discdata->result_array();
|
|
|
|
if (count($discount) > 0) {
|
|
$sqldisc = "INSERT INTO f_memberdiscount(
|
|
F_MemberDiscountF_PaymentID,
|
|
T_OrderMemberDiscountID,
|
|
T_OrderMemberDiscountT_OrderHeaderID,
|
|
T_OrderMemberDiscountBruto,
|
|
T_OrderMemberDiscountNetto,
|
|
T_OrderMemberDiscountPercent,
|
|
T_OrderMemberDiscountCreated,
|
|
T_OrderMemberDiscountCreatedUserID
|
|
) VALUES (?,?,?,?,?,?,NOW(),?)";
|
|
$disc = $this->db_onedev->query($sqldisc, array(
|
|
$xdata->idx,
|
|
$discount[0]['T_OrderMemberDiscountID'],
|
|
$discount[0]['T_OrderMemberDiscountT_OrderHeaderID'],
|
|
$discount[0]['T_OrderMemberDiscountBruto'],
|
|
$discount[0]['T_OrderMemberDiscountNetto'],
|
|
$discount[0]['T_OrderMemberDiscountPercent'],
|
|
$xuserid
|
|
));
|
|
|
|
if (!$disc) {
|
|
$this->sys_error_db("f_memberdiscount insert");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => array('payments' => $payments, 'types' => $rows, 'data' => $xdata)
|
|
);
|
|
$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 = "UPDATE t_order_location
|
|
SET
|
|
T_OrderLocationIsActive = 'N',
|
|
T_OrderLocationLastUpdated = NOW(),
|
|
T_OrderLocationUserID = ?
|
|
WHERE
|
|
T_OrderLocationT_OrderHeaderID = ? AND
|
|
T_OrderLocationT_SampleStationID = ? AND
|
|
T_OrderLocationIsActive = 'Y'";
|
|
$this->db_onedev->query($sql, array($userid, $value['order_id'], $value['station_id']));
|
|
|
|
$sql = "INSERT INTO t_order_location (
|
|
T_OrderLocationT_OrderHeaderID,
|
|
T_OrderLocationM_LocationID,
|
|
T_OrderLocationT_SampleStationID,
|
|
T_OrderLocationIsActive,
|
|
T_OrderLocationCreated,
|
|
T_OrderLocationLastUpdated,
|
|
T_OrderLocationUserID
|
|
)
|
|
VALUES (?,?,?,'Y',NOW(),NOW(),?)";
|
|
$query = $this->db_onedev->query($sql, array($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;
|
|
}
|
|
}
|
|
|
|
function lookup_detail_payment()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT
|
|
F_PaymentID,
|
|
F_PaymentNumber,
|
|
F_PaymentTotal,
|
|
F_PaymentNote,
|
|
F_PaymentDetailM_PaymentTypeID,
|
|
F_PaymentDetailNote,
|
|
F_PaymentDetailAmount,
|
|
F_PaymentDetailActual,
|
|
F_PaymentDetailChange
|
|
FROM f_payment
|
|
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
|
|
WHERE F_PaymentT_OrderHeaderID = ?";
|
|
$query = $this->db_onedev->query($sql, array($prm['orderheaderid']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$this->sys_ok($rows);
|
|
} else {
|
|
$this->sys_error_db("lookup_paymentdetail", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function lookup_company()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$qp = [
|
|
'keyword' => '%'
|
|
];
|
|
|
|
$prm = $this->sys_input;
|
|
$keyword = $prm['keyword'];
|
|
|
|
if ($keyword != '') {
|
|
$qp['keyword'] = "%{$keyword}%";
|
|
}
|
|
|
|
$sql = "SELECT
|
|
M_CompanyID, M_CompanyName,
|
|
IFNULL( concat('[', group_concat( json_object('M_MouID', M_MouID, 'M_MouName', CONCAT(M_MouName,' (',M_MouNumber,')'), 'M_MouStartDate', M_MouStartDate, 'M_MouEndDate', M_MouEndDate, 'M_MouNote', M_MouNote, 'M_MouIsBill', M_MouIsBill, 'M_MouEmail', M_MouEmail, 'M_MouIsDefault', M_MouIsDefault, 'M_MouEmailIsDefault', M_MouEmailIsDefault, 'delivery_email_code', `fn_fo_delivery_code`('MOU', 'EMAIL', '0')) ), ']'), '[]') as mou
|
|
from m_company
|
|
join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
|
|
and M_MouIsApproved = 'Y'
|
|
-- and M_MouStartDate <= date(now()) and M_MouEndDate >= date(now())
|
|
AND M_MouIsReleased = 'Y'
|
|
join m_mouaddon on M_MouAddonM_MouID = M_MouID and M_MouAddonIsVoucher = 'Y' and M_MouAddonIsActive = 'Y'
|
|
where M_CompanyIsActive = 'Y' and M_CompanyName LIKE ?
|
|
group by m_companyid
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql, array($qp['keyword']));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
foreach ($rows as $key => $value) {
|
|
$rows[$key]['mou'] = json_decode($value['mou']);
|
|
}
|
|
|
|
$result = array(
|
|
"total" => sizeof($rows),
|
|
"records" => $rows,
|
|
"total_display" => sizeof($rows)
|
|
);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("lookup_company", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function insert_voucher_payment($orderheaderID, $paymentID, $companyID, $mouID, $userID)
|
|
{
|
|
|
|
$sql = "INSERT INTO f_payment_voucher(
|
|
F_Payment_VoucherT_OrderHeaderID,
|
|
F_Payment_VoucherF_PaymentID,
|
|
F_Payment_VoucherM_CompanyID,
|
|
F_Payment_VoucherM_MouID,
|
|
F_Payment_VoucherCreated,
|
|
F_Payment_VoucherUserID
|
|
) VALUES (?, ?, ?, ?, NOW(), ?)
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($orderheaderID, $paymentID, $companyID, $mouID, $userID));
|
|
if (!$query) {
|
|
$this->sys_error_db("error inserta f payment voucher");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function lookup_print_transaction()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$startId = isset($prm['start_id']) && intval($prm['start_id']) > 0 ? intval($prm['start_id']) : 15;
|
|
$endId = isset($prm['end_id']) && intval($prm['end_id']) > 0 ? intval($prm['end_id']) : 25;
|
|
|
|
if ($startId > $endId) {
|
|
$tmp = $startId;
|
|
$startId = $endId;
|
|
$endId = $tmp;
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM print_transaction
|
|
WHERE Print_TransactionID >= ? AND Print_TransactionID <= ?
|
|
ORDER BY Print_TransactionID ASC";
|
|
$query = $this->db_onedev->query($sql, array($startId, $endId));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("lookup_print_transaction", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_print_transaction_fo_kk_ina()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM print_transaction WHERE Print_TransactionCode = 'FO-KK-INA'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("get_print_transaction_fo_kk_ina", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_report_url_by_code()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$reportCode = trim($prm['code'] ?? $prm['code_report'] ?? '');
|
|
$orderId = intval($prm['order_id'] ?? 0);
|
|
$paymentId = intval($prm['payment_id'] ?? 0);
|
|
|
|
if ($reportCode === '') {
|
|
$this->sys_error("code wajib diisi");
|
|
exit;
|
|
}
|
|
|
|
if ($orderId <= 0 && $paymentId <= 0) {
|
|
$this->sys_error("order_id atau payment_id wajib diisi");
|
|
exit;
|
|
}
|
|
|
|
if ($orderId <= 0 && $paymentId > 0) {
|
|
$orderId = $this->resolve_order_id_by_payment($paymentId);
|
|
}
|
|
|
|
if ($orderId <= 0) {
|
|
$this->sys_error("order_id tidak ditemukan");
|
|
exit;
|
|
}
|
|
|
|
$token = $this->resolve_request_token();
|
|
$url = $this->build_report_proxy_url($token, $reportCode, $orderId, $paymentId);
|
|
|
|
$this->sys_ok(array(
|
|
"url" => $url
|
|
));
|
|
exit;
|
|
}
|
|
|
|
function stream_report_by_code()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$reportCode = trim($prm['code'] ?? $prm['code_report'] ?? '');
|
|
$orderId = intval($prm['order_id'] ?? 0);
|
|
$paymentId = intval($prm['payment_id'] ?? 0);
|
|
|
|
if ($reportCode === '') {
|
|
$this->sys_error("code wajib diisi");
|
|
exit;
|
|
}
|
|
|
|
if ($orderId <= 0 && $paymentId > 0) {
|
|
$orderId = $this->resolve_order_id_by_payment($paymentId);
|
|
}
|
|
|
|
if ($orderId <= 0) {
|
|
$this->sys_error("order_id tidak ditemukan");
|
|
exit;
|
|
}
|
|
|
|
$this->load->library('ibl_patient_decrypt');
|
|
$cacheId = $this->ibl_patient_decrypt->populate_cache_by_order($orderId);
|
|
$patientName = $this->resolve_patient_name_by_cache($cacheId);
|
|
if ($patientName === '') {
|
|
$patientName = $this->resolve_patient_name_by_order($orderId);
|
|
}
|
|
if ($patientName === '') {
|
|
$patientName = $this->resolve_patient_name_from_enc_by_order($orderId);
|
|
}
|
|
|
|
$url = $this->build_birt_url_by_code($reportCode, $orderId, $paymentId, $patientName);
|
|
if ($url === false) {
|
|
$this->ibl_patient_decrypt->delete_cache($cacheId);
|
|
$this->sys_error("print transaction tidak ditemukan: " . $reportCode);
|
|
exit;
|
|
}
|
|
|
|
$pdf = @file_get_contents($this->resolve_fetch_url($url), false, stream_context_create(array(
|
|
'http' => array(
|
|
'timeout' => 120,
|
|
'method' => 'GET',
|
|
),
|
|
)));
|
|
|
|
$this->ibl_patient_decrypt->delete_cache($cacheId);
|
|
|
|
if ($pdf === false) {
|
|
$this->sys_error('Gagal generate report dari BIRT server');
|
|
exit;
|
|
}
|
|
|
|
$filename = $reportCode . '_' . $orderId . '_' . date('Ymd') . '.pdf';
|
|
header('Content-Type: application/pdf');
|
|
header('Content-Disposition: inline; filename="' . $filename . '"');
|
|
header('Content-Length: ' . strlen($pdf));
|
|
echo $pdf;
|
|
exit;
|
|
}
|
|
|
|
private function resolve_order_id_by_payment($paymentId)
|
|
{
|
|
$row = $this->db_onedev->query(
|
|
"SELECT F_PaymentT_OrderHeaderID
|
|
FROM f_payment
|
|
WHERE F_PaymentID = ?
|
|
LIMIT 1",
|
|
array($paymentId)
|
|
)->row_array();
|
|
|
|
return intval($row['F_PaymentT_OrderHeaderID'] ?? 0);
|
|
}
|
|
|
|
private function resolve_payment_id_by_order($orderId)
|
|
{
|
|
$row = $this->db_onedev->query(
|
|
"SELECT F_PaymentID
|
|
FROM f_payment
|
|
WHERE F_PaymentT_OrderHeaderID = ?
|
|
AND IFNULL(F_PaymentIsActive, 'Y') = 'Y'
|
|
ORDER BY F_PaymentID DESC
|
|
LIMIT 1",
|
|
array($orderId)
|
|
)->row_array();
|
|
|
|
return intval($row['F_PaymentID'] ?? 0);
|
|
}
|
|
|
|
private function resolve_patient_name_by_order($orderId)
|
|
{
|
|
$row = $this->db_onedev->query(
|
|
"SELECT ppc_name
|
|
FROM patient_print_cache
|
|
WHERE ppc_order_id = ?
|
|
ORDER BY ppc_id DESC
|
|
LIMIT 1",
|
|
array($orderId)
|
|
)->row_array();
|
|
|
|
return trim($row['ppc_name'] ?? '');
|
|
}
|
|
|
|
private function resolve_patient_name_by_cache($cacheId)
|
|
{
|
|
if (!$cacheId) {
|
|
return '';
|
|
}
|
|
|
|
$row = $this->db_onedev->query(
|
|
"SELECT ppc_name
|
|
FROM patient_print_cache
|
|
WHERE ppc_id = ?
|
|
LIMIT 1",
|
|
array($cacheId)
|
|
)->row_array();
|
|
|
|
return trim($row['ppc_name'] ?? '');
|
|
}
|
|
|
|
private function resolve_patient_name_from_enc_by_order($orderId)
|
|
{
|
|
$this->load->library('ibl_encryptor');
|
|
$row = $this->db_onedev->query(
|
|
"SELECT M_PatientName_enc
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
WHERE T_OrderHeaderID = ?
|
|
LIMIT 1",
|
|
array($orderId)
|
|
)->row_array();
|
|
|
|
return trim($this->ibl_encryptor->decrypt($row['M_PatientName_enc'] ?? '') ?? '');
|
|
}
|
|
|
|
private function resolve_report_username()
|
|
{
|
|
if (!empty($this->sys_user['M_StaffName'])) {
|
|
return trim($this->sys_user['M_StaffName']);
|
|
}
|
|
if (!empty($this->sys_user['M_UserUsername'])) {
|
|
return trim($this->sys_user['M_UserUsername']);
|
|
}
|
|
if (!empty($this->sys_user['userName'])) {
|
|
return trim($this->sys_user['userName']);
|
|
}
|
|
return 'ADMIN';
|
|
}
|
|
|
|
private function build_report_proxy_url($token, $reportCode, $orderId, $paymentId)
|
|
{
|
|
$query = array(
|
|
'token' => $token,
|
|
'code' => $reportCode,
|
|
'order_id' => $orderId,
|
|
);
|
|
|
|
if ($paymentId > 0) {
|
|
$query['payment_id'] = $paymentId;
|
|
}
|
|
|
|
return '/one-api-lab/mockup/fo/cashiernewpayment-v27/payment/stream_report_by_code?' . http_build_query($query);
|
|
}
|
|
|
|
private function resolve_request_token()
|
|
{
|
|
$rawInput = json_decode($this->input->raw_input_stream, true);
|
|
if (is_array($rawInput) && !empty($rawInput['token'])) {
|
|
return trim($rawInput['token']);
|
|
}
|
|
|
|
$postToken = $this->input->post('token', true);
|
|
if (!empty($postToken)) {
|
|
return trim($postToken);
|
|
}
|
|
|
|
$getToken = $this->input->get('token', true);
|
|
if (!empty($getToken)) {
|
|
return trim($getToken);
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
private function build_birt_url_by_code($reportCode, $orderId, $paymentId, $patientName)
|
|
{
|
|
$printTransaction = $this->db_onedev->query(
|
|
"SELECT Print_TransactionUrl
|
|
FROM print_transaction
|
|
WHERE Print_TransactionCode = ?
|
|
LIMIT 1",
|
|
array($reportCode)
|
|
)->row_array();
|
|
|
|
if (!$printTransaction) {
|
|
return false;
|
|
}
|
|
|
|
$username = $this->resolve_report_username();
|
|
$ts = round(microtime(true) * 1000);
|
|
$resolvedPaymentId = $paymentId > 0 ? $paymentId : $this->resolve_payment_id_by_order($orderId);
|
|
$isInternalAppUrl = $this->is_internal_app_url($printTransaction['Print_TransactionUrl']);
|
|
|
|
$replacements = array(
|
|
'PUsername' => $this->format_report_string_param($username, $isInternalAppUrl),
|
|
'PT_OrderHeaderID' => $orderId,
|
|
'PPaymentID' => $resolvedPaymentId,
|
|
'PAn' => $this->format_report_string_param($patientName, $isInternalAppUrl),
|
|
'TS' => $ts,
|
|
);
|
|
|
|
$url = $printTransaction['Print_TransactionUrl'];
|
|
foreach ($replacements as $placeholder => $value) {
|
|
if ($value === null) {
|
|
$value = '';
|
|
}
|
|
$url = str_replace($placeholder, $value, $url);
|
|
}
|
|
|
|
return $url;
|
|
}
|
|
|
|
private function resolve_fetch_url($url)
|
|
{
|
|
$url = trim((string) $url);
|
|
|
|
if ($url === '') {
|
|
return '';
|
|
}
|
|
|
|
if (preg_match('#^https?://#i', $url)) {
|
|
return $url;
|
|
}
|
|
|
|
if (strpos($url, '/birt/') === 0) {
|
|
return 'http://localhost:8080' . $url;
|
|
}
|
|
|
|
if (strpos($url, '/one-api-lab/') === 0) {
|
|
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
|
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
|
|
|
|
return $scheme . '://' . $host . $url;
|
|
}
|
|
|
|
if (strpos($url, '/tools/') === 0 || strpos($url, '/index.php/') === 0) {
|
|
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
|
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
|
|
|
|
return $scheme . '://' . $host . '/one-api-lab' . $url;
|
|
}
|
|
|
|
return 'http://localhost:8080' . $url;
|
|
}
|
|
|
|
private function is_internal_app_url($url)
|
|
{
|
|
$url = (string) $url;
|
|
|
|
return (
|
|
strpos($url, '/one-api-lab/') === 0 ||
|
|
strpos($url, '/tools/') === 0 ||
|
|
strpos($url, '/index.php/') === 0
|
|
);
|
|
}
|
|
|
|
private function format_report_string_param($value, $isInternalAppUrl = false)
|
|
{
|
|
$value = (string) $value;
|
|
|
|
if ($isInternalAppUrl) {
|
|
return rawurlencode($value);
|
|
}
|
|
|
|
return rawurlencode("'" . $value . "'");
|
|
}
|
|
}
|