import { Component, Inject, OnInit } from '@angular/core';
import { MdDialogRef, MD_DIALOG_DATA } from '@angular/material';
import { ContactService } from '../../contact.service';
declare var $: any;
@Component({
  selector: 'app-e-chalan',
  templateUrl: './e-chalan.component.html',
  styleUrls: ['./e-chalan.component.scss']
})
export class EChalanComponent implements OnInit {
 tabelObj: any ;
  Load: boolean;
  main=[];
 
  constructor(public dialogRef: MdDialogRef<EChalanComponent>,
    @Inject(MD_DIALOG_DATA) public data: any,private contactService: ContactService) { 
      // this.main=this.data
      // this.testTable()

      console.log(data);
      
    }

  ngOnInit() {
    this.getechalanHistory()
  }

  getechalanHistory(){
    this.Load=true
    this.contactService.get('/eChalan/getEchalanByVehicleName?vName='+(this.data.dname).replace(/\s/g,'')).subscribe((res:any)=>{
     if(res.length>0){
        this.main=res;
        this.Load=false
      }else{
        this.data_descip = res.message;
         launch_toast();
         this.Load=false

      }
    })

    function launch_toast() {
    var x = document.getElementById("toast")
    //console.log(x);
    x.className = "show";
    setTimeout(function(){ x.className = x.className.replace("show", ""); }, 1500);
}
  }

 
data_descip
fetchNewChalan(){
   this.contactService.get('/eChalan/getEchalan?vName='+(this.data.dname).replace(/\s/g,'')).subscribe((res:any)=>{
      // console.log(res);
      if(res.length>0){
        this.main=res;
        this.Load=false
      }else{
        this.data_descip = res.message;
         launch_toast();
         this.Load=false

      }
    })

    function launch_toast() {
    var x = document.getElementById("toast")
    //console.log(x);
    x.className = "show";
    setTimeout(function(){ x.className = x.className.replace("show", ""); }, 1500);
}
}


}
