import { Component, OnInit, ViewChild } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import * as moment from 'moment';
import { LocalDataSource } from 'ng2-smart-table';
import { SmartTableData } from '../../@core/data/smart-table';
import { PageapiService } from '../pageapi.service';
import { NbDialogService, NbRangepickerComponent, NbToastrService, NbWindowControlButtonsConfig, NbWindowRef, NbWindowService } from '@nebular/theme';
 


import {
  NbComponentStatus,
  NbGlobalLogicalPosition,
  NbGlobalPhysicalPosition,
  NbGlobalPosition,
 
  NbToastrConfig,
} from '@nebular/theme';
import { Router } from '@angular/router';
import { CancelFormComponent } from './cancel-form/cancel-form.component';
import { AssignFormComponent } from './assign-form/assign-form.component';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { ViewDetailsComponent } from './view-details/view-details.component';
interface Item {
  index: number;
 
}
import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
import { log } from 'console';
import { ExcelExportService } from '../excel-export/excel-export.service';
pdfMake.vfs = pdfFonts.pdfMake.vfs;
class Product{
  name: string;
  price: string;
  qty: number;
}
class Invoice{
  customerName: string;
  address: string;
  contactNo: number;
  email: string;
  
  products: Product[] = [];
  additionalDetails: string;
}
@Component({
  selector: 'ngx-order',
  templateUrl: './order.component.html',
  styleUrls: ['./order.component.scss']
})

export class OrderComponent  {
  orders:Item[] =[];
 isChecked: boolean = false;
  settings:any =[];
  source: LocalDataSource = new LocalDataSource();
  minimize = false;
  maximize = false;
  fullScreen = true;
  close = true;
  formData:any=[]
  index = 1;
  destroyByClick = true;
  duration = 2000;
  selectedRows:any=[];
  hasIcon = true;
  position: NbGlobalPosition = NbGlobalPhysicalPosition.TOP_RIGHT;
  preventDuplicates = false;
  drivers:any=[];
  status: NbComponentStatus = 'primary';
  driverForm:any =[];
  singleRow:any =[];
  selectStatus:any =[];
  filteredItems: any[];selectDriver:any=[];CancelReason:any =[];ordersArray:any =[];
  searchTerm: string;
  dateRange: Date[];
  @ViewChild('formpicker') formpicker: NbRangepickerComponent<Date>;
  @ViewChild('dateRangeInput') dateRangeInput;
  dateRangeValue: string; 
   defaultStartDate: Date;
  defaultEndDate: Date;
  ranges: any = {
    'Today': [moment(), moment()],
    'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
    'Last 7 Days': [moment().subtract(6, 'days'), moment()],
    'Last 30 Days': [moment().subtract(29, 'days'), moment()],
    'This Month': [moment().startOf('month'), moment().endOf('month')],
    'Last Month': [
      moment().subtract(1, 'month').startOf('month'),
      moment().subtract(1, 'month').endOf('month')
    ]
  };  invoice = new Invoice(); 
  selectedDateRange: {startDate: moment.Moment, endDate: moment.Moment};

  logo:any ='data:image/png;base64,[encoded data, 84716 characters]' // Path to your logo image
  start: Date;
  end: Date; 
  startDate: Date;
  endDate: Date;
  selectedDate: { fromDate: Date; toDate: Date; };
  constructor(private dialogService: NbDialogService,private domSanitizer: DomSanitizer, private router:Router,private toastrService: NbToastrService,private service: SmartTableData,public _api:PageapiService,public exportService:ExcelExportService,private windowService: NbWindowService) {

      this.dateRangeValue = ''; // Initialize the input field value
    localStorage.setItem('graud','0')
    const data = this.service.getData();
    this.defaultStartDate = new Date(); // Set your desired default start date
    this.defaultEndDate = new Date();
    this.settings = {
      selectMode: 'multi',
       
     actions: {
       
       position: 'right', // left|right
     },
     mode: 'external',
     userRowSelect: (selectedRows: any[]) => {
       this.handleRowSelection(selectedRows);
     },
     add: {
       addButtonContent: '<i class="nb-plus"></i>',
       createButtonContent: '<i class="nb-checkmark"></i>',
       cancelButtonContent: '<i class="nb-close"></i>',
     },
     edit: {
       editButtonContent: '<i class="nb-edit"></i>',
       saveButtonContent: '<i class="nb-checkmark"></i>',
       cancelButtonContent: '<i class="nb-close"></i>',
     },
     delete: {
       deleteButtonContent: '<i class="nb-trash"></i>',
       confirmDelete: true,
     },
     columns: {
       
       index: {
         title: 'ID',
         type: 'number',
               width:"10px"
       },
       orderId: {
         title: 'Order ID',
         type: 'string',
        
       },
       'OrderDetails.CusDetails.cusName': {
         title: 'Customer Name',
         type: 'string',
         width:"40px"
       },
       'ProductDetails.productName': {
         title: 'Product',
         type: 'string',
       
       },
       qty: {
         title: 'Qty',
         type: 'string',
         width:"10px",
         rowClass: (row) => {
          // Function to determine the row class based on the value of a specific column
          const columnName = 'qty'; // Specify the name of the desired column
          const desiredValue = 'qty'; // Specify the desired value for the row color

          if (row[columnName] === desiredValue) {
            return 'desired-value-row'; // CSS class for rows with the desired value
          } else {
            return ''; // CSS class for other rows
          }
        }
       },
       status: {
         title: 'Status',
         type: 'string',
         valuePrepareFunction: (cell, row) => {
          // Add a string value to the column

          if(cell == "Out For Delivery"){
            return  cell + " ("+ row["UserDetails.userName"]+")"; 
           
          }else{

          }
          return cell  ; // Modify this as per your requirement
        }
 
       },  
       reason: {
         title: 'Cancel Reason',
         type: 'string',
         width:"25px"
       },
      
     },
   };
 
  
    this.getorderlistApi()

    this. getDriverlistApi()

    this.driverForm = new FormGroup({
      
 
      driver: new FormControl('', [ Validators.required])
    
    });

    
  }
  notify(id,ordId,cusName){
    let obj = { "id" : id , "ordId" : ordId , 'cusName' : cusName }
    this._api.Notification(obj).subscribe(res => { console.log( "success");
    })
    }


  onDeleteConfirm(event): void {
    console.log(event)
    let passData = event

    const buttonsConfig: NbWindowControlButtonsConfig = {
      minimize: this.minimize,
      maximize: this.maximize,
      fullScreen: this.fullScreen,
      close: this.close,
    };
    const windowRef: NbWindowRef =  this.windowService.open(CancelFormComponent, { title: `Cancel Product`, context: event
    , buttons: buttonsConfig  });
   


      // Subscribe to the afterClosed event
      windowRef.onClose.subscribe((data) => {
        // Handle the window closure
        console.log(data);
        if(data == 1){
          this.showToast('success', 'Data Changed Successfully', 'Order Cancel Completed..!');
         this.getorderlistApi();
           console.log('Window closed 123');
        }else if(data == 0){
          this.showToast('warning', 'Somthing is Wrong...!', 'Order Cancel Failed..!');
        }
       
      
      });
    
  }

  getFuelColor(w){
    console.log(w)
  }
  onCreateConfirm() {
    console.log("Create Event In Console")
   
    const buttonsConfig: NbWindowControlButtonsConfig = {
      minimize: this.minimize,
      maximize: this.maximize,
      fullScreen: this.fullScreen,
      close: this.close,
    };
    let config= {
      hasBackdrop: true,
      width: '500px',
      height: '300px',
    }
    this.addOrder()
  }

  onSaveConfirm(event) {
    console.log("Edit Event In Console")
    console.log(event);

    const buttonsConfig: NbWindowControlButtonsConfig = {
      minimize: this.minimize,
      maximize: this.maximize,
      fullScreen: this.fullScreen,
      close: this.close,
    };
    console.log("add")
    this._api.orderDetails.next(event)

    localStorage.setItem('viewOrder','0')
  
    this.router.navigate(['/pages/order/add']) 
  }

  onViewConfirm(event) {
    console.log("Edit Event In Console")
    console.log(event);
  
    const buttonsConfig: NbWindowControlButtonsConfig = {
      minimize: this.minimize,
      maximize: this.maximize,
      fullScreen: this.fullScreen,
      close: this.close,
    };
    console.log("add")
    this._api.orderDetails.next(event) 
    
    localStorage.setItem('viewOrder','1')
  
    this.router.navigate(['/pages/order/add']) 
  }

  getorderlistApi(){
   
    let element ={
      "startDate": (moment().subtract(6, 'days'))['_d'],
      "endDate":  moment()['_d']
  }
  this.selectedDateRange = element
  console.log(this.selectedDate)
 let from = (moment().subtract(6, 'days'))['_d']
    let param = {fromDate:from
    ,toDate: moment()['_d']}
    console.log(param)
    this._api.getOrders(param).subscribe(res => {
      console.log(res)
      if(res.status == 200){
        this.orders =[];
       let passData =  res.data
       passData.sort((a: any, b: any) => {
        return b.id - a.id;
      });
       passData.forEach((element:any, index) => {
        element.index = index       +1  
        element. selected =false
        element. selectedval =0
        element.customer = element['OrderDetails.CusDetails.cusName']

        element.address = element['OrderDetails.CusDetails.address_1']+","+element['OrderDetails.CusDetails.city']+","+element['OrderDetails.CusDetails.pincode']
        element.productName = element['ProductDetails.productName']
        
      });
      this.orders = passData
      //  console.log(data)
     this.source.load(passData);
      }
    })
   }



  dateWiseFilter() {
    console.log(this.selectedDateRange)
   let param = {fromDate :this.selectedDateRange.startDate['$d']
    ,toDate:this.selectedDateRange.endDate['$d']}

    this._api.getOrders(param).subscribe(res => {
      console.log(res)
      if(res.status == 200){

       let passData =  res.data
       passData.sort((a: any, b: any) => {
        return b.id - a.id;
      });
       passData.forEach((element:any, index) => {
        element.index = index       +1  
        element. selected =false
        element. selectedval =0
        element.customer = element['OrderDetails.CusDetails.cusName']

        element.address = element['OrderDetails.CusDetails.address_1']+","+element['OrderDetails.CusDetails.city']+","+element['OrderDetails.CusDetails.pincode']
        element.productName = element['ProductDetails.productName']
        element. orderDate = element.createdAt
      });
     // this.orders =[];
      this.orders = passData
      //  console.log(data)
     this.source.load(passData);
      }else{

      //  this.orders =[];
      }
    })

  }
  private showToast(type: NbComponentStatus, title: string, body: string) {
    const config = {
      status: type,
      destroyByClick: this.destroyByClick,
      duration: this.duration,
      hasIcon: this.hasIcon,
      position: this.position,
      preventDuplicates: this.preventDuplicates,
    };
    const titleContent = title ? ` ${title}` : '';

    this.index += 1;
    this.toastrService.show(
      body,
      `${titleContent}`,
      config);
  }

  addOrder(){
    console.log("add")
    this._api.orderDetails.next(null)
    this.router.navigate(['/pages/order/add']) 
  }

  handleRowSelection(selectedRows: any[]) {
    // Get the selected row data
    const selectedData = selectedRows.map(row => row.data);
    console.log(selectedData);
  }
  onUserRowSelect(event) {
    console.log(event)
    this.selectedRows = event.selected;
}

Assign(){
  console.log(1)
  if(this.selectedRows.length>0){

 
  const buttonsConfig: NbWindowControlButtonsConfig = {
    minimize: this.minimize,
    maximize: this.maximize,
    fullScreen: this.fullScreen,
    close: this.close,
  };
  const windowRef: NbWindowRef =  this.windowService.open(AssignFormComponent, { title: `Assign Driver`, context: this.selectedRows
 
  , buttons: buttonsConfig  });
 


    // Subscribe to the afterClosed event
    windowRef.onClose.subscribe((data) => {
      // Handle the window closure
      console.log(data);
      if(data == 1){
        this.showToast('success', 'Data Changed Successfully', 'Driver Assign Completed..!');
       this.getorderlistApi();
         console.log('Window closed 123');
      }else if(data == 0){
        this.showToast('warning', 'Somthing is Wrong...!', 'Driver Assign Failed..!');
      }
     
    
    });
  }else{
    this.showToast('warning', 'Somthing is Wrong...!', 'Please Select Orders..!');
  }

}


getDriverlistApi(){
  let param ={}
  this._api.getusers(param).subscribe(res => {
    console.log(res)
    if(res.status == 200){

     let passData =  res.data
     let driver = passData.filter(arr=>{return arr.role == 'DRIVER'}) 
     driver.sort((a: any, b: any) => {
      return b.id - a.id;
    });
     driver.forEach((element:any, index) => {
      element.index = index       +1  
      
    });



    this.drivers = driver
    //  console.log(data)
    
    }
  })
}

onSubmit(){
  if(this.selectedRows.length>0){

 
  console.log( this.selectedRows , this.driverForm.value)
  let tmp=[];
  this.selectedRows.forEach(element => {
    tmp.push({orderId:element.orderId ,driverId: this.driverForm.value.driver ,  status:'Out For Delivery' })
    
  });

 let  param ={driver:tmp}
  
   
    
   
  
 
     
     this._api.CreateOrder (param).subscribe(res => {
       if (res.status == 200) {
 console.log(res)
 this.showToast('success', 'Data Changed Successfully', 'Orders Assign Completed..!');
 this.getorderlistApi();
       }else{
        this.showToast('warning', 'Somthing is Wrong...!', 'Orders Assign Failed..!');
       }
     })
 }else{
    this.showToast('warning', 'Somthing is Wrong...!', 'Please Select Orders..!');
  }
}




onSubmit2(){
  if(this.selectedRows.length>0){

 
  console.log( this.selectedRows , this.selectDriver,this.selectStatus)
  let tmp=[];
  this.selectedRows.forEach(element => {

    
    if(this.selectStatus == "Out For Delivery"){
      tmp.push({orderId:element.orderId  , driverId:this.selectDriver, status:this.selectStatus })
    }else if(this.selectStatus == "Cancelled"){
      tmp.push({orderId:element.orderId  , reason:this.CancelReason, status:this.selectStatus })
    }else{
      tmp.push({orderId:element.orderId  ,  status:this.selectStatus })
    }
  
    
  });

 let  param ={driver:tmp}
  
   
    
   
  
 
     
     this._api.CreateOrder (param).subscribe(res => {
       if (res.status == 200) {
        if(this.selectStatus == "Out For Delivery"){
          this.selectedRows.forEach(async(element) => {
            this.notify(this.selectDriver , element.orderId , element.customer )
          });
        }
        console.log(res)
        this.showToast('success', 'Updated Successfully', '');
console.log(this.selectStatus)
        this.selectStatus = null;
        this.selectDriver = []
        this.selectedRows = []
        console.log(this.selectStatus)
        this.getorderlistApi();
       }else{
        this.showToast('warning', 'Somthing is Wrong...!', '');
       }
     })
 }else{
    this.showToast('warning', 'Somthing is Wrong...!', 'Please Select Orders..!');
    this.selectStatus = null;
    this.selectDriver = []
    this.selectedRows = []
  }
}

updateAllComplete(pa,s,d){

}

selectall(){
  console.log(this.isChecked)
  if(this.isChecked == true){
    this.isChecked = true
  }else{
    this.isChecked = false
  }
  console.log(this.isChecked)

  this.orders.forEach((element:any, index) => {
 
    element. selected = this.isChecked

  })

  if(this.isChecked == true){
    this.selectedRows = this.orders
  }

 
}

onCheckboxChange(data){
  console.log(data.target.checked)
  this.isChecked = data.target.checked
  console.log(this.isChecked)
  // if(this.isChecked == false){
  //   this.isChecked = true
  // }else{
  //   this.isChecked = false
  // }
  console.log(this.isChecked)

  this.orders.forEach((element:any, index) => {
 
    element. selected = this.isChecked

  })

  if(this.isChecked == true){
    this.selectedRows = this.orders
  }


}
selectSingleRow(data){
  console.log(data)
 // this.singleRow.push(data)

  if(data.selected == false){
    data.selectedval = true
  }else{
    data.selectedval = false
  }
  this.selectedRows = this.orders.filter((arr:any)=>{return arr.selectedval == true})  
  console.log(  this.orders, this.selectedRows)

}
handleCheckboxChange(event: boolean) {
  console.log(event);

  if(this.isChecked == false){
    this.isChecked = true
  }else{
    this.isChecked = false
  }
  
  // Output the current value of the checkbox
}


viewData(param:any){
  console.log(param)
  let data:any = {details:param,action:'Edit',title:'Edit Customer'}
  const dialogRef = this.dialogService.open(ViewDetailsComponent, {
    hasBackdrop: true,
    dialogClass: 'custom-dialog-class', // Add your custom CSS class here
    context: data
  });

  dialogRef.onClose.subscribe((result) => {
   // Execute custom logic when the dialog is closed
   console.log(result);       
   if(result == 1){
    // this.getEntityDetails()  
    //this.getuserlistApi();
   // this.showToast('success', 'Data Changed Successfully', 'Edit Customer Data Completed..!');
   //  this.toastrService.success('Entity Added Successfully','Entity');
      console.log('Window closed 123');
   }else if(result == 0){

    //this.showToast('warning', 'Somthing is Wrong...!', 'Edit Customer Data Failed..!');
    // this.toastrService.success('Somthing is Wrong...!', 'Add Entity Failed..!');
   }
  });
}

filterItems() {
 console.log(  this.searchTerm)

  if(  this.searchTerm !=''){


  this.filteredItems = this.orders.filter(item =>
    Object.values(item).some(value => {
      if (typeof value === 'string') {
        return value.toLowerCase().includes(this.searchTerm.toLowerCase());
      }
      return false;
    })
  );
  this.orders = this.filteredItems
}else{
  console.log( 'fhjsgsajdhgasksjgfcckjsdfgckjsdhfk')  

  this.getorderlistApi()
}



console.log( this.filteredItems)
}

refresh(){

  this.dateRangeValue = '';
  this.selectedDate = undefined
  this.getorderlistApi()
}

  

manipulateDate(range: { start: Date, end: Date }){ 
  this.selectedDateRange = {startDate: undefined, endDate: undefined}
  this.start = range.start
  this.end = range.end
 
    this.selectedDate = {fromDate:this.start
    ,toDate: this.end}
    console.log(this.selectedDate)
    this._api.getOrders(this.selectedDate).subscribe(res => {
      console.log(res)
      if(res.status == 200){
        this.orders =[];
       let passData =  res.data
       passData.sort((a: any, b: any) => {
        return b.id - a.id;
      });
       passData.forEach((element:any, index) => {
        element.index = index       +1  
        element. selected =false
        element. selectedval =0
        element.customer = element['OrderDetails.CusDetails.cusName']

        element.address = element['OrderDetails.CusDetails.address_1']+","+element['OrderDetails.CusDetails.city']+","+element['OrderDetails.CusDetails.pincode']
        element.productName = element['ProductDetails.productName']
        
      });
      this.orders = passData
      //  console.log(data)
     this.source.load(passData);
      }else{
        this.orders =[];
      }
    })
}

selectOnRowClick(e){
  console.log(e)
}

download(){
    console.log("download")
    console.log(this.selectedRows)
    this.selectedRows.forEach(element => {
      this.ordersArray.push(element.orderId)
    });
    this.getAnswerProduct() 
}

getAnswerProduct(){

  console.log()

  

  let param={orderId:this.ordersArray}
  this._api.getProductList(param).subscribe(res => {
    console.log(res)
 
    if(res.status == 200){

      let fullData = res.data
      console.log(fullData)
      fullData.forEach(element => {
        console.log(element.ProductDetails[0])
        if(element.ProductDetails[0] != undefined){
          element.name = element.ProductDetails[0].productName+"-("+element.ProductDetails[0].skuId+")"
          element.qty = parseInt(element.qty)
          element.price =  element.ProductDetails[0].productCategory
        }
       
        // this.invoice.additionalDetails = 'https://vnms.in/services/'
      });

      console.log(fullData)
      console.log(this.selectedRows)
      this.selectedRows.forEach(element => {

        

       let result =  fullData.filter(arr=>{return arr.orderId == element.orderId}) 

        element.fullData = result
        
      });
      console.log( this.selectedRows)

      this.generatePDF()
    }
  })
   
}


generatePDF(action = 'download') {

  let displayContent=[];

  this.selectedRows.forEach(element => {
console.log(element)
     let fullData = element.fullData
     console.log(fullData)
    displayContent.push(   {
        image: this.logo,
        width: 100,
        alignment: 'center',
        margin: [0, 10] // Adjust the margins as needed
      },
      // {
      //   text: 'VNMS',
      //   fontSize: 16,
      //   alignment: 'center',
      //   color: '#047886'
      // },
      // {
      //   text: 'INVOICE',
      //   fontSize: 20,
      //   bold: true,
      //   alignment: 'center',
      //   decoration: 'underline',
      //   color: 'skyblue'
      // },
      {
        text: 'Customer Details',
        style: 'sectionHeader'
      },
      {
        columns: [
          [
            {
              text: element['OrderDetails.CusDetails.cusName'],
              
              bold:true
            },
            { text:element['OrderDetails.CusDetails.address_1'] },
            { text:element['OrderDetails.CusDetails.email'] },
            { text:element['OrderDetails.CusDetails.phoneNo'] }
          ],
          [
            { 
              text: `SALES ORDER`,
              alignment: 'right'
            },
            {
              text: `Date: ${new Date(element.createdAt).toLocaleString()}`,
              alignment: 'right'
            },
            { 
              text: `ORDER ID :${ element.orderId }`,
              alignment: 'right'
            }
          ]
        ]
      },
      {
        text: 'Order Details',
        style: 'sectionHeader'
      },
      {
        table: {
          headerRows: 1,
          widths: ['*', 'auto',  'auto'],
          body: [
            [
              { text: 'Product', color: 'white', fillColor: 'black' },
              { text: 'Type', color: 'white', fillColor: 'black' },
              { text: 'Quantity', color: 'white', fillColor: 'black' }
            ],
            ...fullData.map((p) => [
              p.name !== undefined ? p.name : 'N/A',         // Use 'N/A' if p.name is undefined
              p.price !== undefined ? p.price : 0,            // Use 0 if p.price is undefined
              p.qty !== undefined ? p.qty : 'N/A',  // Use 'N/A' if p.qty is undefined
            ]),
            [{text: 'Total Qty', colSpan: 2}, {},    fullData .reduce((sum, p) => sum + p.qty, 0)]
           
          ]
        }
      },
      // {
      //   text: 'Additional Details',
      //   style: 'sectionHeader'
      // },
      {
          text: '',
          margin: [0, 0 ,0, 15]          
      },
      {
        columns: [
          // [{ qr: `${this.invoice.customerName}`, fit: '50' }],
          // [{ text: 'Signature', alignment: 'right', italics: true}],
        ]
      },
      {
        text: 'Terms and Conditions',
        style: 'sectionHeader'
      },
      {
          ul: [
            'Order once placed cannot be changed . Please contact VNMS for any queries.',
            'Delivery of the product will be subject to the manufacturer terms and conditions.',
            'This is a system generated sales order.',
          ],
      },
      { text: '', pageBreak: 'after' },
    )

 

 
  });
  displayContent.pop();
  console.log(displayContent)


//   this.inputFieldGroups.forEach((element:any) => {
    

//     this.productfull.forEach(e => {
      
  
// if(e.id === element.id){
//   element.name = e.productName +"-("+e.skuId+")"


// }
// });

// });
// console.log( this.inputFieldGroups )
// this.invoice.products =[];
// this.inputFieldGroups.forEach((res:any) => {
      
  
//   res.name = res.name
// res.qty = parseInt(res.qty)
// res.price = this.setData['OrderDetails.CusDetails.cusType']
// this.invoice.additionalDetails = 'https://vnms.in/services/'

//  this.invoice.products.push(res)




// })
//   this.invoice.products = this.invoice.products.filter(arr=>{return arr.qty != 0}) 
  let docDefinition = {
    content:  displayContent,
    styles: {
      sectionHeader: {
        bold: true,
        decoration: 'underline',
        fontSize: 14,
        margin: [0, 15,0, 15]          
      }
    }
  };

  if(action==='download'){
     console.log('download')
    let name= "VNMS-Report"
    pdfMake.createPdf(docDefinition).download(name);
    
  }else if(action === 'print'){
    console.log('print')
    pdfMake.createPdf(docDefinition).print();      
  }else{
    console.log('else')
    pdfMake.createPdf(docDefinition).open();      
  }
  //this.orders.filter((arr:any)=>{return arr.selectedval

    this.orders.forEach((element:any) => {
      element.selected = false
    });
}

exportExcelData() { 
  console.log('exportExcelData')
  let d = document.getElementById('orderExcel');
  console.log(d); 
  //this.exportExcelTableData =this.turnover_revenue
  this.exportService.exportExcel(d,'Order_Details');
 
}

}
