Initial import

This commit is contained in:
sas.fajri
2026-04-27 10:26:26 +07:00
commit bf9b9097ee
2388 changed files with 3002242 additions and 0 deletions

View File

@@ -0,0 +1,181 @@
<?php
class Bridging extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Resultentry API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_log = $this->load->database("log", true);
$this->load->helper(array('form', 'url'));
}
public function error_log($data,$userid=999)
{
$sql = "INSERT INTO ais_error_log (
AisErrorLogFnName,
AisErrorLogMessage,
AisErrorLogQuery,
AisErrorLogJson,
AisErrorLogUserID,
AisErrorLogCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($data['fn_name'],$data['message'],$data['query'],$data['json'],$userid));
//echo $this->db_log->last_query();
return true;
}
/**
* Generic POST request function
* @param string $url API endpoint URL
* @param array $data Request payload
* @param array $headers Custom headers (optional)
* @return array Response from API
*/
public function post_request($url, $data = array(), $headers = array())
{
// Default headers
$default_headers = array(
'Content-Type: application/json'
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
} else {
$result = json_decode($response, true);
$result['success'] = true;
}
return $result;
}
function get_config()
{
$sql = "SELECT * FROM ais_config LIMIT 1";
$qry = $this->db_onedev->query($sql);
$dt_config = $qry->row_array();
return $dt_config;
}
/**
* POST request to auth API
* @param string $username Username for authentication
* @param string $password Password for authentication
* @return array Response from API
*/
public function post_auth()
{
$dt_config = $this->get_config();
$baseUrl = $dt_config['AisConfigBaseUrl'];
$url = $baseUrl.'/api/auth/auth.php';
$headers = array(
'Header-Token: '.$dt_config['AisConfigHeaderToken']
);
$username = $dt_config['AisConfigUsername'];
$password = $dt_config['AisConfigPassword'];
$data = array(
'username' => $username,
'password' => $password
);
$result = $this->post_request($url, $data, $headers);
$sql = "INSERT INTO ais_login_log(
AisLoginLogUsername,
AisLoginLogPassword,
AisLoginLogHeaderToken,
AisLoginLogResult,
AisLoginLogCreated
)
VALUES(
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($username,$password,$dt_config['AisConfigHeaderToken'],json_encode($result)));
if(!$qry){
$this->error_log(array('fn_name'=>'post_auth','message'=>'ais_login_log insert','query'=>$sql,'json'=>json_encode($result)),999);
exit;
}
//print_r($result);
//exit;
// Check if success
if(!$result['success']){
$this->error_log(array('fn_name'=>'post_auth','message'=>'failed auth','query'=>'','json'=>json_encode($result)),999);
$errors = array('status' => 'error','message' => 'Gagal Login');
echo json_encode($errors);
exit;
}else{
// Update token
$token = $result['data']['token'];;
$sql = "UPDATE ais_config SET AisConfigAuthToken = ? WHERE AisConfigID = 1";
$qry = $this->db_onedev->query($sql, array($token));
//echo $this->db_onedev->last_query();
//exit;
if(!$qry){
$this->error_log(array('fn_name'=>'post_auth','message'=>'ais_config update','query'=>$sql,'json'=>''),999);
$errors = array('status' => 'error','message' => 'Gagal Update Token');
echo json_encode($errors);
exit;
}
$success = array('status' => 'success','message' => 'Berhasil Login');
echo json_encode($success);
exit;
}
}
}

View File

@@ -0,0 +1,421 @@
<?php
class Corporate extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Resultentry API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_log = $this->load->database("log", true);
$this->load->helper(array('form', 'url'));
}
public function error_log($data, $userid = 999)
{
$sql = "INSERT INTO ais_error_log (
AisErrorLogFnName,
AisErrorLogMessage,
AisErrorLogQuery,
AisErrorLogJson,
AisErrorLogUserID,
AisErrorLogCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($data['fn_name'], $data['message'], $data['query'], $data['json'], $userid));
//echo $this->db_log->last_query();
return true;
}
/**
* Generic POST request function
* @param string $url API endpoint URL
* @param array $data Request payload
* @param array $headers Custom headers (optional)
* @return array Response from API
*/
public function post_request($url, $data = array(), $headers = array())
{
// Default headers
$default_headers = array(
'Content-Type: application/json'
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
}
else {
$result = json_decode($response, true);
if ($result['status'] == 200) {
$result['success'] = true;
}
else {
$result['success'] = false;
}
}
return $result;
}
public function get_request($url, $headers = array())
{
// Retrieve configuration
$config = $this->get_config();
$token = $config['AisConfigAuthToken'] ?? 'default-token';
$header_token = $config['AisConfigHeaderToken'];
// Default headers based on the curl command
$default_headers = array(
'Header-Token: ' . $header_token,
'Authorization: Bearer ' . $token
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
}
else {
$decoded = json_decode($response, true);
$result['response'] = $decoded;
// Check if response is successful based on http code
if ($http_code === 200) {
$result['success'] = true;
}
}
return $result;
}
function get_config()
{
$sql = "SELECT * FROM ais_config LIMIT 1";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->error_log(array('fn_name' => 'get_config', 'message' => 'ais_config select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$dt_config = $qry->row_array();
return $dt_config;
}
/**
* POST request to auth API
* @param string $username Username for authentication
* @param string $password Password for authentication
* @return array Response from API
*/
public function post_auth()
{
$dt_config = $this->get_config();
$baseUrl = $dt_config['AisConfigBaseUrl'];
$url = $baseUrl . '/api/auth/auth.php';
$headers = array(
'Header-Token: ' . $dt_config['AisConfigHeaderToken']
);
$username = $dt_config['AisConfigUsername'];
$password = $dt_config['AisConfigPassword'];
$data = array(
'username' => $username,
'password' => $password
);
$result = $this->post_request($url, $data, $headers);
$sql = "INSERT INTO ais_login_log(
AisLoginLogUsername,
AisLoginLogPassword,
AisLoginLogHeaderToken,
AisLoginLogResult,
AisLoginLogCreated
)
VALUES(
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($username, $password, $dt_config['AisConfigHeaderToken'], json_encode($result)));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'ais_login_log insert', 'query' => $this->db_log->last_query(), 'json' => json_encode($result)), 999);
exit;
}
//print_r($result);
//exit;
// Check if success
if (!$result['success']) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($result)), 999);
$errors = array('status' => 'error', 'message' => 'Gagal Login');
echo json_encode($errors);
exit;
}
else {
// Update token
$token = $result['data']['token'];
;
$sql = "UPDATE ais_config SET AisConfigAuthToken = ? WHERE AisConfigID = 1";
$qry = $this->db_onedev->query($sql, array($token));
//echo $this->db_onedev->last_query();
//exit;
if (!$qry) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'ais_config update', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
$errors = array('status' => 'error', 'message' => 'Gagal Update Token');
echo json_encode($errors);
exit;
}
//$success = array('status' => 'success', 'message' => 'Berhasil Login', 'token' => $token);
return $token;
}
}
/**
* POST request to jenis layanan API
* @param array $data Array of jenis layanan data
* @return array Response from API
*/
function monitoring_corporate()
{
// Ambil parameter
$corporate_name = $this->input->get('corporate_name');
$corporate_status = $this->input->get('corporate_status');
$corporate_code = $this->input->get('corporate_code');
$where_query = "WHERE c.CorporateIsActive = 'Y'";
if ($corporate_name) {
$where_query .= "AND ( c.CorporateName LIKE '%{$corporate_name}%' OR c.CorporateCode LIKE '%{$corporate_name}%' ) ";
}
// Pagination
$page = $this->input->get('page') ? intval($this->input->get('page')) : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$sql_base = "SELECT
DISTINCT c.CorporateID AS corporate_id,
0 as T_OrderHeaderID,
c.CorporateName AS corporate_name,
c.CorporateCode AS corporate_code,
c.CorporateAddress AS corporate_address,
c.CorporateEmail AS corporate_email,
c.CorporatePhone AS corporate_phone,
ais_pillar_name,
'' as Ais_CorporateStatus ,
'' AS corporate_status,
'' AS Ais_CorporateID
FROM corporate c
LEFT JOIN corporate_type ON CorporateCorporateTypeID = CorporateTypeID
LEFT JOIN ais_pillar ON CorporateTypeais_pillar_code = ais_pillar_code
$where_query
GROUP BY c.CorporateID
ORDER BY c.CorporateID ASC
LIMIT $limit OFFSET $offset";
//echo $sql_base;
$params = [];
// Count total records for pagination
$count_sql = "
SELECT COUNT(*) AS total
FROM (
SELECT
DISTINCT c.CorporateID AS corporate_id
FROM corporate c
$where_query
) AS x
";
$qry_count = $this->db_onedev->query($count_sql);
// echo $this->db_onedev->last_query();
$total = $qry_count->row()->total ?? 0;
$qry = $this->db_onedev->query($sql_base);
// echo $this->db_onedev->last_query();
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data monitoring.']);
exit;
}
$data = $qry->result_array();
if ($data) {
foreach ($data as $k => $d) {
$data[$k]['corporate_status'] = 'N';
$data[$k]['Ais_CorporateStatus'] = null;
$data[$k]['Ais_CorporateID'] = null;
$sql = "SELECT *
FROM " . $this->db_log->database . ".ais_corporate
WHERE Ais_CorporateCorporateCode = ?
ORDER BY Ais_CorporateLastUpdate DESC
LIMIT 1";
$qry_corporate = $this->db_log->query($sql, [$d['corporate_code']]);
if ($qry_corporate) {
$data[$k]['corporate_status'] = 'N';
$status = $qry_corporate->row()->Ais_CorporateStatus;
if ($status && $status == 'SUCCESS') {
$data[$k]['corporate_status'] = 'Y';
}
$data[$k]['Ais_CorporateStatus'] = $qry_corporate->row()->Ais_CorporateStatus;
$data[$k]['Ais_CorporateID'] = $qry_corporate->row()->Ais_CorporateID;
}
}
}
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data monitoring.',
'data' => $data,
'total' => $total,
'page' => $page,
'limit' => $limit,
'total_page' => ceil($total / $limit)
]);
exit;
}
function get_json_response()
{
// Ambil corporate_code dari query parameter
$corporate_code = $this->input->get('corporate_code');
if (empty($corporate_code)) {
return $this->output
->set_status_header(400)
->set_content_type('application/json')
->set_output(json_encode([
'status' => 'error',
'message' => 'corporate_code parameter is required'
]));
}
$sql = "SELECT
Ais_CorporateID AS id,
Ais_CorporateCorporateCode AS corporate_code,
Ais_CorporateJSON AS json,
Ais_CorporateStatus AS status,
Ais_CorporateResponse AS response,
Ais_CorporateLastUpdate AS last_update,
Ais_CorporateUserID AS user_id
FROM ais_corporate
WHERE Ais_CorporateCorporateCode = ?
ORDER BY Ais_CorporateLastUpdate DESC";
// Query ke database LOG
$qry = $this->db_log->query($sql, [$corporate_code]);
$results = $qry->result_array();
if ($results) {
foreach ($results as &$r) {
$r['json'] = json_decode($r['json']);
$r['response'] = json_decode($r['response']);
}
unset($r);
return $this->output
->set_content_type('application/json')
->set_output(json_encode([
'status' => 'success',
'data' => $results
]));
}
return $this->output
->set_content_type('application/json')
->set_output(json_encode([
'status' => 'error',
'message' => "No data found for corporate_code: $corporate_code"
]));
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,421 @@
<?php
class Packet extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Resultentry API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_log = $this->load->database("log", true);
$this->load->helper(array('form', 'url'));
}
public function error_log($data, $userid = 999)
{
$sql = "INSERT INTO ais_error_log (
AisErrorLogFnName,
AisErrorLogMessage,
AisErrorLogQuery,
AisErrorLogJson,
AisErrorLogUserID,
AisErrorLogCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($data['fn_name'], $data['message'], $data['query'], $data['json'], $userid));
//echo $this->db_log->last_query();
return true;
}
/**
* Generic POST request function
* @param string $url API endpoint URL
* @param array $data Request payload
* @param array $headers Custom headers (optional)
* @return array Response from API
*/
public function post_request($url, $data = array(), $headers = array())
{
// Default headers
$default_headers = array(
'Content-Type: application/json'
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
} else {
$result = json_decode($response, true);
if ($result['status'] == 200) {
$result['success'] = true;
} else {
$result['success'] = false;
}
}
return $result;
}
public function get_request($url, $headers = array())
{
// Retrieve configuration
$config = $this->get_config();
$token = $config['AisConfigAuthToken'] ?? 'default-token';
$header_token = $config['AisConfigHeaderToken'];
// Default headers based on the curl command
$default_headers = array(
'Header-Token: ' . $header_token,
'Authorization: Bearer ' . $token
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
} else {
$decoded = json_decode($response, true);
$result['response'] = $decoded;
// Check if response is successful based on http code
if ($http_code === 200) {
$result['success'] = true;
}
}
return $result;
}
function get_config()
{
$sql = "SELECT * FROM ais_config LIMIT 1";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->error_log(array('fn_name' => 'get_config', 'message' => 'ais_config select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$dt_config = $qry->row_array();
return $dt_config;
}
/**
* POST request to auth API
* @param string $username Username for authentication
* @param string $password Password for authentication
* @return array Response from API
*/
public function post_auth()
{
$dt_config = $this->get_config();
$baseUrl = $dt_config['AisConfigBaseUrl'];
$url = $baseUrl . '/api/auth/auth.php';
$headers = array(
'Header-Token: ' . $dt_config['AisConfigHeaderToken']
);
$username = $dt_config['AisConfigUsername'];
$password = $dt_config['AisConfigPassword'];
$data = array(
'username' => $username,
'password' => $password
);
$result = $this->post_request($url, $data, $headers);
$sql = "INSERT INTO ais_login_log(
AisLoginLogUsername,
AisLoginLogPassword,
AisLoginLogHeaderToken,
AisLoginLogResult,
AisLoginLogCreated
)
VALUES(
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($username, $password, $dt_config['AisConfigHeaderToken'], json_encode($result)));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'ais_login_log insert', 'query' => $this->db_log->last_query(), 'json' => json_encode($result)), 999);
exit;
}
//print_r($result);
//exit;
// Check if success
if (!$result['success']) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($result)), 999);
$errors = array('status' => 'error', 'message' => 'Gagal Login');
echo json_encode($errors);
exit;
} else {
// Update token
$token = $result['data']['token'];
;
$sql = "UPDATE ais_config SET AisConfigAuthToken = ? WHERE AisConfigID = 1";
$qry = $this->db_onedev->query($sql, array($token));
//echo $this->db_onedev->last_query();
//exit;
if (!$qry) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'ais_config update', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
$errors = array('status' => 'error', 'message' => 'Gagal Update Token');
echo json_encode($errors);
exit;
}
//$success = array('status' => 'success', 'message' => 'Berhasil Login', 'token' => $token);
return $token;
}
}
/**
* POST request to jenis layanan API
* @param array $data Array of jenis layanan data
* @return array Response from API
*/
function monitoring_packet()
{
$sql_base = "SELECT
p.T_PacketID,
p.T_PacketName AS packet_name,
p.T_PacketType,
p.T_PacketPrice,
p.T_PacketSasCode AS packet_code,
p.T_PacketStartDate,
p.T_PacketEndDate,
ph.T_PriceHeaderID,
ph.T_PriceHeaderName AS priceheader_name,
ph.T_PriceHeaderCode AS priceheader_code,
ph.T_PriceHeaderStartDate,
ph.T_PriceHeaderEndDate,
ap.Ais_PacketStatus AS Ais_PacketStatus,
IF(MAX(ap.Ais_PacketID) IS NULL, 'N', 'Y') AS packet_status
FROM t_packet p
JOIN t_priceheader ph
ON ph.T_PriceHeaderID = p.T_PacketT_PriceHeaderID
LEFT JOIN ".$this->db_log->database.".ais_packet ap
ON ap.Ais_PacketT_PacketSasCode = p.T_PacketSasCode
";
// Ambil parameter
$packet_name = $this->input->get('packet_name');
$packet_code = $this->input->get('packet_code');
$priceheader_name = $this->input->get('priceheader_name');
$priceheader_code = $this->input->get('priceheader_code');
$packet_status = $this->input->get('packet_status'); // Y / N
// Pagination
$page = $this->input->get('page') ? intval($this->input->get('page')) : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$params = [];
$where_clauses = [];
// Status packet Y/N dari ais_packet
if ($packet_status === 'Y') {
$where_clauses[] = "ap.Ais_PacketID IS NOT NULL";
} elseif ($packet_status === 'N') {
$where_clauses[] = "ap.Ais_PacketID IS NULL";
}
// Filter by packet name
if ($packet_name) {
$where_clauses[] = "p.T_PacketName LIKE ?";
$params[] = "%$packet_name%";
}
// Filter by packet code
if ($packet_code) {
$where_clauses[] = "p.T_PacketSasCode LIKE ?";
$params[] = "%$packet_code%";
}
// Filter by priceheader name
if ($priceheader_name) {
$where_clauses[] = "ph.T_PriceHeaderName LIKE ?";
$params[] = "%$priceheader_name%";
}
// Filter by priceheader code
if ($priceheader_code) {
$where_clauses[] = "ph.T_PriceHeaderCode LIKE ?";
$params[] = "%$priceheader_code%";
}
// Build WHERE
$where_sql = "";
if (!empty($where_clauses)) {
$where_sql = " WHERE " . implode(" AND ", $where_clauses);
}
// Count total records for pagination
// Count distinct packet ID
$count_sql = "
SELECT COUNT(*) AS total
FROM (
SELECT p.T_PacketID
FROM t_packet p
JOIN t_priceheader ph
ON ph.T_PriceHeaderID = p.T_PacketT_PriceHeaderID
LEFT JOIN ".$this->db_log->database.".ais_packet ap
ON ap.Ais_PacketT_PacketSasCode = p.T_PacketSasCode
$where_sql
GROUP BY p.T_PacketID
) AS x
";
$qry_count = $this->db_onedev->query($count_sql, $params);
$total = $qry_count->row()->total ?? 0;
// Main SQL
$sql = $sql_base . $where_sql . "
GROUP BY p.T_PacketID
ORDER BY p.T_PacketID ASC
LIMIT $limit OFFSET $offset";
$qry = $this->db_onedev->query($sql, $params);
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data monitoring packet.']);
exit;
}
$data = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data monitoring packet.',
'data' => $data,
'total' => $total,
'page' => $page,
'limit' => $limit,
'total_page' => ceil($total / $limit)
]);
exit;
}
function get_json_response()
{
$packet_code = $this->input->get('packet_code');
if (empty($packet_code)) {
return $this->output
->set_status_header(400)
->set_content_type('application/json')
->set_output(json_encode([
'status' => 'error', 'message' => 'packet_code parameter is required']));
}
$sql = "SELECT
Ais_PacketT_PacketSasCode AS packet_code,
Ais_PacketLastUpdated AS packet_update,
Ais_PacketJson AS packet_json,
Ais_PacketStatus AS status,
Ais_PacketResponse AS packet_response
FROM ais_packet
WHERE Ais_PacketT_PacketSasCode = ?
ORDER BY Ais_PacketLastUpdated DESC";
// Query ke database LOG
$qry = $this->db_log->query($sql, array($packet_code));
$results = $qry->row_array();
$results = $qry->result_array();
if ($results) {
// Loop through each result to decode JSON
foreach ($results as &$result) {
$result['packet_json'] = json_decode($result['packet_json']);
$result['packet_response'] = json_decode($result['packet_response']);
}
unset($result); // Unset reference to avoid side effects
echo json_encode(['status' => 'success', 'data' => $results]);
} else {
echo json_encode(['status' => 'error', 'message' => 'Data not found for the given sas code.']);
}
exit;
}
}

View File

@@ -0,0 +1,433 @@
<?php
class Packet extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Resultentry API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_log = $this->load->database("log", true);
$this->load->helper(array('form', 'url'));
}
public function error_log($data, $userid = 999)
{
$sql = "INSERT INTO ais_error_log (
AisErrorLogFnName,
AisErrorLogMessage,
AisErrorLogQuery,
AisErrorLogJson,
AisErrorLogUserID,
AisErrorLogCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($data['fn_name'], $data['message'], $data['query'], $data['json'], $userid));
//echo $this->db_log->last_query();
return true;
}
/**
* Generic POST request function
* @param string $url API endpoint URL
* @param array $data Request payload
* @param array $headers Custom headers (optional)
* @return array Response from API
*/
public function post_request($url, $data = array(), $headers = array())
{
// Default headers
$default_headers = array(
'Content-Type: application/json'
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
}
else {
$result = json_decode($response, true);
if ($result['status'] == 200) {
$result['success'] = true;
}
else {
$result['success'] = false;
}
}
return $result;
}
public function get_request($url, $headers = array())
{
// Retrieve configuration
$config = $this->get_config();
$token = $config['AisConfigAuthToken'] ?? 'default-token';
$header_token = $config['AisConfigHeaderToken'];
// Default headers based on the curl command
$default_headers = array(
'Header-Token: ' . $header_token,
'Authorization: Bearer ' . $token
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
}
else {
$decoded = json_decode($response, true);
$result['response'] = $decoded;
// Check if response is successful based on http code
if ($http_code === 200) {
$result['success'] = true;
}
}
return $result;
}
function get_config()
{
$sql = "SELECT * FROM ais_config LIMIT 1";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->error_log(array('fn_name' => 'get_config', 'message' => 'ais_config select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$dt_config = $qry->row_array();
return $dt_config;
}
/**
* POST request to auth API
* @param string $username Username for authentication
* @param string $password Password for authentication
* @return array Response from API
*/
public function post_auth()
{
$dt_config = $this->get_config();
$baseUrl = $dt_config['AisConfigBaseUrl'];
$url = $baseUrl . '/api/auth/auth.php';
$headers = array(
'Header-Token: ' . $dt_config['AisConfigHeaderToken']
);
$username = $dt_config['AisConfigUsername'];
$password = $dt_config['AisConfigPassword'];
$data = array(
'username' => $username,
'password' => $password
);
$result = $this->post_request($url, $data, $headers);
$sql = "INSERT INTO ais_login_log(
AisLoginLogUsername,
AisLoginLogPassword,
AisLoginLogHeaderToken,
AisLoginLogResult,
AisLoginLogCreated
)
VALUES(
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($username, $password, $dt_config['AisConfigHeaderToken'], json_encode($result)));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'ais_login_log insert', 'query' => $this->db_log->last_query(), 'json' => json_encode($result)), 999);
exit;
}
//print_r($result);
//exit;
// Check if success
if (!$result['success']) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($result)), 999);
$errors = array('status' => 'error', 'message' => 'Gagal Login');
echo json_encode($errors);
exit;
}
else {
// Update token
$token = $result['data']['token'];
;
$sql = "UPDATE ais_config SET AisConfigAuthToken = ? WHERE AisConfigID = 1";
$qry = $this->db_onedev->query($sql, array($token));
//echo $this->db_onedev->last_query();
//exit;
if (!$qry) {
$this->error_log(array('fn_name' => 'post_auth', 'message' => 'ais_config update', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
$errors = array('status' => 'error', 'message' => 'Gagal Update Token');
echo json_encode($errors);
exit;
}
//$success = array('status' => 'success', 'message' => 'Berhasil Login', 'token' => $token);
return $token;
}
}
/**
* POST request to jenis layanan API
* @param array $data Array of jenis layanan data
* @return array Response from API
*/
function monitoring_packet()
{
// Ambil parameter
$packet_name = $this->input->get('packet_name');
$packet_code = $this->input->get('packet_code');
$priceheader_name = $this->input->get('priceheader_name');
$priceheader_code = $this->input->get('priceheader_code');
$packet_status = $this->input->get('packet_status'); // Y / N
// Pagination
$page = $this->input->get('page') ? intval($this->input->get('page')) : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$params = [];
$where_clauses = [];
$sql = "SELECT
p.T_PacketID,
p.T_PacketName AS packet_name,
p.T_PacketType,
p.T_PacketPrice,
p.T_PacketSasCode AS packet_code,
p.T_PacketStartDate,
p.T_PacketEndDate,
ph.T_PriceHeaderID,
ph.T_PriceHeaderName AS priceheader_name,
ph.T_PriceHeaderCode AS priceheader_code,
ph.T_PriceHeaderStartDate,
ph.T_PriceHeaderEndDate,
ap.Ais_PacketStatus AS Ais_PacketStatus,
'' AS packet_status
FROM t_packet p
JOIN t_priceheader ph
ON ph.T_PriceHeaderID = p.T_PacketT_PriceHeaderID AND t_packetIsActive = 'Y'
LEFT JOIN " . $this->db_log->database . ".ais_packet ap
ON ap.Ais_PacketT_PacketSasCode = p.T_PacketSasCode
";
// Status packet Y/N dari ais_packet
if ($packet_status === 'Y') {
$where_clauses[] = "ap.Ais_PacketID IS NOT NULL";
}
elseif ($packet_status === 'N') {
$where_clauses[] = "ap.Ais_PacketID IS NULL";
}
// Filter by packet name
if ($packet_name) {
$where_clauses[] = "p.T_PacketName LIKE ?";
$params[] = "%$packet_name%";
}
// Filter by packet code
if ($packet_code) {
$where_clauses[] = "p.T_PacketSasCode LIKE ?";
$params[] = "%$packet_code%";
}
// Filter by priceheader name
if ($priceheader_name) {
$where_clauses[] = "ph.T_PriceHeaderName LIKE ?";
$params[] = "%$priceheader_name%";
}
// Filter by priceheader code
if ($priceheader_code) {
$where_clauses[] = "ph.T_PriceHeaderCode LIKE ?";
$params[] = "%$priceheader_code%";
}
// Tambahkan WHERE jika ada klausa
if (!empty($where_clauses)) {
$sql .= " WHERE " . implode(" AND ", $where_clauses);
}
// Hitung total data
$sql_count = "SELECT COUNT(*) as total FROM t_packet p
JOIN t_priceheader ph
ON ph.T_PriceHeaderID = p.T_PacketT_PriceHeaderID AND t_packetIsActive = 'Y'
LEFT JOIN " . $this->db_log->database . ".ais_packet ap
ON ap.Ais_PacketT_PacketSasCode = p.T_PacketSasCode
";
if (!empty($where_clauses)) {
$sql_count .= " WHERE " . implode(" AND ", $where_clauses);
}
$qry_count = $this->db_onedev->query($sql_count, $params);
$total = $qry_count->row()->total;
// Tambahkan pagination
$sql .= " LIMIT ? OFFSET ?";
$params[] = $limit;
$params[] = $offset;
$qry = $this->db_onedev->query($sql, $params);
if (!$qry) {
$this->error_log(array('fn_name' => 'monitoring_packet', 'message' => 't_packet select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
$errors = array('status' => 'error', 'message' => 'Gagal mengambil data monitoring packet.');
echo json_encode($errors);
exit;
}
$data = $qry->result_array();
// Format data
foreach ($data as &$row) {
$row['T_PacketStartDate'] = $row['T_PacketStartDate'] ? date('Y-m-d', strtotime($row['T_PacketStartDate'])) : null;
$row['T_PacketEndDate'] = $row['T_PacketEndDate'] ? date('Y-m-d', strtotime($row['T_PacketEndDate'])) : null;
$row['T_PriceHeaderStartDate'] = $row['T_PriceHeaderStartDate'] ? date('Y-m-d', strtotime($row['T_PriceHeaderStartDate'])) : null;
$row['T_PriceHeaderEndDate'] = $row['T_PriceHeaderEndDate'] ? date('Y-m-d', strtotime($row['T_PriceHeaderEndDate'])) : null;
}
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data monitoring packet.',
'data' => $data,
'total' => $total,
'page' => $page,
'limit' => $limit,
'total_page' => ceil($total / $limit)
]);
exit;
}
function get_json_response()
{
$packet_code = $this->input->get('packet_code');
if (empty($packet_code)) {
return $this->output
->set_status_header(400)
->set_content_type('application/json')
->set_output(json_encode([
'status' => 'error', 'message' => 'packet_code parameter is required']));
}
$sql = "SELECT
Ais_PacketT_PacketSasCode AS packet_code,
Ais_PacketLastUpdated AS packet_update,
Ais_PacketJson AS packet_json,
Ais_PacketStatus AS status,
Ais_PacketResponse AS packet_response
FROM ais_packet
WHERE Ais_PacketT_PacketSasCode = ?
ORDER BY Ais_PacketLastUpdated DESC";
// Query ke database LOG
$qry = $this->db_log->query($sql, array($packet_code));
$results = $qry->row_array();
$results = $qry->result_array();
if ($results) {
// Loop through each result to decode JSON
foreach ($results as &$result) {
$result['packet_json'] = json_decode($result['packet_json']);
$result['packet_response'] = json_decode($result['packet_response']);
}
unset($result); // Unset reference to avoid side effects
echo json_encode(['status' => 'success', 'data' => $results]);
}
else {
echo json_encode(['status' => 'error', 'message' => 'Data not found for the given sas code.']);
}
exit;
}
}

View File

@@ -0,0 +1,269 @@
<?php
class Test extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Transaction API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_log = $this->load->database("log", true);
$this->load->helper(array('form', 'url'));
}
/**
* Generic POST request function
* @param string $url API endpoint URL
* @param array $data Request payload
* @param array $headers Custom headers (optional)
* @return array Response from API
*/
/**
* Generic PUT request function
* @param string $url API endpoint URL
* @param array $data Request payload
* @param array $headers Custom headers (optional)
* @return array Response from API
*/
/**
* POST request to auth API
* @param string $username Username for authentication
* @param string $password Password for authentication
* @return array Response from API
*/
public function post_auth()
{
$dt_config = $this->get_config();
$baseUrl = $dt_config['AisConfigBaseUrl'];
$url = $baseUrl.'/api/auth/auth.php';
$headers = array(
'Header-Token: '.$dt_config['AisConfigHeaderToken']
);
$username = $dt_config['AisConfigUsername'];
$password = $dt_config['AisConfigPassword'];
$data = array(
'username' => $username,
'password' => $password
);
$result = $this->post_request($url, $data, $headers);
$sql = "INSERT INTO ais_login_log(
AisLoginLogUsername,
AisLoginLogPassword,
AisLoginLogHeaderToken,
AisLoginLogResult,
AisLoginLogCreated
)
VALUES(
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($username,$password,$dt_config['AisConfigHeaderToken'],json_encode($result)));
if(!$qry){
$this->error_log(array('fn_name'=>'post_auth','message'=>'ais_login_log insert','query'=>$sql,'json'=>json_encode($result)),999);
exit;
}
//print_r($result);
//exit;
// Check if success
if(!$result['success']){
$this->error_log(array('fn_name'=>'post_auth','message'=>'failed auth','query'=>'','json'=>json_encode($result)),999);
$errors = array('status' => 'error','message' => 'Gagal Login');
return $errors;
}else{
// Update token
$token = $result['data']['token'];;
$sql = "UPDATE ais_config SET AisConfigAuthToken = ? WHERE AisConfigID = 1";
$qry = $this->db_onedev->query($sql, array($token));
//echo $this->db_onedev->last_query();
//exit;
if(!$qry){
$this->error_log(array('fn_name'=>'post_auth','message'=>'ais_config update','query'=>$sql,'json'=>''),999);
$errors = array('status' => 'error','message' => 'Gagal Update Token');
return $errors;
}
return $result;
}
}
function monitoring_test()
{
// SQL base
$sql_base = "SELECT
t.T_TestID,
t.T_TestCode AS test_code,
t.T_TestSasCode AS sas_code,
t.T_TestName AS test_name,
t.T_TestIsPrice AS is_price,
t.T_TestIsResult AS is_result,
t.T_TestIsActive AS test_active,
at.Ais_TestStatus AS Ais_TestStatus,
at.Ais_TestLastUpdate AS test_last_update,
IF (at.Ais_TestID IS NULL, 'N', 'Y') AS test_status
FROM t_test t
LEFT JOIN (
SELECT Ais_TestTestSasCode, Ais_TestStatus, Ais_TestLastUpdate, Ais_TestID
FROM ".$this->db_log->database.".ais_test
WHERE Ais_TestStatus = 'success'
) at
ON at.Ais_TestTestSasCode = t.T_TestSasCode
";
// Ambil parameter
$test_name = $this->input->get('test_name'); // TRUE for XSS filtering
$sas_code = $this->input->get('sas_code');
$test_code = $this->input->get('test_code');
$test_status = $this->input->get('test_status');
// Pagination
$page = $this->input->get('page') ? intval($this->input->get('page')) : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$params = [];
$where_clauses = [
"t.T_TestIsActive = 'Y'"
];
// Status filter
if ($test_status === 'Y') {
$where_clauses[] = "at.Ais_TestID IS NOT NULL";
} elseif ($test_status === 'N') {
$where_clauses[] = "at.Ais_TestID IS NULL";
}
if ($test_name) {
$where_clauses[] = "t.T_TestName LIKE ?";
$params[] = "%$test_name%";
}
if ($test_code) {
$where_clauses[] = "t.T_TestCode LIKE ?";
$params[] = "%$test_code%";
}
if ($sas_code) {
$where_clauses[] = "t.T_TestSasCode LIKE ?";
$params[] = "%$sas_code%";
}
$where_sql = "";
if (!empty($where_clauses)) {
$where_sql = " WHERE " . implode(" AND ", $where_clauses);
}
// COUNT
$count_sql = "
SELECT COUNT(*) AS total
FROM (
SELECT t.T_TestID
FROM t_test t
LEFT JOIN (
SELECT Ais_TestTestSasCode, Ais_TestID
FROM ".$this->db_log->database.".ais_test
WHERE Ais_TestStatus = 'success'
) at
ON at.Ais_TestTestSasCode = t.T_TestSasCode
$where_sql
GROUP BY t.T_TestID
) AS x
";
$qry_count = $this->db_onedev->query($count_sql, $params);
$total = $qry_count->row()->total ?? 0;
// MAIN QUERY
$sql = $sql_base . $where_sql . "
GROUP BY t.T_TestID
ORDER BY t.T_TestID ASC
LIMIT $limit OFFSET $offset";
$qry = $this->db_onedev->query($sql, $params);
// if (!$qry) {
// $this->output
// ->set_content_type('application/json')
// ->set_output(json_encode(['status' => 'error', 'message' => 'Gagal mengambil data monitoring.']));
// return;
// }
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data monitoring.']);
exit;
}
$data = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data monitoring.',
'data' => $data,
'total' => $total,
'page' => $page,
'limit' => $limit,
'total_page' => ceil($total / $limit)
]);
exit;
}
function get_json_response()
{
$sas_code = $this->input->get('sas_code');
if (empty($sas_code)) {
return $this->output
->set_status_header(400)
->set_content_type('application/json')
->set_output(json_encode([
'status' => 'error',
'message' => 'sas_code parameter is required'
]));
}
$sql = "SELECT
Ais_TestID AS id,
Ais_TestTestSasCode AS sas_code,
Ais_TestJSON AS test_json,
Ais_TestStatus AS test_status,
Ais_TestResponse AS test_response,
Ais_TestLastUpdate AS test_last_update
FROM ais_test
WHERE Ais_TestTestSasCode = ?
ORDER BY Ais_TestLastUpdate DESC";
// Query ke database LOG
$qry = $this->db_log->query($sql, [$sas_code]);
$results = $qry->row_array();
$results = $qry->result_array();
if ($results) {
// Loop through each result to decode JSON
foreach ($results as &$result) {
$result['packet_json'] = json_decode($result['packet_json']);
$result['packet_response'] = json_decode($result['packet_response']);
}
unset($result); // Unset reference to avoid side effects
echo json_encode(['status' => 'success', 'data' => $results]);
} else {
echo json_encode(['status' => 'error', 'message' => 'Data not found for the given sas code.']);
}
exit;
}
}

View File

@@ -0,0 +1,761 @@
<?php
class Transaction extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Transaction API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_log = $this->load->database("log", true);
$this->load->helper(array('form', 'url'));
}
public function error_log($data,$userid=999)
{
$sql = "INSERT INTO ais_error_log (
AisErrorLogFnName,
AisErrorLogMessage,
AisErrorLogQuery,
AisErrorLogJson,
AisErrorLogUserID,
AisErrorLogCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($data['fn_name'],$data['message'],$data['query'],$data['json'],$userid));
//echo $this->db_log->last_query();
return true;
}
/**
* Generic POST request function
* @param string $url API endpoint URL
* @param array $data Request payload
* @param array $headers Custom headers (optional)
* @return array Response from API
*/
public function post_request($url, $data = array(), $headers = array())
{
// Default headers
$default_headers = array(
'Content-Type: application/json'
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
} else {
$result = json_decode($response, true);
$result['success'] = true;
}
return $result;
}
public function get_request($url, $headers = array())
{
// Retrieve configuration
$config = $this->get_config();
$token = $config['AisConfigAuthToken'] ?? 'default-token';
$header_token = $config['AisConfigHeaderToken'];
// Default headers based on the curl command
$default_headers = array(
'Header-Token: ' . $header_token,
'Authorization: Bearer ' . $token
);
// Merge custom headers with default headers
$final_headers = array_merge($default_headers, $headers);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $final_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Execute cURL request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Prepare result
$result = array(
'success' => false,
'http_code' => $http_code,
'response' => null,
'error' => null
);
if ($error) {
$result['error'] = $error;
} else {
$decoded = json_decode($response, true);
$result['response'] = $decoded;
// Check if response is successful based on http code
if ($http_code === 200) {
$result['success'] = true;
}
}
return $result;
}
function get_config()
{
$sql = "SELECT * FROM ais_config LIMIT 1";
$qry = $this->db_onedev->query($sql);
$dt_config = $qry->row_array();
return $dt_config;
}
/**
* POST request to auth API
* @param string $username Username for authentication
* @param string $password Password for authentication
* @return array Response from API
*/
public function post_auth()
{
$dt_config = $this->get_config();
$baseUrl = $dt_config['AisConfigBaseUrl'];
$url = $baseUrl.'/api/auth/auth.php';
$headers = array(
'Header-Token: '.$dt_config['AisConfigHeaderToken']
);
$username = $dt_config['AisConfigUsername'];
$password = $dt_config['AisConfigPassword'];
$data = array(
'username' => $username,
'password' => $password
);
$result = $this->post_request($url, $data, $headers);
$sql = "INSERT INTO ais_login_log(
AisLoginLogUsername,
AisLoginLogPassword,
AisLoginLogHeaderToken,
AisLoginLogResult,
AisLoginLogCreated
)
VALUES(
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array($username,$password,$dt_config['AisConfigHeaderToken'],json_encode($result)));
if(!$qry){
$this->error_log(array('fn_name'=>'post_auth','message'=>'ais_login_log insert','query'=>$sql,'json'=>json_encode($result)),999);
exit;
}
//print_r($result);
//exit;
// Check if success
if(!$result['success']){
$this->error_log(array('fn_name'=>'post_auth','message'=>'failed auth','query'=>'','json'=>json_encode($result)),999);
$errors = array('status' => 'error','message' => 'Gagal Login');
return $errors;
}else{
// Update token
$token = $result['data']['token'];;
$sql = "UPDATE ais_config SET AisConfigAuthToken = ? WHERE AisConfigID = 1";
$qry = $this->db_onedev->query($sql, array($token));
//echo $this->db_onedev->last_query();
//exit;
if(!$qry){
$this->error_log(array('fn_name'=>'post_auth','message'=>'ais_config update','query'=>$sql,'json'=>''),999);
$errors = array('status' => 'error','message' => 'Gagal Update Token');
return $errors;
}
return $result;
}
}
function post_transaction($labnum='',$xdate=null)
{
// Auth Login
$login = $this->post_auth();
if (!$login['success']) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 555);
$errors = array('status' => 'error', 'message' => 'Gagal Login');
echo json_encode($errors);
exit;
}
// Get config
$dt_config = $this->get_config();
$baseUrl = $dt_config['AisConfigBaseUrl'];
$url = $baseUrl . '/api/transaction_full/transaksi.php';
$headers = array(
'Header-Token: ' . $dt_config['AisConfigHeaderToken'],
'Authorization: Bearer ' . $dt_config['AisConfigAuthToken']
);
if($labnum == ''){
$xdate = $xdate == null ? date('Y-m-d') : $xdate;
}
// Get data
$sql = "SELECT T_OrderHeaderID,
T_OrderHeaderTotal as Total,
T_OrderHeaderLabNumber as RegID,
Mgm_McuM_BranchID as mgm_mcu_m_branch_id,
M_PatientNoReg as MEDRECID,
T_OrderHeaderDate as Tanggal,
T_OrderHeaderDate as PulangTanggal,
IF(Mgm_McuM_BranchID = 100,'',CorporateCode) as PerusahaanID,
IF(Mgm_McuM_BranchID = 100,'',CorporateCode) as AsuransiID,
T_PriceHeaderCode as GroupTarifID,
M_PatientName as Nama,
M_PatientIdentifierValue as NIK,
DATE_FORMAT(M_PatientDOB, '%Y-%m-%d %H:%i:%s') as TglLahir,
IF(M_PatientGender = 'male','L','P') as JnsKelamin,
'' as NomorPolis,
'' as NomerJaminan,
'2' as JenisRegID,
IF(Mgm_McuM_BranchID = 100,0,1) as JenisPasienID,
'LAB-WESTERINDO-01' as DepartemenID,
'Y' as Pulang,
'Y' as BolehPulang,
'' as Catatan,
'Y' as Verified,
'LABKLINIK' as KelasID,
M_UserEmail as LoginBuat,
T_OrderHeaderCreated as TanggalBuat,
branch_order.M_BranchAis_branch_code as BranchCode,
CorporateTypeais_pillar_code as PillarCode,
'4569' as SiteCenterCode,
M_UserEmail as VerifiedBy,
T_OrderHeaderCreated as VerifiedDate,
'' as TrxLayanan,
'' as TrxItem,
'' as TrxItemReturn,
'' as RegpasNominal,
'' as Trxtt,
'' as TrxBayar,
'' as TrxLain,
'' as PaketDispenser
FROM t_orderheader
JOIN m_branch branch_order ON branch_order.M_BranchID = T_OrderHeaderM_BranchID
JOIN m_patient ON M_PatientID = T_OrderHeaderM_PatientID
JOIN corporate ON CorporateID = T_OrderHeaderCorporateID
JOIN corporate_type ON CorporateTypeID = CorporateTypeID
JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID -- AND Mgm_McuID = 1566
JOIN t_priceheader ON Mgm_McuT_PriceHeaderID = T_PriceHeaderID
JOIN m_user ON T_OrderHeaderCreatedUserID = M_UserID
LEFT JOIN cpone_log.ais_transaction ON Ais_TransactionOrderHeaderLabNumber = T_OrderHeaderLabNumber AND
Ais_TransactionStatus = 'success'
WHERE T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderLabNumber = ? AND
Ais_TransactionID IS NULL
GROUP BY T_OrderHeaderID
LIMIT 100";
$qry = $this->db_onedev->query($sql, array($labnum));
//echo $this->db_onedev->last_query();
//exit;
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 't_orderheader select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$raw_data = $qry->result_array();
$data = array();
foreach ($raw_data as $key => $row) {
$row['TrxLayanan'] = [];
$row['TrxItem'] = [];
$row['TrxItemReturn'] = [];
$row['RegpasNominal'] = [];
$row['Trxtt'] = null;
$row['TrxBayar'] = [];
$row['TrxLain'] = null;
$row['PaketDispenser'] = null;
$layanan = [];
$sql = "SELECT * FROM (
SELECT T_OrderDetailID as TrxLayananID,
case
when Nat_GroupID = 1 then '1100'
when Nat_GroupID = 2 then '1200'
when Nat_GroupID = 3 then '1200'
when Nat_GroupID = 4 then '1303'
end as ProfitCostCenterCode,
'' as TrxDepartemenID,
T_OrderDetailCreated as TanggalBuat,
T_OrderDetailT_TestSasCode as LayananID,
T_OrderDetailT_TestName as LayananName,
doctorlab.M_DoctorCode as DokterID,
0 as ShareRS,
0 as ShareDokter,
0 as ShareExternal,
0 as ShareLain2,
'' as PihakExternal,
'' as PihakLain2,
'Percentage' as ShareTipe,
T_OrderDetailPrice as Harga,
1 as Jumlah,
1 as Rate,
'N' as FOC,
T_OrderDetailDiscTotal as Diskon,
'Absolute' as TipeDiskon,
'' as DepartemenID,
IF(Mgm_McuM_BranchID = 100,T_OrderDetailTotal,0) as DitanggungPasien,
IF(Mgm_McuM_BranchID = 100,0,T_OrderDetailTotal) as DitanggungPenjamin,
0 as MarkUpCito,
'N' as Cito,
T_PacketSasCode as PaketID,
'LABKLINIK' as KelasID,
'' as TrxLayananDetail,
'Y' as Tagihkan
FROM t_orderdetail
JOIN t_test ON T_TestID = T_OrderDetailT_TestID AND T_TestIsActive = 'Y'
JOIN nat_test ON T_TestNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y'
JOIN nat_group ON Nat_GroupID = Nat_TestNat_GroupID AND Nat_GroupIsActive = 'Y'
JOIN t_orderdetailorder ON T_OrderDetailT_OrderDetailOrderID = T_OrderDetailOrderID AND
T_OrderDetailOrderIsPacket = 'Y' AND T_OrderDetailOrderIsActive = 'Y'
JOIN t_packet ON T_OrderDetailOrderT_PacketID = T_PacketID
JOIN t_packetdetail ON T_PacketDetailT_PacketID = T_PacketID AND T_PacketDetailT_TestID = T_OrderDetailT_TestID AND
T_PacketDetailIsActive = 'Y'
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailOrderT_OrderHeaderID
JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID
JOIN m_doctor doctorlab ON T_OrderHeaderPjM_DoctorID = M_DoctorID
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = ? AND
T_OrderDetailIsActive = 'Y'
UNION
SELECT T_OrderDetailID as TrxLayananID,
Nat_GroupID as ProfitCostCenterCode,
'' as TrxDepartemenID,
T_OrderDetailCreated as TanggalBuat,
T_OrderDetailT_TestSasCode as LayananID,
T_OrderDetailT_TestName as LayananName,
doctorlab.M_DoctorCode as DokterID,
0 as ShareRS,
0 as ShareDokter,
0 as ShareExternal,
0 as ShareLain2,
'' as PihakExternal,
'' as PihakLain2,
'Percentage' as ShareTipe,
T_OrderDetailPrice as Harga,
1 as Jumlah,
1 as Rate,
'N' as FOC,
T_OrderDetailDiscTotal as Diskon,
'Absolute' as TipeDiskon,
'' as DepartemenID,
IF(Mgm_McuM_BranchID = 100,T_OrderDetailTotal,0) as DitanggungPasien,
IF(Mgm_McuM_BranchID = 100,0,T_OrderDetailTotal) as DitanggungPenjamin,
0 as MarkUpCito,
'N' as Cito,
'' as PaketID,
'LABKLINIK' as KelasID,
NULL as TrxLayananDetail,
'Y' as Tagihkan
FROM `t_orderdetailorder`
JOIN t_orderdetail ON T_OrderdetailT_OrderHeaderID = T_OrderDetailOrderT_OrderHeaderID AND
T_OrderDetailIsActive = 'Y' AND T_OrderDetailT_OrderDetailOrderID = T_OrderDetailOrderID
JOIN t_test ON T_TestID = T_OrderDetailT_TestID AND T_TestIsActive = 'Y'
JOIN nat_test ON T_TestNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y'
JOIN nat_group ON Nat_GroupID = Nat_TestNat_GroupID AND Nat_GroupIsActive = 'Y'
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailOrderT_OrderHeaderID
JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID
JOIN m_doctor doctorlab ON T_OrderHeaderPjM_DoctorID = M_DoctorID
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
WHERE `T_OrderDetailOrderT_OrderHeaderID` = ? AND `T_OrderDetailOrderIsPacket` = 'N' AND
T_OrderDetailOrderIsActive = 'Y'
) AS t_orderdetailorder";
$qry = $this->db_onedev->query($sql, array($row['T_OrderHeaderID'],$row['T_OrderHeaderID']));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 't_orderdetail select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$total_layanan_debug = 0;
$layanan = $qry->result_array();
$raw_data[$key]['TrxLayanan'] = [];
if(count($layanan) > 0){
foreach($layanan as $key_layanan => $row_layanan){
$total_layanan_debug += $row_layanan['Harga'];
$layanan[$key_layanan]['TrxLayananDetail'] = [];
$sql = "SELECT M_DoctorCode, M_DoctorID
FROM `so_resultentry`
JOIN t_orderdetail ON ? = So_ResultEntryT_OrderDetailID AND T_OrderDetailIsActive = 'Y'
JOIN m_doctor ON M_DoctorID = So_ResultEntryM_DoctorID AND M_DoctorIsActive = 'Y'
WHERE `So_ResultEntryT_OrderHeaderID` = ? AND
`So_ResultEntryIsActive` = 'Y' AND `So_ResultEntryM_DoctorID` > '0'
LIMIT 1
";
$qry = $this->db_onedev->query($sql, array($row_layanan['TrxLayananID'],$row['T_OrderHeaderID']));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 'so_resultentry select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$get_resultentry = $qry->result_array();
if (count($get_resultentry) > 0) {
$row_layanan['DokterID'] = $get_resultentry[0]['M_DoctorCode'];
}
$raw_data[$key]['TrxLayanan'][] = $row_layanan;
}
}
$regpasnominal = [];
$jumlah_layanan_lab = 0;
$sql = "SELECT IFNULL(SUM(T_OrderDetailTotal),0) as total_layanan_lab
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsActive = 'Y'
JOIN nat_test ON T_TestNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y'
JOIN nat_group ON Nat_GroupID = Nat_TestNat_GroupID AND Nat_GroupIsActive = 'Y' AND
Nat_GroupID = 1
WHERE T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
";
$qry = $this->db_onedev->query($sql, array($row['T_OrderHeaderID']));
//echo $this->db_onedev->last_query();
//exit;
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 't_orderdetail lab select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$get_layanan_lab = $qry->row_array();
$jumlah_layanan_lab = $get_layanan_lab['total_layanan_lab'];
$jumlah_layanan_radiologi = 0;
$sql = "SELECT IFNULL(SUM(T_OrderDetailTotal),0) as total_layanan_radiologi
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsActive = 'Y'
JOIN nat_test ON T_TestNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y'
JOIN nat_group ON Nat_GroupID = Nat_TestNat_GroupID AND Nat_GroupIsActive = 'Y' AND
Nat_GroupID = 3
WHERE T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
";
$qry = $this->db_onedev->query($sql, array($row['T_OrderHeaderID']));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 't_orderdetail radiologi select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$get_layanan_radiologi = $qry->row_array();
$jumlah_layanan_radiologi = $get_layanan_radiologi['total_layanan_radiologi'];
$jumlah_layanan_lain = 0;
$sql = "SELECT IFNULL(SUM(T_OrderDetailTotal),0) as total_layanan_lain
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsActive = 'Y'
JOIN nat_test ON T_TestNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y'
JOIN nat_group ON Nat_GroupID = Nat_TestNat_GroupID AND Nat_GroupIsActive = 'Y' AND
Nat_GroupID IN (2,4)
WHERE T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
";
$qry = $this->db_onedev->query($sql, array($row['T_OrderHeaderID']));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 't_orderdetail lain select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$get_layanan_lain = $qry->row_array();
$jumlah_layanan_lain = $get_layanan_lain['total_layanan_lain'];
$total_layanan = 0;
$sql = "SELECT SUM(T_OrderDetailTotal) as total_layanan, Mgm_McuM_BranchID as BranchID
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID
WHERE T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
";
$qry = $this->db_onedev->query($sql, array($row['T_OrderHeaderID']));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 't_orderdetail total layanan select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$total_layanan = $qry->row_array();
$total_layanan = $total_layanan['total_layanan'];
$total_bayar = 0;
$sql = "SELECT F_PaymentTotal as total
FROM f_payment
WHERE F_PaymentT_OrderHeaderID = ? AND F_PaymentIsActive = 'Y'
";
$qry = $this->db_onedev->query($sql, array($row['T_OrderHeaderID']));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 'f_payment select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
$get_total_bayar = $qry->result_array();
if (count($get_total_bayar) > 0) {
foreach($get_total_bayar as $key_total_bayar => $row_total_bayar){
$total_bayar += $row_total_bayar['total'];
}
}
$mgm_mcu_m_branch_id = $row['mgm_mcu_m_branch_id'];
$total_ditanggung_pasien = $mgm_mcu_m_branch_id == 100 ? $total_layanan : 0;
$total_ditanggung_penjamin = $mgm_mcu_m_branch_id == 100 ? 0 : $total_layanan;
$regpasnominal = array(
"BiayaParamedik" => "0.00",
"ParamedikDitanggungPasien" => "0.00",
"ParamedikDitanggungPenjamin" => "0.00",
"BiayaAdministrasi" => "0",
"AdmDitanggungPasien" => "0.00",
"AdmDitanggungPenjamin" => "0.00",
"BiayaMaterai" => "0.00",
"BiayaMateraiDitanggungPasien" => "0.00",
"BiayaMateraiDitanggungPenjamin" => "0.00",
"JumlahLayanan" => $jumlah_layanan_lain,
"JumlahLayananRadiologi" => $jumlah_layanan_radiologi,
"JumlahLayananLaboratorium" => $jumlah_layanan_lab,
"JumlahItem" => 0,
"JumlahItemRetur" => 0,
"JumlahTT" => "0.00",
"JumlahBiayaLain" => "0.00",
"JumlahBayar" => $total_bayar,
"TipeDiskonGlobal" => "Absolute",
"DiskonGlobal" => "0.00",
"TotalDitanggungPasien" => $total_ditanggung_pasien,
"TotalDitanggungPenjamin" => $total_ditanggung_penjamin
);
$raw_data[$key]['RegpasNominal'] = array(
$regpasnominal
);
//echo $total_bayar;
$raw_data[$key]['TrxBayar'] = null;
if($total_bayar > 0){
$sql = "SELECT M_PatientNoReg as MEDRECID,
F_PaymentDetailID as BayarID,
IFNULL(F_PaymentDetailAmount,0) as Jumlah,
F_PaymentDetailCreated as Tanggal,
'Pelunasan' as JenisBayarID,
CONCAT(F_PaymentNumber,'.',F_PaymentDetailID) as KwitansiID,
CONCAT(F_PaymentDetailM_PaymentTypeID,F_PaymentDetailM_BankAccountID) as TipeBayarID,
'N' as Dibatalkan
FROM f_paymentdetail
JOIN f_payment ON F_PaymentDetailF_PaymentID = F_PaymentID AND F_PaymentIsActive = 'Y'
JOIN t_orderheader ON F_PaymentT_OrderHeaderID = T_OrderHeaderID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
WHERE
F_PaymentT_OrderHeaderID = ? AND F_PaymentDetailIsActive = 'Y'
GROUP BY F_PaymentDetailID";
$qry = $this->db_onedev->query($sql, array($row['T_OrderHeaderID']));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 'f_payment select', 'query' => $this->db_onedev->last_query(), 'json' => ''), 999);
exit;
}
//echo $this->db_onedev->last_query();
//exit;
$bayar = $qry->result_array();
$raw_data[$key]['TrxBayar'] = $bayar;
}
$raw_data[$key]['Trxtt'] = null;
$raw_data[$key]['TrxLain'] = null;
$raw_data[$key]['PaketDispenser'] = null;
$errors = [];
//echo json_encode($raw_data[$key]);
//exit;
$result = $this->post_request($url, $raw_data[$key], $headers);
if ($result['status'] == '400') {
$sql = "INSERT INTO ais_transaction(
Ais_TransactionOrderHeaderLabNumber,
Ais_TransactionJson,
Ais_TransactionStatus,
Ais_TransactionResponse,
Ais_TransactionUrl,
Ais_TransactionUserID,
Ais_TransactionCreated
)
VALUES(
?,
?,
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array(
$row['RegID'],
json_encode($raw_data[$key]),
'error',
json_encode($result),
$url,
555
));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 'ais_transaction insert', 'query' => $this->db_log->last_query(), 'json' => json_encode($result)), 999);
exit;
}
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 'transaction insert', 'query' => $this->db_onedev->last_query(), 'json' => json_encode($result)), 999);
$errors[] = array('RegID' => $row['RegID'], 'error' => $result['message']);
}else{
//echo 'insert ais_transaction';
$sql = "INSERT INTO ais_transaction(
Ais_TransactionOrderHeaderLabNumber,
Ais_TransactionJson,
Ais_TransactionStatus,
Ais_TransactionResponse,
Ais_TransactionUrl,
Ais_TransactionUserID,
Ais_TransactionCreated
)
VALUES(
?,
?,
?,
?,
?,
?,
NOW()
)";
$qry = $this->db_log->query($sql, array(
$row['RegID'],
json_encode($raw_data[$key]),
'success',
json_encode($result),
$url,
555
));
if (!$qry) {
$this->error_log(array('fn_name' => 'post_transaction', 'message' => 'ais_transaction insert', 'query' => $this->db_log->last_query(), 'json' => json_encode($result)), 999);
exit;
}
}
}
if(count($errors) > 0){
$success = array('status' => 'error', 'message' => 'Gagal Post Transaction', 'errors' => $errors);
echo json_encode($success);
exit;
}else{
$success = array('status' => 'success', 'message' => 'Berhasil Post Transaction');
echo json_encode($success);
exit;
}
}
function get_transaction()
{
// Get id from query parameter
$id = $this->input->get('id');
if (empty($id)) {
$errors = array('status' => 'error', 'message' => 'ID parameter is required');
echo json_encode($errors);
exit;
}
$login = $this->post_auth();
if (!$login['success']) {
$this->error_log(array('fn_name' => 'get_transaction_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999);
$errors = array('status' => 'error', 'message' => 'Gagal Login');
echo json_encode($errors);
exit;
}
$dt_config = $this->get_config();
$baseUrl = $dt_config['AisConfigBaseUrl'];
$url = $baseUrl . '/api/transaksi?id=' . $id;
$result = $this->get_request($url);
if (!$result['success']) {
$this->error_log(array('fn_name' => 'get_transaction', 'message' => 'failed get transaction', 'query' => '', 'json' => json_encode($result)), 999);
$errors = array('status' => 'error', 'message' => 'Gagal Get Transaction');
echo json_encode($errors);
exit;
}
$data = $result['response']['data'] ?? null;
// $data = json_encode($data);
$success = array('status' => 'success', 'message' => 'Berhasil Get Transaction', 'data' => $data);
echo json_encode($success);
exit;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,124 @@
@baseUrl = https://cpone.aplikasi.web.id/one-api/ais
# @baseUrl = http://his.sismedika.online:4081/westerindo_ais
POST {{baseUrl}}/transaction/post_transaction_by_labnumber
Content-Type: application/json
{
"labnumber": "H2509010001"
}
### POST Re Post Transaction by Labnumber
POST {{baseUrl}}/transaction/re_post_transaction_by_labnumber
Content-Type: application/json
{
"labnumber": "H2509010001"
}
### POST Medrec by No Reg
POST {{baseUrl}}/masterdata/post_medrec_by_noreg
Content-Type: application/json
{
"noreg": "CP2406200033"
}
### GET Medrec by No Reg
POST {{baseUrl}}/masterdata/get_medrec_by_noreg
Content-Type: application/json
{
"noreg": "CP2406200033"
}
### GET Perusahaan by Code
POST {{baseUrl}}/masterdata/get_perusahaan_by_code
Content-Type: application/json
{
"corporate_code": "CP0029"
}
### GET Doctor by Code
POST {{baseUrl}}/masterdata/get_doctor_by_code
Content-Type: application/json
{
"doctor_code": "D240700001"
}
### POST Doctor by Code
POST {{baseUrl}}/masterdata/post_doctor_by_code
Content-Type: application/json
{
"doctor_code": "D240700001"
}
### POST Jenis Layanan
POST {{baseUrl}}/post_jenis_layanan
### GET Jenis Perusahaan
GET {{baseUrl}}/get_jenis_perusahaan?id=1
### POST Jenis Perusahaan
POST {{baseUrl}}/post_jenis_perusahaan
### POST Perusahaan
POST {{baseUrl}}/post_perusahaan
### GET Perusahaan
GET {{baseUrl}}/get_perusahaan
### POST Perusahaan Bulk
POST {{baseUrl}}/post_perusahaan_bulk
### GET Jenis Layanan
GET {{baseUrl}}/get_jenislayanan
### Post Jenis Layanan
Post {{baseUrl}}/post_jenislayanan
### GET Layanan
GET {{baseUrl}}/get_layanan
### Post Layanan
POST {{baseUrl}}/post_layanan
### GET Group Layanan
GET {{baseUrl}}/get_grouplayanan
### Post Group Layanan
POST {{baseUrl}}/post_grouplayanan
### GET Departemen
GET {{baseUrl}}/get_departemen
### Post Departement
POST {{baseUrl}}/post_departemen
### GET Departement
GET {{baseUrl}}/get_medrec
### Post Departement
POST {{baseUrl}}/post_medrec
### GET Transaction
GET {{baseUrl}}/get_transaction
### Post Transaction
POST {{baseUrl}}/post_transaction
### Post Transaction
POST {{baseUrl}}/post_transaction?date=2024-02-08&limit=1&offset=0
### GET Payment
GET {{baseUrl}}/get_payment?id=6