Initial import
This commit is contained in:
27
application/controllers/Api_his.http
Normal file
27
application/controllers/Api_his.http
Normal file
@@ -0,0 +1,27 @@
|
||||
@host = http://10.9.10.38:8080
|
||||
@token = MYmIZGwkLQUjmFHiL2kgrOjhUyZnk507oBD2BDwM
|
||||
|
||||
### API Untuk List Paket Dispenser HIS
|
||||
GET {{host}}/api/cpone/paket
|
||||
?search=TESTING BUGS
|
||||
&code=250600004
|
||||
&start_date=2025-01-01
|
||||
&end_date=2027-12-30
|
||||
&per_page=10
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### API Untuk Detail Paket Dispenser HIS
|
||||
GET {{host}}/api/cpone/paket/DISP-260200004
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### API Untuk List Layanan dan Harga HIS
|
||||
GET {{host}}/api/cpone/layanan
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
###
|
||||
GET https://devcpone.aplikasi.web.id/one-api/api_his/GetMapingLayanan
|
||||
|
||||
|
||||
### API Untuk pendaftaran Pasien MCU
|
||||
SE
|
||||
|
||||
5
application/controllers/Api_itf.http
Normal file
5
application/controllers/Api_itf.http
Normal file
@@ -0,0 +1,5 @@
|
||||
POST https://devcpone.aplikasi.web.id/one-api/api_itf/getOrderDetail
|
||||
|
||||
{
|
||||
"orderNumber": "I2410180003"
|
||||
}
|
||||
1247
application/controllers/Api_itf.php
Normal file
1247
application/controllers/Api_itf.php
Normal file
File diff suppressed because it is too large
Load Diff
9
application/controllers/Info.php
Normal file
9
application/controllers/Info.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
class Info extends MY_Controller {
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
function index() {
|
||||
echo json_encode(["status"=>"OK", "message" => Date()]);
|
||||
}
|
||||
}
|
||||
180
application/controllers/Qontak_api.php
Normal file
180
application/controllers/Qontak_api.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
class Qontak_api extends MY_Controller
|
||||
{
|
||||
var $token = "WWEfmnLJXPBGBQodjshDQMQgeyhVDbNDC-VR0apf2lc";
|
||||
var $wa_integration_id = "db560b73-53d1-422f-9482-b3d895191ece";
|
||||
var $template_id = "54770b4e-8603-4dc2-a148-f17447cb2aa6";
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function send_wa()
|
||||
{
|
||||
$url = "https://service-chat.qontak.com/api/open/v1/broadcasts/whatsapp/direct";
|
||||
$hp = $this->sys_input["hp"];
|
||||
$hp_name = $this->sys_input["hp_name"];
|
||||
$patient_name = $this->sys_input["patient_name"];
|
||||
$filename = $this->sys_input["filename"];
|
||||
$result_date = $this->sys_input["result_date"];
|
||||
$uploaded_url_doc = "https://cdn.qontak.com/uploads/direct/files/2bdb1add-fb1f-4d5e-aa66-5cee1cb4864e/example-report.pdf";
|
||||
|
||||
$param = [
|
||||
"to_name" => $hp_name,
|
||||
"to_number" => $hp,
|
||||
"message_template_id" => $this->template_id,
|
||||
"channel_integration_id" => $this->wa_integration_id,
|
||||
"language" => [
|
||||
"code" => "id"
|
||||
],
|
||||
"parameters" => [
|
||||
"header" => [
|
||||
"format" => "DOCUMENT",
|
||||
"params" => [
|
||||
[
|
||||
"key" => "url",
|
||||
"value" => $uploaded_url_doc
|
||||
],
|
||||
[
|
||||
"key" => "filename",
|
||||
"value" => $filename
|
||||
]
|
||||
]
|
||||
],
|
||||
"body" => [
|
||||
[
|
||||
"key" => 1,
|
||||
"value" => "nama",
|
||||
"value_text" => $hp_name
|
||||
],
|
||||
[
|
||||
"key" => 2,
|
||||
"value" => "tipe",
|
||||
"value_text" => $patient_name
|
||||
],
|
||||
[
|
||||
"key" => 3,
|
||||
"value" => "berlaku",
|
||||
"value_text" => $result_date
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
$json_param = json_encode($param);
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS => $json_param,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Authorization: Bearer {$this->token}",
|
||||
"Content-Type: application/json"
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$error = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
if ($error != "") {
|
||||
echo json_encode(["status" => "ERR", "message" => $error]);
|
||||
exit;
|
||||
}
|
||||
echo $response;
|
||||
}
|
||||
function get_integration()
|
||||
{
|
||||
$url = "https://service-chat.qontak.com/api/open/v1/integrations?target_channel=wa&limit=10";
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => false,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"Authorization: Bearer {$this->token}",
|
||||
],
|
||||
]);
|
||||
$response = curl_exec($curl);
|
||||
$error = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
if ($error != "") {
|
||||
echo json_encode(["status" => "ERR", "message" => $error]);
|
||||
exit;
|
||||
}
|
||||
echo $response;
|
||||
}
|
||||
function upload_file()
|
||||
{
|
||||
$url = "https://service-chat.qontak.com/api/open/v1/file_uploader";
|
||||
$fileName = $this->sys_input["file_name"];
|
||||
$rpt_url = $this->sys_input["rpt_url"];
|
||||
$mimeType = $this->sys_input["mime"];
|
||||
|
||||
$fileContents = file_get_contents($rpt_url);
|
||||
|
||||
$boundary = uniqid();
|
||||
|
||||
$body = "--$boundary\r\n" .
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"$fileName\"\r\n" .
|
||||
"Content-Type: $mimeType\r\n\r\n" .
|
||||
$fileContents . "\r\n" .
|
||||
"--$boundary--\r\n";
|
||||
|
||||
// Set cURL options
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"Authorization: Bearer {$this->token}",
|
||||
"Content-Type: multipart/form-data; boundary=$boundary"
|
||||
],
|
||||
CURLOPT_POSTFIELDS => $body
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$error = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($error) {
|
||||
echo json_encode(["status" => "ERR", "message" => $error]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo $response;
|
||||
}
|
||||
function list_template()
|
||||
{
|
||||
$url = "https://service-chat.qontak.com/api/open/v1/templates/whatsapp";
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => false,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"Authorization: Bearer {$this->token}",
|
||||
],
|
||||
]);
|
||||
$response = curl_exec($curl);
|
||||
$error = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
if ($error != "") {
|
||||
echo json_encode(["status" => "ERR", "message" => $error]);
|
||||
exit;
|
||||
}
|
||||
echo $response;
|
||||
}
|
||||
}
|
||||
47
application/controllers/Rpt_img_background.php
Normal file
47
application/controllers/Rpt_img_background.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
class Rpt_img_background extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index() {}
|
||||
function project_from_t_orderheader($id)
|
||||
{
|
||||
$sql = "";
|
||||
$qry = $this->db->query($sql, [$id]);
|
||||
if (!$qry) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
function project($id, $code)
|
||||
{
|
||||
|
||||
$img = APPPATH . "../../one-ui/BackgroundWesterindoPrimaya.png";
|
||||
$referer = $this->input->server('HTTP_REFERER');
|
||||
//di gunakan untuk mencari project berdasarkan code
|
||||
//code ini di hardcode dari rpt untuk menentukan id itu jenis apa
|
||||
switch ($code) {
|
||||
|
||||
default:
|
||||
//T_OrderHeaderID
|
||||
$project_id = $this->project_from_t_orderheader($id);
|
||||
break;
|
||||
}
|
||||
// echo "img : $img";
|
||||
// if (file_exists($img)) {
|
||||
// echo " file exists";
|
||||
// } else {
|
||||
// echo " file not exists";
|
||||
// }
|
||||
if ($project_id == 0) {
|
||||
$img = APPPATH . "../../one-ui/BackgroundWesterindoPrimaya.png";
|
||||
}
|
||||
file_put_contents("/xtmp/referer-rpt.log", "referer : $referer | code : $code |\n");
|
||||
file_put_contents("/xtmp/referer-rpt.log", print_r($_SERVER, true), FILE_APPEND);
|
||||
Header("Content-Type: image/png");
|
||||
|
||||
echo file_get_contents($img);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
479
application/controllers/Station.php
Normal file
479
application/controllers/Station.php
Normal file
@@ -0,0 +1,479 @@
|
||||
<?php
|
||||
class Station extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "STATION API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
|
||||
function lookupbahan(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$sql = "select T_BahanID as id,
|
||||
T_BahanT_SampleStationID as usergroupid,
|
||||
T_BahanCode as code,
|
||||
T_BahanName As name,
|
||||
'xxx' as action
|
||||
from t_bahan
|
||||
join t_samplestation oN T_BahanT_SampleStationID = T_SampleStationID
|
||||
where
|
||||
T_BahanT_SampleStationID = {$id} AND T_BahanIsActive = 'Y'";
|
||||
//echo $sql;
|
||||
$rows = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$result = array ("total" => count($rows), "records" => $rows);
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function lookup()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = $prm['search'];
|
||||
$all = $prm['all'];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$sql = "select COUNT(*) as total
|
||||
from t_samplestation
|
||||
where
|
||||
T_SampleStationIsActive = 'Y'";
|
||||
$sql_param = array($search);
|
||||
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||
|
||||
|
||||
$sql = "select T_SampleStationID as id,
|
||||
T_SampleStationCode as code,
|
||||
T_SampleStationName as name,
|
||||
T_SampleStationIsNonLab as isnonlab, T_SampleStationName as description , 'xxx' as usergrouptype
|
||||
from t_samplestation
|
||||
where
|
||||
T_SampleStationName LIKE CONCAT('%','{$search}','%') AND
|
||||
T_SampleStationIsActive = 'Y' $limit";
|
||||
$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("t_samplestation select",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function addnewstation()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$name_station = $prm['name'];
|
||||
$code_station = $prm['code'];
|
||||
$isnonlab_station = $prm['isnonlab'];
|
||||
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' AND T_SampleStationName = '{$name_station}'";
|
||||
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
||||
|
||||
|
||||
//echo $exist_name;
|
||||
if($exist_name == 0 ){
|
||||
$sql = "insert into t_samplestation(
|
||||
T_SampleStationCode,
|
||||
T_SampleStationName,
|
||||
T_SampleStationIsNonLab,
|
||||
T_SampleStationCreated,
|
||||
T_SampleStationLastUpdated
|
||||
)
|
||||
values( ?, ?, ?,now(), now())";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$name_station,
|
||||
$code_station,
|
||||
$isnonlab_station
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_samplestation insert");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
} else{
|
||||
$errors = array();
|
||||
|
||||
if($exist_name != 0){
|
||||
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada '));
|
||||
}
|
||||
|
||||
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function editstation()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id_station = $prm['id'];
|
||||
$code_station = $prm['code'];
|
||||
$name_station = $prm['name'];
|
||||
$isnonlab_station = $prm['isnonlab'];
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' AND T_SampleStationName = '{$name_station}'
|
||||
AND T_SampleStationID <> {$id_station} ";
|
||||
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
||||
|
||||
|
||||
if($exist_name == 0){
|
||||
|
||||
$sql = "update t_samplestation SET
|
||||
T_SampleStationCode = ?,
|
||||
T_SampleStationName = ?,
|
||||
T_SampleStationIsNonLab = ?,
|
||||
T_SampleStationLastUpdated = now()
|
||||
where
|
||||
T_SampleStationID = ?
|
||||
";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$code_station,
|
||||
$name_station,
|
||||
$isnonlab_station,
|
||||
$id_station
|
||||
)
|
||||
);
|
||||
//file_put_contents("/tmp/adi-update-user.sql",$this->db_onedev->last_query());
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_samplestation update");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => $id_station));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$errors = array();
|
||||
|
||||
|
||||
if($exist_name != 0){
|
||||
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada'));
|
||||
}
|
||||
|
||||
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function editbahan()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$bahanid = $prm['xid'];
|
||||
$code = $prm['code'];
|
||||
$name = $prm['name'];
|
||||
$xstationname = $prm['xstationname'];
|
||||
|
||||
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}'
|
||||
and T_BahanID <> $bahanid ";
|
||||
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
||||
|
||||
if($exist_name == 0){
|
||||
|
||||
$sql = "update m_user SET
|
||||
T_BahanCode = ?,
|
||||
T_BahanName = ?,
|
||||
T_BahanT_SampleStationID = ?,
|
||||
T_BahanLastUpdated = now()
|
||||
where T_BahanID = ? ";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$code,
|
||||
$name,
|
||||
$xstationname["T_SampleStationID"],
|
||||
$bahanid
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_bahan update",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => $bahanid));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
|
||||
if($exist_name != 0){
|
||||
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada yang pakai dong'));
|
||||
}
|
||||
|
||||
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function addnewbahan()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$stationid = $prm['stationid'];
|
||||
$code = $prm['code'];
|
||||
$name = $prm['name'];
|
||||
|
||||
if($prm['xid'] == 0){
|
||||
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}'";
|
||||
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
||||
|
||||
if($exist_name == 0){
|
||||
$sql = "insert into t_bahan(
|
||||
T_BahanT_SampleStationID,
|
||||
T_BahanCode,
|
||||
T_BahanName,
|
||||
T_BahanCreated,
|
||||
T_BahanLastUpdated
|
||||
)
|
||||
values( ?,?,?,now(),now())";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$stationid,
|
||||
$code,
|
||||
$name
|
||||
)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_bahan insert",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$errors = array();
|
||||
if($exist_name != 0){
|
||||
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada yang pakai dong'));
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}else{
|
||||
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}' AND T_BahanID <> {$prm['xid']}";
|
||||
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
||||
//echo $query;
|
||||
|
||||
//echo $query;
|
||||
if($exist_name == 0 ){
|
||||
$sql = "UPDATE t_bahan SET T_BahanName = '{$name}', T_BahanCode = '{$code}' WHERE T_BahanID = '{$prm['xid']}'";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$errors = array();
|
||||
if($exist_name != 0){
|
||||
array_push($errors,array('field'=>'name','msg'=>'name sudah ada yang pakai dong'));
|
||||
}
|
||||
|
||||
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function deletebahan()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "update t_bahan SET
|
||||
T_BahanIsActive = 'N',
|
||||
T_BahanLastUpdated = now()
|
||||
WHERE
|
||||
T_BahanID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_bahan delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteselect()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "update t_samplestation SET
|
||||
T_SampleStationIsActive = 'N',
|
||||
T_SampleStationLastUpdated = now()
|
||||
WHERE
|
||||
T_SampleStationID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_samplestation delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE m_user SET
|
||||
M_UserIsActive = 'N',
|
||||
M_UserLastUpdated = now()
|
||||
WHERE
|
||||
M_UserM_UserGroupID = ?
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("m_user delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
25
application/controllers/Welcome.php
Normal file
25
application/controllers/Welcome.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Welcome extends CI_Controller {
|
||||
|
||||
/**
|
||||
* Index Page for this controller.
|
||||
*
|
||||
* Maps to the following URL
|
||||
* http://example.com/index.php/welcome
|
||||
* - or -
|
||||
* http://example.com/index.php/welcome/index
|
||||
* - or -
|
||||
* Since this controller is set as the default controller in
|
||||
* config/routes.php, it's displayed at http://example.com/
|
||||
*
|
||||
* So any other public methods not prefixed with an underscore will
|
||||
* map to /index.php/welcome/<method_name>
|
||||
* @see https://codeigniter.com/user_guide/general/urls.html
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
echo(".:: -- ::.");
|
||||
}
|
||||
}
|
||||
181
application/controllers/ais/Bridging.php
Normal file
181
application/controllers/ais/Bridging.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
421
application/controllers/ais/Corporate.php
Normal file
421
application/controllers/ais/Corporate.php
Normal 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"
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
4766
application/controllers/ais/Masterdata.php
Normal file
4766
application/controllers/ais/Masterdata.php
Normal file
File diff suppressed because it is too large
Load Diff
3820
application/controllers/ais/Masterdata.php--011225-0909
Normal file
3820
application/controllers/ais/Masterdata.php--011225-0909
Normal file
File diff suppressed because it is too large
Load Diff
4338
application/controllers/ais/Masterdata.php--130126
Normal file
4338
application/controllers/ais/Masterdata.php--130126
Normal file
File diff suppressed because it is too large
Load Diff
4872
application/controllers/ais/Masterdata.php-040326
Normal file
4872
application/controllers/ais/Masterdata.php-040326
Normal file
File diff suppressed because it is too large
Load Diff
421
application/controllers/ais/Packet.php
Normal file
421
application/controllers/ais/Packet.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
433
application/controllers/ais/Packet.php--040326
Normal file
433
application/controllers/ais/Packet.php--040326
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
269
application/controllers/ais/Test.php
Normal file
269
application/controllers/ais/Test.php
Normal 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;
|
||||
}
|
||||
}
|
||||
761
application/controllers/ais/Transaction.php--251125
Normal file
761
application/controllers/ais/Transaction.php--251125
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1370
application/controllers/ais/Transaction.php--25112501
Normal file
1370
application/controllers/ais/Transaction.php--25112501
Normal file
File diff suppressed because it is too large
Load Diff
2488
application/controllers/ais/Transaction.php--270126
Normal file
2488
application/controllers/ais/Transaction.php--270126
Normal file
File diff suppressed because it is too large
Load Diff
3853
application/controllers/ais/Transactionv2.php
Normal file
3853
application/controllers/ais/Transactionv2.php
Normal file
File diff suppressed because it is too large
Load Diff
3821
application/controllers/ais/Transactionv2.php--260326
Normal file
3821
application/controllers/ais/Transactionv2.php--260326
Normal file
File diff suppressed because it is too large
Load Diff
3858
application/controllers/ais/Transactionv3.php
Normal file
3858
application/controllers/ais/Transactionv3.php
Normal file
File diff suppressed because it is too large
Load Diff
3857
application/controllers/ais/Transactionv3.php--
Normal file
3857
application/controllers/ais/Transactionv3.php--
Normal file
File diff suppressed because it is too large
Load Diff
124
application/controllers/ais/example.http
Normal file
124
application/controllers/ais/example.http
Normal 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
|
||||
181
application/controllers/ais_100326/Bridging.php
Normal file
181
application/controllers/ais_100326/Bridging.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
417
application/controllers/ais_100326/Corporate.php
Normal file
417
application/controllers/ais_100326/Corporate.php
Normal file
@@ -0,0 +1,417 @@
|
||||
<?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 || $corporate_code) {
|
||||
$where_query .= "AND ( c.CorporateName LIKE '%{$corporate_code}%' OR c.CorporateCode LIKE '%{$corporate_code}%' ) ";
|
||||
|
||||
}
|
||||
|
||||
// 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"
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
4381
application/controllers/ais_100326/Masterdata.php
Normal file
4381
application/controllers/ais_100326/Masterdata.php
Normal file
File diff suppressed because it is too large
Load Diff
3820
application/controllers/ais_100326/Masterdata.php--011225-0909
Normal file
3820
application/controllers/ais_100326/Masterdata.php--011225-0909
Normal file
File diff suppressed because it is too large
Load Diff
3827
application/controllers/ais_100326/Masterdata.php--021224
Normal file
3827
application/controllers/ais_100326/Masterdata.php--021224
Normal file
File diff suppressed because it is too large
Load Diff
3830
application/controllers/ais_100326/Masterdata.php--031225
Normal file
3830
application/controllers/ais_100326/Masterdata.php--031225
Normal file
File diff suppressed because it is too large
Load Diff
4160
application/controllers/ais_100326/Masterdata.php--111225
Normal file
4160
application/controllers/ais_100326/Masterdata.php--111225
Normal file
File diff suppressed because it is too large
Load Diff
2900
application/controllers/ais_100326/Masterdata.php--11225
Normal file
2900
application/controllers/ais_100326/Masterdata.php--11225
Normal file
File diff suppressed because it is too large
Load Diff
2784
application/controllers/ais_100326/Masterdata.php--251125
Normal file
2784
application/controllers/ais_100326/Masterdata.php--251125
Normal file
File diff suppressed because it is too large
Load Diff
4174
application/controllers/ais_100326/Masterdata.php-151225
Normal file
4174
application/controllers/ais_100326/Masterdata.php-151225
Normal file
File diff suppressed because it is too large
Load Diff
421
application/controllers/ais_100326/Packet.php
Normal file
421
application/controllers/ais_100326/Packet.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
406
application/controllers/ais_100326/Patient.php
Normal file
406
application/controllers/ais_100326/Patient.php
Normal file
@@ -0,0 +1,406 @@
|
||||
<?php
|
||||
class Patient 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_patient()
|
||||
{
|
||||
$sql_base = "SELECT
|
||||
oh.T_OrderHeaderID,
|
||||
oh.T_OrderHeaderM_PatientID AS patient_id,
|
||||
p.M_PatientName AS patient_name,
|
||||
p.M_PatientNoReg AS patient_noreq,
|
||||
p.M_PatientGender AS patient_gender,
|
||||
p.M_PatientDOB AS patient_birthdate,
|
||||
p.M_PatientHp AS patient_hp,
|
||||
p.M_PatientEmail AS patient_email,
|
||||
p.M_PatientIdentifierValue AS patient_identifier,
|
||||
p.M_PatientNIP AS patient_nip,
|
||||
p.M_PatientJob AS patient_job,
|
||||
p.M_PatientPosisi AS patient_posisi,
|
||||
p.M_PatientDivisi AS pasient_divisi,
|
||||
am.Ais_MedrecStatus AS medrec_status,
|
||||
|
||||
-- STATUS AIS
|
||||
IF(MAX(am.Ais_MedrecID) IS NULL, 'N', 'Y') AS medrec_status
|
||||
|
||||
FROM t_orderheader oh
|
||||
JOIN m_patient p
|
||||
ON p.M_PatientID = oh.T_OrderHeaderM_PatientID
|
||||
LEFT JOIN ".$this->db_log->database.".ais_medrec am
|
||||
ON am.Ais_MedrecPatientNoReg = p.M_PatientNoReg
|
||||
";
|
||||
|
||||
// Pagination
|
||||
$page = $this->input->get('page') ? intval($this->input->get('page')) : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
// Filter
|
||||
$patient_name = $this->input->get('patient_name');
|
||||
$patient_noreq = $this->input->get('patient_noreq');
|
||||
$medrec_status = $this->input->get('medrec_status');
|
||||
|
||||
$params = [];
|
||||
$where_clauses = [];
|
||||
|
||||
if ($medrec_status === 'Y') {
|
||||
$where_clauses[] = "am.Ais_MedrecID IS NOT NULL";
|
||||
} elseif ($medrec_status === 'N') {
|
||||
$where_clauses[] = "am.Ais_MedrecID IS NULL";
|
||||
}
|
||||
|
||||
if ($patient_name) {
|
||||
$where_clauses[] = "p.M_PatientName LIKE ?";
|
||||
$params[] = "%$patient_name%";
|
||||
}
|
||||
|
||||
if ($patient_noreq) {
|
||||
$where_clauses[] = "p.M_PatientNoReg LIKE ?";
|
||||
$params[] = "%$patient_noreq%";
|
||||
}
|
||||
|
||||
// WHERE builder
|
||||
$where_sql = "";
|
||||
if (!empty($where_clauses)) {
|
||||
$where_sql = " WHERE " . implode(" AND ", $where_clauses);
|
||||
}
|
||||
|
||||
// Count total rows
|
||||
$count_sql = "SELECT COUNT(DISTINCT oh.T_OrderHeaderM_PatientID) AS total
|
||||
FROM t_orderheader oh
|
||||
JOIN m_patient p
|
||||
ON p.M_PatientID = oh.T_OrderHeaderM_PatientID
|
||||
LEFT JOIN ".$this->db_log->database.".ais_medrec am
|
||||
ON am.Ais_MedrecPatientNoReg = p.M_PatientNoReg
|
||||
$where_sql";
|
||||
|
||||
$qry_count = $this->db_onedev->query($count_sql, $params);
|
||||
$total = $qry_count->row()->total ?? 0;
|
||||
|
||||
// Main query
|
||||
$sql = $sql_base . $where_sql . "
|
||||
GROUP BY oh.T_OrderHeaderM_PatientID
|
||||
LIMIT $limit OFFSET $offset";
|
||||
|
||||
$qry = $this->db_onedev->query($sql, $params);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data pasien.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $qry->result_array();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data pasien.',
|
||||
'data' => $data,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'total_page' => ceil($total / $limit)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function get_json_response()
|
||||
{
|
||||
// Ambil patient_noreg dari query parameter
|
||||
$patient_noreg = $this->input->get('patient_noreg');
|
||||
|
||||
if (empty($patient_noreg)) {
|
||||
$this->output
|
||||
->set_status_header(400)
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'patient_noreg parameter is required'
|
||||
]));
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
Ais_MedrecPatientNoReg AS patient_noreg,
|
||||
Ais_MedrecStatus AS status,
|
||||
Ais_MedrecJSON AS json,
|
||||
Ais_MedrecResponse AS response,
|
||||
Ais_MedrecCreated AS created,
|
||||
Ais_MedrecUserID AS user_id
|
||||
FROM ais_medrec
|
||||
WHERE Ais_MedrecPatientNoReg = ?";
|
||||
|
||||
// Query menggunakan db_log
|
||||
$qry = $this->db_log->query($sql, array($patient_noreg));
|
||||
|
||||
// Ambil multiple rows
|
||||
$results = $qry->result_array();
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as &$result) {
|
||||
$result['json'] = json_decode($result['json']);
|
||||
$result['response'] = json_decode($result['response']);
|
||||
}
|
||||
unset($result);
|
||||
|
||||
echo json_encode(['status' => 'success', 'data' => $results]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'No data found for the given patient_noreq.'
|
||||
]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
269
application/controllers/ais_100326/Test.php
Normal file
269
application/controllers/ais_100326/Test.php
Normal 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;
|
||||
}
|
||||
}
|
||||
2488
application/controllers/ais_100326/Transaction.php
Normal file
2488
application/controllers/ais_100326/Transaction.php
Normal file
File diff suppressed because it is too large
Load Diff
761
application/controllers/ais_100326/Transaction.php--251125
Normal file
761
application/controllers/ais_100326/Transaction.php--251125
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1370
application/controllers/ais_100326/Transaction.php--25112501
Normal file
1370
application/controllers/ais_100326/Transaction.php--25112501
Normal file
File diff suppressed because it is too large
Load Diff
3759
application/controllers/ais_100326/Transactionv2.php
Normal file
3759
application/controllers/ais_100326/Transactionv2.php
Normal file
File diff suppressed because it is too large
Load Diff
1952
application/controllers/ais_100326/Transactionv2.php-011225
Normal file
1952
application/controllers/ais_100326/Transactionv2.php-011225
Normal file
File diff suppressed because it is too large
Load Diff
124
application/controllers/ais_100326/example.http
Normal file
124
application/controllers/ais_100326/example.http
Normal 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
|
||||
52
application/controllers/ais_100326/try.http
Normal file
52
application/controllers/ais_100326/try.http
Normal file
@@ -0,0 +1,52 @@
|
||||
@baseUrl = https://devcpone.aplikasi.web.id/one-api/ais
|
||||
@contentType = application/json
|
||||
|
||||
### ============================================================
|
||||
### LIST TRANSACTION
|
||||
### ============================================================
|
||||
### Request tanpa parameter tanggal (menggunakan default)
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction/monitoring_transaction?page=1&limit=10
|
||||
|
||||
### Request dengan parameter tanggal
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?start_date=2025-08-01&end_date=2025-08-05
|
||||
|
||||
### Request dengan parameter tanggal dan status transaksi
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?ais_status=Y
|
||||
|
||||
### Request dengan parameter corporate_id
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?corporate_id=53
|
||||
|
||||
### Request dengan parameter patient_name
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?patient_name=Dony Wahyu Andreansyah
|
||||
|
||||
### Request dengan parameter lab_number
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?lab_number=H2408010111
|
||||
|
||||
### Request get_corporate
|
||||
GET {{baseUrl}}/transaction/get_corporate
|
||||
|
||||
### Request get_json_response dengan parameter lab_number
|
||||
GET {{baseUrl}}/transaction/get_json_response?lab_number=H2408010111
|
||||
|
||||
|
||||
|
||||
### Request monitoring_patient berdasarkan halaman
|
||||
GET {{baseUrl}}/patient/monitoring_patient?page=1
|
||||
|
||||
### Request monitoring_patient berdasarkan API
|
||||
GET {{baseUrl}}/patient/monitoring_patient?page=1&patient_name=Pasien 5 Karyawan
|
||||
|
||||
|
||||
### Request monitoring_patient
|
||||
GET {{baseUrl}}/patient/monitoring_patient?page=1&patient_noreq=CP2509010001
|
||||
|
||||
###
|
||||
GET {{baseUrl}}/patient/monitoring_patient?medrec_status=N
|
||||
|
||||
###
|
||||
GET {{baseUrl}}/patient/get_json_response?patient_noreg=CP2509010001
|
||||
|
||||
|
||||
###
|
||||
GET {{baseUrl}}/corporate/monitoring_corporate?page=1
|
||||
|
||||
181
application/controllers/ais_130126/Bridging.php
Normal file
181
application/controllers/ais_130126/Bridging.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
417
application/controllers/ais_130126/Corporate.php
Normal file
417
application/controllers/ais_130126/Corporate.php
Normal file
@@ -0,0 +1,417 @@
|
||||
<?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 || $corporate_code) {
|
||||
$where_query .= "AND ( c.CorporateName LIKE '%{$corporate_code}%' OR c.CorporateCode LIKE '%{$corporate_code}%' ) ";
|
||||
|
||||
}
|
||||
|
||||
// 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"
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
4338
application/controllers/ais_130126/Masterdata.php
Normal file
4338
application/controllers/ais_130126/Masterdata.php
Normal file
File diff suppressed because it is too large
Load Diff
3827
application/controllers/ais_130126/Masterdata.php--021224
Normal file
3827
application/controllers/ais_130126/Masterdata.php--021224
Normal file
File diff suppressed because it is too large
Load Diff
3830
application/controllers/ais_130126/Masterdata.php--031225
Normal file
3830
application/controllers/ais_130126/Masterdata.php--031225
Normal file
File diff suppressed because it is too large
Load Diff
4160
application/controllers/ais_130126/Masterdata.php--111225
Normal file
4160
application/controllers/ais_130126/Masterdata.php--111225
Normal file
File diff suppressed because it is too large
Load Diff
2900
application/controllers/ais_130126/Masterdata.php--11225
Normal file
2900
application/controllers/ais_130126/Masterdata.php--11225
Normal file
File diff suppressed because it is too large
Load Diff
2784
application/controllers/ais_130126/Masterdata.php--251125
Normal file
2784
application/controllers/ais_130126/Masterdata.php--251125
Normal file
File diff suppressed because it is too large
Load Diff
4174
application/controllers/ais_130126/Masterdata.php-151225
Normal file
4174
application/controllers/ais_130126/Masterdata.php-151225
Normal file
File diff suppressed because it is too large
Load Diff
421
application/controllers/ais_130126/Packet.php
Normal file
421
application/controllers/ais_130126/Packet.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
406
application/controllers/ais_130126/Patient.php
Normal file
406
application/controllers/ais_130126/Patient.php
Normal file
@@ -0,0 +1,406 @@
|
||||
<?php
|
||||
class Patient 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_patient()
|
||||
{
|
||||
$sql_base = "SELECT
|
||||
oh.T_OrderHeaderID,
|
||||
oh.T_OrderHeaderM_PatientID AS patient_id,
|
||||
p.M_PatientName AS patient_name,
|
||||
p.M_PatientNoReg AS patient_noreq,
|
||||
p.M_PatientGender AS patient_gender,
|
||||
p.M_PatientDOB AS patient_birthdate,
|
||||
p.M_PatientHp AS patient_hp,
|
||||
p.M_PatientEmail AS patient_email,
|
||||
p.M_PatientIdentifierValue AS patient_identifier,
|
||||
p.M_PatientNIP AS patient_nip,
|
||||
p.M_PatientJob AS patient_job,
|
||||
p.M_PatientPosisi AS patient_posisi,
|
||||
p.M_PatientDivisi AS pasient_divisi,
|
||||
am.Ais_MedrecStatus AS medrec_status,
|
||||
|
||||
-- STATUS AIS
|
||||
IF(MAX(am.Ais_MedrecID) IS NULL, 'N', 'Y') AS medrec_status
|
||||
|
||||
FROM t_orderheader oh
|
||||
JOIN m_patient p
|
||||
ON p.M_PatientID = oh.T_OrderHeaderM_PatientID
|
||||
LEFT JOIN ".$this->db_log->database.".ais_medrec am
|
||||
ON am.Ais_MedrecPatientNoReg = p.M_PatientNoReg
|
||||
";
|
||||
|
||||
// Pagination
|
||||
$page = $this->input->get('page') ? intval($this->input->get('page')) : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
// Filter
|
||||
$patient_name = $this->input->get('patient_name');
|
||||
$patient_noreq = $this->input->get('patient_noreq');
|
||||
$medrec_status = $this->input->get('medrec_status');
|
||||
|
||||
$params = [];
|
||||
$where_clauses = [];
|
||||
|
||||
if ($medrec_status === 'Y') {
|
||||
$where_clauses[] = "am.Ais_MedrecID IS NOT NULL";
|
||||
} elseif ($medrec_status === 'N') {
|
||||
$where_clauses[] = "am.Ais_MedrecID IS NULL";
|
||||
}
|
||||
|
||||
if ($patient_name) {
|
||||
$where_clauses[] = "p.M_PatientName LIKE ?";
|
||||
$params[] = "%$patient_name%";
|
||||
}
|
||||
|
||||
if ($patient_noreq) {
|
||||
$where_clauses[] = "p.M_PatientNoReg LIKE ?";
|
||||
$params[] = "%$patient_noreq%";
|
||||
}
|
||||
|
||||
// WHERE builder
|
||||
$where_sql = "";
|
||||
if (!empty($where_clauses)) {
|
||||
$where_sql = " WHERE " . implode(" AND ", $where_clauses);
|
||||
}
|
||||
|
||||
// Count total rows
|
||||
$count_sql = "SELECT COUNT(DISTINCT oh.T_OrderHeaderM_PatientID) AS total
|
||||
FROM t_orderheader oh
|
||||
JOIN m_patient p
|
||||
ON p.M_PatientID = oh.T_OrderHeaderM_PatientID
|
||||
LEFT JOIN ".$this->db_log->database.".ais_medrec am
|
||||
ON am.Ais_MedrecPatientNoReg = p.M_PatientNoReg
|
||||
$where_sql";
|
||||
|
||||
$qry_count = $this->db_onedev->query($count_sql, $params);
|
||||
$total = $qry_count->row()->total ?? 0;
|
||||
|
||||
// Main query
|
||||
$sql = $sql_base . $where_sql . "
|
||||
GROUP BY oh.T_OrderHeaderM_PatientID
|
||||
LIMIT $limit OFFSET $offset";
|
||||
|
||||
$qry = $this->db_onedev->query($sql, $params);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data pasien.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $qry->result_array();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data pasien.',
|
||||
'data' => $data,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'total_page' => ceil($total / $limit)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function get_json_response()
|
||||
{
|
||||
// Ambil patient_noreg dari query parameter
|
||||
$patient_noreg = $this->input->get('patient_noreg');
|
||||
|
||||
if (empty($patient_noreg)) {
|
||||
$this->output
|
||||
->set_status_header(400)
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'patient_noreg parameter is required'
|
||||
]));
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
Ais_MedrecPatientNoReg AS patient_noreg,
|
||||
Ais_MedrecStatus AS status,
|
||||
Ais_MedrecJSON AS json,
|
||||
Ais_MedrecResponse AS response,
|
||||
Ais_MedrecCreated AS created,
|
||||
Ais_MedrecUserID AS user_id
|
||||
FROM ais_medrec
|
||||
WHERE Ais_MedrecPatientNoReg = ?";
|
||||
|
||||
// Query menggunakan db_log
|
||||
$qry = $this->db_log->query($sql, array($patient_noreg));
|
||||
|
||||
// Ambil multiple rows
|
||||
$results = $qry->result_array();
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as &$result) {
|
||||
$result['json'] = json_decode($result['json']);
|
||||
$result['response'] = json_decode($result['response']);
|
||||
}
|
||||
unset($result);
|
||||
|
||||
echo json_encode(['status' => 'success', 'data' => $results]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'No data found for the given patient_noreq.'
|
||||
]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
269
application/controllers/ais_130126/Test.php
Normal file
269
application/controllers/ais_130126/Test.php
Normal 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;
|
||||
}
|
||||
}
|
||||
1943
application/controllers/ais_130126/Transaction.php
Normal file
1943
application/controllers/ais_130126/Transaction.php
Normal file
File diff suppressed because it is too large
Load Diff
2786
application/controllers/ais_130126/Transactionv2.php
Normal file
2786
application/controllers/ais_130126/Transactionv2.php
Normal file
File diff suppressed because it is too large
Load Diff
2733
application/controllers/ais_130126/Transactionv2.php--311225
Normal file
2733
application/controllers/ais_130126/Transactionv2.php--311225
Normal file
File diff suppressed because it is too large
Load Diff
1952
application/controllers/ais_130126/Transactionv2.php-011225
Normal file
1952
application/controllers/ais_130126/Transactionv2.php-011225
Normal file
File diff suppressed because it is too large
Load Diff
90
application/controllers/ais_130126/example.http
Normal file
90
application/controllers/ais_130126/example.http
Normal file
@@ -0,0 +1,90 @@
|
||||
@baseUrl = https://devcpone.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": "CP2406140001"
|
||||
}
|
||||
|
||||
|
||||
### 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
|
||||
52
application/controllers/ais_130126/try.http
Normal file
52
application/controllers/ais_130126/try.http
Normal file
@@ -0,0 +1,52 @@
|
||||
@baseUrl = https://devcpone.aplikasi.web.id/one-api/ais
|
||||
@contentType = application/json
|
||||
|
||||
### ============================================================
|
||||
### LIST TRANSACTION
|
||||
### ============================================================
|
||||
### Request tanpa parameter tanggal (menggunakan default)
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction/monitoring_transaction?page=1&limit=10
|
||||
|
||||
### Request dengan parameter tanggal
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?start_date=2025-08-01&end_date=2025-08-05
|
||||
|
||||
### Request dengan parameter tanggal dan status transaksi
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?ais_status=Y
|
||||
|
||||
### Request dengan parameter corporate_id
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?corporate_id=53
|
||||
|
||||
### Request dengan parameter patient_name
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?patient_name=Dony Wahyu Andreansyah
|
||||
|
||||
### Request dengan parameter lab_number
|
||||
GET {{baseUrl}}/transaction/monitoring_transaction?lab_number=H2408010111
|
||||
|
||||
### Request get_corporate
|
||||
GET {{baseUrl}}/transaction/get_corporate
|
||||
|
||||
### Request get_json_response dengan parameter lab_number
|
||||
GET {{baseUrl}}/transaction/get_json_response?lab_number=H2408010111
|
||||
|
||||
|
||||
|
||||
### Request monitoring_patient berdasarkan halaman
|
||||
GET {{baseUrl}}/patient/monitoring_patient?page=1
|
||||
|
||||
### Request monitoring_patient berdasarkan API
|
||||
GET {{baseUrl}}/patient/monitoring_patient?page=1&patient_name=Pasien 5 Karyawan
|
||||
|
||||
|
||||
### Request monitoring_patient
|
||||
GET {{baseUrl}}/patient/monitoring_patient?page=1&patient_noreq=CP2509010001
|
||||
|
||||
###
|
||||
GET {{baseUrl}}/patient/monitoring_patient?medrec_status=N
|
||||
|
||||
###
|
||||
GET {{baseUrl}}/patient/get_json_response?patient_noreg=CP2509010001
|
||||
|
||||
|
||||
###
|
||||
GET {{baseUrl}}/corporate/monitoring_corporate?page=1
|
||||
|
||||
213
application/controllers/antrian/AntrianCounterDedicated.php
Normal file
213
application/controllers/antrian/AntrianCounterDedicated.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
class AntrianCounterDedicated extends MY_Controller
|
||||
{
|
||||
var $db_antrione;
|
||||
var $load;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_antrione = $this->load->database("antrione", true);
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: Training Playground";
|
||||
}
|
||||
|
||||
function list_location()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM location WHERE locationIsActive = 'Y'";
|
||||
$qry = $this->db_antrione->query($sql);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function list_counter($branchID)
|
||||
{
|
||||
try {
|
||||
// $prm = $this->sys_input;
|
||||
// $locationID = array();
|
||||
// if (isset($prm['locationID'])) {
|
||||
// $locationID = trim($prm["locationID"]);
|
||||
// }
|
||||
$sql = "SELECT counter.* , locationID, locationName,
|
||||
fn_get_serviceID(counterID,counterIsDedicated) as serviceID
|
||||
FROM counter
|
||||
JOIN location ON counterLocationID = locationID
|
||||
AND locationIsActive = 'Y'
|
||||
WHERE counterIsActive = 'Y'
|
||||
AND counterBranchID = ?;
|
||||
";
|
||||
// $sql = "SELECT *
|
||||
// FROM counter
|
||||
// WHERE counterIsActive = 'Y'
|
||||
// AND counterLocationID = ?";
|
||||
$qry = $this->db_antrione->query($sql, [$branchID]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function get_antrian()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$arrCounter = array();
|
||||
if (isset($prm['arr_counter'])) {
|
||||
array_push($prm['arr_counter'], 0);
|
||||
$arrCounter = implode(",", $prm["arr_counter"]);
|
||||
}
|
||||
$branchID = $prm["branchID"];
|
||||
|
||||
$sqlNotServed = "SELECT queueID,
|
||||
statusID, IFNULL(queueNumber,'') as queueNumber,
|
||||
IFNULL(queueSkipDate, 'NEW') as skipQueue,
|
||||
( CASE
|
||||
WHEN statusID = 1 THEN 1
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
AND serviceIsConsultDoctor = 'N'
|
||||
AND queueBranchID = {$branchID}
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (1)
|
||||
AND queueLocationID IN (SELECT GROUP_CONCAT(counterLocationID) FROM counter WHERE counterID IN ($arrCounter))
|
||||
AND queueCounterID IN ($arrCounter)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY IFNULL(queueSkipDate, queueCreated)";
|
||||
$qryNotServed = $this->db_antrione->query($sqlNotServed, []);
|
||||
$last_qry_not = $this->db_antrione->last_query();
|
||||
if (!$qryNotServed) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry_not
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$notServed = $qryNotServed->result_array();
|
||||
|
||||
$sqlCall = "SELECT queueID,
|
||||
statusID, IFNULL(queueNumber,'') as queueNumber,
|
||||
queueCounterID,
|
||||
counterCode,
|
||||
counterID,
|
||||
( CASE
|
||||
WHEN statusID = 2 THEN 1
|
||||
WHEN statusID = 5 THEN 2
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
AND serviceIsConsultDoctor = 'N'
|
||||
AND queueBranchID = {$branchID}
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
JOIN counter ON queueCounterID = counterID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (2, 5)
|
||||
AND queueCounterID IN ($arrCounter)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY order_status, queueCreated asc";
|
||||
$qryCall = $this->db_antrione->query($sqlCall, []);
|
||||
$last_qry_served = $this->db_antrione->last_query();
|
||||
if (!$qryCall) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry_served
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$call = $qryCall->result_array();
|
||||
|
||||
$sqlServed = "SELECT queueID,
|
||||
statusID, IFNULL(queueNumber,'') as queueNumber,
|
||||
queueCounterID,
|
||||
counterCode,
|
||||
counterID,
|
||||
( CASE
|
||||
WHEN statusID = 3 THEN 1
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
AND serviceIsConsultDoctor = 'N'
|
||||
AND queueBranchID = {$branchID}
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
JOIN counter ON queueCounterID = counterID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (3)
|
||||
AND queueCounterID IN ($arrCounter)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY order_status, queueCreated asc";
|
||||
$qryServed = $this->db_antrione->query($sqlServed, []);
|
||||
$last_qry_call = $this->db_antrione->last_query();
|
||||
if (!$qryServed) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry_call
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$served = $qryServed->result_array();
|
||||
$data = [];
|
||||
$data["served"] = $served;
|
||||
$data['not_served'] = $notServed;
|
||||
$data['call'] = $call;
|
||||
$data['qry_call'] = $last_qry_call;
|
||||
$data['qry_not_served'] = $last_qry_not;
|
||||
$data['qry_serve'] = $last_qry_served;
|
||||
$result = array(
|
||||
$data
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
243
application/controllers/antrian/Layanandokter.php
Normal file
243
application/controllers/antrian/Layanandokter.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
class Layanandokter extends MY_Controller
|
||||
{
|
||||
var $db_antrione;
|
||||
var $load;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_antrione = $this->load->database("antrione", true);
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo ('API SERVICE');
|
||||
}
|
||||
|
||||
function list_layanan_dokter()
|
||||
{
|
||||
try {
|
||||
// if (!$this->isLogin) {
|
||||
// $this->sys_error("Invalid Token");
|
||||
// exit;
|
||||
// }
|
||||
$prm = $this->sys_input;
|
||||
$serviceId = "0";
|
||||
if (isset($prm['serviceId'])) {
|
||||
// $serviceId = trim(str_replace("[]","",$prm["serviceId"]));
|
||||
$serviceId = implode(",", $prm['serviceId']);
|
||||
}
|
||||
|
||||
// $serviceIdfix = "1,15";
|
||||
|
||||
// belum dilayani
|
||||
$sql_belum_dilayani = "SELECT queueID,
|
||||
statusID,
|
||||
IFNULL(queueNumber,'') as queueNumber,
|
||||
IFNULL(serviceDoctorName,'') as serviceDoctorName,
|
||||
CONCAT(queueNumber,'-',serviceDoctorName) as antrian_selanjutnya,
|
||||
( CASE
|
||||
WHEN statusID = 1 THEN 1
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (1)
|
||||
AND serviceIsConsultDoctor = 'Y'
|
||||
AND serviceId IN ($serviceId)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY IFNULL(queueSkipDate, queueCreated)";
|
||||
|
||||
$qry_belum_dilayani = $this->db_antrione->query($sql_belum_dilayani);
|
||||
$last_qry_belum_dilayani = $this->db_antrione->last_query();
|
||||
if (!$qry_belum_dilayani) {
|
||||
// $error = array(
|
||||
// "message" => $this->db_antrione->error()["message"],
|
||||
// "sql" => $last_qry
|
||||
// );
|
||||
// $this->sys_error_db($error);
|
||||
// exit;
|
||||
|
||||
$this->db_antrione->trans_rollback();
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => $last_qry_belum_dilayani)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$belum_dilayani = $qry_belum_dilayani->result_array();
|
||||
|
||||
$arr_serviceName = [];
|
||||
$result = [];
|
||||
foreach ($belum_dilayani as $key => $val) {
|
||||
$serviceName = $val['serviceDoctorName'];
|
||||
|
||||
if (in_array($serviceName, $arr_serviceName)) {
|
||||
continue;
|
||||
}
|
||||
$result[] = $val;
|
||||
$arr_serviceName[] = $serviceName;
|
||||
}
|
||||
|
||||
$belum_dilayani = $result;
|
||||
|
||||
$sql_call = "SELECT queueID,
|
||||
statusID,
|
||||
queueServiceID as serviceID,
|
||||
IFNULL(queueNumber,'') as queueNumber,
|
||||
IFNULL(serviceDoctorName,'') as serviceDoctorName,
|
||||
CONCAT(queueNumber,'-',serviceDoctorName) as antrian_selanjutnya,
|
||||
( CASE
|
||||
WHEN statusID = 2 THEN 1
|
||||
WHEN statusID = 5 THEN 3
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (2,5)
|
||||
AND serviceIsConsultDoctor = 'Y'
|
||||
AND serviceId IN ($serviceId)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY order_status, queueCreated asc";
|
||||
$qry_call = $this->db_antrione->query($sql_call);
|
||||
$last_qry_call = $this->db_antrione->last_query();
|
||||
if (!$qry_call) {
|
||||
$this->db_antrione->trans_rollback();
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => $last_qry_call)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$call = $qry_call->result_array();
|
||||
|
||||
$arr_serviceName = [];
|
||||
$result = [];
|
||||
foreach ($call as $key => $val) {
|
||||
$serviceName = $val['serviceDoctorName'];
|
||||
|
||||
if (in_array($serviceName, $arr_serviceName)) {
|
||||
continue;
|
||||
}
|
||||
$result[] = $val;
|
||||
$arr_serviceName[] = $serviceName;
|
||||
}
|
||||
|
||||
$call = $result;
|
||||
|
||||
// sedang dilayani
|
||||
$sql_sedang_dilayani = "SELECT queueID,
|
||||
queueServiceID as serviceID,
|
||||
IFNULL(queueNumber,'') as queueNumber,
|
||||
IFNULL(serviceDoctorName,'') as serviceDoctorName,
|
||||
CONCAT(queueNumber,'-',serviceDoctorName) as antrian_selanjutnya,
|
||||
( CASE
|
||||
WHEN statusID = 3 THEN 1
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (3)
|
||||
AND serviceIsConsultDoctor = 'Y'
|
||||
AND serviceId IN ($serviceId)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY order_status, queueCreated asc";
|
||||
$qry_sedang_dilayani = $this->db_antrione->query($sql_sedang_dilayani);
|
||||
$last_qry_sedang_dilayani = $this->db_antrione->last_query();
|
||||
if (!$qry_sedang_dilayani) {
|
||||
// $error = array(
|
||||
// "message" => $this->db_antrione->error()["message"],
|
||||
// "sql" => $last_qry
|
||||
// );
|
||||
// $this->sys_error_db($error);
|
||||
// exit;
|
||||
|
||||
$this->db_antrione->trans_rollback();
|
||||
echo json_encode(
|
||||
array("status" => "ERR", "message" => $last_qry_sedang_dilayani)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
$sedang_dilayani = $qry_sedang_dilayani->result_array();
|
||||
|
||||
$data = [];
|
||||
$data['call'] = $call;
|
||||
$data['belumDilayani'] = $belum_dilayani;
|
||||
$data['sedangDilayani'] = $sedang_dilayani;
|
||||
|
||||
$result = array(
|
||||
$data
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function list_service()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM service WHERE serviceIsActive = 'Y'
|
||||
and serviceIsConsultDoctor = 'Y'";
|
||||
$qry = $this->db_antrione->query($sql, []);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function list_service_not_consult()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM service
|
||||
WHERE serviceIsActive = 'Y'";
|
||||
$qry = $this->db_antrione->query($sql, []);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
252
application/controllers/antrian/Location.php
Normal file
252
application/controllers/antrian/Location.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
class Location extends MY_Controller
|
||||
{
|
||||
var $db_antrione;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_antrione = $this->load->database("antrione", true);
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
$cek = $this->db_antrione->query("select database() as current_db")->result();
|
||||
// echo $this->db->last_query();
|
||||
|
||||
print_r($cek);
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
try{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db_antrione->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$code = "";
|
||||
if (isset($prm['code'])) {
|
||||
$code = trim($prm["code"]);
|
||||
}
|
||||
|
||||
$name = "";
|
||||
if (isset($prm['name'])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
|
||||
$sql_data = "INSERT INTO location(
|
||||
locationCode,
|
||||
locationName,
|
||||
locationUserID,
|
||||
locationCreated,
|
||||
locationLastUpdated)
|
||||
VALUES (?, ?, ?, NOW(), NOW())";
|
||||
|
||||
$qry_data = $this->db_antrione->query($sql_data, [$code, $name, $userid]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
echo $last_qry;
|
||||
|
||||
// if(!$qry_data) {
|
||||
// $this->db_antrione->trans_rollback();
|
||||
// $error = array(
|
||||
// "message" => $this->db_antrione->error()["message"],
|
||||
// "sql" => $last_qry
|
||||
// );
|
||||
// $this->sys_error_db($error, $this->db_antrione);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $this->db_antrione->trans_commit();
|
||||
// $result = array(
|
||||
// "affected_rows" => $this->db_antrione->affected_rows(),
|
||||
// "inserted_id" => $this->db_antrione->insert_id()
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = "";
|
||||
if(isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != ""){
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
}else{
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sortBy = $prm["sortBy"];
|
||||
$sortStatus = $prm["sortStatus"];
|
||||
if($sortBy){
|
||||
$q_sort = "ORDER BY ".$sortBy." ".$sortStatus;
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
if($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(DISTINCT locationID) as total
|
||||
FROM location
|
||||
WHERE locationName like ? AND locationIsActive = 'Y'";
|
||||
|
||||
$qry_filter = $this->db_antrione->query($sql_filter, [$search]);
|
||||
// $last_qry = $this->db_antrione->last_query();
|
||||
// print_r($last_qry);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
}else{
|
||||
$this->sys_error_db("location select count", $this->db_antrione);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_data = "SELECT DISTINCT locationID as id,
|
||||
locationName, locationIsActive
|
||||
FROM location
|
||||
WHERE locationName like ? AND locationIsActive = 'Y'
|
||||
$q_sort
|
||||
limit ? offset ?";
|
||||
|
||||
$qry_data = $this->db_antrione->query($sql_data, [$search, $number_limit, $number_offset]);
|
||||
if($qry_data) {
|
||||
$rows = $qry_data->result_array();
|
||||
}else{
|
||||
$this->sys_error_db("location select", $this->db_antrione);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function edit()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_antrione->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$name = "";
|
||||
if (isset($prm['name'])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$id = "";
|
||||
if (isset($prm['id'])) {
|
||||
if (is_numeric($prm["id"])){
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE location
|
||||
SET locationName = ?,
|
||||
locationUserID = ?,
|
||||
locationLastUpdated = NOW()
|
||||
WHERE locationID = ?";
|
||||
|
||||
$qry = $this->db_antrione->query($sql, [$name, $userid, $id]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
// print_r($last_qry);
|
||||
if(!$qry) {
|
||||
$this->db_antrione->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db_antrione);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_antrione->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"affected_rows" => $this->db_antrione->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_antrione->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$id = "";
|
||||
if(isset($prm['id'])) {
|
||||
if(is_numeric($prm["id"])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE location
|
||||
SET locationIsActive = 'N',
|
||||
locationUserID = ?,
|
||||
locationLastUpdated = NOW()
|
||||
WHERE locationID = ?";
|
||||
|
||||
$qry = $this->db_antrione->query($sql, [$userid, $id]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if(!$qry){
|
||||
$this->db_antrione->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db_antrione);
|
||||
exit;
|
||||
}
|
||||
// print_r($last_qry);
|
||||
|
||||
$this->db_antrione->trans_commit();
|
||||
$result = array(
|
||||
"affected_rows" => $this->db_antrione->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
131
application/controllers/antrian/Nonlab.php
Normal file
131
application/controllers/antrian/Nonlab.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
class Nonlab extends MY_Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
function get_call($station_id=NULL,$trx_date=NULL,$status=NULL) {
|
||||
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$sql = " SELECT CONCAT(IFNULL(M_TitleName,''),' ',IFNULL(M_PatientPrefix,''),M_PatientName,IFNULL(M_PatientSuffix,'')) as patient_name,
|
||||
T_SamplingQueueLastStatusID as trx_id,
|
||||
T_SampleStationName as sample_station,
|
||||
T_OrderHeaderLabNumber as nolab,
|
||||
T_OrderHeaderLabNumberExt as nolab_ext
|
||||
FROM t_sampling_queue_last_status
|
||||
JOIN t_orderheader ON T_OrderHeaderID = T_SamplingQueueLastStatusT_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN t_samplestation ON T_SamplingQueueLastStatusT_SampleStationID = T_SampleStationID AND
|
||||
T_SampleStationIsActive = 'Y'
|
||||
WHERE
|
||||
T_SamplingQueueLastStatusT_SampleStationID = ? AND
|
||||
T_SamplingQueueLastStatusT_SamplingQueueStatusID = ? AND
|
||||
DATE(T_SamplingQueueLastStatusLastUpdated) = ? AND
|
||||
T_SamplingQueueLastStatusIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,array($station_id,$status,$trx_date));
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$row = $query->result_array();
|
||||
$s_data = $row;
|
||||
$this->sys_ok($s_data);
|
||||
exit;
|
||||
}
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error_db("NOT FOUND CALL", $this->db_onedev);
|
||||
|
||||
}
|
||||
|
||||
function get_data($station_id=NULL,$trx_date=NULL) {
|
||||
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$sql = "SELECT T_OrderHeaderID as order_id,
|
||||
T_OrderHeaderLabNumber as nolab,
|
||||
T_OrderHeaderLabNumberExt as nolab_ext,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',IFNULL(M_PatientPrefix,''),M_PatientName,IFNULL(M_PatientSuffix,'')) as patient_name,
|
||||
IFNULL(T_SamplingQueueStatusName,'new') as status,
|
||||
IFNULL(T_SamplingQueueLastStatusT_SamplingQueueStatusID,0) as last_status_id
|
||||
FROM t_orderheader
|
||||
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
LEFT JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
|
||||
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
||||
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
||||
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = ?
|
||||
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
|
||||
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND
|
||||
T_SamplingSoT_TestID = T_TestID AND
|
||||
T_SamplingSoT_SampleStationID = T_SampleStationID AND
|
||||
T_SamplingSoIsActive = 'Y'
|
||||
LEFT JOIN t_sampling_queue_last_status ON T_OrderHeaderID = T_SamplingQueueLastStatusT_OrderHeaderID
|
||||
LEFT JOIN t_sampling_queue_status ON T_SamplingQueueLastStatusT_SamplingQueueStatusID = T_SamplingQueueStatusID AND
|
||||
T_SamplingCallStatusIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderHeaderIsActive = 'Y' AND
|
||||
( DATE(T_OrderHeaderAddonIsComingDate) = ? OR DATE(T_OrderHeaderDate) = ? )
|
||||
GROUP BY T_OrderHeaderID
|
||||
HAVING fn_fo_get_laststatus(T_OrderHeaderID) IN (3,5) AND last_status_id NOT IN (1,3,5)
|
||||
ORDER BY T_OrderHeaderIsCito DESC, T_OrderHeaderID ASC";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql,array($station_id,$trx_date,$trx_date));
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$row = $query->result_array();
|
||||
$s_data = $row;
|
||||
$this->sys_ok($s_data);
|
||||
exit;
|
||||
}
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error_db("NOT FOUND CALL", $this->db_onedev);
|
||||
|
||||
}
|
||||
|
||||
function get_station(){
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$sql = " SELECT T_SampleStationID as id,
|
||||
T_SampleStationCode as code,
|
||||
T_SampleStationName as name,
|
||||
T_SampleStationIsNonLab as is_nonlab
|
||||
FROM t_samplestation
|
||||
WHERE
|
||||
T_SampleStationIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$row = $query->result_array();
|
||||
$s_data = $row;
|
||||
$this->sys_ok($s_data);
|
||||
exit;
|
||||
}
|
||||
$this->sys_error_db("NOT FOUND CALL", $this->db_onedev);
|
||||
}
|
||||
|
||||
function get_images(){
|
||||
$dir = "/home/one/project/one/one-media/one-antrian/nonlab/";
|
||||
$files = scandir($dir);
|
||||
$results = [];
|
||||
foreach ($files as $key => $value) {
|
||||
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
|
||||
if (!is_dir($path)) {
|
||||
$results[] = $_SERVER['SERVER_NAME']."/one-media/one-antrian/nonlab/".basename($path, ".pdf");
|
||||
} else if ($value != "." && $value != "..") {
|
||||
getDirContents($path, $results);
|
||||
$results[] = $_SERVER['SERVER_NAME']."/one-media/one-antrian/nonlab/".basename($path, ".pdf");
|
||||
}
|
||||
}
|
||||
$this->sys_ok($results);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
1210
application/controllers/antrian/Queuefov2-12-04-2023.php
Normal file
1210
application/controllers/antrian/Queuefov2-12-04-2023.php
Normal file
File diff suppressed because it is too large
Load Diff
1461
application/controllers/antrian/Queuefov2.php
Normal file
1461
application/controllers/antrian/Queuefov2.php
Normal file
File diff suppressed because it is too large
Load Diff
1212
application/controllers/antrian/Queuefov2.php-19-04-2023
Normal file
1212
application/controllers/antrian/Queuefov2.php-19-04-2023
Normal file
File diff suppressed because it is too large
Load Diff
1426
application/controllers/antrian/Queuefov2.php-310125
Normal file
1426
application/controllers/antrian/Queuefov2.php-310125
Normal file
File diff suppressed because it is too large
Load Diff
349
application/controllers/antrian/Service.php
Normal file
349
application/controllers/antrian/Service.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
class Service extends MY_Controller
|
||||
{
|
||||
var $db_antrione;
|
||||
var $load;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_antrione = $this->load->database("antrione", true);
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo ('API SERVICE');
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
// print_r($prm);
|
||||
// exit;
|
||||
$search = "%%";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
}
|
||||
$order_by = "serviceCode";
|
||||
if (isset($prm['order_by'])) {
|
||||
$order_by = trim($prm["order_by"]);
|
||||
}
|
||||
$order = "asc";
|
||||
if (isset($prm['order'])) {
|
||||
$order = trim($prm["order"]);
|
||||
}
|
||||
$sort = "order by " . $order_by . " " . $order;
|
||||
$page = $prm["page"];
|
||||
$ROW_PER_PAGE = 10;
|
||||
$start_offset = 0;
|
||||
if (isset($prm["page"])) {
|
||||
if (
|
||||
is_numeric($prm["page"]) && $prm["page"] > 0
|
||||
) {
|
||||
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
||||
}
|
||||
}
|
||||
$total_count = 0;
|
||||
$total_page = 0;
|
||||
|
||||
$sqlCount = "SELECT COUNT(*) AS total FROM service
|
||||
WHERE serviceIsActive = 'Y'
|
||||
AND ( serviceCode LIKE ? OR serviceName LIKE ?)
|
||||
ORDER BY serviceCode";
|
||||
$qryCount = $this->db_antrione->query($sqlCount, [$search, $search]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCount) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT * FROM service
|
||||
WHERE serviceIsActive = 'Y'
|
||||
AND ( serviceCode LIKE ? OR serviceName LIKE ?)
|
||||
$sort
|
||||
LIMIT 10 OFFSET ?";
|
||||
$qry = $this->db_antrione->query($sql, [$search, $search, $start_offset]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$total = $qryCount->row_array();
|
||||
$total_count = $total['total'];
|
||||
$total_page = ceil($total_count / $ROW_PER_PAGE);
|
||||
$data = $qry->result_array();
|
||||
$result = array(
|
||||
"total_filter" => $total_count,
|
||||
"total" => $total_page,
|
||||
"records" => $data,
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function add()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$code = "";
|
||||
if (isset($prm['code'])) {
|
||||
$code = trim($prm["code"]);
|
||||
}
|
||||
$name = "";
|
||||
if (isset($prm['name'])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$priority = "";
|
||||
if (isset($prm['priority'])) {
|
||||
$priority = trim($prm["priority"]);
|
||||
}
|
||||
$foOrder = "";
|
||||
if (isset($prm['foOrder'])) {
|
||||
$foOrder = trim($prm["foOrder"]);
|
||||
}
|
||||
|
||||
$isConsultDoctor = "";
|
||||
if (isset($prm['isConsultDoctor'])) {
|
||||
$isConsultDoctor = trim($prm["isConsultDoctor"]);
|
||||
}
|
||||
|
||||
$nameDoctor = "";
|
||||
if (isset($prm['nameDoctor'])) {
|
||||
$nameDoctor = trim($prm["nameDoctor"]);
|
||||
}
|
||||
|
||||
if ($isConsultDoctor == 'Y') {
|
||||
if ($code == "" || $name == "" || $priority == "" || $foOrder == "" || $nameDoctor == "") {
|
||||
$this->sys_error("code, name, priority, fo order, nama dokter is mandatory");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
if ($code == "" || $name == "" || $priority == "" || $foOrder == "") {
|
||||
$this->sys_error("code, name, priority, fo order is mandatory");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db_antrione->trans_begin();
|
||||
$sql = "INSERT INTO service
|
||||
(serviceCode,
|
||||
serviceName,
|
||||
servicePriority,
|
||||
serviceIsFoOrder,
|
||||
serviceIsConsultDoctor,
|
||||
serviceDoctorName
|
||||
)
|
||||
VALUES(?, ?, ?, ?, ?, ?)";
|
||||
$qry = $this->db_antrione->query($sql, [$code, $name, $priority, $foOrder, $isConsultDoctor, $nameDoctor]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$insertedId = $this->db_antrione->insert_id();
|
||||
$sqlNumbering = "INSERT INTO numbering
|
||||
(numberingServiceID,
|
||||
numberingPrefix,
|
||||
numberingDigit,
|
||||
numberingReset)
|
||||
VALUES(? ,? , 4, 'D')";
|
||||
$qryNumbering = $this->db_antrione->query($sqlNumbering, [$insertedId, $insertedId]);
|
||||
if (!$qryNumbering) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$this->db_antrione->trans_complete();
|
||||
$result = array(
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function update()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$code = "";
|
||||
if (isset($prm['code'])) {
|
||||
$code = trim($prm["code"]);
|
||||
}
|
||||
$id = "";
|
||||
if (isset($prm['id'])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
$name = "";
|
||||
if (isset($prm['name'])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$priority = "";
|
||||
if (isset($prm['priority'])) {
|
||||
$priority = trim($prm["priority"]);
|
||||
}
|
||||
$foOrder = "";
|
||||
if (isset($prm['foOrder'])) {
|
||||
$foOrder = trim($prm["foOrder"]);
|
||||
}
|
||||
|
||||
$isConsultDoctor = "";
|
||||
if (isset($prm['isConsultDoctor'])) {
|
||||
$isConsultDoctor = trim($prm["isConsultDoctor"]);
|
||||
}
|
||||
|
||||
$nameDoctor = "";
|
||||
if (isset($prm['nameDoctor'])) {
|
||||
$nameDoctor = trim($prm["nameDoctor"]);
|
||||
}
|
||||
|
||||
if ($isConsultDoctor == 'Y') {
|
||||
if ($code == "" || $name == "" || $priority == "" || $foOrder == "" || $nameDoctor == "") {
|
||||
$this->sys_error("code, name, priority, fo order, nama dokter is mandatory");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
if ($code == "" || $name == "" || $priority == "" || $foOrder == "") {
|
||||
$this->sys_error("code, name, priority, fo order is mandatory");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE service SET serviceCode = ?,
|
||||
serviceName = ?,
|
||||
servicePriority = ?,
|
||||
serviceIsFoOrder = ?,
|
||||
serviceIsConsultDoctor = ?,
|
||||
serviceDoctorName = ?
|
||||
WHERE serviceID = ?";
|
||||
$qry = $this->db_antrione->query($sql, [$code, $name, $priority, $foOrder, $isConsultDoctor, $nameDoctor, $id]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$result = array(
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$id = "";
|
||||
if (isset($prm['id'])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
$this->db_antrione->trans_begin();
|
||||
$sql = "UPDATE service SET
|
||||
serviceIsActive = 'N'
|
||||
WHERE serviceID = ?";
|
||||
$qry = $this->db_antrione->query($sql, [intval($id)]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$sqlNumbering = "UPDATE numbering SET
|
||||
numberingIsActive = 'N'
|
||||
WHERE numberingServiceID = ?";
|
||||
$qryNumbering = $this->db_antrione->query($sqlNumbering, [intval($id)]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryNumbering) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$this->db_antrione->trans_complete();
|
||||
$result = array(
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function listService()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM service WHERE serviceIsActive = 'Y'";
|
||||
$qry = $this->db_antrione->query($sql, []);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
319
application/controllers/antrian/Ticket.php
Normal file
319
application/controllers/antrian/Ticket.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
class Ticket extends MY_Controller
|
||||
{
|
||||
var $db_antrione;
|
||||
var $load;
|
||||
var $IP_SOCKET_IO;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_antrione = $this->load->database("antrione", true);
|
||||
$this->IP_SOCKET_IO = "127.0.0.1";
|
||||
// $this->IP_SOCKET_IO = "devone.aplikasi.web.id";
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo ('API GET ANTRIAN NUMBER');
|
||||
}
|
||||
function getAntrian()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$serviceId = '';
|
||||
if (isset($prm['service_id'])) {
|
||||
$serviceId = trim($prm["service_id"]);
|
||||
}
|
||||
$boothId = '';
|
||||
if (isset($prm['booth_id'])) {
|
||||
$boothId = trim($prm["booth_id"]);
|
||||
}
|
||||
$branchID = '';
|
||||
if (isset($prm['branch_id'])) {
|
||||
$branchID = trim($prm["branch_id"]);
|
||||
}
|
||||
if ($serviceId == '' || $boothId == '' || $branchID == '') {
|
||||
$this->sys_error_db("service id, booth id, branch id are mandatory");
|
||||
exit;
|
||||
}
|
||||
$this->db_antrione->trans_begin();
|
||||
$sqlCek = "SELECT * FROM service
|
||||
WHERE serviceIsActive = 'Y'
|
||||
AND serviceID = ?";
|
||||
$qryCek = $this->db_antrione->query($sqlCek, [$serviceId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$serviceCek = $qryCek->result_array();
|
||||
// print_r($serviceCek);
|
||||
// exit;
|
||||
if (count($serviceCek) == 0) {
|
||||
$error = array(
|
||||
"message" => "service tidak ada ",
|
||||
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
$this->db_antrione->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlGetLocation = "SELECT *, SUM(fn_get_max_queue(counterID, counterBranchID)) as maxQueue FROM counter
|
||||
LEFT JOIN counter_service ON counterID = counterServiceCounterID
|
||||
AND counterServiceIsActive = 'Y'
|
||||
JOIN location ON counterLocationID = locationID
|
||||
AND locationIsActive = 'Y'
|
||||
WHERE (counterIsDedicated = 'N' OR counterServiceServiceID = ?)
|
||||
AND counterBranchID = ?
|
||||
AND counterIsActive = 'Y'
|
||||
GROUP BY locationID
|
||||
ORDER BY locationID";
|
||||
// $sqlGetLocation = "SELECT *, SUM(counterMaxQueue) as maxQueue FROM
|
||||
// counter_service
|
||||
// JOIN counter ON counterServiceCounterID = counterID
|
||||
// AND counterIsActive = 'Y'
|
||||
// JOIN location ON counterLocationID = locationID
|
||||
// AND locationIsActive = 'Y'
|
||||
// WHERE counterServiceServiceID = ?
|
||||
// AND counterServiceIsActive = 'Y'
|
||||
// GROUP BY locationID
|
||||
// ORDER BY locationID";
|
||||
$qrygetLocation = $this->db_antrione->query($sqlGetLocation, [$serviceId, $branchID]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$location = $qrygetLocation->result_array();
|
||||
// print_r($location);
|
||||
// exit;
|
||||
$ticketMsg = '';
|
||||
|
||||
$locationIdFinal = 0;
|
||||
$countLocation = count($location);
|
||||
$masukMana = "";
|
||||
if ($countLocation == 0) {
|
||||
$locationIdFinal = 1;
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office";
|
||||
$masukMana = "TIdak ada counter yang melayani";
|
||||
}
|
||||
if ($countLocation == 1) {
|
||||
$locationId = intval($location[0]['locationID']);
|
||||
$sqlCek = "SELECT COUNT(queueID) as total FROM queue
|
||||
WHERE
|
||||
DATE_FORMAT(queueCreated, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
|
||||
AND queueIsActive = 'Y'
|
||||
AND queueStatusID <> 4
|
||||
AND queueLocationID = ?
|
||||
AND queueServiceID = ?
|
||||
AND queueBranchID = ?";
|
||||
$qryCek = $this->db_antrione->query($sqlCek, [$locationId, $serviceId, $branchID]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$queue = $qryCek->row_array();
|
||||
$queueNum = intval($queue['total']);
|
||||
if ($queueNum < $location[0]["maxQueue"]) {
|
||||
$locationIdFinal = $location[0]['locationID'];
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office " . $location[0]['locationName'];
|
||||
$masukMana = "ada 1 counter yang melayani";
|
||||
} else {
|
||||
$locationIdFinal = 1;
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office Lantai 1";
|
||||
$masukMana = "ada 1 counter yang melayani";
|
||||
}
|
||||
}
|
||||
if ($countLocation > 1) {
|
||||
|
||||
$locationDedicated = array();
|
||||
foreach ($location as $value) {
|
||||
$locationId = intval($value["locationID"]);
|
||||
$sqlCek = "SELECT COUNT(queueID) as total FROM queue
|
||||
WHERE
|
||||
DATE_FORMAT(queueCreated, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
|
||||
AND queueIsActive = 'Y'
|
||||
AND queueStatusID <> 4
|
||||
AND queueLocationID = ?
|
||||
AND queueServiceID = ?
|
||||
AND queueBranchID = ?";
|
||||
$qryCek = $this->db_antrione->query($sqlCek, [$locationId, $serviceId, $branchID]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$queue = $qryCek->row_array();
|
||||
$queueNum = intval($queue['total']);
|
||||
|
||||
if ($value['counterIsDedicated'] == 'Y' && $queueNum < $value["maxQueue"]) {
|
||||
$locationDedicated = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// print_r($locationDedicated);
|
||||
// exit;
|
||||
if ($locationDedicated) {
|
||||
$locationIdFinal = $locationDedicated['locationID'];
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office " . $locationDedicated['locationName'];
|
||||
} else {
|
||||
for ($i = 0; $i < $countLocation; $i++) {
|
||||
$val = $location[$i];
|
||||
$maxQueue = intval($val["maxQueue"]);
|
||||
$locationId = intval($val["locationID"]);
|
||||
$locationName = $val['locationName'];
|
||||
$isDedicated = $val['counterIsDedicated'];
|
||||
|
||||
$sqlCek = "SELECT COUNT(queueID) as total FROM queue
|
||||
WHERE
|
||||
DATE_FORMAT(queueCreated, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
|
||||
AND queueIsActive = 'Y'
|
||||
AND queueStatusID <> 4
|
||||
AND queueLocationID = ?
|
||||
AND queueServiceID = ?
|
||||
AND queueBranchID = ?";
|
||||
$qryCek = $this->db_antrione->query($sqlCek, [$locationId, $serviceId, $branchID]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$queue = $qryCek->row_array();
|
||||
$queueNum = intval($queue['total']);
|
||||
if ($countLocation == ($i + 1) && $queueNum >= $maxQueue) {
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office " . $location[0]['locationName'];
|
||||
$locationIdFinal = $location[0]['locationID'];
|
||||
$masukMana = "countLocation == key && queueNum >= maxQueue";
|
||||
break;
|
||||
}
|
||||
if ($queueNum < $maxQueue) {
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office " . $locationName;
|
||||
$masukMana = "queueNum < maxQueue";
|
||||
$locationIdFinal = $locationId;
|
||||
break;
|
||||
}
|
||||
if ($queueNum >= $maxQueue) {
|
||||
$masukMana = "queueNum >= maxQueue";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// print_r([$masukMana, $queueNum, $location, $queue, $ticketMsg]);
|
||||
// exit;
|
||||
$sqlGetNumber = "SELECT fn_get_numbering(?, ?) AS number";
|
||||
$qryGetNumber = $this->db_antrione->query($sqlGetNumber, [$serviceId, $branchID]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$number = $qryGetNumber->row_array();
|
||||
$numberQueue = $number['number'];
|
||||
|
||||
$uniqueCode = bin2hex(random_bytes(13)); // Generate a unique code of 25 characters
|
||||
|
||||
$sqlInsert = "INSERT INTO queue
|
||||
(queueNumber,
|
||||
queueStatusID,
|
||||
queueServiceID,
|
||||
queueLocationID,
|
||||
queueTicketBoothID,
|
||||
queueBranchID,
|
||||
queueCode)
|
||||
VALUES
|
||||
(?, 1, ?, ?, ?, ?, ?)";
|
||||
$qryInsert = $this->db_antrione->query($sqlInsert, [$numberQueue, $serviceId, $locationIdFinal, $boothId, $branchID, $uniqueCode]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryInsert) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$queueId = $this->db_antrione->insert_id();
|
||||
|
||||
$sqlLog = "INSERT INTO queuelog
|
||||
(queueLogDate,
|
||||
queueLogStatusID,
|
||||
queueLogCounterID)
|
||||
VALUES(NOW(),1,0)";
|
||||
$qryLog = $this->db_antrione->query($sqlLog);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryLog) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$logId = $this->db_antrione->insert_id();
|
||||
|
||||
$sqlUpdate = "UPDATE queue SET
|
||||
queueQueueLogID = ?
|
||||
WHERE queueID = ?";
|
||||
$qryUpdate = $this->db_antrione->query($sqlUpdate, [$logId, $queueId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryUpdate) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$logId = $this->db_antrione->insert_id();
|
||||
$this->db_antrione->trans_complete();
|
||||
$result = array(
|
||||
"number" => $numberQueue,
|
||||
"location" => $ticketMsg,
|
||||
"bagian" => $masukMana,
|
||||
"code" => $uniqueCode,
|
||||
"maxQueuePerLantai" => $location
|
||||
);
|
||||
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9088/broadcast/printed.fo.{$serviceId}.{$branchID}");
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
302
application/controllers/antrian/Ticketrspad.php
Normal file
302
application/controllers/antrian/Ticketrspad.php
Normal file
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
class Ticketrspad extends MY_Controller
|
||||
{
|
||||
var $db_antrione;
|
||||
var $load;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_antrione = $this->load->database("antrione", true);
|
||||
$this->IP_SOCKET_IO = "devone.aplikasi.web.id";
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo ('API GET ANTRIAN NUMBER');
|
||||
}
|
||||
function getAntrian()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$serviceId = '';
|
||||
if (isset($prm['service_id'])) {
|
||||
$serviceId = trim($prm["service_id"]);
|
||||
}
|
||||
$boothId = '';
|
||||
if (isset($prm['booth_id'])) {
|
||||
$boothId = trim($prm["booth_id"]);
|
||||
}
|
||||
if ($serviceId == '' || $boothId == '') {
|
||||
$this->sys_error_db("service id & booth id is mandatory");
|
||||
exit;
|
||||
}
|
||||
$this->db_antrione->trans_begin();
|
||||
$sqlCek = "SELECT * FROM service
|
||||
WHERE serviceIsActive = 'Y'
|
||||
AND serviceID = ?";
|
||||
$qryCek = $this->db_antrione->query($sqlCek, [$serviceId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$serviceCek = $qryCek->result_array();
|
||||
if (count($serviceCek) == 0) {
|
||||
$error = array(
|
||||
"message" => "service tidak ada ",
|
||||
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
$this->db_antrione->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlGetLocation = "SELECT *, SUM(fn_get_max_queue(counterID)) as maxQueue FROM counter
|
||||
LEFT JOIN counter_service ON counterID = counterServiceCounterID
|
||||
AND counterServiceIsActive = 'Y'
|
||||
JOIN location ON counterLocationID = locationID
|
||||
AND locationIsActive = 'Y'
|
||||
WHERE (counterIsDedicated = 'N' OR counterServiceServiceID = ?)
|
||||
AND counterIsActive = 'Y'
|
||||
GROUP BY locationID
|
||||
ORDER BY locationID";
|
||||
// $sqlGetLocation = "SELECT *, SUM(counterMaxQueue) as maxQueue FROM
|
||||
// counter_service
|
||||
// JOIN counter ON counterServiceCounterID = counterID
|
||||
// AND counterIsActive = 'Y'
|
||||
// JOIN location ON counterLocationID = locationID
|
||||
// AND locationIsActive = 'Y'
|
||||
// WHERE counterServiceServiceID = ?
|
||||
// AND counterServiceIsActive = 'Y'
|
||||
// GROUP BY locationID
|
||||
// ORDER BY locationID";
|
||||
$qrygetLocation = $this->db_antrione->query($sqlGetLocation, [$serviceId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$location = $qrygetLocation->result_array();
|
||||
// print_r($location);
|
||||
// exit;
|
||||
$ticketMsg = '';
|
||||
|
||||
$locationIdFinal = 0;
|
||||
$countLocation = count($location);
|
||||
$masukMana = "";
|
||||
if ($countLocation == 0) {
|
||||
$locationIdFinal = 1;
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office";
|
||||
$masukMana = "TIdak ada counter yang melayani";
|
||||
}
|
||||
if ($countLocation == 1) {
|
||||
$locationId = intval($location[0]['locationID']);
|
||||
$sqlCek = "SELECT COUNT(queueID) as total FROM queue
|
||||
WHERE
|
||||
DATE_FORMAT(queueCreated, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
|
||||
AND queueIsActive = 'Y'
|
||||
AND queueStatusID <> 4
|
||||
AND queueLocationID = ?
|
||||
AND queueServiceID = ?";
|
||||
$qryCek = $this->db_antrione->query($sqlCek, [$locationId, $serviceId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$queue = $qryCek->row_array();
|
||||
$queueNum = intval($queue['total']);
|
||||
if ($queueNum < $location[0]["maxQueue"]) {
|
||||
$locationIdFinal = $location[0]['locationID'];
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office " . $location[0]['locationName'];
|
||||
$masukMana = "ada 1 counter yang melayani";
|
||||
} else {
|
||||
$locationIdFinal = 1;
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office Lantai 1";
|
||||
$masukMana = "ada 1 counter yang melayani";
|
||||
}
|
||||
}
|
||||
if ($countLocation > 1) {
|
||||
|
||||
$locationDedicated = array();
|
||||
foreach ($location as $value) {
|
||||
$locationId = intval($value["locationID"]);
|
||||
$sqlCek = "SELECT COUNT(queueID) as total FROM queue
|
||||
WHERE
|
||||
DATE_FORMAT(queueCreated, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
|
||||
AND queueIsActive = 'Y'
|
||||
AND queueStatusID <> 4
|
||||
AND queueLocationID = ?
|
||||
AND queueServiceID = ?";
|
||||
$qryCek = $this->db_antrione->query($sqlCek, [$locationId, $serviceId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$queue = $qryCek->row_array();
|
||||
$queueNum = intval($queue['total']);
|
||||
|
||||
if ($value['counterIsDedicated'] == 'Y' && $queueNum < $value["maxQueue"]) {
|
||||
$locationDedicated = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// print_r($locationDedicated);
|
||||
// exit;
|
||||
if ($locationDedicated) {
|
||||
$locationIdFinal = $locationDedicated['locationID'];
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office " . $locationDedicated['locationName'];
|
||||
} else {
|
||||
for ($i = 0; $i < $countLocation; $i++) {
|
||||
$val = $location[$i];
|
||||
$maxQueue = intval($val["maxQueue"]);
|
||||
$locationId = intval($val["locationID"]);
|
||||
$locationName = $val['locationName'];
|
||||
$isDedicated = $val['counterIsDedicated'];
|
||||
|
||||
$sqlCek = "SELECT COUNT(queueID) as total FROM queue
|
||||
WHERE
|
||||
DATE_FORMAT(queueCreated, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
|
||||
AND queueIsActive = 'Y'
|
||||
AND queueStatusID <> 4
|
||||
AND queueLocationID = ?
|
||||
AND queueServiceID = ?";
|
||||
$qryCek = $this->db_antrione->query($sqlCek, [$locationId, $serviceId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$queue = $qryCek->row_array();
|
||||
$queueNum = intval($queue['total']);
|
||||
if ($countLocation == ($i + 1) && $queueNum >= $maxQueue) {
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office " . $location[0]['locationName'];
|
||||
$locationIdFinal = $location[0]['locationID'];
|
||||
$masukMana = "countLocation == key && queueNum >= maxQueue";
|
||||
break;
|
||||
}
|
||||
if ($queueNum < $maxQueue) {
|
||||
$ticketMsg = "Anda Akan Dilayan Di Front Office " . $locationName;
|
||||
$masukMana = "queueNum < maxQueue";
|
||||
$locationIdFinal = $locationId;
|
||||
break;
|
||||
}
|
||||
if ($queueNum >= $maxQueue) {
|
||||
$masukMana = "queueNum >= maxQueue";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// print_r([$masukMana, $queueNum, $location, $queue, $ticketMsg]);
|
||||
// exit;
|
||||
$sqlGetNumber = "SELECT fn_get_numbering(?) AS number";
|
||||
$qryGetNumber = $this->db_antrione->query($sqlGetNumber, [$serviceId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryCek) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$number = $qryGetNumber->row_array();
|
||||
$numberQueue = $number['number'];
|
||||
|
||||
$sqlInsert = "INSERT INTO queue
|
||||
(queueNumber,
|
||||
queueStatusID,
|
||||
queueServiceID,
|
||||
queueLocationID,
|
||||
queueTicketBoothID)
|
||||
VALUES
|
||||
(?, 1, ?, ?, ?)";
|
||||
$qryInsert = $this->db_antrione->query($sqlInsert, [$numberQueue, $serviceId, $locationIdFinal, $boothId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryInsert) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$queueId = $this->db_antrione->insert_id();
|
||||
|
||||
$sqlLog = "INSERT INTO queuelog
|
||||
(queueLogDate,
|
||||
queueLogStatusID,
|
||||
queueLogCounterID)
|
||||
VALUES(NOW(),1,0)";
|
||||
$qryLog = $this->db_antrione->query($sqlLog);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryLog) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$logId = $this->db_antrione->insert_id();
|
||||
|
||||
$sqlUpdate = "UPDATE queue SET
|
||||
queueQueueLogID = ?
|
||||
WHERE queueID = ?";
|
||||
$qryUpdate = $this->db_antrione->query($sqlUpdate, [$logId, $queueId]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qryUpdate) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->db_antrione->trans_rollback();
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$logId = $this->db_antrione->insert_id();
|
||||
$this->db_antrione->trans_complete();
|
||||
$result = array(
|
||||
"number" => $numberQueue,
|
||||
"location" => $ticketMsg,
|
||||
"bagian" => $masukMana,
|
||||
"maxQueuePerLantai" => $location
|
||||
);
|
||||
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/printed.fo.{$serviceId}");
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
235
application/controllers/antrian_online/Download_aol.php
Normal file
235
application/controllers/antrian_online/Download_aol.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
class Download_aol extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->baseUrl = "https://mobile.pramita.co.id/one_api_coba/antrian_online/downloader/";
|
||||
}
|
||||
function index()
|
||||
{
|
||||
|
||||
//branch
|
||||
$sql =
|
||||
"select * from m_branch where M_BranchIsActive='Y' and M_BranchIsDefault='Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n . {$this->db->last_query}";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->log("ERR : No Default Branch");
|
||||
exit();
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$url = $this->baseUrl . "download/$branchID";
|
||||
$resp = $this->get($url);
|
||||
if ($resp["status"] != "OK") {
|
||||
echo json_encode($resp);
|
||||
exit;
|
||||
}
|
||||
$total = 0;
|
||||
foreach ($resp["data"] as $data) {
|
||||
$total++;
|
||||
$this->db->trans_begin();
|
||||
$queueID = $data["queueID"];
|
||||
$queue = [];
|
||||
$subservice = [];
|
||||
$patient = [];
|
||||
foreach ($data as $k => $v) {
|
||||
if (strpos($k, "queue") === 0) {
|
||||
$queue[$k] = $v;
|
||||
}
|
||||
if (strpos($k, "M_Patient") === 0) {
|
||||
$patient[$k] = $v;
|
||||
}
|
||||
if (strpos($k, "subService") === 0) {
|
||||
$subservice[$k] = $v;
|
||||
}
|
||||
}
|
||||
//insert into antrian_online.queue
|
||||
$resp = $this->insert_or_update("antrian_online.queue", $queue, ["queueID"]);
|
||||
if ($resp["status"] != "OK") {
|
||||
echo json_encode($resp);
|
||||
exit;
|
||||
}
|
||||
//insert or update antrian_online.subservice
|
||||
$resp = $this->insert_or_update(
|
||||
"antrian_online.subservice",
|
||||
$subservice,
|
||||
["subServiceID"]
|
||||
);
|
||||
if ($resp["status"] != "OK") {
|
||||
echo json_encode($resp);
|
||||
exit;
|
||||
}
|
||||
//insert or update antrian_online.m_patient
|
||||
$resp = $this->insert_or_update(
|
||||
"antrian_online.m_patient",
|
||||
$patient,
|
||||
["M_PatientID"]
|
||||
);
|
||||
if ($resp["status"] != "OK") {
|
||||
echo json_encode($resp);
|
||||
exit;
|
||||
}
|
||||
// post to update
|
||||
$prm = ["queueID" => $queueID, "status" => "Y"];
|
||||
$url = $this->baseUrl . "/update";
|
||||
$resp = $this->post($url, json_encode($prm));
|
||||
if ($resp["status"] == "OK") {
|
||||
$this->db->trans_commit();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
echo json_encode($resp);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
echo json_encode(["status" => "OK", "message" => "$total Queue Downloaded"]);
|
||||
}
|
||||
function insert_or_update($table, $dt, $keys)
|
||||
{
|
||||
$s_where = "";
|
||||
$param = [];
|
||||
foreach ($keys as $k) {
|
||||
if ($s_where != "") {
|
||||
$s_where .= " and ";
|
||||
}
|
||||
$s_where .= " $k = ?";
|
||||
$param[] = $dt[$k];
|
||||
}
|
||||
$sql = "select count(*) as total
|
||||
from $table
|
||||
where $s_where ";
|
||||
$qry = $this->db->query($sql, $param);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$status = "Insert";
|
||||
if (count($rows) > 0) {
|
||||
if ($rows[0]["total"] > 0) {
|
||||
foreach ($keys as $k) {
|
||||
$this->db->where($k, $dt[$k]);
|
||||
}
|
||||
$qry = $this->db->update($table, $dt);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"ERR Update : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$status = "Update";
|
||||
} else {
|
||||
//insert
|
||||
$qry = $this->db->insert($table, $dt);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"ERR Insert : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//insert
|
||||
$qry = $this->db->insert($table, $dt);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"ERR Insert : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
}
|
||||
return ["status" => "OK", "message" => $status];
|
||||
}
|
||||
function log($msg)
|
||||
{
|
||||
echo "{$this->now()} $msg\n";
|
||||
}
|
||||
function get($url)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch) > 0) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => curl_error($ch),
|
||||
];
|
||||
}
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode != 200) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "Http Response : $httpCode",
|
||||
];
|
||||
}
|
||||
$j_result = json_decode($result, true);
|
||||
if (!$j_result) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "JSON invalid: $result",
|
||||
];
|
||||
}
|
||||
return $j_result;
|
||||
}
|
||||
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_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/octet-stream",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch) > 0) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => curl_error($ch),
|
||||
];
|
||||
}
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode != 200) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "Http Response : $httpCode",
|
||||
];
|
||||
}
|
||||
$j_result = json_decode($result, true);
|
||||
if (!$j_result) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "JSON invalid: $result",
|
||||
];
|
||||
}
|
||||
return $j_result;
|
||||
}
|
||||
}
|
||||
207
application/controllers/antrian_online/Upload_aol.php
Normal file
207
application/controllers/antrian_online/Upload_aol.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
class Upload_aol extends MY_Controller
|
||||
{
|
||||
var $base_url;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->debug = false;
|
||||
$this->base_url = "https://mobile.pramita.co.id/";
|
||||
}
|
||||
function now()
|
||||
{
|
||||
return Date("Y-m-d H:i:s");
|
||||
}
|
||||
function log($msg)
|
||||
{
|
||||
echo "{$this->now()} $msg\n";
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
//antrian_upload
|
||||
$this->db->trans_begin();
|
||||
$sql =
|
||||
"select * from antrian_upload where AntrianUploadIsActive='Y' and AntrianUploadIsSent ='N' limit 0,1";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->log("Error antrian_upload : " . $this->db->error()["message"]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
if (count($qry->result_array()) == 0) {
|
||||
$this->log("No Pending antrian_upload.");
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
//branch
|
||||
$sql =
|
||||
"select * from m_branch where M_BranchIsActive='Y' and M_BranchIsDefault='Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n . {$this->db->last_query}";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->log("ERR : No Default Branch");
|
||||
exit();
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$branchCode = $rows[0]["M_BranchCode"];
|
||||
//subservice
|
||||
//subservice_kuota
|
||||
//subservice_kuota_detail
|
||||
$sql =
|
||||
"select ? subServiceM_BranchID, subservice.*
|
||||
from subservice";
|
||||
$qry = $this->db->query($sql, [$branchID]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR subservice: {$this->db->error()["message"]}\n . {$this->db->last_query()}";
|
||||
exit();
|
||||
}
|
||||
$subservice = $qry->result_array();
|
||||
|
||||
$sql = "select ? subServiceQuotaM_BranchID, subservice_kuota.*
|
||||
from subservice_kuota";
|
||||
$qry = $this->db->query($sql, [$branchID]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR subservice_kuota: {$this->db->error()["message"]}\n . {$this->db->last_query()}";
|
||||
exit();
|
||||
}
|
||||
$subservice_kuota = $qry->result_array();
|
||||
|
||||
$sql = "select ? SubServiceKuotaDetailM_BranchID, subservice_kuota_detail.*
|
||||
from subservice_kuota_detail";
|
||||
$qry = $this->db->query($sql, [$branchID]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR subservice_kuota_detail : {$this->db->error()["message"]}\n . {$this->db->last_query()}";
|
||||
exit();
|
||||
}
|
||||
$subservice_kuota_detail = $qry->result_array();
|
||||
|
||||
$data = [
|
||||
"subservice" => $subservice,
|
||||
"subservice_kuota" => $subservice_kuota,
|
||||
"subservice_kuota_detail" => $subservice_kuota_detail,
|
||||
];
|
||||
$jdata = json_encode($data);
|
||||
$md5 = md5($jdata);
|
||||
$param = ["md5" => $md5, "data" => $data];
|
||||
$jparam = json_encode($param);
|
||||
$zparam = gzcompress($jparam);
|
||||
$size = round(strlen($zparam) / 1024, 2);
|
||||
$size_org = round(strlen($jparam) / 1024, 2);
|
||||
$this->log(
|
||||
"Upload SubService Kuota Masterdata (compressed): " .
|
||||
$size_org .
|
||||
" => " .
|
||||
$size .
|
||||
" kB"
|
||||
);
|
||||
$url = "{$this->base_url}one-api/antrian_online/r_aol";
|
||||
$resp = $this->post($url, $zparam);
|
||||
if ($resp["status"] == "ERR") {
|
||||
$this->log("Error Upload Subservice Masterdata " . $resp["message"]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$sql =
|
||||
"update antrian_upload set AntrianUploadIsSent='Y', AntrianUploadSentDate = now() where AntrianUploadIsSent='N' and AntrianUploadIsActive='Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR update antrian_upload : {$this->db->error()["message"]}\n . {$this->db->last_query()}";
|
||||
exit();
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->log("Upload Subservice MasterData [OK] " . json_encode($resp["result"]));
|
||||
}
|
||||
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_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/octet-stream",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch) > 0) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => curl_error($ch),
|
||||
];
|
||||
}
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode != 200) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "Http Response : $httpCode",
|
||||
];
|
||||
}
|
||||
$j_result = json_decode($result, true);
|
||||
if (!$j_result) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "JSON invalid: $result",
|
||||
];
|
||||
}
|
||||
return $j_result;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
CREATE TABLE `hs_schedule` (
|
||||
`HS_ScheduleID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`HS_ScheduleM_BranchID` int(11) NOT NULL,
|
||||
`HS_ScheduleM_BranchCode` varchar(2),
|
||||
`HS_ScheduleM_RegDayID` int(11) NOT NULL,
|
||||
`HS_ScheduleLimit` int(11) NOT NULL DEFAULT 10,
|
||||
`HS_ScheduleIsActive` char(1) NOT NULL DEFAULT 'Y',
|
||||
`HS_ScheduleUserID` int(11) NOT NULL DEFAULT 3,
|
||||
`HS_ScheduleCreated` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`HS_ScheduleLastUpdated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||
PRIMARY KEY (`HS_ScheduleID`,HS_ScheduleM_BranchID),
|
||||
key(HS_ScheduleM_RegDayID),
|
||||
key(HS_ScheduleM_BranchCode)
|
||||
);
|
||||
|
||||
CREATE TABLE `hs_scheduledetail` (
|
||||
`HS_ScheduleDetailID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`HS_ScheduleDetailM_BranchID` int(11) NOT NULL ,
|
||||
`HS_ScheduleDetailM_BranchCode` varchar(2) NOT NULL ,
|
||||
`HS_ScheduleDetailHS_ScheduleID` int(11) NOT NULL,
|
||||
`HS_ScheduleDetailM_RegTimeID` int(11) NOT NULL,
|
||||
`HS_ScheduleDetailIsActive` char(1) NOT NULL DEFAULT 'Y',
|
||||
`HS_ScheduleDetailUserID` int(11) NOT NULL DEFAULT 3,
|
||||
`HS_ScheduleDetailCreated` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`HS_ScheduleDetailLastUpdated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||
PRIMARY KEY (`HS_ScheduleDetailID`,HS_ScheduleDetailM_BranchID),
|
||||
KEY `HS_ScheduleDetailHS_ScheduleID` (`HS_ScheduleDetailHS_ScheduleID`),
|
||||
KEY `HS_ScheduleDetailHS_Time` (`HS_ScheduleDetailM_RegTimeID`)
|
||||
);
|
||||
|
||||
drop table hs_sum_tx;
|
||||
create table hs_sum_tx (
|
||||
HS_SumTxM_BranchID int,
|
||||
HS_SumTxM_BranchCode varchar(2),
|
||||
HS_SumTxT_TransactionID int,
|
||||
HS_SumTxT_TrancactionCreated datetime,
|
||||
HS_SumTxT_OrderDateTime datetime,
|
||||
HS_SumTxT_OrderID int,
|
||||
HS_SumTxT_OrderNumber varchar(50),
|
||||
HS_SumTxT_TransactionIsActive varchar(1),
|
||||
HS_SumTxT_OrderIsActive varchar(1),
|
||||
primary key (HS_SumTxM_BranchID,HS_SumTxT_TransactionID,HS_SumTxT_OrderID),
|
||||
key (HS_SumTxM_BranchID),
|
||||
key (HS_SumTxT_TransactionID),
|
||||
key (HS_SumTxT_TrancactionCreated),
|
||||
key (HS_SumTxT_OrderDateTime),
|
||||
key (HS_SumTxT_OrderIsActive),
|
||||
key (HS_SumTxT_TransactionIsActive)
|
||||
);
|
||||
*/
|
||||
39
application/controllers/chart/Qr_polos.php
Normal file
39
application/controllers/chart/Qr_polos.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
class Qr_polos extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function pcr($nolab)
|
||||
{
|
||||
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $nolab);
|
||||
header("Content-type: image/png");
|
||||
echo $img_qrcode;
|
||||
exit;
|
||||
}
|
||||
public 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_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt(
|
||||
$ch,
|
||||
CURLOPT_HTTPHEADER,
|
||||
array(
|
||||
'Content-Type: application/text',
|
||||
'Content-Length: ' . strlen($data)
|
||||
)
|
||||
);
|
||||
$result = curl_exec($ch);
|
||||
|
||||
if (curl_error($ch) != "") {
|
||||
return "ERROR Accessing QrCode : " . curl_error($ch) . "\n";
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
430
application/controllers/chart/The_qr.php
Normal file
430
application/controllers/chart/The_qr.php
Normal file
@@ -0,0 +1,430 @@
|
||||
<?php
|
||||
class The_qr extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function get_one_row($sql, $param = false)
|
||||
{
|
||||
if ($param) {
|
||||
$qry = $this->db->query($sql, $param);
|
||||
} else {
|
||||
$qry = $this->db->query($sql);
|
||||
}
|
||||
if (!$qry) {
|
||||
return ["status" => -1];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return ["status" => 0];
|
||||
}
|
||||
return ["status" => 1, "data" => $rows[0]];
|
||||
}
|
||||
public function get_rows($sql, $param = false)
|
||||
{
|
||||
if ($param) {
|
||||
$qry = $this->db->query($sql, $param);
|
||||
} else {
|
||||
$qry = $this->db->query($sql);
|
||||
}
|
||||
if (!$qry) {
|
||||
return ["status" => -1];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return ["status" => 0];
|
||||
}
|
||||
return ["status" => 1, "data" => $rows];
|
||||
}
|
||||
public function v1($orderHeaderID, $date = "")
|
||||
{
|
||||
$sql = "call sp_rpt_t_hasil2(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
if ($rs["status"] == -1) {
|
||||
echo "Error : sp_rpt | " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
if ($rs["status"] == 0) {
|
||||
echo "Error : No Order found.";
|
||||
exit();
|
||||
}
|
||||
$rows = $rs["data"];
|
||||
$r = $rows[0];
|
||||
|
||||
$msg = <<<EOF
|
||||
{$r["T_OrderHeaderLabNumber"]}
|
||||
{$r["M_PatientName"]}
|
||||
EOF;
|
||||
$msg = trim($msg);
|
||||
$msg .= "\n";
|
||||
foreach ($rows as $r) {
|
||||
$msg .=
|
||||
$r["T_TestNameAA"] .
|
||||
" : " .
|
||||
str_replace("</br>", "", $r["T_OrderDetailResult"]) .
|
||||
"\n";
|
||||
}
|
||||
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $msg);
|
||||
header("Content-type: image/png");
|
||||
echo $img_qrcode;
|
||||
exit();
|
||||
}
|
||||
public 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_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/text",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
|
||||
if (curl_error($ch) != "") {
|
||||
return "ERROR Accessing QrCode : " . curl_error($ch) . "\n";
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
public function post_gz($url, $data)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
$zdata = gzdeflate($data, 9);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $zdata);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/octet",
|
||||
"Content-Length: " . strlen($zdata),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
|
||||
if (curl_error($ch) != "") {
|
||||
return "ERROR Accessing QrCode : " . curl_error($ch) . "\n";
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
public function post_debug($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_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/text",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
|
||||
if (curl_error($ch) != "") {
|
||||
return "ERROR Accessing QrCode : " . curl_error($ch) . "\n";
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
public function v2($orderHeaderID, $date = "")
|
||||
{
|
||||
$this->load->library("Jwt");
|
||||
$sql = "call sp_rpt_t_hasil2(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
if ($rs["status"] == -1) {
|
||||
echo "Error : sp_rpt | " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
if ($rs["status"] == 0) {
|
||||
echo "Error : No Order found.";
|
||||
exit();
|
||||
}
|
||||
$rows = $rs["data"];
|
||||
$secretToken = "--!!Super!!Suket#@!1231456";
|
||||
$j_result = json_encode($rows);
|
||||
$jwtToken = JWT::encode($j_result, $secretToken);
|
||||
|
||||
$rst = $this->post(
|
||||
"https://result.pramita.co.id/one-api/verify/shortener",
|
||||
$jwtToken
|
||||
);
|
||||
$j_rst = json_decode($rst, true);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
$url = $j_rst["url"];
|
||||
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $url);
|
||||
header("Content-type: image/png");
|
||||
echo $img_qrcode;
|
||||
exit();
|
||||
}
|
||||
|
||||
public function v3_old($orderHeaderID, $date = "")
|
||||
{
|
||||
$this->load->library("Jwt");
|
||||
$sql = "call sp_rpt_t_hasil2(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
if ($rs["status"] == -1) {
|
||||
echo "Error : sp_rpt | " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
if ($rs["status"] == 0) {
|
||||
echo "Error : No Order found.";
|
||||
exit();
|
||||
}
|
||||
$rows = $rs["data"];
|
||||
$secretToken = "--!!Super!!Suket#@!1231456";
|
||||
$j_result = json_encode($rows);
|
||||
$jwtToken = JWT::encode($j_result, $secretToken);
|
||||
|
||||
$rst = $this->post(
|
||||
"https://result.pramita.co.id/one-api/verify/shortener_v2",
|
||||
$jwtToken
|
||||
);
|
||||
$j_rst = json_decode($rst, true);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
$url = $j_rst["url"];
|
||||
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $url);
|
||||
header("Content-type: image/png");
|
||||
echo $img_qrcode;
|
||||
exit();
|
||||
}
|
||||
public function v3_dual($orderHeaderID, $date = "")
|
||||
{
|
||||
$this->load->library("Jwt");
|
||||
$sql = "call sp_rpt_t_hasil2(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
if ($rs["status"] == -1) {
|
||||
echo "Error : sp_rpt | " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
if ($rs["status"] == 0) {
|
||||
echo "Error : No Order found.";
|
||||
exit();
|
||||
}
|
||||
$rows = $rs["data"];
|
||||
$sql = "select count(*) tot
|
||||
from t_orderheaderaddon
|
||||
where T_OrderHeaderAddOnIsActive = 'Y'
|
||||
and T_OrderHeaderAddOnSecondM_LangID = 2
|
||||
and T_OrderHeaderAddOnT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$orderHeaderID]);
|
||||
if (!$qry) {
|
||||
echo "Error : " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$flag_have_en = "N";
|
||||
if ($xrows[0]["tot"] > 0) {
|
||||
$flag_have_en = "Y";
|
||||
$sql = "call sp_rpt_t_hasil_eng(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
if ($rs["status"] == -1) {
|
||||
echo "Error : sp_rpt | " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
$rows_en = $rs["data"];
|
||||
$result_en = [];
|
||||
$test_en = [];
|
||||
|
||||
foreach ($rows_en as $r) {
|
||||
list($dob_en, $age_en) = explode(
|
||||
"/",
|
||||
$r["T_OrderHeaderM_PatientAge"]
|
||||
);
|
||||
$age_en = trim($age_en);
|
||||
$sex_en = $r["M_SexName"];
|
||||
$name_en = $r["M_PatientName"];
|
||||
$testID = $r["T_TestID"];
|
||||
$result_en[$testID] = $r["T_OrderDetailResult"];
|
||||
$test_en[$testID] = $r["T_TestNameAA"];
|
||||
}
|
||||
}
|
||||
foreach ($rows as $idx => $r) {
|
||||
$rows[$idx]["HaveEnglish"] = $flag_have_en;
|
||||
$testID = $r["T_TestID"];
|
||||
if ($flag_have_en == "Y") {
|
||||
$rows[$idx]["M_PatientName_en"] = $name_en;
|
||||
$rows[$idx]["Umur_en"] = $age_en . " / " . $sex_en;
|
||||
$rows[$idx]["T_OrderDetailResult_en"] = $result_en[$testID];
|
||||
$rows[$idx]["T_TestNameAA_en"] = $test_en[$testID];
|
||||
} else {
|
||||
$rows[$idx]["Umur_en"] = "";
|
||||
$rows[$idx]["T_OrderDetailResult_en"] = "";
|
||||
$rows[$idx]["T_TestNameAA_en"] = "";
|
||||
$rows[$idx]["M_PatientName_en"] = "";
|
||||
}
|
||||
}
|
||||
|
||||
$secretToken = "--!!Super!!Suket#@!1231456";
|
||||
$j_result = json_encode($rows);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
$jwtToken = JWT::encode($j_result, $secretToken);
|
||||
$rst = $this->post_gz(
|
||||
"https://result.pramita.co.id/one-api/verify/shortener_v2_gz",
|
||||
$jwtToken
|
||||
);
|
||||
$j_rst = json_decode($rst, true);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
$url = $j_rst["url"];
|
||||
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $url);
|
||||
header("Content-type: image/png");
|
||||
echo $img_qrcode;
|
||||
exit();
|
||||
}
|
||||
public function v3($orderHeaerID, $date = "") {
|
||||
$this->v3_dual($orderHeaerID,$date);
|
||||
}
|
||||
public function v3_en($orderHeaderID, $date = "")
|
||||
{
|
||||
$this->load->library("Jwt");
|
||||
$sql = "call sp_rpt_t_hasil_eng(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
if ($rs["status"] == -1) {
|
||||
echo "Error : sp_rpt | " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
if ($rs["status"] == 0) {
|
||||
echo "Error : No Order found.";
|
||||
exit();
|
||||
}
|
||||
$rows = $rs["data"];
|
||||
$secretToken = "--!!Super!!Suket#@!1231456";
|
||||
$j_result = json_encode($rows);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
$jwtToken = JWT::encode($j_result, $secretToken);
|
||||
$rst = $this->post_gz(
|
||||
"https://result.pramita.co.id/one-api/verify/shortener_v2_gz",
|
||||
$jwtToken
|
||||
);
|
||||
$j_rst = json_decode($rst, true);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
$url = $j_rst["url"];
|
||||
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $url);
|
||||
header("Content-type: image/png");
|
||||
echo $img_qrcode;
|
||||
exit();
|
||||
}
|
||||
|
||||
public function v3_show($orderHeaderID, $date = "")
|
||||
{
|
||||
$this->load->library("Jwt");
|
||||
$sql = "call sp_rpt_t_hasil2(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
print_r($rs);
|
||||
}
|
||||
public function v3_show_en($orderHeaderID, $date = "")
|
||||
{
|
||||
$this->load->library("Jwt");
|
||||
$sql = "call sp_rpt_t_hasil_eng(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
print_r($rs);
|
||||
}
|
||||
public function v3_before_dual($orderHeaderID, $date = "")
|
||||
{
|
||||
$this->load->library("Jwt");
|
||||
$sql = "call sp_rpt_t_hasil2(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
if ($rs["status"] == -1) {
|
||||
echo "Error : sp_rpt | " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
if ($rs["status"] == 0) {
|
||||
echo "Error : No Order found.";
|
||||
exit();
|
||||
}
|
||||
$rows = $rs["data"];
|
||||
$secretToken = "--!!Super!!Suket#@!1231456";
|
||||
$j_result = json_encode($rows);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
$jwtToken = JWT::encode($j_result, $secretToken);
|
||||
$rst = $this->post_gz(
|
||||
"https://result.pramita.co.id/one-api/verify/shortener_v2_gz",
|
||||
$jwtToken
|
||||
);
|
||||
$j_rst = json_decode($rst, true);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
$url = $j_rst["url"];
|
||||
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $url);
|
||||
header("Content-type: image/png");
|
||||
echo $img_qrcode;
|
||||
exit();
|
||||
}
|
||||
|
||||
public function v3b($orderHeaderID, $date = "")
|
||||
{
|
||||
$this->load->library("Jwt");
|
||||
$sql = "call sp_rpt_t_hasil2(?,'admin')";
|
||||
$rs = $this->get_rows($sql, [$orderHeaderID]);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
if ($rs["status"] == -1) {
|
||||
echo "Error : sp_rpt | " . $this->db->error()["message"];
|
||||
exit();
|
||||
}
|
||||
if ($rs["status"] == 0) {
|
||||
echo "Error : No Order found.";
|
||||
exit();
|
||||
}
|
||||
$rows = $rs["data"];
|
||||
$secretToken = "--!!Super!!Suket#@!1231456";
|
||||
$j_result = json_encode($rows);
|
||||
$jwtToken = JWT::encode($j_result, $secretToken);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Encode Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
echo strlen($jwtToken) . "\n";
|
||||
$rst = $this->post(
|
||||
"https://result.pramita.co.id/one-api/verify/shortener_v2",
|
||||
$jwtToken
|
||||
);
|
||||
echo $rst;
|
||||
$j_rst = json_decode($rst, true);
|
||||
if (json_last_error_msg() != "No error") {
|
||||
echo "Error Json Token : " . json_last_error_msg();
|
||||
exit();
|
||||
}
|
||||
exit();
|
||||
$url = $j_rst["url"];
|
||||
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $url);
|
||||
header("Content-type: image/png");
|
||||
echo $img_qrcode;
|
||||
exit();
|
||||
}
|
||||
}
|
||||
784
application/controllers/confirm-result/Confirmresult.php
Normal file
784
application/controllers/confirm-result/Confirmresult.php
Normal file
@@ -0,0 +1,784 @@
|
||||
<?php
|
||||
class Confirmresult extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// db wilayah contoh surabaya
|
||||
// $this->db = $this->load->database("regional", true);
|
||||
|
||||
// string database
|
||||
$this->db_str_doctor = 'one_doctor';
|
||||
$this->M_MouM_CompanyID = "1235";
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "request upload";
|
||||
}
|
||||
|
||||
// search v1 tanpa proteksi lunas dan ini yang lama
|
||||
public function search_v1()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
// if (isset($prm['search'])) {
|
||||
// $search = trim($prm["search"]);
|
||||
// if ($search != "") {
|
||||
// $search = '%' . $prm['search'] . '%';
|
||||
// }else{
|
||||
// $search = '%%';
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$where = " T_OrderHeaderIsActive = 'Y' ";
|
||||
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
|
||||
$filter_date = " AND DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
if ($startdate != '' && $enddate != '') {
|
||||
$where = " T_OrderHeaderIsActive = 'Y' $filter_date ";
|
||||
}
|
||||
|
||||
if ($search != '')
|
||||
$where .= " AND ( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' OR T_OrderHeaderLabNumberExt LIKE '%{$search}%' )";
|
||||
|
||||
|
||||
$sortBy = $prm['sortBy'];
|
||||
// $sortStatus = $prm['sortStatus'];
|
||||
$q_sort = '';
|
||||
$limit = '';
|
||||
if ($sortBy) {
|
||||
$q_sort = "ORDER BY " . $sortBy;
|
||||
}
|
||||
if ($all == 'N') {
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 20;
|
||||
// $number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "select count(*) as total
|
||||
from (
|
||||
select
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
)
|
||||
as nama_pasien,
|
||||
fn_get_doctor_fullname($this->db_str_doctor.order_fo.OrderFoM_DoctorID) as nama_dokter,
|
||||
M_MouName as nama_mou,
|
||||
T_OrderHeaderTotal as total,
|
||||
if($this->db_str_doctor.request_upload.RequestUploadIsUploaded is NULL,'N',RequestUploadIsUploaded) as RequestIsUploaded
|
||||
from t_orderheader
|
||||
join $this->db_str_doctor.order_fo
|
||||
ON OrderFoT_OrderHeaderID = T_OrderHeaderID
|
||||
AND OrderFoIsActive = 'Y'
|
||||
join $this->db_str_doctor.order_patient
|
||||
ON OrderFoOrderPatientID = OrderPatientID
|
||||
AND OrderPatientIsActive = 'Y'
|
||||
left join $this->db_str_doctor.request_upload
|
||||
ON T_OrderHeaderID = RequestUploadT_OrderHeaderID
|
||||
AND RequestUploadIsActive = 'Y'
|
||||
AND RequestUploadIsUploaded = 'N'
|
||||
join m_mou
|
||||
ON OrderFoM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouM_CompanyID = 1235
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
) x";
|
||||
// $sql_param = array($search);
|
||||
// $total = $this->db->query($sql,$sql_param)->row()->total;
|
||||
|
||||
$query_filter = $this->db->query($sql_filter);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query_filter) {
|
||||
$tot_count = $query_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql_data = "select
|
||||
ifnull(RequestUploadIsUploaded,'x') as RequestUploadIsUploaded,
|
||||
if(RequestUploadLastUpdated is null,'', DATE_FORMAT(RequestUploadLastUpdated,'%d-%m-%Y %H:%i'))
|
||||
as RequestUploadLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
OrderPatientID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
)
|
||||
as nama_pasien,
|
||||
fn_get_doctor_fullname($this->db_str_doctor.order_fo.OrderFoM_DoctorID) as nama_dokter,
|
||||
M_MouName as nama_mou,
|
||||
T_OrderHeaderTotal as total,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join $this->db_str_doctor.order_fo
|
||||
ON OrderFoT_OrderHeaderID = T_OrderHeaderID
|
||||
AND OrderFoIsActive = 'Y'
|
||||
join $this->db_str_doctor.order_patient
|
||||
ON OrderFoOrderPatientID = OrderPatientID
|
||||
AND OrderPatientIsActive = 'Y'
|
||||
left join $this->db_str_doctor.request_upload
|
||||
ON T_OrderHeaderID = RequestUploadT_OrderHeaderID
|
||||
AND RequestUploadIsActive = 'Y'
|
||||
AND RequestUploadIsUploaded = 'N'
|
||||
join m_mou
|
||||
ON OrderFoM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouM_CompanyID = 1235
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
// $sql_param = array($search);
|
||||
$query_data = $this->db->query($sql_data);
|
||||
//echo $this->db->last_query();
|
||||
|
||||
if ($query_data) {
|
||||
$rows = $query_data->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$sql_dt = "";
|
||||
foreach ($rows as $k => $v) {
|
||||
$order_id = $v['T_OrderHeaderID'];
|
||||
$dt_test = [];
|
||||
$sql_dt = "SELECT T_OrderDetailT_TestName as x_test
|
||||
from t_orderdetail
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $order_id
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_TestIsPrice = 'Y'
|
||||
";
|
||||
|
||||
// echo $sql_dt;
|
||||
$xdt_test = $this->db->query($sql_dt);
|
||||
// print_r($xdt_test);
|
||||
if (!$xdt_test) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order detail");
|
||||
exit;
|
||||
} else {
|
||||
$testArr = $xdt_test->result_array();
|
||||
$rows[$k]['test'] = $testArr;
|
||||
$xno = ($k + 1) + $number_offset;
|
||||
$rows[$k]['rownumber'] = $xno;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload select");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_all" => $tot_count,
|
||||
"total_filter" => count($rows),
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
// $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, 'sql'=> $this->db->last_query());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// search dibawah ini dengan proteksi lunas
|
||||
// pas di listing ketambahan WHERE
|
||||
// (F_OrderheaderLunas = Y
|
||||
// OR M_MouIsBill = Y)
|
||||
// AND T_OrderHeaderID ada di tabel result_processtooffice
|
||||
// update code tanggal 20-07-2023
|
||||
|
||||
public function search()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
$mouID = $prm["mou_id"];
|
||||
|
||||
// if (isset($prm['search'])) {
|
||||
// $search = trim($prm["search"]);
|
||||
// if ($search != "") {
|
||||
// $search = '%' . $prm['search'] . '%';
|
||||
// }else{
|
||||
// $search = '%%';
|
||||
// }
|
||||
// }
|
||||
|
||||
$where_company = "";
|
||||
|
||||
$companyid = $prm['companyid'];
|
||||
if ($companyid != "" || $companyid != 0 || $companyid != "0") {
|
||||
$companyid = $prm['companyid'];
|
||||
$where_company = " AND M_MouM_CompanyID = $companyid";
|
||||
}
|
||||
if (isset($prm['mou_id'])) {
|
||||
# code...
|
||||
if (
|
||||
$mouID != "" || $mouID != 0 || $mouID != "0"
|
||||
) {
|
||||
$mouID = $prm['mou_id'];
|
||||
$where_company .= " AND M_MouID = $mouID";
|
||||
}
|
||||
}
|
||||
|
||||
// if (isset($prm['companyid'])) {
|
||||
// $companyid = trim($prm["companyid"]);
|
||||
// // selain all dan kosong
|
||||
// if ($companyid != "" || $companyid != 0 || $companyid != "0") {
|
||||
// $companyid = $prm['companyid'];
|
||||
// $where_company = "AND M_MouM_CompanyID = $companyid";
|
||||
// }else{
|
||||
// $where_company = "";
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$where = "";
|
||||
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
|
||||
$filter_date = " DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
if ($startdate != '' && $enddate != '') {
|
||||
$where = "$filter_date ";
|
||||
}
|
||||
|
||||
if ($search != '') {
|
||||
$where .= " AND ( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' OR T_OrderHeaderLabNumberExt LIKE '%{$search}%' ) ";
|
||||
}
|
||||
|
||||
$sortBy = $prm['sortBy'];
|
||||
// $sortStatus = $prm['sortStatus'];
|
||||
$q_sort = '';
|
||||
$limit = '';
|
||||
if ($sortBy) {
|
||||
$q_sort = "ORDER BY " . $sortBy;
|
||||
}
|
||||
if ($all == 'N') {
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 20;
|
||||
// $number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "select count(*) as total
|
||||
from (
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
AND M_MouIsBill = 'Y'
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
|
||||
UNION
|
||||
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join f_payment
|
||||
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
AND F_PaymentIsActive = 'Y'
|
||||
join f_payment_orderheader
|
||||
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
||||
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
) x";
|
||||
|
||||
$query_filter = $this->db->query($sql_filter);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query_filter) {
|
||||
$tot_count = $query_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql_data = "
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
AND M_MouIsBill = 'Y'
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
|
||||
UNION
|
||||
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join f_payment
|
||||
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
AND F_PaymentIsActive = 'Y'
|
||||
join f_payment_orderheader
|
||||
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
||||
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
// $sql_param = array($search);
|
||||
$query_data = $this->db->query($sql_data);
|
||||
//echo $this->db->last_query();
|
||||
|
||||
if ($query_data) {
|
||||
$rows = $query_data->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$sql_dt = "";
|
||||
foreach ($rows as $k => $v) {
|
||||
$order_id = $v['T_OrderHeaderID'];
|
||||
$dt_test = [];
|
||||
$sql_dt = "SELECT T_OrderDetailT_TestName as x_test
|
||||
from t_orderdetail
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $order_id
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_TestIsPrice = 'Y'
|
||||
";
|
||||
|
||||
// echo $sql_dt;
|
||||
$xdt_test = $this->db->query($sql_dt);
|
||||
// print_r($xdt_test);
|
||||
if (!$xdt_test) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order detail");
|
||||
exit;
|
||||
} else {
|
||||
$testArr = $xdt_test->result_array();
|
||||
$rows[$k]['test'] = $testArr;
|
||||
$xno = ($k + 1) + $number_offset;
|
||||
$rows[$k]['rownumber'] = $xno;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_all" => $tot_count,
|
||||
"total_filter" => count($rows),
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query(),
|
||||
"sql_data" => ($sql_data),
|
||||
"sql_filter" => ($sql_filter)
|
||||
);
|
||||
// $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, 'sql'=> $this->db->last_query());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses insert log
|
||||
public function proses_insert_one_result_log($OneResultConfirmStatus, $OneResultLogOneResultConfirmID)
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_insert = "INSERT INTO one_result_log(
|
||||
OneResultLogAction,
|
||||
OneResultLogM_UserID,
|
||||
OneResultLogDate,
|
||||
OneResultLogOneResultConfirmID
|
||||
) values (
|
||||
?,
|
||||
?,
|
||||
NOW(),
|
||||
?
|
||||
)";
|
||||
|
||||
$qry = $this->db->query(
|
||||
$sql_insert,
|
||||
[
|
||||
$OneResultConfirmStatus,
|
||||
$userID,
|
||||
$OneResultLogOneResultConfirmID
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "insert one_result_log | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
return $this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses confirm
|
||||
public function process_confirm()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
$OneResultConfirmT_OrderHeaderID = $prm['OneResultConfirmT_OrderHeaderID'];
|
||||
|
||||
$sql_insert = "INSERT INTO one_result_confirm(
|
||||
OneResultConfirmT_OrderHeaderID,
|
||||
OneResultConfirmStatus,
|
||||
OneResultConfirmM_UserID,
|
||||
OneResultConfirmCreated
|
||||
) values (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW()
|
||||
)";
|
||||
|
||||
$qry = $this->db->query(
|
||||
$sql_insert,
|
||||
[
|
||||
$OneResultConfirmT_OrderHeaderID,
|
||||
"C",
|
||||
$userID
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry) {
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "insert one_result_confirm | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$OneResultLogOneResultConfirmID = $this->db->insert_id();
|
||||
|
||||
// Confirmed
|
||||
$OneResultConfirmStatus = "C";
|
||||
$this->proses_insert_one_result_log($OneResultConfirmStatus, $OneResultLogOneResultConfirmID);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
|
||||
// $result = array(
|
||||
// "total" => 1 ,
|
||||
// "records" => $prm
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses reupload
|
||||
public function process_reupload()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$OneResultConfirmID = $prm['OneResultConfirmID'];
|
||||
|
||||
$sql_update = "UPDATE one_result_confirm
|
||||
SET
|
||||
OneResultConfirmStatus = ?,
|
||||
OneResultConfirmRetry = ?,
|
||||
OneResultConfirmLastUpdated = NOW()
|
||||
WHERE OneResultConfirmID = ?";
|
||||
|
||||
$qry = $this->db->query(
|
||||
$sql_update,
|
||||
[
|
||||
"R",
|
||||
"0",
|
||||
$OneResultConfirmID,
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry) {
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "update one_result_confirm | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Confirmed
|
||||
$OneResultConfirmStatus = "R";
|
||||
$this->proses_insert_one_result_log($OneResultConfirmStatus, $OneResultConfirmID);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
|
||||
// $result = array(
|
||||
// "total" => 1 ,
|
||||
// "records" => $prm
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// autocomplete M_CompanyID
|
||||
public function search_company()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$qry = "%" . $prm["qry"] . '%';
|
||||
|
||||
$sql = "Select M_CompanyID, M_CompanyName
|
||||
from m_company
|
||||
where M_CompanyName like ?
|
||||
and M_CompanyIsActive = 'Y'
|
||||
limit 0,30";
|
||||
$query = $this->db->query($sql, array($qry));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$rows = $query->result_array();
|
||||
$rows[] = array("M_CompanyID" => 0, "M_CompanyName" => "Semua");
|
||||
$result = array("data" => $rows);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}
|
||||
public function search_mou()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$qry = "%" . $prm["qry"] . '%';
|
||||
$companyID = $prm["company_id"];
|
||||
|
||||
$sql = "SELECT
|
||||
M_MouID,
|
||||
M_MouName,
|
||||
M_MouM_CompanyID
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouM_CompanyID = ?
|
||||
AND M_MouName LIKE ?
|
||||
AND M_MouIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($companyID, $qry));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$rows = $query->result_array();
|
||||
$rows[] = array("M_MouID" => 0, "M_MouName" => "Semua", "M_MouM_CompanyID" => 0);
|
||||
$result = array("data" => $rows);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
744
application/controllers/confirm-result/Confirmresult.php190224
Normal file
744
application/controllers/confirm-result/Confirmresult.php190224
Normal file
@@ -0,0 +1,744 @@
|
||||
<?php
|
||||
class Confirmresult extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// db wilayah contoh surabaya
|
||||
// $this->db = $this->load->database("regional", true);
|
||||
|
||||
// string database
|
||||
$this->db_str_doctor = 'one_doctor';
|
||||
$this->M_MouM_CompanyID = "1235";
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "request upload";
|
||||
}
|
||||
|
||||
// search v1 tanpa proteksi lunas dan ini yang lama
|
||||
public function search_v1()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
// if (isset($prm['search'])) {
|
||||
// $search = trim($prm["search"]);
|
||||
// if ($search != "") {
|
||||
// $search = '%' . $prm['search'] . '%';
|
||||
// }else{
|
||||
// $search = '%%';
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$where = " T_OrderHeaderIsActive = 'Y' ";
|
||||
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
|
||||
$filter_date = " AND DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
if($startdate != '' && $enddate !=''){
|
||||
$where = " T_OrderHeaderIsActive = 'Y' $filter_date ";
|
||||
}
|
||||
|
||||
if($search != '')
|
||||
$where .= " AND ( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' OR T_OrderHeaderLabNumberExt LIKE '%{$search}%' )";
|
||||
|
||||
|
||||
$sortBy = $prm['sortBy'];
|
||||
// $sortStatus = $prm['sortStatus'];
|
||||
$q_sort = '';
|
||||
$limit = '';
|
||||
if($sortBy){
|
||||
$q_sort = "ORDER BY ".$sortBy;
|
||||
}
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 20;
|
||||
// $number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$number_offset = 0;
|
||||
if($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "select count(*) as total
|
||||
from (
|
||||
select
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
)
|
||||
as nama_pasien,
|
||||
fn_get_doctor_fullname($this->db_str_doctor.order_fo.OrderFoM_DoctorID) as nama_dokter,
|
||||
M_MouName as nama_mou,
|
||||
T_OrderHeaderTotal as total,
|
||||
if($this->db_str_doctor.request_upload.RequestUploadIsUploaded is NULL,'N',RequestUploadIsUploaded) as RequestIsUploaded
|
||||
from t_orderheader
|
||||
join $this->db_str_doctor.order_fo
|
||||
ON OrderFoT_OrderHeaderID = T_OrderHeaderID
|
||||
AND OrderFoIsActive = 'Y'
|
||||
join $this->db_str_doctor.order_patient
|
||||
ON OrderFoOrderPatientID = OrderPatientID
|
||||
AND OrderPatientIsActive = 'Y'
|
||||
left join $this->db_str_doctor.request_upload
|
||||
ON T_OrderHeaderID = RequestUploadT_OrderHeaderID
|
||||
AND RequestUploadIsActive = 'Y'
|
||||
AND RequestUploadIsUploaded = 'N'
|
||||
join m_mou
|
||||
ON OrderFoM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouM_CompanyID = 1235
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
) x";
|
||||
// $sql_param = array($search);
|
||||
// $total = $this->db->query($sql,$sql_param)->row()->total;
|
||||
|
||||
$query_filter = $this->db->query($sql_filter);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query_filter) {
|
||||
$tot_count = $query_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql_data = "select
|
||||
ifnull(RequestUploadIsUploaded,'x') as RequestUploadIsUploaded,
|
||||
if(RequestUploadLastUpdated is null,'', DATE_FORMAT(RequestUploadLastUpdated,'%d-%m-%Y %H:%i'))
|
||||
as RequestUploadLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
OrderPatientID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
)
|
||||
as nama_pasien,
|
||||
fn_get_doctor_fullname($this->db_str_doctor.order_fo.OrderFoM_DoctorID) as nama_dokter,
|
||||
M_MouName as nama_mou,
|
||||
T_OrderHeaderTotal as total,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join $this->db_str_doctor.order_fo
|
||||
ON OrderFoT_OrderHeaderID = T_OrderHeaderID
|
||||
AND OrderFoIsActive = 'Y'
|
||||
join $this->db_str_doctor.order_patient
|
||||
ON OrderFoOrderPatientID = OrderPatientID
|
||||
AND OrderPatientIsActive = 'Y'
|
||||
left join $this->db_str_doctor.request_upload
|
||||
ON T_OrderHeaderID = RequestUploadT_OrderHeaderID
|
||||
AND RequestUploadIsActive = 'Y'
|
||||
AND RequestUploadIsUploaded = 'N'
|
||||
join m_mou
|
||||
ON OrderFoM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouM_CompanyID = 1235
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
// $sql_param = array($search);
|
||||
$query_data = $this->db->query($sql_data);
|
||||
//echo $this->db->last_query();
|
||||
|
||||
if ($query_data) {
|
||||
$rows = $query_data->result_array();
|
||||
if(count($rows) > 0){
|
||||
$sql_dt = "";
|
||||
foreach($rows as $k => $v){
|
||||
$order_id = $v['T_OrderHeaderID'];
|
||||
$dt_test = [];
|
||||
$sql_dt = "SELECT T_OrderDetailT_TestName as x_test
|
||||
from t_orderdetail
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $order_id
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_TestIsPrice = 'Y'
|
||||
";
|
||||
|
||||
// echo $sql_dt;
|
||||
$xdt_test = $this->db->query($sql_dt);
|
||||
// print_r($xdt_test);
|
||||
if(!$xdt_test){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order detail");
|
||||
exit;
|
||||
}else{
|
||||
$testArr = $xdt_test->result_array();
|
||||
$rows[$k]['test'] = $testArr;
|
||||
$xno = ($k + 1) + $number_offset;
|
||||
$rows[$k]['rownumber'] = $xno;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload select");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_all"=>$tot_count,
|
||||
"total_filter"=>count($rows),
|
||||
"records" => $rows,
|
||||
"sql"=> $this->db->last_query()
|
||||
);
|
||||
// $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, 'sql'=> $this->db->last_query());
|
||||
$this->sys_ok($result);
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// search dibawah ini dengan proteksi lunas
|
||||
// pas di listing ketambahan WHERE
|
||||
// (F_OrderheaderLunas = Y
|
||||
// OR M_MouIsBill = Y)
|
||||
// AND T_OrderHeaderID ada di tabel result_processtooffice
|
||||
// update code tanggal 20-07-2023
|
||||
|
||||
public function search()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
// if (isset($prm['search'])) {
|
||||
// $search = trim($prm["search"]);
|
||||
// if ($search != "") {
|
||||
// $search = '%' . $prm['search'] . '%';
|
||||
// }else{
|
||||
// $search = '%%';
|
||||
// }
|
||||
// }
|
||||
|
||||
$where_company = "";
|
||||
|
||||
$companyid = $prm['companyid'];
|
||||
if ($companyid != "" || $companyid != 0 || $companyid != "0") {
|
||||
$companyid = $prm['companyid'];
|
||||
$where_company = "AND M_MouM_CompanyID = $companyid";
|
||||
}
|
||||
|
||||
// if (isset($prm['companyid'])) {
|
||||
// $companyid = trim($prm["companyid"]);
|
||||
// // selain all dan kosong
|
||||
// if ($companyid != "" || $companyid != 0 || $companyid != "0") {
|
||||
// $companyid = $prm['companyid'];
|
||||
// $where_company = "AND M_MouM_CompanyID = $companyid";
|
||||
// }else{
|
||||
// $where_company = "";
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$where = "";
|
||||
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
|
||||
$filter_date = " DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
if($startdate != '' && $enddate !=''){
|
||||
$where = "$filter_date ";
|
||||
}
|
||||
|
||||
if($search != ''){
|
||||
$where .= " AND ( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' OR T_OrderHeaderLabNumberExt LIKE '%{$search}%' ) ";
|
||||
}
|
||||
|
||||
$sortBy = $prm['sortBy'];
|
||||
// $sortStatus = $prm['sortStatus'];
|
||||
$q_sort = '';
|
||||
$limit = '';
|
||||
if($sortBy){
|
||||
$q_sort = "ORDER BY ".$sortBy;
|
||||
}
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 20;
|
||||
// $number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$number_offset = 0;
|
||||
if($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "select count(*) as total
|
||||
from (
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
AND M_MouIsBill = 'Y'
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
|
||||
UNION
|
||||
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join f_payment
|
||||
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
AND F_PaymentIsActive = 'Y'
|
||||
join f_payment_orderheader
|
||||
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
||||
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
) x";
|
||||
|
||||
$query_filter = $this->db->query($sql_filter);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query_filter) {
|
||||
$tot_count = $query_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql_data = "
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
AND M_MouIsBill = 'Y'
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
|
||||
UNION
|
||||
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join f_payment
|
||||
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
AND F_PaymentIsActive = 'Y'
|
||||
join f_payment_orderheader
|
||||
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
||||
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
// $sql_param = array($search);
|
||||
$query_data = $this->db->query($sql_data);
|
||||
//echo $this->db->last_query();
|
||||
|
||||
if ($query_data) {
|
||||
$rows = $query_data->result_array();
|
||||
if(count($rows) > 0){
|
||||
$sql_dt = "";
|
||||
foreach($rows as $k => $v){
|
||||
$order_id = $v['T_OrderHeaderID'];
|
||||
$dt_test = [];
|
||||
$sql_dt = "SELECT T_OrderDetailT_TestName as x_test
|
||||
from t_orderdetail
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $order_id
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_TestIsPrice = 'Y'
|
||||
";
|
||||
|
||||
// echo $sql_dt;
|
||||
$xdt_test = $this->db->query($sql_dt);
|
||||
// print_r($xdt_test);
|
||||
if(!$xdt_test){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order detail");
|
||||
exit;
|
||||
}else{
|
||||
$testArr = $xdt_test->result_array();
|
||||
$rows[$k]['test'] = $testArr;
|
||||
$xno = ($k + 1) + $number_offset;
|
||||
$rows[$k]['rownumber'] = $xno;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_all" => $tot_count,
|
||||
"total_filter" => count($rows),
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query(),
|
||||
"sql_data" => ($sql_data),
|
||||
"sql_filter" => ($sql_filter)
|
||||
);
|
||||
// $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, 'sql'=> $this->db->last_query());
|
||||
$this->sys_ok($result);
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses insert log
|
||||
public function proses_insert_one_result_log($OneResultConfirmStatus, $OneResultLogOneResultConfirmID)
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_insert = "INSERT INTO one_result_log(
|
||||
OneResultLogAction,
|
||||
OneResultLogM_UserID,
|
||||
OneResultLogDate,
|
||||
OneResultLogOneResultConfirmID
|
||||
) values (
|
||||
?,
|
||||
?,
|
||||
NOW(),
|
||||
?
|
||||
)";
|
||||
|
||||
$qry = $this->db->query($sql_insert,
|
||||
[
|
||||
$OneResultConfirmStatus,
|
||||
$userID,
|
||||
$OneResultLogOneResultConfirmID
|
||||
]);
|
||||
|
||||
if(!$qry){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "insert one_result_log | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
return $this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses confirm
|
||||
public function process_confirm()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
$OneResultConfirmT_OrderHeaderID = $prm['OneResultConfirmT_OrderHeaderID'];
|
||||
|
||||
$sql_insert = "INSERT INTO one_result_confirm(
|
||||
OneResultConfirmT_OrderHeaderID,
|
||||
OneResultConfirmStatus,
|
||||
OneResultConfirmM_UserID,
|
||||
OneResultConfirmCreated
|
||||
) values (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW()
|
||||
)";
|
||||
|
||||
$qry = $this->db->query($sql_insert,
|
||||
[
|
||||
$OneResultConfirmT_OrderHeaderID,
|
||||
"C",
|
||||
$userID
|
||||
]);
|
||||
|
||||
if(!$qry){
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "insert one_result_confirm | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$OneResultLogOneResultConfirmID = $this->db->insert_id();
|
||||
|
||||
// Confirmed
|
||||
$OneResultConfirmStatus = "C";
|
||||
$this->proses_insert_one_result_log($OneResultConfirmStatus, $OneResultLogOneResultConfirmID);
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
|
||||
// $result = array(
|
||||
// "total" => 1 ,
|
||||
// "records" => $prm
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses reupload
|
||||
public function process_reupload()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$OneResultConfirmID = $prm['OneResultConfirmID'];
|
||||
|
||||
$sql_update = "UPDATE one_result_confirm
|
||||
SET
|
||||
OneResultConfirmStatus = ?,
|
||||
OneResultConfirmRetry = ?,
|
||||
OneResultConfirmLastUpdated = NOW()
|
||||
WHERE OneResultConfirmID = ?";
|
||||
|
||||
$qry = $this->db->query($sql_update,
|
||||
[
|
||||
"R",
|
||||
"0",
|
||||
$OneResultConfirmID,
|
||||
]);
|
||||
|
||||
if(!$qry){
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "update one_result_confirm | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Confirmed
|
||||
$OneResultConfirmStatus = "R";
|
||||
$this->proses_insert_one_result_log($OneResultConfirmStatus, $OneResultConfirmID);
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
|
||||
// $result = array(
|
||||
// "total" => 1 ,
|
||||
// "records" => $prm
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// autocomplete M_CompanyID
|
||||
public function search_company()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$qry = "%" . $prm["qry"] . '%';
|
||||
|
||||
$sql = "Select M_CompanyID, M_CompanyName
|
||||
from m_company
|
||||
where M_CompanyName like ?
|
||||
and M_CompanyIsActive = 'Y'
|
||||
limit 0,30";
|
||||
$query = $this->db->query($sql, array($qry) );
|
||||
if(!$query){
|
||||
$this->sys_error_db("", $this->db);
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
$rows = $query->result_array();
|
||||
$rows[] = array("M_CompanyID" => 0, "M_CompanyName" => "Semua");
|
||||
$result = array("data" => $rows );
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
791
application/controllers/confirm-result/Confirmresult_v2.php
Normal file
791
application/controllers/confirm-result/Confirmresult_v2.php
Normal file
@@ -0,0 +1,791 @@
|
||||
<?php
|
||||
class Confirmresult_v2 extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// db wilayah contoh surabaya
|
||||
// $this->db = $this->load->database("regional", true);
|
||||
|
||||
// string database
|
||||
$this->db_str_doctor = 'one_doctor';
|
||||
$this->M_MouM_CompanyID = "1235";
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "request upload";
|
||||
}
|
||||
|
||||
// search v1 tanpa proteksi lunas dan ini yang lama
|
||||
public function search_v1()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
// if (isset($prm['search'])) {
|
||||
// $search = trim($prm["search"]);
|
||||
// if ($search != "") {
|
||||
// $search = '%' . $prm['search'] . '%';
|
||||
// }else{
|
||||
// $search = '%%';
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$where = " T_OrderHeaderIsActive = 'Y' ";
|
||||
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
|
||||
$filter_date = " AND DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
if ($startdate != '' && $enddate != '') {
|
||||
$where = " T_OrderHeaderIsActive = 'Y' $filter_date ";
|
||||
}
|
||||
|
||||
if ($search != '')
|
||||
$where .= " AND ( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' OR T_OrderHeaderLabNumberExt LIKE '%{$search}%' )";
|
||||
|
||||
|
||||
$sortBy = $prm['sortBy'];
|
||||
// $sortStatus = $prm['sortStatus'];
|
||||
$q_sort = '';
|
||||
$limit = '';
|
||||
if ($sortBy) {
|
||||
$q_sort = "ORDER BY " . $sortBy;
|
||||
}
|
||||
if ($all == 'N') {
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 20;
|
||||
// $number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "select count(*) as total
|
||||
from (
|
||||
select
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
)
|
||||
as nama_pasien,
|
||||
fn_get_doctor_fullname($this->db_str_doctor.order_fo.OrderFoM_DoctorID) as nama_dokter,
|
||||
M_MouName as nama_mou,
|
||||
T_OrderHeaderTotal as total,
|
||||
if($this->db_str_doctor.request_upload.RequestUploadIsUploaded is NULL,'N',RequestUploadIsUploaded) as RequestIsUploaded
|
||||
from t_orderheader
|
||||
join $this->db_str_doctor.order_fo
|
||||
ON OrderFoT_OrderHeaderID = T_OrderHeaderID
|
||||
AND OrderFoIsActive = 'Y'
|
||||
join $this->db_str_doctor.order_patient
|
||||
ON OrderFoOrderPatientID = OrderPatientID
|
||||
AND OrderPatientIsActive = 'Y'
|
||||
left join $this->db_str_doctor.request_upload
|
||||
ON T_OrderHeaderID = RequestUploadT_OrderHeaderID
|
||||
AND RequestUploadIsActive = 'Y'
|
||||
AND RequestUploadIsUploaded = 'N'
|
||||
join m_mou
|
||||
ON OrderFoM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouM_CompanyID = 1235
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
) x";
|
||||
// $sql_param = array($search);
|
||||
// $total = $this->db->query($sql,$sql_param)->row()->total;
|
||||
|
||||
$query_filter = $this->db->query($sql_filter);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query_filter) {
|
||||
$tot_count = $query_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql_data = "select
|
||||
ifnull(RequestUploadIsUploaded,'x') as RequestUploadIsUploaded,
|
||||
if(RequestUploadLastUpdated is null,'', DATE_FORMAT(RequestUploadLastUpdated,'%d-%m-%Y %H:%i'))
|
||||
as RequestUploadLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
OrderPatientID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
)
|
||||
as nama_pasien,
|
||||
fn_get_doctor_fullname($this->db_str_doctor.order_fo.OrderFoM_DoctorID) as nama_dokter,
|
||||
M_MouName as nama_mou,
|
||||
T_OrderHeaderTotal as total,
|
||||
'' as test
|
||||
from t_orderheader
|
||||
join $this->db_str_doctor.order_fo
|
||||
ON OrderFoT_OrderHeaderID = T_OrderHeaderID
|
||||
AND OrderFoIsActive = 'Y'
|
||||
join $this->db_str_doctor.order_patient
|
||||
ON OrderFoOrderPatientID = OrderPatientID
|
||||
AND OrderPatientIsActive = 'Y'
|
||||
left join $this->db_str_doctor.request_upload
|
||||
ON T_OrderHeaderID = RequestUploadT_OrderHeaderID
|
||||
AND RequestUploadIsActive = 'Y'
|
||||
AND RequestUploadIsUploaded = 'N'
|
||||
join m_mou
|
||||
ON OrderFoM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouM_CompanyID = 1235
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
// $sql_param = array($search);
|
||||
$query_data = $this->db->query($sql_data);
|
||||
//echo $this->db->last_query();
|
||||
|
||||
if ($query_data) {
|
||||
$rows = $query_data->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$sql_dt = "";
|
||||
foreach ($rows as $k => $v) {
|
||||
$order_id = $v['T_OrderHeaderID'];
|
||||
$dt_test = [];
|
||||
$sql_dt = "SELECT T_OrderDetailT_TestName as x_test
|
||||
from t_orderdetail
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $order_id
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_TestIsPrice = 'Y'
|
||||
";
|
||||
|
||||
// echo $sql_dt;
|
||||
$xdt_test = $this->db->query($sql_dt);
|
||||
// print_r($xdt_test);
|
||||
if (!$xdt_test) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order detail");
|
||||
exit;
|
||||
} else {
|
||||
$testArr = $xdt_test->result_array();
|
||||
$rows[$k]['test'] = $testArr;
|
||||
$xno = ($k + 1) + $number_offset;
|
||||
$rows[$k]['rownumber'] = $xno;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload select");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_all" => $tot_count,
|
||||
"total_filter" => count($rows),
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
// $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, 'sql'=> $this->db->last_query());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// search dibawah ini dengan proteksi lunas
|
||||
// pas di listing ketambahan WHERE
|
||||
// (F_OrderheaderLunas = Y
|
||||
// OR M_MouIsBill = Y)
|
||||
// AND T_OrderHeaderID ada di tabel result_processtooffice
|
||||
// update code tanggal 20-07-2023
|
||||
|
||||
public function search()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
$mouID = $prm["mou_id"];
|
||||
|
||||
// if (isset($prm['search'])) {
|
||||
// $search = trim($prm["search"]);
|
||||
// if ($search != "") {
|
||||
// $search = '%' . $prm['search'] . '%';
|
||||
// }else{
|
||||
// $search = '%%';
|
||||
// }
|
||||
// }
|
||||
|
||||
$where_company = "";
|
||||
|
||||
$companyid = $prm['companyid'];
|
||||
if ($companyid != "" || $companyid != 0 || $companyid != "0") {
|
||||
$companyid = $prm['companyid'];
|
||||
$where_company = "AND M_MouM_CompanyID = $companyid";
|
||||
}
|
||||
if (isset($prm['mou_id'])) {
|
||||
# code...
|
||||
if (
|
||||
$mouID != "" || $mouID != 0 || $mouID != "0"
|
||||
) {
|
||||
$mouID = $prm['mou_id'];
|
||||
$where_company .= " AND M_MouID = $mouID";
|
||||
}
|
||||
}
|
||||
|
||||
// if (isset($prm['companyid'])) {
|
||||
// $companyid = trim($prm["companyid"]);
|
||||
// // selain all dan kosong
|
||||
// if ($companyid != "" || $companyid != 0 || $companyid != "0") {
|
||||
// $companyid = $prm['companyid'];
|
||||
// $where_company = "AND M_MouM_CompanyID = $companyid";
|
||||
// }else{
|
||||
// $where_company = "";
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$where = "";
|
||||
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
|
||||
$filter_date = " DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
if ($startdate != '' && $enddate != '') {
|
||||
$where = "$filter_date ";
|
||||
}
|
||||
|
||||
if ($search != '') {
|
||||
$where .= " AND ( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' OR T_OrderHeaderLabNumberExt LIKE '%{$search}%' ) ";
|
||||
}
|
||||
|
||||
$sortBy = $prm['sortBy'];
|
||||
// $sortStatus = $prm['sortStatus'];
|
||||
$q_sort = '';
|
||||
$limit = '';
|
||||
if ($sortBy) {
|
||||
$q_sort = "ORDER BY " . $sortBy;
|
||||
}
|
||||
if ($all == 'N') {
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 20;
|
||||
// $number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "select count(*) as total
|
||||
from (
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test,
|
||||
M_MouName
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
AND M_MouIsBill = 'Y'
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
|
||||
UNION
|
||||
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test,
|
||||
M_MouName
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join f_payment
|
||||
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
AND F_PaymentIsActive = 'Y'
|
||||
join f_payment_orderheader
|
||||
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
||||
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
) x";
|
||||
|
||||
$query_filter = $this->db->query($sql_filter);
|
||||
// $last_qry = $this->db->last_query();
|
||||
// print_r($last_qry);
|
||||
// exit;
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query_filter) {
|
||||
$tot_count = $query_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql_data = "
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test,
|
||||
M_MouName
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
AND M_MouIsBill = 'Y'
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
|
||||
UNION
|
||||
|
||||
select
|
||||
OneResultConfirmID,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry,
|
||||
DATE_FORMAT(OneResultConfirmCreated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmCreated,
|
||||
DATE_FORMAT(OneResultConfirmLastUpdated, '%d-%m-%Y %H:%i:%s') AS OneResultConfirmLastUpdated,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test,
|
||||
M_MouName
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
$where_company
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join f_payment
|
||||
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
AND F_PaymentIsActive = 'Y'
|
||||
join f_payment_orderheader
|
||||
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
||||
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
||||
where $where
|
||||
group by T_OrderHeaderID
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
// $sql_param = array($search);
|
||||
$query_data = $this->db->query($sql_data);
|
||||
//echo $this->db->last_query();
|
||||
|
||||
if ($query_data) {
|
||||
$rows = $query_data->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$sql_dt = "";
|
||||
foreach ($rows as $k => $v) {
|
||||
$order_id = $v['T_OrderHeaderID'];
|
||||
$dt_test = [];
|
||||
$sql_dt = "SELECT T_OrderDetailT_TestName as x_test
|
||||
from t_orderdetail
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $order_id
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_TestIsPrice = 'Y'
|
||||
";
|
||||
|
||||
// echo $sql_dt;
|
||||
$xdt_test = $this->db->query($sql_dt);
|
||||
// print_r($xdt_test);
|
||||
if (!$xdt_test) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order detail");
|
||||
exit;
|
||||
} else {
|
||||
$testArr = $xdt_test->result_array();
|
||||
$rows[$k]['test'] = $testArr;
|
||||
$xno = ($k + 1) + $number_offset;
|
||||
$rows[$k]['rownumber'] = $xno;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request_upload select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_all" => $tot_count,
|
||||
"total_filter" => count($rows),
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query(),
|
||||
"sql_data" => ($sql_data),
|
||||
"sql_filter" => ($sql_filter)
|
||||
);
|
||||
// $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, 'sql'=> $this->db->last_query());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses insert log
|
||||
public function proses_insert_one_result_log($OneResultConfirmStatus, $OneResultLogOneResultConfirmID)
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_insert = "INSERT INTO one_result_log(
|
||||
OneResultLogAction,
|
||||
OneResultLogM_UserID,
|
||||
OneResultLogDate,
|
||||
OneResultLogOneResultConfirmID
|
||||
) values (
|
||||
?,
|
||||
?,
|
||||
NOW(),
|
||||
?
|
||||
)";
|
||||
|
||||
$qry = $this->db->query(
|
||||
$sql_insert,
|
||||
[
|
||||
$OneResultConfirmStatus,
|
||||
$userID,
|
||||
$OneResultLogOneResultConfirmID
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "insert one_result_log | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
return $this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses confirm
|
||||
public function process_confirm()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
$OneResultConfirmT_OrderHeaderID = $prm['OneResultConfirmT_OrderHeaderID'];
|
||||
|
||||
$sql_insert = "INSERT INTO one_result_confirm(
|
||||
OneResultConfirmT_OrderHeaderID,
|
||||
OneResultConfirmStatus,
|
||||
OneResultConfirmM_UserID,
|
||||
OneResultConfirmCreated
|
||||
) values (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW()
|
||||
)";
|
||||
|
||||
$qry = $this->db->query(
|
||||
$sql_insert,
|
||||
[
|
||||
$OneResultConfirmT_OrderHeaderID,
|
||||
"C",
|
||||
$userID
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry) {
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "insert one_result_confirm | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$OneResultLogOneResultConfirmID = $this->db->insert_id();
|
||||
|
||||
// Confirmed
|
||||
$OneResultConfirmStatus = "C";
|
||||
$this->proses_insert_one_result_log($OneResultConfirmStatus, $OneResultLogOneResultConfirmID);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
|
||||
// $result = array(
|
||||
// "total" => 1 ,
|
||||
// "records" => $prm
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// proses reupload
|
||||
public function process_reupload()
|
||||
{
|
||||
try {
|
||||
# cek token valid
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$OneResultConfirmID = $prm['OneResultConfirmID'];
|
||||
|
||||
$sql_update = "UPDATE one_result_confirm
|
||||
SET
|
||||
OneResultConfirmStatus = ?,
|
||||
OneResultConfirmRetry = ?,
|
||||
OneResultConfirmLastUpdated = NOW()
|
||||
WHERE OneResultConfirmID = ?";
|
||||
|
||||
$qry = $this->db->query(
|
||||
$sql_update,
|
||||
[
|
||||
"R",
|
||||
"0",
|
||||
$OneResultConfirmID,
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry) {
|
||||
$this->sys_error_db(["status" => "ERR", "message" => "update one_result_confirm | " .
|
||||
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Confirmed
|
||||
$OneResultConfirmStatus = "R";
|
||||
$this->proses_insert_one_result_log($OneResultConfirmStatus, $OneResultConfirmID);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
|
||||
// $result = array(
|
||||
// "total" => 1 ,
|
||||
// "records" => $prm
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// autocomplete M_CompanyID
|
||||
public function search_company()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$qry = "%" . $prm["qry"] . '%';
|
||||
|
||||
$sql = "Select M_CompanyID, M_CompanyName
|
||||
from m_company
|
||||
where M_CompanyName like ?
|
||||
and M_CompanyIsActive = 'Y'
|
||||
ORDER BY M_CompanyName DESC";
|
||||
$query = $this->db->query($sql, array($qry));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$rows = $query->result_array();
|
||||
$rows[] = array("M_CompanyID" => 0, "M_CompanyName" => "Semua");
|
||||
$result = array("data" => $rows);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}
|
||||
public function search_mou()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$qry = "%" . $prm["qry"] . '%';
|
||||
$companyID = $prm["company_id"];
|
||||
|
||||
$sql = "SELECT
|
||||
M_MouID,
|
||||
M_MouName,
|
||||
M_MouM_CompanyID
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouM_CompanyID = ?
|
||||
AND M_MouName LIKE ?
|
||||
AND M_MouIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($companyID, $qry));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$rows = $query->result_array();
|
||||
$rows[] = array("M_MouID" => 0, "M_MouName" => "Semua", "M_MouM_CompanyID" => 0);
|
||||
$result = array("data" => $rows);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
218
application/controllers/confirm-result/Getorder.php
Normal file
218
application/controllers/confirm-result/Getorder.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
class Getorder extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// db wilayah contoh surabaya
|
||||
// $this->db = $this->load->database("regional", true);
|
||||
|
||||
// string database
|
||||
$this->db_str_doctor = 'one_doctor';
|
||||
$this->M_MouM_CompanyID = "1235";
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "GET RESULT";
|
||||
}
|
||||
|
||||
public function getdata()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$limit = 10;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm["limit"]);
|
||||
$limit = $prm['limit'];
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
AND M_MouIsBill = 'Y'
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
WHERE (OneResultConfirmStatus = 'C' OR OneResultConfirmStatus = 'R' OR OneResultConfirmStatus = 'E') AND OneResultConfirmRetry <= 5
|
||||
group by T_OrderHeaderID
|
||||
|
||||
UNION
|
||||
|
||||
select
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test,
|
||||
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
||||
OneResultConfirmRetry
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_mou
|
||||
ON T_OrderHeaderM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'
|
||||
left join one_result_confirm
|
||||
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
||||
AND OneResultConfirmIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join f_payment
|
||||
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
AND F_PaymentIsActive = 'Y'
|
||||
join f_payment_orderheader
|
||||
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
||||
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
||||
WHERE (OneResultConfirmStatus = 'C' OR OneResultConfirmStatus = 'R' OR OneResultConfirmStatus = 'E') AND OneResultConfirmRetry <= 5
|
||||
group by T_OrderHeaderID
|
||||
limit $limit";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$query) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$this->sys_ok($rows);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function update_status()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$id = 0;
|
||||
if (isset($prm['id'])) {
|
||||
$id = trim($prm["id"]);
|
||||
$id = $prm['id'];
|
||||
}
|
||||
$status = "A";
|
||||
if (isset($prm['status'])) {
|
||||
$status = trim($prm["status"]);
|
||||
$status = $prm['status'];
|
||||
}
|
||||
|
||||
// print_r("$status & $id");
|
||||
// exit;
|
||||
|
||||
if ($id == 0) {
|
||||
$this->sys_error("ID mandatory !");
|
||||
exit;
|
||||
}
|
||||
if ($status == "A") {
|
||||
$this->sys_error("status mandatory !");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_retry = "SELECT OneResultConfirmRetry
|
||||
FROM one_result_confirm
|
||||
WHERE OneResultConfirmT_OrderHeaderID = ?";
|
||||
$query_retry = $this->db->query($sql_retry, [$id]);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$query_retry) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$retry = intval($query_retry->result_array()[0]['OneResultConfirmRetry']) + 1;
|
||||
// print_r(
|
||||
// array(
|
||||
// "retrydb" => $query_retry->result_array()[0]['OneResultConfirmRetry'],
|
||||
// "retry + 1" => $query_retry->result_array()[0]['OneResultConfirmRetry'] + 1,
|
||||
// "resp" => $query_retry->result_array(),
|
||||
// "last_qry" => $this->db->last_query(),
|
||||
// "retry_var" => $retry
|
||||
// )
|
||||
|
||||
// );
|
||||
// exit;
|
||||
|
||||
if (count($query_retry->result_array()) > 0) {
|
||||
if ($status == "E") {
|
||||
|
||||
$sql = "UPDATE one_result_confirm SET
|
||||
OneResultConfirmStatus = 'E'
|
||||
,OneResultConfirmRetry = ?
|
||||
,OneResultConfirmLastUpdated = ?
|
||||
WHERE OneResultConfirmT_OrderHeaderID = ?";
|
||||
$query = $this->db->query($sql, [$retry, date("Y-m-d H:i:s"), $id]);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$query) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
} else if ($status == "S") {
|
||||
$sql = "UPDATE one_result_confirm SET
|
||||
OneResultConfirmStatus = 'S'
|
||||
WHERE OneResultConfirmT_OrderHeaderID = ?";
|
||||
$query = $this->db->query($sql, [$id]);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$query) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error = array(
|
||||
"message" => "ID not found",
|
||||
);
|
||||
$this->sys_error($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok("OK");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
application/controllers/confirm-result/Or_dummy.php
Normal file
33
application/controllers/confirm-result/Or_dummy.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
class Or_dummy extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function svc()
|
||||
{
|
||||
$data = $this->get_param();
|
||||
$param = [
|
||||
"IncomingJSONData" => json_encode($data),
|
||||
"IncomingM_BranchID" => $data["branch_id"],
|
||||
"IncomingT_OrderHeaderID" => $data["T_OrderHeaderID"],
|
||||
];
|
||||
$qry = $this->db->insert("or_dummy.incoming", $param);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Err incoming " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
echo json_encode(["status" => "OK", "message" => ""]);
|
||||
}
|
||||
function get_param()
|
||||
{
|
||||
$zdata = file_get_contents("php://input");
|
||||
$data = gzuncompress($zdata);
|
||||
|
||||
return json_decode($data, true);
|
||||
}
|
||||
}
|
||||
1802
application/controllers/confirm-result/Uploaderconfirmresult.php
Normal file
1802
application/controllers/confirm-result/Uploaderconfirmresult.php
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
948
application/controllers/corp/Request.php
Normal file
948
application/controllers/corp/Request.php
Normal file
@@ -0,0 +1,948 @@
|
||||
<?php
|
||||
|
||||
class Request extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "BRANCH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
function lookuppgbankbyname(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$pgbank = $prm['branch'];
|
||||
$all = $prm['all'];
|
||||
$startdate = $prm["startdate"];
|
||||
$enddate = $prm["enddate"];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
from one_rekap.request
|
||||
JOIN m_company ON M_CompanyID = requestM_CompanyID
|
||||
WHERE
|
||||
(M_CompanyNumber LIKE CONCAT('%','{$pgbank}','%') OR
|
||||
M_CompanyName LIKE CONCAT('%','{$pgbank}','%'))
|
||||
-- AND ( requestStartDate = '{$startdate}' AND requestEndDate = '{$enddate}')
|
||||
";
|
||||
// $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("corp_upload count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select requestID as id,
|
||||
TypeID,
|
||||
TypeCode,
|
||||
TypeName,
|
||||
M_CompanyID,
|
||||
M_CompanyName,
|
||||
DATE_FORMAT(requestCreated,'%d-%m-%Y %h:%i:%s') as waktuupload,
|
||||
CONCAT(DATE_FORMAT(requestStartDate,'%d-%m-%Y'),' sampai ', DATE_FORMAT(requestEndDate,'%d-%m-%Y')) as periode,
|
||||
CASE
|
||||
WHEN requestStatus = 'N' THEN 'Baru'
|
||||
WHEN requestStatus = 'P' THEN 'Proses'
|
||||
WHEN requestStatus = 'Y' THEN 'Selesai'
|
||||
WHEN requestStatus = 'F' THEN 'Gagal'
|
||||
END as status,
|
||||
request.*
|
||||
from one_rekap.request
|
||||
JOIN m_company ON M_CompanyID = requestM_CompanyID
|
||||
JOIN one_rekap.type ON TypeCode = requestType
|
||||
WHERE
|
||||
(M_CompanyNumber LIKE CONCAT('%','{$pgbank}','%') OR
|
||||
M_CompanyName LIKE CONCAT('%','{$pgbank}','%'))
|
||||
-- AND ( requestStartDate = '{$startdate}' AND requestEndDate = '{$enddate}')
|
||||
GROUP BY requestID
|
||||
ORDER BY requestID 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();
|
||||
if($rows){
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->sys_error_db("corp_upload select");
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows,"reports" => '');
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function add_regtime(){
|
||||
$query =" SELECT corp_report.*,'N' as isregtime, 0 as xid
|
||||
FROM corp_report
|
||||
WHERE Corp_ReportIsActive = 'Y'
|
||||
ORDER BY Corp_ReportCode ASC";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
if(!$rows)
|
||||
$rows = array();
|
||||
return $rows;
|
||||
}
|
||||
public function lookupregionalbyname()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regional = $prm['regional'];
|
||||
$pgbank = $prm['pgbank'];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
FROM(SELECT *
|
||||
from s_regional
|
||||
LEFT JOIN corp_upload ON S_RegionalID = Corp_UploadS_RegionalID AND Corp_UploadIsActive = 'Y'
|
||||
where
|
||||
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
|
||||
IFNULL(Corp_UploadName,'') LIKE CONCAT('%','{$pgbank}','%') AND
|
||||
S_RegionalIsActive = 'Y'
|
||||
GROUP BY S_RegionalID) a";
|
||||
$sql_param = array($search);
|
||||
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
$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("s_regional count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select S_RegionalID as id,
|
||||
S_RegionalName as name,
|
||||
S_RegionalName as namex,
|
||||
s_regional.*
|
||||
from s_regional
|
||||
LEFT JOIN corp_upload ON S_RegionalID = Corp_UploadS_RegionalID AND Corp_UploadIsActive = 'Y'
|
||||
where
|
||||
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
|
||||
IFNULL(Corp_UploadName,'') LIKE CONCAT('%','{$pgbank}','%') AND
|
||||
S_RegionalIsActive = 'Y'
|
||||
GROUP BY S_RegionalID
|
||||
ORDER BY S_RegionalName ASC
|
||||
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("s_regional 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 addnewregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$name = $prm['name'];
|
||||
$sql = "insert into s_regional(
|
||||
S_RegionalName,
|
||||
S_RegionalCreated,
|
||||
S_RegionalLastUpdated
|
||||
)
|
||||
values( ?, now(), now())";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$name
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("s_regional 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);
|
||||
}
|
||||
}
|
||||
|
||||
public function editregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$name = $prm['name'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sqlcompany = "update s_regional SET
|
||||
S_RegionalName = ?,
|
||||
S_RegionalLastUpdated = now()
|
||||
where
|
||||
S_RegionalID = ?
|
||||
";
|
||||
$querycompany = $this->db_onedev->query($sqlcompany,
|
||||
array(
|
||||
$name,
|
||||
$id
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$querycompany) {
|
||||
$this->sys_error_db("s_regional update");
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => $id));
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function addnewpgbank()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$type = $prm['type'];
|
||||
$startdate = $prm['startdateform'];
|
||||
$enddate = $prm['enddateform'];
|
||||
$companyid = $prm['companyid'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
|
||||
if($prm['xid'] == 0){
|
||||
$sql = "insert into one_rekap.request(
|
||||
requestType,
|
||||
requestM_CompanyID,
|
||||
requestStartDate,
|
||||
requestEndDate,
|
||||
requestCreated,
|
||||
requestLasUpdated,
|
||||
requestUserID)
|
||||
values(?,?,?,?,now(),now(),?)";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$type,
|
||||
$companyid,
|
||||
$startdate,
|
||||
$enddate,
|
||||
$userid)
|
||||
);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload insert",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "update s_regional SET
|
||||
S_RegionalIsActive = 'N',
|
||||
S_RegionalLastUpdated = now()
|
||||
WHERE
|
||||
S_RegionalID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("s_regional delete");
|
||||
exit;
|
||||
}
|
||||
$sql = "update corp_upload SET
|
||||
Corp_UploadIsActive = 'N',
|
||||
Corp_UploadLastUpdated = now()
|
||||
WHERE
|
||||
Corp_UploadS_RegionalID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function deletepgbank()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "update corp_upload SET
|
||||
Corp_UploadIsActive = 'N',
|
||||
Corp_UploadLastUpdated = now()
|
||||
WHERE
|
||||
Corp_UploadID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchakun(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['tes'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['tes']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouNumber like ?
|
||||
AND M_MouIsActive = 'Y'";
|
||||
$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_mou count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT M_MouID,CONCAT(M_MouName, ' [',M_MouNumber,'] ') as M_MouNumber
|
||||
FROM m_mou
|
||||
|
||||
JOIN m_company ON M_CompanyID = M_MouM_CompanyID
|
||||
WHERE
|
||||
CONCAT(M_MouName, ' [',M_MouNumber,'] ') like ?
|
||||
AND M_MouIsActive = 'Y'
|
||||
ORDER BY M_MouName ASC
|
||||
";
|
||||
$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_mou rows",$this->db_onedev);
|
||||
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 searchregionalbyname(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM s_regional
|
||||
WHERE
|
||||
S_RegionalName like ?
|
||||
AND S_RegionalIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("s_regional count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE
|
||||
S_RegionalName like ?
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
ORDER BY S_RegionalName ASC
|
||||
";
|
||||
$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("s_regional rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function searchpaymenttype(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_paymenttype
|
||||
WHERE
|
||||
M_PaymentTypeName like ?
|
||||
AND M_PaymentTypeIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("t_subcategory count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT M_PaymentTypeID, M_PaymentTypeName
|
||||
FROM m_paymenttype
|
||||
WHERE
|
||||
M_PaymentTypeName like ?
|
||||
AND M_PaymentTypeIsActive = 'Y'
|
||||
ORDER BY M_PaymentTypeName ASC
|
||||
";
|
||||
$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("t_subcategory rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function searchdistrict(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_district
|
||||
WHERE
|
||||
M_DistrictName like ?
|
||||
AND M_DistrictT_SubCategoryID = '{$id}'
|
||||
AND M_DistrictIsActive = 'Y'";
|
||||
$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_district count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_district
|
||||
WHERE
|
||||
M_DistrictName like ?
|
||||
AND M_DistrictT_SubCategoryID = '{$id}'
|
||||
AND M_DistrictIsActive = 'Y'
|
||||
ORDER BY M_DistrictName ASC
|
||||
";
|
||||
$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_district rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchkelurahan(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_kelurahan
|
||||
WHERE
|
||||
M_KelurahanName like ?
|
||||
AND M_KelurahanM_DistrictID = '{$id}'
|
||||
AND M_KelurahanIsActive = 'Y'";
|
||||
$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_district count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_kelurahan
|
||||
WHERE
|
||||
M_KelurahanName like ?
|
||||
AND M_KelurahanM_DistrictID = '{$id}'
|
||||
AND M_KelurahanIsActive = 'Y'
|
||||
ORDER BY M_KelurahanName ASC
|
||||
";
|
||||
$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_district rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchcompany(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['tes'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['tes']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_company
|
||||
WHERE
|
||||
M_CompanyName like ?
|
||||
AND M_CompanyIsActive = 'Y'";
|
||||
$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_company count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_company
|
||||
WHERE
|
||||
M_CompanyName like ?
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
ORDER BY M_CompanyName ASC
|
||||
";
|
||||
$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_company rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchmou(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM one_rekap.type
|
||||
WHERE
|
||||
TypeName like ?
|
||||
AND TypeIsActive = 'Y'";
|
||||
$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_mou count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM one_rekap.type
|
||||
WHERE
|
||||
TypeName like ?
|
||||
AND TypeIsActive = 'Y'
|
||||
ORDER BY TypeName ASC
|
||||
";
|
||||
$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_mou rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchdoctor(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
|
||||
FROM m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y') a
|
||||
WHERE
|
||||
M_DoctorName like ?";
|
||||
$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_doctor count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
|
||||
FROM m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y') a
|
||||
WHERE
|
||||
M_DoctorName like ?
|
||||
GROUP BY M_DoctorID
|
||||
ORDER BY M_DoctorName ASC";
|
||||
$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_doctor rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function selectaddressdoctor(){
|
||||
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$rows = [];
|
||||
$query ="SELECT M_DoctorAddressID,
|
||||
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
|
||||
FROM
|
||||
m_doctoraddress
|
||||
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
|
||||
//echo $query;
|
||||
$rows['addressdoctors'] = $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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
935
application/controllers/corp/Upload.php
Normal file
935
application/controllers/corp/Upload.php
Normal file
@@ -0,0 +1,935 @@
|
||||
<?php
|
||||
|
||||
class Upload extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "BRANCH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
function lookuppgbankbyname(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$pgbank = $prm['branch'];
|
||||
$all = $prm['all'];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
from corp_upload
|
||||
JOIN m_mou ON M_MouID = Corp_UploadM_MouID
|
||||
WHERE
|
||||
(M_MouNumber LIKE CONCAT('%','{$pgbank}','%') OR
|
||||
M_MouName LIKE CONCAT('%','{$pgbank}','%')) AND
|
||||
Corp_UploadIsActive = 'Y'";
|
||||
// $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("corp_upload count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select Corp_UploadID as id,
|
||||
M_MouID,
|
||||
CONCAT(M_MouName,' [',M_MouNumber,'] ') M_MouNumber,
|
||||
M_MouName,
|
||||
M_CompanyID,
|
||||
M_CompanyName,
|
||||
DATE_FORMAT(Corp_UploadSentDate,'%d-%m-%Y %h:%i:%s') as waktuupload,
|
||||
CASE
|
||||
WHEN Corp_UploadStatus = 'N' THEN 'Baru'
|
||||
WHEN Corp_UploadStatus = 'P' THEN 'Proses'
|
||||
WHEN Corp_UploadStatus = 'D' THEN 'Selesai'
|
||||
WHEN Corp_UploadStatus = 'F' THEN 'Gagal'
|
||||
END as status,
|
||||
corp_upload.*
|
||||
from corp_upload
|
||||
JOIN m_mou ON M_MouID = Corp_UploadM_MouID
|
||||
JOIN m_company ON M_CompanyID = M_MouM_CompanyID
|
||||
WHERE
|
||||
(M_MouNumber LIKE CONCAT('%','{$pgbank}','%') OR
|
||||
M_MouName LIKE CONCAT('%','{$pgbank}','%')) AND
|
||||
Corp_UploadIsActive = 'Y'
|
||||
GROUP BY Corp_UploadID
|
||||
ORDER BY M_MouName ASC
|
||||
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("corp_upload 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 lookupregionalbyname()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regional = $prm['regional'];
|
||||
$pgbank = $prm['pgbank'];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
FROM(SELECT *
|
||||
from s_regional
|
||||
LEFT JOIN corp_upload ON S_RegionalID = Corp_UploadS_RegionalID AND Corp_UploadIsActive = 'Y'
|
||||
where
|
||||
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
|
||||
IFNULL(Corp_UploadName,'') LIKE CONCAT('%','{$pgbank}','%') AND
|
||||
S_RegionalIsActive = 'Y'
|
||||
GROUP BY S_RegionalID) a";
|
||||
$sql_param = array($search);
|
||||
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
$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("s_regional count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select S_RegionalID as id,
|
||||
S_RegionalName as name,
|
||||
S_RegionalName as namex,
|
||||
s_regional.*
|
||||
from s_regional
|
||||
LEFT JOIN corp_upload ON S_RegionalID = Corp_UploadS_RegionalID AND Corp_UploadIsActive = 'Y'
|
||||
where
|
||||
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
|
||||
IFNULL(Corp_UploadName,'') LIKE CONCAT('%','{$pgbank}','%') AND
|
||||
S_RegionalIsActive = 'Y'
|
||||
GROUP BY S_RegionalID
|
||||
ORDER BY S_RegionalName ASC
|
||||
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("s_regional 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 addnewregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$name = $prm['name'];
|
||||
$sql = "insert into s_regional(
|
||||
S_RegionalName,
|
||||
S_RegionalCreated,
|
||||
S_RegionalLastUpdated
|
||||
)
|
||||
values( ?, now(), now())";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$name
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("s_regional 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);
|
||||
}
|
||||
}
|
||||
|
||||
public function editregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$name = $prm['name'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sqlcompany = "update s_regional SET
|
||||
S_RegionalName = ?,
|
||||
S_RegionalLastUpdated = now()
|
||||
where
|
||||
S_RegionalID = ?
|
||||
";
|
||||
$querycompany = $this->db_onedev->query($sqlcompany,
|
||||
array(
|
||||
$name,
|
||||
$id
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$querycompany) {
|
||||
$this->sys_error_db("s_regional update");
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => $id));
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function addnewpgbank()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$Corp_UploadM_MouID = $prm['mouid'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
|
||||
if($prm['xid'] == 0){
|
||||
$sql = "insert into corp_upload(
|
||||
Corp_UploadM_MouID,
|
||||
Corp_UploadCreated,
|
||||
Corp_UploadLastUpdated,
|
||||
Corp_UploadUserID)
|
||||
values(?,now(),now(),?)";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$Corp_UploadM_MouID,
|
||||
$userid)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload insert",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
}else{
|
||||
$sql = "UPDATE corp_upload SET Corp_UploadStatus = 'N',
|
||||
Corp_UploadRetry = Corp_UploadRetry + 1,
|
||||
Corp_UploadUserID = '{$userid}',
|
||||
Corp_UploadLastUpdated = now()
|
||||
WHERE Corp_UploadID = '{$prm['xid']}'";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "update s_regional SET
|
||||
S_RegionalIsActive = 'N',
|
||||
S_RegionalLastUpdated = now()
|
||||
WHERE
|
||||
S_RegionalID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("s_regional delete");
|
||||
exit;
|
||||
}
|
||||
$sql = "update corp_upload SET
|
||||
Corp_UploadIsActive = 'N',
|
||||
Corp_UploadLastUpdated = now()
|
||||
WHERE
|
||||
Corp_UploadS_RegionalID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function deletepgbank()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "update corp_upload SET
|
||||
Corp_UploadIsActive = 'N',
|
||||
Corp_UploadLastUpdated = now()
|
||||
WHERE
|
||||
Corp_UploadID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchakun(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['tes'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['tes']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouNumber like ?
|
||||
AND M_MouIsActive = 'Y'";
|
||||
$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_mou count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT M_MouID,CONCAT(M_MouName, ' [',M_MouNumber,'] ') as M_MouNumber
|
||||
FROM m_mou
|
||||
|
||||
JOIN m_company ON M_CompanyID = M_MouM_CompanyID
|
||||
WHERE
|
||||
CONCAT(M_MouName, ' [',M_MouNumber,'] ') like ?
|
||||
AND M_MouIsActive = 'Y'
|
||||
ORDER BY M_MouName ASC
|
||||
";
|
||||
$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_mou rows",$this->db_onedev);
|
||||
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 searchregionalbyname(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM s_regional
|
||||
WHERE
|
||||
S_RegionalName like ?
|
||||
AND S_RegionalIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("s_regional count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE
|
||||
S_RegionalName like ?
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
ORDER BY S_RegionalName ASC
|
||||
";
|
||||
$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("s_regional rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function searchpaymenttype(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_paymenttype
|
||||
WHERE
|
||||
M_PaymentTypeName like ?
|
||||
AND M_PaymentTypeIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("t_subcategory count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT M_PaymentTypeID, M_PaymentTypeName
|
||||
FROM m_paymenttype
|
||||
WHERE
|
||||
M_PaymentTypeName like ?
|
||||
AND M_PaymentTypeIsActive = 'Y'
|
||||
ORDER BY M_PaymentTypeName ASC
|
||||
";
|
||||
$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("t_subcategory rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function searchdistrict(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_district
|
||||
WHERE
|
||||
M_DistrictName like ?
|
||||
AND M_DistrictT_SubCategoryID = '{$id}'
|
||||
AND M_DistrictIsActive = 'Y'";
|
||||
$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_district count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_district
|
||||
WHERE
|
||||
M_DistrictName like ?
|
||||
AND M_DistrictT_SubCategoryID = '{$id}'
|
||||
AND M_DistrictIsActive = 'Y'
|
||||
ORDER BY M_DistrictName ASC
|
||||
";
|
||||
$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_district rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchkelurahan(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_kelurahan
|
||||
WHERE
|
||||
M_KelurahanName like ?
|
||||
AND M_KelurahanM_DistrictID = '{$id}'
|
||||
AND M_KelurahanIsActive = 'Y'";
|
||||
$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_district count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_kelurahan
|
||||
WHERE
|
||||
M_KelurahanName like ?
|
||||
AND M_KelurahanM_DistrictID = '{$id}'
|
||||
AND M_KelurahanIsActive = 'Y'
|
||||
ORDER BY M_KelurahanName ASC
|
||||
";
|
||||
$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_district rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchcompany(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['tes'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['tes']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_company
|
||||
WHERE
|
||||
M_CompanyName like ?
|
||||
AND M_CompanyIsActive = 'Y'";
|
||||
$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_company count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_company
|
||||
WHERE
|
||||
M_CompanyName like ?
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
ORDER BY M_CompanyName ASC
|
||||
";
|
||||
$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_company rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchmou(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouName like ?
|
||||
AND M_MouM_CompanyID = '{$id}'
|
||||
AND M_MouIsActive = 'Y'";
|
||||
$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_mou count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouName like ?
|
||||
AND M_MouM_CompanyID = '{$id}'
|
||||
AND M_MouIsActive = 'Y'
|
||||
ORDER BY M_MouName ASC
|
||||
";
|
||||
$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_mou rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchdoctor(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
|
||||
FROM m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y') a
|
||||
WHERE
|
||||
M_DoctorName like ?";
|
||||
$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_doctor count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
|
||||
FROM m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y') a
|
||||
WHERE
|
||||
M_DoctorName like ?
|
||||
GROUP BY M_DoctorID
|
||||
ORDER BY M_DoctorName ASC";
|
||||
$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_doctor rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function selectaddressdoctor(){
|
||||
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$rows = [];
|
||||
$query ="SELECT M_DoctorAddressID,
|
||||
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
|
||||
FROM
|
||||
m_doctoraddress
|
||||
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
|
||||
//echo $query;
|
||||
$rows['addressdoctors'] = $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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
974
application/controllers/corp/Upload_v2.php
Normal file
974
application/controllers/corp/Upload_v2.php
Normal file
@@ -0,0 +1,974 @@
|
||||
<?php
|
||||
|
||||
class Upload_v2 extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "BRANCH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
function lookuppgbankbyname(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$pgbank = $prm['branch'];
|
||||
$all = $prm['all'];
|
||||
$startdate = $prm["startdate"];
|
||||
$enddate = $prm["enddate"];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
from corp_upload
|
||||
JOIN m_mou ON M_MouID = Corp_UploadM_MouID
|
||||
WHERE
|
||||
(M_MouNumber LIKE CONCAT('%','{$pgbank}','%') OR
|
||||
M_MouName LIKE CONCAT('%','{$pgbank}','%')) AND
|
||||
Corp_UploadIsActive = 'Y' AND
|
||||
( Corp_UploadCreated BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )";
|
||||
// $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("corp_upload count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select Corp_UploadID as id,
|
||||
M_MouID,
|
||||
CONCAT(M_MouName,' [',M_MouNumber,'] ', '<br>', 'Cetak Hasil : ',GROUP_CONCAT(CONCAT(Corp_ReportCode,'-',Corp_ReportName) SEPARATOR ', ')) as M_MouNumber,
|
||||
M_MouName,
|
||||
M_CompanyID,
|
||||
M_CompanyName,
|
||||
DATE_FORMAT(Corp_UploadSentDate,'%d-%m-%Y %h:%i:%s') as waktuupload,
|
||||
CASE
|
||||
WHEN Corp_UploadStatus = 'N' THEN 'Baru'
|
||||
WHEN Corp_UploadStatus = 'P' THEN 'Proses'
|
||||
WHEN Corp_UploadStatus = 'D' THEN 'Selesai'
|
||||
WHEN Corp_UploadStatus = 'F' THEN 'Gagal'
|
||||
END as status,
|
||||
'xxx' as regtimes,
|
||||
corp_upload.*
|
||||
from corp_upload
|
||||
JOIN m_mou ON M_MouID = Corp_UploadM_MouID
|
||||
JOIN m_company ON M_CompanyID = M_MouM_CompanyID
|
||||
JOIN corp_uploaderdetail ON Corp_UploaderDetailCorp_UploadID = Corp_UploadID AND Corp_UploaderDetailIsActive = 'Y'
|
||||
JOIN corp_report ON Corp_ReportID = Corp_UploaderDetailCorp_ReportID
|
||||
WHERE
|
||||
(M_MouNumber LIKE CONCAT('%','{$pgbank}','%') OR
|
||||
M_MouName LIKE CONCAT('%','{$pgbank}','%')) AND
|
||||
Corp_UploadIsActive = 'Y' AND
|
||||
( Corp_UploadCreated BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
|
||||
GROUP BY Corp_UploadID
|
||||
ORDER BY Corp_UploadID 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();
|
||||
if($rows){
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->sys_error_db("corp_upload select");
|
||||
exit;
|
||||
}
|
||||
$sqlreport = "SELECT corp_report.*,'Y' as isregtime, 0 as xid
|
||||
FROM corp_report
|
||||
WHERE Corp_ReportIsActive = 'Y'
|
||||
ORDER BY Corp_ReportCode ASC";
|
||||
$queryreport = $this->db_onedev->query($sqlreport)->result_array();
|
||||
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows,"reports" => $queryreport);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function add_regtime(){
|
||||
$query =" SELECT corp_report.*,'N' as isregtime, 0 as xid
|
||||
FROM corp_report
|
||||
WHERE Corp_ReportIsActive = 'Y'
|
||||
ORDER BY Corp_ReportCode ASC";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
if(!$rows)
|
||||
$rows = array();
|
||||
return $rows;
|
||||
}
|
||||
public function lookupregionalbyname()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regional = $prm['regional'];
|
||||
$pgbank = $prm['pgbank'];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
FROM(SELECT *
|
||||
from s_regional
|
||||
LEFT JOIN corp_upload ON S_RegionalID = Corp_UploadS_RegionalID AND Corp_UploadIsActive = 'Y'
|
||||
where
|
||||
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
|
||||
IFNULL(Corp_UploadName,'') LIKE CONCAT('%','{$pgbank}','%') AND
|
||||
S_RegionalIsActive = 'Y'
|
||||
GROUP BY S_RegionalID) a";
|
||||
$sql_param = array($search);
|
||||
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
$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("s_regional count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select S_RegionalID as id,
|
||||
S_RegionalName as name,
|
||||
S_RegionalName as namex,
|
||||
s_regional.*
|
||||
from s_regional
|
||||
LEFT JOIN corp_upload ON S_RegionalID = Corp_UploadS_RegionalID AND Corp_UploadIsActive = 'Y'
|
||||
where
|
||||
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
|
||||
IFNULL(Corp_UploadName,'') LIKE CONCAT('%','{$pgbank}','%') AND
|
||||
S_RegionalIsActive = 'Y'
|
||||
GROUP BY S_RegionalID
|
||||
ORDER BY S_RegionalName ASC
|
||||
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("s_regional 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 addnewregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$name = $prm['name'];
|
||||
$sql = "insert into s_regional(
|
||||
S_RegionalName,
|
||||
S_RegionalCreated,
|
||||
S_RegionalLastUpdated
|
||||
)
|
||||
values( ?, now(), now())";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$name
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("s_regional 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);
|
||||
}
|
||||
}
|
||||
|
||||
public function editregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$name = $prm['name'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sqlcompany = "update s_regional SET
|
||||
S_RegionalName = ?,
|
||||
S_RegionalLastUpdated = now()
|
||||
where
|
||||
S_RegionalID = ?
|
||||
";
|
||||
$querycompany = $this->db_onedev->query($sqlcompany,
|
||||
array(
|
||||
$name,
|
||||
$id
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$querycompany) {
|
||||
$this->sys_error_db("s_regional update");
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => $id));
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function addnewpgbank()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$Corp_UploadM_MouID = $prm['mouid'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
|
||||
if($prm['xid'] == 0){
|
||||
$sql = "insert into corp_upload(
|
||||
Corp_UploadM_MouID,
|
||||
Corp_UploadCreated,
|
||||
Corp_UploadLastUpdated,
|
||||
Corp_UploadUserID)
|
||||
values(?,now(),now(),?)";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$Corp_UploadM_MouID,
|
||||
$userid)
|
||||
);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
foreach($prm['reports'] as $k=>$v){
|
||||
if($v['isregtime'] === 'Y'){
|
||||
$xreportid = $v['Corp_ReportID'];
|
||||
$query = "INSERT INTO corp_uploaderdetail(
|
||||
Corp_UploaderDetailCorp_UploadID,
|
||||
Corp_UploaderDetailCorp_ReportID,
|
||||
Corp_UploaderDetailUserID,
|
||||
Corp_UploaderDetailCreated,
|
||||
Corp_UploaderDetailLastUpdated
|
||||
)
|
||||
VALUES(?,?,?,now(),now())";
|
||||
$insert_detail = $this->db_onedev->query($query,array($last_id,$xreportid,$userid));
|
||||
}
|
||||
}
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload insert",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
}else{
|
||||
$sql = "UPDATE corp_upload SET Corp_UploadStatus = 'N',
|
||||
Corp_UploadRetry = Corp_UploadRetry + 1,
|
||||
Corp_UploadUserID = '{$userid}',
|
||||
Corp_UploadLastUpdated = now()
|
||||
WHERE Corp_UploadID = '{$prm['xid']}'";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteregional()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "update s_regional SET
|
||||
S_RegionalIsActive = 'N',
|
||||
S_RegionalLastUpdated = now()
|
||||
WHERE
|
||||
S_RegionalID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("s_regional delete");
|
||||
exit;
|
||||
}
|
||||
$sql = "update corp_upload SET
|
||||
Corp_UploadIsActive = 'N',
|
||||
Corp_UploadLastUpdated = now()
|
||||
WHERE
|
||||
Corp_UploadS_RegionalID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function deletepgbank()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "update corp_upload SET
|
||||
Corp_UploadIsActive = 'N',
|
||||
Corp_UploadLastUpdated = now()
|
||||
WHERE
|
||||
Corp_UploadID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("corp_upload delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchakun(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['tes'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['tes']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouNumber like ?
|
||||
AND M_MouIsActive = 'Y'";
|
||||
$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_mou count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT M_MouID,CONCAT(M_MouName, ' [',M_MouNumber,'] ') as M_MouNumber
|
||||
FROM m_mou
|
||||
|
||||
JOIN m_company ON M_CompanyID = M_MouM_CompanyID
|
||||
WHERE
|
||||
CONCAT(M_MouName, ' [',M_MouNumber,'] ') like ?
|
||||
AND M_MouIsActive = 'Y'
|
||||
ORDER BY M_MouName ASC
|
||||
";
|
||||
$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_mou rows",$this->db_onedev);
|
||||
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 searchregionalbyname(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM s_regional
|
||||
WHERE
|
||||
S_RegionalName like ?
|
||||
AND S_RegionalIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("s_regional count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE
|
||||
S_RegionalName like ?
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
ORDER BY S_RegionalName ASC
|
||||
";
|
||||
$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("s_regional rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function searchpaymenttype(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_paymenttype
|
||||
WHERE
|
||||
M_PaymentTypeName like ?
|
||||
AND M_PaymentTypeIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("t_subcategory count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT M_PaymentTypeID, M_PaymentTypeName
|
||||
FROM m_paymenttype
|
||||
WHERE
|
||||
M_PaymentTypeName like ?
|
||||
AND M_PaymentTypeIsActive = 'Y'
|
||||
ORDER BY M_PaymentTypeName ASC
|
||||
";
|
||||
$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("t_subcategory rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function searchdistrict(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_district
|
||||
WHERE
|
||||
M_DistrictName like ?
|
||||
AND M_DistrictT_SubCategoryID = '{$id}'
|
||||
AND M_DistrictIsActive = 'Y'";
|
||||
$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_district count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_district
|
||||
WHERE
|
||||
M_DistrictName like ?
|
||||
AND M_DistrictT_SubCategoryID = '{$id}'
|
||||
AND M_DistrictIsActive = 'Y'
|
||||
ORDER BY M_DistrictName ASC
|
||||
";
|
||||
$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_district rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchkelurahan(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_kelurahan
|
||||
WHERE
|
||||
M_KelurahanName like ?
|
||||
AND M_KelurahanM_DistrictID = '{$id}'
|
||||
AND M_KelurahanIsActive = 'Y'";
|
||||
$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_district count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_kelurahan
|
||||
WHERE
|
||||
M_KelurahanName like ?
|
||||
AND M_KelurahanM_DistrictID = '{$id}'
|
||||
AND M_KelurahanIsActive = 'Y'
|
||||
ORDER BY M_KelurahanName ASC
|
||||
";
|
||||
$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_district rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchcompany(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['tes'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['tes']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_company
|
||||
WHERE
|
||||
M_CompanyName like ?
|
||||
AND M_CompanyIsActive = 'Y'";
|
||||
$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_company count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *, CONCAT(M_CompanyName,' [',M_CompanyNumber,']') as M_CompanyName
|
||||
FROM m_company
|
||||
WHERE
|
||||
M_CompanyName like ?
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
ORDER BY M_CompanyName ASC
|
||||
";
|
||||
$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_company rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchmou(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouName like ?
|
||||
AND M_MouM_CompanyID = '{$id}'
|
||||
AND M_MouIsActive = 'Y'";
|
||||
$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_mou count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT *, CONCAT(M_MouName,' [',M_MouNumber,']') as M_MouName
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouName like ?
|
||||
AND M_MouM_CompanyID = '{$id}'
|
||||
AND M_MouIsActive = 'Y'
|
||||
ORDER BY M_MouName ASC
|
||||
";
|
||||
$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_mou rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function searchdoctor(){
|
||||
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
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
|
||||
FROM m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y') a
|
||||
WHERE
|
||||
M_DoctorName like ?";
|
||||
$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_doctor count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
|
||||
FROM m_doctor
|
||||
WHERE M_DoctorIsActive = 'Y') a
|
||||
WHERE
|
||||
M_DoctorName like ?
|
||||
GROUP BY M_DoctorID
|
||||
ORDER BY M_DoctorName ASC";
|
||||
$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_doctor rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function selectaddressdoctor(){
|
||||
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$rows = [];
|
||||
$query ="SELECT M_DoctorAddressID,
|
||||
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
|
||||
FROM
|
||||
m_doctoraddress
|
||||
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
|
||||
//echo $query;
|
||||
$rows['addressdoctors'] = $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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
913
application/controllers/corporate-price/Companyprice.php
Normal file
913
application/controllers/corporate-price/Companyprice.php
Normal file
@@ -0,0 +1,913 @@
|
||||
<?php
|
||||
class Companyprice extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Corporate Price API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$this->load->library("SsPriceMou");
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
|
||||
$corporate_code = $input['corporate_code'] ?? $this->input->get('corporate_code');
|
||||
$corporate_name = $input['corporate_name'] ?? $this->input->get('corporate_name');
|
||||
$search = $input['search'] ?? $this->input->get('search');
|
||||
|
||||
$page_val = $input['page'] ?? $this->input->get('page');
|
||||
$page = $page_val ? intval($page_val) : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$where_clauses = [];
|
||||
$params = [];
|
||||
|
||||
$where_clauses[] = "c.CorporateIsActive = 'Y'";
|
||||
|
||||
if (!empty($corporate_code)) {
|
||||
$where_clauses[] = "c.CorporateCode LIKE ?";
|
||||
$params[] = "%" . $corporate_code . "%";
|
||||
}
|
||||
|
||||
if (!empty($corporate_name)) {
|
||||
$where_clauses[] = "c.CorporateName LIKE ?";
|
||||
$params[] = "%" . $corporate_name . "%";
|
||||
}
|
||||
|
||||
if (!empty($search)) {
|
||||
$where_clauses[] = "(c.CorporateCode LIKE ? OR c.CorporateName LIKE ?)";
|
||||
$params[] = "%" . $search . "%";
|
||||
$params[] = "%" . $search . "%";
|
||||
}
|
||||
|
||||
$where_sql = "";
|
||||
if (count($where_clauses) > 0) {
|
||||
$where_sql = " WHERE " . implode(" AND ", $where_clauses);
|
||||
}
|
||||
|
||||
$base_join_sql = "
|
||||
FROM corporate c
|
||||
INNER JOIN corporate_price cp
|
||||
ON c.CorporateID = cp.CorporatePriceCorporateID
|
||||
AND cp.CorporatePriceIsActive = 'Y'
|
||||
";
|
||||
|
||||
$count_sql = "SELECT COUNT(DISTINCT c.CorporateID) AS total " . $base_join_sql . $where_sql;
|
||||
|
||||
$qry_count = $this->db_onedev->query($count_sql, $params);
|
||||
$total = $qry_count->row()->total ?? 0;
|
||||
|
||||
$main_sql = "SELECT
|
||||
c.CorporateID,
|
||||
c.CorporateCode,
|
||||
c.CorporateName,
|
||||
c.CorporateAddress,
|
||||
c.CorporatePICName,
|
||||
c.CorporatePhone,
|
||||
c.CorporateEmail,
|
||||
c.CorporateIsActive,
|
||||
c.CorporateCreated,
|
||||
cp.CorporatePriceID,
|
||||
cp.CorporatePriceT_PriceHeaderID,
|
||||
cp.CorporatePriceIsDefault,
|
||||
cp.CorporatePriceStartDate,
|
||||
cp.CorporatePriceEndDate,
|
||||
cp.CorporatePriceNote
|
||||
" . $base_join_sql . $where_sql . "
|
||||
GROUP BY c.CorporateID
|
||||
ORDER BY
|
||||
c.CorporateName ASC,
|
||||
cp.CorporatePriceID DESC
|
||||
LIMIT ? OFFSET ?
|
||||
";
|
||||
|
||||
|
||||
$main_params = array_merge($params, [$limit, $offset]);
|
||||
$qry = $this->db_onedev->query($main_sql, $main_params);
|
||||
if (!$qry) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data corporate.']);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data corporate.',
|
||||
'data' => $data,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'total_page' => ceil($total / $limit)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getlistcorporate(){
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$search = $input['search'] ?? $this->input->get('search');
|
||||
|
||||
if (empty($search)) {
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Ketik code atau nama corporate',
|
||||
'data' => [],
|
||||
'total' => 0
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
CorporateID,
|
||||
CorporateCode,
|
||||
CorporateName
|
||||
FROM corporate
|
||||
WHERE CorporateIsActive = 'Y'
|
||||
AND (CorporateCode LIKE ? OR CorporateName LIKE ?)";
|
||||
|
||||
$params = ["%" . $search . "%", "%" . $search . "%"];
|
||||
|
||||
$sql .= " ORDER BY CorporateName ASC";
|
||||
|
||||
$qry = $this->db_onedev->query($sql, $params);
|
||||
if (!$qry) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data corporate.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $qry->result_array();
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data corporate.',
|
||||
'data' => $result,
|
||||
'total' => count($result)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getcorporateprice()
|
||||
{
|
||||
$sql = "SELECT
|
||||
cp.*,
|
||||
c.CorporateName
|
||||
FROM corporate_price cp
|
||||
LEFT JOIN corporate c
|
||||
ON c.CorporateID = cp.CorporatePriceCorporateID
|
||||
ORDER BY cp.CorporatePriceID DESC";
|
||||
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data price header.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $qry->result_array();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data price header.',
|
||||
'data' => $result,
|
||||
'total' => count($result)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getcorporateprice2($corporateID)
|
||||
{
|
||||
$sql = "SELECT
|
||||
cp.*,
|
||||
c.CorporateName
|
||||
FROM corporate_price cp
|
||||
INNER JOIN corporate c
|
||||
ON c.CorporateID = cp.CorporatePriceCorporateID
|
||||
WHERE c.CorporateID = ?
|
||||
ORDER BY cp.CorporatePriceID DESC";
|
||||
|
||||
$qry = $this->db_onedev->query($sql, [$corporateID]);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal mengambil data price header.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $qry->result_array();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data price header.',
|
||||
'data' => $result,
|
||||
'total' => count($result)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getlistpriceheader(){
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$search = $input['search'] ?? $this->input->get('search');
|
||||
|
||||
if (empty($search)) {
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Ketik code atau nama price header',
|
||||
'data' => [],
|
||||
'total' => 0
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
T_PriceHeaderID,
|
||||
T_PriceHeaderCode,
|
||||
T_PriceHeaderName
|
||||
FROM t_priceheader
|
||||
WHERE T_PriceHeaderIsActive = 'Y'
|
||||
AND (T_PriceHeaderCode LIKE ? OR T_PriceHeaderName LIKE ?)";
|
||||
|
||||
$params = ["%" . $search . "%", "%" . $search . "%"];
|
||||
|
||||
$sql .= " ORDER BY T_PriceHeaderName ASC";
|
||||
$qry = $this->db_onedev->query($sql, $params);
|
||||
if (!$qry) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data corporate.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $qry->result_array();
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data priceheader.',
|
||||
'data' => $result,
|
||||
'total' => count($result)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function gettestbypriceheader()
|
||||
{
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
if (!isset($input['price_header_id'])) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'price_header_id wajib diisi'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$priceHeaderID = $input['price_header_id'];
|
||||
$search = $input['search'] ?? $this->input->get('search');
|
||||
$page_val = $input['page'] ?? $this->input->get('page');
|
||||
$page = $page_val ? intval($page_val) : 1;
|
||||
$limit = 5;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$base_sql = "FROM t_test t
|
||||
INNER JOIN ss_price_mou s
|
||||
ON t.T_TestID = s.T_TestID
|
||||
WHERE s.Ss_PriceMouT_PriceHeaderID = ?";
|
||||
|
||||
$params = [$priceHeaderID];
|
||||
|
||||
if (!empty($search)) {
|
||||
$base_sql .= " AND (t.T_TestCode LIKE ? OR t.T_TestName LIKE ?)";
|
||||
$params[] = "%" . $search . "%";
|
||||
$params[] = "%" . $search . "%";
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(t.T_TestID) AS total " . $base_sql;
|
||||
$qry_count = $this->db_onedev->query($count_sql, $params);
|
||||
$total = $qry_count->row()->total ?? 0;
|
||||
|
||||
$sql = "SELECT
|
||||
t.T_TestID,
|
||||
t.T_TestCode,
|
||||
t.T_TestName,
|
||||
s.T_PriceAmount,
|
||||
t.T_TestIsActive
|
||||
" . $base_sql . "
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$main_params = array_merge($params, [$limit, $offset]);
|
||||
|
||||
$qry = $this->db_onedev->query($sql, $main_params);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal mengambil data test'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $qry->result_array();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data test',
|
||||
'data' => $result,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'total_page' => ceil($total / $limit)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getpacketbypriceheader()
|
||||
{
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
if (!isset($input['price_header_id'])) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'price_header_id wajib diisi'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$priceHeaderID = $input['price_header_id'];
|
||||
$search = $input['search'] ?? $this->input->get('search');
|
||||
|
||||
$page_val = $input['page'] ?? $this->input->get('page');
|
||||
$page = $page_val ? intval($page_val) : 1;
|
||||
$limit = 5;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$base_sql = "FROM t_packet p
|
||||
INNER JOIN ss_price_mou s
|
||||
ON p.T_PacketID = s.packet_id
|
||||
WHERE s.is_packet = 'Y'
|
||||
AND s.Ss_PriceMouT_PriceHeaderID = ?
|
||||
AND p.T_PacketIsActive = 'Y'";
|
||||
|
||||
$params = [$priceHeaderID];
|
||||
|
||||
if (!empty($search)) {
|
||||
$base_sql .= " AND (p.T_PacketSasCode LIKE ? OR p.T_PacketName LIKE ?)";
|
||||
$params[] = "%" . $search . "%";
|
||||
$params[] = "%" . $search . "%";
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(DISTINCT p.T_PacketID) AS total " . $base_sql;
|
||||
$qry_count = $this->db_onedev->query($count_sql, $params);
|
||||
$total = $qry_count->row()->total ?? 0;
|
||||
|
||||
$sql = "SELECT DISTINCT
|
||||
p.T_PacketID,
|
||||
p.T_PacketName,
|
||||
p.T_PacketType,
|
||||
p.T_PacketPrice,
|
||||
p.T_PacketIsActive,
|
||||
p.T_PacketSasCode
|
||||
" . $base_sql . "
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$main_params = array_merge($params, [$limit, $offset]);
|
||||
|
||||
$qry = $this->db_onedev->query($sql, $main_params);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal mengambil data packet'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $qry->result_array();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data packet',
|
||||
'data' => $result,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'total_page' => ceil($total / $limit)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
// {
|
||||
// $input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
// $CorporateID = $input['CorporateID'] ?? null;
|
||||
// $T_PriceHeaderID = $input['T_PriceHeaderID'] ?? null;
|
||||
// $StartDate = $input['StartDate'] ?? date('Y-m-d');
|
||||
// $EndDate = $input['EndDate'] ?? date('Y-m-d');
|
||||
// $Note = $input['Note'] ?? '';
|
||||
|
||||
// $T_TestIDs = $input['T_TestIDs'] ?? '';
|
||||
// if(is_array($T_TestIDs)){
|
||||
// $T_TestIDs = implode(',', $T_TestIDs);
|
||||
// }
|
||||
|
||||
// $T_PacketIDs = $input['T_PacketIDs'] ?? '';
|
||||
// if(is_array($T_PacketIDs)){
|
||||
// $T_PacketIDs = implode(',', $T_PacketIDs);
|
||||
// }
|
||||
|
||||
// $IsDefault = ($T_PriceHeaderID == 115) ? 'Y' : 'N';
|
||||
// $IsActive = 'Y';
|
||||
|
||||
// $sql = "INSERT INTO `corporate_price` (
|
||||
// `CorporatePriceCorporateID`,
|
||||
// `CorporatePriceT_PriceHeaderID`,
|
||||
// `CorporatePriceIsDefault`,
|
||||
// `CorporatePriceStartDate`,
|
||||
// `CorporatePriceEndDate`,
|
||||
// `CorporatePriceNote`,
|
||||
// `CorporatePriceT_TestIDs`,
|
||||
// `CorporatePriceT_PacketIDs`,
|
||||
// `CorporatePriceIsActive`,
|
||||
// `CorporatePriceCreated`,
|
||||
// `CorporatePriceCreatedUserID`
|
||||
// ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), 1)";
|
||||
|
||||
// $params = [$CorporateID, $T_PriceHeaderID, $IsDefault, $StartDate, $EndDate, $Note, $T_TestIDs, $T_PacketIDs, $IsActive];
|
||||
|
||||
// $this->db_onedev->trans_start();
|
||||
// $this->db_onedev->query($sql, $params);
|
||||
// $this->db_onedev->trans_complete();
|
||||
|
||||
// if ($this->db_onedev->trans_status() === FALSE) {
|
||||
// echo json_encode(['status' => 'error', 'message' => 'Gagal menyimpan data.']);
|
||||
// } else {
|
||||
// echo json_encode([
|
||||
// 'status' => 'OK',
|
||||
// 'message' => 'Berhasil menyimpan data.',
|
||||
// 'data' => ['records' => [], 'total' => 0]
|
||||
// ]);
|
||||
// }
|
||||
// exit;
|
||||
// }
|
||||
|
||||
|
||||
function savecorporateprice()
|
||||
{
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
$CorporateID = $input['CorporateID'] ?? null;
|
||||
$T_PriceHeaderID = $input['T_PriceHeaderID'] ?? null;
|
||||
$StartDate = $input['StartDate'] ?? date('Y-m-d');
|
||||
$EndDate = $input['EndDate'] ?? date('Y-m-d');
|
||||
$Note = $input['Note'] ?? '';
|
||||
|
||||
if (empty($CorporateID) || empty($T_PriceHeaderID)) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'CorporateID dan PriceHeaderID harus diisi.']);
|
||||
exit;
|
||||
}
|
||||
$checkSql = "SELECT CorporatePriceID FROM `corporate_price`
|
||||
WHERE `CorporatePriceCorporateID` = ?
|
||||
AND `CorporatePriceT_PriceHeaderID` = ?
|
||||
AND `CorporatePriceIsActive` = 'Y'";
|
||||
|
||||
$checkQuery = $this->db_onedev->query($checkSql, [$CorporateID, $T_PriceHeaderID]);
|
||||
|
||||
if ($checkQuery->num_rows() > 0) {
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal simpan: Price Header tersebut sudah terdaftar untuk Corporate ini.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($StartDate > $EndDate) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal simpan: Tanggal Mulai tidak boleh lebih besar dari Tanggal Akhir.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$T_TestIDs = $input['T_TestIDs'] ?? '';
|
||||
if(is_array($T_TestIDs)){
|
||||
$T_TestIDs = implode(',', $T_TestIDs);
|
||||
}
|
||||
|
||||
$T_PacketIDs = $input['T_PacketIDs'] ?? '';
|
||||
if(is_array($T_PacketIDs)){
|
||||
$T_PacketIDs = implode(',', $T_PacketIDs);
|
||||
}
|
||||
|
||||
$IsDefault = ($T_PriceHeaderID == 115) ? 'Y' : 'N';
|
||||
$IsActive = 'Y';
|
||||
|
||||
$sql = "INSERT INTO `corporate_price` (
|
||||
`CorporatePriceCorporateID`,
|
||||
`CorporatePriceT_PriceHeaderID`,
|
||||
`CorporatePriceIsDefault`,
|
||||
`CorporatePriceStartDate`,
|
||||
`CorporatePriceEndDate`,
|
||||
`CorporatePriceNote`,
|
||||
`CorporatePriceT_TestIDs`,
|
||||
`CorporatePriceT_PacketIDs`,
|
||||
`CorporatePriceIsActive`,
|
||||
`CorporatePriceCreated`,
|
||||
`CorporatePriceCreatedUserID`
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), 1)";
|
||||
|
||||
$params = [$CorporateID, $T_PriceHeaderID, $IsDefault, $StartDate, $EndDate, $Note, $T_TestIDs, $T_PacketIDs, $IsActive];
|
||||
|
||||
$this->db_onedev->trans_start();
|
||||
$this->db_onedev->query($sql, $params);
|
||||
$this->db_onedev->trans_complete();
|
||||
|
||||
if ($this->db_onedev->trans_status() === FALSE) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal menyimpan data ke database.']);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'OK',
|
||||
'message' => 'Berhasil menyimpan data.',
|
||||
'data' => ['records' => [], 'total' => 0]
|
||||
]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function updatecorporateprice()
|
||||
{
|
||||
// 1. Ambil Input
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
// Validasi ID Utama
|
||||
$CorporatePriceID = $input['CorporatePriceID'] ?? null;
|
||||
if (empty($CorporatePriceID)) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'CorporatePriceID wajib diisi.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ambil Parameter Lain
|
||||
$CorporateID = $input['CorporateID'] ?? null;
|
||||
$T_PriceHeaderID = $input['T_PriceHeaderID'] ?? null;
|
||||
$StartDate = $input['StartDate'] ?? date('Y-m-d');
|
||||
$EndDate = $input['EndDate'] ?? date('Y-m-d');
|
||||
$Note = $input['Note'] ?? '';
|
||||
|
||||
// --- VALIDASI TANGGAL (BARU DITAMBAHKAN) ---
|
||||
// Menggunakan strtotime agar aman untuk segala format tanggal
|
||||
if (strtotime($StartDate) > strtotime($EndDate)) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal update: Tanggal Mulai tidak boleh lebih besar dari Tanggal Akhir.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
// -------------------------------------------
|
||||
|
||||
// Format Array ke String (Sesuai kolom varchar(500))
|
||||
$T_TestIDs = $input['T_TestIDs'] ?? '';
|
||||
if(is_array($T_TestIDs)){
|
||||
$T_TestIDs = implode(',', $T_TestIDs);
|
||||
}
|
||||
|
||||
$T_PacketIDs = $input['T_PacketIDs'] ?? '';
|
||||
if(is_array($T_PacketIDs)){
|
||||
$T_PacketIDs = implode(',', $T_PacketIDs);
|
||||
}
|
||||
|
||||
// Logika Default
|
||||
$IsDefault = ($T_PriceHeaderID == 115) ? 'Y' : 'N';
|
||||
|
||||
// --- 2. AMBIL DATA LAMA (BEFORE) ---
|
||||
$sqlGet = "SELECT * FROM corporate_price WHERE CorporatePriceID = ?";
|
||||
$qryGet = $this->db_onedev->query($sqlGet, [$CorporatePriceID]);
|
||||
$oldData = $qryGet->row_array();
|
||||
|
||||
if (!$oldData) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Data ID ' . $CorporatePriceID . ' tidak ditemukan.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- 3. SUSUN DATA BARU (AFTER) UNTUK LOG ---
|
||||
// Kita copy data lama, lalu timpa value-nya dengan inputan baru
|
||||
$newData = $oldData;
|
||||
$newData['CorporatePriceCorporateID'] = $CorporateID;
|
||||
$newData['CorporatePriceT_PriceHeaderID'] = $T_PriceHeaderID;
|
||||
$newData['CorporatePriceIsDefault'] = $IsDefault;
|
||||
$newData['CorporatePriceStartDate'] = $StartDate;
|
||||
$newData['CorporatePriceEndDate'] = $EndDate;
|
||||
$newData['CorporatePriceNote'] = $Note;
|
||||
$newData['CorporatePriceT_TestIDs'] = $T_TestIDs;
|
||||
$newData['CorporatePriceT_PacketIDs'] = $T_PacketIDs;
|
||||
|
||||
// --- 4. MULAI TRANSAKSI DATABASE ---
|
||||
$this->db_onedev->trans_start();
|
||||
|
||||
// A. Query Update Data Utama
|
||||
$sql = "UPDATE `corporate_price` SET
|
||||
`CorporatePriceCorporateID` = ?,
|
||||
`CorporatePriceT_PriceHeaderID` = ?,
|
||||
`CorporatePriceIsDefault` = ?,
|
||||
`CorporatePriceStartDate` = ?,
|
||||
`CorporatePriceEndDate` = ?,
|
||||
`CorporatePriceNote` = ?,
|
||||
`CorporatePriceT_TestIDs` = ?,
|
||||
`CorporatePriceT_PacketIDs` = ?
|
||||
WHERE `CorporatePriceID` = ?";
|
||||
|
||||
$params = [
|
||||
$CorporateID,
|
||||
$T_PriceHeaderID,
|
||||
$IsDefault,
|
||||
$StartDate,
|
||||
$EndDate,
|
||||
$Note,
|
||||
$T_TestIDs,
|
||||
$T_PacketIDs,
|
||||
$CorporatePriceID
|
||||
];
|
||||
|
||||
$this->db_onedev->query($sql, $params);
|
||||
|
||||
// B. Query Insert Log
|
||||
$sqlLog = "INSERT INTO cpone_log.log_corporate_price (
|
||||
Log_CorporateType,
|
||||
Log_CorporatePriceCorporateID,
|
||||
Log_CorporatePriceT_PriceHeaderID,
|
||||
Log_CorporatePriceBefore,
|
||||
Log_CorporatePriceAfter,
|
||||
Log_CorporatePriceUserID,
|
||||
Log_CorporatePriceCreated
|
||||
) VALUES (?, ?, ?, ?, ?, ?, NOW())";
|
||||
|
||||
$paramsLog = [
|
||||
'UPDATE',
|
||||
$oldData['CorporatePriceCorporateID'],
|
||||
$oldData['CorporatePriceT_PriceHeaderID'],
|
||||
json_encode($oldData),
|
||||
json_encode($newData),
|
||||
1
|
||||
];
|
||||
|
||||
$this->db_onedev->query($sqlLog, $paramsLog);
|
||||
|
||||
// --- 5. SELESAI TRANSAKSI ---
|
||||
$this->db_onedev->trans_complete();
|
||||
|
||||
if ($this->db_onedev->trans_status() === FALSE) {
|
||||
$error = $this->db_onedev->error();
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal update data: ' . ($error['message'] ?? 'Unknown Error')
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'OK',
|
||||
'message' => 'Berhasil mengupdate data.',
|
||||
'data' => ['records' => [], 'total' => 0]
|
||||
]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function getlistcorporateprice()
|
||||
{
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
$CorporateID = $input['CorporateID'] ?? null;
|
||||
$page_val = $input['page'] ?? 1;
|
||||
$page = intval($page_val) > 0 ? intval($page_val) : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
$where_clauses = ["cp.CorporatePriceIsActive = 'Y'"];
|
||||
$params = [];
|
||||
|
||||
if (!empty($CorporateID)) {
|
||||
$where_clauses[] = "cp.CorporatePriceCorporateID = ?";
|
||||
$params[] = $CorporateID;
|
||||
}
|
||||
|
||||
$where_sql = " WHERE " . implode(" AND ", $where_clauses);
|
||||
$count_sql = "SELECT COUNT(cp.CorporatePriceID) as total
|
||||
FROM corporate_price cp
|
||||
" . $where_sql;
|
||||
|
||||
$qry_count = $this->db_onedev->query($count_sql, $params);
|
||||
$total = $qry_count->row()->total ?? 0;
|
||||
$main_sql = "SELECT
|
||||
cp.*,
|
||||
c.CorporateName,
|
||||
ph.T_PriceHeaderCode,
|
||||
ph.T_PriceHeaderName,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(t.T_TestID, '||', t.T_TestCode, '||', t.T_TestName) ORDER BY t.T_TestName SEPARATOR ';;') AS TestDetails,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(p.T_PacketID, '||', p.T_PacketSasCode, '||', p.T_PacketName, '||', p.T_PacketPrice) ORDER BY p.T_PacketName SEPARATOR ';;') AS PacketDetails
|
||||
FROM corporate_price cp
|
||||
LEFT JOIN corporate c
|
||||
ON c.CorporateID = cp.CorporatePriceCorporateID
|
||||
LEFT JOIN t_priceheader ph
|
||||
ON ph.T_PriceHeaderID = cp.CorporatePriceT_PriceHeaderID
|
||||
LEFT JOIN t_test t
|
||||
ON FIND_IN_SET(t.T_TestID, cp.CorporatePriceT_TestIDs) > 0
|
||||
LEFT JOIN t_packet p
|
||||
ON FIND_IN_SET(p.T_PacketID, cp.CorporatePriceT_PacketIDs) > 0
|
||||
" . $where_sql . "
|
||||
GROUP BY cp.CorporatePriceID
|
||||
ORDER BY cp.CorporatePriceID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$main_params = array_merge($params, [$limit, $offset]);
|
||||
|
||||
$qry = $this->db_onedev->query($main_sql, $main_params);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data price header.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $qry->result_array();
|
||||
foreach ($result as &$row) {
|
||||
$testList = [];
|
||||
if (!empty($row['TestDetails'])) {
|
||||
$items = explode(';;', $row['TestDetails']);
|
||||
foreach ($items as $item) {
|
||||
$parts = explode('||', $item);
|
||||
if (count($parts) === 3) {
|
||||
$testList[] = [
|
||||
'T_TestID' => $parts[0],
|
||||
'T_TestCode' => $parts[1],
|
||||
'T_TestName' => $parts[2]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$row['TestDetails'] = $testList;
|
||||
$packetList = [];
|
||||
if (!empty($row['PacketDetails'])) {
|
||||
$items = explode(';;', $row['PacketDetails']);
|
||||
foreach ($items as $item) {
|
||||
$parts = explode('||', $item);
|
||||
if (count($parts) === 4) {
|
||||
$packetList[] = [
|
||||
'T_PacketID' => $parts[0],
|
||||
'T_PacketSasCode' => $parts[1],
|
||||
'T_PacketName' => $parts[2],
|
||||
'T_PacketPrice' => $parts[3]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$row['PacketDetails'] = $packetList;
|
||||
}
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil data price header.',
|
||||
'data' => $result,
|
||||
'total' => intval($total),
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'total_page' => ceil($total / $limit)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function deletecorporateprice()
|
||||
{
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
$CorporatePriceID = $input['CorporatePriceID'] ?? null;
|
||||
|
||||
if (empty($CorporatePriceID)) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'CorporatePriceID wajib diisi.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlGet = "SELECT * FROM corporate_price WHERE CorporatePriceID = ?";
|
||||
$qryGet = $this->db_onedev->query($sqlGet, [$CorporatePriceID]);
|
||||
$oldData = $qryGet->row_array();
|
||||
|
||||
if (!$oldData) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE corporate_price
|
||||
SET CorporatePriceIsActive = 'N',
|
||||
CorporatePriceDeleted = NOW(),
|
||||
CorporatePriceDeletedUserID = 1
|
||||
WHERE CorporatePriceID = ?";
|
||||
|
||||
$this->db_onedev->trans_start();
|
||||
$this->db_onedev->query($sql, [$CorporatePriceID]);
|
||||
|
||||
$newData = $oldData;
|
||||
$newData['CorporatePriceIsActive'] = 'N';
|
||||
$newData['CorporatePriceDeleted'] = date('Y-m-d H:i:s');
|
||||
$newData['CorporatePriceDeletedUserID'] = 1;
|
||||
|
||||
$sqlLog = "INSERT INTO cpone_log.log_corporate_price (Log_CorporateType, Log_CorporatePriceCorporateID, Log_CorporatePriceT_PriceHeaderID, Log_CorporatePriceBefore, Log_CorporatePriceAfter, Log_CorporatePriceUserID, Log_CorporatePriceCreated) VALUES (?, ?, ?, ?, ?, ?, NOW())";
|
||||
$this->db_onedev->query($sqlLog, [
|
||||
'DELETE',
|
||||
$oldData['CorporatePriceCorporateID'],
|
||||
$oldData['CorporatePriceT_PriceHeaderID'],
|
||||
json_encode($oldData),
|
||||
json_encode($newData),
|
||||
1
|
||||
]);
|
||||
|
||||
$this->db_onedev->trans_complete();
|
||||
|
||||
if ($this->db_onedev->trans_status() === FALSE) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal menghapus data.']);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'OK',
|
||||
'message' => 'Berhasil menghapus data.'
|
||||
]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function getdetailcorporateprice()
|
||||
{
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
$CorporatePriceID = $input['CorporatePriceID'] ?? null;
|
||||
|
||||
if (empty($CorporatePriceID)) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'CorporatePriceID wajib diisi.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
cp.*,
|
||||
c.CorporateName,
|
||||
ph.T_PriceHeaderCode,
|
||||
ph.T_PriceHeaderName,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(t.T_TestID, '||', t.T_TestCode, '||', t.T_TestName) ORDER BY t.T_TestName SEPARATOR ';;') AS TestDetails,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(p.T_PacketID, '||', p.T_PacketSasCode, '||', p.T_PacketName, '||', p.T_PacketPrice) ORDER BY p.T_PacketName SEPARATOR ';;') AS PacketDetails
|
||||
FROM corporate_price cp
|
||||
LEFT JOIN corporate c
|
||||
ON c.CorporateID = cp.CorporatePriceCorporateID
|
||||
LEFT JOIN t_priceheader ph
|
||||
ON ph.T_PriceHeaderID = cp.CorporatePriceT_PriceHeaderID
|
||||
LEFT JOIN t_test t
|
||||
ON FIND_IN_SET(t.T_TestID, cp.CorporatePriceT_TestIDs) > 0
|
||||
LEFT JOIN t_packet p
|
||||
ON FIND_IN_SET(p.T_PacketID, cp.CorporatePriceT_PacketIDs) > 0
|
||||
WHERE cp.CorporatePriceID = ?
|
||||
GROUP BY cp.CorporatePriceID";
|
||||
|
||||
$qry = $this->db_onedev->query($sql, [$CorporatePriceID]);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil detail corporate price.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $qry->result_array();
|
||||
|
||||
foreach ($result as &$row) {
|
||||
$testList = [];
|
||||
if (!empty($row['TestDetails'])) {
|
||||
$items = explode(';;', $row['TestDetails']);
|
||||
foreach ($items as $item) {
|
||||
$parts = explode('||', $item);
|
||||
if (count($parts) === 3) {
|
||||
$testList[] = [
|
||||
'T_TestID' => $parts[0],
|
||||
'T_TestCode' => $parts[1],
|
||||
'T_TestName' => $parts[2]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$row['TestDetails'] = $testList;
|
||||
|
||||
$packetList = [];
|
||||
if (!empty($row['PacketDetails'])) {
|
||||
$items = explode(';;', $row['PacketDetails']);
|
||||
foreach ($items as $item) {
|
||||
$parts = explode('||', $item);
|
||||
if (count($parts) === 4) {
|
||||
$packetList[] = [
|
||||
'T_PacketID' => $parts[0],
|
||||
'T_PacketSasCode' => $parts[1],
|
||||
'T_PacketName' => $parts[2],
|
||||
'T_PacketPrice' => $parts[3]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$row['PacketDetails'] = $packetList;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Berhasil mengambil detail corporate price.',
|
||||
'data' => $result,
|
||||
'total' => count($result)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
61
application/controllers/corporate-price/try.http
Normal file
61
application/controllers/corporate-price/try.http
Normal file
@@ -0,0 +1,61 @@
|
||||
@baseUrl = https://devcpone.aplikasi.web.id/one-api/corporate-price
|
||||
@contentType = application/json
|
||||
|
||||
####
|
||||
POST {{baseUrl}}/Companyprice/search
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
###
|
||||
POST {{baseUrl}}/Companyprice/search
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"corporate_code": "C25040007"
|
||||
}
|
||||
|
||||
####
|
||||
POST {{baseUrl}}/Companyprice/search
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"corporate_name": "PT Gerbang Saranabaja"
|
||||
}
|
||||
|
||||
####
|
||||
POST {{baseUrl}}/Companyprice/getcorporateprices
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"corporate_id": 132
|
||||
}
|
||||
|
||||
###
|
||||
GET {{baseUrl}}/Companyprice/getcorporateprice
|
||||
|
||||
|
||||
###
|
||||
POST {{baseUrl}}/Companyprice/getlistpriceheader
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
###
|
||||
POST {{baseUrl}}/Companyprice/gettestbypriceheader
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"price_header_id": 115
|
||||
}
|
||||
|
||||
###
|
||||
POST {{baseUrl}}/Companyprice/getpacketbypriceheader
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"price_header_id": 115
|
||||
}
|
||||
1141
application/controllers/corporate/Uploader.php
Normal file
1141
application/controllers/corporate/Uploader.php
Normal file
File diff suppressed because it is too large
Load Diff
907
application/controllers/corporate/Uploader_dbg.php
Normal file
907
application/controllers/corporate/Uploader_dbg.php
Normal file
@@ -0,0 +1,907 @@
|
||||
<?php
|
||||
class Uploader_dbg extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function get_param()
|
||||
{
|
||||
$raw = file_get_contents("php://input");
|
||||
return json_decode($raw, true);
|
||||
}
|
||||
function get_company($companyID)
|
||||
{
|
||||
$sql = "select M_CompanyID, M_CompanyOldID, M_BranchID M_CompanyM_BranchID, M_CompanyName, M_CompanyNumber,
|
||||
M_CompanyIDParent, M_CompanyM_CompanyTypeID, M_CompanyM_CompanyBusinessID,
|
||||
M_CompanyM_ProvinceID, M_CompanyM_CityID, M_CompanyM_DistrictID, M_CompanyM_KelurahanID,
|
||||
M_CompanyAddress, M_CompanyPhone, M_CompanyFax, M_CompanyEmail, M_CompanyPIC,
|
||||
M_CompanyM_StaffID, M_CompanyNat_CompanyLevelID, M_CompanyNat_HierarchyID,
|
||||
M_CompanyIsLabFrom, M_CompanyIsLabTo, M_CompanyIsDefault, M_CompanyM_DoctorID,
|
||||
M_CompanyCreated, M_CompanyLastUpdated, M_CompanyIsActive, M_CompanyAddressLocation,
|
||||
M_CompanyHp, M_CompanyPrivateRequest
|
||||
from m_company
|
||||
join m_branch on M_CompanyID = ?
|
||||
and M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql, [$companyID]);
|
||||
if (!$qry) {
|
||||
$this->reply_gz(
|
||||
json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => $this->db->error()["message"],
|
||||
])
|
||||
);
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$this->reply_gz(
|
||||
json_encode([
|
||||
"status" => "OK",
|
||||
"data" => $rows,
|
||||
])
|
||||
);
|
||||
}
|
||||
function update_upload_mou()
|
||||
{
|
||||
$param = $this->get_param();
|
||||
$uploadID = $param["uploadID"];
|
||||
$status = $param["status"];
|
||||
$sql = "update corp_upload set Corp_UploadStatus = ?
|
||||
, Corp_UploadRetry = Corp_UploadRetry+1
|
||||
, Corp_UploadSentDate = now()
|
||||
where Corp_UploadID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$status, $uploadID]);
|
||||
if (!$qry) {
|
||||
$this->reply_gz(
|
||||
json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => $this->db->error()["message"],
|
||||
])
|
||||
);
|
||||
}
|
||||
$this->reply_gz(
|
||||
json_encode([
|
||||
"status" => "OK",
|
||||
"message" => "",
|
||||
])
|
||||
);
|
||||
}
|
||||
function get_upload_mou()
|
||||
{
|
||||
//Hardcode 1st
|
||||
//2277,2278,2279,2613
|
||||
list($branchID, $branchCode) = $this->get_branch();
|
||||
$sql = "select Corp_UploadID, Corp_UploadM_MouID M_MouID,
|
||||
M_MouM_CompanyID
|
||||
from corp_upload
|
||||
join m_mou on Corp_UploadM_MouID = M_MouID
|
||||
where
|
||||
Corp_UploadStatus <> 'Y'
|
||||
and
|
||||
Corp_UploadIsActive = 'Y'
|
||||
and Corp_UploadRetry < 5
|
||||
limit 0,10
|
||||
";
|
||||
$resp = $this->get_rows($sql);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz($resp["message"]);
|
||||
}
|
||||
$result = [];
|
||||
foreach ($resp["data"] as $idx => $r) {
|
||||
$result[] = $r;
|
||||
}
|
||||
$data = json_encode(["status" => "OK", "data" => $result]);
|
||||
$this->reply_gz($data);
|
||||
}
|
||||
function mou_order($mouID)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->get_branch();
|
||||
// get order | pasien
|
||||
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,T_OrderHeaderLabNumberExt,
|
||||
T_OrderHeaderLastUpdated, max(ifnull(T_OrderDetailValDate,'1971-01-01 00:01:01')) LastValidationDate,
|
||||
max(ifnull(T_OrderDetailVerDate,'1971-01-01 00:01:01')) LastVerifDate,
|
||||
$branchID M_BranchID, '$branchCode' M_BranchCode, T_OrderHeaderM_PatientID,
|
||||
JSON_UNQUOTE( JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID),'$.patient_fullname')) FullName,
|
||||
JSON_UNQUOTE( JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID),'$.M_PatientName')) M_PatientName,
|
||||
T_OrderHeaderM_CompanyID M_CompanyID, M_CompanyNumber,
|
||||
T_OrderHeaderM_MouID M_MouID,
|
||||
M_PatientNIK, M_PatientJabatan, M_PatientKedudukan, M_PatientLocation, M_PatientJob
|
||||
from
|
||||
t_orderheader
|
||||
join t_orderheaderaddon on
|
||||
T_OrderHeaderM_MouID = ?
|
||||
and T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
-- and T_OrderHeaderAddOnValidationDone = 'Y'
|
||||
join m_company on M_CompanyID = T_OrderHeaderM_CompanyID
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join t_orderdetail
|
||||
on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
group by T_OrderHeaderID";
|
||||
$resp = $this->get_rows($sql, [$mouID]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz(
|
||||
"Err Get Order for MOU ID : $mouID | " . $resp["message"]
|
||||
);
|
||||
exit();
|
||||
}
|
||||
$orders = $resp["data"];
|
||||
echo $this->reply_gz(
|
||||
json_encode(["status" => "OK", "data" => $orders])
|
||||
);
|
||||
}
|
||||
|
||||
//Get Detail Mou
|
||||
function mou_detail($mouID)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->get_branch();
|
||||
$sql = "select $branchID Corp_M_BranchID , '$branchCode' Corp_M_BranchCode,
|
||||
M_MouID, M_MouName, M_MouNote , M_CompanyNumber M_MouM_CompanyNumber,
|
||||
M_MouM_CompanyID , M_MouRefNumber ,
|
||||
M_MouNumber , M_MouStartDate , M_MouEndDate , M_MouBase,
|
||||
M_MouM_OmzetTypeID , M_MouIsReleased , M_MouReleaseDate ,
|
||||
M_MouReleaseUserID , M_MouCreated , M_MouLastUpdated ,
|
||||
M_MouIsActive, M_MouUserID
|
||||
from m_mou
|
||||
join m_company on M_MouM_CompanyID = M_CompanyID
|
||||
where M_MouID = ?";
|
||||
$resp = $this->get_row($sql, [$mouID]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz($resp["message"]);
|
||||
}
|
||||
if ($resp["status"] == 0) {
|
||||
$this->error_reply_gz("Mou ID $mouID not found.");
|
||||
}
|
||||
$result = $resp["data"];
|
||||
$this->reply_gz(
|
||||
json_encode(["status" => "OK", "data" => $resp["data"]])
|
||||
);
|
||||
}
|
||||
function reply_gz($resp)
|
||||
{
|
||||
echo gzcompress($resp);
|
||||
exit();
|
||||
}
|
||||
function get_branch()
|
||||
{
|
||||
$sql =
|
||||
"select M_BranchID,M_BranchCode from m_branch where M_BranchIsActive='Y' and M_BranchIsDefault ='Y'";
|
||||
$resp = $this->get_row($sql);
|
||||
if ($resp["status"] != 1) {
|
||||
echo json_encode($resp);
|
||||
exit();
|
||||
}
|
||||
return [$resp["data"]["M_BranchID"], $resp["data"]["M_BranchCode"]];
|
||||
}
|
||||
function log($msg)
|
||||
{
|
||||
$dt = date("Y-m-d H:i:s");
|
||||
echo "$dt $msg\n";
|
||||
}
|
||||
function error_reply_gz($msg)
|
||||
{
|
||||
echo gzcompress(json_encode(["status" => "ERR", "message" => $msg]));
|
||||
}
|
||||
function reply($resp, $type = 1)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
}
|
||||
function error_reply($msg)
|
||||
{
|
||||
echo json_encode(["status" => "ERR", "message" => $msg]);
|
||||
}
|
||||
function get_mou_param($mouID)
|
||||
{
|
||||
$sql = "select M_MouM_CompanyID, M_MouStartDate, M_MouEndDate
|
||||
from m_mou
|
||||
where M_MouID = ?";
|
||||
$resp = $this->get_row($sql, [$mouID]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply(
|
||||
"Err Get Mou Param from $mouID : " . $resp["message"]
|
||||
);
|
||||
exit();
|
||||
}
|
||||
if ($resp["status"] == 0) {
|
||||
return [0, "1971-01-01", "1971-01-01"];
|
||||
}
|
||||
$r = $resp["data"];
|
||||
return [
|
||||
$r["M_MouM_CompanyID"],
|
||||
$r["M_MouStartDate"],
|
||||
$r["M_MouEndDate"],
|
||||
];
|
||||
}
|
||||
function getCompanyNumber($companyID)
|
||||
{
|
||||
$sql = "select M_CompanyNumber from m_company where M_CompanyID = ?";
|
||||
$resp = $this->get_row($sql, [$companyID]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply(
|
||||
"Err Get Company from $companyID: " . $resp["message"]
|
||||
);
|
||||
exit();
|
||||
}
|
||||
if ($resp["status"] == 0) {
|
||||
return "";
|
||||
}
|
||||
$r = $resp["data"];
|
||||
return $r["M_CompanyNumber"];
|
||||
}
|
||||
//
|
||||
function do_global($mouID)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->get_branch();
|
||||
$arr_sp = ["sp_rpt_nl_001_v2", "sp_rpt_nl_002_v2", "sp_rpt_nl_003_v2"];
|
||||
list($companyID, $startDate, $endDate) = $this->get_mou_param($mouID);
|
||||
$companyNumber = $this->getCompanyNumber($companyID);
|
||||
|
||||
$result = [];
|
||||
for ($idx = 0; $idx < 3; $idx++) {
|
||||
$sp = $arr_sp[$idx];
|
||||
$key = str_replace("sp_", "", $sp);
|
||||
$key = str_replace("_v2", "", $key);
|
||||
|
||||
$sql = "call {$sp}(?,?,?,?,'admin')";
|
||||
$resp = $this->get_sp($sql, [
|
||||
$startDate,
|
||||
$endDate,
|
||||
$companyID,
|
||||
$mouID,
|
||||
]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz("Err $sp : " . $resp["message"]);
|
||||
exit();
|
||||
}
|
||||
$xresult = [];
|
||||
foreach ($resp["data"] as $r) {
|
||||
$r["M_CompanyNumber"] = $companyNumber;
|
||||
$r["M_BranchID"] = $branchID;
|
||||
$r["M_BranchCode"] = $branchCode;
|
||||
$xresult[] = $r;
|
||||
}
|
||||
$result[$key] = $xresult;
|
||||
}
|
||||
echo $this->reply_gz(
|
||||
json_encode([
|
||||
"status" => "OK",
|
||||
"branchID" => $branchID,
|
||||
"branchCode" => $branchCode,
|
||||
"companyID" => $companyID,
|
||||
"result" => $result,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
function get_resume_id($headerID)
|
||||
{
|
||||
$sql = "select Mcu_ResumeID from mcu_resume
|
||||
where Mcu_ResumeT_OrderHeaderID = ?
|
||||
and Mcu_ResumeIsActive = 'Y'
|
||||
order by Mcu_ResumeID desc
|
||||
limit 0,1";
|
||||
$resp = $this->get_row($sql, [$headerID]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply(
|
||||
"Err Get ResumeID from T_OrderHeaderID $headerID : " .
|
||||
$resp["message"]
|
||||
);
|
||||
exit();
|
||||
}
|
||||
if ($resp["status"] == 0) {
|
||||
return 0;
|
||||
}
|
||||
return $resp["data"]["Mcu_ResumeID"];
|
||||
}
|
||||
function json_get_so_id($headerID, $so = "")
|
||||
{
|
||||
echo json_encode($this->get_so_result_entry_id($headerID, $so));
|
||||
}
|
||||
function get_so_result_entry_id($headerID, $so = "")
|
||||
{
|
||||
$sql = "select So_ResultEntryID
|
||||
from so_resultentry
|
||||
join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_TestNat_GroupID = 4
|
||||
and T_TestIsNonLab = 'FISIK UMUM'
|
||||
where So_ResultEntryT_OrderHeaderID = ?
|
||||
and So_ResultentryIsActive = 'Y'
|
||||
order by So_ResultEntryID desc
|
||||
limit 0,1";
|
||||
|
||||
|
||||
if ($so == "audio") {
|
||||
$sql = "select So_ResultEntryID
|
||||
from so_resultentry
|
||||
join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_TestNat_GroupID = 2
|
||||
and T_TestIsNonLab = 'AUDIOMETRY'
|
||||
where So_ResultEntryT_OrderHeaderID = ?
|
||||
and So_ResultentryIsActive = 'Y'
|
||||
order by So_ResultEntryID desc
|
||||
limit 0,1";
|
||||
} elseif ($so == "ecg") {
|
||||
$sql = "select So_ResultEntryID
|
||||
from so_resultentry
|
||||
join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_TestNat_GroupID = 2
|
||||
and T_TestIsNonLab = 'ELECTROMEDIS'
|
||||
where So_ResultEntryT_OrderHeaderID = ?
|
||||
and So_ResultentryIsActive = 'Y'
|
||||
order by So_ResultEntryID desc
|
||||
limit 0,1";
|
||||
} elseif ($so == "treadmill") {
|
||||
$sql = "select So_ResultEntryID
|
||||
from so_resultentry
|
||||
join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_TestNat_GroupID = 2
|
||||
and T_TestIsNonLab = 'TREADMILL'
|
||||
where So_ResultEntryT_OrderHeaderID = ?
|
||||
and So_ResultentryIsActive = 'Y'
|
||||
order by So_ResultEntryID desc
|
||||
limit 0,1";
|
||||
} elseif ($so == "elmd") {
|
||||
$sql = "select So_ResultEntryID
|
||||
from so_resultentry
|
||||
join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_TestNat_GroupID = 2
|
||||
where So_ResultEntryT_OrderHeaderID = ?
|
||||
and So_ResultentryIsActive = 'Y'
|
||||
order by So_ResultEntryID desc
|
||||
limit 0,1";
|
||||
} elseif ($so == "usg") {
|
||||
$sql = "select So_ResultEntryID
|
||||
from so_resultentry
|
||||
join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_TestNat_GroupID = 3
|
||||
and T_TestNat_SubGroupID = 22
|
||||
where So_ResultEntryT_OrderHeaderID = ?
|
||||
and So_ResultentryIsActive = 'Y'
|
||||
order by So_ResultEntryID desc
|
||||
limit 0,1";
|
||||
} elseif ($so == "manthoux") {
|
||||
$sql = "select So_ResultEntryID
|
||||
from so_resultentry
|
||||
join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_TestNat_GroupID = 1
|
||||
and T_TestNat_SubGroupID = 10
|
||||
where So_ResultEntryT_OrderHeaderID = ?
|
||||
and So_ResultentryIsActive = 'Y'
|
||||
order by So_ResultEntryID desc
|
||||
limit 0,1";
|
||||
}
|
||||
$resp = $this->get_row($sql, [$headerID]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply(
|
||||
"Err Get ResumeID from T_OrderHeaderID $headerID : " .
|
||||
$resp["message"]
|
||||
);
|
||||
exit();
|
||||
}
|
||||
if ($resp["status"] == 0) {
|
||||
return 0;
|
||||
}
|
||||
return $resp["data"]["So_ResultEntryID"];
|
||||
}
|
||||
|
||||
// Hasil lab per individu
|
||||
// Hasil Non Lab per individu
|
||||
// Hasil Resume Individu
|
||||
// by T_OrderHeaderID
|
||||
function get_report($uploadID)
|
||||
{
|
||||
$sql = "select Corp_ReportCode
|
||||
from
|
||||
corp_report
|
||||
join corp_uploaderdetail on
|
||||
Corp_UploaderDetailCorp_ReportID = Corp_ReportID
|
||||
and Corp_UploaderDetailCorp_UploadID = ?";
|
||||
$qry = $this->db->query($sql, [$uploadID]);
|
||||
if (!$qry) {
|
||||
$this->reply_gz(
|
||||
json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error get Reports : " . $this->db->error()["message"],
|
||||
])
|
||||
);
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
//pasti ikut
|
||||
$result[] = "sp_rpt_t_hasil_sampling";
|
||||
$result[] = "sp_rpt_t_hasil_sampling_eng";
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
foreach ($rows as $r) {
|
||||
$rpt_code = $r["Corp_ReportCode"];
|
||||
switch ($rpt_code) {
|
||||
case "001":
|
||||
if (!in_array("sp_rpt_t_hasil2", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil2";
|
||||
}
|
||||
break;
|
||||
case "002":
|
||||
if (!in_array("sp_rpt_t_hasil_eng", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_eng";
|
||||
}
|
||||
break;
|
||||
case "003":
|
||||
if (!in_array("sp_rpt_t_hasil_so", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
}
|
||||
if (!in_array("sp_rpt_t_hasil_so_xray", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so_xray";
|
||||
}
|
||||
break;
|
||||
case "004":
|
||||
if (!in_array("sp_rpt_t_hasil_so", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
}
|
||||
if (!in_array("sp_rpt_t_hasil_so_elmd", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so_elmd";
|
||||
}
|
||||
break;
|
||||
case "005":
|
||||
if (!in_array("sp_rpt_t_hasil_so", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
}
|
||||
if (!in_array("sp_rpt_mcu_resume_cp_r", $result)) {
|
||||
$result[] = "sp_rpt_mcu_resume_cp_r";
|
||||
}
|
||||
if (!in_array("sp_rpt_mcu_resume_cp_r_eng", $result)) {
|
||||
$result[] = "sp_rpt_mcu_resume_cp_r_eng";
|
||||
}
|
||||
break;
|
||||
case "006":
|
||||
if (!in_array("sp_rpt_t_hasil_so", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
}
|
||||
if (!in_array("sp_rpt_mcu_resume_cp_r", $result)) {
|
||||
$result[] = "sp_rpt_mcu_resume_cp_r";
|
||||
}
|
||||
if (!in_array("sp_rpt_mcu_resume_cp_r_eng", $result)) {
|
||||
$result[] = "sp_rpt_mcu_resume_cp_r_eng";
|
||||
}
|
||||
break;
|
||||
case "007":
|
||||
if (!in_array("sp_rpt_t_hasil_so", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
}
|
||||
if (!in_array("sp_rpt_mcu_resume_cp_r", $result)) {
|
||||
$result[] = "sp_rpt_mcu_resume_cp_r";
|
||||
}
|
||||
if (!in_array("sp_rpt_mcu_resume_cp_r_eng", $result)) {
|
||||
$result[] = "sp_rpt_mcu_resume_cp_r_eng";
|
||||
}
|
||||
break;
|
||||
case "008":
|
||||
case "009":
|
||||
if (!in_array("riw", $result)) {
|
||||
$result[] = "sp_dummy_fisik";
|
||||
}
|
||||
break;
|
||||
|
||||
case "010": //audio
|
||||
if (!in_array("sp_rpt_t_hasil_so", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
}
|
||||
if (!in_array("sp_rpt_t_hasil_so_elmd-audio", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so_elmd-audio";
|
||||
}
|
||||
break;
|
||||
case "011": //ecg
|
||||
if (!in_array("sp_rpt_t_hasil_so", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
}
|
||||
if (!in_array("sp_rpt_t_hasil_so_elmd-ecg", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so_elmd-ecg";
|
||||
}
|
||||
break;
|
||||
case "012": //treadmill
|
||||
if (!in_array("sp_rpt_t_hasil_so", $result)) {
|
||||
$result[] = "sp_rpt_t_hasil_so";
|
||||
}
|
||||
if (
|
||||
!in_array("sp_rpt_t_hasil_so_elmd-treadmill", $result)
|
||||
) {
|
||||
$result[] = "sp_rpt_t_hasil_so_elmd-treadmill";
|
||||
}
|
||||
break;
|
||||
case "013": //pajanan
|
||||
if (!in_array("sp_dummy_pajanan", $result)) {
|
||||
$result[] = "sp_dummy_pajanan";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
function individu($headerID, $uploadID)
|
||||
{
|
||||
$arr_sp = $this->get_report($uploadID);
|
||||
$result = [];
|
||||
foreach ($arr_sp as $sp) {
|
||||
$key = str_replace("sp_", "", $sp);
|
||||
$sql = "call {$sp}(?,'admin')";
|
||||
|
||||
if ($sp == "sp_rpt_mcu_resume_cp_r") {
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resumeID = $this->get_resume_id($headerID);
|
||||
$resp = $this->get_sp($sql, [$resumeID]);
|
||||
} elseif ($sp == "sp_rpt_mcu_resume_cp_r_eng") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resumeID = $this->get_resume_id($headerID);
|
||||
$resp = $this->get_sp($sql, [$resumeID]);
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id($headerID);
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_bdm") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resp = $this->get_sp($sql, [$headerID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$headerID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_elmd") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"elmd"
|
||||
);
|
||||
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_elmd-audio") {
|
||||
$xsp = "sp_rpt_t_hasil_so_elmd";
|
||||
$sql = "call {$xsp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"audio"
|
||||
);
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$xsp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_elmd-ecg") {
|
||||
$xsp = "sp_rpt_t_hasil_so_elmd";
|
||||
$sql = "call {$xsp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"ecg"
|
||||
);
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$xsp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_elmd-treadmill") {
|
||||
$xsp = "sp_rpt_t_hasil_so_elmd";
|
||||
$sql = "call {$xsp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"treadmill"
|
||||
);
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$xsp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_dummy_pajanan") {
|
||||
$arr_sub_url = [
|
||||
"pribadi",
|
||||
"faktor_biologi",
|
||||
"faktor_ergonomi",
|
||||
"faktor_fisik",
|
||||
"faktor_kimia",
|
||||
"faktor_psikologi",
|
||||
];
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"pajanan"
|
||||
);
|
||||
$new_data = ["pajanan" => []];
|
||||
|
||||
if ($resultEntryID > 0) {
|
||||
foreach ($arr_sub_url as $s_url) {
|
||||
$new_data["pajanan"][$s_url] = $this->get_fisik(
|
||||
$s_url,
|
||||
$resultEntryID,
|
||||
"k3"
|
||||
);
|
||||
}
|
||||
}
|
||||
$resp = ["data" => $new_data, "status" => 0];
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_layanan") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"layanan"
|
||||
);
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_manthoux") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"manthoux"
|
||||
);
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_manthoux_sampling") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"manthoux"
|
||||
);
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_usg") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"usg"
|
||||
);
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$resultEntryID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_rpt_t_hasil_so_xray") {
|
||||
$sql = "call {$sp}(?,2,'admin')";
|
||||
$resp = $this->get_sp($sql, [$headerID]);
|
||||
$new_data = [];
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 2;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$sql = "call {$sp}(?,1,'admin')";
|
||||
$resp = $this->get_sp($sql, [$headerID]);
|
||||
foreach ($resp["data"] as $d) {
|
||||
$d["M_LangID"] = 1;
|
||||
$new_data[] = $d;
|
||||
}
|
||||
$resp["data"] = $new_data;
|
||||
} elseif ($sp == "sp_dummy_fisik") {
|
||||
$arr_sub_url = [
|
||||
"pribadi",
|
||||
"keluhan_saat_ini_new",
|
||||
"riwayat_phobia",
|
||||
"riwayat_obat",
|
||||
"riwayat_penyakit",
|
||||
"riwayat_hidup",
|
||||
"riwayat_keluarga",
|
||||
"tanda_vital",
|
||||
"status_gizi",
|
||||
"keadaan_umum",
|
||||
"mulut",
|
||||
"gigi",
|
||||
"visus",
|
||||
"kepala_wajah",
|
||||
"mata",
|
||||
"telinga",
|
||||
"thorax",
|
||||
"paru",
|
||||
"jantung",
|
||||
"integumen",
|
||||
"sistem",
|
||||
"anggota",
|
||||
"genitourinaria",
|
||||
"perut",
|
||||
"leher",
|
||||
"hidung",
|
||||
"persepsi_warna",
|
||||
];
|
||||
$resultEntryID = $this->get_so_result_entry_id(
|
||||
$headerID,
|
||||
"fisik"
|
||||
);
|
||||
$new_data = ["fisik" => [], "riwayat" => []];
|
||||
if ($resultEntryID > 0) {
|
||||
foreach ($arr_sub_url as $s_url) {
|
||||
$new_data["fisik"][$s_url] = $this->get_fisik(
|
||||
$s_url,
|
||||
$resultEntryID,
|
||||
"fisik"
|
||||
);
|
||||
$new_data["riwayat"][$s_url] = $this->get_fisik(
|
||||
$s_url,
|
||||
$resultEntryID,
|
||||
"riwayat"
|
||||
);
|
||||
}
|
||||
}
|
||||
$resp = ["data" => $new_data, "status" => 0];
|
||||
} else {
|
||||
$resp = $this->get_sp($sql, [$headerID]);
|
||||
}
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz("Err $sp : " . $resp["message"]);
|
||||
exit();
|
||||
}
|
||||
$result[$key] = $resp["data"];
|
||||
}
|
||||
echo $this->reply_gz(
|
||||
json_encode(["status" => "OK", "result" => $result])
|
||||
);
|
||||
}
|
||||
function get_fisik($param, $result_entry_id, $type, $lang_id = 1)
|
||||
{
|
||||
$url = "http://localhost/one-api/v1/report/fisik/$param/$result_entry_id/$lang_id/$type";
|
||||
$resp = $this->get($url);
|
||||
return json_decode($resp, true);
|
||||
}
|
||||
function get($url, $timeout = 60, $c_timeout = 5)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
return json_encode(["status" => "ERR", "message" => $err_msg]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
function get_sp($sql, $param = false)
|
||||
{
|
||||
$resp = $this->get_rows($sql, $param);
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
return $resp;
|
||||
}
|
||||
function get_mou($companyID)
|
||||
{
|
||||
$sql = "select M_MouID,M_MouName, M_MouNumber
|
||||
from m_mou
|
||||
where M_MouIsActive = 'Y' and M_MouM_CompanyID = ?";
|
||||
$resp = $this->get_rows($sql, [$companyID]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply("Error Get MOU by Company $companyID");
|
||||
exit();
|
||||
}
|
||||
echo json_encode([
|
||||
"status" => "OK",
|
||||
"data" => $resp["data"],
|
||||
]);
|
||||
}
|
||||
function step_debug($rows)
|
||||
{
|
||||
print_r($rows);
|
||||
exit();
|
||||
}
|
||||
function get_rows($sql, $param = false)
|
||||
{
|
||||
if ($param) {
|
||||
$qry = $this->db->query($sql, $param);
|
||||
} else {
|
||||
$qry = $this->db->query($sql);
|
||||
}
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => -1,
|
||||
"message" =>
|
||||
$this->db->last_query() .
|
||||
"|" .
|
||||
$this->db->error()["message"],
|
||||
];
|
||||
}
|
||||
return ["status" => 0, "data" => $qry->result_array()];
|
||||
}
|
||||
function get_row($sql, $param = false)
|
||||
{
|
||||
$resp = $this->get_rows($sql, $param);
|
||||
if ($resp["status"] == -1) {
|
||||
return $resp;
|
||||
}
|
||||
if (count($resp["data"]) == 0) {
|
||||
return ["status" => 0, "message" => "Not found."];
|
||||
}
|
||||
return ["status" => 1, "data" => $resp["data"][0]];
|
||||
}
|
||||
}
|
||||
?>
|
||||
31
application/controllers/cpone/Patient.http
Normal file
31
application/controllers/cpone/Patient.http
Normal file
@@ -0,0 +1,31 @@
|
||||
POST https://{{host}}/cpone/patient/index
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/cpone/patient/generate_adm_patient
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
"date": "2023-07-11",
|
||||
"corporateID": 46
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/cpone/patient/insert_patient
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
"patientoldID": "0001170402882"
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/cpone/patient/patientloop
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
377
application/controllers/cpone/Patient.php
Normal file
377
application/controllers/cpone/Patient.php
Normal file
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
class Patient extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// $this->db = $this->load->database("cpone", true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "PATIENT GENERATE ADM API";
|
||||
}
|
||||
|
||||
public function generate_adm_patient()
|
||||
{
|
||||
try {
|
||||
// $this->db->trans_begin();
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
//$date = $prm['date'];
|
||||
|
||||
$sql = "SELECT
|
||||
REG_DATE,
|
||||
REG_NO,
|
||||
PATIENT_ID,
|
||||
PATIENT_NAME,
|
||||
SEX_ID,
|
||||
DOB,
|
||||
AGE,
|
||||
NPK,
|
||||
JOB_TITLE,
|
||||
DEPT,
|
||||
DIVISION,
|
||||
LOCATION,
|
||||
AGREEMENT_NAME,
|
||||
OTHER_ID
|
||||
FROM x_adm_rekap_patient
|
||||
WHERE STAGE = '20'";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select adm rekap patient error", $this->db);
|
||||
}
|
||||
|
||||
// print_r($rows);
|
||||
// exit;
|
||||
$count_m_patient = 1;
|
||||
$insert_query = [];
|
||||
foreach ($rows as $key => $value) {
|
||||
|
||||
// print_r($value['PATIENT_ID']);
|
||||
// exit;
|
||||
$timestamp = strtotime($value['DOB']);
|
||||
$pdob = date('Y-m-d', $timestamp);
|
||||
$p_name = addslashes($value['PATIENT_NAME']);
|
||||
$sql_check = "SELECT
|
||||
M_PatientID,
|
||||
M_PatientOldPID,
|
||||
M_PatientName
|
||||
FROM m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND
|
||||
(
|
||||
( M_PatientName = '{$p_name}' AND M_PatientDOB = '{$pdob}' AND '{$value['OTHER_ID']}' = '') OR
|
||||
('{$value['NPK']}' <> '' AND M_PatientNIP = '{$value['NPK']}' AND M_PatientDOB = M_PatientDOB = '{$pdob}' ) OR
|
||||
('{$value['OTHER_ID']}' <> '' AND M_PatientDOB = '{$pdob}' AND trim(M_PatientIdentifierValue) = '{$value['OTHER_ID']}')
|
||||
) ";
|
||||
$qry_check = $this->db->query($sql_check);
|
||||
|
||||
|
||||
if ($qry_check) {
|
||||
$rows_check = $qry_check->result_array();
|
||||
} else {
|
||||
/* $this->db->trans_rollback();
|
||||
$this->sys_error_db("select check patient error", $this->db);
|
||||
exit;*/
|
||||
}
|
||||
|
||||
// print_r(count($rows_check));
|
||||
// exit;
|
||||
|
||||
$title_id = 0;
|
||||
$gender = "";
|
||||
if (TRIM($value['SEX_ID']) == 'M') {
|
||||
$title_id = 1;
|
||||
$gender = "male";
|
||||
} else {
|
||||
$title_id = 3;
|
||||
$gender = "female";
|
||||
}
|
||||
|
||||
if (count($rows_check) == 0) {
|
||||
// print_r("insert");
|
||||
// exit;
|
||||
$p_name = addslashes($value['PATIENT_NAME']);
|
||||
$sql_insert = "INSERT INTO m_patient(
|
||||
M_PatientRegisteredByCorporateID,
|
||||
M_PatientOldPID,
|
||||
M_PatientNoReg,
|
||||
M_PatientM_TitleID,
|
||||
M_PatientName,
|
||||
M_PatientGender,
|
||||
M_PatientDOB,
|
||||
M_PatientNIP,
|
||||
M_PatientJob,
|
||||
M_PatientDivisi,
|
||||
M_PatientLocation,
|
||||
M_PatientDepartement,
|
||||
M_PatientCreated,
|
||||
M_PatientLastUpdated
|
||||
) VALUES(
|
||||
50,
|
||||
'{$value['PATIENT_ID']}',
|
||||
`fn_numbering_cpone`('P'),
|
||||
{$title_id},
|
||||
'{$p_name}',
|
||||
'{$gender}',
|
||||
'{$pdob}',
|
||||
'{$value['NPK']}',
|
||||
'{$value['JOB_TITLE']}',
|
||||
'{$value['DIVISION']}',
|
||||
'{$value['LOCATION']}',
|
||||
'{$value['DEPT']}',
|
||||
NOW(),
|
||||
NOW()
|
||||
)";
|
||||
$qry_insert = $this->db->query($sql_insert);
|
||||
$insert_query [] = $this->db->last_query();
|
||||
|
||||
/*if (!$qry_insert) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("insert m_patient error", $this->db);
|
||||
exit;
|
||||
}*/
|
||||
$count_m_patient = $count_m_patient +1;
|
||||
} else {
|
||||
$sql_select = "SELECT X_PatientM_PatientID,
|
||||
X_PatientM_PatientOldPID
|
||||
FROM x_patient
|
||||
WHERE X_PatientM_PatientID = {$rows_check[0]['M_PatientID']}";
|
||||
$qry_select = $this->db->query($sql_select);
|
||||
if ($qry_select) {
|
||||
$rows = $qry_select->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select x_patient", $this->db);
|
||||
}
|
||||
|
||||
|
||||
if (count($rows) == 0) {
|
||||
$sql = "UPDATE m_patient SET M_PatientOldPID = '{$value['PATIENT_ID']}'
|
||||
WHERE M_PatientID = {$rows_check[0]['M_PatientID']} ";
|
||||
$this->db->query($sql);
|
||||
if ($rows_check[0]['M_PatientOldPID'] == "") {
|
||||
$sql = "INSERT INTO x_patient(
|
||||
X_PatientM_PatientID,
|
||||
X_PatientM_PatientOldPID,
|
||||
X_PatientCreated) VALUES(
|
||||
'{$rows_check[0]['M_PatientID']}',
|
||||
'{$value['PATIENT_ID']}',
|
||||
NOW()
|
||||
)";
|
||||
$qry = $this->db->query($sql);
|
||||
/*if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("insert m_patient error", $this->db);
|
||||
exit;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//$this->db->trans_commit();
|
||||
$result = array(
|
||||
"message" => "Pasien berhasil ditambahkan sebanyak ".$count_m_patient,
|
||||
"affected_rows" => $this->db->affected_rows(),
|
||||
"sql_insert"=> JOIN(";",$insert_query)
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
/* function patientloop()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$patientoldID = $prm['patientoldID'];
|
||||
$sql = "select *
|
||||
from x_adm_rekap_patient";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$this->insert_patient($value['PATIENT_ID']);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
"message" => "Selesai"
|
||||
]);
|
||||
} */
|
||||
|
||||
public function insert_patient()
|
||||
{
|
||||
try {
|
||||
|
||||
//$this->db->trans_begin();
|
||||
|
||||
$sql_adm = "SELECT REG_DATE,
|
||||
REG_NO,
|
||||
PATIENT_ID,
|
||||
PATIENT_NAME,
|
||||
AGE,
|
||||
top_patient.M_PatientID as m_patient_id
|
||||
FROM x_adm_rekap_patient
|
||||
JOIN m_patient as top_patient ON PATIENT_ID = top_patient.M_PatientOldPID
|
||||
WHERE
|
||||
STAGE = '20'";
|
||||
$qry_adm = $this->db->query($sql_adm);
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry_adm) {
|
||||
//$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db('select x_adm_rekap_patient error', $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry_adm->result_array();
|
||||
//print_r($rows);
|
||||
// exit;
|
||||
$count_order = 1;
|
||||
foreach ($rows as $key => $row_adm) {
|
||||
$sql_check_order = "SELECT
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderOldLabNumber,
|
||||
T_OrderHeaderM_PatientID
|
||||
FROM x_t_orderheader
|
||||
WHERE T_OrderHeaderIsActive = 'Y'
|
||||
AND T_OrderHeaderOldLabNumber = ?";
|
||||
$qry_check_order = $this->db->query($sql_check_order, array(
|
||||
$row_adm['REG_NO']
|
||||
));
|
||||
// echo $this->db->last_query();
|
||||
if ($qry_check_order) {
|
||||
$rows_check_order = $qry_check_order->result_array();
|
||||
} else {
|
||||
//$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("select check t_orderheader", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$reg_date = $row_adm['REG_DATE'];
|
||||
$full_date = $reg_date . ' 12:00:00';
|
||||
|
||||
if (count($rows_check_order) == 0) {
|
||||
// print_r('belum ada');
|
||||
// exit;
|
||||
|
||||
$sql_insert_order = "INSERT INTO x_t_orderheader(
|
||||
T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderOldLabNumber,
|
||||
T_OrderHeaderM_PatientID,
|
||||
T_OrderHeaderCorporateID,
|
||||
T_OrderHeaderMgm_McuID,
|
||||
T_OrderHeaderM_PatientAge,
|
||||
T_OrderHeaderCreated,
|
||||
T_OrderHeaderLastUpdated) VALUES(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
now(),
|
||||
now())";
|
||||
$qry_insert_order = $this->db->query($sql_insert_order, array(
|
||||
$full_date,
|
||||
$row_adm['REG_NO'],
|
||||
$row_adm['REG_NO'],
|
||||
$row_adm['m_patient_id'],
|
||||
77,
|
||||
0,
|
||||
$row_adm['AGE']
|
||||
));
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry_insert_order) {
|
||||
//$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("insert t_orderheader error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$count_order = $count_order + 1;
|
||||
$insertid = $this->db->insert_id();
|
||||
|
||||
$sql_select_testid = "SELECT
|
||||
name,
|
||||
name_v,
|
||||
test_id
|
||||
FROM x_map_lab";
|
||||
$qry_select_testid = $this->db->query($sql_select_testid);
|
||||
//echo $this->db->last_query();
|
||||
if ($qry_select_testid) {
|
||||
$rows_test = $qry_select_testid->result_array();
|
||||
} else {
|
||||
//$this->db->trans_rollback;
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("select x_map_lab", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// print_r($rows_test);
|
||||
// exit;
|
||||
foreach ($rows_test as $key => $value) {
|
||||
// print_r($value);
|
||||
// exit;
|
||||
$sql_insert_detail = "insert into x_t_orderdetail (
|
||||
T_OrderDetailT_OrderHeaderID,
|
||||
T_OrderDetailT_TestID,
|
||||
T_OrderDetailT_TestCode,
|
||||
T_OrderDetailT_TestSasCode,
|
||||
T_OrderDetailT_TestName,
|
||||
T_OrderDetailT_TestIsResult,
|
||||
T_OrderDetailT_TestIsPrice )
|
||||
SELECT
|
||||
?,
|
||||
T_TestID,
|
||||
T_TestCode,
|
||||
T_TestSasCode,
|
||||
T_TestName,
|
||||
T_TestIsResult,
|
||||
T_TestIsPrice
|
||||
FROM t_test
|
||||
WHERE T_TestID in (?)";
|
||||
$qry_insert_detail = $this->db->query($sql_insert_detail, array(
|
||||
$insertid,
|
||||
$value['test_id']
|
||||
));
|
||||
//echo $this->db->last_query();
|
||||
// exit;
|
||||
if (!$qry_insert_detail) {
|
||||
// $this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db('insert t_orderdetail error', $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//$this->db->trans_commit();
|
||||
$result = array(
|
||||
"message" => "Berhasil",
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
368
application/controllers/cpone/Patient.php-minusnpk
Normal file
368
application/controllers/cpone/Patient.php-minusnpk
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
class Patient extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// $this->db = $this->load->database("cpone", true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "PATIENT GENERATE ADM API";
|
||||
}
|
||||
|
||||
public function generate_adm_patient()
|
||||
{
|
||||
try {
|
||||
// $this->db->trans_begin();
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
//$date = $prm['date'];
|
||||
|
||||
$sql = "SELECT
|
||||
REG_DATE,
|
||||
REG_NO,
|
||||
PATIENT_ID,
|
||||
PATIENT_NAME,
|
||||
SEX_ID,
|
||||
DOB,
|
||||
AGE,
|
||||
NPK,
|
||||
JOB_TITLE,
|
||||
DEPT,
|
||||
DIVISION,
|
||||
LOCATION,
|
||||
AGREEMENT_NAME
|
||||
FROM x_adm_rekap_patient
|
||||
WHERE STAGE = '3'";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select adm rekap patient error", $this->db);
|
||||
}
|
||||
|
||||
// print_r($rows);
|
||||
// exit;
|
||||
$count_m_patient = 1;
|
||||
foreach ($rows as $key => $value) {
|
||||
|
||||
// print_r($value['PATIENT_ID']);
|
||||
// exit;
|
||||
$timestamp = strtotime($value['DOB']);
|
||||
$pdob = date('Y-m-d', $timestamp);
|
||||
$p_name = addslashes($value['PATIENT_NAME']);
|
||||
$sql_check = "SELECT
|
||||
M_PatientID,
|
||||
M_PatientOldPID,
|
||||
M_PatientName
|
||||
FROM m_patient
|
||||
WHERE M_PatientIsActive = 'Y'
|
||||
AND M_PatientName = '{$p_name}'
|
||||
AND M_PatientDOB = '{$pdob}'
|
||||
AND M_PatientNIP = '{$value['NPK']}'";
|
||||
$qry_check = $this->db->query($sql_check);
|
||||
|
||||
if ($qry_check) {
|
||||
$rows_check = $qry_check->result_array();
|
||||
} else {
|
||||
/* $this->db->trans_rollback();
|
||||
$this->sys_error_db("select check patient error", $this->db);
|
||||
exit;*/
|
||||
}
|
||||
|
||||
// print_r(count($rows_check));
|
||||
// exit;
|
||||
|
||||
$title_id = 0;
|
||||
$gender = "";
|
||||
if (TRIM($value['SEX_ID']) == 'M') {
|
||||
$title_id = 1;
|
||||
$gender = "male";
|
||||
} else {
|
||||
$title_id = 3;
|
||||
$gender = "female";
|
||||
}
|
||||
|
||||
if (count($rows_check) == 0) {
|
||||
// print_r("insert");
|
||||
// exit;
|
||||
$p_name = addslashes($value['PATIENT_NAME']);
|
||||
$sql_insert = "INSERT INTO m_patient(
|
||||
M_PatientRegisteredByCorporateID,
|
||||
M_PatientOldPID,
|
||||
M_PatientNoReg,
|
||||
M_PatientM_TitleID,
|
||||
M_PatientName,
|
||||
M_PatientGender,
|
||||
M_PatientDOB,
|
||||
M_PatientNIP,
|
||||
M_PatientJob,
|
||||
M_PatientDivisi,
|
||||
M_PatientLocation,
|
||||
M_PatientDepartement,
|
||||
M_PatientCreated,
|
||||
M_PatientLastUpdated
|
||||
) VALUES(
|
||||
50,
|
||||
'{$value['PATIENT_ID']}',
|
||||
`fn_numbering_cpone`('P'),
|
||||
{$title_id},
|
||||
'{$p_name}',
|
||||
'{$gender}',
|
||||
'{$pdob}',
|
||||
'{$value['NPK']}',
|
||||
'{$value['JOB_TITLE']}',
|
||||
'{$value['DIVISION']}',
|
||||
'{$value['LOCATION']}',
|
||||
'{$value['DEPT']}',
|
||||
NOW(),
|
||||
NOW()
|
||||
)";
|
||||
$qry_insert = $this->db->query($sql_insert);
|
||||
//echo $this->db->last_query();
|
||||
/*if (!$qry_insert) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("insert m_patient error", $this->db);
|
||||
exit;
|
||||
}*/
|
||||
$count_m_patient = $count_m_patient +1;
|
||||
} else {
|
||||
$sql_select = "SELECT X_PatientM_PatientID,
|
||||
X_PatientM_PatientOldPID
|
||||
FROM x_patient
|
||||
WHERE X_PatientM_PatientID = {$rows_check[0]['M_PatientID']}";
|
||||
$qry_select = $this->db->query($sql_select);
|
||||
if ($qry_select) {
|
||||
$rows = $qry_select->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select x_patient", $this->db);
|
||||
}
|
||||
|
||||
|
||||
if (count($rows) == 0) {
|
||||
$sql = "UPDATE m_patient SET M_PatientOldPID = '{$value['PATIENT_ID']}'
|
||||
WHERE M_PatientID = {$rows_check[0]['M_PatientID']} ";
|
||||
$this->db->query($sql);
|
||||
if ($rows_check[0]['M_PatientOldPID'] == "") {
|
||||
$sql = "INSERT INTO x_patient(
|
||||
X_PatientM_PatientID,
|
||||
X_PatientM_PatientOldPID,
|
||||
X_PatientCreated) VALUES(
|
||||
'{$rows_check[0]['M_PatientID']}',
|
||||
'{$value['PATIENT_ID']}',
|
||||
NOW()
|
||||
)";
|
||||
$qry = $this->db->query($sql);
|
||||
/*if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("insert m_patient error", $this->db);
|
||||
exit;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//$this->db->trans_commit();
|
||||
$result = array(
|
||||
"message" => "Pasien berhasil ditambahkan sebanyak ".$count_m_patient,
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function patientloop()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$patientoldID = $prm['patientoldID'];
|
||||
$sql = "select *
|
||||
from x_adm_rekap_patient";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$this->insert_patient($value['PATIENT_ID']);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
"message" => "Selesai"
|
||||
]);
|
||||
}
|
||||
|
||||
public function insert_patient()
|
||||
{
|
||||
try {
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$sql_adm = "SELECT REG_DATE,
|
||||
REG_NO,
|
||||
PATIENT_ID,
|
||||
PATIENT_NAME,
|
||||
AGE,
|
||||
top_patient.M_PatientID as m_patient_id
|
||||
FROM x_adm_rekap_patient
|
||||
JOIN m_patient as top_patient ON PATIENT_ID = top_patient.M_PatientOldPID
|
||||
WHERE
|
||||
STAGE = '2'";
|
||||
$qry_adm = $this->db->query($sql_adm);
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry_adm) {
|
||||
$this->db->trans_rollback();
|
||||
//echo $this->db->last_query();
|
||||
$this->sys_error_db('select x_adm_rekap_patient error', $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry_adm->result_array();
|
||||
//print_r($rows);
|
||||
// exit;
|
||||
foreach ($rows as $key => $row_adm) {
|
||||
$sql_check_order = "SELECT
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderOldLabNumber,
|
||||
T_OrderHeaderM_PatientID
|
||||
FROM x_t_orderheader
|
||||
WHERE T_OrderHeaderIsActive = 'Y'
|
||||
AND T_OrderHeaderOldLabNumber = ?";
|
||||
$qry_check_order = $this->db->query($sql_check_order, array(
|
||||
$row_adm['REG_NO']
|
||||
));
|
||||
// echo $this->db->last_query();
|
||||
if ($qry_check_order) {
|
||||
$rows_check_order = $qry_check_order->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
//echo $this->db->last_query();
|
||||
$this->sys_error_db("select check t_orderheader", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$reg_date = $row_adm['REG_DATE'];
|
||||
$full_date = $reg_date . ' 12:00:00';
|
||||
|
||||
if (count($rows_check_order) == 0) {
|
||||
// print_r('belum ada');
|
||||
// exit;
|
||||
|
||||
$sql_insert_order = "INSERT INTO x_t_orderheader(
|
||||
T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderOldLabNumber,
|
||||
T_OrderHeaderM_PatientID,
|
||||
T_OrderHeaderCorporateID,
|
||||
T_OrderHeaderMgm_McuID,
|
||||
T_OrderHeaderM_PatientAge,
|
||||
T_OrderHeaderCreated,
|
||||
T_OrderHeaderLastUpdated) VALUES(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
now(),
|
||||
now())";
|
||||
$qry_insert_order = $this->db->query($sql_insert_order, array(
|
||||
$full_date,
|
||||
$row_adm['REG_NO'],
|
||||
$row_adm['REG_NO'],
|
||||
$row_adm['m_patient_id'],
|
||||
50,
|
||||
0,
|
||||
$row_adm['AGE']
|
||||
));
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry_insert_order) {
|
||||
$this->db->trans_rollback();
|
||||
//echo $this->db->last_query();
|
||||
$this->sys_error_db("insert t_orderheader error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$insertid = $this->db->insert_id();
|
||||
|
||||
$sql_select_testid = "SELECT
|
||||
name,
|
||||
name_v,
|
||||
test_id
|
||||
FROM x_map_lab";
|
||||
$qry_select_testid = $this->db->query($sql_select_testid);
|
||||
//echo $this->db->last_query();
|
||||
if ($qry_select_testid) {
|
||||
$rows_test = $qry_select_testid->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback;
|
||||
//echo $this->db->last_query();
|
||||
$this->sys_error_db("select x_map_lab", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// print_r($rows_test);
|
||||
// exit;
|
||||
foreach ($rows_test as $key => $value) {
|
||||
// print_r($value);
|
||||
// exit;
|
||||
$sql_insert_detail = "insert into x_t_orderdetail (
|
||||
T_OrderDetailT_OrderHeaderID,
|
||||
T_OrderDetailT_TestID,
|
||||
T_OrderDetailT_TestCode,
|
||||
T_OrderDetailT_TestSasCode,
|
||||
T_OrderDetailT_TestName,
|
||||
T_OrderDetailT_TestIsResult,
|
||||
T_OrderDetailT_TestIsPrice )
|
||||
SELECT
|
||||
?,
|
||||
T_TestID,
|
||||
T_TestCode,
|
||||
T_TestSasCode,
|
||||
T_TestName,
|
||||
T_TestIsResult,
|
||||
T_TestIsPrice
|
||||
FROM t_test
|
||||
WHERE T_TestID in (?)";
|
||||
$qry_insert_detail = $this->db->query($sql_insert_detail, array(
|
||||
$insertid,
|
||||
$value['test_id']
|
||||
));
|
||||
//echo $this->db->last_query();
|
||||
// exit;
|
||||
if (!$qry_insert_detail) {
|
||||
$this->db->trans_rollback();
|
||||
// echo $this->db->last_query();
|
||||
$this->sys_error_db('insert t_orderdetail error', $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"message" => "Berhasil",
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
application/controllers/cpone/Result.http
Normal file
35
application/controllers/cpone/Result.http
Normal file
@@ -0,0 +1,35 @@
|
||||
POST https://{{host}}/cpone/result/index
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/cpone/result/get_branch
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI3IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMSIsIk1fU3RhZmZOYW1lIjpudWxsLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxMzkuMTkyLjE3My42MiIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyNS4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA2LTA2IDE2OjQ3OjAwIn0.5S84dVOQbpET7_L7vN-DZMr2uSWuhsxPZYtq-HvzKkI"
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/cpone/result/search
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
"date": "2024-03-08",
|
||||
"branchCode": "W001",
|
||||
"search": "",
|
||||
"current_page": 1,
|
||||
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI3IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMSIsIk1fU3RhZmZOYW1lIjpudWxsLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxMzkuMTkyLjE3My42MiIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyNS4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA2LTA2IDE2OjQ3OjAwIn0.5S84dVOQbpET7_L7vN-DZMr2uSWuhsxPZYtq-HvzKkI"
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/cpone/result/getlistlogapi
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
"resultID": 23,
|
||||
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI3IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMSIsIk1fU3RhZmZOYW1lIjpudWxsLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxMzkuMTkyLjE3My42MiIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyNS4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA2LTA2IDE2OjQ3OjAwIn0.5S84dVOQbpET7_L7vN-DZMr2uSWuhsxPZYtq-HvzKkI"
|
||||
}
|
||||
169
application/controllers/cpone/Result.php
Normal file
169
application/controllers/cpone/Result.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
class Result extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// $this->db = $this->load->database("cpone", true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "RESULT API";
|
||||
}
|
||||
|
||||
function get_branch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "SELECT M_BranchID as branchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
M_BranchAddress
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("branch select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
}
|
||||
$test_name = "";
|
||||
if (isset($prm['test_name'])) {
|
||||
$test_name = trim($prm["test_name"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_tot = "SELECT COUNT(*) AS total FROM(
|
||||
SELECT api_result.*, IF(Nat_TestName IS NULL, 'Belum Mapping', Nat_TestName) AS Nat_TestName
|
||||
FROM api_result
|
||||
LEFT JOIN nat_testmap ON Nat_TestMapCode = api_ResultTestCode
|
||||
LEFT JOIN nat_test ON Nat_TestMapNat_TestID = Nat_TestID
|
||||
WHERE `api_ResultNolab` = ? AND (`api_ResultTestName` LIKE CONCAT('%', ?, '%') OR api_ResultTestCode LIKE CONCAT('%', ?, '%'))
|
||||
) x";
|
||||
$qry_tot = $this->db->query($sql_tot, [ $search, $test_name, $test_name]);
|
||||
//echo $this->db->last_query();
|
||||
//exit;
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_tot) {
|
||||
$tot_count = $qry_tot->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("result count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT api_result.*, IF(Nat_TestName IS NULL, 'Belum Mapping', Nat_TestName) AS Nat_TestName, IF(Nat_TestCode IS NULL, '', Nat_TestCode) AS Nat_TestCode
|
||||
FROM api_result
|
||||
LEFT JOIN nat_testmap ON Nat_TestMapCode = api_ResultTestCode
|
||||
LEFT JOIN nat_test ON Nat_TestMapNat_TestID = Nat_TestID
|
||||
WHERE `api_ResultNolab` = ? AND (`api_ResultTestName` LIKE CONCAT('%', ?, '%') OR api_ResultTestCode LIKE CONCAT('%', ?, '%'))
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [ $search, $test_name, $test_name,$number_limit, $number_offset]);
|
||||
//echo $this->db->last_query();
|
||||
//exit;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select result error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getlistlogapi()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
$resultID = $prm["resultID"];
|
||||
|
||||
$sql = "SELECT log_ApiID,
|
||||
log_ApiDate,
|
||||
log_ApiM_BranchCode,
|
||||
log_ApiEndpoint,
|
||||
log_ApiParam,
|
||||
log_ApiResponse,
|
||||
log_ApiType,
|
||||
log_ApiIsParsed
|
||||
FROM cpone_log.log_api
|
||||
JOIN api_result ON log_ApiID = api_ResultLog_ApiID
|
||||
WHERE api_ResultID = ?";
|
||||
$qry = $this->db->query($sql, [$resultID]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select log_api error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$rows[$key]["log_ApiParam"] = json_encode(json_decode($value["log_ApiParam"]), JSON_PRETTY_PRINT);
|
||||
}
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
169
application/controllers/cpone/Result.php--050325
Normal file
169
application/controllers/cpone/Result.php--050325
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
class Result extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// $this->db = $this->load->database("cpone", true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "RESULT API";
|
||||
}
|
||||
|
||||
function get_branch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "SELECT M_BranchID as branchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
M_BranchAddress
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("branch select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
}
|
||||
$test_name = "";
|
||||
if (isset($prm['test_name'])) {
|
||||
$test_name = trim($prm["test_name"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_tot = "SELECT COUNT(*) AS total FROM(
|
||||
SELECT api_result.*, IF(Nat_TestName IS NULL, 'Belum Mapping', Nat_TestName) AS Nat_TestName
|
||||
FROM api_result
|
||||
LEFT JOIN nat_testmap ON Nat_TestMapCode = api_ResultTestCode
|
||||
LEFT JOIN nat_test ON Nat_TestMapNat_TestID = Nat_TestID
|
||||
WHERE `api_ResultNolab` = ? AND (`api_ResultTestName` LIKE CONCAT('%', ?, '%') OR api_ResultTestCode LIKE CONCAT('%', ?, '%'))
|
||||
) x";
|
||||
$qry_tot = $this->db->query($sql_tot, [ $search, $test_name, $test_name]);
|
||||
//echo $this->db->last_query();
|
||||
//exit;
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_tot) {
|
||||
$tot_count = $qry_tot->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("result count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT api_result.*, IF(Nat_TestName IS NULL, 'Belum Mapping', Nat_TestName) AS Nat_TestName
|
||||
FROM api_result
|
||||
LEFT JOIN nat_testmap ON Nat_TestMapCode = api_ResultTestCode
|
||||
LEFT JOIN nat_test ON Nat_TestMapNat_TestID = Nat_TestID
|
||||
WHERE `api_ResultNolab` = ? AND (`api_ResultTestName` LIKE CONCAT('%', ?, '%') OR api_ResultTestCode LIKE CONCAT('%', ?, '%'))
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [ $search, $test_name, $test_name,$number_limit, $number_offset]);
|
||||
//echo $this->db->last_query();
|
||||
//exit;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select result error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getlistlogapi()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
$resultID = $prm["resultID"];
|
||||
|
||||
$sql = "SELECT log_ApiID,
|
||||
log_ApiDate,
|
||||
log_ApiM_BranchCode,
|
||||
log_ApiEndpoint,
|
||||
log_ApiParam,
|
||||
log_ApiResponse,
|
||||
log_ApiType,
|
||||
log_ApiIsParsed
|
||||
FROM cpone_log.log_api
|
||||
JOIN api_result ON log_ApiID = api_ResultLog_ApiID
|
||||
WHERE api_ResultID = ?";
|
||||
$qry = $this->db->query($sql, [$resultID]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select log_api error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$rows[$key]["log_ApiParam"] = json_encode(json_decode($value["log_ApiParam"]), JSON_PRETTY_PRINT);
|
||||
}
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
2907
application/controllers/cpone/inject/Corporate.php
Normal file
2907
application/controllers/cpone/inject/Corporate.php
Normal file
File diff suppressed because it is too large
Load Diff
2907
application/controllers/cpone/inject/Preregisterv2.php
Normal file
2907
application/controllers/cpone/inject/Preregisterv2.php
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user