import { Injectable, Inject } from '@angular/core'; //import { HttpClient, HttpParams, HttpRequest} from "@angular/common/http"; import { Http, Response, Headers, RequestOptions, HttpModule } from '@angular/http'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; import { User } from '../UserEntity/datamodel'; import { UsageReports } from '../Reports/reportdatamodel'; import 'rxjs/add/operator/do'; import { Observable } from 'rxjs/Observable'; import { GlobalService } from '../../shared/global'; import { DatePipe } from '@angular/common'; @Injectable() export class ReportService { datePipe: DatePipe = new DatePipe('en-US'); constructor(private http: Http, public commonService: GlobalService) { } GetCountry() { return this.http.get(this.commonService.resourceBaseUrl + "Common/Countries") .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetState() { return this.http.get(this.commonService.resourceBaseUrl + "Common/States") .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetLicenceType() { return this.http.get(this.commonService.resourceBaseUrl + "License/LicenseTypes") .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetAccountType() { return this.http.get(this.commonService.resourceBaseUrl + "Common/GetAccountType") .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetEdition() { return this.http.get(this.commonService.resourceBaseUrl + "Common/GetEdition") .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetDiscountCodes() { return this.http.get(this.commonService.resourceBaseUrl + "Common/GetDiscountCode") .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetUsageReport(obj: any) { if (obj.sFromDate == '' || obj.sFromDate == null) { obj.sFromDate = '1/1/1'; } if (obj.sToDate == '' || obj.sToDate == null) { obj.sToDate = '1/1/9999'; } obj.sFromDate = this.datePipe.transform(obj.sFromDate, 'MM/dd/yyyy'); obj.sToDate = this.datePipe.transform(obj.sToDate, 'MM/dd/yyyy'); return this.http.get(this.commonService.resourceBaseUrl + "Report/GetUsageReport?sFromDate=" + obj.sFromDate + "&sToDate=" + obj.sToDate + "&sAccoutNumber=" + obj.sAccountNumber + "&sZip=" + obj.sZip + "&iState=" + obj.iState + "&iCountry=" + obj.iCountry + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetCustomerSummeryReport(obj: any) { if (obj.sSubscriptionStart == undefined || obj.sSubscriptionStart === '') obj.sSubscriptionStart = -1; if (obj.sSubscriptionEnd == undefined || obj.sSubscriptionEnd === '') obj.sSubscriptionEnd = -1; return this.http.get(this.commonService.resourceBaseUrl + "Report/GetCustomerSummeryReport?sAccoutNumber=" + obj.sAccountNumber + "&sLicenseeFullName=" + obj.sLicenseeName + "&iStartPrice=" + obj.sSubscriptionStart + "&iEndPrice=" + obj.sSubscriptionEnd + "&iLicenseType=" + obj.sLicenseType + "&iAccountType=" + obj.sAccountType + "&iLicenseType=" + obj.sLicenseType + "&sZip=" + obj.sZip + "&iState=" + obj.iState + "&iCountry=" + obj.iCountry + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetExpiringSubscriptionReport(obj: any) { if (obj.sFromDate == '' || obj.sFromDate == null) { obj.sFromDate = '1/1/1'; } if (obj.sToDate == '' || obj.sToDate == null) { obj.sToDate = '1/1/9999'; } if (obj.iStartPrice == undefined || obj.iStartPrice==='') obj.iStartPrice = -1; if (obj.iEndPrice == undefined || obj.iEndPrice === '') obj.iEndPrice = -1; obj.sFromDate = this.datePipe.transform(obj.sFromDate, 'MM/dd/yyyy'); obj.sToDate = this.datePipe.transform(obj.sToDate, 'MM/dd/yyyy'); return this.http.get(this.commonService.resourceBaseUrl + "Report/GetExpiringSubscriptionReport?sFromDate=" + obj.sFromDate + "&sToDate=" + obj.sToDate + "&iStartPrice=" + obj.iStartPrice + "&iEndPrice=" + obj.iEndPrice + "&iLicenseTypeId=" + obj.iLicenseTypeId + "&iAccountTypeId=" + obj.iAccountTypeId + "&sZip=" + obj.sZip + "&iStateId=" + obj.iStateId + "&iCountryId=" + obj.iCountryId + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetSubscriptionReport(obj: any) { if (obj.sFromDate == '' || obj.sFromDate == null) { obj.sFromDate = '1/1/1'; } if (obj.sToDate == '' || obj.sToDate == null) { obj.sToDate = '1/1/9999'; } obj.sFromDate = this.datePipe.transform(obj.sFromDate, 'MM/dd/yyyy'); obj.sToDate = this.datePipe.transform(obj.sToDate, 'MM/dd/yyyy'); if (obj.icStartPrice == undefined || obj.icStartPrice==='') obj.icStartPrice = -1; if (obj.icEndPrice == undefined || obj.icEndPrice === '') obj.icEndPrice = -1; return this.http.get(this.commonService.resourceBaseUrl + "Report/GetSubscriptionReport?sFromDate=" + obj.sFromDate + "&sToDate=" + obj.sToDate + "&icStartPrice=" + obj.icStartPrice + "&icEndPrice=" + obj.icEndPrice + "&iLicenseTypeId=" + obj.iLicenseTypeId + "&iAccountTypeId=" + obj.iAccountTypeId + "&sZip=" + obj.sZip + "&iStateId=" + obj.iStateId + "&iCountryId=" + obj.iCountryId + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetSubscriptionCancellationReport(obj: any) { if (obj.sFromDate == '' || obj.sFromDate == null) { obj.sFromDate = '1/1/1'; } if (obj.sToDate == '' || obj.sToDate == null) { obj.sToDate = '1/1/9999'; } obj.sFromDate = this.datePipe.transform(obj.sFromDate, 'MM/dd/yyyy'); obj.sToDate = this.datePipe.transform(obj.sToDate, 'MM/dd/yyyy'); if (obj.icStartPrice == undefined || obj.icStartPrice === '') obj.icStartPrice = -1; if (obj.icEndPrice == undefined || obj.icEndPrice === '') obj.icEndPrice = -1; return this.http.get(this.commonService.resourceBaseUrl + "Report/GetSubscriptionCancellationReport?sFromDate=" + obj.sFromDate + "&sToDate=" + obj.sToDate + "&icStartPrice=" + obj.icStartPrice + "&icEndPrice=" + obj.icEndPrice + "&iLicenseTypeId=" + obj.iLicenseTypeId + "&iAccountTypeId=" + obj.iAccountTypeId + "&sZip=" + obj.sZip + "&iStateId=" + obj.iStateId + "&iCountryId=" + obj.iCountryId + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetNetAdSummaryReport(obj: any) { if (obj.sFromDate == '' || obj.sFromDate == null) { obj.sFromDate = '1/1/1'; } if (obj.sToDate == '' || obj.sToDate == null) { obj.sToDate = '1/1/9999'; } obj.sFromDate = this.datePipe.transform(obj.sFromDate, 'MM/dd/yyyy'); obj.sToDate = this.datePipe.transform(obj.sToDate, 'MM/dd/yyyy'); if (obj.iStartPrice == undefined || obj.iStartPrice == '') obj.iStartPrice = -1; if (obj.iEndPrice == undefined || obj.iEndPrice == '') obj.iEndPrice = -1; return this.http.get(this.commonService.resourceBaseUrl + "Report/GetNetAdSummaryReport?sFromDate=" + obj.sFromDate + "&sToDate=" + obj.sToDate + "&iStartPrice=" + obj.iStartPrice + "&iEndPrice=" + obj.iEndPrice + "&iLicenseTypeId=" + obj.iLicenseTypeId + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetSiteLicenseUsageReport(obj: any) { if (obj.sFromDate == '' || obj.sFromDate == null) { obj.sFromDate = '1/1/1'; } if (obj.sToDate == '' || obj.sToDate == null) { obj.sToDate = '1/1/9999'; } obj.sFromDate = this.datePipe.transform(obj.sFromDate, 'MM/dd/yyyy'); obj.sToDate = this.datePipe.transform(obj.sToDate, 'MM/dd/yyyy'); if (obj.sAccountNumber == null) obj.sAccountNumber = ''; return this.http.get(this.commonService.resourceBaseUrl + "Report/GetSiteLicenseUsageReport?sFromDate=" + obj.sFromDate + "&sToDate=" + obj.sToDate + "&sAccountNumber=" + obj.sAccountNumber + "&iEdition=" + obj.iEdition + "&iLoginTypeId=" + obj.iLoginTypeId + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetDiscountReport(obj: any) { if (obj.sFromDate == '' || obj.sFromDate == null) { obj.sFromDate = '1/1/1'; } if (obj.sToDate == '' || obj.sToDate == null) { obj.sToDate = '1/1/9999'; } obj.sFromDate = this.datePipe.transform(obj.sFromDate, 'MM/dd/yyyy'); obj.sToDate = this.datePipe.transform(obj.sToDate, 'MM/dd/yyyy'); if (obj.sAccountNumber == null) obj.sAccountNumber = ''; return this.http.get(this.commonService.resourceBaseUrl + "Report/GetDiscountReport?sFromDate=" + obj.sFromDate + "&sToDate=" + obj.sToDate + "&iDiscountCode=" + obj.iDiscountCode + "&sAccountNumber=" + obj.sAccountNumber + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetImageExportReport(obj: any) { if (obj.sFromDate == '' || obj.sFromDate == null) { obj.sFromDate = '1/1/1'; } if (obj.sToDate == '' || obj.sToDate == null) { obj.sToDate = '1/1/9999'; } obj.sFromDate = this.datePipe.transform(obj.sFromDate, 'MM/dd/yyyy'); obj.sToDate = this.datePipe.transform(obj.sToDate, 'MM/dd/yyyy'); if (obj.sAccountNumber == null) obj.sAccountNumber = ''; return this.http.get(this.commonService.resourceBaseUrl + "Report/GetImageExportReport?sFromDate=" + obj.sFromDate + "&sToDate=" + obj.sToDate + "&sAccountNumber=" + obj.sAccountNumber + "&sortColumn=" + obj.sortColumn + "&sortOrder=" + obj.sortOrder + "&pageNo=" + obj.pageNo + "&pageLength=" + obj.pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } extractData(res: Response) { let body = res.json(); return body; } handleError(error: any) { // In a real world app, we might use a remote logging infrastructure // We'd also dig deeper into the error to get a better message let errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : 'Server error'; console.error(errMsg); // log to console instead return Observable.throw(errMsg); } }