212 lines
7.1 KiB
PHP
212 lines
7.1 KiB
PHP
<?php
|
|
class Updateprocessresult extends MY_Controller
|
|
{
|
|
var $db;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
function index()
|
|
{
|
|
echo "Api: UPDATE STATUS PROSES & HASIL";
|
|
}
|
|
function reply($resp)
|
|
{
|
|
echo json_encode($resp);
|
|
}
|
|
|
|
function reply_gz($resp, $debug = "")
|
|
{
|
|
if ($debug != "") {
|
|
echo json_encode($resp);
|
|
} else {
|
|
echo gzcompress(json_encode($resp));
|
|
}
|
|
}
|
|
|
|
function get_param()
|
|
{
|
|
$body = file_get_contents("php://input");
|
|
return json_decode($body, true);
|
|
}
|
|
|
|
function get_param_z()
|
|
{
|
|
$body_z = file_get_contents("php://input");
|
|
$body = gzuncompress($body_z);
|
|
return json_decode($body, true);
|
|
}
|
|
public function getRegionalIPAddress()
|
|
{
|
|
$sql_get = "SELECT S_SystemIPAddressRegional
|
|
FROM conf_systems
|
|
WHERE S_SystemsIsActive = 'Y'";
|
|
|
|
$qry = $this->db->query($sql_get);
|
|
if (!$qry) {
|
|
$this->sys_error_db("get ip regional failed", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
|
|
$data = $qry->result_array();
|
|
return $data[0]['S_SystemIPAddressRegional'];
|
|
}
|
|
function updateprocess($date = "")
|
|
{
|
|
try {
|
|
if ($date == "") {
|
|
$date = date("Y-m-d");
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$getIPRegionalAddress = $this->getRegionalIPAddress();
|
|
|
|
|
|
$sql = "SELECT GROUP_CONCAT(DISTINCT T_OrderID) AS ID
|
|
FROM one_mitra.t_order
|
|
JOIN future_map ON T_OrderFutureOrderID = FutureMapFutureOrderID AND FutureMapIsActive = 'Y' AND T_OrderIsActive = 'Y'
|
|
JOIN t_orderheader ON T_OrderHeaderID = FutureMapT_OrderHeaderID AND T_OrderHeaderIsActive = 'Y'
|
|
JOIN t_ordersample ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND T_OrderSampleIsActive = 'Y'
|
|
WHERE
|
|
date(T_OrderHeaderDate) = ?
|
|
AND
|
|
(T_OrderStatus <> 'P' AND T_OrderStatus <> 'R')";
|
|
$qry = $this->db->query($sql, [$date]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("", $this->db->error());
|
|
exit;
|
|
}
|
|
$statusOrder = $qry->result_array();
|
|
|
|
$data = [
|
|
"order" => $statusOrder,
|
|
];
|
|
|
|
$z_param = gzcompress(json_encode($data));
|
|
$resp = $this->post("http://$getIPRegionalAddress/one-api/one_mitra/Updateprocessresult/updateprocess", $z_param);
|
|
$resultUnc = gzuncompress($resp);
|
|
$result = json_decode($resultUnc, true);
|
|
// $this->sys_ok($result);
|
|
// exit;
|
|
|
|
|
|
$successOrder = $result['order']['success'];
|
|
for ($i = 0; $i < count($successOrder); $i++) {
|
|
$sql = "UPDATE one_mitra.t_order
|
|
SET T_OrderStatus = 'P'
|
|
WHERE T_OrderID = ?
|
|
AND T_OrderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql, [$successOrder[$i]]);
|
|
if (!$qry) {
|
|
$this->sys_error_db($this->db->error());
|
|
exit;
|
|
}
|
|
}
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function updateresult($date = "")
|
|
{
|
|
try {
|
|
if ($date == "") {
|
|
$date = date("Y-m-d");
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$getIPRegionalAddress = $this->getRegionalIPAddress();
|
|
|
|
|
|
$sql = "SELECT GROUP_CONCAT(DISTINCT T_OrderID) AS ID
|
|
FROM one_mitra.t_order
|
|
JOIN future_map ON T_OrderFutureOrderID = FutureMapFutureOrderID AND FutureMapIsActive = 'Y' AND T_OrderIsActive = 'Y'
|
|
JOIN t_orderheader ON T_OrderHeaderID = FutureMapT_OrderHeaderID AND T_OrderHeaderIsActive = 'Y'
|
|
JOIN t_ordersample ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND T_OrderSampleIsActive = 'Y'
|
|
JOIN result_processtooffice ON Result_ProcessToOfficeT_OrderHeaderID = T_OrderHeaderID AND Result_ProcessToOfficeIsActive = 'Y'
|
|
WHERE
|
|
date(T_OrderHeaderDate) = ?
|
|
AND
|
|
(T_OrderStatus = 'P' AND T_OrderStatus <> 'R')";
|
|
$qry = $this->db->query($sql, [$date]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("", $this->db->error());
|
|
exit;
|
|
}
|
|
$statusOrder = $qry->result_array();
|
|
|
|
$data = [
|
|
"order" => $statusOrder,
|
|
];
|
|
|
|
$z_param = gzcompress(json_encode($data));
|
|
$resp = $this->post("http://$getIPRegionalAddress/one-api/one_mitra/Updateprocessresult/updateresult", $z_param);
|
|
$resultUnc = gzuncompress($resp);
|
|
$result = json_decode($resultUnc, true);
|
|
// $this->sys_ok($result);
|
|
// exit;
|
|
|
|
|
|
$successOrder = $result['order']['success'];
|
|
for ($i = 0; $i < count($successOrder); $i++) {
|
|
$sql = "UPDATE one_mitra.t_order
|
|
SET T_OrderStatus = 'R'
|
|
WHERE T_OrderID = ?
|
|
AND T_OrderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql, [$successOrder[$i]]);
|
|
if (!$qry) {
|
|
$this->sys_error_db($this->db->error());
|
|
exit;
|
|
}
|
|
}
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function post($url, $data)
|
|
{
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Content-Type: application/text",
|
|
"Content-Length: " . strlen($data),
|
|
]);
|
|
$result = curl_exec($ch);
|
|
if (curl_error($ch) != "") {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Http Error : " . curl_error($ch),
|
|
]);
|
|
curl_close($ch);
|
|
exit();
|
|
}
|
|
curl_close($ch);
|
|
return $result;
|
|
}
|
|
function convertobjtoarr($data)
|
|
{
|
|
|
|
if (is_object($data)) {
|
|
$data = get_object_vars($data);
|
|
}
|
|
|
|
if (is_array($data)) {
|
|
return array_map(__FUNCTION__, $data);
|
|
} else {
|
|
return $data;
|
|
}
|
|
}
|
|
}
|