158 lines
6.1 KiB
PHP
158 lines
6.1 KiB
PHP
<?php
|
|
|
|
class Senddata extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "BAHAN API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("nasional", true);
|
|
}
|
|
|
|
|
|
function Get($code){
|
|
try {
|
|
$sql = "SELECT Nat_CompanyNumber,
|
|
nat_mou.*,
|
|
'' as prices,
|
|
'' as packets,
|
|
'' as packetdetails
|
|
FROM nat_mou
|
|
JOIN nat_company ON Nat_MouNat_CompanyID = Nat_CompanyID
|
|
WHERE
|
|
Nat_MouNumber = '{$code}' AND Nat_MouIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rtn = $this->db_onedev->query($sql)->row_array();
|
|
//echo $this->db_onedev->getLastQuery();
|
|
if($rtn){
|
|
$sql = "SELECT t_price.*
|
|
FROM t_price
|
|
WHERE
|
|
T_PriceNat_CompanyID = {$rtn['Nat_MouNat_CompanyID']} AND T_PriceNat_MouID = {$rtn['Nat_MouID']} AND
|
|
T_PriceIsActive = 'Y'";
|
|
$prices = $this->db_onedev->query($sql)->result_array();
|
|
$rtn['prices'] = $prices;
|
|
|
|
$sql = "SELECT t_packet.*
|
|
FROM t_packet
|
|
WHERE
|
|
T_PacketNat_CompanyID = {$rtn['Nat_MouNat_CompanyID']} AND T_PacketNat_MouID = {$rtn['Nat_MouID']} AND T_PacketIsActive = 'Y'";
|
|
$packets = $this->db_onedev->query($sql)->result_array();
|
|
$rtn['packets'] = $packets;
|
|
|
|
$sql = "SELECT t_packetdetail.*
|
|
FROM t_packetdetail
|
|
JOIN t_packet ON T_PacketDetailT_PacketID = T_PacketID AND
|
|
T_PacketNat_CompanyID = {$rtn['Nat_MouNat_CompanyID']} AND T_PacketNat_MouID = {$rtn['Nat_MouID']} AND T_PacketIsActive = 'Y'
|
|
WHERE
|
|
T_PacketDetailIsActive = 'Y'";
|
|
$packetdetails = $this->db_onedev->query($sql)->result_array();
|
|
$rtn['packetdetails'] = $packetdetails;
|
|
|
|
return $rtn;
|
|
}else{
|
|
return [];
|
|
}
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function Send($mouConfirmID, $userID)
|
|
{
|
|
try {
|
|
$sql = "SELECT Mou_ConfirmDetailID,
|
|
Nat_MouNumber,
|
|
S_RegionalUrl
|
|
FROM mou_confirm
|
|
JOIN mou_confirmdetail ON Mou_ConfirmDetailMou_ConfirmID = Mou_ConfirmID AND
|
|
Mou_ConfirmDetailStatus = 'N' AND
|
|
Mou_ConfirmDetailIsActive = 'Y'
|
|
JOIN s_regional ON Mou_ConfirmDetailS_RegionalID = S_RegionalID
|
|
JOIN nat_mou ON Mou_ConfirmNat_MouID = Nat_MouID
|
|
WHERE
|
|
Mou_ConfirmID = {$mouConfirmID} AND Mou_ConfirmStatus <> 'done' AND Mou_ConfirmIsActive = 'Y'
|
|
GROUP BY Mou_ConfirmDetailID";
|
|
$data_set = $this->db_onedev->query($sql)->result_array();
|
|
//print_r($data_set);
|
|
if($data_set){
|
|
$rtn = [];
|
|
$data_get = $this->Get($data_set[0]['Nat_MouNumber']);
|
|
//print_r($data_get);
|
|
foreach ($data_set as $key => $value) {
|
|
//API URL
|
|
$url="http://".$value['S_RegionalUrl']."/one-api/nasacom/downloaddata/downloadfromnational";
|
|
$data = $data_get;
|
|
//echo $url;
|
|
$ch = curl_init( $url );
|
|
# Setup request to send json via POST.
|
|
$payload = json_encode( $data );
|
|
|
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($payload))
|
|
);
|
|
# Return response instead of printing.
|
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
|
# Send request.
|
|
$result = curl_exec($ch);
|
|
curl_close($ch);
|
|
# Print response.
|
|
$array_rst = $this->objToArray(json_decode($result));
|
|
//print_r($result);
|
|
if($array_rst['status'] == 'OK'){
|
|
$data_respon = $array_rst['data'];
|
|
$sql = "UPDATE mou_confirmdetail SET
|
|
Mou_ConfirmDetailStatus = 'Y',
|
|
Mou_ConfirmDetailLastUpdated = NOW(),
|
|
Mou_ConfirmDetailUpdateUserID = {$userID}
|
|
WHERE Mou_ConfirmDetailID = {$value['Mou_ConfirmDetailID']}";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if(!$qry){
|
|
$this->sys_error_db("update mou_confirmdetail Mou_ConfirmDetailStatus = Y error", $this->db_onedev->last_query());
|
|
exit;
|
|
}
|
|
array_push($rtn,$data_respon);
|
|
}
|
|
}
|
|
|
|
$result = array( "records" => $rtn);
|
|
$this->sys_ok($result);
|
|
}
|
|
else{
|
|
$message = "ID tidak ditemukan !";
|
|
$this->sys_error($message);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
protected function objToArray($obj)
|
|
{
|
|
// Not an object or array
|
|
if (!is_object($obj) && !is_array($obj)) {
|
|
return $obj;
|
|
}
|
|
|
|
// Parse array
|
|
foreach ($obj as $key => $value) {
|
|
$arr[$key] = $this->objToArray($value);
|
|
}
|
|
|
|
// Return parsed array
|
|
return $arr;
|
|
}
|
|
|
|
|
|
}
|