/** * @Component Name: OrderProductsComponent * @Module: Home * @Module Functionality : To display the order products section * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnInit, OnDestroy } from '@angular/core'; import * as Constants from '../constants'; import * as FormConstants from '../form.constants'; import Utils from '../../shared/utils'; import CartUtils from '../cart.utils'; import { IPackage } from '../modal/common'; import { TradeinService } from '../../services/tradein.service'; import { SharedService } from '../../shared/shared.service'; declare interface TableData { headerRow: string[]; dataRows: IPackage[]; } @Component({ selector: 'products-cmp', moduleId: module.id, templateUrl: 'products.component.html', styleUrls: ['products.component.css'] }) export class ProductsComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'ProductsComponent'; storeId: number; headerRow: string[] = ['Type', 'Qty', 'Price', 'Discount', 'Due Monthly', 'Tax', 'Due Today']; headerRowMobile: string[] = ['Type', 'Due Monthly', 'Due Today']; packageTypes: string[] = [ Constants.PACKAGE_TYPE_VOICE, Constants.PACKAGE_TYPE_DATA, Constants.PACKAGE_TYPE_PREPAID, Constants.PACKAGE_TYPE_ACCESSORY ]; @Input() cart: any; tradeinOfferDisplay: string = Constants.TRADE_IN_OFFER_DISPLAY; dataPackageType: string = Constants.PACKAGE_TYPE_DATA; @Input() enrollAutopay: boolean = false; tradeInList: any; dormanFlag:any; rtStoreId: number = Constants.STORE_ID_RT; constructor(public tradeinService: TradeinService , public sharedService: SharedService) { } /** * This function is used to initialize the directive/component after Angular * first displays the data-bound properties.It is invoked only once when the * directive is instantiated. * @returns void */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); this.dormanFlag =this.sharedService.getDormantProperties(); if (this.cart && this.cart.packages) { for (let i = 0; i < this.cart.packages.length; i++) { this.cart.packages[i].showPackage = false; } this.cart.packages[0].showPackage = true; } } /** * Cleanup just before Angular destroys the directive/component. * Unsubscribe Observables and detach event handlers to avoid memory leaks. * @returns void */ ngOnDestroy(): void { const METHOD_NAME: string = 'ngOnDestroy()'; this.cart = null; this.headerRow = null; this.headerRowMobile = null; this.packageTypes = null; } /** * This function is used to get the list of package based on the package type. * @param {string} type contains valid package type. * @returns IPackage */ getPackages(type: string): IPackage[] { const METHOD_NAME: string = 'getPackages()'; return this.cart.packages.filter((pkg) => { return (pkg && pkg.packageType === type) }); } /** * This function is used to get line name based on line type. * @param {string} type - line type * @returns Object */ getLineName(pack: IPackage): Object { const METHOD_NAME: string = 'getLineName()'; return CartUtils.getLineName(pack); } /** * This function is used to get fee name based on line fee. * @returns string */ getFeeName(): string { const METHOD_NAME: string = 'getFeeName()'; return FormConstants.ADDITIONAL_LINE_FEE; } /** * This function is used to get fee type based on fees. * @returns string */ getFeeType(): string { const METHOD_NAME: string = 'getFeeType()'; return FormConstants.FEES; } /** * This function is used to get deposit name based on deposit. * @returns string */ getDepositName(): string { const METHOD_NAME: string = 'getDepositName()'; return FormConstants.DEPOSIT; } /** This function is used to get primary line details. * @param {any} item * @returns string */ getPrimaryLineDetails(item: any): string { const METHOD_NAME: string = 'getPrimaryLineDetails()'; let lineName = ''; if (item) { lineName = CartUtils.getPrimaryLine(this.cart, item); } return lineName; } findTradeInExists (item: any): any { this.tradeInList = this.tradeinService.getTradeInInfo(); if (item && item.device && item.device.orderItemId && this.tradeInList.length > 0) { for (const tradein of this.tradeInList) { if (item.device.orderItemId === tradein.orderItemsId) { return { duration : tradein.duration, price: tradein.price } } } } } mobileNumber(phoneNumber: string): string { return Utils.formatPhoneNumber(phoneNumber ); } actErrorMessage(errorMessage:string):string { return Utils.formatActErrorMessage(errorMessage ); } }