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[]; page: number = 1; error; 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; actualPageNo: number; actualPageLength: number; SearchField:any={ sLicenseeName:'', sLicenseType:0, sAccountNumber:'', sAccountType:0, sZip:'', sSubscriptionStart:0, sSubscriptionEnd:-1, iState:0, iCountry:0, sortColumn:'AccountNumber', sortOrder:'asc', pageNo:1, pageLength:10 }; @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; } if(this.scrHeight<=360) this.scrHeight=360; $(".ft_container").css("height",this.scrHeight); } 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; this.previousdate.setDate(this.previousdate.getDate()); this.CustomerSummaryReportForm = this.fb.group({ sLicenseeName: [''], sLicenseType: [0], sZip: [''], sAccountNumber: [''], sAccountType: [0], iState: [0], sSubscriptionStart: [''], 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: 140, align: 'center' }, { width: 200, align: 'center' }, { width: 150, align: 'Center' }, { width: 150, align: 'Center' }, { width: 150, align: 'Center' }, { width: 170, align: 'Center' }, { width: 100, align: 'Center' }, { width: 130, align: 'center' }, { width: 130, align: 'Center' }, { width: 110, align: 'center' }, { width: 100, align: 'center' }, { width: 120, align: 'center' }, { width: 130, align: 'center' }, { width: 150, align: 'center' }, { width: 130, align: 'center' }, { width: 110, align: 'Center' } ], sort: true }); var thisObject=this;//class object $(".ft_rwrapper table thead tr th").on("click",function(event){ if(event.currentTarget.id!=undefined && event.currentTarget.id!="" && event.currentTarget.id!=null) { var fieldName=event.currentTarget.id; var sortType='' var isAscSort = $(".ft_rwrapper table thead tr #"+fieldName).hasClass('fx_sort_asc'); $(".ft_rwrapper table thead tr th").removeClass('fx_sort_asc fx_sort_desc'); if (isAscSort) { $(".ft_rwrapper table thead tr #"+fieldName).addClass('fx_sort_desc').removeClass('fx_sort_asc'); sortType="desc"; } else { $(".ft_rwrapper table thead tr #"+fieldName).addClass('fx_sort_asc').removeClass('fx_sort_desc'); sortType="asc"; } thisObject.SortTableRecords(fieldName,sortType); } }); } 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 = error); } GetState() { this.reportservice.GetState().subscribe(st => { this.lstState = st; }, error => this.error = error); } GetLicenceType() { this.reportservice.GetLicenceType().subscribe(st => { this.lstLicenceType = st; }, error => this.error = error); } GetAccountType() { this.reportservice.GetAccountType().subscribe(st => { this.lstAccountType = st; }, error => this.error = error); } SortTableRecords(fieldName:string,sortType:string) { this.SearchField.sortColumn=fieldName; this.SearchField.sortOrder=sortType; this.GetCustomerSummeryList(); } GetCustomerSummeryReport(evt: any) { this.actualPageNo = this.pageNo; this.actualPageLength =this.pageLength; var tempArr = evt.split(','); this.pageNo = parseInt(tempArr[0]); this.pageLength = parseInt(tempArr[1]); this.SearchField.pageNo=this.pageNo; this.SearchField.pageLength=this.pageLength; this.GetCustomerSummeryList(); } GetCustomerSummeryList() { this._loadingService.ShowLoading("global-loading"); $(".ft_rwrapper table thead tr th").removeClass('fx_sort_asc fx_sort_desc'); if (this.SearchField.sortOrder=='asc') { $(".ft_rwrapper table thead tr #"+this.SearchField.sortColumn).addClass('fx_sort_asc').removeClass('fx_sort_desc'); } else { $(".ft_rwrapper table thead tr #"+this.SearchField.sortColumn).addClass('fx_sort_desc').removeClass('fx_sort_asc'); } if (this.ExportingStart) { this.reportservice.GetCustomerSummeryReport(this.SearchField).subscribe((CustomerSummaryReports: CustomerSummaryReports[]) => { //reset length after csvexport this.pageNo = this.actualPageNo; this.pageLength=this.actualPageLength; this.SearchField.pageNo=this.pageNo; this.SearchField.pageLength=this.pageLength; this.ExportService(CustomerSummaryReports); }, error => this.error = error); } else { this.reportservice.GetCustomerSummeryReport(this.SearchField).subscribe((CustomerSummaryReports: CustomerSummaryReports[]) => { this.BindFormFields(CustomerSummaryReports); }, error => this.error = error); } this.ExportingStart = false; } SearchRecords() { this.ExportingStart = false; this.pageNo=1; this.SearchField.sLicenseeName=this.CustomerSummaryReportForm.controls['sLicenseeName'].value; this.SearchField.sLicenseType=this.CustomerSummaryReportForm.controls['sLicenseType'].value; this.SearchField.sAccountNumber=this.CustomerSummaryReportForm.controls['sAccountNumber'].value; this.SearchField.sAccountType=this.CustomerSummaryReportForm.controls['sAccountType'].value; this.SearchField.sZip=this.CustomerSummaryReportForm.controls['sZip'].value; this.SearchField.sSubscriptionStart=this.CustomerSummaryReportForm.controls['sSubscriptionStart'].value; this.SearchField.sSubscriptionEnd=this.CustomerSummaryReportForm.controls['sSubscriptionEnd'].value; this.SearchField.iState=this.CustomerSummaryReportForm.controls['iState'].value; this.SearchField.iCountry=this.CustomerSummaryReportForm.controls['iCountry'].value; this.SearchField.pageNo=this.pageNo; this.GetCustomerSummeryList(); } BindFormFields(data) { this.recordCount = data.RecordCount; this.lstCustomerSummaryReport = data.CustomerSummery; 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); } } ExportService(data: any) { for (let i = 0; i < data.CustomerSummery.length; i++) { data.CustomerSummery[i]['StartDate']= this.datePipe.transform(data.CustomerSummery[i]['StartDate'], 'MM/dd/yyyy'); data.CustomerSummery[i]['EndDate']= this.datePipe.transform(data.CustomerSummery[i]['EndDate'], 'MM/dd/yyyy'); data.CustomerSummery[i]['LicenseCreationDate']= this.datePipe.transform(data.CustomerSummery[i]['LicenseCreationDate'], 'MM/dd/yyyy'); } var reportname=+ this.date.getDay() + "-" + (this.date.getMonth()+1) + "-" + this.date.getSeconds() this.global.ExportToCSV(data.CustomerSummery, "CustomerSummeryReport-"+reportname); this._loadingService.HideLoading("global-loading"); } }