session_start(); $_SESSION['UserId']=4468; $_SESSION['sys_group_id']=4493; include_once('C:/myxamdev/htdocs/newtracking/config.php'); //include_once(__DOCUMENT_ROOT."/include/header.php"); //include_once(__DOCUMENT_ROOT.'/reports/private/master.php'); include_once(__DOCUMENT_ROOT.'/reports/private/common.php'); $connu = mysqli_connect(__DB_HOST_STAGING, __DB_USER_STAGING, __DB_PASSWORD_STAGING,__DB_DATABASE_STAGING); function Get_LatLng_From_Google_Maps($address) { //echo $address; $LatLng = array( 'lat' => '0.0', 'lng' => '0.0', ); $Poito="select * from matrix.`pois` where sys_user_id=".$_SESSION['UserId']." and name like '%".trim($address)."%'"; $IsexistPoito=db__select($Poito); //print_r( $Isexist_countpoito=count($IsexistPoito); if($Isexist_countpoito>0) { $LatLng = array( 'lat' => $IsexistPoito[0]["gps_latitude"], 'lng' => $IsexistPoito[0]["gps_longitude"], ); } else { If(trim($address)=="UP BORDER") { $LatLng = array( 'lat' => '28.676298141', 'lng' => '77.330680847', ); } else { if($_SESSION['sys_group_id']=='49311110') { $address=str_Replace(" ","+",$address); $url = "https://maps.googleapis.com/maps/api/geocode/json?address=$address&sensor=false"; // Make the HTTP request $data = @file_get_contents($url); // Parse the json response $jsondata = json_decode($data,true); //print_r($jsondata);die(); // If the json data is invalid, return empty array //if (!check_status($jsondata)) return array(); $LatLng = array( 'lat' => $jsondata["results"][0]["geometry"]["location"]["lat"], 'lng' => $jsondata["results"][0]["geometry"]["location"]["lng"], ); } } } return $LatLng; } $UserId = $_SESSION['UserId']; $tableName="tripbyclient"; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.affablesolution.com/api/VLT/TruckData", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_POSTFIELDS => "", CURLOPT_HTTPHEADER => array( "Postman-Token: 07b0a14d-752e-4e9a-a963-02bcfb37db10", "cache-control: no-cache" ), curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0), curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0), curl_setopt($curl, CURLINFO_HEADER_OUT, true), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); // echo "
";
// print_r(json_decode($response));
// echo 1;die;
if ($err) {
echo "cURL Error #:" . $err;
} else {
//echo $response;
$data=json_decode($response);
$VehicleidQry="select * from group_services where group_services.active=true and sys_group_id=".$_SESSION['sys_group_id'];
$VehicleId = db__select($VehicleidQry, "");
$_SESSION['Total_vehicle']=count($VehicleId);
if(count($VehicleId)>0){
foreach($VehicleId as $key=>$value){
$_SESSION['vehId'].=$value['sys_service_id'].",";
}
$_SESSION['vehId']=substr($_SESSION['vehId'],0,strlen($_SESSION['vehId'])-1);
}
//echo $_SESSION['vehId'];die;
$condition = "";
$update = db__select("UPDATE tripbyclient SET status =0 WHERE sys_service_id in (".$_SESSION['vehId'].")","");
//count($data)
for ($i=0; $i ch_no;
// $data[$i]->ch_date;
// $data[$i]->load_station;
// $data[$i]->ch_dest;
// $data[$i]->truck_no;
$source_lat=0.0;
$source_long=0.0;
$destin_lat=0.0;
$destin_long=0.0;
$date=date('Y-m-d H:i:s',(strtotime ($data[$i]->ch_date)));
$source= explode(" ", $data[$i]->load_station);
$destin= explode(" ", $data[$i]->ch_dest);
/*$sourcelatlong=Get_LatLng_From_Google_Maps(trim($source[0]));
$destinlatlong=Get_LatLng_From_Google_Maps(trim($destin[0]));
$source_lat=$sourcelatlong['lat'];
echo $source_long=$sourcelatlong['long'];
$destin_lat=$destinlatlong['lat'];
echo $destin_long=$destinlatlong['long'];*/
//echo "select id from matrix.services where veh_reg='".$data[$i]->truck_no."'";
$vehicle_no = db__select("select id from matrix.services where veh_reg='".$data[$i]->truck_no."'", $condition);
$sys_service_id = $vehicle_no[0]["id"];
$checking = db__select("select * from matrix.".$tableName." where lorry_no='".$data[$i]->truck_no."' and challan_no='".$data[$i]->ch_no."' ", $condition);
//$checking_new = mysqli_query($connu,"SELECT * FROM ".$tableName." where lorry_no='".$data[$i]->truck_no."' and challan_no='".$data[$i]->ch_no."' ");
$arivalkmhr = file_get_contents("https://yatayaat.in/newtracking/reports/getjourney_hours_viareact.php?source=".str_replace(' ','%20',$data[$i]->load_station)."&destination=".str_replace(' ','%20',$data[$i]->ch_dest)."&via=true&viaone=&viatwo=&viathree=&viafour=&routetype=normal&viaone_halthr_input=&viatwo_halthr_input=&viathree_halthr_input=&viafour_tillkm=");
//echo 1;die;
$arivalkmhrArr = explode("##",$arivalkmhr);
//echo "";
//print_r($arivalkmhr);
$arivalkm = $arivalkmhrArr[0];
$arivalhr = $arivalkmhrArr[1];
//print_r($arivalkmhr);
//die;
$arrivaldate = date('Y-m-d H:i:s',strtotime('+'.$arivalhr.' hour',strtotime($data[$i]->ch_date)));
//echo $arrivaldate."
";die;
//$arrivaldate = date('Y-m-d H:i:s',strtotime('+40 hour',strtotime($data[$i]->ch_date)));
//echo "INSERT INTO tripbyclient SET sys_user_id = '".$UserId."', lorry_no='".$data[$i]->truck_no."', sys_service_id='".$sys_service_id."' , challan_no='".$data[$i]->ch_no."', challan_date='".$date."', arrival_date='".$arrivaldate."',departure_date='".$date."', station_from_location='".$data[$i]->load_station."',station_from_lat='".$source_lat."',station_from_long='".$source_long."', station_to_location='".$data[$i]->ch_dest."',station_to_lat='".$destin_lat."',station_to_long='".$destin_long."', status=1 ";die;
if(count($checking)>0)
{
//echo 1;
echo "UPDATE matrix.tripbyclient SET status =1, arrival_date='".$arrivaldate."', totaltripkmbygoogle='".$arivalkm."' WHERE lorry_no='".$data[$i]->truck_no."' and challan_no='".$data[$i]->ch_no."' and sys_user_id='4468' "."
";
$update = db__select("UPDATE matrix.tripbyclient SET status =1, arrival_date='".$arrivaldate."', totaltripkmbygoogle='".$arivalkm."' WHERE lorry_no='".$data[$i]->truck_no."' and challan_no='".$data[$i]->ch_no."' and sys_user_id='4468' ","");
if($update){
echo "updated--".$i."
";
}
}else{
$insert =db__insert("matrix.tripbyclient", array(
'sys_user_id' => $UserId,
'lorry_no' => $data[$i]->truck_no,
'sys_service_id' => $sys_service_id,
'challan_no' => $data[$i]->ch_no,
'challan_date' => $date,
'arrival_date' => $arrivaldate,
'totaltripkmbygoogle' => $arivalkm,
'departure_date' => $date,
'station_from_location' => $data[$i]->load_station,
'station_from_lat' => $source_lat,
'station_from_long' => $source_long,
'station_to_location' => $data[$i]->ch_dest,
'station_to_lat' => $destin_lat,
'station_to_long' => $destin_long,
'status' => '1'
)
);
if ($insert) {
echo "inserted--".$i."
";
}
}
}//for Loop
} // else curl