
import { environment } from '../environments/environment';
import { Injectable } from '@angular/core';
import{Http, Headers,Response, ResponseContentType} from '@angular/http';
import 'rxjs/add/operator/map';
import {Contact} from './contact';
import {Map} from './map';
import {Temp} from './temp';
import {Device} from './device';
import {Graph} from './graph';
import {Token} from './token';
import {Matrix} from './matrix';
import {Otp_log} from './otp_log'
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';

import * as io from 'socket.io-client';
import { Schedule } from './shedule';
import { Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs';
import { IdleReportComponent } from './device-report/idle-report/idle-report.component';
import { map, take } from 'rxjs/operators';


@Injectable()
export class ContactService {
totalTicketCount:BehaviorSubject<number> = new BehaviorSubject<number>(10);

 dev_url = environment.hostUrl;
 dev_url2= environment.hostUrl2
 //dev_url = 'http://localhost:3000';
userToken  = localStorage.getItem('token');
headersVal = new Headers();
// tempDevobject:any ={};

public menuReturnFlag:any='';
  tempData: any;
  languages: string[];
  Output_languages: string[];
  private messageSource = new BehaviorSubject('');
  currentMessage = this.messageSource.asObservable();
  constructor(private http: Http, private router: Router) {
  
  this.languages = ['en','es'];


   }
// retrieving
/*
https://roads.googleapis.com/v1/snapToRoads?path=&interpolate=true&key=AIzaSyBLNw1Bop4CPvxZV9MmxgYc9pog2Pcx8nA
https://roads.googleapis.com/v1/snapToRoads?path=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796&interpolate=true&key=AIzaSyBLNw1Bop4CPvxZV9MmxgYc9pog2Pcx8nA
*/
/* Location(f){
   return this.http.get('https://roads.googleapis.com/v1/snapToRoads?path='+f+'&interpolate=true&key=AIzaSyBLNw1Bop4CPvxZV9MmxgYc9pog2Pcx8nA')
   .map(res => res.json());
}
http://localhost:3000/gps/getGpsSpeedReport?imei=087074133830
*/







menuReturnGet(){
  return localStorage.menuReturnFlag;
}
menuReturnSet(id){
  localStorage.menuReturnFlag = id;
  this.menuReturnFlag = id;
  return localStorage.menuReturnFlag;
}
dealerInfo(url){
  console.log("url at point of api trigger=>",url);

  return this.http.get(this.dev_url  + '/users/getDealerInfo?&url='+url)
  .map(res => res.json());
}

demo(a,b,c,d,e){
  return this.http.get(this.dev_url  + '/users/demo?&fname='+a+'&lname='+b+'&email='+c+'&mobile='+d+'&dealeID='+e)
  .map(res => res.json());
}
contactus(data){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url + '/users/contactous', data, {headers:this.headersVal})
   .map(res => res.json()) ;
}
pwdreset(a,b){
  return this.http.get(this.dev_url  + '/users/foremailpwdchg?&cred='+a+'&newpwd='+b)
  .map(res => res.json());
}
shareloc(did,conatct){
  return this.http.get(this.dev_url  + '/gps/ShareLocation?&imei='+did+'&contact='+conatct)
  .map(res => res.json());
}

shareLiveLocation(data){
  return this.http.post('https://www.oneqlik.in' + '/share', data)
  .map(res => res.json()) ;
}

sendLiveLocationLink(data){
  return this.http.post('https://www.oneqlik.in' + '/devices/shareLocationLink', data)
  .map(res => res.json()) ;
}

demorequest(dpld){
  return this.http.post(this.dev_url + '/users/DemoRequest', dpld)
  .map(res => res.json()) ;
}

updateReminder(data){ 
  return this.http.post(this.dev_url + '/reminder/updateReminder', data)
  .map(res => res.json()) ;  
}


recalculateODO(imei){

  return this.http.get(this.dev_url + '/gps/reCalculateODO?imei=' + imei)
  .map(res => res.json()) ;  
}
deleteReminder(data){
  return this.http.post(this.dev_url + '/reminder/deleteReminder', data)
  .map(res => res.json()) ;  
}

sendMessages(pld){
 return this.http.post(this.dev_url + '/users/notificationMessage', pld)
  .map(res => res.json()) ;  
}

sendReceipt(mres){
  return this.http.post(this.dev_url+ '/product/orderSave_mail', mres)
  .map(res => res.json()) ;
}

getOederSummary(){
  return this.http.get(this.dev_url + '/product/orderDetail')
  .map(res => res.json());
}

deletegpsdata(id){
  return this.http.get(this.dev_url + '/gps/gpsdelete?id='+id)
  .map(res => res.json());
}
trip_logs(uId,from_date,to_date,devId){
  console.log('devId',devId);
    var  Url = '/user_trip/trip_detail?&uId='+uId+'&from_date='+from_date+'&to_date='+to_date
    if(devId.length==0){
      Url
    }else{
      Url ='/user_trip/trip_detail?&uId='+uId+'&from_date='+from_date+'&to_date='+to_date+'&device='+devId
    }

  return this.http.get(this.dev_url  + Url)
  .map(res => res.json());
}




speedlimit2(doid,status){
  return this.http.get(this.dev_url  + '/devices/DeviceAllert?&SpeedAlert='+status+'&doid='+doid)
  .map(res => res.json());
}
speedlimit(doid,speed,status){

  return this.http.get(this.dev_url  + '/devices/DeviceAllert?SpeedLimit='+speed+'&SpeedAlert='+status+'&doid='+doid)
  .map(res => res.json());
}

getSpeedreport(imei,time){
  //http://localhost:3000/users/forgotpwd?cred="email/phone"console.log(imei);
  return this.http.get(this.dev_url  + '/gps/getGpsSpeedReport?imei='+imei+'&time='+time)
  .map(res => res.json());
}
resetemail(email){
  return this.http.get(this.dev_url  + '/users/forgotpwd?cred='+email)
  .map(res => res.json());
}
resetpwd(email,code,pwd){
  return this.http.get(this.dev_url  + '/users/forgotpwd?phone='+email+'&otp='+code+'&newpwd='+pwd+'&cred='+email)
  .map(res => res.json());
}
ingtime(email,from,to){
  return this.http.get(this.dev_url  + '/gps/IgnReport?email='+email+'&from='+from+'&to='+to)
  .map(res => res.json());
}
ignitionGraph(did,from,to){
  return this.http.get(this.dev_url  + '/gps/IgnGraph?did='+did+'&from='+from+'&to='+to)
  .map(res => res.json());
}

acReport(fdate,tdate,userid,imei){
  return this.http.get(this.dev_url + '/notifs/acReport?from_date='+fdate+'&to_date='+tdate+'&_u='+userid+'&vname='+imei)
  .map(res => res.json());
}

acReportMain(fdate,tdate,userid,imei){
  return this.http.get(this.dev_url + '/notifs/ACSwitchReport?from_date='+fdate+'&to_date='+tdate+'&user='+userid+'&device='+imei)
  .map(res => res.json());
}

getCustumer(uid,s,l,i,au){

  if(i && i!='undefined'){
    s=1;
  }
  var url = this.dev_url +'/users/getCustomer?uid='+uid+'&pageNo='+s+'&size='+l;
  if(i && i!="undefined"){
    url+= "&search="+i;
  }
  if(au === true){
    url+= "&all="+au;
  }
  return this.http.get(url)
  .map(res => res.json());
}

getCustumer1(uid,s,l,i,au,status){

  if(i && i!='undefined'){
    s=1;
  }
  var url = this.dev_url +'/users/getCustomer?uid='+uid+'&pageNo='+s+'&size='+l;
  if(i && i!="undefined"){
    url+= "&search="+i;
  }
  if(au === true){
    url+= "&all="+au;
  }
  if(status!=undefined){
    url+= "&status="+status;
  }
  return this.http.get(url)
  .map(res => res.json());
}

getTechnician(uid,s,l,i,au){

  if(i && i!='undefined'){
    s=1;
  }
  var url = this.dev_url +'/users/getTechnician?uid='+uid+'&pageNo='+s+'&size='+l;
  if(i && i!="undefined"){
    url+= "&search="+i;
  }
  if(au === true){
    url+= "&all="+au;
  }
  return this.http.get(url)
  .map(res => res.json());
}

getDeviceReport(user,to,from,did,s,l){
  var url = this.dev_url  + '/gps/getGpsReport';
  if(user){
    url += '?id=' + user ;
  }
  if(did){
    url += '&devId=' + did;
    s=0;
  }
  url += '&to=' + to + '&from=' +from + '&s=' + s + '&l='+ l;
  return this.http.get(url)
  .map(res => res.json());

}

getDeviceReport2(email,to,from){
  return this.http.get(this.dev_url  + '/gps/getGpsReport?id='+email+'&to='+to+'&from='+from)
  .map(res => res.json());

}

getDevModel(){

  return this.http.get(this.dev_url  + '/deviceModel/getDeviceModel')
  .map(res => res.json());

}


getDeviceStatus(id,status){
  return this.http.get(this.dev_url  + '/devices/updateStatus?_id='+id+'&status='+status)
  .map(res => res.json());

}

resetODO(pload){
  return this.http.post(this.dev_url + '/devices/reset_odo', pload)
  .map(res => res.json()) ;

}

delete_gps_data(pload){
  return this.http.post(this.dev_url + '/devices/delete_device_history', pload)
  .map(res => res.json()) ;
}

getContactsbyUser(supadm){
  return this.http.get(this.dev_url  + '/users/getAll?supadm='+ supadm)
  .map(res => res.json());

}

getIdealData(id,date){
  return this.http.get(this.dev_url  + '/gps/getGpsIdlingReport?imei='+id+'&to='+date)
  .map(res => res.json());
}
// getDashboardGraph(a, t){
//   return this.http.get(this.dev_url  + '/gps/getDashGraph?imei='+a+'&t='+t)
//   .map(res => res.json());

// }
getDashboard(id,from,to,_id,groupId,supadm,dealer){
  console.log("superAdmin=>",supadm);
  var url = this.dev_url + '/gps/getDashboard?email='+id+'&from='+from+'&to='+to+'&id='+_id ;
  if(groupId)
  url+= '&group=' + groupId;
  if(supadm)
  url+= '&supAdmin=' + supadm;
  if(dealer)
  url+= '&dealer=' + dealer;
  return this.http.get(url)
  .map(res => res.json());
 }
  editdevice(data){
    this.headersVal = new Headers();
    this.headersVal.append('Authorization',this.userToken);
    return this.http.post(this.dev_url + '/devices/deviceupdate', data,  {headers:this.headersVal})
     .map(res => res.json()) ;
  }

  restoreDevice(devid){
    return this.http.get(this.dev_url  + '/devices/restoreDevice?devid='+ devid)
    .map(res =>res.json());
  }

  getPoiReplay(id,uid){
    return this.http.get(this.dev_url  + '/trackRouteMap/getRoutePathMapWithPoi?id='+id+"&user="+uid)
    .map(res =>res.json());
  }

  getIgnition(pld){
 
    return this.http.get(this.dev_url  + '/notifs/ignitionReport?from_date='+pld.fromDate+"&_u="+pld.user+"&to_date="+pld.toDate + "&device="+pld.device)
    .map(res =>res.json());
  }

  getSharedDevices(did){
    return this.http.get(this.dev_url  + '/devices/ShareDeviceOwner?doid='+did)
    .map(res =>res.json());
  }

  // http://localhost:3000/trackRouteMap/getRoutePathMapWithPoi?id=5b470200b0ae406bfe21b07d&user=5a27deca4468572f678e2d91
  
  updateuid(data){
    this.headersVal = new Headers();
    this.headersVal.append('Authorization',this.userToken);
    return this.http.post(this.dev_url + '/users/Account_Edit', data, {headers:this.headersVal})
     .map(res => res.json()) ;
  }
getContacts(){
 return this.http.get(this.dev_url  + '/users/getAllUsers')
.map(res => res.json());

}


getvehType(uid){
  return this.http.get(this.dev_url  + '/vehicleType/getVehicleTypes?user='+uid)
  .map(res => res.json());
}



getPOIdata(i,u){
  return this.http.get(this.dev_url  + '/trackRoute/routepath/getRoutePathWithPoi?id='+i+"&user="+u)
  .map(res => res.json());
}

getFuelDetail(ustate){

  return this.http.get(this.dev_url  + '/googleAddress/getFuelPrice?state='+ustate)
  .map(res => res.json());
}

// http://localhost:3000/trackRoute/routepath/getRoutePathWithPoi?id=5b449ae5755a5527be41f7cc&user=59cbbdbe508f164aa2fef3d8
getContactsbyDealer(uid){
  return this.http.get(this.dev_url  + '/users/getAllUsers?dealer='+uid)
  .map(res => res.json());
}
getDistance(ddid,fromtime,totime,satelite){
  console.log(satelite);
  
  if(satelite==undefined){
    return this.http.get(this.dev_url  + '/gps/getDistanceSpeed?imei='+ddid+'&from='+fromtime+'&to='+totime)
    .map(res => res.json());
  }else{
     return this.http.get(this.dev_url  + '/gps/getDistanceSpeed?imei='+ddid+'&from='+fromtime+'&to='+totime+'&satelite='+satelite)
    .map(res => res.json());
  }
}
/* getCurrentLocation2(id){
  return this.http.get('http://35.154.237.104:15151/gps?id='+id)
 .map(res => res.json());

 } */
 statusUpdateGeoFence(id,status,entering,exiting){
  return this.http.get(this.dev_url  + '/geofencing/geofencestatus?gid='+id+'&status='+status+'&entering='+entering+'&exiting='+exiting)
  .map(res => res.json());
 }

 accountSuspend(pld){
  return this.http.post(this.dev_url+ "/users/accountSuspension" , pld)
  .map(res => res.json());
 }

 getCurrentLocation2(id){
  return this.http.get(this.dev_url  + '/gps?id='+id)
 .map(res => res.json());
}
// satelite +'&satelite='+satelite
getCurrentLocation(id,from,to){
  return this.http.get(this.dev_url  + '/gps?id='+id+'&from='+from+'&to='+to)
 .map(res => res.json());
 
 }
 // for satelitefilter------------
 getCurrentLocation1(id,from,to,satelite){
   if(satelite==undefined){
     return this.http.get(this.dev_url  + '/gps?id='+id+'&from='+from+'&to='+to)
.map(res => res.json());
   }
    else{
  return this.http.get(this.dev_url  + '/gps?id='+id+'&from='+from+'&to='+to+'&satelite='+satelite)
 .map(res => res.json());
    }
 
 }
 getallgeofence(id){
  return this.http.get(this.dev_url  + '/geofencing/getallgeofence?uid='+id)
  .map(res => res.json());
 }


 getLoad_managementData(id){
  return this.http.get(this.dev_url  + '/lm?u='+id)
  .map(res => res.json());

 }

 fuelReportData(dID,fDate,tDate){
  return this.http.get(this.dev_url  + '/summary/fuel?i='+dID+"&f="+fDate+"&t="+tDate)
  .map(res => res.json());
 }

//  summary/fuel/i,f,t


 getGeoFence(id){
  return this.http.get(this.dev_url  + '/geofencing/getgeofence?uid='+id)
  .map(res => res.json());
 }
 getperGeoFence(gid){
  return this.http.get(this.dev_url  + '/geofencing/getdevicegeofence?gid='+gid)
  .map(res => res.json());
 }
deleteGeoFence(gid){
  return this.http.get(this.dev_url  + '/geofencing/deletegeofence?id='+gid)
  .map(res => res);
}
getgraph(){
  return this.http.get(this.dev_url + '/api/graph')
 .map(res => res);
 
 }
  getgraphh(url:string){
  return this.http.get(this.dev_url+'/api/graph')
  .map(data3 =>{
    data3.json();
    var grapha = data3.json().graph;
    // console.log("Graph:");
    // console.log("Graph:",grapha);
    return data3.json();
  });
} 
getContacts2(){
  return this.http.get(this.dev_url  + '/users/SendOtp')
 .map(res => res.json());
 
 }

/* getDevice(emailid){
  console.log(emailid);
  return this.http.get(this.dev_url + "/devices/getDeviceByUser?email="+emailid)
  .map(res => res.json());
} */
shrdeviceOwner(did){
  return this.http.get(this.dev_url + "/devices/ShareDeviceOwner?doid="+did)
  .map(res => res.json());
}
deldevshr(did,uid){
  return this.http.get(this.dev_url+ "/devices/RemoveShareDevice?did="+did+"&uid="+uid)
  .map(res => res.json());
}
deldev(d){
  //  device:data.Device_ID,
  //                     userId:that.useridd
 // console.log("Delete Device"+d)
 if(d.permenant){
   return this.http.get(this.dev_url+ "/devices/deleteDevice?did="+d.device+"&userId="+d.userId+"&permenant="+d.permenant)
  .map(res => res.json());
 }else{
   return this.http.get(this.dev_url+ "/devices/deleteDevice?did="+d.device+"&userId="+d.userId)
   .map(res => res.json());

 }
}

deluser(d){ 
  // console.log("Delete Device"+d)
  var uObj = {
    userId : d,
    deleteuser : true
  }
   return this.http.post(this.dev_url+ "/users/deleteUser" , uObj)
   .map(res => res.json());
 }
delshu(s){
  return this.http.get(this.dev_url + "/schd/deleteSchedule?did="+s)
  .map(res => res.json());
}

getsche(did){
  return this.http.get(this.dev_url + "/schd/getSchdbyDevice?did="+did)
  .map(res => res.json());
}
getcustToken(id){
  return this.http.get(this.dev_url + "/users/getCustumerDetail?uid="+id)
  .map(res => res.json());
}

getUserObj(id){
  return this.http.get(this.dev_url + "/users/getuserDetail?uid="+id)
  .map(res => res.json());
}


getmatrix(did){
  return this.http.get("http://localhost:3005/api/getmatrix?did="+did)
  .map(res => res.json());
}
cancel_signup(phone){
  return this.http.get(this.dev_url +"/users/cancel_signup?phone="+phone)
  .map(res => res.json());
}
getdet(){
  return this.http.get(this.dev_url + "/users/getAllUsers")
  .map(res => res.json());
}
resendotp(phone){
  return this.http.get(this.dev_url + "/users/otpResend?phone="+phone)
  .map(res => res.json());
}
getsh(on_id){
  return this.http.get(this.dev_url + "/schd/getallSchdbyDevice?did="+on_id)
  .map(res => res.json());
}
//add 


custStatus(custData){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  
  return this.http.post(this.dev_url +'/users/user_status',custData,{headers:this.headersVal})
  .map(res => res.json());

}

editUsermaster(uObj){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url +'/users/editUserMaster',uObj,{headers:this.headersVal})
  .map(res => res);
}


getTravel_path_report(payload){
  return this.http.post(this.dev_url +'/gps/travelPathReport',payload)
  .map(res => res.json());
}

newgetTravel_path_report(payload){
  return this.http.post(this.dev_url +'/gps/newtravelPathReport',payload)
  .map(res => res.json());
}

editDevMaster(dObj){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url +'/devices/editDevMaster',dObj,{headers:this.headersVal})
  .map(res => res);

}


addPoints(iobj){
  return this.http.post(this.dev_url +'/points/addpointAllocation',iobj)
  .map(res => res);
}

removeSharedDevice(removeData){
  return this.http.post(this.dev_url+'/devices/RemoveShare',removeData)
  .map(res => res);
}

getAvialblePoints(distId,distPoint){

  // /users/checkPointAvailablity?u_id=(user id)&demanded_points=20
  return this.http.get(this.dev_url + "/users/checkPointAvailablity?u_id="+distId +'&demanded_points=' + distPoint)
  .map(res => res.json());
}


getPointDetails(uId,fdate,tdate){
  return this.http.get(this.dev_url + "/points/getPointAllocation?uid="+uId + "&fdate=" + fdate + "&tdate="+ tdate)
  .map(res => res.json());


}


saveRoute(routeDetail){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url +'/trackRoute',routeDetail,{headers:this.headersVal})
  .map(res => res.json());

}


updateRoute(routeDetail,id){
  console.log(id);
  return this.http.put(this.dev_url +'/trackRoute/updateRoute',routeDetail)
  .map(res => res);
}


addPOI(poipayload){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url +'/trackRouteMap/updateRoute_map',poipayload,{headers:this.headersVal})
  .map(res => res.json());
}
deletePOI(data){
  return this.http.get(this.dev_url +'/poi/deletePoi?_id='+data)
}


updatePOIdetail(poipayload){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url +'/trackRouteMap/updatePOI',poipayload,{headers:this.headersVal})
  .map(res => res.json());

}

editPOIdetails(poipayload){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url +'/poi/updatePOI',poipayload,{headers:this.headersVal})
  .map(res => res.json());

}
getRouteDetail(uId){
  return this.http.get(this.dev_url + "/trackRoute/user/"+uId)
  .map(res => res.json());

}

getdevById(did){
  return this.http.get(this.dev_url + "/devices/getDevicebyId?deviceId="+did)
  .map(res => res);

}


createTrip(payload){
  return this.http.post(this.dev_url +'/user_trip/planTrip',payload)
  .map(res => res.json());
}

armDisarm(armDIsarmPayload){
  return this.http.post(this.dev_url +'/devices/serverCommand',armDIsarmPayload)
  .map(res => res.json());

}

addBillingDetail(payload){
  return this.http.post(this.dev_url+'/billing/addBillingDetail',payload)
  .map(res => res.json());
}


updateBillingDetail(payload){
  return this.http.post(this.dev_url +'/billing/updateBillingDetail',payload)
  .map(res => res.json());
}

endTrip(payload){
  return this.http.post(this.dev_url +'/user_trip/updatePlantrip',payload)
  .map(res => res.json());
}


saveExpense(e_payload){
  return this.http.post(this.dev_url +'/expense/addExpense',e_payload)
  .map(res => res.json());
}

getDetailedExpense(e_payload){

  return this.http.get(this.dev_url +'/expense/tripdetailbyType?user='+e_payload.user + "&type=" + e_payload.type + "&fdate=" + e_payload.fdate + "&tdate=" + e_payload.tdate + "&vehicle=" + e_payload.vehicle)
  .map(res => res.json());
}

getDistributer(userId,role){
  return this.http.get(this.dev_url +'/broadcastNotification/getContactList?user='+userId +'&role=' + role)
  .map(res => res.json());
}



updatedailyLog(pld){
  return this.http.post(this.dev_url +'/devices/editDailyReport',pld)
  .map(res => res.json());

}




getLastTripStatus(tripInfo,status,devId){
  return this.http.get(this.dev_url + "/user_trip/getLastTrip?device="+devId+ "&status="+status+"&tripInfo="+tripInfo)
  .map(res => res.json());
}

deleteExpense(expenseId){
  
  return this.http.get(this.dev_url + "/expense/deleteExpense?_id="+expenseId)
  .map(res => res);

}


getExpense(tripId){
  return this.http.get(this.dev_url + "/expense/getExpense?trip="+tripId)
  .map(res => res.json());
}



getRouteDetail_path(uId){
  return this.http.get(this.dev_url + "/trackRoute/user_path/"+uId)
  .map(res => res.json());

}
POIDATA(id,userId){
    return this.http.get(this.dev_url + "/trackRouteMap/user/getRouteMap?id="+id+"&userid="+userId)
  .map(res => res.json());

}

// http://localhost:3000/trackRouteMap/driverPerformance?from_date=2018-03-10T09:29:43.547Z&to_date=2018-06-12T09:29:43.547Z&driverid



driverReport_data(from,to,id){
  return this.http.get(this.dev_url + "/trackRouteMap/driverPerformance?from_date="+from+"&to_date="+to+"&driverid="+id)
  .map(res => res.json());
}


tripHistory(rId){
return this.http.get(this.dev_url + "/notifs/tripStory?tripid="+rId)
  .map(res => res.json());
}


getDrivers(uId){
  return this.http.get(this.dev_url + "/driver/getDrivers?userid="+uId)
  .map(res => res.json());

}


getExpVehDetails(uId,emailId,status,skip,limit,input,supadmin,dealer){
  // return this.http.get(this.dev_url + "/devices/getDeviceByUser?email="+emailId+"&id="+uId+"&status="+status)
  // .map(res => res.json());
  console.log(skip);
  if(input && input!='undefined'){
    skip=0;
  }
  var url = this.dev_url + "/devices/getDeviceByUser?email=" + emailId +'&id='+ uId ;
  if(input && input!="undefined"){
    url+= "&search="+input;
  }
  if(status == true){
    url += '&status=' + status ;
  }
  if(skip)
  console.log(skip);
  url+= '&skip='+skip;
  if(limit)
  url += "&limit="+limit
  if(supadmin)
  url+= '&supAdmin=' + supadmin;
  if(dealer)
  url+= '&dealer=' + dealer;
  return this.http.get(url)
   .map(res => res.json());

}


getNotificationType(){
  return this.http.get(this.dev_url + "/notifs/getTypes")
  .map(res => res.json());
}


getReferenceId(rid){
  return this.http.get(this.dev_url + "/reference/verifyRef?ref_id="+rid)
  .map(res => res.json());
}


  getDeviceByFilter_dash(a, email, user, s, l, input, supadm, dealer, status) {

    if (input && input != 'undefined') {
      s = 0;
    }

    var url = this.dev_url + "/devices/getDeviceByUser?id=" + user + "&email=" + email + "&skip=" + s + "&limit=" + l;

    if ((a != null) || (a != undefined)) {
      url += "&statuss=" + a
    }
    if (status == true) {
      url += "&status=" + status
    }

    if (input && input != "undefined") {
      url += "&search=" + input;
    }
    if (supadm)
      url += '&supAdmin=' + supadm;
    if (dealer)
      url += '&dealer=' + dealer;

    // if(group){
    //   url+='&group='+group;
    // }

    return this.http.get(url)
      .map(res => res.json());
  }

getDeviceByFilter_dashNew(a,email,user,s,l,input,supadm,dealer,status){

  if(input && input!='undefined'){
    s=0;
  }
  
  var url = this.dev_url + "/devices/getDeviceForDashboard?id="+user+"&email="+email+"&skip="+s+"&limit="+l;

  if((a!=null)||(a!=undefined)){
    url += "&statuss="+a
  }
  if(status ==true){
    url += "&status=" + status
  }
  
  if(input && input!="undefined"){
    url+= "&search="+input;
  }
  if(supadm)
  url+= '&supAdmin=' + supadm;
  if(dealer)
  url+= '&dealer=' + dealer;

  // if(group){
  //   url+='&group='+group;
  // }

  return this.http.get(url)
  .map(res => res.json());
}





getfilteredgeofance(gID,uId){
  return this.http.get(this.dev_url + "/geofencing/getallgeofence?uid="+uId+"&vehiclegrp="+gID)
  .map(res => res.json());
}



// http://13.126.36.205:3000/devices/getDeviceByUser?email=gaurav.gupta@adnate.in&id=59cbbdbe508f164aa2fef3d8&status=true
getRouteDriver(uId){
  return this.http.get(this.dev_url + "/driver/getDrivers?userid="+uId)
  .map(res => res.json());
}


addCommandQueue(pld){
  return this.http.post(this.dev_url + "/devices/addCommandQueue",pld)
  .map(res => res.json());
}

deviceCmdQueue(imei){
  return this.http.get(this.dev_url + "/devices/getCommandQueue?imei="+imei)
  .map(res => res.json());
}

ProductSave(pld){
  return this.http.post(this.dev_url + "/product/addProduct",pld)
  .map(res => res.json());

}

getProducts(){
  return this.http.get(this.dev_url + "/product/getProduct")
  .map(res => res.json());

}

getExpensesbyCategory(pld){
  // user : this.useridd,
  // fromDate:this.Fromdate,
  // toDate : this.todate,
  // vehicle : this.deviceArr[0]

  return this.http.get(this.dev_url + "/expense/expensebycateogry?user="+pld.user + '&fdate='+pld.fromDate + '&tdate=' + pld.toDate + '&vehicle=' + pld.vehicle)
  .map(res => res.json());
}

addExpenses(pld){

  return this.http.post(this.dev_url + "/expense/addExpense",pld)
  .map(res => res.json());
}


getDeviceModelbyID(modelId){
  
  return this.http.get(this.dev_url + "/deviceModel/getDevModelByName?id="+modelId)
  .map(res => res.json());

}

saveAdd(addressObj){
  return this.http.post(this.dev_url + "/googleAddress/addGoogleAddress",addressObj)
  .map(res => res.json());
  
}

getlatLong(){
  
  return this.http.get('http://ip-api.com/json')
  .map(res => res.json());
}

getEngineCutStatus(id){
  return this.http.get(this.dev_url + "/trackRouteMap/getRideStatusApp?_id="+id)
  .map(res => res.json());
}

getEngineCutStatus_1(id){
  return this.http.get(this.dev_url + "/trackRouteMap/checkStatus?_id="+id)
  .map(res => res.json());
}

checkForPassword(id){
  return this.http.post(this.dev_url + "/users/get_user_setting",id)
  .map(res => res.json());

}

trakcRouteMap(uId){
  return this.http.get(this.dev_url + "/trackRouteMap/user/getRouteMap?userid="+uId)
  .map(res => res.json());
}

updateRouteStatus(payload,id){
  return this.http.put(this.dev_url +'/trackRoute/id',payload)
  .map(res => res.json());

}

// http://13.126.36.205:3000/trackRouteMap/user/getRouteMap?userid=59cbbdbe508f164aa2fef3d8

  addRouteMap(mapPayload) {
    this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
    return this.http.post(this.dev_url + "/trackRouteMap", mapPayload,{headers:this.headersVal})
      .map(res => res.json());
  }



delRouteDetail(rId){
  return this.http.delete(this.dev_url + "/trackRoute/"+rId)
  .map(res => res);
}

getVehDetail(VehiclePayload){
  return this.http.get(this.dev_url + "/devices/getdeviceByGroupId?vgroup="+VehiclePayload)
  .map(res => res.json());
}

deletePermanently(deviceId){
  return this.http.get(this.dev_url + '/devices/deletePermanently?Device_ID=' + deviceId).map(res=>res.json());
}


getLoadUnload(gioPayload){
  return this.http.get(this.dev_url + "/geofencing/getGeoFenceByGroupId?vgroup="+gioPayload)
  .map(res => res.json());
}

getGeoFenceData(uId){
  return this.http.get(this.dev_url + "/geofencing/getGeoTypeCount?uid="+uId)
  .map(res => res.json());
}

// http://13.126.36.205:3000/geofencing/getGeoTypeCount?uid=5a27deca4468572f678e2d91
addmatrix(mat){
  var headers = new Headers();
  headers.append('Content-Type','application/json');
  return this.http.post(this.dev_url + '/api/matrixw', mat, {headers:headers})
   .map(res => res.json()) ;
  
}
addContact(newContact){
this.headersVal = new Headers();
 this.headersVal.append('Authorization',this.userToken);
 return this.http.post(this.dev_url + '/users/signUp', newContact, {headers:this.headersVal})
  .map(res => res.json()) ;
 
}


  
log(newlog){
  this.headersVal = new Headers();
 this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url + '/users/LoginWithOtp', newlog,  {headers:this.headersVal})
   .map(res => res.json()) ;
}

editshe(newshe){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url  + '/schd/editSchedule',newshe, {headers:this.headersVal})
   .map(res => res.json());
}

addshe(newshe){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url  + '/schd/createSchedule',newshe, {headers:this.headersVal})
   .map(res => res.json());
}
addContact2(newContact2){
  var headers = new Headers();
  headers.append('Content-Type','application/json');
  return this.http.post(this.dev_url  + '/users/SendOtp',newContact2, {headers:headers})
   .map(res => res.json());
}
addDevice(newDevice){
  this.headersVal = new Headers();
  // this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url  + '/devices/addDevice',newDevice)
   .map(res => res.json()

  );
}
addKycDevice(newDevice){
  this.headersVal = new Headers();
  // this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url  + '/devices/addKYCDevice',newDevice)
   .map(res => res.json()

  );
}

addMultipleDevice(deviceUploadObject){

  return this.http.post(this.dev_url  + '/devices/uploadDevice',deviceUploadObject)
  .map(res => res.json())
}



editDealer(editDealerPayload){
  return this.http.post(this.dev_url  + '/users/editUserDetails',editDealerPayload)
   .map(res => res.json());
}

savereminder(payload){
  return this.http.post(this.dev_url  + '/reminder/addReminder',payload)
  .map(res => res.json());

}


getVehicleReminder(id){
 
  return this.http.get(this.dev_url  + '/reminder/dashboardReminder?id=' + id)
  .map(res => res.json());
}

deleteCostumer(deletePayload){
  return this.http.post(this.dev_url  + '/users/deleteUser',deletePayload)
  .map(res => res.json());
}

permanentDeluser(id){
  return this.http.get(this.dev_url  + '/users/DeleteUser?id=' + id)
  .map(res => res.json());
}


getExpenseGrapgData(id){
  // http://localhost:3000/expense/dashboardExpense?id=5d8736b6c377321aa93a3ed3  
  return this.http.get(this.dev_url  + '/expense/dashboardExpense?id=' + id)
  .map(res => res.json());
}

restoreUser(id){
  return this.http.get(this.dev_url  + '/users/restoreUsers?id=' + id)
  .map(res => res.json());

}


updateImage(imgarr){
  console.log(imgarr);
  return this.http.post(this.dev_url  + '/users/updateImagePath',imgarr)
  .map(res => res.json());
}

dealer_Info1(user_id,s,l,i,role){
  if(i && i!='undefined'){
    s=1;
  }
  var url = this.dev_url +'/users/getDealers?supAdmin='+user_id +'&pageNo='+ s +"&size="+l  ;
  if(i && i!="undefined"){
    url+= "&search="+i;
  }
  if(role === 'subadmin'){
    url+= "&customer_role="+role+',kycApproval,cc';
  }
  return this.http.get(url)
    .map(res=>res.json());
}

// getAllDealerVehicles
dealer_Info(){
  return this.http.get(this.dev_url +'/users/getAllDealerVehicles')
    .map(res=>res.json());
}

dealer_Info_dealer_list(superadm){
  return this.http.get(this.dev_url +'/users/getAllDealerVehicles?supAdmin=' + superadm)
    .map(res=>res.json());
}

getTableData(superadm){
  return this.http.get(this.dev_url +'/users/getDealerAndcust?supAdmin=' + superadm)
  .map(res=>res.json());
}

dealer_Info_dealer_list_copy(pload){
  if(pload === true){
    var url = '/users/getAllDealerVehicles';
  }else{
    var url  = '/users/getAllDealerVehicles?supAdmin=' + pload ; 
  }
 
  return this.http.get(this.dev_url + url)
  .map(res=>res.json());
  
}
addGeo(geodata){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url  + '/geofencing/addgeofence',geodata,  {headers:this.headersVal})
   .map(res => res.json()

  );
}

updateGeo(geodata){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url  + '/geofencing/updateGeoFence',geodata,  {headers:this.headersVal})
   .map(res => res.json()

  );
}

addToken(newToken){
  var headers = new Headers();
  headers.append('Content-Type','application/json');
  return this.http.post(this.dev_url  + '/devices/checkToken',newToken, {headers:headers})
   .map(res => res.json());
}
//loginwithotp
loginotp(userlog){
  var headers = new Headers();
  headers.append('Content-Type','application/json');
  return this.http.post(this.dev_url  +'/devices/deleteDevice?did=123/users/LoginWithOtp',userlog, {headers:headers})
   .map(res => res.json());
}

getDataObservable(url:string) {
  return this.http.get(this.dev_url  + '/mos/getMosChannel')
      .map(data => {
          data.json();
         
           var temp = data.json().temperature[0];
           var dis = data.json().distance[0];
           var hum = data.json().humidity[0];
           var  longi = data.json().gps[0];
          // console.log("GPS: ",longi);
          // console.log("Temprature: ",temp);
          // console.log("Humidity: ",hum);
          // console.log("Distance: ",dis);
          
          return data.json();
  });
}
/* getDevice_id(id){
  return this.http.get(this.dev_url + "/devices/getDeviceByUser?id="+id)
  .map(data => {
      data.json();
     
       var devices = data.json().devices;
    
      return data.json();
});
}
https://www.adnateiot.com/gps?id='+id+'&from='+from+'&to='+to
http://localhost:3000/devices/deviceShare?uid=5a27deca4468572f678e2d91&email=ultimateanshulsaxena@gmail.com&did=5a449636fa04d91b64565e60*/
ShareDevice(email,id,did){
  // console.log(did)
  return this.http.get(this.dev_url + "/devices/deviceShare?email="+email+'&uid='+id+'&did='+did
)
      .map(data => {
          data.json();
         
           var devices = data.json().devices;
          /* console.log("Devices: ",temp);  */
          return data.json();
  });
}
getDevice(emailid,id) {
  // https://www.oneqlik.in/devices/getDeviceByUserDropdown?id=5c6ebc892f8b64770399f762&email=haribhau.lagad@swarajtraanslink.com
  return this.http.get(this.dev_url + "/devices/getDeviceByUserDropdown?email="+emailid+'&id='+id)
      .map(data => {
          data.json();      
           var devices = data.json().devices;
          /* console.log("Devices: ",temp);  */
          return data.json();
  });
}

imageupload(img){
  // return this.http.post(this.dev_url + "/users/uploadProfilePicture",img)
  return this.http.post("https://www.oneqlik.in/users/uploadProfilePicture",img)
  .map(res=>res);
}

deviceImageupload(img){
  // return this.http.post(this.dev_url + "/devices/uploadDeviceImage",img)
   return this.http.post("https://www.oneqlik.in/users/uploadProfilePicture",img)
  .map(res=>res);
}

imageuploadTracker(img){
  return this.http.post('http://13.126.36.205'+ "/users/uploadTrackerImage",img)
  .map(res=>res);
}

updateAddress(pld){
  return this.http.post(this.dev_url+ "/googleAddress/manualAddressUpdate",pld)
  .map(res=>res);
}

changeAddress(pld){
  return this.http.post(this.dev_url+ "/googleAddress/updateManualAddress",pld)
  .map(res=>res);

}

getUpdatedAddress(){
  return this.http.get(this.dev_url + '/googleAddress/getManualAddress')
    .map(res=>res);
}


triggerCommand(pld){
  return this.http.post(this.dev_url+ "/devices/manualserverCommand",pld)
  .map(res=>res);
}



triggerCommand1(pld){
  return this.http.post(this.dev_url+ "/devices/serverCommand",pld)
  .map(res=>res.json());
}

deleteSystemLogs(imei){
  return this.http.get(this.dev_url + '/gps/deleteSystemLogs?imei='+imei)
  .map(res=>res);
}
DownloadDocument(imglink){
  return this.http.get(this.dev_url + '/users/downloadDoc?docImage='+imglink, { responseType: ResponseContentType.Blob })
    .map(res=>res);
}
//copy of above "getDevice" web service with extra parameters to filter data, specially for "DashboardComponent"
getDeviceByFilter(emailid,id,groupid, status, statuss,s,l,i,supadm,dealer,dateobject,licenceType ) {
  console.log(supadm,dealer,id);
  console.log('dateobject',dateobject);
  
  if(dateobject != undefined){
   var fdate = dateobject?dateobject.from_date:"";
   var tdate = dateobject?dateobject.to_date:"";
  }
  
  if(i && i!='undefined'){
    s=0;
  }

  var url = this.dev_url + "/devices/getDeviceByUser?email=" + emailid +'&id='+ id + '&status=' + status + '&groupid=' + groupid + '&statuss=' + statuss+'&skip='+s+"&limit="+l+"&licenceType="+licenceType
  if(i && i!="undefined"){
    url+= "&search="+i;
  }
  if(supadm)
  url+= '&supAdmin=' + supadm;
  if(dealer)
  url+= '&dealer=' + dealer;

  if(fdate != undefined){
    url += '&fdate=' + fdate;
  }
  if(tdate != undefined){
    url += '&tdate=' + tdate;
  }
console.log(url)
  return this.http.get(url)
      .map(data => {
          data.json();     
           var devices = data.json().devices;
          /* console.log("Devices: ",temp);  */
          return data.json();
  });
}

getDeviceByFilter1(emailid,id,groupid, status, statuss,s,l,i,supadm,dealer,dateobject,licenceType,kycStatus,state ) {
  console.log(supadm,dealer,id);
  console.log('dateobject',dateobject);
  
  if(dateobject != undefined){
   var fdate = dateobject?dateobject.from_date:"";
   var tdate = dateobject?dateobject.to_date:"";
  }
  
  if(i && i!='undefined'){
    s=0;
  }

  var url = this.dev_url + "/devices/getDeviceByUser?email=" + emailid +'&id='+ id + '&status=' + status + '&groupid=' + groupid + '&statuss=' + statuss+'&skip='+s+"&limit="+l+"&licenceType="+licenceType
  if(i && i!="undefined"){
    url+= "&search="+i;
  }
  if(supadm)
  url+= '&supAdmin=' + supadm;
  if(dealer)
  url+= '&dealer=' + dealer;

  if(fdate != undefined){
    url += '&fdate=' + fdate;
  }
  if(tdate != undefined){
    url += '&tdate=' + tdate;
  }
  if(state != undefined){
    url += '&state=' + state;
  }
  if(kycStatus != undefined){
    url += '&kycStatus=' + kycStatus;
  }
console.log(url)
  return this.http.get(url)
      .map(data => {
          data.json();     
           var devices = data.json().devices;
          /* console.log("Devices: ",temp);  */
          return data.json();
  });
}

ignitionPoint(uid,from_date,to_date,device,min_time){
   // http://localhost:3000/stoppage/trip_idle?uId=59cbbdbe508f164aa2fef3d8&from_date=2019-08-30T18:30:00.000Z&to_date=2019-10-01T07:43:52.000Z&device=5d92054693dea3510753a9a8&min_time=1
  return this.http.get(this.dev_url+"/stoppage/trip_idle?uId="+uid+"&from_date="+from_date+"&to_date="+to_date+"&device="+ device + "&min_time=" + min_time)
  .map(res => res.json());

}



filteredRoute(uId,stat){
  return this.http.get(this.dev_url+"/trackRoute/user/"+uId+"?status="+stat)
  .map(res => res.json());
}

// http://localhost:3000/trackRoute/user/5a27deca4468572f678e2d91?status=Active

stoppage_points(ddid,fromtime,totime,useridd){
  return this.http.get(this.dev_url+"/stoppage/stoppage_detail?uId="+useridd +'&from_date='+fromtime+'&to_date='+totime+'&device='+ddid)
  .map(res => res.json());
}


stoppage_report(f_date,t_date,uId,vName){
  var url = this.dev_url+"/stoppage/stoppageReport?from_date="+f_date +'&to_date='+t_date+'&_u='+uId;
  if(vName){
    url += '&vname='+vName;
  }
  
  return this.http.get(url)
  .map(res => res.json());
}

daywiseRep(fdate,tdate,uid){
  return this.http.get(this.dev_url+"/summary/dayWiseSummary?user="+uid +'&to='+tdate+'&from='+fdate)
  .map(res => res.json());
}

ignitionReport(f_date,t_date,vName,uId){
  var url = this.dev_url+"/notifs/ignitionReport?from_date="+f_date +'&to_date='+t_date+'&_u='+uId;
  if(vName.length != 0){  
    url +='&vname='+vName;
  }
  return this.http.get(url)
  .map(res => res.json());

}

getAddress(lat,lng){
  return this.http.get("https://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+','+lng+'&key='+'AIzaSyCNT3eO1wPQHUhY_cmQ9N_9BkLzJ_GB9j8')
  .map(res => res.json());
}


shareCostumerInfo(uid){
  return this.http.get(this.dev_url+"/users/shareUserDetails?user="+uid)
  .map(res => res.json());
}

filteredNotifications(from,to,notif,option,Id,skp,lmt){
  // console.log(option);
 let suburl="";
 suburl+="/notifs/getNotifByFilters?";
 if(from)suburl+='from_date='+from.toISOString();;
 if(to)
 suburl+="&to_date="+to.toISOString();
 if(Id){
  suburl+="&user="+Id;
 }

 if(notif)
 suburl+="&type="+notif;
 if(option)
//  suburl += "&vehicle="+option.did;
 suburl += "&vehicle="+option;
 suburl += "&sortOrder="+"-1";
 suburl += "&skip="+skp;
 suburl += "&limit="+lmt;

  return this.http.get(this.dev_url+suburl)
  .map(res => res.json());  

}

commentSave(p){
  return this.http.post(this.dev_url+"/notifs/commentMessage",p)
  .map(res => res.json());

}

// http://localhost:3000/notifs/getNotifByFilters?from_date=2018-05-10T09:16:54.328Z&to_date=2018-05-15T09:16:54.328Z&user=5a27deca4468572f678e2d91&type=overspeed&vehicleName=Testing-2&sortOrder=-1

geofenceData(f_date,t_date,uId,geoId){
  return this.http.get(this.dev_url+"/notifs/GeoFencingReport?from_date="+f_date +'&to_date='+t_date+'&_u='+uId+'&geoid='+geoId)
  .map(res => res.json());

}

overSpeed(f_date,t_date,uId,dev){

  var url = this.dev_url+"/notifs/overSpeedReport?from_date="+f_date +'&to_date='+t_date+'&_u='+uId;
  if(dev.length != 0)
  url += '&device='+dev
  return this.http.get(url)
  .map(res => res.json());

}


deviceSOSreport(queryPayload){
  console.log(queryPayload);
  var user = queryPayload.user;
  var from = queryPayload.from;
  var to = queryPayload.to;
  var url = this.dev_url + '/notifs/SoSNotification?user=' + user + '&fromDate='+ from + '&toDate=' + to
  return this.http.get(url)
  .map(res => res.json());

}
getVehicleExcelSheet(from,to,uId){

  return this.http.get(this.dev_url+'devices/devReport?user='+uId+"&fromDate=" +from + "&toDate="+ to,  { responseType: ResponseContentType.Blob })
  .map(res => res);
}


route_violation(f_date, t_date, uId){
  return this.http.get(this.dev_url+"/notifs/RouteVoilationReprot?from_date="+f_date +'&to_date='+t_date+'&_u='+uId)
  .map(res => res.json());
}



getDeviceCount(role,user_id){
  return this.http.get(this.dev_url+"/gps/DeviceAddCount?role="+role +'&id='+user_id)
  .map(res => res.json());
}

getDeviceCount1(role,user_id,key,skip,limit){
  return this.http.get(this.dev_url+"/gps/DeviceAddCount?role="+role +'&id='+user_id + '&purpose=' + 'list' + '&for=' + key+'&skip='+skip + '&limit='+limit)
  .map(res => res.json());
}

getExpiredDeviceCount(role,user_id){

  return this.http.get(this.dev_url+"/gps/DeviceExpiredCount?role="+role +'&id='+user_id)
  .map(res => res.json());

}

getExpiredDeviceCount1(role,user_id,key,skip,limit){

  return this.http.get(this.dev_url+"/gps/DeviceExpiredCount?role="+role +'&id='+user_id + '&purpose='+ 'list' + '&for='+ key+'&skip='+skip + '&limit='+limit)
  .map(res => res.json());

}

getRenewDeviceCount(role,user_id){
  return this.http.get(this.dev_url+"/gps/DeviceRenewCount?role="+role +'&id='+user_id)
  .map(res => res.json());
}

getRenewDeviceCount1(role,user_id,key,skip,limit){
  return this.http.get(this.dev_url+"/gps/DeviceRenewCount?role="+role +'&id='+user_id + '&purpose='+'list'+'&for='+key+'&skip='+skip + '&limit='+limit)
  .map(res => res.json());
}

summary_rep(f_date, t_date, uId,did){
  var url= this.dev_url+"/summary?to="+t_date +'&from='+f_date+'&user='+uId;
  if(did){
    url += '&device='+did

  }
  return this.http.get(url)
  .map(res => res.json());
}

summary_rep_new(f_date, t_date, uId,did){
  var url= this.dev_url+"/summary/summaryReport?to="+t_date +'&from='+f_date+'&user='+uId;
  if(did){
    url += '&device='+did
  }
  return this.http.get(url)
  .map(res => res.json());
}


distanceReport(f_date, t_date, uId,DID){
  var url = this.dev_url+"/summary/distance?from="+f_date +'&to='+t_date+'&user='+uId;
  if(DID!=''){
    url += '&device='+DID 
  }
 
  return this.http.get(url)
  .map(res => res.json());

}

addPOICol(poipayload){
  this.headersVal = new Headers();
 this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url +'/poi/addpoi',poipayload, {headers:this.headersVal})
  .map(res => res.json());
}


setlanguage(payload){
  return this.http.post(this.dev_url +'/users/set_user_setting',payload)
  .map(res => res.json());
}

getLanguages(payload){
  return this.http.post(this.dev_url +'/users/get_user_setting',payload)
  .map(res => res.json());
}


getAddressByApi(latlng){
  
  return this.http.post(this.dev_url +'/googleAddress/getGoogleAddress',latlng)
  .map(res => res.json());

}

  resetPass(pld) {
    return this.http.post(this.dev_url + '/users/hardresetPassword', pld)
      .map(res => res.json());
  }


  setDealerPermission(pld){
    return this.http.post(this.dev_url + '/users/setDealerPermission', pld)
      .map(res => res.json());

  }

setReportPrefrence(payload){
  return this.http.post(this.dev_url+'/users/reportPrefrence',payload)
  .map(res => res.json());
}

setDashboardContent(payload){
  return this.http.post(this.dev_url+'/users/dashboardContent',payload)
  .map(res => res.json());
}


addOnePoi(poipayload){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url +'/poi/addpoi',poipayload,{headers:this.headersVal});
}


routeViolation(uId){
  return this.http.get(this.dev_url+"/trackRoute/user/"+uId)
    .map(res => res.json());

}


devicefuelreport(payload){
  var suburl = this.dev_url+'/gps/updatedFuelReport'
  return this.http.post(suburl,payload)
  .map(res => res.json());
}

addGroup(detail){
  this.headersVal = new Headers();
  this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url+"/groups/addGroup",detail,{headers:this.headersVal})
  .map(res => res.json());

}

fueleventCall(fuelobj){
 return this.http.post(this.dev_url+"/gps/getFuelNotifs",fuelobj)
  .map(res => res.json());
}


editGroup(dev){
  this.headersVal = new Headers();
 this.headersVal.append('Authorization',this.userToken);
  return this.http.post(this.dev_url+"/groups/updateGroup",dev,{headers:this.headersVal})
  .map(res => res.json());

}
  
saveDevInventory(inventoryPayload){
  return this.http.post(this.dev_url + '/inventory/addInventory',inventoryPayload)
    .map(res=>res.json());

}


editDevInventory(inventoryPayload){
  return this.http.post(this.dev_url + '/inventory/editInventory',inventoryPayload)
  .map(res=>res.json());
}

getDealersDetails(supAdmin){
  return this.http.get(this.dev_url+'/users/getDealers?supAdmin='+ supAdmin + "&size=1000&pageNo=1")
    .map(res=>res.json());
}


//deprecated: New with count also
getGroup(geoname){
  return this.http.get(this.dev_url+"/groups/getGroups_list?uid="+geoname)
  .map(res => res.json());
}
//New with count also
getGroupWithStatus(geoname){
  return this.http.get(this.dev_url+"/devices/getDeviceCountByTripStatus?userid="+geoname)
  .map(res => res.json());
}

getgoogleApi(u_id){
  return this.http.get(this.dev_url+"/users/getApiKey?u_id="+u_id)
  .map(res => res.json());
}

setgoogleApi(pld){
  return this.http.get(this.dev_url+"/users/setApiKey?u_id="+pld.u_id + "&api_key="+pld.api_key)
  .map(res => res.json());
}


alldevices(){
  return this.http.get(this.dev_url+"/devices/getDevice")
  .map(res => res.json());
}

alldevices1(uid,email,supadmin,dealer,searchh){
  var url  = this.dev_url + "/devices/getDeviceByUser?id="+uid + "&email=" + email; 
  if(supadmin)
  url += "&supAdmin=" + supadmin;
  if(dealer)
  url += "&dealer=" + dealer ; 
  if(searchh){
    url += "&search=" + searchh;

  }
  return this.http.get(url)
  .map(res => res.json());
}

deleteGroup(uId){
  return this.http.get(this.dev_url+"/groups/deleteGroup?_id="+uId)
  .map(res => res.status);

}

changeBillingStauts(pld){
  return this.http.post(this.dev_url+'/billing/updateBillingStatus',pld).map(res=>res.json())

}

getNearByVehicles(pld){
 
  return this.http.post(this.dev_url+'/devices/nearVehicles',pld).map(res=>res.json())
}

getDistributerList(uid){
  return this.http.get(this.dev_url+"/users/getsupAdmin?supAdmin="+uid)
  .map(res => res.json());
}

addPOIfromLive(pObj){
  return this.http.post(this.dev_url+"/groups/addGroup",pObj)
  .map(res => res.json());

}
getShe(did) {
  return this.http.get(this.dev_url + "/schd/getSchdbyDevice?did="+did)
      .map(data => {
          data.json();
         
           var did = data.json();
          
          return data.json();
  });
}
// Get Data
getdata(url:string){
  return this.http.get('')
  .map(data2 =>{
    data2.json();

  })
}
 
// Sockets 

private url = 'http://localhost:2000'; 
//13.126.36.205:5000 
//private url = 'http://13.126.36.205:5000 ';
private socket;
/* 1883 */
title = 'app';
sendMessage(message){
  //this.socket.emit('add-message', message);    
}

getMessages() {
 /*  let observable = new Observable(observer => {
    this.socket = io(this.url);
    this.socket.on('message', (data) => {
      observer.next(data);    
    });
    return () => {
      this.socket.disconnect();
    };  
  })     
  return observable; */
  let observable = new Observable(observer => {
/*     this.socket = io(this.url);
    this.socket.on('message', (data) => {
    
      console.log(data);
      observer.next(data);
     
    });
    return () => {
      this.socket.disconnect();
    };   */
    //this.socket = this.injectData.getSocket_5000();
      //io.connect('http://13.126.36.205:5000');
    //this.socket.on('connect', function(){
    //  console.log("IO Connected");
    //  this.socket.on('mqtt', function (msg)  {
        
    //      console.log(msg.topic + msg.payload);
          //observer.next(msg);
         
    //    });
    /*   this.socket.on('mqtt',function(msg){
        console.log(msg.topic + msg.payload);
      }); */
   // });
  })     
 
  return observable;
}  

gensock(){
 // this.socket = io.connect('http://localhost:5000');
 // this.socket.on('connect', function(){
  //  console.log("IO Connected");
  //  this.socket.on('mqtt',function(msg){
  //    console.log(msg.topic + msg.payload);
  //  });
  //});
}


getDriver(UID_For_Drivers) {
  return this.http.get(this.dev_url + "/driver/getDrivers?userid="+UID_For_Drivers)
      .map(data => {
          data.json();
         
           var devices = data;
          /* console.log("Devices: ",temp);  */
          return data.json();
  });
}

getImagePath(uid){
  return this.http.get(this.dev_url+'/users/shareProfileImage?uid=' +uid)
    .map(res=>res.json());
}

getVehicleType(id) {
  return this.http.get(this.dev_url + "/vehicleType/getVehicleTypes?user="+id)
      .map(data => {
          data.json();
         
           var devices = data;
          /* console.log("Devices: ",temp);  */
          return data.json();
  });
}



getDeviceModel(s,l,i) {
  var dynamicurl = this.dev_url + "/deviceModel/getDeviceModel?skip="+s + '&limit='+l;
  if(i != undefined){
    var input  = i;
    dynamicurl += "&input="+ i ; 
  }
  
  return this.http.get(dynamicurl)
      .map(data => {
          data.json();
         
           var devices = data;
          /* console.log("Devices: ",temp);  */
          return data.json();
  });
}

addDeviceModel(newDeviceModel){
  var headers = new Headers();
  headers.append('Content-Type','application/json');
  return this.http.post(this.dev_url  + '/deviceModel/addDeviceModel',newDeviceModel, {headers:headers})
   .map(res => res.json()

  );
}


//url trigger of add device here


//https://www.oneqlik.in/driver/addDriverDetails

addDriver(newDriver){
  var headers = new Headers();
  headers.append('Content-Type','application/json');
  return this.http.post(this.dev_url  + '/driver/addDriverDetails',newDriver, {headers:headers})
   .map(res => res.json()

  );
}

addVehicleType(newVehicleModel){
  var headers = new Headers();
  headers.append('Content-Type','application/json');
  return this.http.post(this.dev_url  + '/vehicleType/addvehicleType',newVehicleModel, {headers:headers})
   .map(res => res.json()

  );
}


updateVehType(vehtypeObj){
  console.log(vehtypeObj);
  return this.http.post(this.dev_url  + '/vehicleType/updatevehicleType',vehtypeObj)
  .map(res => res.json());

}


deleteVehicleType(data){
  return this.http.get(this.dev_url +"/vehicleType/deleteVehicleType?_id="+data)
   .map(res => {
    // console.log(res); 
    return res});
}



deleteDeviceModel(data){
  
    return this.http.get(this.dev_url +"/deviceModel/deleteDeviceModel?_id="+data)
     .map(res => {
      // console.log(res); 
      return res});
  
   
  }

  editDevModel(devModel){
    return this.http.post(this.dev_url + '/deviceModel/updateDeviceModel',devModel)
    .map(res => res.json())
  }

  deleteDriver(data){
   
      return this.http.get(this.dev_url +"/driver/deleteDriver?_id="+data)
       .map(res => {
        // console.log(res); 
        return res});   
    }

    // http://localhost:3000/trackRouteMap/updateRoute_map

    updateRouteMap(updateMap){

      return this.http.post(this.dev_url + "/trackRouteMap/updateRoute_map", updateMap)
        .map(res =>res.json());

    }


    vehicleUtilization(role,userid){
      return this.http.get(this.dev_url+"/gps/vehicleUtilizationPercentage?role="+role+"&id="+userid)
      .map(res => res.json());

    }


    xlStoppageReport(Fdate,tdate,uId,vName){
      return this.http.get(this.dev_url+"/stoppage/stoppageXlReport?from_date="+Fdate+"&to_date="+tdate+"&_u="+uId+"&vname="+vName)
        .map(res=> res.json());
    }

    getCurrencies(){
      return this.http.get('https://openexchangerates.org/api/currencies.json')
        .map(res=> res.json());
    }



    xlRVReport(f,t,u){
      return this.http.get(this.dev_url+"/notifs/RouteVoilationXlReport?from_date="+f+"&to_date="+t+"&_u="+u)
      .map(res=>res.json());
    }

    ignXLreport(f,t,vn,user){
      return this.http.get(this.dev_url+"/notifs/IgnitionXlReport?from_date="+f+"&to_date="+t+"&vname="+vn+"&_u="+user)
      .map(res => res.json());  
    }

    public post(url:string,data:any,isJson=true){
      $("#loading").css({"visibility": "visible"});
  
      if(isJson){
        // this.dev_url+url,data
        return this.http.post(this.dev_url+url,data).map((res : Response) => {
          $("#loading").css({"visibility": "hidden","background":"red"});
          return res.json();
        })
      }else{
        // this.dev_url+url,data
        return this.http.post(this.dev_url+url,data).map((res : Response) => {
          $("#loading").css({"visibility": "hidden"});
          return res;
        })
      }
    }

    OSXLreport(fd,td,vn,u){
      return this.http.get(this.dev_url+"/notifs/overspeedXlReport?from_date="+fd+"&to_date="+td+"&_u="+u+"&vname="+vn)
      .map(res => res.json());  
    }

    gettripByDevice(find){
      return this.http.get(this.dev_url + "/user_trip/getLastTrip?tripInfo=all_trip&user=" + find.user  +"&device=" + find.device+ "&fromDate=" + find.fromDate + "&toDate=" + find.toDate + "&skip=" + 1 + "&limit=" + 10)
      .map(res=>res.json());
      
    }

    getPOI(data){  
      return this.http.get(this.dev_url + "/poi/getPois?user=" + data)
      .map(res => {
      // console.log(res); 
      return res.json()});
      }

      sharedData:any;
      setService(data){
      this.sharedData = data;
      }
      getService(){
      return this.sharedData;
      }


      getAddressPrefrence(){
      var reportAddressPref =  JSON.parse(window.atob(window.localStorage.token.split('.')[1])).report_address_preference;  
      return reportAddressPref ; 
      }
     
      getGroupById(groupId){
      return this.http.get(this.dev_url + "/groups/getGroupById?_id="+groupId)
      .map(res => res.json());
      }

        public get(url:string,isJson=true,loader=true){
    if(loader==true)
    $("#loading").css({"visibility": "visible"});
    if(isJson)
    return this.http.get(this.dev_url+url).map((res : Response) => {
      if(loader==true)
      $("#loading").css({"visibility": "hidden"});
      return res.json();
    })
    else
    return this.http.get(this.dev_url+url).map((res : Response) => {
      $("#loading").css({"visibility": "hidden"});
      return res;
    })
  }

  changeMessage(message: string) {
    this.messageSource.next(message)
  }

  getDetails(url){
    return this.http.get(this.dev_url2+url)
  .map(res => res.json());
  }

  addressTranslationInHindi(data){
    return this.http.post(this.dev_url + '/users/translate', data)
  .map(res => res.json()) ;
  }

  searchByImei(data){
    return this.http.post(this.dev_url+'/devices/searchByIMEI',data) .map(res => res.json()) ;
  }

  "---------------------------New Method for calculate area------------------------------"

  calculateArea(data){
    return this.http.get(this.dev_url+'/hulls?imei='+data.imei+'&f='+data.f+'&t='+data.t).map(res => res.json()) ;
  }

  getVehicleList(data){
    if(data.supAdm){
      return this.http.get(this.dev_url+'/devices/getDeviceList?deviceType='+data.deviceType+'&fromDate='+data.f+'&toDate='+data.t+'&licenceType='+data.licenceType+'&supAdm='+data.supAdm).map(res => res.json()) ;
    }else{

      return this.http.get(this.dev_url+'/devices/getDeviceList?deviceType='+data.deviceType+'&fromDate='+data.f+'&toDate='+data.t+'&licenceType='+data.licenceType).map(res => res.json()) ;
    }
  //   licenceType:that.licenceStatus,
  //  supAdm:that.supAdm
  }

  addMultipleTolls(data){
    return this.http.post(this.dev_url+'/toll/multipleToll',data)
    .map(res => res.json()) ;
  }
  addToll(data){
    return this.http.post(this.dev_url+'/toll/add',data)
    // .map(res => res.json()) ;
  }

   getTolls(){
    return this.http.get(this.dev_url+'/toll/get')
    .map(res => res.json()) ;
  }

  deleteToll(data){
    return this.http.post(this.dev_url+'/toll/delete',data)
  }
  updateToll(data){
    return this.http.post(this.dev_url+'/toll/update',data)
    // .map(res => res.json()) ;
  }

  getSuperAdminList(){
    return this.http.get(this.dev_url+'/users/getSuperAdminList').map(res => res.json()) ;
  }
  getApprovalAddressList(id){
    return this.http.get(this.dev_url+'/googleAddress/addressList?id='+id).map(res => res.json()) ;
  }
  getRenewalHistory(id){
    return this.http.get(this.dev_url+'/devices/renewalHistory?id='+id).map(res => res.json()) ;
  }
   addMultipleInventory(data){
    return this.http.post(this.dev_url+'/Device_inventory/addMultiple',data)
    .map(res => res.json()) ;
  }
   transferInventory(data){
    return this.http.post(this.dev_url+'/Device_inventory/transfer',data)
    .map(res => res.json()) ;
  }
  getInventoryByStatus(){
    return this.http.get(this.dev_url+'/Device_inventory/getInventoryByStatus').map(res => res.json()) ;
  }
  getInventoryCount(id){
    return this.http.get(this.dev_url+'/Device_inventory/getInventoryCount?user='+id).map(res => res.json()) ;
  }
  changeKycStatus(data){
    return this.http.post(this.dev_url+'/users/changeKYCStatus',data)
    .map(res => res.json()) ;
  }
  
//   addMultipleDevice(deviceUploadObject){

//   return this.http.post(this.dev_url  + '/devices/uploadDevice',deviceUploadObject)
//   .map(res => res.json())
// }

imageUrlToBase64(url: string) {

  const httpOptions = {
      headers: new Headers({
        'Content-Type': 'application/json'
      }),
      observe: 'response' as 'body'
    };
    return this.http.get(url, httpOptions).pipe(
      take(1),
      map((arrayBuffer:any) =>
        btoa(
          Array.from(new Uint8Array(arrayBuffer))
          .map((b) => String.fromCharCode(b))
          .join('')
        )
      ),
    )

  // return this.http.get(urL, {
  //     observe: 'body',
  //     responseType: 'arraybuffer',
  //   })
  //   .pipe(
  //     take(1),
  //     map((arrayBuffer) =>
  //       btoa(
  //         Array.from(new Uint8Array(arrayBuffer))
  //         .map((b) => String.fromCharCode(b))
  //         .join('')
  //       )
  //     ),
  //   )
}

  
}
//http://localhost:3000/notifs/overspeedXlReport?from_date=2018-01-24T11:37:08.673Z&to_date=2018-01-24T11:37:08.673Z&_u=5a27deca4468572f678e2d91
//http://localhost:3000/notifs/IgnitionXlReport?from_date=2018-04-02T07:37:10.109Z&to_date=2018-05-17T07:37:10.109Z&vname=MH 08 E 0625&_u=5ae09545f01a5576cf6c0e1b
 // http://localhost:3000/stoppage/stoppageXlReport?from_date=2018-04-06T13:26:02.444Z&to_date=2018-04-06T13:26:02.444Z&_u=5a27deca4468572f678e2d91&vname=5a46086f3ab69a449498bc21

