Search This Blog

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();
     }


}

No comments:

Post a Comment

Validating to select in sequencial order using angular

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