180 lines
6.5 KiB
PHP
180 lines
6.5 KiB
PHP
<?php
|
|
|
|
class Sendtransaction extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "CONTROL API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
function lookuptransaction(){
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$all = $prm['all'];
|
|
$sdate = $prm['sdate'];
|
|
$limit = '';
|
|
if($all == 'N'){
|
|
$limit = ' LIMIT 10';
|
|
}
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
$sql = "select COUNT(*) as total
|
|
from f_reg_sendtransaction
|
|
JOIN m_user ON F_RegSendTransactionUserID = M_UserID AND M_UserIsActive = 'Y'
|
|
where
|
|
(F_RegSendTransactionNoTransaction LIKE CONCAT('%','{$search}','%') OR
|
|
F_RegSendTransactionNoRef LIKE CONCAT('%','{$search}','%')) AND
|
|
date(F_RegSendTransactionCreated) = '{$sdate}'";
|
|
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("f_reg_sendtransaction count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select F_RegSendTransactionID as id,
|
|
DATE_FORMAT(F_RegSendTransactionCreated,'%d-%m-%Y') as tanggal,
|
|
f_reg_sendtransaction.*,
|
|
M_UserUsername
|
|
from f_reg_sendtransaction
|
|
JOIN m_user ON F_RegSendTransactionUserID = M_UserID AND M_UserIsActive = 'Y'
|
|
where
|
|
(F_RegSendTransactionNoTransaction LIKE CONCAT('%','{$search}','%') OR
|
|
F_RegSendTransactionNoRef LIKE CONCAT('%','{$search}','%')) AND
|
|
date(F_RegSendTransactionCreated) = '{$sdate}'
|
|
GROUP BY F_RegSendTransactionID
|
|
ORDER BY F_RegSendTransactionID DESC
|
|
limit $number_limit offset $number_offset";
|
|
$sql_param = array($search);
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
|
|
} else {
|
|
$this->sys_error_db("f_reg_sendtransaction select");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
public function addnewtransaction()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$notransaction = $prm['notransaction'];
|
|
$noref = $prm['noref'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$username = $this->sys_user["M_UserUsername"];
|
|
$token = $prm['token'];
|
|
$sql = $this->db_onedev->query("SELECT M_BranchCode as branchcode FROM m_branch
|
|
WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'")->row();
|
|
$branchcode = $sql->branchcode;
|
|
$param = array (
|
|
"username" => $username,
|
|
"branchCode" => $branchcode,
|
|
"transactionNo" => $notransaction,
|
|
"RefNo" => $noref,
|
|
"token" => $token
|
|
);
|
|
$j_param = json_encode($param);
|
|
$url = "https://mobile.pramita.co.id/one-api/fix/tx_force";
|
|
$post_rst = $this->post($url,$j_param);
|
|
$j_rst = json_decode($post_rst,true);
|
|
$xstatus = $j_rst["status"];
|
|
$xpesan = $j_rst["message"];
|
|
$query = "INSERT INTO f_reg_sendtransaction (
|
|
F_RegSendTransactionNoTransaction,
|
|
F_RegSendTransactionNoRef,
|
|
F_RegSendTransactionStatus,
|
|
F_RegSendTransactionMessage,
|
|
F_RegSendTransactionUserID,
|
|
F_RegSendTransactionCreated,
|
|
F_RegSendTransactionLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,now(),now()
|
|
)";
|
|
$insert_new_test = $this->db_onedev->query($query,array(
|
|
$notransaction,
|
|
$noref,
|
|
$xstatus,
|
|
$xpesan,
|
|
$userid
|
|
));
|
|
if (!$query) {
|
|
$this->sys_error_db("m_user insert");
|
|
exit;
|
|
}
|
|
|
|
$last_id = $this->db_onedev->insert_id();
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
$last_id = $this->db_onedev->insert_id();
|
|
|
|
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function post($url,$data) {
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($data))
|
|
);
|
|
$result = curl_exec($ch);
|
|
if (curl_errno($ch)){
|
|
return json_encode( array("status" => "ERR",
|
|
"message" => curl_error($ch)) );
|
|
}
|
|
curl_close($ch);
|
|
return $result;
|
|
}
|
|
|
|
|
|
}
|