import { Component, OnInit, Output, EventEmitter, Input, OnChanges } from '@angular/core';
import { BsDatepickerConfig } from 'ngx-bootstrap';
import { ContactService } from '../../contact.service';
declare var $:any;
import * as moment from 'moment-timezone';
import { Router } from '@angular/router';
import { ReportService } from '../report.service';
@Component({
  selector: 'app-report-filter',
  templateUrl: './report-filter.component.html',
  styleUrls: ['./report-filter.component.scss']
})
export class ReportFilterComponent implements OnInit {
  from_date =new Date();
  to_date = new Date();
  isCC:Boolean=true;
  bsConfig: Partial<BsDatepickerConfig>;
  @Output() onReportFIlter: EventEmitter<any> = new EventEmitter<any>();
  superAdmin: any;
  fs: any;
  emailid: any;
  ls: any;
  or: any;
  useridd: any;
  bilingMonth = new Date();
  mb: any;
  selectGroup=""
  custtype: any;
  devicesss: any;
  minIdleTime:any=5;
  showXL : Boolean =true; 
  filterRtype = 'Time';
  userFilterType='Name';
  deviceFilterType='IMEI';
  // selectedComponent="summary_report"
  clicked:boolean=false;
  reportType = ['Time','Daily','Trip'];
  userRadio= ['Phone', 'Name'];
  deviceRadio= ['IMEI','SIM'];
  deviceRadio1= ['IMEI','NAME'];
  billingType = [{
    selectedValue:'Monthly',
    value: 'Monthly'
  },

  {
    selectedValue:'Yearly',
    value: 'Yearly'
  }]

  billing_status =[
    {
      selectedValue:'Paid',
      value: 'Paid'
    },
    {
      selectedValue:'Pending',
      value: 'Pending'
    }

  ]
  finall: any;
  deleteduser:boolean=false;
  deleteddevice:boolean=false;
  options: any=[{selectedValue : '',value:''}];
  cust: boolean;
  logoutbut: boolean;
  dealer: boolean;
  showLoader:boolean=true;
  sidenavbarcontent:boolean=true
  colorTheme = 'theme-dark-blue';
  optionLabel:String = 'Vehicle';
  showFromDate : Boolean = true;
  lableVariable = 'To' ; 
  stoppage_duration =[{value: "0",view_value:"All Data"},{value: "1",view_value:"Less Than 2 Hours"},{value: "2",view_value:"More Than 2 Hours"},{value: "6",view_value:"More Than 6 Hours"},{value: "12",view_value:"More Than 12 Hours"},{value: "24",view_value:"More Than 24 Hours"}];
  selectedStopageDuration="0"
  componentIdentifier=""
  
  reportArray = [
    {name : "AC Report",Rstatus:true,Astatus:false,value:"ac_report"},
    {name:"Daily Report",Rstatus:true,Astatus:false,value:"daily_report"},
    {name:"Daily Logs",Rstatus:true,Astatus:false,value:"daily_logs"},
    {name:"Daywise Report",Rstatus:true,Astatus:false,value:"daywise_report"},
    {name : "Data Push Reports",Rstatus : true,Astatus:false,value:"dataPushReport"},
    {name:"Distance Report",Rstatus : true,Astatus:false,value:"distance_report"},
    {name : "Driver Performance Report",Rstatus : true,Astatus:false,value:"driver_performanceReport"},
    {name : "Geofence Report",Rstatus : true,Astatus:false,value:"geofence_report"},
    {name :"Idle Report",Rstatus : true,Astatus:false,value:"idle_report"},
    {name : "Ignition Report",Rstatus : true,Astatus:false,value:"ignition_report"},
    {name : "Loading Unloading Trip",Rstatus : true,Astatus:false,value:"loading_unloading_trip"},
    {name : "Notification Center",Rstatus : true,Astatus:false,value:"notification_master"},
    {name : "Overspeed Report",Rstatus : true,Astatus:false,value:"overspeed_report"},
    {name : "Performance Reports",Rstatus : true,Astatus:false,value:"performanceReport"},
    {name : "POI Report",Rstatus : true,Astatus:false,value:"poi_report"},
    {name : "Route Violation Report",Rstatus : true,Astatus:false,value:"route_violation_report"},
    {name :  "Speed Variation",Rstatus:true,Astatus:false,value:"speed_variation"},
    {name : "Summary Report",Rstatus : true,Astatus:false,value:"summary_report"},
    {name : "Stoppage Report",Rstatus : true,Astatus:false,value:"stoppage_report"},
    {name : "SOS Report",Rstatus : true,Astatus:false,value:"sos_report"},
    {name:"Trip Report",Rstatus:true,Astatus:false,value:"trip_report"},
    {name : "Travel Path Report",Rstatus : true,Astatus:false,value:"travel_path_report"},
    {name : "Working Hours Reports",Rstatus : true,Astatus:false,value:"working_hours_report"},
    {name : "Maintenance Reports",Rstatus : true,Astatus:false,value:"maintanance_report"},
    

//     ac_report: {Rstatus: false, Astatus: false}
// alert_report: {Rstatus: false, Astatus: false}
// daily_report: {Rstatus: false, Astatus: false}
// daywise_report: {Rstatus: false, Astatus: false}
// distance_report: {Rstatus: false, Astatus: false}
// driver_performanceReport: {Rstatus: false, Astatus: false}
// fuel_consumption_report: {Rstatus: false, Astatus: false}
// fuel_report: {Rstatus: false, Astatus: false}
// geofence_report: {Rstatus: false, Astatus: false}
// idle_report: {Rstatus: false, Astatus: false}
// ignition_report: {Rstatus: false, Astatus: false}
// loading_unloading_trip: {Rstatus: false, Astatus: false}
// overspeed_report: {Rstatus: false, Astatus: false}
// poi_report: {Rstatus: false, Astatus: false}
// route_violation_report: {Rstatus: false, Astatus: false}
// sos_report: {Rstatus: false, Astatus: false}
// speed_variation: {Rstatus: false, Astatus: false}
// stoppage_report: {Rstatus: false, Astatus: false}
// summary_report: {Rstatus: false, Astatus: false}
// travel_path_report: {Rstatus: false, Astatus: false}
// trip_report: {Rstatus: false, Astatus: false}
// user_trip_report: {Rstatus: false, Astatus: false}
// __proto__: Object

    // {name :"Fuel Report",Rstatus : true,Astatus:false,value:"fuel_report"},
    // {name:"Fuel Consumption Report",Rstatus:true,Astatus:false,value:"fuel_consumption_report"},
    // 
    // {name : "User Trip Report",Rstatus : true,Astatus:false,value:"user_trip_report"},
    // {name : "Alert Report",Rstatus : true,Astatus:false,value:"alert_report"}  ,
  ];
  reportPrefrecne:any
  componentArray=['AC_report','daily_report','ss','dayWiseReport','distance_report','Driver_performance','geofence_report',
  'idle_report','ignition_report','loadunloadTrip','notification_master','over_speed','poi_report','route_violation_report','speed_variation','summary_report','stoppage_report','device_sos_report',
  'trip_report','travel_path-report','working_hours_report','maintanance_report',]
  // 'notification_master',"billing_detail",'fuel_report_graph','vehicle_expenses','temp_report_graph','deviceMaster','gps_master','usersMaster','fuel_consumption_report']
  // @Input() componentIdentifier: string;
  constructor(private contactService: ContactService,private router:Router,private reportService:ReportService) { 
    console.log(this.componentIdentifier,this.selectedStopageDuration);
    this.bsConfig = Object.assign({ dateInputFormat: 'DD-MM-YYYY, h:mm:ss a' }, { containerClass: this.colorTheme });
  }
  groups
  ngOnInit() {
    
    this.loadropdown();
    var fTime = new Date();
    fTime.setHours(0,0,0,0);   
    this.from_date = new Date(fTime);
   
    if(this.componentIdentifier=="performanceReport"){
      fTime.setDate(fTime.getDate()-1);
     
      this.from_date = new Date(fTime);
    }
    $("#dbselect_1").change(function () {
  
   that.clicked=false
});
   
       $("#dbselect_billtype").change(function () {
  
   that.clicked=false
});

       $("#dbselect_billStatus").change(function () {
  
   that.clicked=false
});

    
       $("#dbselectPhone").change(function () {
  
   that.clicked=false
});

       $("#dbselectName").change(function () {
  
   that.clicked=false
});  

$("#dbselectSIM").change(function () {
  
   that.clicked=false
});    
   
$("#dbselectIMEI").change(function () {
  
   that.clicked=false
});
  
$("#dbselectVehicleName").change(function () {
  
   that.clicked=false
});
    
$("#dbselect_2").change(function () {
  
   that.clicked=false
});
   
 $("#dbselect_3").change(function () {
  
   that.clicked=false
});  
        $("#dbselect_notif").change(function () {
  
   that.clicked=false
});  
    
    $("#dbselect").change(function () {
  
   that.clicked=false
});
$("#dbselect1").change(function () {
  
   that.clicked=false
});

$("#dbselectNotif").change(function () {
  
   that.clicked=false
});
    // console.log('this.componentIdentifier',this.componentIdentifier);
     this.reportPrefrecne = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).report_preference;
    console.log("----------------",this.reportPrefrecne,'---->',typeof(this.reportPrefrecne));
   
      let that = this;
    if(this.reportPrefrecne !=undefined){
      for(var i=0;i<this.reportArray.length;i++){
        if(this.reportPrefrecne[this.reportArray[i].value]){
          // console.log(this.reportArray[i],'->',this.reportPrefrecne[this.reportArray[i].value].Rstatus);
          this.reportArray[i].Rstatus=this.reportPrefrecne[this.reportArray[i].value].Rstatus;
          // //  this.reportArray[i].Astatus=this.reportPrefrecne[this.reportArray[i].value].Astatus
          // if(!(this.reportPrefrecne[this.reportArray[i].value].Rstatus)){
          //   // this.reportArray.splice(i,1);
          // }
        }else if(this.reportArray[i].value=="dataPushReport"){
            this.reportArray[i].Rstatus=true;
        }
      }    
    }
    
    // for(var j=0;j<this.reportArray.length;j++){
    //   if(this.reportArray[j].Rstatus==false){
    //     this.reportArray.splice(j,1);
    //   }
    // }
    this.reportArray.filter(x => x.Rstatus === false).forEach(x => this.reportArray.splice(this.reportArray.indexOf(x), 1));
    // console.log(this.reportArray);

    if(this.reportArray.length==0){
      this.router.navigate(['/reports/no-report'])
    }

    if( this.componentIdentifier=="driver_performanceReport" ){
     this.sidenavbarcontent=false
    }else{
       this.sidenavbarcontent=true
    }

    if(this.componentIdentifier === 'summary_report'){
   
      fTime.setDate(fTime.getDate()-1);
     
      this.from_date = new Date(fTime);
  
      var td  = new Date().setHours(23,59,59,999);
      this.to_date = new Date(td);
      this.bsConfig = Object.assign({ dateInputFormat: 'DD-MM-YYYYY' }, { containerClass: this.colorTheme });

    }

    if((this.componentIdentifier === 'daywise_report')){
      var yt = moment().subtract(1, 'days');
      var ptt = new Date(yt).setHours(0, 0, 0);
      var ttt = new Date(yt).setHours(23,59,59);
      this.from_date = new Date(ptt);
      this.to_date = new Date(ttt);
      
      console.log('this.from_date', this.from_date);
      console.log('this.to_date', this.to_date);
    }

    if(this.componentIdentifier === 'daily_report' || this.componentIdentifier === 'ss' || this.componentIdentifier=="speed_variation"){
      this.showFromDate = false;
      this.lableVariable = 'Select Date';
      
    }


    if((this.componentIdentifier === 'fuel_report_graph') || (this.componentIdentifier === 'vehicle_expenses')||(this.componentIdentifier === 'temp_report_graph','vehicle_expenses')){
      this.showXL = false;
    }
   
  
    this.superAdmin = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).isSuperAdmin;
 
    this.fs = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).fn;
    this.ls = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).ln;
    this.emailid = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).email;
    this.or = JSON.parse(window.atob(window.localStorage.token.split(".")[1]))._orgName;
    this.useridd = JSON.parse(window.atob(window.localStorage.token.split('.')[1]))._id;
    this.mb =  JSON.parse(window.atob(window.localStorage.token.split('.')[1])).phn;
    this.custtype =  JSON.parse(window.atob(window.localStorage.token.split('.')[1])).isDealer;
    var cc= JSON.parse(window.atob(window.localStorage.token.split('.')[1])).customer_role;
 
    
     if(cc=="cc"){
       this.isCC=false;
     }
    if(this.componentIdentifier === 'geofence_report'){
      this.optionLabel = 'geofences'; 
      
      this.getgeofence();
    }else if(this.componentIdentifier === 'route_violation_report'){
      this.routeViolationArr()
    }else if(this.componentIdentifier === 'billing_detail'){
      this.getUser();

    }else{
      // this.contactService.getDevice(this.emailid,this.useridd).subscribe(
      this.optionLabel = 'Vehicle';
      //   data => {
          this.devicesss = JSON.parse(localStorage.getItem('vehicaleData'));
          this.groups=JSON.parse(localStorage.getItem('groupData'))
          console.log(this.devicesss);
          
          this.finall = (this.devicesss);
          this.options = [];
        
          for(let i=0;i<this.devicesss.length;i++){
  
            // if(this.devicesss.devices[i].type_of_device =="Tracker"){
              let a ={
                value : this.devicesss[i].Device_Name,
                viewValue:this.devicesss[i].Device_Name,
                did:this.devicesss[i].Device_ID,
                id:this.devicesss[i]._id,
                user:this.devicesss[i].user,
                groupName:this.devicesss[i].groupName?this.devicesss[i].groupName:'',
                // email: this.devicesss.devices[i].Email_ID,
                // deviceType: this.devicesss.devices[i].type_of_device,      
              }
             
             if ((this.componentIdentifier === 'trip_report')||(this.componentIdentifier === 'idle_report')||(this.componentIdentifier == 'fuel_consumption_report')||(this.componentIdentifier === 'poi_report')||(this.componentIdentifier === 'stoppage_report')||(this.componentIdentifier === 'vehicle_expenses')||(this.componentIdentifier === 'loadunloadTrip')||(this.componentIdentifier === 'maintanance_report') || (this.componentIdentifier==="loading_unloading_trip") ){
                a['selectedValue'] = this.devicesss[i]._id ; 
             } else if ((this.componentIdentifier === 'fuel_report_graph') || (this.componentIdentifier === 'distance_report') || (this.componentIdentifier === 'ac_report')|| (this.componentIdentifier === 'travel_path_report') ||(this.componentIdentifier === 'temp_report_graph')||(this.componentIdentifier === 'summary_report')||(this.componentIdentifier === 'overspeed_report')||(this.componentIdentifier === 'daily_report')||(this.componentIdentifier === 'sos_report')||(this.componentIdentifier === 'ignition_report') ||(this.componentIdentifier === 'working_hours_report')|| (this.componentIdentifier==="performanceReport")|| (this.componentIdentifier === 'daywise_report')||(this.componentIdentifier === 'censor_detail')||(this.componentIdentifier === 'notification_master') || !this.isCC ||(this.componentIdentifier === 'daily_logs') || ( this.componentIdentifier==="dataPushReport")||(this.componentIdentifier=="speed_variation")){
                a['selectedValue'] = this.devicesss[i].Device_ID ; 

              }
              this.options.push(a);
            // }
          }

          if(this.componentIdentifier == 'poi_report'){
            this.getPOI();
          }else{
            this.loadropdown();
          }
      

        
            // console.log("ignition option",this.options);
            let that = this;
            // setTimeout(()=>{ 
            // },100)  
        
        // });

      

    }
  



      if(this.custtype == true){
        this.cust = true;
      }  
      if(this.mb.charAt(0)=="n"){
        this.mb = ' '
      }

      if( window.localStorage['Custumer'] == 'ON'){
        this.logoutbut = false
        this.dealer = true
     }
     else{
         this.logoutbut = true
     } 
     
     if(this.componentIdentifier == 'usersMaster'){  
      this.getAllUser();
     }

     if((this.componentIdentifier == 'deviceMaster')||(this.componentIdentifier == 'gps_master')){  
      this.getAllDevice();
     }
     if(this.componentIdentifier === 'notification_master' || !this.isCC){
          this.getDeviceForNotif();
     }
      
  
     
  }

  loadropdown() {
    let that = this;
    var placeholderval;
    if(this.componentIdentifier == 'geofence_report'){
      placeholderval = 'Select Geofence .....'
    }
    if((this.componentIdentifier === 'distance_report')||(this.componentIdentifier === 'fuel_report_graph')||(this.componentIdentifier === 'temp_report_graph')||(this.componentIdentifier === 'loadunloadTrip')||(this.componentIdentifier === 'censor_detail') || (this.componentIdentifier === 'idle_report') ||(this.componentIdentifier ==='performanceReport')){
      placeholderval = 'Select Vehicles .....'
    }
    if(this.componentIdentifier === 'billing_detail'){
      placeholderval = 'Select User .....'

    }
    var script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", "https://unpkg.com/multiple-select@1.3.1/dist/multiple-select.min.js");
    document.getElementsByTagName("head")[0].appendChild(script);
    // ||(this.componentIdentifier === 'notification_master')
  
    if((this.componentIdentifier == 'geofence_report')||(this.componentIdentifier == 'usersMaster')||(this.componentIdentifier == 'deviceMaster')||(this.componentIdentifier === 'poi_report')||(this.componentIdentifier === 'billing_detail')||(this.componentIdentifier === 'fuel_report_graph')||(this.componentIdentifier === 'temp_report_graph')||(this.componentIdentifier === 'fuel_consumption_report')||(this.componentIdentifier === 'sos_report')||(this.componentIdentifier === 'vehicle_expenses')||(this.componentIdentifier === 'censor_detail')||(this.componentIdentifier ==='gps_master') ){
      console.log(placeholderval);

      setTimeout(() => {
        $('#dbselect').multipleSelect({
          width: 200,
          placeholder: this.componentIdentifier == 'geofence_report'?'Select Geofence .....': placeholderval,
          filter: true,
          single: true,
          selectAll: false
   
        })
    
       that.showLoader = false;
      }, 100);
      

      if(this.componentIdentifier === 'billing_detail'){
        setTimeout(() => {

          $('#dbselect_billtype').multipleSelect({
            width: 200,
            placeholder: "Select Type",
            filter: true,
            single: true,
            selectAll: false  
          }) 
       
  
          $('#dbselect_billStatus').multipleSelect({
            width: 200,
            placeholder: "Select Status",
            filter: true,
            single: true,
            selectAll: false  
          }) 
        }, 100);
      }

      if(this.componentIdentifier == 'usersMaster'){
        setTimeout(() => {
          $('#dbselectPhone').multipleSelect({
            width: 250,
            placeholder: "Customer Phone",
            filter: true,
            single: true,
            selectAll: false  ,
         
          }) 

          $("#dbselectPhone").multipleSelect("disable");
    
          $('#dbselectName').multipleSelect({
            width: 250,
            placeholder: "Customer Name",
            filter: true,
            single: true,
            selectAll: false  
          }) 
    
        },100)
       }

       if(this.componentIdentifier == 'deviceMaster'){

        setTimeout(() => {
          $('#dbselectIMEI').multipleSelect({
            width: 250,
            placeholder: "Vehicle IMEI",
            filter: true,
            single: true,
            selectAll: false  
          }) 
    
          $('#dbselectSIM').multipleSelect({
            width: 250,
            placeholder: "Sim Number",
            filter: true,
            single: true,
            selectAll: false  
          }) 

          $("#dbselectSIM").multipleSelect("disable");
    
        },100)
       }

       if(this.componentIdentifier == 'gps_master'){

        setTimeout(() => {
          $('#dbselectIMEI').multipleSelect({
            width: 250,
            placeholder: "Vehicle IMEI",
            filter: true,
            single: true,
            selectAll: false  
          }) 
    
          $('#dbselectVehicleName').multipleSelect({
            width: 250,
            placeholder: "Vehicle Name",
            filter: true,
            single: true,
            selectAll: false  
          }) 

          $("#dbselectVehicleName").multipleSelect("disable");
    
        },100)

       }
    }else{      
      setTimeout(() => {
        $('#dbselect').multipleSelect({
          width: 200,
          placeholder:this.componentIdentifier == 'geofence_report'?'Select Geofence....': 'Select Vehicle.....',
          filter: true,
   
        })  
      }, 100);

    }
    if(this.componentIdentifier == 'poi_report'){
      setTimeout(() => {
        $('#dbselect_1').multipleSelect({
          width: 200,
          placeholder: "Select POI",
          filter: true,
          single: true,
          selectAll: false  
        }) 
      }, 100);
    }

  

    if(this.componentIdentifier == 'stoppage_report'){
      setTimeout(() => {
        $('#dbselect_2').multipleSelect({
          width: 200,
          placeholder: "Select Duration",
          filter: true,
          single: true,
          selectAll: false,  
        }) 
      }, 200);
    }

    if(this.componentIdentifier == 'route_violation_report'){
      setTimeout(() => {
        $('#dbselect_3').multipleSelect({
          width: 200,
          placeholder: "Select Route",
          filter: true,
          single: true,
          selectAll: false  
        }) 
      }, 100);
    }

    if(this.componentIdentifier == 'notification_master' ||!this.isCC){
      setTimeout(() => {
        $('#dbselect_notif').multipleSelect({
          width: 200,
          placeholder: "Select type",
          filter: true,
          // single: true,
          // selectAll: false  
        }) 

        $('#dbselectNotif').multipleSelect({
          width: 200,
          placeholder: "Select Vehicle",
          filter: true,
          // single: true,
          // selectAll: false  
        }) 
      }, 100);

    
    }


    // if(this.componentIdentifier == 'usersMaster'){
      
    //   $('#dbselectPhone').multipleSelect({
    //     width: 200,
    //     placeholder: "Customer Phone",
    //     filter: true,
    //     single: true,
    //     selectAll: false  
    //   }) 

    //   $('#dbselectName').multipleSelect({
    //     width: 200,
    //     placeholder: "Customer Name",
    //     filter: true,
    //     single: true,
    //     selectAll: false  
    //   }) 
    // }
    // var triggerReport = setTimeout(()=>{
    //   clearTimeout(triggerReport);
    //   var data = '';
    //   if(that.componentIdentifier != 'fuel_report_graph'){
    //     that.reportFilter(data);
    //   }
    
    // },200)
   
  }


  deviceArr = [];
  deviceFilterArr :any;
   reportFilter(data): void {
     var demo=[]
    this.deviceArr =  $('#dbselect').multipleSelect('getSelects','value'); 
    // var group =  $('#groupSelect').multipleSelect('getSelects','value'); 
    //   console.log("GROUPS==>",group);
      
     if(this.componentIdentifier=="travel_path_report"){
       console.log(this.options)
       for(var i=0;i<this.deviceArr.length;i++){
         for(var j=0;j<this.options.length;j++){
           if(this.deviceArr[0]==this.options[j].did){
             demo.push({id:$('#dbselect').multipleSelect('getSelects','value'),'name':this.options[j].value},)
             console.log("assasa", demo);
             
           }
         }
       }
      //  this.deviceArr=
     }
    //  else
    // this.deviceArr =  $('#dbselect').multipleSelect('getSelects','value'); 
    console.log('this.deviceArr',this.deviceArr);
    var that  = this;
     var filter = {
       fromDate : this.from_date,
       toDate : this.to_date,
       deviceArr :this.componentIdentifier=="travel_path_report"? demo:this.deviceArr
     }
     if (this.componentIdentifier == 'fuel_consumption_report') {
       filter['filter_type'] = this.filterRtype;
          var tempArr = [];
          var dataArr = this.options.filter(function (item) {  
              if(item.id == that.deviceArr[0]){   
                return item;
              }             
          });
       
          filter.deviceArr = dataArr ; 
     }

     if(this.componentIdentifier === 'idle_report'){
      filter['minidleT'] = this.minIdleTime ; 
     }

     if(this.componentIdentifier === 'poi_report'){
      let poi_id =  $('#dbselect_1').multipleSelect('getSelects','value');
      filter['poi_id'] = poi_id ; 
     }

     
     if(this.componentIdentifier === 'stoppage_report'){
      let duration = [];
      duration =  $('#dbselect_2').multipleSelect('getSelects','value');
      filter['duration'] = duration ; 
     }

     if(this.componentIdentifier === 'route_violation_report'){
      let vroute = [];
      vroute =  $('#dbselect_3').multipleSelect('getSelects','value');
      var routeArr = this.routeArr.filter(function (item) {  
        if(item._id == vroute[0]){   
          return item;
        }             
    });
      filter['route'] = routeArr ; 
     }

     if(this.componentIdentifier === 'notification_master'||!this.isCC){
      let notif_type = [];
      notif_type =  $('#dbselect_notif').multipleSelect('getSelects','value');

      filter.deviceArr =  $('#dbselectNotif').multipleSelect('getSelects','value');

      // var devIwner = this.notifDevArr.filter((u)=>{
      //   filter.deviceArr.
      // })
  
      filter['notitype'] = notif_type ; 
     }

     if(this.componentIdentifier === 'usersMaster'){
      var userID = $('#dbselectPhone').multipleSelect('getSelects','value'); 
      var userID1 = $('#dbselectName').multipleSelect('getSelects','value'); 
      if((userID != undefined)&&(this.userFilterType == 'Phone')){
        filter['userId'] = userID;
      }
      if((userID1 != undefined)&&(this.userFilterType === 'Name')){
        filter['userId'] = userID1;
      }
        filter['deletedUser']  = this.deleteduser;
     }

     if((this.componentIdentifier === 'deviceMaster')||(this.componentIdentifier === 'gps_master')){
      var DID = $('#dbselectIMEI').multipleSelect('getSelects','value'); 
      if((this.componentIdentifier === 'deviceMaster')){
        var DID1 = $('#dbselectSIM').multipleSelect('getSelects','value'); 
      }else{
        var DID1 = $('#dbselectVehicleName').multipleSelect('getSelects','value'); 
      }
    
      if((DID != undefined)&&(this.deviceFilterType == 'IMEI')){
        filter['deviceId'] = DID;
        filter['type'] = 'IMEI';
      }
      if((DID1 != undefined)&&(this.deviceFilterType === 'SIM')){
        filter['deviceId'] = DID1;
        if(this.componentIdentifier === 'deviceMaster'){
          filter['type'] = 'SIM';
        }else{
          filter['type'] = 'VNAME';
        }
    

      }
      console.log('this.deleteddevice',this.deleteddevice);
        filter['deletedDevice']  = this.deleteddevice;
       
     }
    
     console.log("FILTER---",filter,this.componentIdentifier);
     if(this.componentIdentifier=="daily_report")
      this.reportService.callMethodOfSecondComponent(filter)

      if(this.componentIdentifier=="ac_report")
      this.reportService.accReport(filter)

       if(this.componentIdentifier=="speed_variation")
      this.reportService.speedVariation(filter)


      if(this.componentIdentifier=="daily_logs")
      this.reportService.dailyLogs(filter)

      if(this.componentIdentifier=="daywise_report")
      this.reportService.dayWiseReport(filter)

      if(this.componentIdentifier=="distance_report")
      {
        this.reportService.distanceReport(filter)
      }

      

       if(this.componentIdentifier=="geofence_report")
      this.reportService.geofenceReport(filter)

       if(this.componentIdentifier=="idle_report")
      this.reportService.idleReport(filter)

       if(this.componentIdentifier=="ignition_report")
      this.reportService.ignitionReport(filter)

       if(this.componentIdentifier=="loadunloadTrip")
      this.reportService.loadunloadTrip(filter)

        if(this.componentIdentifier=="notification_master" ||!this.isCC)
        {
          console.log(filter);
          
          this.reportService.notificationMaster(filter)

        }

       if(this.componentIdentifier=="overspeed_report")
      this.reportService.overspeedReport(filter)

      if(this.componentIdentifier=="poi_report")
      this.reportService.poiReport(filter)

       if(this.componentIdentifier=="route_violation_report")
      this.reportService.routeViolationReport(filter)

      if(this.componentIdentifier=="summary_report")
      this.reportService.summaryReport(filter)

      if(this.componentIdentifier=="stoppage_report")
      this.reportService.stoppageReport(filter)

      if(this.componentIdentifier=="sos_report")
      this.reportService.sosReport(filter)
        if(this.componentIdentifier=="loading_unloading_trip"){
          this.reportService.loadunloadTrip(filter)
        }

      if(this.componentIdentifier=="trip_report")
      this.reportService.tripReport(filter)

      if(this.componentIdentifier=="travel_path_report"){
        this.reportService.travelPathReport(filter)
      }

        if(this.componentIdentifier=="working_hours_report")
      this.reportService.workingHoursReport(filter)

        if(this.componentIdentifier=="maintanance_report")
      this.reportService.maintanceReport(filter)

       if(this.componentIdentifier=="dataPushReport")
      this.reportService.datapushReport(filter)

      if(this.componentIdentifier=="performanceReport")
      {
        this.reportService.performanceReport(filter)
      }
    this.onReportFIlter.emit(filter);
}

reportFilter_billing(){
  var userObj =  $('#dbselect').multipleSelect('getSelects','value'); 
  var billingType = $('#dbselect_billtype').multipleSelect('getSelects','value'); 
  var billingStatus = $('#dbselect_billStatus').multipleSelect('getSelects','value'); 
  
  var filter = {
    date : this.modelDate,
    type : billingType,
    status : billingStatus,
    user :userObj
  }

  console.log(filter);

  this.onReportFIlter.emit(filter);
}


  
changeDate(dateid) {
this.clicked=false
  if (dateid == 'today') {
    var td = new Date();
    this.from_date = new Date(td.setHours(0, 0, 0));
    this.to_date = new Date();
    console.log('this.from_date', this.from_date);
  }
  if (dateid == 'yesterday') {
    var yt = moment().subtract(1, 'days');
    var ptt = new Date(yt).setHours(0, 0, 0);
    var ttt = new Date(yt).setHours(23,59,59);
    this.from_date = new Date(ptt);
    this.to_date = new Date(ttt);
    console.log('this.from_date', this.from_date);
    console.log('this.to_date', this.to_date);
  }
  if (dateid == 'week') {
    var wd = moment().startOf('week')
    this.from_date = new Date(wd);
    console.log('this.from_date', this.from_date);
    this.to_date = new Date();
  }
  if (dateid == 'month') {
    var md = moment().startOf('month').format();
    this.from_date = new Date(md);
    console.log('this.from_date', this.from_date);
    this.to_date = new Date();
  }
}
exportPDF(){
  var filter='getPdf'
      //  this.reportService.callMethodOfSecondComponent('getExcel')

        if(this.componentIdentifier=="daily_report")
      this.reportService.callMethodOfSecondComponent(filter)

      if(this.componentIdentifier=="ac_report")
      this.reportService.accReport(filter)

       if(this.componentIdentifier=="speed_variation")
      this.reportService.speedVariation(filter)


      if(this.componentIdentifier=="daily_logs")
      this.reportService.dailyLogs(filter)

      if(this.componentIdentifier=="daywise_report")
      this.reportService.dayWiseReport(filter)

      if(this.componentIdentifier=="distance_report")
      {
        this.reportService.distanceReport(filter)
      }

       if(this.componentIdentifier=="geofence_report")
      this.reportService.geofenceReport(filter)

       if(this.componentIdentifier=="idle_report")
      this.reportService.idleReport(filter)

       if(this.componentIdentifier=="ignition_report")
      this.reportService.ignitionReport(filter)

       if(this.componentIdentifier=="loadunloadTrip")
      this.reportService.loadunloadTrip(filter)

        if(this.componentIdentifier=="notification_master" ||!this.isCC)
      this.reportService.notificationMaster(filter)

       if(this.componentIdentifier=="overspeed_report")
      this.reportService.overspeedReport(filter)

      if(this.componentIdentifier=="poi_report")
      this.reportService.poiReport(filter)

       if(this.componentIdentifier=="route_violation_report")
      this.reportService.routeViolationReport(filter)

      if(this.componentIdentifier=="summary_report")
      this.reportService.summaryReport(filter)

      if(this.componentIdentifier=="stoppage_report")
      this.reportService.stoppageReport(filter)

      if(this.componentIdentifier=="sos_report")
      this.reportService.sosReport(filter)

      if(this.componentIdentifier=="trip_report")
      this.reportService.tripReport(filter)

      if(this.componentIdentifier=="travel_path_report"){
        this.reportService.travelPathReport(filter)
      }

        if(this.componentIdentifier=="working_hours_report")
      this.reportService.workingHoursReport(filter)

        if(this.componentIdentifier=="maintanance_report")
      this.reportService.maintanceReport(filter)

       if(this.componentIdentifier=="loading_unloading_trip"){
          this.reportService.loadunloadTrip(filter)
        }
         if(this.componentIdentifier=="dataPushReport")
      this.reportService.datapushReport(filter);

     if(this.componentIdentifier=="performanceReport")
      {
        this.reportService.performanceReport(filter)
      }

}

exportExel(){
  // this.onReportFIlter.emit('getExcel');
  var filter='getExcel'
      //  this.reportService.callMethodOfSecondComponent('getExcel')

        if(this.componentIdentifier=="daily_report")
      this.reportService.callMethodOfSecondComponent(filter)

      if(this.componentIdentifier=="ac_report")
      this.reportService.accReport(filter)

       if(this.componentIdentifier=="speed_variation")
      this.reportService.speedVariation(filter)


      if(this.componentIdentifier=="daily_logs")
      this.reportService.dailyLogs(filter)

      if(this.componentIdentifier=="daywise_report")
      this.reportService.dayWiseReport(filter)

      if(this.componentIdentifier=="distance_report")
      {
        this.reportService.distanceReport(filter)
      }

       if(this.componentIdentifier=="geofence_report")
      this.reportService.geofenceReport(filter)

       if(this.componentIdentifier=="idle_report")
      this.reportService.idleReport(filter)

       if(this.componentIdentifier=="ignition_report")
      this.reportService.ignitionReport(filter)

       if(this.componentIdentifier=="loadunloadTrip")
      this.reportService.loadunloadTrip(filter)

        if(this.componentIdentifier=="notification_master" ||!this.isCC)
      this.reportService.notificationMaster(filter)

       if(this.componentIdentifier=="overspeed_report")
      this.reportService.overspeedReport(filter)

      if(this.componentIdentifier=="poi_report")
      this.reportService.poiReport(filter)

       if(this.componentIdentifier=="route_violation_report")
      this.reportService.routeViolationReport(filter)

      if(this.componentIdentifier=="summary_report")
      this.reportService.summaryReport(filter)

      if(this.componentIdentifier=="stoppage_report")
      this.reportService.stoppageReport(filter)

      if(this.componentIdentifier=="sos_report")
      this.reportService.sosReport(filter)

      if(this.componentIdentifier=="trip_report")
      this.reportService.tripReport(filter)

      if(this.componentIdentifier=="travel_path_report"){
        this.reportService.travelPathReport(filter)
      }

        if(this.componentIdentifier=="working_hours_report")
      this.reportService.workingHoursReport(filter)

        if(this.componentIdentifier=="maintanance_report")
      this.reportService.maintanceReport(filter)

       if(this.componentIdentifier=="loading_unloading_trip"){
          this.reportService.loadunloadTrip(filter)
        }
         if(this.componentIdentifier=="dataPushReport")
      this.reportService.datapushReport(filter);

       if(this.componentIdentifier=="performanceReport")
      {
        this.reportService.performanceReport(filter)
      }

}
geofenceArr = [];
getgeofence(){
  this.geofenceArr=[];
  this.contactService.getallgeofence(this.useridd).subscribe(
    data => {
      this.options = data ;
      for(var i = 0; i<this.options.length;i++){
        this.options[i]['selectedValue'] = this.options[i]._id;
        this.options[i]['value']  = this.options[i].geoname ; 
      }
      let that = this;
      setTimeout(()=>{
        that.loadropdown();
      },100)  
      console.log('this.options',this.options);
    });
}


getUser(){
  this.contactService.getDistributerList(this.useridd).subscribe(
    data => {
      console.log('data',data);
      this.options = data ;
      for(var i = 0; i<this.options.length;i++){
        this.options[i]['selectedValue'] = this.options[i]._id;
        this.options[i]['value']  = this.options[i].first_name + ' '  +  this.options[i].last_name; 
      }
      let that = this;
      setTimeout(()=>{
        that.loadropdown();
      },100)  
      console.log('this.options',this.options);
    });

}

route_detail_show=[];
poiArr=[];
getPOI(){
  // console.log("Mapping history !!!");
  this.contactService.getPOI(this.useridd)
  .subscribe(res=>{
  //   console.log("routedet",res);
    this.route_detail_show=res;

    var poiObj; 

    for(var i=0;i<this.route_detail_show.length;i++){
      poiObj ={
          poiname: this.route_detail_show[i].poi.poiname,
          id : this.route_detail_show[i]._id
        }

        this.poiArr.push(poiObj);
    }

  
    this.loadropdown();
  //   console.log("routeDetails=>",this.poiArr);
  },err=>{
    this.loadropdown();
  })
}

routeArr =[];

routeViolationArr(){
  var that =this;
  this.contactService.routeViolation(this.useridd).subscribe(
    res => {
      
      var route =[];
      this.routeArr =[];
      route = res;       
      for(let i=0;i<route.length;i++){      
          this.routeArr.push(route[i]);   
      }
        console.log(this.routeArr);

        setTimeout(()=>{
          that.loadropdown();
        },100)  
    });
  
}

modelDate:any=new Date();

onOpenCalendar(container) {
  var that= this;
  container.monthSelectHandler = (event: any): void => {
    container._store.dispatch(container._actions.select(event.date));
    console.log(that.modelDate);
  };     
    container.setViewMode('month');
   
 }

 censor_detail(){
  var deviceObj =  $('#dbselect').multipleSelect('getSelects','value'); 
 
  console.log(deviceObj);
  var filter = {
   device : deviceObj
  }

  console.log(filter);

  this.onReportFIlter.emit(filter);

 }

 userArr=[];
 notifDevArr=[];
 getAllUser(){
   var that = this;
   var userObj = {
    "draw": 1,
    "columns": [
      {"data": "_id"},
      {
        "data": "first_name"},
      { "data": "phone"},
      {"data": "last_name"},
    ],
    "order": [
      {
        "column": 0,
        "dir": "desc"
      }
    ],
    "start": 0,
    "length": -1,
    "search": {
      "value": "",
      "regex": false
    },
    "op": {},
    "select": [],
    "find": {
      "supAdmin": this.useridd,
      "DeletedUser": {
        "$exists": false
      }
    }
  }

  if(this.deleteduser === true){
        userObj.find.DeletedUser.$exists = true;
  }
  
  var suburl = "/users/datatable";
   that.contactService.post(suburl, userObj).subscribe(resp => {
     this.userArrFunc(resp);
   },err=>{
     console.log(err);

   })
 }

 userArrFunc(uOb){
  this.userArr=[];
  this.userArr = uOb.data;
  console.log('userArr',this.userArr);
  setTimeout(()=>{
    this.loadropdown();
    // $("#dbselectPhone").multipleSelect("disable");
  },100)  

 }


 getAllDevice(){
  
  var findObj={};
   if(this.custtype === true){
    findObj = {
      "$and" : [{"Dealer":this.useridd},{ "deletedDevice": {"$exists": this.deleteddevice}}]
    };
   }else{
    findObj = {
      "$and" : [{"supAdmin":this.useridd},{ "deletedDevice": {"$exists":  this.deleteddevice}}]
    };
   }



  var devObj = {
    "draw": 1,
    "columns": [
      {
        "data": "_id"
      },
      {
        "data": "Device_Name"
      },
     
    
      {
        "data": "Device_ID"
      },
  
      {
        "data": "sim_number"
      },
   
 
    ],
    "order": [
      {
        "column": 0,
        "dir": "asc"
      }
    ],
    "start": 0,
    "length": -1,
    "search": {
      "value": "",
      "regex": false
    },
    "op": {},
    "select": [],
    "find": findObj
  }

  // if(this.deleteddevice === true){
  //   console.log("devObj.find['findObj']",devObj.find['findObj']);
    
  //   devObj.find['$and'][1]['deletedDevice']['$exists'] = true;
  // }
  console.log('devObj.find',devObj.find);

  var suburl = "/devices/datatable";
 
  this.deviceArrFunc(this.devicesss);
  // this.contactService.post(suburl, devObj).subscribe(resp => {
  //   console.log('device api respoonse=>',resp);
  // })

 }
 getDeviceForNotif(){
  
  var findObj={};
   if(this.custtype === true){
    findObj = {
      "$and" : [{"Dealer":this.useridd},{ "deletedDevice": {"$exists": this.deleteddevice}}]
    };
   } else if(this.superAdmin === true){
    findObj = {
      "$and" : [{"supAdmin":this.useridd},{ "deletedDevice": {"$exists":  this.deleteddevice}}]
    }
   }else{
    findObj = {
      "$and" : [{"user":this.useridd},{ "deletedDevice": {"$exists":  this.deleteddevice}}]
    }
   }


  var devObj = {
    "draw": 1,
    "columns": [
      {
        "data": "_id"
      },
      {
        "data": "Device_Name"
      },
     
    
      {
        "data": "Device_ID"
      },
  
      {
        "data": "sim_number"
      },
      {
        "data": "user"
      },
   
 
    ],
    "order": [
      {
        "column": 0,
        "dir": "asc"
      }
    ],
    "start": 0,
    "length": -1,
    "search": {
      "value": "",
      "regex": false
    },
    "op": {},
    "select": [],
    "find": findObj
  }

  // if(this.deleteddevice === true){
  //   console.log("devObj.find['findObj']",devObj.find['findObj']);
    
  //   devObj.find['$and'][1]['deletedDevice']['$exists'] = true;
  // }
  console.log('devObj.find',devObj.find);

  var suburl = "/devices/datatable";
 
  this.deviceArrFunc1(this.devicesss);
  // this.contactService.post(suburl, devObj).subscribe(resp => {
  //   console.log('device api respoonse=>',resp);
  //   // notifDevArr
  // })

 }



 deviceArr_1:any=[]
 deviceArrFunc(dOb){
  this.deviceArr_1=[];
  this.deviceArr_1 = dOb.data;
  console.log('deviceArr_1',this.deviceArr_1);
  var that= this;
  setTimeout(()=>{
    that.loadropdown();
   
  },100)  

 }

 deviceArrFunc1(dOb){
  this.notifDevArr=[];
  this.notifDevArr = dOb;
  console.log('deviceArr_1',this.deviceArr_1);
  var that= this;
  setTimeout(()=>{
    that.loadropdown();
   
  },100)  

 }
 userRadioButton(){
  console.log('userFilterType',this.userFilterType);
  // userRadio= ['Phone', 'Name'];
  // deviceRadio= ['IMEI','SIM'];
  if(this.userFilterType === 'Phone'){
    $("#dbselectPhone").multipleSelect("disable");
    $("#dbselectName").multipleSelect("enable");
  }
  if(this.userFilterType === 'Name'){
   
    $("#dbselectName").multipleSelect("disable");
    $("#dbselectPhone").multipleSelect("enable");
  }

 }


 deviceRadioButton(){
  console.log('userFilterType',this.deviceFilterType);
  if(this.deviceFilterType === 'IMEI'){
    $("#dbselectIMEI").multipleSelect("disable");
    $("#dbselectSIM").multipleSelect("enable");
  }
  if(this.deviceFilterType === 'SIM'){
    $("#dbselectSIM").multipleSelect("disable");
    $("#dbselectIMEI").multipleSelect("enable");
  
  }
 }
 userDeleted(ev){
   console.log('event=>',ev);
   this.deleteduser = ev.checked ;
      this.getAllUser();
 }

 deletedDevices(ev1){
   this.deleteddevice = ev1.checked ;
   this.getAllDevice();
 }

//  callMethod(id) {
  
//   if(id == 'grouped'){
//     $("#dbselect").multipleSelect("disable");
   
//   }else{
//     $("#dbselect").multipleSelect("enable");
//   }

// }


notificationArr= [
  {view:'Overspeed',value:'overspeed'}, {view:'Ignition',value:'IGN'}, {view:'Point of intrest',value:'Route'}, {view:'Geofence',value:'Geo-Fence'}, {view:'Maxstoppage',value:'MAXSTOPPAGE'}, {view:'Fuel',value:'Fuel'}, {view:'AC',value:'AC'}, {view:'Route POI',value:'route-poi'}, {view:'Power',value:'power'}, {view:'Panic button',value:'SOS'}, {view:'Relay',value:'immo'},{view:'Parking',value:'theft'}
]

changeComponent(component){
  this.clicked=false
  this.componentIdentifier=component
  this.selectGroup="all"
  console.log(this.componentIdentifier);
  // if(component=='distance_report')
  // {

  // }
   
  this.router.navigate(['/reports/'+component])
  if(this.componentIdentifier === 'daily_report' || this.componentIdentifier === 'daily_logs' || this.componentIdentifier=="speed_variation"){
      this.showFromDate = false;
      this.lableVariable = 'Select Date';
      
    }else{
      this.showFromDate = true;
      this.lableVariable = 'To Date';
    }
    // this.loadropdown()
  this.ngOnInit()
  
}
onChangeGroup(event){
  console.log(event);
  this.clicked=false
  if(event=="all"){
    // this.devicesss=localStorage.getItem('vehicaleData');
    for(let i=0;i<this.devicesss.length;i++){
              let a ={
                value : this.devicesss[i].Device_Name,
                viewValue:this.devicesss[i].Device_Name,
                did:this.devicesss[i].Device_ID,
                id:this.devicesss[i]._id,
                user:this.devicesss[i].user,
                groupName:this.devicesss[i].groupName?this.devicesss[i].groupName:'',    
              }
             
             if ((this.componentIdentifier === 'trip_report')||(this.componentIdentifier === 'idle_report')||(this.componentIdentifier == 'fuel_consumption_report')||(this.componentIdentifier === 'poi_report')||(this.componentIdentifier === 'stoppage_report')||(this.componentIdentifier === 'vehicle_expenses')||(this.componentIdentifier === 'loadunloadTrip')||(this.componentIdentifier === 'maintanance_report') || (this.componentIdentifier==="loading_unloading_trip")){
                a['selectedValue'] = this.devicesss[i]._id ; 
             } else if ((this.componentIdentifier === 'fuel_report_graph') || (this.componentIdentifier === 'distance_report') || (this.componentIdentifier === 'ac_report')|| (this.componentIdentifier === 'travel_path_report') ||(this.componentIdentifier === 'temp_report_graph')||(this.componentIdentifier === 'summary_report')||(this.componentIdentifier === 'overspeed_report')||(this.componentIdentifier === 'daily_report')||(this.componentIdentifier === 'sos_report')||(this.componentIdentifier === 'ignition_report') ||(this.componentIdentifier === 'working_hours_report')|| (this.componentIdentifier === 'daywise_report')||(this.componentIdentifier === 'censor_detail')||(this.componentIdentifier === 'notification_master')||!this.isCC ||(this.componentIdentifier === 'daily_logs') || ( this.componentIdentifier==="dataPushReport")||(this.componentIdentifier=="speed_variation")){
                a['selectedValue'] = this.devicesss[i].Device_ID ; 

              }
              this.options.push(a);
          }
            this.loadropdown();
  }else{
    // var arr=[];
    //  for(var i=0;i<this.devicesss.length;i++){
    //    if(event==this.devicesss[i].groupName){
    //      arr.push(this.devicesss[i])
    //    }
    //  }
    //  this.devicesss=arr;
     this.options=[];
     
     for(let i=0;i<this.devicesss.length;i++){
       let a ={
         value : this.devicesss[i].Device_Name,
         viewValue:this.devicesss[i].Device_Name,
         did:this.devicesss[i].Device_ID,
         id:this.devicesss[i]._id,
         user:this.devicesss[i].user,
         groupName:this.devicesss[i].groupName?this.devicesss[i].groupName:'',    
        }
        
        if ((this.componentIdentifier === 'trip_report')||(this.componentIdentifier === 'idle_report')||(this.componentIdentifier == 'fuel_consumption_report')||(this.componentIdentifier === 'poi_report')||(this.componentIdentifier === 'stoppage_report')||(this.componentIdentifier === 'vehicle_expenses')||(this.componentIdentifier === 'loadunloadTrip')||(this.componentIdentifier === 'maintanance_report') || (this.componentIdentifier==="loading_unloading_trip")){
          a['selectedValue'] = this.devicesss[i]._id ; 
        } else if ((this.componentIdentifier === 'fuel_report_graph') || (this.componentIdentifier === 'distance_report') || (this.componentIdentifier === 'ac_report')|| (this.componentIdentifier === 'travel_path_report') ||(this.componentIdentifier === 'temp_report_graph')||(this.componentIdentifier === 'summary_report')||(this.componentIdentifier === 'overspeed_report')||(this.componentIdentifier === 'daily_report')||(this.componentIdentifier === 'sos_report')||(this.componentIdentifier === 'ignition_report') ||(this.componentIdentifier === 'working_hours_report')|| (this.componentIdentifier === 'daywise_report')||(this.componentIdentifier === 'censor_detail')||(this.componentIdentifier === 'notification_master')||!this.isCC ||(this.componentIdentifier === 'daily_logs') || ( this.componentIdentifier==="dataPushReport")||(this.componentIdentifier=="speed_variation")){
          a['selectedValue'] = this.devicesss[i].Device_ID ; 
          
        }
        if(event==this.devicesss[i].groupName){
          this.options.push(a);
        }
      }
      console.log(this.options);
      this.loadropdown();
            // this.devicesss=localStorage.getItem('vehicaleData');
  }

  // // $(document).ready(function() {
  //   // $("dbselect").multiselect({
  //   //    selectedText: "# of # selected"
  //   // });
  //   // var hidValue = event;
  //   // alert(hidValue);
  //   // var selectedOptions = hidValue.split(",");
  //   for(var i=0;i<this.options.length;i++){
  //     // console.log(this.options[i]);
      
  //     if(this.options[i].groupName==event){
  //       console.log(this.options[i]);
  //        if ((this.componentIdentifier === 'trip_report')||(this.componentIdentifier === 'distance_report')||(this.componentIdentifier === 'idle_report')||(this.componentIdentifier == 'fuel_consumption_report')||(this.componentIdentifier === 'poi_report')||(this.componentIdentifier === 'stoppage_report')||(this.componentIdentifier === 'vehicle_expenses')||(this.componentIdentifier === 'loadunloadTrip')||(this.componentIdentifier === 'maintanance_report') || (this.componentIdentifier==="loading_unloading_trip")){
  //               this.options[i]['selectedValue'] = this.options[i].id ; 
  //             }else if ((this.componentIdentifier === 'fuel_report_graph')|| (this.componentIdentifier === 'ac_report')|| (this.componentIdentifier === 'travel_path_report') ||(this.componentIdentifier === 'temp_report_graph')||(this.componentIdentifier === 'summary_report')||(this.componentIdentifier === 'overspeed_report')||(this.componentIdentifier === 'daily_report')||(this.componentIdentifier === 'sos_report')||(this.componentIdentifier === 'ignition_report') ||(this.componentIdentifier === 'working_hours_report')|| (this.componentIdentifier === 'daywise_report')||(this.componentIdentifier === 'censor_detail')||(this.componentIdentifier === 'notification_master') ||(this.componentIdentifier === 'daily_logs') || ( this.componentIdentifier==="dataPushReport")||(this.componentIdentifier=="speed_variation")){
  //               this.options[i]['selectedValue'] = this.options[i].did ; 

  //             }
  //       // console.log($("dbselect").find("option[value="+this.options[i].id+"]").prop("selected", "selected"));
        
  //       $("dbselect").find("option[value="+this.options[i].selectedValue+"]").prop("selected", "selected");
  //     }
  //   }
  //   // for(var i in selectedOptions) {
  //   //     var optionVal = selectedOptions[i];
  //   //     $("select").find("option[value="+optionVal+"]").prop("selected", "selected");
  //   // }
  //   $("dbselect").multipleSelect('refresh');
    

// });

  
}

actionMethod(i){
  console.log("CLidkkdsj",i);
  
}



}



