Initial import
This commit is contained in:
195
application/controllers/tools/regonline/Carousel_upload.php
Normal file
195
application/controllers/tools/regonline/Carousel_upload.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
class Carousel_upload extends MY_Controller
|
||||
{
|
||||
var $url;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//$this->url= "https://devregonline.pramita.co.id/one-api/tools/regonline/r_carousel";
|
||||
$this->url= "https://mobile.pramita.co.id/one-api/tools/regonline/r_carousel";
|
||||
}
|
||||
function step_debug($rows)
|
||||
{
|
||||
print_r($rows);
|
||||
exit();
|
||||
}
|
||||
function index() {
|
||||
$branchCode = $this->get_branch();
|
||||
$date = $this->get_heartbeat();
|
||||
$sql = "select max(M_CarouselLastUpdated) LastUpdated, max(M_CarouselCreated) LastCreated
|
||||
from m_carousel";
|
||||
$qry = $this->db->query($sql,[$date]);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->log("No Carousel updated");
|
||||
exit;
|
||||
}
|
||||
if ($rows[0]["LastUpdated"] < $date && $rows[0]["LastCreated"] < $date) {
|
||||
$this->log("No Carousel updated or created neeed to be uploaded");
|
||||
exit;
|
||||
}
|
||||
$sql = "select M_CarouselID, M_CarouselImageUrl, ifnull(M_CarouselOrder,0) M_CarouselOrder
|
||||
from m_carousel where M_CarouselIsActive='Y' and M_CarouselStatus = 'Y'
|
||||
order by M_CarouselOrder, M_CarouselID ";
|
||||
|
||||
$qry = $this->db->query($sql,[$date]);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$data = [];
|
||||
$counter_data =0;
|
||||
$all_name = "";
|
||||
$arr_real_name = [];
|
||||
foreach($rows as $r) {
|
||||
$order = $r["M_CarouselOrder"];
|
||||
$id = $r["M_CarouselID"];
|
||||
$name = sprintf("%02d",$order) . "-" . sprintf("%03d",$id) . "-" . $r["M_CarouselImageUrl"];
|
||||
$real_name = "/home/one/project/one/one-media/one-regonline/" . $r["M_CarouselImageUrl"];
|
||||
if(! file_exists($real_name)) {
|
||||
$this->log("File $real_name not exits");
|
||||
} else {
|
||||
$all_name .= $name;
|
||||
$data[] = array(
|
||||
"name" => $name,
|
||||
"branchCode" => $branchCode,
|
||||
"content" => base64_encode(file_get_contents($real_name))
|
||||
);
|
||||
$counter_data++;
|
||||
$arr_real_name[] = $real_name;
|
||||
}
|
||||
}
|
||||
if ($counter_data == 0) {
|
||||
$this->log("No Carousel to upload");
|
||||
exit;
|
||||
}
|
||||
$msg = "Uploaded {$counter_data} image.";
|
||||
$j_data = json_encode(array(
|
||||
"data" => $data,
|
||||
"md5" => md5($all_name . $branchCode . "545123")
|
||||
));
|
||||
$j_resp = $this->post($this->url, $j_data);
|
||||
$resp = json_decode($j_resp,true);
|
||||
$json_error = json_last_error_msg();
|
||||
if (json_last_error() != 0) {
|
||||
$msg .= " [JSON ERR] $json_error " ;
|
||||
}
|
||||
if($resp["status"] == "OK") {
|
||||
$msg .= " [Success] ";
|
||||
$this->update_heartbeat("OK","");
|
||||
} else {
|
||||
$msg .= " [ERR] " ;
|
||||
if($resp["message"] != "") $msg .= " " . $resp["message"];
|
||||
$this->update_heartbeat("ERR",$msg);
|
||||
}
|
||||
$this->log($msg);
|
||||
$this->log("Uploaded files : " . implode(", ", $arr_real_name));
|
||||
}
|
||||
function log($msg) {
|
||||
$date = date("Y-m-d H:i:s");
|
||||
echo "$date $msg\n";
|
||||
}
|
||||
function get_branch() {
|
||||
$sql = "select M_BranchCode from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows) == 0) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : No Default branch" .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
return $rows[0]["M_BranchCode"];
|
||||
}
|
||||
function get_heartbeat() {
|
||||
|
||||
$sql="select * from regonline.heartbeat where heartbeatCode='CAROUSEL'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$sql = "insert into regonline.heartbeat(heartbeatCode,heartbeatStatus,heartbeatExecuted,heartbeatMessage)
|
||||
values('CAROUSEL','OK','1971-01-01 00:00:01','')";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
return "1971-01-01 00:00:01";
|
||||
}
|
||||
return $rows[0]["heartbeatExecuted"];
|
||||
}
|
||||
function update_heartbeat( $status, $msg)
|
||||
{
|
||||
$type = "CAROUSEL";
|
||||
if ($status == "OK") {
|
||||
$sql = "update regonline.heartbeat set heartbeatExecuted = now(), heartbeatStatus = ? , heartbeatMessage = ?
|
||||
where heartbeatCode = ?";
|
||||
$qry = $this->db->query($sql, array($status, $msg, $type));
|
||||
} else {
|
||||
$sql = "update regonline.heartbeat set heartbeatStatus = ? , heartbeatMessage = ?
|
||||
where heartbeatCode = ?";
|
||||
$qry = $this->db->query($sql, array($status, $msg, $type));
|
||||
}
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " \t Error $type : {$this->db->error()['message']}\n";
|
||||
}
|
||||
}
|
||||
|
||||
function post($url, $data, $timeout = 60, $c_timeout = 5)
|
||||
{
|
||||
$zdata = gzcompress($data);
|
||||
$this->log("Upload to $url : " . ( round(strlen($zdata) / 1024) ) . " kB");
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $zdata);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/octet",
|
||||
"Content-Length: " . strlen($zdata),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
return json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => $err_msg,
|
||||
"url" => $url,
|
||||
"data" => json_decode($data, true),
|
||||
]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
2004
application/controllers/tools/regonline/Download.php
Normal file
2004
application/controllers/tools/regonline/Download.php
Normal file
File diff suppressed because it is too large
Load Diff
150
application/controllers/tools/regonline/Download_sync_branch.php
Normal file
150
application/controllers/tools/regonline/Download_sync_branch.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
class Download_sync_branch extends MY_Controller
|
||||
{
|
||||
function __contruct()
|
||||
{
|
||||
parent::__contruct();
|
||||
}
|
||||
|
||||
function get_branch()
|
||||
{
|
||||
$sql =
|
||||
"select M_BranchCode from m_branch where M_BranchIsDefault='Y' and M_BranchIsActive ='Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"Error Get Default Branch | " .
|
||||
$this->db->error()["message"] .
|
||||
"\n" .
|
||||
$this->db->last_query()
|
||||
);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows) == 0) {
|
||||
$this->log(
|
||||
"Error No Default Branch "
|
||||
);
|
||||
exit();
|
||||
}
|
||||
return $rows[0]["M_BranchCode"];
|
||||
}
|
||||
// curl -o data.gz http://bandungraya.aplikasi.web.id/one-api/pramitalabku/sync
|
||||
function index()
|
||||
{
|
||||
//download nasional data
|
||||
// php /home/one/project/one/one-api/index.php pramitalabku download_sync
|
||||
$this->log("Start Download from Nasional");
|
||||
$url = "http://bandungraya.aplikasi.web.id/one-api/pramitalabku/sync_branch";
|
||||
$branchCode = $this->get_branch();
|
||||
$jdata = $this->post(
|
||||
$url,
|
||||
json_encode(["branchCode" => $branchCode ])
|
||||
);
|
||||
$resp = json_decode($jdata, true);
|
||||
if ($resp["status"] != "OK") {
|
||||
$this->log($resp["message"]);
|
||||
exit();
|
||||
}
|
||||
foreach ($resp["data"] as $table => $rows) {
|
||||
switch ($table) {
|
||||
case "t_subcategory":
|
||||
$keys = ["T_SubCategoryID"];
|
||||
break;
|
||||
case "t_subcategory_test":
|
||||
$keys = ["T_SubcategoryTestID"];
|
||||
break;
|
||||
default:
|
||||
$this->log("Table $table not configured yet!");
|
||||
exit();
|
||||
}
|
||||
$tot_insert = 0;
|
||||
$tot_update = 0;
|
||||
foreach ($rows as $r) {
|
||||
$state = $this->insert_or_update($table, $r, $keys);
|
||||
if ($state == "U") {
|
||||
$tot_update++;
|
||||
} else {
|
||||
$tot_insert++;
|
||||
}
|
||||
}
|
||||
$tot_rows = $tot_insert + $tot_update;
|
||||
$this->log(
|
||||
"$table , $tot_insert inserted / $tot_update updated total : $tot_rows"
|
||||
);
|
||||
}
|
||||
}
|
||||
function post($url, $data, $timeout = 60, $c_timeout = 5)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
$this->log("Err Post " . $err_msg);
|
||||
exit();
|
||||
}
|
||||
return gzuncompress($result);
|
||||
}
|
||||
|
||||
function insert_or_update($table, $data, $key)
|
||||
{
|
||||
$s_where = "";
|
||||
foreach ($key as $k) {
|
||||
if ($s_where != "") {
|
||||
$_where .= " and ";
|
||||
}
|
||||
$s_where .= " $k = '" . $data[$k] . "' ";
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$sql = "select " . $key[0] . " from $table " . " where $s_where ";
|
||||
$qry = $this->db->query($sql, $key);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"Error Insert/Update $table Check | " .
|
||||
$this->db->error()["message"] .
|
||||
"\n" .
|
||||
$this->db->last_query()
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
foreach ($key as $k) {
|
||||
$this->db->where($k, $data[$k]);
|
||||
}
|
||||
$qry = $this->db->update($table, $data);
|
||||
$state = "U";
|
||||
} else {
|
||||
$qry = $this->db->insert($table, $data);
|
||||
$state = "I";
|
||||
}
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"Error Insert/Update $table | " .
|
||||
$this->db->error()["message"] .
|
||||
"\n" .
|
||||
$this->db->last_query()
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
return $state;
|
||||
}
|
||||
|
||||
function log($message)
|
||||
{
|
||||
echo date("Y-m-d H:i:s ") . $message . "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
2119
application/controllers/tools/regonline/Download_v2.php
Normal file
2119
application/controllers/tools/regonline/Download_v2.php
Normal file
File diff suppressed because it is too large
Load Diff
516
application/controllers/tools/regonline/Heartbeat-prod.php
Normal file
516
application/controllers/tools/regonline/Heartbeat-prod.php
Normal file
@@ -0,0 +1,516 @@
|
||||
<?php
|
||||
class Heartbeat extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->url_heartbeat = "https://regonline.pramita.co.id/one-api/tools/regonline/r_heartbeat";
|
||||
}
|
||||
function get_sel_px()
|
||||
{
|
||||
$sql = "select M_MouID from m_mou where M_MouIsActive = 'Y'
|
||||
and M_MouIsOnline = 'Y' and M_MouIsReleased = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err GET SEL PX: " . $this->db->error()["message"] . "\n";
|
||||
return "0";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$mou_ids = "0";
|
||||
foreach ($rows as $r) {
|
||||
$mou_ids .= "," . $r["M_MouID"];
|
||||
}
|
||||
$sql = "select T_TestID
|
||||
from
|
||||
ss_price_mou
|
||||
where Ss_PriceMouM_MouID in ( $mou_ids )
|
||||
and is_packet = 'N'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err Ss PriceMou Test : " . $this->db->error()["message"] . "\n";
|
||||
return "0";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = "0";
|
||||
foreach ($rows as $r) {
|
||||
$result .= "," . $r["T_TestID"];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
function get_order($date)
|
||||
{
|
||||
if ($date == "") {
|
||||
$date = date("Y-m-d 00:00:01");
|
||||
}
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
$px_ids = $this->get_sel_px();
|
||||
$sql = "select T_OrderHeaderID branch_OrderT_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber branch_OrderT_OrderHeaderLabNumber,
|
||||
$branchID branch_OrderM_BranchID,
|
||||
'$branchCode' branch_OrderM_BranchCode,
|
||||
T_OrderHeaderDate branch_OrderT_OrderHeaderDate,
|
||||
T_OrderDetailT_TestID branch_OrderT_TestID,
|
||||
T_OrderDetailT_TestName branch_OrderT_TestName,
|
||||
datediff(T_OrderPromiseDateTime, T_OrderHeaderDate) branch_OrderCitoInDay,
|
||||
T_OrderDetailIsActive branch_OrderIsActive,
|
||||
T_OrderDetailValidation branch_OrderValidation
|
||||
from t_orderheader
|
||||
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderAddOnFoVerification = 'Y'
|
||||
and T_OrderHeaderAddOnLabNumberOrigin is null
|
||||
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailLastUpdated >= ?
|
||||
and date(T_OrderHeaderDate) >= date(?)
|
||||
and T_OrderDetailT_TestID in ( $px_ids )
|
||||
join t_orderpromise on T_OrderDetailT_OrderPromiseID = T_OrderPromiseID";
|
||||
$qry = $this->db->query($sql, array($date, $date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err : " . $this->db->error()["message"] . "\n";
|
||||
return array("type" => "ORDER_BRANCH", "data" => []);
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return array("type" => "ORDER_BRANCH", "data" => $rows);
|
||||
}
|
||||
function now()
|
||||
{
|
||||
return Date("Y-m-d H:i:s");
|
||||
}
|
||||
function get_price($date = "")
|
||||
{
|
||||
// check the upload konfirmasion
|
||||
$sql = "select count(*) total
|
||||
from s_regonline_upload
|
||||
where S_RegOnlineUploadIsSent = 'N' and S_RegOnlineUploadIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$tot_reqonline_upload = 0;
|
||||
if (count($rows) > 0) {
|
||||
$tot_reqonline_upload = $rows[0]["total"];
|
||||
}
|
||||
if ($tot_reqonline_upload == 0) {
|
||||
echo "{$this->now()} ERR : No Upload Confirmation \n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$sql = "update s_regonline_upload set S_RegOnlineUploadIsSent = 'Y',
|
||||
S_RegOnlineUploadSentDate = now()
|
||||
where S_RegOnlineUploadIsSent = 'N' ";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
|
||||
$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";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
//Online Released MOU
|
||||
$sql = "select * from m_mou where
|
||||
M_MouIsReleased='Y' and
|
||||
M_MouIsOnline='Y'
|
||||
order by M_MouID desc";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Online Released MOU not found\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$mou = $rows[0];
|
||||
$mouID = $mou["M_MouID"];
|
||||
|
||||
//SsPrice MOU
|
||||
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mou["M_MouID"]));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Ss Price MOU not found\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$ss_price_mou = $rows;
|
||||
|
||||
//Working
|
||||
$sql = "select $branchID M_RegPacketWorkM_BranchID,
|
||||
m_reg_packetwork.*, T_PacketName
|
||||
from m_reg_packetwork
|
||||
join t_packet on M_RegPacketWorkT_PacketID = T_PacketID
|
||||
where M_RegPacketWorkIsActive = 'Y'
|
||||
and M_RegPacketWorkM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_working = array();
|
||||
foreach ($rows as $r) {
|
||||
$arr_working[ strtolower($r["T_PacketName"])] = true;
|
||||
}
|
||||
|
||||
$sql = "select $branchID M_RegPacketWorkM_BranchID,
|
||||
m_reg_packetwork.*
|
||||
from m_reg_packetwork
|
||||
join t_packet on M_RegPacketWorkT_PacketID = T_PacketID
|
||||
and M_RegPacketWorkM_MouID=?
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_working = $qry->result_array();
|
||||
|
||||
//Sale
|
||||
$sql = "select $branchID M_RegPacketSaleM_BranchID,
|
||||
m_reg_packetsale.* , T_PacketName
|
||||
from m_reg_packetsale
|
||||
join t_packet on M_RegPacketSaleT_PacketID = T_PacketID
|
||||
where M_RegPacketSaleIsActive = 'Y'
|
||||
and M_RegPacketSaleM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_sell = array();
|
||||
$sale_ids = "0";
|
||||
foreach ($rows as $r) {
|
||||
$arr_sell[ strtolower($r["T_PacketName"]) ] = true;
|
||||
$sale_ids .= "," . $r["M_RegPacketSaleID"];
|
||||
}
|
||||
$sql = "select $branchID M_RegPacketSaleOptionM_BranchID,
|
||||
m_reg_packetsaleoption.*
|
||||
from m_reg_packetsaleoption
|
||||
where M_RegPacketSaleOptionM_RegPacketSaleID in ( $sale_ids )
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_sell_option = $qry->result_array();
|
||||
$sql = "select $branchID M_RegPacketSaleM_BranchID,
|
||||
m_reg_packetsale.*
|
||||
from m_reg_packetsale
|
||||
join t_packet on M_RegPacketSaleT_PacketID = T_PacketID
|
||||
and M_RegPacketSaleM_MouID=?
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_sell = $qry->result_array();
|
||||
|
||||
$s_packet = "-1";
|
||||
foreach ($ss_price_mou as $idx => $r) {
|
||||
$ss_price_mou[$idx]["Ss_PriceMouM_BranchID"] = $branchID;
|
||||
$is_sell = "N";
|
||||
$is_work = "N";
|
||||
$packetName = strtolower($r["T_TestName"]);
|
||||
$packetID = $r["packet_id"];
|
||||
if ($packetID > 0) {
|
||||
if (isset($arr_working[$packetName])) $is_work = "Y";
|
||||
if (isset($arr_sell[$packetName])) $is_sell = "Y";
|
||||
}
|
||||
$ss_price_mou[$idx]["Ss_PriceMouIsSell"] = $is_sell;
|
||||
$ss_price_mou[$idx]["Ss_PriceMouIsWork"] = $is_work;
|
||||
$s_packet .= "," . $packetID;
|
||||
}
|
||||
$sql = "select $branchID T_PacketM_BranchID, t_packet.*
|
||||
from t_packet where T_PacketID in ( $s_packet) ";
|
||||
// and T_PacketLastUpdated >= ? ";
|
||||
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$packets = $qry->result_array();
|
||||
|
||||
$sql = "select $branchID T_PacketDetailM_BranchID, t_packetdetail.*
|
||||
from t_packetdetail
|
||||
where T_PacketDetailT_PacketID in ( $s_packet) and T_PacketDetailIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$packet_details = $qry->result_array();
|
||||
|
||||
$data = array(
|
||||
"ss_price_mou" => $ss_price_mou,
|
||||
"packet" => $packets,
|
||||
"working" => $reg_working,
|
||||
"sell" => $reg_sell,
|
||||
"sell_option" => $reg_sell_option,
|
||||
"detail" => $packet_details
|
||||
);
|
||||
return array("type" => "PRICE_PACKET", "data" => $data);
|
||||
}
|
||||
function index()
|
||||
{
|
||||
$this->process();
|
||||
}
|
||||
function process($addhoc_date = "")
|
||||
{
|
||||
$sql = "select * from regonline.heartbeat";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$heartbeat = array();
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $r) {
|
||||
$heartbeat[$r["heartbeatCode"]] = $r["heartbeatExecuted"];
|
||||
if ($addhoc_date != "") {
|
||||
$heartbeat[$r["heartbeatCode"]] = "$addhoc_date 00:00:01";
|
||||
}
|
||||
}
|
||||
|
||||
//Ping
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
$ping_param = array("type" => "PING", "data" => array("branchID" => $branchID, "branchCode" => $branchCode));
|
||||
//SWAB Schedule
|
||||
$swab_param = $this->upload_swab($heartbeat["SWAB"]);
|
||||
//QUOTA PCR
|
||||
$quota_param = $this->upload_kuota($heartbeat["QUOTA_PCR"]);
|
||||
|
||||
//ORDER BRANCH
|
||||
$order_branch_param = $this->get_order($heartbeat["ORDER_BRANCH"]);
|
||||
|
||||
$price_packet_param = $this->get_price($heartbeat["PRICE_PACKET"]);
|
||||
//do the heartbeat
|
||||
echo date("Y-m-d H:i:s") . " Start HeartBeat to : {$this->url_heartbeat}\n";
|
||||
$data = array(
|
||||
$ping_param, $swab_param, $quota_param, $order_branch_param,
|
||||
$price_packet_param
|
||||
);
|
||||
$md5 = md5(json_encode($data));
|
||||
$z_param = gzdeflate(json_encode(array(
|
||||
"md5" => $md5,
|
||||
"data" => $data
|
||||
)), 9);
|
||||
|
||||
$response = $this->post($this->url_heartbeat, $z_param);
|
||||
$j_response = json_decode($response, true);
|
||||
if (!$j_response) {
|
||||
echo date("Y-m-d H:i:s") . " End HeartBeat : Error Json : $response\n";
|
||||
exit;
|
||||
}
|
||||
if ($j_response["status"] == "ERR") {
|
||||
echo date("Y-m-d H:i:s") . " End HeartBeat : Error : {$j_response['message']}\n";
|
||||
exit;
|
||||
}
|
||||
foreach ($j_response["result"] as $type => $rst) {
|
||||
$msg = "";
|
||||
if (isset($rst["message"])) $msg = $rst["message"];
|
||||
$status = $rst["status"];
|
||||
$this->update_heartbeat($type, $status, $msg);
|
||||
echo date("Y-m-d H:i:s") . " \t $type : $status : $msg \n";
|
||||
}
|
||||
}
|
||||
function update_heartbeat($type, $status, $msg)
|
||||
{
|
||||
//jika tidak OK executed tidak di set
|
||||
if ($status == "OK") {
|
||||
$sql = "update regonline.heartbeat set heartbeatExecuted = now(), heartbeatStatus = ? , heartbeatMessage = ?
|
||||
where heartbeatCode = ?";
|
||||
$qry = $this->db->query($sql, array($status, $msg, $type));
|
||||
} else {
|
||||
$sql = "update regonline.heartbeat set heartbeatStatus = ? , heartbeatMessage = ?
|
||||
where heartbeatCode = ?";
|
||||
$qry = $this->db->query($sql, array($status, $msg, $type));
|
||||
}
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " \t Error $type : {$this->db->error()['message']}\n";
|
||||
}
|
||||
}
|
||||
function upload_kuota($date)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
if ($date == "") $date = "2020-01-01 00:00:00";
|
||||
$sql = "select m_reg_kuota.*, $branchID M_RegKuotaM_BranchID, '$branchCode' M_RegKuotaM_BranchCode
|
||||
from m_reg_kuota where M_RegKuotaLastUpdated > ?";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Error Kuota : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$kuota = $qry->result_array();
|
||||
$sql = "select m_reg_kuota_log.*, $branchID M_RegKuotaLogM_BranchID, '$branchCode' M_RegKuotaLogM_BranchCode
|
||||
from m_reg_kuota_log where M_RegKuotaLogLastUpdated > ?";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Error Kuota Log : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$log = $qry->result_array();
|
||||
$param = array("type" => "QUOTA_PCR", "data" => array("kuota" => $kuota, "log" => $log));
|
||||
return $param;
|
||||
}
|
||||
|
||||
function upload_swab($date)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
if ($date == "") $date = "2020-01-01 00:00:00";
|
||||
$sql = "select m_reg_schedule.*, $branchID M_RegScheduleM_BranchID, '$branchCode' M_RegScheduleM_BranchCode
|
||||
from m_reg_schedule where M_RegScheduleIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Error Schedule : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$schedule = $qry->result_array();
|
||||
$sql = "select m_reg_scheduledetail.*, $branchID M_RegScheduleDetailM_BranchID, '$branchCode' M_RegScheduleDetailM_BranchCode
|
||||
from m_reg_scheduledetail where M_RegScheduleDetailIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Error Schedule : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$detail = $qry->result_array();
|
||||
$param = array("type" => "SWAB", "data" => array("schedule" => $schedule, "detail" => $detail));
|
||||
return $param;
|
||||
}
|
||||
function get_mou()
|
||||
{
|
||||
$sql = "select S_SystemIPAddressRegional from conf_systems";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) return $rows[0]["S_SystemIPAddressRegional"];
|
||||
}
|
||||
function do_insert($table, $r)
|
||||
{
|
||||
$qry = $this->db->insert($table, $r);
|
||||
if (!$qry) echo $this->db->error()["message"] . " \n";
|
||||
}
|
||||
function do_update($table, $id, $r)
|
||||
{
|
||||
$this->db->set($r);
|
||||
$this->db->where($id, $r[$id]);
|
||||
$qry = $this->db->update($table);
|
||||
if (!$qry) echo $this->db->error()["message"] . " \n";
|
||||
}
|
||||
function exists($table, $id, $val)
|
||||
{
|
||||
$sql = "select count(*) total from {$table} where {$id} = ? ";
|
||||
$qry = $this->db->query($sql, array($val));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return $rows[0]["total"] > 0;
|
||||
}
|
||||
function update_mou($mou)
|
||||
{
|
||||
foreach ($mou as $m) {
|
||||
$mouID = $m["selMouID"];
|
||||
if ($this->exists("regonline.sel_mou", "selMouID", $mouID)) {
|
||||
$this->do_update("regonline.sel_mou", "selMouID", $m);
|
||||
} else {
|
||||
$this->do_insert("regonline.sel_mou", $m);
|
||||
}
|
||||
}
|
||||
}
|
||||
function update_px($px)
|
||||
{
|
||||
foreach ($px as $r) {
|
||||
$pxID = $r["selPxID"];
|
||||
if ($this->exists("regonline.sel_px", "selPxID", $pxID)) {
|
||||
$this->do_update("regonline.sel_px", "selPxID", $r);
|
||||
} else {
|
||||
$this->do_insert("regonline.sel_px", $r);
|
||||
}
|
||||
}
|
||||
}
|
||||
function getBranch()
|
||||
{
|
||||
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err Get Branch: " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo date("Y-m-d H:i:s") . " Err Get Branch: " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
return array($rows[0]["M_BranchID"], $rows[0]["M_BranchCode"]);
|
||||
}
|
||||
function getRegionalIP()
|
||||
{
|
||||
$sql = "select S_SystemIPAddressRegional from conf_systems";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) return $rows[0]["S_SystemIPAddressRegional"];
|
||||
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
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(array("status" => "ERR", "message" => $err_msg));
|
||||
}
|
||||
return gzinflate($result);
|
||||
}
|
||||
function post($url, $data, $timeout = 60, $c_timeout = 5)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($data)
|
||||
));
|
||||
$result = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
return json_encode(array("status" => "ERR", "message" => $err_msg,
|
||||
"url" => $url, "data" => json_decode($data,true)));
|
||||
}
|
||||
return gzinflate($result);
|
||||
}
|
||||
}
|
||||
687
application/controllers/tools/regonline/Heartbeat.php
Normal file
687
application/controllers/tools/regonline/Heartbeat.php
Normal file
@@ -0,0 +1,687 @@
|
||||
<?php
|
||||
class Heartbeat extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->url_heartbeat = "https://regonline.pramita.co.id/one-api/tools/regonline/r_heartbeat";
|
||||
}
|
||||
function get_sel_px()
|
||||
{
|
||||
$sql = "select M_MouID from m_mou where M_MouIsActive = 'Y'
|
||||
and M_MouIsOnline = 'Y' and M_MouIsReleased = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err GET SEL PX: " . $this->db->error()["message"] . "\n";
|
||||
return "0";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$mou_ids = "0";
|
||||
foreach ($rows as $r) {
|
||||
$mou_ids .= "," . $r["M_MouID"];
|
||||
}
|
||||
$sql = "select T_TestID
|
||||
from
|
||||
ss_price_mou
|
||||
where Ss_PriceMouM_MouID in ( $mou_ids )
|
||||
and is_packet = 'N'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err Ss PriceMou Test : " . $this->db->error()["message"] . "\n";
|
||||
return "0";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = "0";
|
||||
foreach ($rows as $r) {
|
||||
$result .= "," . $r["T_TestID"];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
function get_order($date)
|
||||
{
|
||||
if ($date == "") {
|
||||
$date = date("Y-m-d 00:00:01");
|
||||
}
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
$px_ids = $this->get_sel_px();
|
||||
$sql = "select T_OrderHeaderID branch_OrderT_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber branch_OrderT_OrderHeaderLabNumber,
|
||||
$branchID branch_OrderM_BranchID,
|
||||
'$branchCode' branch_OrderM_BranchCode,
|
||||
T_OrderHeaderDate branch_OrderT_OrderHeaderDate,
|
||||
T_OrderDetailT_TestID branch_OrderT_TestID,
|
||||
T_OrderDetailT_TestName branch_OrderT_TestName,
|
||||
datediff(T_OrderPromiseDateTime, T_OrderHeaderDate) branch_OrderCitoInDay,
|
||||
T_OrderDetailIsActive branch_OrderIsActive,
|
||||
T_OrderDetailValidation branch_OrderValidation
|
||||
from t_orderheader
|
||||
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderAddOnFoVerification = 'Y'
|
||||
and T_OrderHeaderAddOnLabNumberOrigin is null
|
||||
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailLastUpdated >= ?
|
||||
and date(T_OrderHeaderDate) >= date(?)
|
||||
and T_OrderDetailT_TestID in ( $px_ids )
|
||||
join t_orderpromise on T_OrderDetailT_OrderPromiseID = T_OrderPromiseID";
|
||||
$qry = $this->db->query($sql, array($date, $date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err : " . $this->db->error()["message"] . "\n";
|
||||
return array("type" => "ORDER_BRANCH", "data" => []);
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return array("type" => "ORDER_BRANCH", "data" => $rows);
|
||||
}
|
||||
function now()
|
||||
{
|
||||
return Date("Y-m-d H:i:s");
|
||||
}
|
||||
|
||||
function get_price_debug() {
|
||||
$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";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
//Online Released MOU
|
||||
$sql = "select * from m_mou where
|
||||
M_MouIsReleased='Y' and
|
||||
M_MouIsOnline='Y'
|
||||
order by M_MouID desc";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Online Released MOU not found\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$mou = $rows[0];
|
||||
$mouID = $mou["M_MouID"];
|
||||
|
||||
//SsPrice MOU
|
||||
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mou["M_MouID"]));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Ss Price MOU not found\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$ss_price_mou = $rows;
|
||||
|
||||
//Working
|
||||
$sql = "select $branchID M_RegPacketWorkM_BranchID,
|
||||
m_reg_packetwork.*, T_PacketName
|
||||
from m_reg_packetwork
|
||||
join t_packet on M_RegPacketWorkT_PacketID = T_PacketID
|
||||
where M_RegPacketWorkIsActive = 'Y'
|
||||
and M_RegPacketWorkM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_working = array();
|
||||
foreach ($rows as $r) {
|
||||
$arr_working[ strtolower($r["T_PacketName"])] = true;
|
||||
}
|
||||
|
||||
$sql = "select $branchID M_RegPacketWorkM_BranchID,
|
||||
m_reg_packetwork.*
|
||||
from m_reg_packetwork
|
||||
join t_packet on M_RegPacketWorkT_PacketID = T_PacketID
|
||||
and M_RegPacketWorkM_MouID=?
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR; : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_working = $qry->result_array();
|
||||
|
||||
//Sale
|
||||
$sql = "select $branchID M_RegPacketSaleM_BranchID,
|
||||
m_reg_packetsale.* , T_PacketName
|
||||
from m_reg_packetsale
|
||||
join t_packet on M_RegPacketSaleT_PacketID = T_PacketID
|
||||
where M_RegPacketSaleIsActive = 'Y'
|
||||
and M_RegPacketSaleM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_sell = array();
|
||||
$sale_ids = "0";
|
||||
foreach ($rows as $r) {
|
||||
$arr_sell[ strtolower($r["T_PacketName"]) ] = true;
|
||||
$sale_ids .= "," . $r["M_RegPacketSaleID"];
|
||||
}
|
||||
$sql = "select $branchID M_RegPacketSaleOptionM_BranchID,
|
||||
m_reg_packetsaleoption.*
|
||||
from m_reg_packetsaleoption
|
||||
where M_RegPacketSaleOptionM_RegPacketSaleID in ( $sale_ids )
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_sell_option = $qry->result_array();
|
||||
$sql = "select $branchID M_RegPacketSaleM_BranchID,
|
||||
m_reg_packetsale.*
|
||||
from m_reg_packetsale
|
||||
join t_packet on M_RegPacketSaleT_PacketID = T_PacketID
|
||||
and M_RegPacketSaleM_MouID=?
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_sell = $qry->result_array();
|
||||
|
||||
$s_packet = "-1";
|
||||
foreach ($ss_price_mou as $idx => $r) {
|
||||
$ss_price_mou[$idx]["Ss_PriceMouM_BranchID"] = $branchID;
|
||||
$is_sell = "N";
|
||||
$is_work = "N";
|
||||
$packetName = strtolower($r["T_TestName"]);
|
||||
$packetID = $r["packet_id"];
|
||||
//echo "----|" . $packetName . "|----| $packetID \n" ;
|
||||
if ($packetID > 0) {
|
||||
if (isset($arr_working[$packetName])) $is_work = "Y";
|
||||
if (isset($arr_sell[$packetName])) $is_sell = "Y";
|
||||
}
|
||||
$ss_price_mou[$idx]["Ss_PriceMouIsSell"] = $is_sell;
|
||||
$ss_price_mou[$idx]["Ss_PriceMouIsWork"] = $is_work;
|
||||
$s_packet .= "," . $packetID;
|
||||
}
|
||||
$sql = "select $branchID T_PacketM_BranchID, t_packet.*
|
||||
from t_packet where T_PacketID in ( $s_packet) ";
|
||||
// and T_PacketLastUpdated >= ? ";
|
||||
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$packets = $qry->result_array();
|
||||
|
||||
$sql = "select $branchID T_PacketDetailM_BranchID, t_packetdetail.*
|
||||
from t_packetdetail
|
||||
where T_PacketDetailT_PacketID in ( $s_packet) and T_PacketDetailIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$packet_details = $qry->result_array();
|
||||
|
||||
$data = array(
|
||||
"ss_price_mou" => $ss_price_mou,
|
||||
"packet" => $packets,
|
||||
"working" => $reg_working,
|
||||
"sell" => $reg_sell,
|
||||
"sell_option" => $reg_sell_option,
|
||||
"detail" => $packet_details
|
||||
);
|
||||
//print_r($ss_price_mou);
|
||||
|
||||
}
|
||||
function get_price($date = "")
|
||||
{
|
||||
// check the upload konfirmasion
|
||||
$sql = "select count(*) total
|
||||
from s_regonline_upload
|
||||
where S_RegOnlineUploadIsSent = 'N' and S_RegOnlineUploadIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$tot_reqonline_upload = 0;
|
||||
if (count($rows) > 0) {
|
||||
$tot_reqonline_upload = $rows[0]["total"];
|
||||
}
|
||||
if ($tot_reqonline_upload == 0) {
|
||||
echo "{$this->now()} ERR : No Upload Confirmation \n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$sql = "update s_regonline_upload set S_RegOnlineUploadIsSent = 'Y',
|
||||
S_RegOnlineUploadSentDate = now()
|
||||
where S_RegOnlineUploadIsSent = 'N' ";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
|
||||
$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";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
//Online Released MOU
|
||||
$sql = "select * from m_mou where
|
||||
M_MouIsReleased='Y' and
|
||||
M_MouIsOnline='Y'
|
||||
order by M_MouID desc";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Online Released MOU not found\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$mou = $rows[0];
|
||||
$mouID = $mou["M_MouID"];
|
||||
|
||||
//SsPrice MOU
|
||||
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mou["M_MouID"]));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Ss Price MOU not found\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$ss_price_mou = $rows;
|
||||
|
||||
//Working
|
||||
$sql = "select $branchID M_RegPacketWorkM_BranchID,
|
||||
m_reg_packetwork.*, T_PacketName
|
||||
from m_reg_packetwork
|
||||
join t_packet on M_RegPacketWorkT_PacketID = T_PacketID
|
||||
where M_RegPacketWorkIsActive = 'Y'
|
||||
and M_RegPacketWorkM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_working = array();
|
||||
foreach ($rows as $r) {
|
||||
$arr_working[ trim(strtolower($r["T_PacketName"])) ] = true;
|
||||
}
|
||||
|
||||
$sql = "select $branchID M_RegPacketWorkM_BranchID,
|
||||
m_reg_packetwork.*
|
||||
from m_reg_packetwork
|
||||
join t_packet on M_RegPacketWorkT_PacketID = T_PacketID
|
||||
and M_RegPacketWorkM_MouID=?
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_working = $qry->result_array();
|
||||
|
||||
//Sale
|
||||
$sql = "select $branchID M_RegPacketSaleM_BranchID,
|
||||
m_reg_packetsale.* , T_PacketName
|
||||
from m_reg_packetsale
|
||||
join t_packet on M_RegPacketSaleT_PacketID = T_PacketID
|
||||
where M_RegPacketSaleIsActive = 'Y'
|
||||
and M_RegPacketSaleM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_sell = array();
|
||||
$sale_ids = "0";
|
||||
foreach ($rows as $r) {
|
||||
$arr_sell[ trim(strtolower($r["T_PacketName"])) ] = true;
|
||||
$sale_ids .= "," . $r["M_RegPacketSaleID"];
|
||||
}
|
||||
|
||||
$sql = "select $branchID M_RegPacketSaleOptionM_BranchID,
|
||||
m_reg_packetsaleoption.*
|
||||
from m_reg_packetsaleoption
|
||||
where M_RegPacketSaleOptionM_RegPacketSaleID in ( $sale_ids )
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_sell_option = $qry->result_array();
|
||||
$sql = "select $branchID M_RegPacketSaleM_BranchID,
|
||||
m_reg_packetsale.*
|
||||
from m_reg_packetsale
|
||||
join t_packet on M_RegPacketSaleT_PacketID = T_PacketID
|
||||
and M_RegPacketSaleM_MouID=?
|
||||
";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$reg_sell = $qry->result_array();
|
||||
|
||||
$s_packet = "-1";
|
||||
foreach ($ss_price_mou as $idx => $r) {
|
||||
$ss_price_mou[$idx]["Ss_PriceMouM_BranchID"] = $branchID;
|
||||
$is_sell = "N";
|
||||
$is_work = "N";
|
||||
$packetName = trim(strtolower($r["T_TestName"]));
|
||||
$packetID = $r["packet_id"];
|
||||
|
||||
if ($packetID > 0) {
|
||||
if (isset($arr_working[$packetName])) $is_work = "Y";
|
||||
if (isset($arr_sell[$packetName])) $is_sell = "Y";
|
||||
}
|
||||
$ss_price_mou[$idx]["Ss_PriceMouIsSell"] = $is_sell;
|
||||
$ss_price_mou[$idx]["Ss_PriceMouIsWork"] = $is_work;
|
||||
$s_packet .= "," . $packetID;
|
||||
}
|
||||
$sql = "select $branchID T_PacketM_BranchID, t_packet.*
|
||||
from t_packet where T_PacketID in ( $s_packet) ";
|
||||
// and T_PacketLastUpdated >= ? ";
|
||||
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$packets = $qry->result_array();
|
||||
|
||||
$sql = "select $branchID T_PacketDetailM_BranchID, t_packetdetail.*
|
||||
from t_packetdetail
|
||||
where T_PacketDetailT_PacketID in ( $s_packet) and T_PacketDetailIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n";
|
||||
return array("type" => "ERR_PRICE_PACKET", "data" => array());
|
||||
}
|
||||
$packet_details = $qry->result_array();
|
||||
|
||||
$data = array(
|
||||
"ss_price_mou" => $ss_price_mou,
|
||||
"packet" => $packets,
|
||||
"working" => $reg_working,
|
||||
"sell" => $reg_sell,
|
||||
"sell_option" => $reg_sell_option,
|
||||
"detail" => $packet_details
|
||||
);
|
||||
return array("type" => "PRICE_PACKET", "data" => $data);
|
||||
}
|
||||
function index()
|
||||
{
|
||||
$this->process();
|
||||
}
|
||||
function process($addhoc_date = "")
|
||||
{
|
||||
$sql = "select * from regonline.heartbeat";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$heartbeat = array();
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $r) {
|
||||
$heartbeat[$r["heartbeatCode"]] = $r["heartbeatExecuted"];
|
||||
if ($addhoc_date != "") {
|
||||
$heartbeat[$r["heartbeatCode"]] = "$addhoc_date 00:00:01";
|
||||
}
|
||||
}
|
||||
|
||||
//Ping
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
$ping_param = array("type" => "PING", "data" => array("branchID" => $branchID, "branchCode" => $branchCode));
|
||||
//SWAB Schedule
|
||||
$swab_param = $this->upload_swab($heartbeat["SWAB"]);
|
||||
//QUOTA PCR
|
||||
$quota_param = $this->upload_kuota($heartbeat["QUOTA_PCR"]);
|
||||
|
||||
//ORDER BRANCH
|
||||
$order_branch_param = $this->get_order($heartbeat["ORDER_BRANCH"]);
|
||||
|
||||
$price_packet_param = $this->get_price($heartbeat["PRICE_PACKET"]);
|
||||
//do the heartbeat
|
||||
echo date("Y-m-d H:i:s") . " Start HeartBeat to : {$this->url_heartbeat}\n";
|
||||
$data = array(
|
||||
$ping_param, $swab_param, $quota_param, $order_branch_param,
|
||||
$price_packet_param
|
||||
);
|
||||
$md5 = md5(json_encode($data));
|
||||
$z_param = gzdeflate(json_encode(array(
|
||||
"md5" => $md5,
|
||||
"data" => $data
|
||||
)), 9);
|
||||
|
||||
$response = $this->post($this->url_heartbeat, $z_param);
|
||||
$j_response = json_decode($response, true);
|
||||
if (!$j_response) {
|
||||
echo date("Y-m-d H:i:s") . " End HeartBeat : Error Json : $response\n";
|
||||
exit;
|
||||
}
|
||||
if ($j_response["status"] == "ERR") {
|
||||
echo date("Y-m-d H:i:s") . " End HeartBeat : Error : {$j_response['message']}\n";
|
||||
exit;
|
||||
}
|
||||
foreach ($j_response["result"] as $type => $rst) {
|
||||
$msg = "";
|
||||
if (isset($rst["message"])) $msg = $rst["message"];
|
||||
$status = $rst["status"];
|
||||
$this->update_heartbeat($type, $status, $msg);
|
||||
echo date("Y-m-d H:i:s") . " \t $type : $status : $msg \n";
|
||||
}
|
||||
}
|
||||
function update_heartbeat($type, $status, $msg)
|
||||
{
|
||||
//jika tidak OK executed tidak di set
|
||||
if ($status == "OK") {
|
||||
$sql = "update regonline.heartbeat set heartbeatExecuted = now(), heartbeatStatus = ? , heartbeatMessage = ?
|
||||
where heartbeatCode = ?";
|
||||
$qry = $this->db->query($sql, array($status, $msg, $type));
|
||||
} else {
|
||||
$sql = "update regonline.heartbeat set heartbeatStatus = ? , heartbeatMessage = ?
|
||||
where heartbeatCode = ?";
|
||||
$qry = $this->db->query($sql, array($status, $msg, $type));
|
||||
}
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " \t Error $type : {$this->db->error()['message']}\n";
|
||||
}
|
||||
}
|
||||
function upload_kuota($date)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
if ($date == "") $date = "2020-01-01 00:00:00";
|
||||
$sql = "select m_reg_kuota.*, $branchID M_RegKuotaM_BranchID, '$branchCode' M_RegKuotaM_BranchCode
|
||||
from m_reg_kuota where M_RegKuotaLastUpdated > ?";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Error Kuota : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$kuota = $qry->result_array();
|
||||
$sql = "select m_reg_kuota_log.*, $branchID M_RegKuotaLogM_BranchID, '$branchCode' M_RegKuotaLogM_BranchCode
|
||||
from m_reg_kuota_log where M_RegKuotaLogLastUpdated > ?";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Error Kuota Log : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$log = $qry->result_array();
|
||||
$param = array("type" => "QUOTA_PCR", "data" => array("kuota" => $kuota, "log" => $log));
|
||||
return $param;
|
||||
}
|
||||
|
||||
function upload_swab($date)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
if ($date == "") $date = "2020-01-01 00:00:00";
|
||||
$sql = "select m_reg_schedule.*, $branchID M_RegScheduleM_BranchID, '$branchCode' M_RegScheduleM_BranchCode
|
||||
from m_reg_schedule where M_RegScheduleIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Error Schedule : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$schedule = $qry->result_array();
|
||||
$sql = "select m_reg_scheduledetail.*, $branchID M_RegScheduleDetailM_BranchID, '$branchCode' M_RegScheduleDetailM_BranchCode
|
||||
from m_reg_scheduledetail where M_RegScheduleDetailIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Error Schedule : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$detail = $qry->result_array();
|
||||
$param = array("type" => "SWAB", "data" => array("schedule" => $schedule, "detail" => $detail));
|
||||
return $param;
|
||||
}
|
||||
function get_mou()
|
||||
{
|
||||
$sql = "select S_SystemIPAddressRegional from conf_systems";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) return $rows[0]["S_SystemIPAddressRegional"];
|
||||
}
|
||||
function do_insert($table, $r)
|
||||
{
|
||||
$qry = $this->db->insert($table, $r);
|
||||
if (!$qry) echo $this->db->error()["message"] . " \n";
|
||||
}
|
||||
function do_update($table, $id, $r)
|
||||
{
|
||||
$this->db->set($r);
|
||||
$this->db->where($id, $r[$id]);
|
||||
$qry = $this->db->update($table);
|
||||
if (!$qry) echo $this->db->error()["message"] . " \n";
|
||||
}
|
||||
function exists($table, $id, $val)
|
||||
{
|
||||
$sql = "select count(*) total from {$table} where {$id} = ? ";
|
||||
$qry = $this->db->query($sql, array($val));
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err : " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return $rows[0]["total"] > 0;
|
||||
}
|
||||
function update_mou($mou)
|
||||
{
|
||||
foreach ($mou as $m) {
|
||||
$mouID = $m["selMouID"];
|
||||
if ($this->exists("regonline.sel_mou", "selMouID", $mouID)) {
|
||||
$this->do_update("regonline.sel_mou", "selMouID", $m);
|
||||
} else {
|
||||
$this->do_insert("regonline.sel_mou", $m);
|
||||
}
|
||||
}
|
||||
}
|
||||
function update_px($px)
|
||||
{
|
||||
foreach ($px as $r) {
|
||||
$pxID = $r["selPxID"];
|
||||
if ($this->exists("regonline.sel_px", "selPxID", $pxID)) {
|
||||
$this->do_update("regonline.sel_px", "selPxID", $r);
|
||||
} else {
|
||||
$this->do_insert("regonline.sel_px", $r);
|
||||
}
|
||||
}
|
||||
}
|
||||
function getBranch()
|
||||
{
|
||||
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") . " Err Get Branch: " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo date("Y-m-d H:i:s") . " Err Get Branch: " . $this->db->error()["message"] . "\n";
|
||||
exit;
|
||||
}
|
||||
return array($rows[0]["M_BranchID"], $rows[0]["M_BranchCode"]);
|
||||
}
|
||||
function getRegionalIP()
|
||||
{
|
||||
$sql = "select S_SystemIPAddressRegional from conf_systems";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) return $rows[0]["S_SystemIPAddressRegional"];
|
||||
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
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(array("status" => "ERR", "message" => $err_msg));
|
||||
}
|
||||
return gzinflate($result);
|
||||
}
|
||||
function post($url, $data, $timeout = 60, $c_timeout = 5)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($data)
|
||||
));
|
||||
$result = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
return json_encode(array("status" => "ERR", "message" => $err_msg,
|
||||
"url" => $url, "data" => json_decode($data,true)));
|
||||
}
|
||||
return gzinflate($result);
|
||||
}
|
||||
}
|
||||
783
application/controllers/tools/regonline/Heartbeat_v2.php
Normal file
783
application/controllers/tools/regonline/Heartbeat_v2.php
Normal file
@@ -0,0 +1,783 @@
|
||||
<?php
|
||||
class Heartbeat_v2 extends MY_Controller
|
||||
{
|
||||
var $url_heartbeat;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//$this->url_heartbeat = "https://devregonline.pramita.co.id/one-api/tools/regonline/r_heartbeat_v2";
|
||||
//Production
|
||||
$this->url_heartbeat = "https://mobile.pramita.co.id/one-api/tools/regonline/r_heartbeat_v2";
|
||||
}
|
||||
function step_debug($rows)
|
||||
{
|
||||
print_r($rows);
|
||||
exit();
|
||||
}
|
||||
function get_sel_px()
|
||||
{
|
||||
$sql = "select Nat_TestSellLocalT_TestID T_TestID
|
||||
from
|
||||
nat_testselllocal
|
||||
where Nat_TestSellLocalIsActive = 'Y' ";
|
||||
//Test in nat_localselltest
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err Nat_TestSellLocal : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
return "0";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = "0";
|
||||
foreach ($rows as $r) {
|
||||
$result .= "," . $r["T_TestID"];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
function get_order($date)
|
||||
{
|
||||
$date = date("Y-m-d 00:00:01");
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
$px_ids = $this->get_sel_px();
|
||||
$sql = "select distinct T_OrderHeaderID branch_OrderT_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber branch_OrderT_OrderHeaderLabNumber,
|
||||
$branchID branch_OrderM_BranchID,
|
||||
'$branchCode' branch_OrderM_BranchCode,
|
||||
T_OrderHeaderDate branch_OrderT_OrderHeaderDate,
|
||||
T_OrderDetailT_TestID branch_OrderT_TestID,
|
||||
T_OrderDetailT_TestName branch_OrderT_TestName,
|
||||
0 branch_OrderCitoInDay,
|
||||
T_OrderDetailIsCito branch_OrderIsCito,
|
||||
T_OrderDetailIsActive branch_OrderIsActive,
|
||||
T_OrderDetailValidation branch_OrderValidation
|
||||
from t_orderheader
|
||||
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderAddOnFoVerification = 'Y'
|
||||
and T_OrderHeaderAddOnLabNumberOrigin is null
|
||||
and date(T_OrderHeaderDate) >= date(?)
|
||||
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailLastUpdated >= ?
|
||||
and T_OrderDetailT_TestID in ( $px_ids )
|
||||
left join t_onlineorder on T_OrderHeaderID = T_OnlineOrderT_OrderHeaderID
|
||||
where T_OnlineOrderID is null";
|
||||
$qry = $this->db->query($sql, [$date, $date]);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
return ["type" => "ORDER_BRANCH", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return ["type" => "ORDER_BRANCH", "data" => $rows];
|
||||
}
|
||||
function now()
|
||||
{
|
||||
return date("Y-m-d H:i:s");
|
||||
}
|
||||
function get_hs($date = "")
|
||||
{
|
||||
$sql = "select count(*) xtot
|
||||
from hs_test
|
||||
where HS_TestLastUpdated > ? or HS_TestCreated > ?";
|
||||
$qry = $this->db->query($sql, [$date, $date]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Get Total : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_HS", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$xtot = 0;
|
||||
if (count($rows) > 0) {
|
||||
$xtot = $rows[0]["xtot"];
|
||||
}
|
||||
$empty_hs_test = false;
|
||||
if ($xtot == 0) {
|
||||
$empty_hs_test = true;
|
||||
}
|
||||
|
||||
$sql = "select count(*) xtot
|
||||
from hs_price
|
||||
where HS_PriceLastUpdated > ? or HS_PriceCreated > ?";
|
||||
$qry = $this->db->query($sql, [$date, $date]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Get Total : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_HS", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$xtot = 0;
|
||||
if (count($rows) > 0) {
|
||||
$xtot = $rows[0]["xtot"];
|
||||
}
|
||||
$empty_hs_price = false;
|
||||
if ($xtot == 0) {
|
||||
$empty_hs_price = true;
|
||||
}
|
||||
if ($empty_hs_price && $empty_hs_test) {
|
||||
return [
|
||||
"type" => "HS",
|
||||
"data" => ["test" => [], "price" => []],
|
||||
];
|
||||
}
|
||||
$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";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
return ["type" => "ERR_HS", "data" => []];
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$rows_test = [];
|
||||
if (!$empty_hs_test) {
|
||||
$sql = "select $branchID HS_TestM_BranchID,hs_test.* from hs_test";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_HS", "data" => []];
|
||||
}
|
||||
$rows_test = $qry->result_array();
|
||||
}
|
||||
|
||||
$rows_price = [];
|
||||
if (!$empty_hs_price) {
|
||||
$sql = "select $branchID HS_PriceM_BranchID,hs_price.* from hs_price";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_HS", "data" => []];
|
||||
}
|
||||
$rows_price = $qry->result_array();
|
||||
foreach ($rows_price as $idx => $r) {
|
||||
$rows_price[$idx]["HS_PriceM_BranchID"] = $branchID;
|
||||
}
|
||||
}
|
||||
return [
|
||||
"type" => "HS",
|
||||
"data" => ["test" => $rows_test, "price" => $rows_price],
|
||||
];
|
||||
}
|
||||
function get_best_seller($branchID, $date = "")
|
||||
{
|
||||
$sql = "select count(*) xtot
|
||||
from m_bestseller
|
||||
where M_BestSellerLastUpdated > ? or M_BestSellerCreated > ?
|
||||
and M_BestSellerM_BranchID = ?";
|
||||
$qry = $this->db->query($sql, [$date, $date,$branchID]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Get Total : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_BestSeller", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$xtot = 0;
|
||||
if (count($rows) > 0) {
|
||||
$xtot = $rows[0]["xtot"];
|
||||
}
|
||||
if ($xtot == 0) {
|
||||
return ["type" => "BEST_SELLER", "data" => []];
|
||||
}
|
||||
$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";
|
||||
return ["type" => "ERR_BestSeller", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
return ["type" => "ERR_BestSeller", "data" => []];
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$sql = "select * from m_bestseller ";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_BestSeller", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $idx => $r) {
|
||||
$rows[$idx]["M_BestSellerM_BranchID"] = $branchID;
|
||||
}
|
||||
return ["type" => "BEST_SELLER", "data" => $rows];
|
||||
}
|
||||
function get_price($date = "")
|
||||
{
|
||||
// check the upload konfirmasion
|
||||
$sql = "select count(*) total
|
||||
from s_regonline_upload
|
||||
where S_RegOnlineUploadIsSent = 'N' and S_RegOnlineUploadIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$tot_reqonline_upload = 0;
|
||||
if (count($rows) > 0) {
|
||||
$tot_reqonline_upload = $rows[0]["total"];
|
||||
}
|
||||
if ($tot_reqonline_upload == 0) {
|
||||
echo "{$this->now()} ERR : No Upload Confirmation \n";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
$sql = "update s_regonline_upload set S_RegOnlineUploadIsSent = 'Y',
|
||||
S_RegOnlineUploadSentDate = now()
|
||||
where S_RegOnlineUploadIsSent = 'N' ";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
|
||||
$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";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
//Online Released MOU
|
||||
$sql = "select * from m_mou where
|
||||
M_MouIsReleased='Y' and
|
||||
M_MouIsOnline='Y'
|
||||
and M_MouIsActive='Y'
|
||||
order by M_MouID desc";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Online Released MOU not found\n";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
$mou = $rows[0];
|
||||
$mouID = $mou["M_MouID"];
|
||||
|
||||
//SsPrice MOU Regular dan Cito
|
||||
$sql = "select
|
||||
$branchID Ss_PriceMouM_BranchID,
|
||||
ss_price_mou.*
|
||||
from ss_price_mou
|
||||
join nat_testselllocal on Ss_PriceMouM_MouID = ?
|
||||
and T_TestID = Nat_TestSellLocalT_TestID
|
||||
and Nat_TestSellLocalIsActive = 'Y'
|
||||
and Nat_TestSellLocalIsReguler = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and is_packet = 'N'
|
||||
union
|
||||
select
|
||||
$branchID Ss_PriceMouM_BranchID,
|
||||
ss_price_mou.*
|
||||
from ss_price_mou
|
||||
join nat_testselllocal on Ss_PriceMouM_MouID = ?
|
||||
and T_TestID = Nat_TestSellLocalT_TestID
|
||||
and Nat_TestSellLocalIsActive = 'Y'
|
||||
and Nat_TestSellLocalIsCito = 'Y'
|
||||
and T_PriceIsCito = 'Y'
|
||||
and is_packet = 'N'
|
||||
";
|
||||
$qry = $this->db->query($sql, [$mou["M_MouID"],$mou["M_MouID"]]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "ERR_PRICE_PACKET", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Ss Price MOU not found\n";
|
||||
return ["type" => "ERR_PRICE Test", "data" => []];
|
||||
}
|
||||
foreach ($rows as $idx => $r) {
|
||||
if ($r["px_type"] == "PXR") {
|
||||
$child_test = json_decode($r["child_test"], true);
|
||||
$sum_amount = 0;
|
||||
$sum_disc_rp = 0;
|
||||
$sum_sub_total = 0;
|
||||
$sum_total = 0;
|
||||
foreach ($child_test as $ct) {
|
||||
$sum_amount += $ct["T_PriceAmount"];
|
||||
$sum_disc_rp += $ct["T_PriceDiscRp"];
|
||||
$sum_sub_total += $ct["T_PriceSubTotal"];
|
||||
$sum_total += $ct["T_PriceTotal"];
|
||||
}
|
||||
$rows[$idx]["T_PriceAmount"] = $sum_amount;
|
||||
$rows[$idx]["T_PriceDiscRp"] = $sum_disc_rp;
|
||||
$rows[$idx]["T_PriceSubTotal"] = $sum_sub_total;
|
||||
$rows[$idx]["T_PriceTotal"] = $sum_total;
|
||||
}
|
||||
}
|
||||
$ss_price_mou = $rows;
|
||||
|
||||
// ss_price_mou packet
|
||||
// packetID dengan detail ada di nat_testselllocal semua
|
||||
$sql = "select
|
||||
T_PacketID, T_PacketDetailT_TestID,
|
||||
if(Nat_TestSellLocalT_TestID is null, 'N','Y') isSell
|
||||
from
|
||||
t_packet
|
||||
join t_packetdetail
|
||||
on T_PacketM_MouID = ?
|
||||
and T_PacketIsCito = 'Y'
|
||||
and t_packetdetailIsActive = 'Y'
|
||||
and T_PacketID = T_PacketDetailT_PacketID
|
||||
and T_PacketIsActive = 'Y'
|
||||
left join nat_testselllocal
|
||||
on T_PacketDetailT_TestID = Nat_TestSellLocalT_TestID
|
||||
and Nat_TestSellLocalIsActive = 'Y'
|
||||
and Nat_TestSellLocalIsCito = 'Y'
|
||||
union
|
||||
select
|
||||
T_PacketID, T_PacketDetailT_TestID,
|
||||
if(Nat_TestSellLocalT_TestID is null, 'N','Y') isSell
|
||||
from
|
||||
t_packet
|
||||
join t_packetdetail
|
||||
on T_PacketM_MouID = ?
|
||||
and T_PacketIsCito= 'N'
|
||||
and t_packetdetailIsActive = 'Y'
|
||||
and T_PacketID = T_PacketDetailT_PacketID
|
||||
and T_PacketIsActive = 'Y'
|
||||
left join nat_testselllocal
|
||||
on T_PacketDetailT_TestID = Nat_TestSellLocalT_TestID
|
||||
and Nat_TestSellLocalIsActive = 'Y'
|
||||
and Nat_TestSellLocalIsReguler = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql, [$mou["M_MouID"], $mou["M_MouID"]]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return ["type" => "Get Packet ", "data" => []];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Packet Detail not found\n";
|
||||
}
|
||||
$non_full_packet = [];
|
||||
$packetID = [];
|
||||
foreach ($rows as $r) {
|
||||
$packetID[$r["T_PacketID"]] = true;
|
||||
if ($r["isSell"] == "N") {
|
||||
$non_full_packet[$r["T_PacketID"]] = true;
|
||||
}
|
||||
}
|
||||
$packet_ids = array_keys($packetID);
|
||||
$exclude_packet_ids = array_keys($non_full_packet);
|
||||
$packet_ids = array_filter($packet_ids, function ($p) use (
|
||||
$exclude_packet_ids
|
||||
) {
|
||||
if (in_array($p, $exclude_packet_ids)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
$packets = [];
|
||||
$packet_details = [];
|
||||
if (count($packet_ids) > 0) {
|
||||
$s_packet_ids = implode(",", $packet_ids);
|
||||
$sql = "select
|
||||
$branchID Ss_PriceMouM_BranchID,
|
||||
ss_price_mou.*
|
||||
from ss_price_mou
|
||||
where packet_id in ($s_packet_ids)
|
||||
and is_packet = 'Y'";
|
||||
$qry = $this->db->query($sql, [$mou["M_MouID"]]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return [
|
||||
"type" => "Get ss_price_mou Sold Packet ",
|
||||
"data" => [],
|
||||
];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $idx => $r) {
|
||||
if ($r["px_type"] == "PR") {
|
||||
$child_test = json_decode($r["child_test"], true);
|
||||
$sum_amount = 0;
|
||||
$sum_disc_rp = 0;
|
||||
$sum_sub_total = 0;
|
||||
$sum_total = 0;
|
||||
foreach ($child_test as $ct) {
|
||||
$sum_amount += $ct["T_PriceAmount"];
|
||||
$sum_disc_rp += $ct["T_PriceDiscRp"];
|
||||
$sum_sub_total += $ct["T_PriceSubTotal"];
|
||||
$sum_total += $ct["T_PriceTotal"];
|
||||
}
|
||||
$rows[$idx]["T_PriceAmount"] = $sum_amount;
|
||||
$rows[$idx]["T_PriceDiscRp"] = $sum_disc_rp;
|
||||
$rows[$idx]["T_PriceSubTotal"] = $sum_sub_total;
|
||||
$rows[$idx]["T_PriceTotal"] = $sum_total;
|
||||
}
|
||||
}
|
||||
$ss_price_mou = array_merge($ss_price_mou, $rows);
|
||||
//packet
|
||||
$sql = "select $branchID T_PacketM_BranchID,
|
||||
t_packet.*
|
||||
from t_packet where T_PacketID in ($s_packet_ids)";
|
||||
$qry = $this->db->query($sql, [$mou["M_MouID"]]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return [
|
||||
"type" => "Get sold packet",
|
||||
"data" => [],
|
||||
];
|
||||
}
|
||||
$packets = $qry->result_array();
|
||||
//packet_details
|
||||
$sql = "select $branchID T_PacketDetailM_BranchID,
|
||||
t_packetdetail.*
|
||||
from t_packetdetail
|
||||
where T_PacketDetailT_PacketID in ($s_packet_ids)
|
||||
and T_PacketDetailIsActive ='Y'";
|
||||
$qry = $this->db->query($sql, [$mou["M_MouID"]]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
return [
|
||||
"type" => "Get sold packet details",
|
||||
"data" => [],
|
||||
];
|
||||
}
|
||||
$packet_details = $qry->result_array();
|
||||
}
|
||||
$data = [
|
||||
"ss_price_mou" => $ss_price_mou,
|
||||
"packet" => $packets,
|
||||
"detail" => $packet_details,
|
||||
];
|
||||
return ["type" => "PRICE_PACKET", "data" => $data];
|
||||
}
|
||||
function index()
|
||||
{
|
||||
$this->process();
|
||||
}
|
||||
function log($msg)
|
||||
{
|
||||
echo date("Y-m-d H:i:s") . " $msg\n";
|
||||
}
|
||||
//debug set addhoc in future
|
||||
// php project/one/one-api/index.php tools regonline heartbeat_v2
|
||||
function process($addhoc_date = "")
|
||||
{
|
||||
$sql = "select * from regonline.heartbeat";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$heartbeat = [];
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $r) {
|
||||
$heartbeat[$r["heartbeatCode"]] = $r["heartbeatExecuted"];
|
||||
if ($addhoc_date != "") {
|
||||
$heartbeat[$r["heartbeatCode"]] = "$addhoc_date 00:00:01";
|
||||
}
|
||||
}
|
||||
|
||||
//Ping
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
$ping_param = [
|
||||
"type" => "PING",
|
||||
"data" => ["branchID" => $branchID, "branchCode" => $branchCode],
|
||||
];
|
||||
//SWAB Schedule
|
||||
$swab_param = $this->upload_swab($heartbeat["SWAB"]);
|
||||
//QUOTA PCR
|
||||
$quota_param = $this->upload_kuota($heartbeat["QUOTA_PCR"]);
|
||||
|
||||
//ORDER BRANCH
|
||||
$order_branch_param = $this->get_order($heartbeat["ORDER_BRANCH"]);
|
||||
|
||||
$price_packet_param = $this->get_price($heartbeat["PRICE_PACKET"]);
|
||||
if (!isset($heartbeat["HS"])) {
|
||||
$heartbeat["HS"] = "2021-01-01 00:00:00";
|
||||
}
|
||||
$hs_param = $this->get_hs($heartbeat["HS"]);
|
||||
if (!isset($heartbeat["BEST_SELLER"])) {
|
||||
$heartbeat["BEST_SELLER"] = "2021-01-01 00:00:00";
|
||||
}
|
||||
$best_seller_param = $this->get_best_seller($branchID,$heartbeat["BEST_SELLER"]);
|
||||
$data = [
|
||||
$ping_param,
|
||||
$swab_param,
|
||||
$quota_param,
|
||||
$order_branch_param,
|
||||
$price_packet_param,
|
||||
$hs_param,
|
||||
$best_seller_param,
|
||||
];
|
||||
$md5 = md5(json_encode($data));
|
||||
$z_param = gzdeflate(
|
||||
json_encode([
|
||||
"md5" => $md5,
|
||||
"data" => $data,
|
||||
]),
|
||||
9
|
||||
);
|
||||
|
||||
//do the heartbeat
|
||||
$size = round(strlen($z_param) / 1024);
|
||||
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Start HeartBeat to : {$this->url_heartbeat} Size: {$size} kB\n";
|
||||
$response = $this->post($this->url_heartbeat, $z_param);
|
||||
$j_response = json_decode($response, true);
|
||||
if (!$j_response) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" End HeartBeat : Error Json : $response\n";
|
||||
exit();
|
||||
}
|
||||
if ($j_response["status"] == "ERR") {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" End HeartBeat : Error : {$j_response["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
foreach ($j_response["result"] as $type => $rst) {
|
||||
$msg = "";
|
||||
if (isset($rst["message"])) {
|
||||
$msg = $rst["message"];
|
||||
}
|
||||
$status = $rst["status"];
|
||||
$this->update_heartbeat($type, $status, $msg);
|
||||
echo date("Y-m-d H:i:s") . " \t $type : $status : $msg \n";
|
||||
}
|
||||
}
|
||||
function update_heartbeat($type, $status, $msg)
|
||||
{
|
||||
//jika tidak OK executed tidak di set
|
||||
if ($status == "OK") {
|
||||
$sql = "update regonline.heartbeat set heartbeatExecuted = now(), heartbeatStatus = ? , heartbeatMessage = ?
|
||||
where heartbeatCode = ?";
|
||||
$qry = $this->db->query($sql, [$status, $msg, $type]);
|
||||
} else {
|
||||
$sql = "update regonline.heartbeat set heartbeatStatus = ? , heartbeatMessage = ?
|
||||
where heartbeatCode = ?";
|
||||
$qry = $this->db->query($sql, [$status, $msg, $type]);
|
||||
}
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" \t Error $type : {$this->db->error()["message"]}\n";
|
||||
}
|
||||
}
|
||||
function upload_kuota($date)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
if ($date == "") {
|
||||
$date = "2020-01-01 00:00:00";
|
||||
}
|
||||
$sql = "select m_reg_kuota.*, $branchID M_RegKuotaM_BranchID, '$branchCode' M_RegKuotaM_BranchCode
|
||||
from m_reg_kuota where M_RegKuotaLastUpdated > ?";
|
||||
$qry = $this->db->query($sql, [$date]);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Error Kuota : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$kuota = $qry->result_array();
|
||||
$sql = "select m_reg_kuota_log.*, $branchID M_RegKuotaLogM_BranchID, '$branchCode' M_RegKuotaLogM_BranchCode
|
||||
from m_reg_kuota_log where M_RegKuotaLogLastUpdated > ?";
|
||||
$qry = $this->db->query($sql, [$date]);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Error Kuota Log : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$log = $qry->result_array();
|
||||
$param = [
|
||||
"type" => "QUOTA_PCR",
|
||||
"data" => ["kuota" => $kuota, "log" => $log],
|
||||
];
|
||||
return $param;
|
||||
}
|
||||
|
||||
function upload_swab($date)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->getBranch();
|
||||
if ($date == "") {
|
||||
$date = "2020-01-01 00:00:00";
|
||||
}
|
||||
$sql = "select m_reg_schedule.*, $branchID M_RegScheduleM_BranchID, '$branchCode' M_RegScheduleM_BranchCode
|
||||
from m_reg_schedule where M_RegScheduleIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$date]);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Error Schedule : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$schedule = $qry->result_array();
|
||||
$sql = "select m_reg_scheduledetail.*, $branchID M_RegScheduleDetailM_BranchID, '$branchCode' M_RegScheduleDetailM_BranchCode
|
||||
from m_reg_scheduledetail where M_RegScheduleDetailIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$date]);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Error Schedule : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$detail = $qry->result_array();
|
||||
$param = [
|
||||
"type" => "SWAB",
|
||||
"data" => ["schedule" => $schedule, "detail" => $detail],
|
||||
];
|
||||
return $param;
|
||||
}
|
||||
function get_mou()
|
||||
{
|
||||
$sql = "select S_SystemIPAddressRegional from conf_systems";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
return $rows[0]["S_SystemIPAddressRegional"];
|
||||
}
|
||||
}
|
||||
function do_insert($table, $r)
|
||||
{
|
||||
$qry = $this->db->insert($table, $r);
|
||||
if (!$qry) {
|
||||
echo $this->db->error()["message"] . " \n";
|
||||
}
|
||||
}
|
||||
function do_update($table, $id, $r)
|
||||
{
|
||||
$this->db->set($r);
|
||||
$this->db->where($id, $r[$id]);
|
||||
$qry = $this->db->update($table);
|
||||
if (!$qry) {
|
||||
echo $this->db->error()["message"] . " \n";
|
||||
}
|
||||
}
|
||||
function exists($table, $id, $val)
|
||||
{
|
||||
$sql = "select count(*) total from {$table} where {$id} = ? ";
|
||||
$qry = $this->db->query($sql, [$val]);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err : " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return $rows[0]["total"] > 0;
|
||||
}
|
||||
function update_mou($mou)
|
||||
{
|
||||
foreach ($mou as $m) {
|
||||
$mouID = $m["selMouID"];
|
||||
if ($this->exists("regonline.sel_mou", "selMouID", $mouID)) {
|
||||
$this->do_update("regonline.sel_mou", "selMouID", $m);
|
||||
} else {
|
||||
$this->do_insert("regonline.sel_mou", $m);
|
||||
}
|
||||
}
|
||||
}
|
||||
function update_px($px)
|
||||
{
|
||||
foreach ($px as $r) {
|
||||
$pxID = $r["selPxID"];
|
||||
if ($this->exists("regonline.sel_px", "selPxID", $pxID)) {
|
||||
$this->do_update("regonline.sel_px", "selPxID", $r);
|
||||
} else {
|
||||
$this->do_insert("regonline.sel_px", $r);
|
||||
}
|
||||
}
|
||||
}
|
||||
function getBranch()
|
||||
{
|
||||
$sql =
|
||||
"select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err Get Branch: " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo date("Y-m-d H:i:s") .
|
||||
" Err Get Branch: " .
|
||||
$this->db->error()["message"] .
|
||||
"\n";
|
||||
exit();
|
||||
}
|
||||
return [$rows[0]["M_BranchID"], $rows[0]["M_BranchCode"]];
|
||||
}
|
||||
function getRegionalIP()
|
||||
{
|
||||
$sql = "select S_SystemIPAddressRegional from conf_systems";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
return $rows[0]["S_SystemIPAddressRegional"];
|
||||
}
|
||||
|
||||
return "devone.aplikasi.web.id";
|
||||
}
|
||||
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 gzinflate($result);
|
||||
}
|
||||
function post($url, $data, $timeout = 180, $c_timeout = 5)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
return json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => $err_msg,
|
||||
"url" => $url,
|
||||
"data" => json_decode($data, true),
|
||||
]);
|
||||
}
|
||||
return gzinflate($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
<?php
|
||||
|
||||
class Pramitalabku_download extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->debug = false;
|
||||
$this->ONLINE_USER_ID = 1500;
|
||||
$this->SENDER_DOCTOR_ID = 0;
|
||||
$this->SENDER_ADDRESS_ID = 0;
|
||||
$this->PJ_DOCTOR_ID = 0;
|
||||
$this->KASIR_ONLINE_USER = 1500;
|
||||
$this->url = "https://mobile.pramita.co.id/one-api/tools/regonline/r_download/";
|
||||
$this->url_v2 = "https://mobile.pramita.co.id/one-api/tools/regonline/r_download_v2/";
|
||||
}
|
||||
public function now()
|
||||
{
|
||||
return Date("Y-m-d H:i:s");
|
||||
}
|
||||
public function get_tx_id($orgID)
|
||||
{
|
||||
$result = 0;
|
||||
$sql = "select T_OnlineTxID
|
||||
from t_onlinetx
|
||||
where T_OnlineTxOrgID=?";
|
||||
$qry = $this->db->query($sql, array($orgID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Exist Tx : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
return $rows[0]["T_OnlineTxID"];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function tx_ehac($tx, $txID)
|
||||
{
|
||||
$order = $tx["order"];
|
||||
$sum_ehac = 0;
|
||||
foreach ($order as $o) {
|
||||
$sum_ehac += $o["T_OrderEHAC"];
|
||||
}
|
||||
$arr = [
|
||||
"T_OnlineTxID" => $txID,
|
||||
"T_OnlineTxEhacFee" => $sum_ehac,
|
||||
];
|
||||
$qry = $this->db->where("T_OnlineTxID", $txID);
|
||||
$qry = $this->db->update("t_onlinetx", $arr);
|
||||
if (!$qry) {
|
||||
return [false, $this->db->error()["message"]];
|
||||
}
|
||||
return [true, ""];
|
||||
}
|
||||
|
||||
public function strip_unicode($inp)
|
||||
{
|
||||
$result = mb_convert_encoding($inp, "US-ASCII", "UTF-8");
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "{$this->now()} Start Download Online Order [Duitku]\n";
|
||||
$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";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
|
||||
$date = date("Y-m-d H:i:s");
|
||||
$url = $this->url;
|
||||
$param = ["branchID" => $branchID, "date" => $date];
|
||||
$z_param = gzdeflate(json_encode($param), 9);
|
||||
|
||||
$resp = $this->post($url, $z_param);
|
||||
if ($resp["status"] == "OK") {
|
||||
$this->db->trans_begin();
|
||||
$db_msg = "";
|
||||
$tx_counter = 0;
|
||||
$order_counter = 0;
|
||||
foreach ($resp["txs"] as $tx) {
|
||||
$ref = "";
|
||||
foreach ($tx["duitku"] as $d) {
|
||||
if ($ref != "") {
|
||||
$ref .= "|";
|
||||
}
|
||||
$ref .=
|
||||
$d["duitkuCbReference"] .
|
||||
"^" .
|
||||
$d["duitkuCbPaymentResultCode"];
|
||||
}
|
||||
$tx_order = $tx["order"];
|
||||
$px_name = "";
|
||||
$px_qrcode = "";
|
||||
$px_date = "";
|
||||
$arr_px_date = [];
|
||||
foreach ($tx_order as $txo) {
|
||||
if ($px_date != "") {
|
||||
$px_date .= ",";
|
||||
}
|
||||
$x_date = $txo["T_OrderDate"] . " " . $txo["T_OrderTime"];
|
||||
if (strtotime($x_date)) {
|
||||
$px_date .= date("d-m-Y H:i", strtotime($x_date));
|
||||
} else {
|
||||
$px_date .=
|
||||
$txo["T_OrderDate"] . " " . $txo["T_OrderTime"];
|
||||
}
|
||||
if ($px_qrcode != "") {
|
||||
$px_qrcode .= ",";
|
||||
}
|
||||
$px_qrcode .= $txo["T_OrderQrCode"];
|
||||
if ($px_name != "") {
|
||||
$px_name .= ",";
|
||||
}
|
||||
$px_name .= $txo["patient"]["M_PatientName"];
|
||||
$arr_px_date[] = $px_date;
|
||||
}
|
||||
$dt = [
|
||||
"T_OnlineTxOrgID" => $tx["T_TransactionID"],
|
||||
"T_OnlineTxDate" => $tx["T_TransactionDate"],
|
||||
"T_OnlineTxNumbering" => $tx["T_TransactionNumbering"],
|
||||
"T_OnlineTxTotal" => $tx["T_TransactionTotal"],
|
||||
"T_OnlineTxFee" => $tx["T_TransactionFee"],
|
||||
"T_OnlineTxPgReference" => $ref,
|
||||
"T_OnlineTxJsonGz" => gzdeflate(json_encode($tx), 9),
|
||||
"T_OnlineTxBookingQrCode" => $px_qrcode,
|
||||
"T_OnlineTxBookingDate" => $px_date,
|
||||
"T_OnlineTxBookingName" => $px_name,
|
||||
"T_OnlineTxConfig" => json_encode($tx["config"]),
|
||||
];
|
||||
|
||||
if ($this->exists_tx($tx["T_TransactionID"])) {
|
||||
$this->db->where("T_OnlineTxOrgID", $tx["T_TransactionID"]);
|
||||
$qry = $this->db->update("t_onlinetx", $dt);
|
||||
$tOnlineTxID = $this->get_tx_id($tx["T_TransactionID"]);
|
||||
} else {
|
||||
$qry = $this->db->insert("t_onlinetx", $dt);
|
||||
$tOnlineTxID = $this->db->insert_id();
|
||||
}
|
||||
if (!$qry) {
|
||||
$db_msg .=
|
||||
"|Insert T_OnlineTx " . $this->db->error()["message"];
|
||||
$db_msg .= $this->db->last_query();
|
||||
}
|
||||
list($statusEhac, $db_msg) = $this->tx_ehac($tx, $tOnlineTxID);
|
||||
$tx_counter++;
|
||||
}
|
||||
if ($db_msg != "") {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR : {$db_msg}\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($this->db->trans_status === false) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR : {$db_msg}\n";
|
||||
} else {
|
||||
$this->db->trans_commit();
|
||||
echo "{$this->now()} Downloaded $tx_counter Transaction\n";
|
||||
$this->download_bayar_ditempat();
|
||||
}
|
||||
} else {
|
||||
echo "{$this->now()} ERR : {$resp["message"]}\n";
|
||||
}
|
||||
}
|
||||
function download_bayar_ditempat()
|
||||
{
|
||||
echo "{$this->now()} Start Download Online Order [Bayar di tempat]\n";
|
||||
$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";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
|
||||
$date = date("Y-m-d H:i:s");
|
||||
$url = $this->url_v2;
|
||||
$param = ["branchID" => $branchID, "date" => $date];
|
||||
$z_param = gzdeflate(json_encode($param), 9);
|
||||
|
||||
$resp = $this->post($url, $z_param);
|
||||
if ($resp["status"] == "OK") {
|
||||
$this->db->trans_begin();
|
||||
$db_msg = "";
|
||||
$tx_counter = 0;
|
||||
$order_counter = 0;
|
||||
foreach ($resp["txs"] as $tx) {
|
||||
$ref = "";
|
||||
foreach ($tx["duitku"] as $d) {
|
||||
if ($ref != "") {
|
||||
$ref .= "|";
|
||||
}
|
||||
$ref .=
|
||||
$d["duitkuCbReference"] .
|
||||
"^" .
|
||||
$d["duitkuCbPaymentResultCode"];
|
||||
}
|
||||
$tx_order = $tx["order"];
|
||||
$px_name = "";
|
||||
$px_qrcode = "";
|
||||
$px_date = "";
|
||||
foreach ($tx_order as $txo) {
|
||||
if ($px_date != "") {
|
||||
$px_date .= ",";
|
||||
}
|
||||
$x_date = $txo["T_OrderDate"] . " " . $txo["T_OrderTime"];
|
||||
if (strtotime($x_date)) {
|
||||
$px_date .= date("d-m-Y H:i", strtotime($x_date));
|
||||
} else {
|
||||
$px_date .=
|
||||
$txo["T_OrderDate"] . " " . $txo["T_OrderTime"];
|
||||
}
|
||||
if ($px_qrcode != "") {
|
||||
$px_qrcode .= ",";
|
||||
}
|
||||
$px_qrcode .= $txo["T_OrderQrCode"];
|
||||
if ($px_name != "") {
|
||||
$px_name .= ",";
|
||||
}
|
||||
$px_name .= $txo["patient"]["M_PatientName"];
|
||||
}
|
||||
|
||||
$dt = [
|
||||
"T_OnlineTxOrgID" => $tx["T_TransactionID"],
|
||||
"T_OnlineTxDate" => $tx["T_TransactionDate"],
|
||||
"T_OnlineTxNumbering" => $tx["T_TransactionNumbering"],
|
||||
"T_OnlineTxTotal" => $tx["T_TransactionTotal"],
|
||||
"T_OnlineTxFee" => $tx["T_TransactionFee"],
|
||||
"T_OnlineTxPgReference" => $ref,
|
||||
"T_OnlineTxJsonGz" => gzdeflate(json_encode($tx), 9),
|
||||
"T_OnlineTxBookingQrCode" => $px_qrcode,
|
||||
"T_OnlineTxBookingDate" => $px_date,
|
||||
"T_OnlineTxBookingName" => $px_name,
|
||||
"T_OnlineTxConfig" => json_encode($tx["config"]),
|
||||
];
|
||||
|
||||
if ($this->exists_tx($tx["T_TransactionID"])) {
|
||||
$this->db->where("T_OnlineTxOrgID", $tx["T_TransactionID"]);
|
||||
$qry = $this->db->update("t_onlinetx", $dt);
|
||||
$tOnlineTxID = $this->get_tx_id($tx["T_TransactionID"]);
|
||||
} else {
|
||||
$qry = $this->db->insert("t_onlinetx", $dt);
|
||||
$tOnlineTxID = $this->db->insert_id();
|
||||
}
|
||||
if (!$qry) {
|
||||
$db_msg .=
|
||||
"|Insert T_OnlineTx " . $this->db->error()["message"];
|
||||
$db_msg .= $this->db->last_query();
|
||||
}
|
||||
list($statusEhac, $db_msg) = $this->tx_ehac($tx, $tOnlineTxID);
|
||||
$tx_counter++;
|
||||
}
|
||||
if ($db_msg != "") {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR : {$db_msg}\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($this->db->trans_status === false) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR : {$db_msg}\n";
|
||||
} else {
|
||||
$this->db->trans_commit();
|
||||
echo "{$this->now()} Downloaded $tx_counter Transaction\n";
|
||||
}
|
||||
} else {
|
||||
echo "{$this->now()} ERR : {$resp["message"]}\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function post($url, $data)
|
||||
{
|
||||
echo "{$this->now()} DEBUG Connect to : $url\n";
|
||||
$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/json",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$z_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 | $z_result",
|
||||
];
|
||||
}
|
||||
|
||||
$result = gzinflate($z_result);
|
||||
$j_result = json_decode($result, true);
|
||||
if (!$j_result) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "JSON invalid: $z_result",
|
||||
];
|
||||
}
|
||||
return $j_result;
|
||||
}
|
||||
|
||||
public function exists_tx($txID)
|
||||
{
|
||||
$sql = "select count(*) total
|
||||
from t_onlinetx
|
||||
where T_OnlineTxOrgID=?";
|
||||
$qry = $this->db->query($sql, [$txID]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Exist Tx : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return $rows[0]["total"] > 0;
|
||||
}
|
||||
}
|
||||
196
application/controllers/tools/regonline/Pramitalabku_kasir.php
Normal file
196
application/controllers/tools/regonline/Pramitalabku_kasir.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
class Pramitalabku_kasir extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->debug = false;
|
||||
$this->ONLINE_USER_ID = 1500;
|
||||
$this->SENDER_DOCTOR_ID = 0;
|
||||
$this->SENDER_ADDRESS_ID = 0;
|
||||
$this->PJ_DOCTOR_ID = 0;
|
||||
$this->KASIR_ONLINE_USER = 1500;
|
||||
$this->url =
|
||||
"https://mobile.pramita.co.id/one-api/tools/regonline/r_download/";
|
||||
}
|
||||
public function hs()
|
||||
{
|
||||
echo "{$this->now()} Start Serahkan HS ke kasir\n";
|
||||
$this->db->trans_begin();
|
||||
$arr = [
|
||||
"F_PaymentKasirNumber",
|
||||
"F_PaymentKasirDate",
|
||||
"F_PaymentKasirUserID",
|
||||
];
|
||||
$arrd = [
|
||||
"F_PaymentKasirDetailF_PaymentID",
|
||||
"F_PaymentKasirDetailF_PaymentKasirID",
|
||||
];
|
||||
$sql = "select F_PaymentID
|
||||
from f_payment
|
||||
join one_hs.t_order
|
||||
on F_PaymentT_OrderHeaderID = T_OrderT_OrderHeaderID
|
||||
and T_OrderIsActive = 'Y'
|
||||
and F_PaymentIsActive = 'Y'
|
||||
and F_PaymentID not in (
|
||||
select F_PaymentKasirDetailF_PaymentID
|
||||
from f_payment_kasir_detail
|
||||
where F_PaymentKasirDetailIsActive = 'Y'
|
||||
)";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$payment_rows = $qry->result_array();
|
||||
if (count($payment_rows) == 0) {
|
||||
echo "{$this->now()} No Transaction\n";
|
||||
exit();
|
||||
}
|
||||
//get serah no
|
||||
$sql = "select fn_numbering('F2C') serah_no";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR Get F2C Numbering : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} No F2C Numbering \n";
|
||||
exit();
|
||||
}
|
||||
$f2c_no = $rows[0]["serah_no"];
|
||||
|
||||
//create F_PaymentKasir
|
||||
$arr_kasir = [
|
||||
"F_PaymentKasirNumber" => $f2c_no,
|
||||
"F_PaymentKasirDate" => date("Y-m-d H:i:s"),
|
||||
"F_PaymentKasirCreated" => date("Y-m-d H:i:s"),
|
||||
"F_PaymentKasirCreated" => date("Y-m-d H:i:s"),
|
||||
"F_PaymentKasirUserID" => $this->KASIR_ONLINE_USER,
|
||||
];
|
||||
$qry = $this->db->insert("f_payment_kasir", $arr_kasir);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR Insert F Payment Kasir : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$fPaymentKasirID = $this->db->insert_id();
|
||||
//create F_PaymentKasirDetail
|
||||
foreach ($payment_rows as $p) {
|
||||
$arrd = [
|
||||
"F_PaymentKasirDetailF_PaymentID" => $p["F_PaymentID"],
|
||||
"F_PaymentKasirDetailF_PaymentKasirID" => $fPaymentKasirID,
|
||||
];
|
||||
$qry = $this->db->insert("f_payment_kasir_detail", $arrd);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR Insert F Payment Kasir Detail : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->db->trans_status === false) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR : {$db_msg}\n";
|
||||
} else {
|
||||
$this->db->trans_commit();
|
||||
echo "{$this->now()} Created Penyerahan Kasir HS $f2c_no\n";
|
||||
}
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
echo "{$this->now()} Start Serahkan ke kasir\n";
|
||||
$this->db->trans_begin();
|
||||
$arr = [
|
||||
"F_PaymentKasirNumber",
|
||||
"F_PaymentKasirDate",
|
||||
"F_PaymentKasirUserID",
|
||||
];
|
||||
$arrd = [
|
||||
"F_PaymentKasirDetailF_PaymentID",
|
||||
"F_PaymentKasirDetailF_PaymentKasirID",
|
||||
];
|
||||
$sql = "select F_PaymentID
|
||||
from f_payment
|
||||
join t_onlineorder
|
||||
on F_PaymentT_OrderHeaderID = T_OnlineOrderT_OrderHeaderID
|
||||
and T_OnlineOrderIsActive = 'Y'
|
||||
and F_PaymentIsActive = 'Y'
|
||||
and F_PaymentID not in (
|
||||
select F_PaymentKasirDetailF_PaymentID
|
||||
from f_payment_kasir_detail
|
||||
where F_PaymentKasirDetailIsActive = 'Y'
|
||||
)";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$payment_rows = $qry->result_array();
|
||||
if (count($payment_rows) == 0) {
|
||||
echo "{$this->now()} No Transaction\n";
|
||||
exit();
|
||||
}
|
||||
//get serah no
|
||||
$sql = "select fn_numbering('F2C') serah_no";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR Get F2C Numbering : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} No F2C Numbering \n";
|
||||
exit();
|
||||
}
|
||||
$f2c_no = $rows[0]["serah_no"];
|
||||
|
||||
//create F_PaymentKasir
|
||||
$arr_kasir = [
|
||||
"F_PaymentKasirNumber" => $f2c_no,
|
||||
"F_PaymentKasirDate" => date("Y-m-d H:i:s"),
|
||||
"F_PaymentKasirCreated" => date("Y-m-d H:i:s"),
|
||||
"F_PaymentKasirCreated" => date("Y-m-d H:i:s"),
|
||||
"F_PaymentKasirUserID" => $this->KASIR_ONLINE_USER,
|
||||
];
|
||||
$qry = $this->db->insert("f_payment_kasir", $arr_kasir);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR Insert F Payment Kasir : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$fPaymentKasirID = $this->db->insert_id();
|
||||
//create F_PaymentKasirDetail
|
||||
foreach ($payment_rows as $p) {
|
||||
$arrd = [
|
||||
"F_PaymentKasirDetailF_PaymentID" => $p["F_PaymentID"],
|
||||
"F_PaymentKasirDetailF_PaymentKasirID" => $fPaymentKasirID,
|
||||
];
|
||||
$qry = $this->db->insert("f_payment_kasir_detail", $arrd);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR Insert F Payment Kasir Detail : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->db->trans_status === false) {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR : {$db_msg}\n";
|
||||
} else {
|
||||
$this->db->trans_commit();
|
||||
echo "{$this->now()} Created Penyerahan Kasir $f2c_no\n";
|
||||
$this->hs();
|
||||
}
|
||||
}
|
||||
public function now()
|
||||
{
|
||||
return Date("Y-m-d H:i:s");
|
||||
}
|
||||
}
|
||||
880
application/controllers/tools/regonline/Pramitalabku_upload.php
Normal file
880
application/controllers/tools/regonline/Pramitalabku_upload.php
Normal file
@@ -0,0 +1,880 @@
|
||||
<?php
|
||||
|
||||
class Pramitalabku_upload extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->debug = false;
|
||||
$this->ONLINE_USER_ID = 1500;
|
||||
$this->SENDER_DOCTOR_ID = 0;
|
||||
$this->SENDER_ADDRESS_ID = 0;
|
||||
$this->PJ_DOCTOR_ID = 0;
|
||||
$this->KASIR_ONLINE_USER = 1500;
|
||||
$this->url = "https://mobile.pramita.co.id/one-api/tools/regonline/r_download/";
|
||||
}
|
||||
public function now()
|
||||
{
|
||||
return Date("Y-m-d H:i:s");
|
||||
}
|
||||
|
||||
public function get_branch_default()
|
||||
{
|
||||
$sql =
|
||||
"select * from m_branch where M_BranchIsDefault = 'Y' and M_BranchIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR Get Default Branch: {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$branchKelurahanID = $rows[0]["M_BranchM_KelurahanID"];
|
||||
$this->SENDER_DOCTOR_ID = $rows[0]["M_BranchM_DoctorID"];
|
||||
$this->SENDER_ADDRESS_ID = $rows[0]["M_BranchM_DoctorAddressID"];
|
||||
|
||||
$sql =
|
||||
"select * from m_doctorpj where M_DoctorPjIsActive = 'Y' and M_DoctorPjIsDefaultPJ='Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR Get Default PJ: {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$this->PJ_DOCTOR_ID = $rows[0]["M_DoctorPjM_DoctorID"];
|
||||
|
||||
return [$branchKelurahanID];
|
||||
}
|
||||
|
||||
public function get_promise_by_px($pxID, $headerDate)
|
||||
{
|
||||
$sql = "select
|
||||
date(
|
||||
case
|
||||
when M_ScheduleFlagAtTime = 'Y' then
|
||||
concat( date( ? + interval M_ScheduleMonth * 4 day + interval 7 * M_ScheduleWeek day + interval M_ScheduleDay day) , ' ',
|
||||
M_ScheduleAtTime , ':00')
|
||||
else
|
||||
? + interval M_ScheduleMonth * 4 day + interval 7 * M_ScheduleWeek day + interval M_ScheduleDay day +
|
||||
interval M_ScheduleHour Hour + interval M_ScheduleMinute minute
|
||||
end
|
||||
)
|
||||
promiseDate,
|
||||
max(
|
||||
case
|
||||
when M_ScheduleFlagAtTime = 'Y' then
|
||||
concat( date( ? + interval M_ScheduleMonth * 4 day + interval 7 * M_ScheduleWeek day + interval M_ScheduleDay day) , ' ',
|
||||
M_ScheduleAtTime , ':00')
|
||||
else
|
||||
? + interval M_ScheduleMonth * 4 day + interval 7 * M_ScheduleWeek day + interval M_ScheduleDay day +
|
||||
interval M_ScheduleHour Hour + interval M_ScheduleMinute minute
|
||||
end
|
||||
)
|
||||
promiseDateTime
|
||||
from
|
||||
t_test
|
||||
join m_schedulegrouptest on T_TestNat_TestID = M_ScheduleGroupTestNat_TestID
|
||||
and M_ScheduleGroupTestIsActive = 'Y'
|
||||
join m_schedule on M_ScheduleM_ScheduleGroupID = M_ScheduleGroupTestM_ScheduleGroupID
|
||||
and M_ScheduleIsActive = 'Y'
|
||||
and M_ScheduleDayOfWeek = dayofweek(?)
|
||||
and date_format(?, '%H:%i') >= M_ScheduleStartHourMinute
|
||||
and date_format(?, '%H:%i') <= M_ScheduleEndHourMinute
|
||||
and T_TestID in ( $pxID )
|
||||
group by promiseDate";
|
||||
$qry = $this->db->query($sql, [
|
||||
$headerDate,
|
||||
$headerDate,
|
||||
$headerDate,
|
||||
$headerDate,
|
||||
$headerDate,
|
||||
$headerDate,
|
||||
$headerDate,
|
||||
]);
|
||||
if (!$qry) {
|
||||
//echo "{$this->now()} ERR Promise Reguler : {$this->db->error()['message']} | {$this->db->last_query()}\n";
|
||||
return ["", ""];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
//echo "{$this->now()} ERR Promise Reguler : Not Found \n";
|
||||
return ["", ""];
|
||||
}
|
||||
//ambil yg pertama
|
||||
$promiseDate = $rows[0]["promiseDate"];
|
||||
$promiseDateTime = $rows[0]["promiseDateTime"];
|
||||
return [$promiseDate, $promiseDateTime];
|
||||
}
|
||||
public function status_order()
|
||||
{
|
||||
echo "{$this->now()} Start Order Create Status\n";
|
||||
list($branchKelurahanID) = $this->get_branch_default();
|
||||
$db_msg = "";
|
||||
|
||||
$this->db->trans_begin();
|
||||
//1. Get Branch
|
||||
$sql = "select
|
||||
M_BranchName, M_BranchAddress
|
||||
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";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR Update Status - Branch : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$branchName = $rows[0]["M_BranchName"];
|
||||
$branchAddress = $rows[0]["M_BranchAddress"];
|
||||
|
||||
//1. Order Creation
|
||||
$sql = "select T_OnlineTxOrgID, T_OnlineOrderT_OrderID, T_OnlineOrderID,
|
||||
T_OrderHeaderLabNumberExt, T_OrderHeaderDate, T_OrderHeaderID
|
||||
from t_onlineorder
|
||||
join t_onlinetx on T_OnlineOrderT_OnlineTxID = T_OnlineTxID
|
||||
join t_orderheader on T_OrderHeaderID = T_OnlineOrderT_OrderHeaderID
|
||||
where T_OnlineOrderUploaded is null";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$counter = 0;
|
||||
$status = [];
|
||||
$headerDate = date("Y-m-d H:i:s");
|
||||
foreach ($rows as $r) {
|
||||
$msg =
|
||||
"Nomor Registrasi\t: " . $r["T_OrderHeaderLabNumberExt"] . "\n";
|
||||
$msg .= "Lab. Pramita $branchName\n$branchAddress\n";
|
||||
$msg .= "Jadwal\t: " . $this->get_hari_id($r["T_OrderHeaderDate"]);
|
||||
$resp = $this->get_promise_by_px(
|
||||
$r["T_OrderHeaderID"],
|
||||
$r["T_OrderHeaderDate"]
|
||||
);
|
||||
if ($resp["status"] != "OK") {
|
||||
$db_msg .= "|Err Promise Info : {$resp["message"]}";
|
||||
} else {
|
||||
$msg .= "\n" . $resp["message"];
|
||||
}
|
||||
$status[] = [
|
||||
"T_TxMessageT_TransactionID" => $r["T_OnlineTxOrgID"],
|
||||
"T_TxMessageT_OrderID" => $r["T_OnlineOrderT_OrderID"],
|
||||
"T_TxMessageNote" => $msg,
|
||||
"T_TxMessageCode" => "ORDER",
|
||||
];
|
||||
$counter++;
|
||||
$headerDate = $r["T_OrderHeaderDate"];
|
||||
$sql = "update t_onlineorder set T_OnlineOrderUploaded=?
|
||||
where T_OnlineOrderID = ?";
|
||||
$qry = $this->db->query($sql, [$headerDate, $r["T_OnlineOrderID"]]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Update Uploaded: {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (count($status) > 0) {
|
||||
//upload
|
||||
$url = $this->url . "status";
|
||||
$param = ["status" => $status];
|
||||
$z_param = gzdeflate(json_encode($param), 9);
|
||||
$resp = $this->post($url, $z_param);
|
||||
if ($resp["status"] == "OK") {
|
||||
$this->db->trans_commit();
|
||||
echo "{$this->now()} Upload Status Creation : $counter\n";
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR {$resp["message"]}\n";
|
||||
}
|
||||
} else {
|
||||
echo "{$this->now()} Upload Status Creation : $counter | 0 Status \n";
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
}
|
||||
|
||||
public function status_validasi()
|
||||
{
|
||||
echo "{$this->now()} Start Validasi Status\n";
|
||||
$this->db->trans_begin();
|
||||
$sql = "select
|
||||
T_OrderHeaderID, T_OrderHeaderLabNumberExt,
|
||||
T_OnlineOrderID, T_OnlineOrderT_OrderID, T_OnlineTxOrgID,
|
||||
max(T_OrderDetailValDate) maxDate
|
||||
from
|
||||
t_onlineorder
|
||||
join t_onlinetx on T_OnlineOrderT_OnlineTxID = T_OnlineTxID
|
||||
and T_OnlineOrderIsActive = 'Y'
|
||||
and T_OnlineTxIsActive = 'Y'
|
||||
join t_orderheader
|
||||
on T_OnlineOrderT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OnlineOrderUploaded is not null
|
||||
join pb_upload on pbUploadCode = 'VALIDASI'
|
||||
join t_orderheaderaddon
|
||||
on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
||||
and T_OrderHeaderAddOnIsActive = 'Y'
|
||||
and T_OrderHeaderAddOnValidationDone <> 'N'
|
||||
and T_OrderHeaderAddOnLastUpdated > pbUploadExecuted
|
||||
join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailValidation = 'Y'
|
||||
group by T_OrderHeaderID";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Status Validasi : {$this->db->error()["message"]}\n";
|
||||
return;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} No Status Validation\n";
|
||||
return;
|
||||
}
|
||||
$sql = "update pb_upload set pbUploadExecuted=now()
|
||||
where pbUploadCode = 'VALIDASI'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Update Uploaded: {$this->db->error()["message"]}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$status = [];
|
||||
$counter = 0;
|
||||
foreach ($rows as $r) {
|
||||
$headerID = $r["T_OrderHeaderID"];
|
||||
$maxDate = $r["maxDate"];
|
||||
$staffName = $this->get_validation_staff($headerID, $maxDate);
|
||||
$msg =
|
||||
"Nomor Registrasi : " . $r["T_OrderHeaderLabNumberExt"] . "\n";
|
||||
$msg .=
|
||||
"Sudah di validasi oleh $staffName pada " .
|
||||
$this->get_hari_id($maxDate);
|
||||
$status[] = [
|
||||
"T_TxMessageT_TransactionID" => $r["T_OnlineTxOrgID"],
|
||||
"T_TxMessageT_OrderID" => $r["T_OnlineOrderT_OrderID"],
|
||||
"T_TxMessageNote" => $msg,
|
||||
"T_TxMessageCode" => "VALIDATION",
|
||||
];
|
||||
|
||||
$counter++;
|
||||
}
|
||||
|
||||
if (count($status) > 0) {
|
||||
//upload
|
||||
$url = $this->url . "status";
|
||||
$param = ["status" => $status];
|
||||
$z_param = gzdeflate(json_encode($param), 9);
|
||||
$resp = $this->post($url, $z_param);
|
||||
if ($resp["status"] == "OK") {
|
||||
$this->db->trans_commit();
|
||||
echo "{$this->now()} Upload Status Validation : $counter\n";
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR {$resp["message"]}\n";
|
||||
}
|
||||
} else {
|
||||
echo "{$this->now()} Upload Status Validasi : $counter\n";
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
}
|
||||
public function get_validation_staff($headerID, $maxDate)
|
||||
{
|
||||
$sql = "select M_StaffName
|
||||
from
|
||||
t_orderdetail
|
||||
join m_user
|
||||
on T_OrderDetailT_OrderHeaderID = ?
|
||||
and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailValidation = 'Y'
|
||||
and T_OrderDetailValDate = ?
|
||||
and T_OrderDetailValUserID = M_UserID
|
||||
join m_staff on M_UserM_StaffID = M_StaffID";
|
||||
$qry = $this->db->query($sql, [$headerID, $maxDate]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Status Validasi : {$this->db->error()["message"]}\n";
|
||||
return "";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return "";
|
||||
}
|
||||
return $rows[0]["M_StaffName"];
|
||||
}
|
||||
|
||||
public function status_report($debug = "N")
|
||||
{
|
||||
echo "{$this->now()} Start Report Status\n";
|
||||
$this->db->trans_begin();
|
||||
$sql = "select
|
||||
M_BranchCode
|
||||
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";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR Update Status - Branch : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$branchCode = $rows[0]["M_BranchCode"];
|
||||
|
||||
$or_debug = "";
|
||||
/*
|
||||
if ($debug == "Y") {
|
||||
$or_debug =
|
||||
" or date(Result_ProcessToOfficeLastUpdated) >= date(now()) ";
|
||||
}
|
||||
*/
|
||||
$sql = "select T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderLabNumberExt, T_OrderHeaderID,
|
||||
T_OnlineOrderID, T_OnlineOrderT_OrderID,
|
||||
T_OnlineTxOrgID, max(Result_ProcessToOfficeLastUpdated) maxDate ,
|
||||
max(T_OrderHeaderAddonReadyPrintDate) maxPrintDate,
|
||||
T_OrderHeaderM_PatientID
|
||||
from t_onlineorder
|
||||
join t_onlinetx on T_OnlineOrderT_OnlineTxID = T_OnlineTxID
|
||||
and T_OnlineOrderIsActive = 'Y'
|
||||
and T_OnlineTxIsActive = 'Y'
|
||||
and T_OnlineOrderUploaded is not null
|
||||
join t_orderheader
|
||||
on T_OnlineOrderT_OrderHeaderID = T_OrderHeaderID
|
||||
and date(T_OrderHeaderDate) >= '2021-12-13'
|
||||
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
||||
join pb_upload
|
||||
on pbUploadCode = 'RESULT'
|
||||
join result_processtooffice on
|
||||
Result_ProcessToOfficeT_OrderHeaderID = T_OrderHeaderID
|
||||
and Result_ProcessToOfficeIsActive = 'Y'
|
||||
and (
|
||||
Result_ProcessToOfficeLastUpdated > pbUploadExecuted
|
||||
-- or
|
||||
-- T_OrderHeaderAddonReadyPrintDate > pbUploadExecuted
|
||||
)
|
||||
group by T_OrderHeaderID
|
||||
";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Status Report : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
echo $tot_row = count($rows);
|
||||
if ($tot_row == 0) {
|
||||
echo "{$this->now()} No Status Report : $tot_row \n";
|
||||
$sql = "update pb_upload set pbUploadExecuted=now()
|
||||
where pbUploadCode='RESULT'";
|
||||
$qry = $this->db->query($sql);
|
||||
$this->db->trans_commit();
|
||||
return;
|
||||
}
|
||||
$s_patientID = "0";
|
||||
foreach ($rows as $r) {
|
||||
$s_patientID .= "," . $r["T_OrderHeaderM_PatientID"];
|
||||
}
|
||||
//get patient
|
||||
$sql = "
|
||||
select M_PatientName,
|
||||
M_PatientDOB,
|
||||
M_PatientNoreg,
|
||||
M_PatientM_SexID,
|
||||
M_PatientJob,
|
||||
M_PatientM_IdTypeID,
|
||||
M_PatientIDNumber,
|
||||
T_OnlineOrderT_OrderID
|
||||
from m_patient
|
||||
join t_onlineorder
|
||||
on M_PatientID in ($s_patientID)
|
||||
and T_OnlineOrderM_PatientID = M_PatientID
|
||||
and T_OnlineOrderIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Report : Patient : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
|
||||
exit();
|
||||
}
|
||||
$patients = $qry->result_array();
|
||||
|
||||
|
||||
$status = [];
|
||||
$counter = 0;
|
||||
|
||||
echo "{$this->now()} Upload Status Report : \n";
|
||||
foreach ($rows as $r) {
|
||||
$headerID = $r["T_OrderHeaderID"];
|
||||
$reports = $this->get_report($headerID);
|
||||
if ($reports == []) {
|
||||
echo "\t\t" .
|
||||
$r["T_OrderHeaderLabNumber"] .
|
||||
" No Report Found\n";
|
||||
continue;
|
||||
}
|
||||
$arr_reports = [];
|
||||
$idx = 1;
|
||||
foreach ($reports as $xr) {
|
||||
if (trim($xr["url_rpt"]) == "-") {
|
||||
echo "\t {$r['T_OrderHeaderLabNumber']} : {$xr['Group_ResultName']} => Kosong \n";
|
||||
continue;
|
||||
}
|
||||
$rpt_url = "http://localhost/" . $xr["url_rpt"];
|
||||
$fname =
|
||||
$r["T_OnlineTxOrgID"] .
|
||||
"_" .
|
||||
$r["T_OnlineOrderT_OrderID"] .
|
||||
"_" .
|
||||
$xr["Group_ResultName"] .
|
||||
"_" .
|
||||
$r["T_OrderHeaderLabNumberExt"] .
|
||||
".pdf";
|
||||
$arr_reports[] = [
|
||||
"name" => $xr["Group_ResultName"],
|
||||
"branchCode" => $branchCode,
|
||||
"fname" => $fname,
|
||||
"content" => base64_encode(file_get_contents($rpt_url)),
|
||||
];
|
||||
$idx++;
|
||||
echo "\t {$r['T_OrderHeaderLabNumber']} => $fname : $rpt_url\n";
|
||||
}
|
||||
$msg =
|
||||
"Nomor Registrasi : " . $r["T_OrderHeaderLabNumberExt"] . "\n";
|
||||
$msg .= "Sudah selesai.";
|
||||
$status[] = [
|
||||
"T_TxMessageT_TransactionID" => $r["T_OnlineTxOrgID"],
|
||||
"T_TxMessageT_OrderID" => $r["T_OnlineOrderT_OrderID"],
|
||||
"T_TxMessageNote" => $msg,
|
||||
"reports" => $arr_reports,
|
||||
"T_TxMessageCode" => "RESULT",
|
||||
];
|
||||
$counter++;
|
||||
}
|
||||
|
||||
if (count($status) > 0) {
|
||||
$url = $this->url . "status";
|
||||
$param = ["status" => $status, "patients" => $patients];
|
||||
$z_param = gzdeflate(json_encode($param), 9);
|
||||
$resp = $this->post($url, $z_param);
|
||||
if ($resp["status"] == "OK") {
|
||||
$this->db->trans_commit();
|
||||
echo "{$this->now()} Upload Status Report : $counter\n{$resp["message"]}\n";
|
||||
foreach ($status["report"] as $r) {
|
||||
echo "{$this->now()} => $fname \n";
|
||||
}
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
echo "{$this->now()} ERR {$resp["message"]}\n";
|
||||
}
|
||||
} else {
|
||||
echo "{$this->now()} Upload Status Report : $counter\n";
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
//update pb_upload
|
||||
$sql = "update pb_upload set pbUploadExecuted=now()
|
||||
where pbUploadCode='RESULT'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Update Uploaded: {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
function get_report($headerID)
|
||||
{
|
||||
$sql = "select distinct
|
||||
Group_ResultID,Group_ResultName,
|
||||
Group_ResultFlagNonLab,IFNULL(T_EmailNonLabUrl,'-') EmailNonLabUrl,
|
||||
IF(T_EmailNonLabUrl IS NULL AND Group_ResultFlagNonLab = 'Y',' [Belum Pilih Format Hasil]','') temail
|
||||
from
|
||||
t_orderdetail
|
||||
join group_resultdetail
|
||||
on Group_ResultDetailT_TestID = T_OrderDetailT_TestID
|
||||
and T_OrderDetailIsActive = 'Y' and Group_ResultDetailIsActive = 'Y'
|
||||
and T_OrderDetailT_OrderHeaderID = ?
|
||||
join group_result
|
||||
on Group_ResultDetailGroup_ResultID = Group_ResultID
|
||||
and Group_ResultIsActive = 'Y'
|
||||
LEFT JOIN t_email_nonlab ON T_EmailNonLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_EmailNonLabType LIKE CONCAT('%',REPLACE(Group_ResultName, 'Elektromedik', 'electromedis'),'%')
|
||||
group by Group_ResultID";
|
||||
$qry = $this->db->query($sql, [$headerID]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} Error Ger Report : " .
|
||||
$this->db->error()["message"] .
|
||||
"|\n" .
|
||||
$this->db->last_query() .
|
||||
" \n";
|
||||
return [];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$ts = "&ts=" . date("Ymdhis");
|
||||
$id = $headerID;
|
||||
$result = [];
|
||||
|
||||
foreach ($rows as $r) {
|
||||
$xname = $r["Group_ResultName"];
|
||||
$name = $this->escape_fname($xname);
|
||||
$gid = $r["Group_ResultID"];
|
||||
$temail = $r["temail"];
|
||||
$isnonlab = $r["Group_ResultFlagNonLab"];
|
||||
$emailnonlaburl = str_replace(" ", "", $r["EmailNonLabUrl"]);
|
||||
if (strpos($emailnonlaburl, "fisik") > 0) {
|
||||
continue;
|
||||
}
|
||||
$report = "";
|
||||
switch ($gid) {
|
||||
case 1:
|
||||
$report =
|
||||
"/birt/frameset?__report=report/one/lab/rpt_test_email.rptdesign&__format=pdf&username=admin&PID=" .
|
||||
$id .
|
||||
$ts;
|
||||
break;
|
||||
case 2:
|
||||
$report =
|
||||
"/birt/frameset?__report=report/one/lab/rpt_hasil_papsmear_email.rptdesign&__format=pdf&username=admin&PID=" .
|
||||
$id .
|
||||
$ts;
|
||||
break;
|
||||
case 3:
|
||||
$report =
|
||||
"/birt/frameset?__report=report/one/lab/rpt_hasil_fna_email.rptdesign&__format=pdf&username=admin&PID=" .
|
||||
$id .
|
||||
$ts;
|
||||
break;
|
||||
case 4:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 5:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 6:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 7:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 8:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 9:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 10:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 11:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 12:
|
||||
$report =
|
||||
"/birt/frameset?__report=report/one/lab/rpt_hasil_lcprep_email.rptdesign&__format=pdf&username=admin&PID=" .
|
||||
$id .
|
||||
$ts;
|
||||
break;
|
||||
case 13:
|
||||
$report =
|
||||
"/birt/frameset?__report=report/one/lab/rpt_test_mikro_email.rptdesign&__format=pdf&username=admin&PID=" .
|
||||
$id .
|
||||
$ts;
|
||||
break;
|
||||
case 14:
|
||||
$report =
|
||||
"/birt/frameset?__report=report/one/lab/rpt_hasil_cytologi_email.rptdesign&__format=pdf&username=admin&PID=" .
|
||||
$id .
|
||||
$ts;
|
||||
break;
|
||||
case 15:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 16:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
case 17:
|
||||
$report = $emailnonlaburl;
|
||||
break;
|
||||
}
|
||||
$result[] = ["Group_ResultName" => $xname, "url_rpt" => $report];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function get_report_v1($headerID)
|
||||
{
|
||||
$sql = "SELECT
|
||||
distinct
|
||||
Group_ResultName,
|
||||
CASE
|
||||
WHEN Group_ResultID = 1 THEN
|
||||
CONCAT('/birt/frameset?__report=report/one/lab/rpt_test_email.rptdesign&__format=pdf&username=','regonline','&PID=',T_OrderHeaderID,'&ts=',UNIX_TIMESTAMP())
|
||||
WHEN Group_ResultID = 2 THEN
|
||||
CONCAT('/birt/frameset?__report=report/one/lab/rpt_hasil_papsmear_email.rptdesign&__format=pdf&username=','regonline','&PID=',T_OrderHeaderID,'&ts=',UNIX_TIMESTAMP())
|
||||
WHEN Group_ResultID = 3 THEN
|
||||
CONCAT('/birt/frameset?__report=report/one/lab/rpt_hasil_fna_email.rptdesign&__format=pdf&username=','regonline','&PID=',T_OrderHeaderID,'&ts=',UNIX_TIMESTAMP())
|
||||
WHEN Group_ResultID = 12 THEN
|
||||
CONCAT('/birt/frameset?__report=report/one/lab/rpt_hasil_lcprep_email.rptdesign&__format=pdf&username=','regonline','&PID=',T_OrderHeaderID,'&ts=',UNIX_TIMESTAMP())
|
||||
WHEN Group_ResultID = 13 THEN
|
||||
CONCAT('/birt/frameset?__report=report/one/lab/rpt_test_mikro_email.rptdesign&__format=pdf&username=','regonline','&PID=',T_OrderHeaderID,'&ts=',UNIX_TIMESTAMP())
|
||||
WHEN Group_ResultID = 14 THEN
|
||||
CONCAT('/birt/frameset?__report=report/one/lab/rpt_hasil_cytologi_email.rptdesign&__format=pdf&username=','regonline','&PID=',T_OrderHeaderID,'&ts=',UNIX_TIMESTAMP())
|
||||
END as url_rpt
|
||||
FROM t_orderheader
|
||||
JOIN t_orderdetail
|
||||
ON T_OrderHeaderID = ?
|
||||
AND T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
JOIN t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN group_resultdetail
|
||||
ON Group_ResultDetailT_TestID = T_TestID
|
||||
JOIN group_result
|
||||
ON Group_ResultDetailGroup_ResultID = Group_ResultID
|
||||
AND Group_ResultFlagNonLab = 'N'
|
||||
";
|
||||
$qry = $this->db->query($sql, [$headerID]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Get Report : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return [];
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function status_patient()
|
||||
{
|
||||
$sql = "select
|
||||
T_OnlineOrderT_OrderID,
|
||||
M_PatientID,
|
||||
M_PatientName
|
||||
M_PatientDOB,
|
||||
M_PatientM_SexID,
|
||||
M_PatientJob,
|
||||
M_PatientM_IdTypeID,
|
||||
M_PatientIDNumber,
|
||||
M_PatientUserID
|
||||
from t_onlineorder
|
||||
join pb_upload
|
||||
on pbUploadCode = 'PATIENT'
|
||||
join m_patient on T_OnlineOrderM_PatientID = M_PatientID
|
||||
and M_PatientIsActive = 'Y'
|
||||
and M_PatientLastUpdated > pbUploadExecuted
|
||||
";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Status Report : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} No Status Report\n";
|
||||
$sql = "update pb_upload set pbUploadExecuted=now()
|
||||
where pbUploadCode='RESULT'";
|
||||
$qry = $this->db->query($sql);
|
||||
$this->db->trans_commit();
|
||||
return;
|
||||
}
|
||||
//update pb_upload
|
||||
$sql = "update pb_upload set pbUploadExecuted=now()
|
||||
where pbUploadCode = 'PASIEN'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Update Uploaded: {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
$status = [];
|
||||
$counter = 0;
|
||||
}
|
||||
|
||||
public function get_hari_id($orderDate)
|
||||
{
|
||||
$bulan = [
|
||||
1 => "Januari",
|
||||
"Februari",
|
||||
"Maret",
|
||||
"April",
|
||||
"Mei",
|
||||
"Juni",
|
||||
"Juli",
|
||||
"Agustus",
|
||||
"September",
|
||||
"Oktober",
|
||||
"November",
|
||||
"Desember",
|
||||
];
|
||||
$tanggal = date("Y-m-d", strtotime($orderDate));
|
||||
$split = explode("-", $tanggal);
|
||||
$hari = $split[2] . " " . $bulan[(int) $split[1]] . " " . $split[0];
|
||||
$dow = date("l", strtotime($orderDate));
|
||||
switch ($dow) {
|
||||
case "Sunday":
|
||||
$dow = "Minggu";
|
||||
break;
|
||||
case "Monday":
|
||||
$dow = "Senin";
|
||||
break;
|
||||
case "Tuesday":
|
||||
$dow = "Selasa";
|
||||
break;
|
||||
case "Wednesday":
|
||||
$dow = "Rabu";
|
||||
break;
|
||||
case "Thursday":
|
||||
$dow = "Kamis";
|
||||
break;
|
||||
case "Friday":
|
||||
$dow = "Jumat";
|
||||
break;
|
||||
case "Saturday":
|
||||
$dow = "Sabtu";
|
||||
break;
|
||||
}
|
||||
$result = "";
|
||||
if ($dow != "") {
|
||||
$result .= $dow . ", ";
|
||||
}
|
||||
$result .= $hari . " jam " . date("H:i", strtotime($orderDate));
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function strip_unicode($inp)
|
||||
{
|
||||
$result = mb_convert_encoding($inp, "US-ASCII", "UTF-8");
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->status_order();
|
||||
sleep(5);
|
||||
$this->status_validasi();
|
||||
sleep(5);
|
||||
$this->status_report();
|
||||
sleep(5);
|
||||
$this->status_lunas();
|
||||
}
|
||||
function status_lunas() {
|
||||
echo "{$this->now()} Start Pelunasan Bayar di Tempat\n";
|
||||
$sql = "select pbUploadExecuted from pb_upload where pbUploadCode = 'LUNAS'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$sql = "insert into pb_upload(pbUploadCode,pbUploadExecuted) values('LUNAS',now())";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Init pb Upload Pelunasan bayar di tempat: {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$last_updated = "2021-11-01 00:00:01";
|
||||
} else {
|
||||
$last_updated = $rows[0]["pbUploadExecuted"];
|
||||
}
|
||||
echo "\t\tLast Updated : $last_updated\n";
|
||||
$sql = "select distinct T_OnlineTxOrgID, T_OnlineTxNumbering, T_OnlineTxBookingName
|
||||
from t_onlinetx
|
||||
join t_onlineorder on T_OnlineTxID = T_OnlineOrderT_OnlineTxID
|
||||
and T_OnlineTxIsLunas = 'Y'
|
||||
and T_OnlineTxLastUpdated > ?
|
||||
join t_orderheader on T_OrderHeaderID = T_OnlineOrderT_OrderHeaderID
|
||||
join f_payment on F_PaymentT_OrderHeaderID = T_OrderHeaderID
|
||||
join f_payment_orderheader on F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
||||
and F_Payment_OrderHeaderIsLunas = 'Y'
|
||||
join f_paymentdetail on F_PaymentID = F_PaymentDetailF_PaymentID
|
||||
and F_PaymentDetailM_PaymentTypeID <> 1000
|
||||
";
|
||||
$qry = $this->db->query($sql,[$last_updated]);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Get TxOnineID: {$this->db->error()["message"]}\n";
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "\t No Upload data\n";
|
||||
exit;
|
||||
}
|
||||
$url = $this->url . "status_lunas";
|
||||
$param = ["data" => $rows ];
|
||||
$z_param = gzdeflate(json_encode($param), 9);
|
||||
$resp = $this->post($url, $z_param);
|
||||
if ($resp["status"] == "OK") {
|
||||
$counter = count($rows);
|
||||
$sql = "update pb_upload set pbUploadExecuted = now() where pbUploadCode = 'LUNAS'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "Error update pb_upload : ". $this->db->error()["message"] . "\n";
|
||||
return;
|
||||
} else {
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
echo "{$this->now()} Upload Pelunasan bayar di tempat : $counter\n";
|
||||
} else {
|
||||
echo "{$this->now()} ERR Upload Pelunasan bayar di tempat : {$resp["message"]}\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function post($url, $data)
|
||||
{
|
||||
echo "{$this->now()} DEBUG : $url\n";
|
||||
$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/json",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$z_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 | $z_result",
|
||||
];
|
||||
}
|
||||
|
||||
$result = gzinflate($z_result);
|
||||
$j_result = json_decode($result, true);
|
||||
if (!$j_result) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "JSON invalid: $z_result",
|
||||
];
|
||||
}
|
||||
return $j_result;
|
||||
}
|
||||
|
||||
function escape_fname($xname)
|
||||
{
|
||||
$find = [" ", "&", '\r\n', '\n', "+", ","];
|
||||
$xname = str_replace($find, "-", $xname);
|
||||
|
||||
//delete and replace rest of special chars
|
||||
$find = ["/[^a-zA-Z0-9\-<>]/", "/[\-]+/", "/<[^>]*>/"];
|
||||
$repl = ["", "-", ""];
|
||||
$xname = preg_replace($find, $repl, $xname);
|
||||
return $xname;
|
||||
}
|
||||
}
|
||||
228
application/controllers/tools/regonline/Upload_price.php
Normal file
228
application/controllers/tools/regonline/Upload_price.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
class Upload_price extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->debug = false;
|
||||
}
|
||||
function now()
|
||||
{
|
||||
return Date("Y-m-d H:i:s");
|
||||
}
|
||||
public 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";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : No Default Branch\n";
|
||||
exit;
|
||||
}
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$branchName = $rows[0]["M_BranchName"];
|
||||
//Online Released MOU
|
||||
$sql = "select * from m_mou where
|
||||
M_MouIsReleased='Y' and
|
||||
M_MouIsOnline='Y'
|
||||
order by M_MouID desc";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Online Released MOU not found\n";
|
||||
exit;
|
||||
}
|
||||
$mou = $rows[0];
|
||||
$mouID = $mou["M_MouID"];
|
||||
|
||||
|
||||
//SsPrice MOU
|
||||
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mou["M_MouID"]));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "{$this->now()} ERR : Ss Price MOU not found\n";
|
||||
exit;
|
||||
}
|
||||
$ss_price_mou = $rows;
|
||||
|
||||
//Working
|
||||
$sql = "select $branchID M_RegPacketWorkM_BranchID,
|
||||
m_reg_packetwork.*, T_PacketName
|
||||
from m_reg_packetwork
|
||||
join t_packet on M_RegPacketWorkT_PacketID = T_PacketID
|
||||
where M_RegPacketWorkIsActive = 'Y'
|
||||
and M_RegPacketWorkM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_working = array();
|
||||
foreach ($rows as $r) {
|
||||
$arr_working[$r["T_PacketName"]] = true;
|
||||
}
|
||||
|
||||
|
||||
$sql = "select $branchID M_RegPacketWorkM_BranchID,
|
||||
m_reg_packetwork.*
|
||||
from m_reg_packetwork
|
||||
join t_packet on M_RegPacketWorkT_PacketID = T_PacketID
|
||||
and M_RegPacketWorkM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$reg_working = $qry->result_array();
|
||||
|
||||
//Sale
|
||||
$sql = "select $branchID M_RegPacketSaleM_BranchID,
|
||||
m_reg_packetsale.* , T_PacketName
|
||||
from m_reg_packetsale
|
||||
join t_packet on M_RegPacketSaleT_PacketID = T_PacketID
|
||||
where M_RegPacketSaleIsActive = 'Y'
|
||||
and M_RegPacketSaleM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_sell = array();
|
||||
foreach ($rows as $r) {
|
||||
$arr_sell[$r["T_PacketName"]] = true;
|
||||
}
|
||||
|
||||
$sql = "select $branchID M_RegPacketSaleM_BranchID,
|
||||
m_reg_packetsale.*
|
||||
from m_reg_packetsale
|
||||
join t_packet on M_RegPacketSaleT_PacketID = T_PacketID
|
||||
and M_RegPacketSaleM_MouID=?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$reg_sell = $qry->result_array();
|
||||
|
||||
|
||||
$s_packet = "-1";
|
||||
foreach ($ss_price_mou as $idx => $r) {
|
||||
$ss_price_mou[$idx]["Ss_PriceMouM_BranchID"] = $branchID;
|
||||
$is_sell = "N";
|
||||
$is_work = "N";
|
||||
$packetName = $r["T_TestName"];
|
||||
$packetID = $r["packet_id"];
|
||||
if ($packetID > 0) {
|
||||
if (isset($arr_working[$packetName])) $is_work = "Y";
|
||||
if (isset($arr_sell[$packetName])) $is_sell = "Y";
|
||||
}
|
||||
$ss_price_mou[$idx]["Ss_PriceMouIsSell"] = $is_sell;
|
||||
$ss_price_mou[$idx]["Ss_PriceMouIsWork"] = $is_work;
|
||||
$s_packet .= "," . $packetID;
|
||||
}
|
||||
|
||||
// echo "Packet Di di $branchName:\n";
|
||||
// foreach ($ss_price_mou as $r) {
|
||||
// if ($r["is_packet"] == "Y") {
|
||||
// echo $r["T_TestName"];
|
||||
// echo " , packet : : " . $r["packet_id"] . " , ";
|
||||
// echo " [ Cito : " . $r["T_PriceIsCito"] . "] : ";
|
||||
// echo " IsSell = " . $r["Ss_PriceMouIsSell"];
|
||||
// echo " , IsWork = " . $r["Ss_PriceMouIsWork"] . " \n";
|
||||
// }
|
||||
// }
|
||||
|
||||
// packet
|
||||
$sql = "select $branchID T_PacketM_BranchID, t_packet.*
|
||||
from t_packet where T_PacketID in ( $s_packet) ";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$packets = $qry->result_array();
|
||||
|
||||
$sql = "select $branchID T_PacketDetailM_BranchID, t_packetdetail.*
|
||||
from t_packetdetail
|
||||
where T_PacketDetailT_PacketID in ( $s_packet) and T_PacketDetailIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n";
|
||||
exit;
|
||||
}
|
||||
$packet_details = $qry->result_array();
|
||||
|
||||
$data = array(
|
||||
"ss_price_mou" => $ss_price_mou,
|
||||
"packet" => $packets,
|
||||
"working" => $reg_working,
|
||||
"sell" => $reg_sell,
|
||||
"detail" => $packet_details
|
||||
);
|
||||
$md5 = md5(json_encode($data));
|
||||
$param = array("md5" => $md5, "data" => $data);
|
||||
$z_param = gzdeflate(json_encode($param), 9);
|
||||
|
||||
$url = "https://regonline.pramita.co.id/one-api/tools/regonline/r_price";
|
||||
$resp = $this->post($url, $z_param);
|
||||
print_r($resp);
|
||||
}
|
||||
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, array(
|
||||
'Content-Type: application/octet-stream',
|
||||
'Content-Length: ' . strlen($data)
|
||||
));
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch) > 0) {
|
||||
return array(
|
||||
"status" => "ERR",
|
||||
"message" => curl_error($ch)
|
||||
);
|
||||
}
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode != 200) {
|
||||
return array(
|
||||
"status" => "ERR",
|
||||
"message" => "Http Response : $httpCode"
|
||||
);
|
||||
}
|
||||
$j_result = json_decode($result, true);
|
||||
if (!$j_result) {
|
||||
return array(
|
||||
"status" => "ERR",
|
||||
"message" => "JSON invalid: $result"
|
||||
);
|
||||
}
|
||||
return $j_result;
|
||||
}
|
||||
}
|
||||
39
application/controllers/tools/regonline/Viewlog.php
Normal file
39
application/controllers/tools/regonline/Viewlog.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class Viewlog extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function read_log($logfile)
|
||||
{
|
||||
$fp = fopen("/tmp/$logfile", 'r');
|
||||
$pos = -1; // Skip final new line character (Set to -1 if not present)
|
||||
|
||||
$lines = array();
|
||||
$currentLine = '';
|
||||
$idx = 0;
|
||||
$msg = "<pre>";
|
||||
while (-1 !== fseek($fp, $pos, SEEK_END)) {
|
||||
$char = fgetc($fp);
|
||||
if (PHP_EOL == $char) {
|
||||
$msg .= $currentLine;
|
||||
$currentLine = '';
|
||||
} else {
|
||||
$currentLine = $char . $currentLine;
|
||||
}
|
||||
$pos--;
|
||||
$idx++;
|
||||
if ($idx > 1000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$msg .= "</pre>";
|
||||
return $msg;
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo $this->read_log("log-order-regonline.log");
|
||||
}
|
||||
}
|
||||
7
application/controllers/tools/regonline/x-collect.sh
Normal file
7
application/controllers/tools/regonline/x-collect.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
d="2020-12-22"
|
||||
while [ "$d" != "2021-01-01" ] ; do
|
||||
echo "Processing $d"
|
||||
/usr/bin/php /home/one/project/one/one-api/index.php tools regonline heartbeat process $d
|
||||
d=$(date -d "$d + 1 day" +"%Y-%m-%d")
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user