131 lines
4.8 KiB
Plaintext
131 lines
4.8 KiB
Plaintext
<?php
|
|
class Uploadtocenter extends MY_Controller
|
|
{
|
|
var $db;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_inventory = $this->load->database("inventory", true);
|
|
$this->db_inventory_log = $this->load->database('inventory_log', true);
|
|
$this->db_onex = 'one_aditya';
|
|
}
|
|
|
|
function get_example()
|
|
{
|
|
$sql = "SELECT mutasirequest.*,'' details
|
|
FROM `mutasirequest`
|
|
WHERE
|
|
MutasiRequestID = 2";
|
|
//echo $sql;
|
|
$qry = $this->db_inventory->query($sql);
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasirequest error", $this->db_inventory->last_query());
|
|
exit;
|
|
|
|
}
|
|
//echo $sql;
|
|
$data_get = $qry->row_array();
|
|
if($data_get){
|
|
$sql = "SELECT mutasirequestdetail.*
|
|
FROM `mutasirequestdetail`
|
|
WHERE
|
|
MutasiRequestDetailMutasiRequestID = {$data_get['MutasiRequestID']}";
|
|
//echo $sql;
|
|
$qry = $this->db_inventory->query($sql);
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasirequestdetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
|
|
}
|
|
$datas = $qry->result_array();
|
|
$data_get['details'] = $datas;
|
|
}
|
|
|
|
echo json_encode($data_get);
|
|
}
|
|
|
|
function upload_data()
|
|
{
|
|
try {
|
|
$sql = "SELECT mutasirequest_upload.*, M_BranchIPAddress as branch_ip
|
|
FROM `mutasirequestrespon`
|
|
JOIN `companyaddress` ON MutasiRequestUploadFromCompanyAddressID = CompanyAddressID
|
|
JOIN `company` ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.`m_branch` ON CompanyM_BranchID = M_BranchID
|
|
WHERE
|
|
MutasiRequestUploadIsSent = 'N'";
|
|
//echo $sql;
|
|
$qry = $this->db_inventory->query($sql);
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasirequestrespon error", $this->db_inventory->last_query());
|
|
exit;
|
|
|
|
}
|
|
$data_get = $qry->result_array();
|
|
if($data_get){
|
|
|
|
//API URL
|
|
$url="http://".$data_get[0]['branch_ip']."/one-api/inventory/mutasirequest/downloadfrombranch/download_data";
|
|
$data = $qry->result_array();
|
|
|
|
$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'];
|
|
//print_r($data_respon['records']);
|
|
if(count($data_respon['records']) > 0){
|
|
foreach ($data_respon['records'] as $key => $value) {
|
|
$sql = "UPDATE mutasirequest_upload SET
|
|
MutasiRequestUploadIsSent = 'Y'
|
|
WHERE MutasiRequestUploadID = ?";
|
|
$qry = $this->db_inventory->query($sql,[$value]);
|
|
if(!$qry){
|
|
$this->sys_error_db("update mutasirequestrespon MutasiRequestUploadIsSent = Y error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
$result = array( "records" => $data_respon['records']);
|
|
$this->sys_ok($result);
|
|
}
|
|
}
|
|
}
|
|
} 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;
|
|
}
|
|
|
|
}
|