customersummaryreport.component.ts 8.3 KB
import { Component, OnInit, AfterViewChecked, ViewChild,HostListener  } from '@angular/core';
import { Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
//import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';
import { CustomerSummaryReports } from '../reports/reportdatamodel';
import { ReportService } from '../reports/report.service';
import { GlobalService } from '../../shared/global';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
import { DatePipe } from '@angular/common';
import { BsDatepickerModule } from 'ngx-bootstrap';
import { Http, Response } from '@angular/http';
import { LoadingService } from '../../shared/loading.service'; 
import { PagerComponent } from '../../shared/pager/pager.component';
declare var $: any;

@Component({
    templateUrl: './customersummaryreport.component.html'
})


export class CustomerSummaryReport implements OnInit, AfterViewChecked {
    public lstCustomerSummaryReport: any;
    public lstCountry: any;
    public lstState: any;
    public lstLicenceType: any;
    public lstAccountType: any;
    CustomerSummaryReportForm: FormGroup;
    CustomerSummaryReports: CustomerSummaryReports[];
    numberOfCustomerSummaryReport: number;
    limit: number;
    page: number = 1;
    error;
    CustomerSummaryReport = new CustomerSummaryReports();
    modalAlerts: string;
    divClass: string = '';
    topPos: string = '2000px';
    selectedRow: number = 0;
    datePipe: DatePipe = new DatePipe('en-US');
    bsValue1: Date = new Date();
    bsValue2: Date = new Date();
    selectedId: number = 0;
    modalRef: BsModalRef;
    date = new Date();
    previousdate = new Date();
    NoRecord: string;
    ExportingStart: boolean;
    buttonStatus: boolean;
    @ViewChild(PagerComponent) pagerComponent: PagerComponent;
    recordCount: number;
    pageNo: number;
    pageLength: number;
     // Declare height and width variables
     scrHeight:any;
     scrWidth:any;
     @HostListener('window:resize', ['$event'])
     getScreenSize(event?) {
 
      var $ua = navigator.userAgent;
      if (($ua.match(/(iPod|iPhone|iPad|android)/i))) {
        this.scrHeight = window.innerHeight-580;
      }
      else
      {
        this.scrHeight = window.innerHeight-480;
      }
     
     }
    constructor(private router: Router, private reportservice: ReportService, private fb: FormBuilder,
      private modalService: BsModalService, public global: GlobalService, private _loadingService: LoadingService) { this.getScreenSize(); }

    ngOnInit(): void {
      this.ExportingStart = false;
      this.buttonStatus = false;
        this.NoRecord = this.global.NoRecords;
        let CustomerSummaryReport = new CustomerSummaryReports();
        this.previousdate.setDate(this.previousdate.getDate());
        this.CustomerSummaryReportForm = this.fb.group({
            sLicenseeName: [''],
            sLicenseType: [0],
            sZip: [''],
            sAccountNumber: [''],
            sAccountType: [0],
            iState: [0],
            sSubscriptionStart: [0.00],
            sSubscriptionEnd: [''],
            iCountry: [0]
        });
        this._loadingService.ShowLoading("global-loading");
        this.GetCountry();
        this.GetState();
        this.GetAccountType();
        this.GetLicenceType();
        this.recordCount = 0;
        this.pageNo = 1;
        this.pageLength = 10;
        this.pagerComponent = new PagerComponent();       
       
        $('#fixed_hdr2').fxdHdrCol({
            fixedCols: 0,
            width: "100%",
            height: this.scrHeight,
            colModal: [
              { width: 150, align: 'center' },
              { width: 200, align: 'center' },
              { width: 150, align: 'Center' },
              { width: 150, align: 'Center' },
              { width: 150, align: 'Center' },
              { width: 150, align: 'Center' },
              { width: 150, align: 'Center' },
              { width: 150, align: 'center' },
              { width: 150, align: 'Center' },
              { width: 150, align: 'center' },
              { width: 150, align: 'center' },
              { width: 150, align: 'center' },
              { width: 150, align: 'center' },
              { width: 150, align: 'center' },
              { width: 200, align: 'center' },
              { width: 200, align: 'Center' },
                //{ width: 400, align: 'Center' },
                //{ width: 150, align: 'center' },
                //{ width: 110, align: 'center' },
            ],
            sort: true
        });
        if(document.getElementById("fixed_table_rc") != null){
          document.getElementById("fixed_table_rc").remove();
          var testScript = document.createElement("script");
          testScript.setAttribute("id", "fixed_table_rc");
          testScript.setAttribute("src", "../assets/scripts/fixed_table_rc.js");
          testScript.setAttribute("type", "text/javascript");
          document.body.appendChild(testScript);
        }
        
    }
    ngAfterViewChecked() {
      $('#fixed_hdr2 thead').css('width', $('#fixed_hdr2 tbody tr:eq(0)').width());
    }
    GetCountry() {
        this.reportservice.GetCountry().subscribe(y => { this.lstCountry = y; }, error => this.error = <any>error);
    }

    GetState() {
        this.reportservice.GetState().subscribe(st => { this.lstState = st; }, error => this.error = <any>error);
    }
    GetLicenceType() {
        this.reportservice.GetLicenceType().subscribe(st => { this.lstLicenceType = st; }, error => this.error = <any>error);
    }

    GetAccountType() {
        this.reportservice.GetAccountType().subscribe(st => { this.lstAccountType = st; }, error => this.error = <any>error);
    }

    GetCustomerSummeryReport(evt: any) {
      this._loadingService.ShowLoading("global-loading");
      var tempArr = evt.split(',');
      this.pageNo = parseInt(tempArr[0]);
      var actulalength=this.pageLength;
      this.pageLength = parseInt(tempArr[1]);
      
      this.CustomerSummaryReport = this.CustomerSummaryReportForm.value;
      var obj = this.CustomerSummaryReport;
      if (this.ExportingStart) {
        this.reportservice.GetCustomerSummeryReport(obj, this.pageNo, this.pageLength).subscribe((CustomerSummaryReports: CustomerSummaryReports[]) => {
           //reset length after csvexport
           this.pageLength=actulalength;
           this.ExportService(CustomerSummaryReports); }, error => this.error = <any>error);      
      }
      else {
        this.reportservice.GetCustomerSummeryReport(obj, this.pageNo, this.pageLength).subscribe((CustomerSummaryReports: CustomerSummaryReports[]) => { this.BindFormFields(CustomerSummaryReports); }, error => this.error = <any>error);
      }
      
    }
    SearchRecords() {
      this.ExportingStart = false;
      this.GetCustomerSummeryReport('1, ' + this.pageLength);
    }
    BindFormFields(data) {
      this.recordCount = data.RecordCount;     
      this.lstCustomerSummaryReport = data.CustomerSummery;
      this.numberOfCustomerSummaryReport = this.lstCustomerSummaryReport.length; this.limit = this.lstCustomerSummaryReport.length;
      if (this.lstCustomerSummaryReport.length > 0) {
        this.NoRecord = '';
        this.buttonStatus = true;
       
      }
      if (this.lstCustomerSummaryReport.length == 0) {
        this.NoRecord = this.global.NoRecords;
        this.buttonStatus = false;
      }
      this._loadingService.HideLoading("global-loading");
    }
    ExportEvent() {
      if (this.buttonStatus) {
        this.ExportingStart = true;
        this.GetCustomerSummeryReport('1, ' + this.recordCount);
        this.ExportingStart = false;
      }
    }
    ExportService(data: any) {
      for (let c = 0; c < this.global.RemoveColumns.length; c++) {
        for (let i = 0; i < data.CustomerSummery.length; i++) {
          delete data.CustomerSummery[i][this.global.RemoveColumns[c].toString()];
        }
      }
      this._loadingService.HideLoading("global-loading");
      this.global.ExportToCSV(data.CustomerSummery, "CustomerSummeryReport-" + this.date.getDay() + "-" + this.date.getMonth() + "-" + this.date.getSeconds())
      
    }
}