Files
2026-04-15 15:24:12 +07:00

245 lines
6.1 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,
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'
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;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
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'];
//$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){
$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'];
$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 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'
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();
$result = array(
"total" => count($rows) ,
"records" => array('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;
}
}