Search This Blog

Wednesday, March 30, 2022

Json Response in Static Format in Angular

 findDaysInverstoryOutstanding(event)
  {
 
    this.flipFrontShow = false;
    this.flipFrontBack = true;
    let DaysInverstoryOutstanding = this.getPayload(this.daysinventoryForm.value);
    console.log(DaysInverstoryOutstanding);
    event.srcElement.firstChild.childNodes[0].classList.add("flip-card-rotate");
    this._dashboardService.filterInventoryDaysOutstanding(DaysInverstoryOutstanding, res =>{
      //res = [{days:123.4, total_value : 140008999}];
      this.inventoryOutStandingDate = res[0];
      });
  }

Friday, March 25, 2022

Iteration only the values by using the key

 loadPrimaryTrendLine()
  {
    this._dashboardService.getPrimaryTrendLine(res =>{
      let linecharts = res[0];  
      Object.keys(linecharts).forEach(key => {
        this.PrimaryTrendLine.push(linecharts[key]);
      });
     })
  }                          

Json : Api Hit (http://127.0.0.1:8000/app_dashboard/primary_trend_line)

[
    {
        "primary_01_value"0,
        "primary_02_value"1836.0,
        "primary_03_value"133785.096
    }
]





                                                             

Friday, March 11, 2022

Angular Multiple Subject behaviour

 import { Component, OnInit, ViewEncapsulation, HostListener } from '@angular/core';

import { StorageService } from 'src/app/core/services/storage/storage.service';
import { FormValidatorService } from 'src/app/core/services/formValidator/form-validator.service';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Roles } from 'src/app/modules/auth/model/user';
import { CpbookingService } from 'src/app/modules/cpadmin/service/cpbooking.service';
import { UtilsService } from 'src/app/core/services/utils/utils.service';
import { StockReportService } from 'src/app/modules/common/service/stock-reports/stock-report.service';
import { PermissionMenuListService } from 'src/app/core/services/utils/permission-menu-list.service';
import { ActionItems } from 'src/app/core/services/constants';
import { MomentService } from 'src/app/core/services/utils/moment.service';
import { IGetRowsParams } from 'ag-grid-community';
import { OutboundService } from '../../../service/outbound/outbound.service';
import { PromptService } from 'src/app/core/modules/shared/components/prompt/prompt.service';
import { syncService } from 'src/app/core/services/utils/sync.service';

@Component({
  selector: 'app-opf-invoice-report',
  templateUrl: './opf-invoice-report.component.html',
  styleUrls: ['./opf-invoice-report.component.css'],
  encapsulation:ViewEncapsulation.None

})
export class OpfInvoiceReportComponent implements OnInit {
  public columnDefs;
  public defaultColDef;
  public gridOptions;
  public gridApi;
  public gridColumnApi;
  public gridData = [];
  public stockReportForm: FormGroup;
  public role;
  public isAdmin:boolean = false;
  public clientNames =[];
  public otlList =[];
  public opfList =[];
  public partList=[];
  public cpList=[];
  public pageSize = 10;
  public isChannelPartner;
  public stockReportPermission;
  public displayChannelPartnerKeys = ['name', 'cpnumber']
  public displayChannelPartnerKeys1 = ['name', 'custNumber']
  public isLoading:any = false;

  public isError:any = false;
  constructor(private _StorageService: StorageService,private _permissionMenuListService: PermissionMenuListService, private _bookingService :CpbookingService, private _utilsService : UtilsService,
    private _formValidator: FormValidatorService, private fb: FormBuilder,private _StockReportService:StockReportService,private _momentService: MomentService,
     private _outboundService: OutboundService, private _PromptService: PromptService, private _syncService : syncService) { }
    @HostListener('window:resize', ['$event'])onResize(event) {
      this.gridApi.sizeColumnsToFit();
    }

  ngOnInit() {
    this.loadStockReportForm();
    this.role = this._StorageService.getUserDetails().role;

    this.isAdmin =this._utilsService.isAdminRole(this.role);

    this.isChannelPartner = this._utilsService.isCpRole(this.role);
    // calling filters api
    this.setClientList();
    this.setPartsList();
    this.setOtlList();
    this.setCPList();

    this._syncService.getSync().subscribe(res =>  this.isLoading = res)
    this._syncService.getErrorSync().subscribe(res =>  this.isError = res )
    this.defaultColDef = {
      sortable: true,
      filter: true,
      resizable: true,
 
    };
    this.gridOptions = {
      rowHeight: 45,
      paginationPageSize: 10,
      cacheBlockSize : 10,
      rowModelType :'infinite',
      cacheOverflowSize:100,
      maxConcurrentDatasourceRequests: 2
    };

    this.gridOptions.onSortChanged = event => {
      this.gridApi.redrawRows();
    }
    this.columnDefs = [
      {
        field: "",
        headerName: 'S No.',
        width: 100,
        sortable: false,
        filter: false,
        valueGetter: "node.rowIndex + 1",
        suppressSizeToFit: true
      },
      {
        headerName: 'OTL No.',
        field: "OTLNumber",
        width: 150,
        comparator: (param1, param2) => {
          return this._utilsService.alphaNumbericSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
      {
        headerName: 'End Customer Number',
        field: "custNumber",
        width: 200,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
      {
        headerName: 'End Customer Name',
        field: "custName",
        width: 300,
        suppressSizeToFit: true
      },
      {
        headerName: 'End Customer Site Id',
        field: "site_id",
        width: 200,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
      {
        headerName: 'CP Number',
        field: "cpnumber",
        width: 200,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
      {
        headerName: 'CP Name',
        field: "cpName",
        width: 350,
        suppressSizeToFit: true
      },        
      {
        headerName: 'CP SITE CITY',
        field: "cp_site_city",
        width: 159,
        suppressSizeToFit: true
      },
      {
        headerName: 'CP Site ID',
        field: "siteId",
        width: 200,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
      {
        headerName: 'OPF No.',
        field: "OPFNumber",
        width: 150,
        comparator: (param1, param2) => {
          return this._utilsService.alphaNumbericSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
      {
        headerName: 'OPF Created Date',
        field: 'created_on',
        valueFormatter : this.formatDate.bind(this),

                width: 250,
        suppressSizeToFit: true,
      },
      {
        headerName: 'Part No.',
        field: "partNumber",
        width: 150,
        comparator: (param1, param2) => {
          return this._utilsService.alphaNumbericSorting(param1,param2);
        },
        suppressSizeToFit: true,
      },
      {
        headerName: 'Description',
        field: "description",
        width: 250,
        suppressSizeToFit: true
      },

 
      {
        headerName: 'Unit Price ',
        field: "price",
        width: 140,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        cellRenderer :(params) =>{
          return params.value || params.value == 0?  "<div class = 'text-right'>" + this._utilsService.rupeeFormat(this.RoundOFTwoDigit(params.value)) + "</div>"  : ''
        },
        suppressSizeToFit: true,
      },
     
   
      {
        headerName: 'OPF Quantity',
        field: "quantity",
        width: 150,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },

     
      {
        headerName: 'OPF Line Value',
        field: "parts_total_amount_with_out_tax",
        width: 150,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        cellRenderer :(params) =>{
          return params.value || params.value == 0?  "<div class = 'text-right'>" + this._utilsService.rupeeFormat(this.RoundOFTwoDigit(params.value)) + "</div>"  : ''
        },
        suppressSizeToFit: true,
      },

      {
        headerName: 'Beckman Invoiced Qty',
        field: "quantityInvoiced",
        width: 150,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },

      {
        headerName: 'Beckman Invoice Number',
        field: "invoiceNumber",
        width: 200,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
      {
        headerName: 'Total Beckman Invoiced Qty',
        field: "total_invoice_quantity",
        width: 150,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
      {
        headerName: 'OPF Invoice Status',
        field: "invoice_status",
        width: 200,
        suppressSizeToFit: true
      },
      {
        headerName: 'OPF Order Status',
        field: "status",
        width: 200,
        suppressSizeToFit: true
      },
      {
        headerName: 'ORACLE Order Number',
        field: "oracleOrderNumber",
        width: 200,
        comparator: (param1, param2) => {
          return this._utilsService.numberSorting(param1,param2);
        },
        suppressSizeToFit: true
      },
     
    ];
    this.loadReportsPermission()
  }
  setActionsPermission(name){
        return this.stockReportPermission && typeof this.stockReportPermission[ActionItems[name]] != 'undefined'  ?  true : false;

 }

 loadReportsPermission(){
  this._permissionMenuListService.getActionPermission({model : 'appreport'}, response =>{
    this.stockReportPermission= response['appreport'];    
  });
}
generateListNow() {

 this._syncService.setSync(true);

 this._outboundService.generateNow(res => {  

      if(res.success === true)
      {
        this._syncService.setSync(false);  
      }
     else
     {    
      this._syncService.setSync(false);
      this._syncService.setErrorSync(true);    
     }
 
  });    
   
}



formatDate(params){
  return params.data ? this._momentService.getDate(params.data.created_on) : ''
}
  // start - set values for  filter fields
  setPartsList(){
    this._StockReportService.getListParts(this.role,(res) => {
      this.partList =res;
    });
  }

  setClientList(){
    this._bookingService.listHospital( res =>{
      this.clientNames =  this._utilsService.groupByMultipleKeys(res,['name','custNumber'])
    })
  }
  setOtlList(){
    this._bookingService.getListofOTLParts(res =>{
      this.otlList =  this._utilsService.groupByMultipleKeys(res,['name','OTLnumber'])
    })
  }

  setCPList(){
    this._bookingService.listChannelPartner(res=>{
      this.cpList = this._utilsService.groupByMultipleKeys(res,['name','cpnumber'])  
    })
  }
// end - set values for  filter fields


onGridReady(params) {
  this.gridApi = params.api;
  this.gridColumnApi = params.columnApi;
  this.gridApi.sizeColumnsToFit();
  this.getStockOverviewReportList()
}

getStockOverviewReportList(){

  let data = {
    created_on_start_date : this._momentService.getFilterFormat(this.stockReportForm.get('from_date').value),
    created_on_end_date : this._momentService.getFilterFormat(this.stockReportForm.get('to_date').value, "toDate"),
  }
return this.getCPList(data);
}
getCPList(data?: any){
 
  let payload = {};
  var datasource = {
    getRows: (params: IGetRowsParams) =>{
      if (data) {
        payload = data;
      }
      payload['page_size'] =this.pageSize
      payload['page'] = ((params.endRow % this.pageSize) == 0) ? (params.endRow / this.pageSize) : (params.endRow / this.pageSize)+1
      payload['sort_key'] =params.sortModel.length ? params.sortModel[0]['colId'] : ''
      payload['sort_type'] = params.sortModel.length ? params.sortModel[0]['sort'] : ''
     
      this._StockReportService.searchGetOpfInvoiceReport(data,(res)=>{
          let length = res['total'];
          this.gridData = res['results'];
          console.log(this.gridData,'-203-');
         
          console.log(res['results']);
          params.successCallback(res['results'], length)
        })
    }
  }
    this.gridApi.setDatasource(datasource);
}

  loadStockReportForm(){
    this.stockReportForm = this.fb.group({
      from_date:[this._momentService.deceedDate(new Date(),31)],
      to_date:[new Date()],
      status:[null],
      custNumber: ['', this._formValidator.requireMatch],
      cpNumber: ['', this._formValidator.requireMatch],
      OPFNumber: [''],
      OTLNumber: ['', this._formValidator.requireMatch],
      partNumber: ['', this._formValidator.requireMatch],
      invoiceNumber : ['']
    });
  }


  exportStockReport(){
    let paylaod =  this.getPayload(this.stockReportForm.value);
    paylaod['is_export'] = true;
    this._StockReportService.exportOpfReportFilter(paylaod);
  }
  getPayload(formValue){
    let data =  {};
    //Success Scenario
     data['created_on_start_date'] = formValue.from_date ? this._momentService.getFilterFormat(formValue.from_date, "toDate") : '';
     data['created_on_end_date'] = formValue.to_date ? this._momentService.getFilterFormat(formValue.to_date, "toDate") : '';
     data['OPFNumber'] =  formValue.OPFNumber ? formValue.OPFNumber : '';
     data['custNumber'] =  formValue.custNumber ? formValue.custNumber.custNumber : '';
     data['invoiceNumber']  =  formValue.invoiceNumber ? formValue.invoiceNumber : '';
     data['OTLNumber'] = formValue.OTLNumber ? formValue.OTLNumber.OTLnumber : '';
     data['partNumber'] =formValue.partNumber ? formValue.partNumber.partNumber : '';
     data['cpnumber'] = formValue.cpNumber ? formValue.cpNumber.cpnumber : '';
     data['invoice_status_value'] = formValue.status ? formValue.status : '';
    return data;
    }
 

  searchStockReport(){

    if (this.stockReportForm.valid){
      let invoiceFilterValues = this.getPayload(this.stockReportForm.value);
      return this.getCPList(invoiceFilterValues);
      }
    }
  cancelStockReport(){
    this.stockReportForm.reset();
    this.stockReportForm.get('from_date').setValue(this._momentService.deceedDate(new Date(),31));
    this.stockReportForm.get('to_date').setValue(new Date())
    this.getStockOverviewReportList();
  }
  RoundOFTwoDigit(num: any){
    var number = Math.round(num * Math.pow(10, 2)) / Math.pow(10, 2);
    return number;
  }

}








import { Injectable } from '@angular/core';

import { BehaviorSubject, Observable, Subject } from 'rxjs';

@Injectable({providedIn: 'root'})
export class syncService {

    private isSync = new BehaviorSubject<any>(false);

    private isSyncError = new BehaviorSubject<any>(false);

    setSync(message) {
       this.isSync.next(message);
    }

    getSync(): Observable<any>  {
        return this.isSync.asObservable();
    }

    setErrorSync(message) {
        this.isSyncError.next(message);
     }
 
     getErrorSync(): Observable<any>  {
         return this.isSyncError.asObservable();
     }


}

Behaviour Resuable code in angular

 import { Injectable } from '@angular/core';

import { BehaviorSubject, Observable, Subject } from 'rxjs';


@Injectable({ providedIn: 'root' })

export class FilterService {

        public openfilters = new BehaviorSubject<any>(null);

        public bookedfilter = new BehaviorSubject<any>(null);

        public rejectedfilter = new BehaviorSubject<any>(null);

    setFilterData(message, screen) {


        if(screen === 'open')

        {

            this.openfilters.next(message);

        }

        else if(screen === 'booked')

        {

            this.bookedfilter.next(message);

        }

        else if (screen === 'rejected')

        {

            this.rejectedfilter.next(message);

        }

   

     }


     getFilterData(screen): Observable<any> {


         let Observable = null;


        if(screen === 'open')

        {

            Observable = this.openfilters.asObservable();

        }

        else if(screen === 'booked')

        {

            Observable = this.bookedfilter.asObservable();

        }

        else if (screen === 'rejected')

        {

            Observable = this.rejectedfilter.asObservable();

        }

   


        return Observable;

    }

}




import { Component, OnInit, HostListener } from '@angular/core';

import { FormGroup, FormBuilder } from '@angular/forms';

import { CpbookingService } from 'src/app/modules/cpadmin/service/cpbooking.service';

import { UtilsService } from 'src/app/core/services/utils/utils.service';

import { MomentService } from 'src/app/core/services/utils/moment.service';

import { FormValidatorService } from 'src/app/core/services/formValidator/form-validator.service';

import { AgGridRouterComponent } from 'src/app/core/modules/shared/components/ag-grid-router/ag-grid-router.component';

import { AgGridMenuComponent } from 'src/app/core/modules/shared/components/ag-grid-router/ag-grid-menu.component';

import { Roles } from 'src/app/modules/auth/model/user';

import { IGetRowsParams } from 'ag-grid-community';

import { ActionItems } from 'src/app/core/services/constants';

import { StockReportService } from 'src/app/modules/common/service/stock-reports/stock-report.service';

import { StorageService } from 'src/app/core/services/storage/storage.service';

import { FilterService } from '../../../filterService';


@Component({

  selector: 'app-agent-my-booking',

  templateUrl: './agent-my-booking.component.html',

  styleUrls: ['./agent-my-booking.component.css']

})

export class AgentMyBookingComponent implements OnInit {


  

  public columnDefs;

  public defaultColDef

  public gridOptions;

  public gridApi;

  public gridColumnApi;

  public searchValue;

  public gridData =[];

  public cpName =[] ;

  otlList =[];


  public bookingSearchForm: FormGroup;

  clientNames=[]; 

  public parent_permission =[];

  public pageSize = 10;

  public editOpf = false;

  public editOpfActionMenu = false;

  public opfPermission;

  public partList=[];

  public role;

  public displayChannelPartnerKeys = ['name', 'cpnumber']

  public displayHospitalKeys = ['name', 'custNumber']

  public userEmail;

  public subscription;

  public cpnum:any;

  public custNumber :any;


  constructor(private _bookingService: CpbookingService,private _StockReportService:StockReportService,private _StorageService : StorageService,

    private _utilsService : UtilsService , private _momentService: MomentService, private fb: FormBuilder,private _formValidator: FormValidatorService,public _FilterService : FilterService ) { }

  @HostListener('window:resize', ['$event'])onResize(event) {

      this.gridApi.sizeColumnsToFit();

  }

  ngOnInit() {



   this.userEmail = this._StorageService.getUserDetails().email;

    this.loadopfPermission();

    this.role = this._StorageService.getUserDetails().role

    this.loadBookingSearchForm();

    this.setOtlList()

    this.setClientList();

    this.setCpList();

    this.setPartsList()

    this.checkEditAccessControl();

    this.defaultColDef = {

      sortable: true,

      filter: false,

      resizable: true

    };


    this.gridOptions = {

      rowHeight: 45,

      paginationPageSize: 10,

      cacheBlockSize : 10,

      rowModelType :'infinite',

      cacheOverflowSize:100,

      maxConcurrentDatasourceRequests: 2,

      onPaginationChanged: (params) => {

        if (params.newPage) {

            let currentPageBooked= params.api.paginationGetCurrentPage();    

           localStorage.setItem('currentPageBooked', JSON.stringify(currentPageBooked));

          }

        }

    };


    this.gridOptions.onSortChanged = event => {

      this.gridApi.redrawRows(); 

    }

    this.gridOptions.onFilterChanged = event => {

      this.gridApi.redrawRows(); 

    }

    this.columnDefs = [

      {

        field: 'id',

        headerName: 'S No.',

        width: 100,

        sortable: false,

        filter: false,

        valueGetter: "node.rowIndex + 1",

      },

      {

        headerName: 'OPF Number',

        field: 'OPFNumber',

        width: 190,

        cellRendererFramework: AgGridRouterComponent,

        cellRendererParams: {

          inRouterLink: '/agent/bookings/ba/view/',

        },

      },

      {

        headerName: 'Ordered Date and Time',

        field: 'created_on',

        valueFormatter : this.formatDate.bind(this),

        width: 250,

      },

      {

        headerName: 'Client Name',

        field: 'custName',

        width: 420,

      },

      {

        headerName: 'Channel Partner',

        field: 'cpName',

        width: 250,

      },

      {

        headerName: 'OTL No.',

        field: 'OTLNumber',

        width: 200,

      },

      {

        headerName: 'Net Amount (Rs.)',

        field: 'net_amount',

        width: 200,

        comparator: (param1, param2) => {

          return this._utilsService.numberSorting(param1,param2);

        },

        cellRenderer :(params) =>{

          return typeof params.value !== 'undefined' ? "<div class = 'text-right'>" + this._utilsService.rupeeFormat(this.RoundOFTwoDigit(params.value)) + "</div>"  : ''

        }


      },

      {

        headerName: 'Total Amount (Rs.)',

        field: 'total_amount',

        width: 200,

        comparator: (param1, param2) => {

          return this._utilsService.numberSorting(param1,param2);

        },

        cellRenderer :(params) =>{

          return typeof params.value !== 'undefined' ? "<div class = 'text-right'>" + this._utilsService.rupeeFormat(this.RoundOFTwoDigit(params.value))  + "</div>"   : ''

        }

      },

      {

        headerName: 'Order Status',

        field: 'status',

        width: 190,

      },

      {

        field: 'status',

        headerName: 'Action',

        sortable: false, 

        filter: false,

        width: 100,

        cellRendererFramework: AgGridMenuComponent,

        cellRendererParams:  (params) => {

          let menu = [];

          menu.push({

            name: 'View',

            link: '/agent/bookings/ba/view/',

          });

          if (this.editOpfActionMenu && params.data && !params.data['isInvoiced'] && this.editOpf) {

            menu.push({

                name: 'Edit',

                link: '/agent/bookings/ba/edit/',

              })

          }

          return { 

            menu

          }

        },

      }

    ];


  }

  setActionsPermission(name){

    return this.opfPermission && typeof this.opfPermission[ActionItems[name]] != 'undefined'  ?  true : false;

  }


  loadopfPermission(){

      this._bookingService.getActionPermission({model : 'opf'}, response =>{

        this.opfPermission= response['opf'];

        this.editOpfActionMenu = this.setActionsPermission('EDIT')

      });

  }


  checkEditAccessControl(){

    this._bookingService.getOPFAccessControls({module:'OPF_Edit', email: this.userEmail},response =>{

     //this.editOpf = response[0]['isBAAllowed'];

      //this.editOpf  = response.field_permission;


      this.editOpf  =  response.parent_permission[0]['is_allowed'];

      //this.parent_permission =  response.parent_permission[0]['is_allowed'];

  

    })

  }


  setOtlList(){

    this._bookingService.getListofOTLParts(res =>{

      this.otlList =  this._utilsService.groupByMultipleKeys(res,['name','OTLnumber'])

    })

  }


  setClientList(){

    this._bookingService.listHospital( res =>{

      this.clientNames = this._utilsService.groupByMultipleKeys(res,['name','custNumber'])

    })

  }


  setCpList(){

    this._bookingService.listChannelPartner(res=>{

      this.cpName = this._utilsService.groupByMultipleKeys(res,['name','cpnumber']) 

    })

  }

  formatDate(params){

    return params.data ? this._momentService.getDateTimeFormat(params.data.created_on) : ''

  }

  onGridReady(params) {

    this.gridApi = params.api;

    this.gridColumnApi = params.columnApi;

    this.gridApi.sizeColumnsToFit();

    this.setOpfParams();

  }


  setOpfParams(){

  //   let data = {

  //     from_date : this._momentService.getFilterFormat(this.bookingSearchForm.get('from_date').value),

  //     to_date : this._momentService.getFilterFormat(this.bookingSearchForm.get('to_date').value, "toDate"),

  //     status: 'Booked'

  //   }

  //  return  this.getOPFList(data);



   this.subscription = this._FilterService.getFilterData('booked').subscribe(res => {

    let data = {};


    if(res)

    {

    this._bookingService.listChannelPartner(res1=>{

   this.cpName =  this._utilsService.groupByMultipleKeys(res1,['name','cpnumber'])

  this.cpnum = this.cpName.filter(marker => {

    return marker.cpnumber === res.cpnumber;


 })


 this.bookingSearchForm.get('cpnumber').setValue({ name: this.cpnum[0].name, cpnumber: this.cpnum[0].cpnumber });


})


this._bookingService.listHospital( res2 =>{

  this.clientNames =  this._utilsService.groupByMultipleKeys(res2,['name','custNumber'])


     this.custNumber = this.clientNames.filter(clientnames => {

       return clientnames.custNumber  === res.custNumber

     })


     this.bookingSearchForm.get('custNumber').setValue({ name: this.custNumber[0].name, cpnumber: this.custNumber[0].custNumber });

})





       console.log(this.cpnum, this.bookingSearchForm);


      this.bookingSearchForm.get('OTLNumber').setValue({OTLnumber : res.OTLNumber});

      this.bookingSearchForm.get('partNumber').setValue({partNumber: res.partNumber});


      this.bookingSearchForm.get('OPFNumber').setValue(res.OPFNumber);


      //this.bookingSearchForm.get('status').setValue(res.status);

      this.bookingSearchForm.get('from_date').setValue(res.from_date);

      this.bookingSearchForm.get('to_date').setValue(res.to_date);

      this.getOPFList(res);


    }

    else

    {

       data = {

        from_date : this._momentService.getFilterFormat(this.bookingSearchForm.get('from_date').value),

        to_date : this._momentService.getFilterFormat(this.bookingSearchForm.get('to_date').value, "toDate"),

        status: 'Booked'

       }


      this.getOPFList(data);

    }


  });












  


  }



  getOPFList(data ?:any) {

    let payload = {};

    var datasource = {

      getRows: (params: IGetRowsParams) =>{

        if (data) {

          payload = data;

        }

        payload['page_size'] =this.pageSize

        payload['page'] = ((params.endRow % this.pageSize) == 0) ? (params.endRow / this.pageSize) : (params.endRow / this.pageSize)+1

        payload['sort_key'] =params.sortModel.length ? params.sortModel[0]['colId'] : ''

        payload['sort_type'] = params.sortModel.length ? params.sortModel[0]['sort'] : ''

          this._bookingService.searchBooking(payload,(res)=>{

            let length = res['total'];

            this.gridData = res['results'];

            params.successCallback(res['results'], length)

            const pageToNavigate = JSON.parse(localStorage.getItem('currentPageBooked'));

            this.gridApi.paginationGoToPage(pageToNavigate);

          })

      }

    }

    this.gridApi.setDatasource(datasource);

  }



 //  search filter 

 loadBookingSearchForm(){

  this.bookingSearchForm = this.fb.group({

    custNumber: ['',this._formValidator.requireMatch],

    OPFNumber: [''],

    cpnumber: [''],

    OTLNumber: [''],

    from_date:[this._momentService.deceedDate(new Date(),31)],

    to_date:[new Date()],

    partNumber :  ['',this._formValidator.requireMatch],

  },{ validator: this._formValidator.dateValidation('from_date', 'to_date') });

}


searchBookingFilter(){

if (this.bookingSearchForm.valid){

  let data = this.getBookingPayload(this.bookingSearchForm.value);

  this._FilterService.setFilterData(data, 'booked');

  this._FilterService.getFilterData('booked').subscribe(res => {

  this.getOPFList(res);

 })

}

}


ngOnDestroy() {

  this.subscription.unsubscribe();

}


setPartsList(){

  // need to change api  

  this._StockReportService.getListParts(this.role,(res) => {

    this.partList = res  

  });

}

getBookingPayload(bookingValue){

   let data =  {};

  data['custNumber'] =  bookingValue.custNumber ? bookingValue.custNumber.custNumber : '';

  if(data['custNumber'] == undefined)

  {

    data['custNumber'] = bookingValue.custNumber.cpnumber;

  }

  data['cpnumber'] =  bookingValue.cpnumber ? bookingValue.cpnumber.cpnumber : '';

  if(data['cpnumber'] == undefined)

  {

    data['cpnumber'] = bookingValue.cpnumber.cpnumber;

  }

  data['OTLNumber'] = bookingValue.OTLNumber ? bookingValue.OTLNumber.OTLnumber : '';

  if(data['OTLNumber'] == undefined)

  {

    data['OTLNumber'] = "";

  }

  data['from_date'] = bookingValue.from_date ?  this._momentService.getFilterFormat(bookingValue.from_date,"toDate") : '';

  data['to_date'] = bookingValue.to_date ? this._momentService.getFilterFormat(bookingValue.to_date, "toDate") : '';

  data['OPFNumber'] =bookingValue.OPFNumber ? bookingValue.OPFNumber : '';

  data['partNumber'] =bookingValue.partNumber ? bookingValue.partNumber.partNumber : '';

  if(data['partNumber'] == undefined)

  {

    data['partNumber'] = "";

  }

   data['status'] =  'Booked'

 // data['status'] =  bookingValue.status ? bookingValue.status : 'Booked'

  return data;

}

cancelFilter(){

  this.bookingSearchForm.reset();

  this.bookingSearchForm.get('from_date').setValue(this._momentService.deceedDate(new Date(),31));

  this.bookingSearchForm.get('to_date').setValue(new Date())

  let data = {

    from_date : this._momentService.getFilterFormat(this.bookingSearchForm.get('from_date').value, "toDate"),

    to_date : this._momentService.getFilterFormat(this.bookingSearchForm.get('to_date').value, "toDate"),

    status: 'Booked' 

   }

   this.getOPFList(data);

   this._FilterService.setFilterData(data, 'booked');



  //this.setOpfParams();

}


exportBookingFilter(){

  let bookingPayload =  this.getBookingPayload(this.bookingSearchForm.value);

  // bookingPayload['from_date'] = bookingPayload['from_date'] ?  bookingPayload['from_date'] : this._momentService.getFilterFormat(this._momentService.deceedDate(new Date(),90))

  // bookingPayload['to_date'] =  bookingPayload['to_date'] ?  bookingPayload['to_date'] : this._momentService.getFilterFormat(new Date(), "toDate")

  bookingPayload['status'] = 'Booked'

 this._bookingService.exportBookingFilter(bookingPayload);

}

RoundOFTwoDigit(num: any){

  var number = Math.round(num * Math.pow(10, 2)) / Math.pow(10, 2);

  return number;

}


}
















Validating to select in sequencial order using angular

    < input type = "checkbox" (change) = "handleSelectTaskItem($event, taskItem)" [checked] = " taskItem . i...