Files
2026-04-27 10:26:26 +07:00

784 lines
28 KiB
PHP

<?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);
}
}