624 lines
16 KiB
PHP
624 lines
16 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 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' => '');
|
|
$rows[$k]['selected_account'] = 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 selectpaymenttype()
|
|
{
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query = " SELECT *
|
|
FROM m_paymenttype
|
|
WHERE
|
|
M_PaymentTypeIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function selectbank()
|
|
{
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query = " SELECT *
|
|
FROM nat_bank
|
|
WHERE
|
|
Nat_BankIsActive = 'Y'
|
|
ORDER BY Nat_BankCode DESC
|
|
";
|
|
//echo $query;
|
|
$rows['banks'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function selectaccount()
|
|
{
|
|
|
|
try {
|
|
//# 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';
|
|
}
|
|
|
|
$rows = [];
|
|
$query = " SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName
|
|
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";
|
|
//echo $query;
|
|
$rows['accounts'] = $this->db_onedev->query($query, $EDC)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
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
|
|
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 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'];
|
|
$real_date = isset($prm['real_date']) ? $prm['real_date'] : date('Y-m-d');
|
|
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
|
|
$sql = "INSERT INTO f_bill_payment
|
|
(F_BillPaymentF_BillID, F_BillPaymentDate, F_BillPaymentRealDate, F_BillPaymentCreated, F_BillPaymentUserID)
|
|
VALUES (?, CURDATE(), ?, NOW(), ?)";
|
|
$query = $this->db_onedev->query(
|
|
$sql,
|
|
array(
|
|
$orderid,
|
|
$real_date,
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("f_bill_payment insert");
|
|
exit;
|
|
}
|
|
$headerid = $this->db_onedev->insert_id();
|
|
//echo $headerid;
|
|
|
|
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 = "CALL `sp_bill_payment_add_cash`(" . $orderid . "," . $amount . "," . $amount . "," . $headerid . "," . $v['id'] . "," . $xuserid . ")";
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("f_bill_payment_detail 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'];
|
|
$selected_account = $v['selected_account']['id'];
|
|
}
|
|
$sql = "CALL `sp_bill_payment_add_noncash`(" . $orderid . "," . $amount . "," . $amount . "," . $headerid . "," . $v['id'] . "," . $xuserid . "," . $selected_card . "," . $selected_edc . "," . $selected_account . ")";
|
|
//echo $sql;
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$this->sys_error_db("f_bill_payment_detail non cash insert");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$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_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => array('types' => $rows, 'data' => $xdata)
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function paymanual()
|
|
{
|
|
//# 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'];
|
|
$amount = $prm['amount'];
|
|
$paymenttype = $prm['paymenttype'];
|
|
$real_date = isset($prm['real_date']) ? $prm['real_date'] : date('Y-m-d');
|
|
if ($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5) {
|
|
$card = 0;
|
|
$edc = 0;
|
|
$account = 0;
|
|
} elseif ($prm['paymenttype'] == 4) {
|
|
$card = 0;
|
|
$edc = 0;
|
|
$account = $prm['account'];
|
|
} else {
|
|
$card = $prm['card'];
|
|
$edc = $prm['edc'];
|
|
$account = 0;
|
|
}
|
|
$voucher = $prm['voucher'];
|
|
$bills = $prm['bills'];
|
|
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
|
|
$sql = "INSERT INTO f_bill_payment
|
|
(F_BillPaymentF_BillID,
|
|
F_BillPaymentDate,
|
|
F_BillPaymentRealDate,
|
|
F_BillPaymentAmount,
|
|
F_BillPaymentM_PaymentTypeID,
|
|
F_BillPaymentEDCNat_BankID,
|
|
F_BillPaymentCardNat_BankID,
|
|
F_BillPaymentM_BankAccountID,
|
|
F_BillPaymentVoucherNumber,
|
|
F_BillPaymentCreated,
|
|
F_BillPaymentUserID)
|
|
VALUES (?,
|
|
CURDATE(),
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
NOW(),
|
|
?)";
|
|
$query = $this->db_onedev->query(
|
|
$sql,
|
|
array(
|
|
$orderid,
|
|
$real_date,
|
|
$amount,
|
|
$paymenttype,
|
|
$edc,
|
|
$card,
|
|
$account,
|
|
$voucher,
|
|
$xuserid
|
|
)
|
|
);
|
|
$headerid = $this->db_onedev->insert_id();
|
|
if (!$query) {
|
|
$this->sys_error_db("f_bill_payment insert");
|
|
exit;
|
|
} else {
|
|
$sqlbill = "UPDATE f_bill SET
|
|
F_BillUnpaid = F_BillUnpaid - $amount,
|
|
F_BillIsLunas = IF(F_BillUnpaid = 0,'Y','N')
|
|
WHERE F_BillID = $orderid";
|
|
$querybill = $this->db_onedev->query($sqlbill);
|
|
}
|
|
|
|
//echo $headerid;
|
|
|
|
foreach ($bills as $k => $v) {
|
|
if ($v['tagihan_bayar'] > 0) {
|
|
$F_BillDetailID = $v['F_BillDetailID'];
|
|
$tagihan_bayar = $v['tagihan_bayar'];
|
|
$F_BillDetailT_OrderHeaderID = $v['F_BillDetailT_OrderHeaderID'];
|
|
$sql = "INSERT INTO f_bill_payment_detail(
|
|
F_BillPaymentDetailF_BillPaymentID,
|
|
F_BillPaymentDetailF_BillID,
|
|
F_BillPaymentDetailF_BillDetailID,
|
|
F_BillPaymentDetailAmount,
|
|
F_BillPaymentDetailUserID,
|
|
F_BillPaymentDetailCreated,
|
|
F_BillPaymentDetailLastUpdated)
|
|
VALUES(
|
|
$headerid,
|
|
$orderid,
|
|
$F_BillDetailID,
|
|
$tagihan_bayar,
|
|
$xuserid,
|
|
now(),
|
|
now())";
|
|
$query = $this->db_onedev->query($sql);
|
|
$billpaymentdetailid = $this->db_onedev->insert_id();
|
|
if (!$query) {
|
|
$this->sys_error_db("f_bill_payment_detail cash insert");
|
|
exit;
|
|
} else {
|
|
$sqlbilldetail = "UPDATE f_bill_detail SET
|
|
F_BillDetailUnpaid = F_BillDetailUnpaid - $tagihan_bayar
|
|
WHERE F_BillDetailID = $F_BillDetailID";
|
|
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
|
|
|
|
$sqlpayment = "INSERT INTO f_payment
|
|
(F_PaymentT_OrderHeaderID,
|
|
F_PaymentDate,
|
|
F_PaymentTotal,
|
|
F_PaymentCreated,
|
|
F_PaymentLastUpdated,
|
|
F_PaymentM_UserID)
|
|
VALUES(
|
|
$F_BillDetailT_OrderHeaderID,
|
|
now(),
|
|
$tagihan_bayar,
|
|
now(),
|
|
now(),
|
|
$xuserid)";
|
|
$querypayment = $this->db_onedev->query($sqlpayment);
|
|
$paymentid = $this->db_onedev->insert_id();
|
|
$sqlpaymentdetail = "INSERT INTO f_paymentdetail
|
|
(F_PaymentDetailF_PaymentID,
|
|
F_PaymentDetailM_PaymentTypeID,
|
|
F_PaymentDetailAmount,
|
|
F_PaymentDetailActual,
|
|
F_PaymentDetailChange,
|
|
F_PaymentDetailEDCNat_BankID,
|
|
F_PaymentDetailCardNat_BankID,
|
|
F_PaymentDetailM_BankAccountID,
|
|
F_PaymentDetailCreated,
|
|
F_PaymentDetailLastUpdated,
|
|
F_PaymentDetailUserID)
|
|
VALUES(
|
|
$paymentid,
|
|
$paymenttype,
|
|
$tagihan_bayar,
|
|
$tagihan_bayar,
|
|
0,
|
|
$edc,
|
|
$card,
|
|
$account,
|
|
now(),
|
|
now(),
|
|
$xuserid)";
|
|
//echo $sqlpaymentdetail;
|
|
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
|
|
|
|
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_detail SET
|
|
F_BillPaymentDetailF_PaymentID = $paymentid
|
|
WHERE F_BillPaymentDetailID = $billpaymentdetailid";
|
|
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => array('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_bill_payment SET F_BillPaymentIsActive = 'N', F_BillPaymentNote = '{$catatan}' WHERE F_BillPaymentID = {$prmnota['note_id']}";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("f_bill_payment delete");
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE f_bill_payment_detail SET F_BillPaymentDetailIsActive = 'N' WHERE F_BillPaymentDetailF_BillPaymentID = {$prmnota['note_id']}";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("f_bill_payment_detail delete");
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('prm' => $prm)
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
}
|