expiringsubscriptionreport.component.ts 11.6 KB
import { Component, OnInit, AfterViewChecked, ViewChild } 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 { ExpiringSubscriptionReports } 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, BsDatepickerConfig   } from 'ngx-bootstrap';
import { Http, Response } from '@angular/http';
import { LoadingService } from '../../shared/loading.service';
import { PagerComponent } from '../../shared/pager/pager.component';
//import { Ng2SmartTableModule, LocalDataSource } from 'ng2-smart-table';

declare var $: any;

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

export class ExpiringSubscriptionReport implements OnInit, AfterViewChecked {
    public lstExpiringSubscriptionReport: any;
    public lstCountry: any;
    public lstState: any;
    public lstLicenceType: any;
    public lstAccountType: any;
    ExpiringSubscriptionReportForm: FormGroup;
    ExpiringSubscriptionReports: ExpiringSubscriptionReports[];
    numberOfExpiringSubscriptionReport: number;
    limit: number;
    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;
    alerts: string;
    enableTextboxColor: boolean;
    bsConfig: Partial<BsDatepickerConfig>;
    ExportingStart: boolean;
    buttonStatus: boolean;
    @ViewChild(PagerComponent) pagerComponent: PagerComponent;
    recordCount: number;
    pageNo: number;
    pageLength: number;
    key: string = 'AccountNumber'; //set default
    reverse: boolean = false;
    //settings = {
    //  actions: { add: false, edit: false, delete: false },
    //  pager: {
    //    display: true,
    //    perPage: 5
    //  },
    //  attr: {
    //    class: 'table table-condensed table-bordered table-striped table-hover'        
    //  },
    //  //hideSubHeader:true,
    //  //rowClassFunction: (row) => {
    //  //  if (row.index == this.selectedRow) {
    //  //    return 'ng2-smart-row selected';
    //  //  }
    //  //  else {
    //  //    return 'ng2-smart-row';
    //  //  }
    //  //},
    //  //noDataMessage:'Loading, Please wait...',
    //  columns: {
    //    AccountNumber: {
    //      title: 'Account Number',
    //      width: '140px',
          
          
    //    },
    //    LicenseeName: {
    //      title: 'Licensee Name',
    //      width: '140px'
    //    },
    //    LicenseType: {
    //      title: 'License Type',
    //      width: '140px'
    //    },
    //    InstitutionName: {
    //      title: 'Institution Name',
    //      width: '140px'
    //    }
    //    ,
    //    //Edition: {
    //    //  title: 'Edition',
    //    //  width: '140px'
    //    //}
    //    //,
    //    StartDate: {
    //      title: 'Start Date',
    //      width: '140px'
    //    },
    //    EndDate: {
    //      title: 'End Date',
    //      width: '140px'
    //    }
    //    ,
    //    LicenseCreationDate: {
    //      title: 'Original Entry Date',
    //      width: '140px'
    //    },
    //    SubscriptionPrice: {
    //      title: 'Subscription Price',
    //      width: '140px'
    //    },
    //    AccountType: {
    //      title: 'Account Type',
    //      width: '140px'
    //    }
    //    ,
    //    DaysRemaining: {
    //      title: 'Time Period',
    //      width: '140px'
    //    }
    //    ,
    //    CardNumber: {
    //      title: 'Credit Card Number',
    //      width: '140px'
    //    }
    //    //Serial_No: {
    //    //  title: 'Serial_No'
    //    //}


    //  }
    //};
    
    //source: LocalDataSource;
    ExpiringSubscription = new ExpiringSubscriptionReports();
    constructor(private router: Router, private reportservice: ReportService,
      private fb: FormBuilder, private modalService: BsModalService,
      public global: GlobalService, private _loadingService: LoadingService) { }

    ngOnInit(): void {
      this.buttonStatus = false;
      this.ExportingStart = false;
      this.bsConfig = Object.assign({}, { containerClass: 'theme-dark-blue' });
      this.NoRecord = this.global.NoRecords;
        let ExpiringSubscriptionReport = new ExpiringSubscriptionReports();
        this.previousdate.setDate(this.previousdate.getDate());
        this.ExpiringSubscriptionReportForm = this.fb.group({
            sFromDate: [this.previousdate],
            sToDate: [this.date],
            sZip: [''],
            iLicenseTypeId: [0],
            iAccountTypeId: [0],
            iStateId: [0],
            iStartPrice: [0.00],
            iEndPrice: [0.00],
            iCountryId: [0]
        });
        this.alerts = '';
        this.enableTextboxColor = true;
        this._loadingService.ShowLoading("global-loading");
        this.GetCountry();
        this.GetState();
        this.GetAccountType();
        this.GetLicenceType();
        this.pageNo = 1;
        this.pageLength = 10;
        this.pagerComponent = new PagerComponent();       
        this._loadingService.HideLoading("global-loading");
        //this.GetCustomerSummeryReport();
        $('#fixed_hdr2').fxdHdrCol({
            fixedCols: 0,
            width: "100%",
            height: 300,
            colModal: [
                { width: 180, align: 'center' },
                { width: 230, align: 'center' },
                { width: 150, align: 'Center' },
                { width: 150, align: 'Center' },
                { width: 350, align: 'Center' },
                { width: 500, align: 'Center' },
                { width: 130, align: 'Center' },
                { width: 150, align: 'center' },
                { width: 280, align: 'Center' },
                { width: 180, align: 'center' },
                { width: 200, align: 'center' },
                { width: 170, align: 'center' },
                { width: 80, align: 'center' },
                { width: 150, align: 'center' },
                { width: 150, align: 'center' },
                { width: 180, align: 'Center' },
                //{ width: 400, align: 'Center' },
                //{ width: 150, align: 'center' },
                //{ width: 110, align: 'center' },
            ],
            sort: true
        });
        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);
    }

    GetExpiringSubscriptionReport(evt: any) {
      var tempArr = evt.split(',');
      this.pageNo = parseInt(tempArr[0]);
      this.pageLength = parseInt(tempArr[1]);
      this.alerts = '';
      this.global.compareTwoDates(this.ExpiringSubscriptionReportForm.controls['sToDate'].value, this.ExpiringSubscriptionReportForm.controls['sFromDate'].value);
      if (this.global.ValidationMsg != '') {
        this.alerts = this.global.ValidationMsg
      } 
      if (this.alerts == '') {
        this._loadingService.ShowLoading("global-loading");
        this.ExpiringSubscription = this.ExpiringSubscriptionReportForm.value;
        var obj = this.ExpiringSubscription;
        if (this.ExportingStart) {
          this.reportservice.GetExpiringSubscriptionReport(obj, this.pageNo, this.pageLength).subscribe((ExpiringSubscriptionReports: ExpiringSubscriptionReports[]) => { this.ExportService(ExpiringSubscriptionReports); }, error => this.error = <any>error);
        }
        else {
          this.reportservice.GetExpiringSubscriptionReport(obj, this.pageNo, this.pageLength).subscribe((ExpiringSubscriptionReports: ExpiringSubscriptionReports[]) => { this.BindFormFields(ExpiringSubscriptionReports); }, error => this.error = <any>error);
        }
        
      }
            
    }
    SearchRecords() {
      this.ExportingStart = false;
      this.GetExpiringSubscriptionReport('1, ' + this.pageLength);
    }
    ExportEvent() {
      if (this.buttonStatus) {
        this.ExportingStart = true;
        this.GetExpiringSubscriptionReport('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.ExpiringSubscription.length; i++) {
          delete data.ExpiringSubscription[i][this.global.RemoveColumns[c].toString()];
        }
      }
      this._loadingService.HideLoading("global-loading");
      this.global.ExportToCSV(data.ExpiringSubscription, "ExpiringSubscriptionReport-" + this.date.getDay() + "-" + this.date.getMonth() + "-" + this.date.getSeconds())
     
    }
   
    sort(key) {
      debugger;;
      this.key = key;
      this.reverse = !this.reverse;
    }
    //compareTwoDates() {
      
    //  if (new Date(this.ExpiringSubscriptionReportForm.controls['sToDate'].value) < new Date(this.ExpiringSubscriptionReportForm.controls['sFromDate'].value)) {
        
    //   //this.enableTextboxColor = false;
    //  }
    //}
    
    onKeyUp(event: any) {
      debugger;;
      //this.enableTextboxColor = true;
    };

    //onKeyPress(event: any) {
    //  debugger;;
    //  this.enableTextboxColor = true;
    //};

    onchange(event: any) {
      debugger;;
      //this.enableTextboxColor = true;
    };

    //onKeydown(event: any) {
    //  debugger;;
    //  this.enableTextboxColor = true;
    //}
    
    BindFormFields(datas) {
      this.recordCount = datas.RecordCount;
      this.lstExpiringSubscriptionReport = datas.ExpiringSubscription;
      //this.source = new LocalDataSource(this.lstExpiringSubscriptionReport);
      //let data = datas.ExpiringSubscription;
      //this.source = new LocalDataSource(data);
     
      this.numberOfExpiringSubscriptionReport = this.lstExpiringSubscriptionReport.length; this.limit = this.lstExpiringSubscriptionReport.length;
      if (this.lstExpiringSubscriptionReport.length > 0) {
        this.NoRecord = '';
        this.buttonStatus = true;
        this._loadingService.HideLoading("global-loading");
      }
      if (this.lstExpiringSubscriptionReport.length == 0) {
        this.NoRecord = this.global.NoRecords;
        this._loadingService.HideLoading("global-loading");
        this.buttonStatus = false;
      }
    }
}