Files
2026-04-27 10:31:17 +07:00

163 lines
6.1 KiB
PHP

<?php
class Billsend 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_bill_confirm_issue
LEFT JOIN f_bill_detail ON F_BillDetailF_BillID = F_BillConfirmIssueF_BillID AND F_BillDetailIsActive = 'Y'
LEFT JOIN t_orderheader ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID
where
F_BillConfirmIssueIsActive = 'Y' AND F_BillConfirmIssueIsConfirm = 'Y' AND
(F_BillConfirmIssueRefNumber LIKE CONCAT('%','{$search}','%') OR
F_BillNo LIKE CONCAT('%','{$search}','%') OR
M_CompanyName LIKE CONCAT('%','{$search}','%'))";
// $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_bill_confirm_issue count", $this->db_onedev);
exit;
}
$sql = "select F_BillConfirmIssueID as id,
F_BillConfirmIssueRefNumber,
F_BillNo,
DATE_FORMAT(F_BillConfirmIssueDate ,n'%d-%m-%Y') as xdate,
F_BillConfirmIssueDate,
M_CompanyName,
M_MouName
from f_bill_confirm_issue
LEFT JOIN f_bill_detail ON F_BillDetailF_BillID = F_BillConfirmIssueF_BillID AND F_BillDetailIsActive = 'Y'
LEFT JOIN t_orderheader ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID
where
F_BillConfirmIssueIsActive = 'Y' AND F_BillConfirmIssueIsConfirm = 'Y' AND
(F_BillConfirmIssueRefNumber LIKE CONCAT('%','{$search}','%') OR
F_BillNo LIKE CONCAT('%','{$search}','%') OR
M_CompanyName LIKE CONCAT('%','{$search}','%'))
GROUP BY F_BillConfirmIssueID
ORDER BY F_BillConfirmIssueDate 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_bill_confirm_issue 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 fix()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$nomor = md5($prm['nomor']);
$userid = $this->sys_user["M_UserID"];
$sql = $this->db_onedev->query("SELECT M_BranchIPAddress as branch_ip_address FROM m_branch WHERE M_BranchIsDefault = 'Y'")->row();
$branch_ip_address = $sql->branch_ip_address;
$param = array (
"id" => $id,
"nomor" => $nomor);
$j_param = json_encode($param);
$url = "http://$branch_ip_address/one-api/keu/titip_tagihan/upload/".$id."/".$userid;
$post_rst = $this->post($url);
// echo "to $url \nresponse : $post_rst\n";
$j_rst = json_decode($post_rst,true);
$xstatus = $j_rst["status"];
$xpesan = $j_rst["message"];
$result = array ("total" => 1, "records" => array("xid" => 0),"pesan"=>$post_rst);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function post($url) {
//$data = $data;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//echo "RST : $result ";
return $result;
}
function postold($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;
}
}