import { Injectable } from '@angular/core'; import * as global from '../../core/common'; import { Http, RequestOptions, URLSearchParams, Response } from '@angular/http'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; import 'rxjs/add/observable/throw'; import { Observable, throwError } from 'rxjs' import { ITimeZone } from '../../core/general/ITimeZone'; import { IStoreSetupGeneral } from '../../core/general/IStoreSetupGeneral'; import { ICurrency } from '../../core/general/ICurrency'; import { IStoreSetupCheckout } from '../../core/general/IStoreSetupCheckout'; import { IContinent } from '../../core/general/IContinent'; import { SelectItem } from 'primeng/api'; import { IShippingProfile } from '../../core/shipping/IShippingProfile'; import { IShippingProfileInfo } from '../../core/shipping/IShippingProfileInfo'; import { ICurrencyFormat } from '../../core/shipping/ICurrencyFormat'; import { ISlip } from '../../core/shipping/ISlip'; import { TreeviewItem, TreeItem } from '../../lib'; @Injectable({ providedIn: 'root' }) export class GeneralService { private GetTimeZoneUrl = global.automationServerBase + '/api/Localisation/GetTimeZones'; private GetStoreSetupGeneralUrl = global.serverBase + '/api/Configurations/GetStoreSetupGeneral'; private SetStoreSetupGeneralUrl = global.serverBase + '/api/Configurations/SetStoreSetupGeneral'; private GetCurrencyUrl = global.serverBase + '/api/Configurations/GetCurrency'; private GetStoreSetupCheckoutUrl = global.serverBase + '/api/Configurations/GetStoreSetupCheckout'; private SetStoreSetupCheckoutUrl = global.serverBase + '/api/Configurations/SetStoreSetupCheckout'; private GetContinentsUrl = global.serverBase + '/api/Configurations/GetContinents'; private GetShippingTypesUrl = global.serverBase + '/api/Shipping/GetShippingTypes'; private SetShippingProfileUrl = global.serverBase + '/api/Shipping/SetShippingProfile'; private GetShippingProfileUrl = global.serverBase + '/api/Shipping/GetShippingProfile'; private GetShippingProfileListUrl = global.serverBase + '/api/Shipping/GetShippingProfileList'; private GetCurrencyFormatUrl = global.serverBase + '/api/Shipping/GetCurrencyFormat'; private CopyRangeUrl = global.serverBase + '/api/Shipping/CopyRateRange'; private SetSlipUrl = global.serverBase + '/api/Shipping/SetShippingSlip'; private GetSlipUrl = global.serverBase + '/api/Shipping/GetShippingSlip'; private GetCountriesUrl = global.serverBase + '/api/Shipping/GetCountryList'; private GetStateListUrl = global.serverBase + '/api/Shipping/GetStateList'; constructor(private http: Http) { } // Get time zones GetTimeZones(): Observable { return this.http.get(this.GetTimeZoneUrl) .map((response: Response) => response.json()) .catch(this.handleError); } // Get store setup generals GetStoreSetupGeneral(companyId: number, actionType: string = "All"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetStoreSetupGeneralUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Set store setup generals SetStoreSetupGeneral(companyId: number, storeSetupGeneral: IStoreSetupGeneral, actionType: string = "SET"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.post(this.SetStoreSetupGeneralUrl, storeSetupGeneral, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Get currency GetCurrency(): Observable { return this.http.get(this.GetCurrencyUrl) .map((response: Response) => response.json()) .catch(this.handleError); } // Get store setup checkout GetStoreSetupCheckout(companyId: number, actionType: string = "All"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetStoreSetupCheckoutUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Set store setup checkout SetStoreSetupCheckout(companyId: number, storeSetupCheckout: IStoreSetupCheckout, actionType: string = "SET"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.post(this.SetStoreSetupCheckoutUrl, storeSetupCheckout, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Get continents GetContinents(): Observable { return this.http.get(this.GetContinentsUrl) .map((response: Response) => response.json()) .catch(this.handleError); } // Get shipping cost types GetShippingTypes(companyId: number, actionType: string = "All"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetShippingTypesUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Set shipping profile SetShippingProfile(companyId: number, shippingProfile: IShippingProfile, actionType: string = "SET"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.post(this.SetShippingProfileUrl, shippingProfile, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Get shipping profile GetShippingProfile(companyId: number, shippingProfileId: number, actionType: string = "All"): Observable { const myparams = new URLSearchParams(); myparams.append('shippingProfileId', shippingProfileId.toString()); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetShippingProfileUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Get shipping profile list GetShippingProfileList(companyId: number, shippingProfileId: number, actionType: string = "All"): Observable { const myparams = new URLSearchParams(); myparams.append('id', shippingProfileId.toString()); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetShippingProfileListUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Get currency format GetCurrencyFormat(companyId: number, actionType: string = "All"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetCurrencyFormatUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Get currency format CopyRange(companyId: number, id: number, rangeId: number, costType: string, actionType: string): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('id', id.toString()); myparams.append('rangeId', rangeId.toString()); myparams.append('costType', costType); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.CopyRangeUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Set slip SetSlip(companyId: number, slip: ISlip, actionType: string = "SET"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.post(this.SetSlipUrl, slip, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } // Get slip GetSlip(companyId: number, actionType: string = "GET"): Observable { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetSlipUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } getCountryList():Observable { return this.http.get(this.GetCountriesUrl) .map((response: Response) => response.json()) .catch(this.handleError); } getStateList(countryId:string,actionType:string):Observable { const myparams = new URLSearchParams(); myparams.append('countryId', countryId); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetStateListUrl, { params: options }) .map((response: Response) => response.json()) .catch(this.handleError); } private handleError(error): Observable { const message = error.statusText || 'Server error'; return throwError(error); } }