db->query($sql,$date); if (! $qry) { echo "Err :" ; print_r($this->db->error()); exit; } $rows = $qry->result_array(); if (count($rows) == 0 ) { echo "Err : No Branch."; exit; } $branchCode = $rows[0]["M_BranchCode"]; $branchName = $rows[0]["M_BranchName"]; $prm = $this->sys_input; $originBranch = $prm["branchCode"]; $s_order = "'0x0'"; $result = array(); foreach($prm["order"] as $d) { if($s_order != "" ) $s_order .= ","; $s_order .= "'" . $d . "'"; $result[$d] = array("Tx" => "Y" , "Rx" => "N"); } $sql = "select * from incoming_ref where incomingRefOriginM_BranchCode=? and incomingRefT_RefDeliveryOrderNumber in ( $s_order ) "; $qry = $this->db->query($sql, array($originBranch)); if (! $qry ) { echo json_encode(array("status" => "ERR" , "message" => print_r($this->db->error(),true))); } $rows = $qry->result_array(); foreach($rows as $r) { $result[$r["incomingRefT_RefDeliveryOrderNumber"]]["Rx"] = "Y"; } echo json_encode( array("status"=>"OK" , "branchName" => $branchName, "data" => $result)); } function cek($date = "") { if ($date == "" ) $date = date("Y-m-d"); $sql = "select * from m_branch where M_BranchIsDefault = 'Y' and M_BranchIsActive = 'Y'"; $qry = $this->db->query($sql,$date); if (! $qry) { echo "Err :" ; print_r($this->db->error()); exit; } $rows = $qry->result_array(); if (count($rows) == 0 ) { echo "Err : No Branch."; exit; } $branchCode = $rows[0]["M_BranchCode"]; $sql = "select group_concat(T_RefDeliveryOrderNumber separator '^') as Nomor, M_BranchIPAddress from t_ref_deliveryorder join m_branch on T_RefDeliveryOrderM_DestinationID = M_BranchID where T_RefDeliveryOrderIsActive = 'Y' and (T_RefDeliveryOrderIsConfirm = 'S' ) and ( date(T_RefDeliveryOrderLastUpdated) = ? ) group by M_BranchCode limit 0,50 "; $qry = $this->db->query($sql,$date); if (! $qry) { echo "Err :" ; print_r($this->db->error()); exit; } $rows = $qry->result_array(); foreach($rows as $r) { $ip_address = $r["M_BranchIPAddress"]; $a_nomor = explode("^",$r["Nomor"]); $url = "http://$ip_address/one-api/fix/merujuk/verify"; $date = date("Y-m-d H:i:s"); echo "\n$date Check : $url\n"; $param = json_encode( array("branchCode" => $branchCode , "order" => $a_nomor)); $result = $this->post($url,$param); $j_result = json_decode($result,true); if (! $j_result ) { echo "\t $result\n"; continue; } if ($j_result["status"] == "ERR" ) { echo "\t {$j_result['message']}\n"; continue; } echo "\t {$j_result['branchName']}\n"; foreach($a_nomor as $n) { if ($j_result["data"][$n]["Rx"] == "N" ) { $sql = "select * from t_ref_deliveryorder where T_RefDeliveryOrderNumber= '$n'"; $qry = $this->db->query($sql); $xid = 0; $xstatus = ""; if ($qry) { $xrows = $qry->result_array(); if(count($xrows) > 0 ) { $xid = $xrows[0]["T_RefDeliveryOrderID"]; $xstatus = $xrows[0]["T_RefDeliveryOrderIsConfirm"]; $sql = "update t_ref_deliveryorder set T_RefDeliveryOrderIsConfirm = 'Y' where T_RefDeliveryOrderID = $xid"; $this->db->query($sql); } } else { print_r($this->db->error()); } echo "\t{$n} sent not received | $xid | $xstatus \n"; } else { if ($j_result["data"][$n]["Rx"] == "Y" ) { echo "\t{$n} sent received\n"; } else { echo "\t{$n} sent not received\n"; } } } } } 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_VERBOSE, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data)) ); $result = curl_exec($ch); //echo "RST : $result "; return $result; } }