/** * @Component Name: MIRateplansComponent * @Module: Home * @Module Functionality : To display the mi rate plans * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, ChangeDetectionStrategy, OnInit, DoCheck, OnDestroy } from '@angular/core'; import Utils from '../../../shared/utils'; import CartUtils from '../../../shared/cart.utils'; import { SORT_BY_OPTIONS } from '../../../shared/form.constants'; import { IKeyValue } from '../../../shared/modal/key.value'; import * as Constants from '../../../shared/constants'; import { IRateplan, IFilterList, IFilter, IPackage } from '../../../shared/modal/common'; import { User } from '../../../shared/modal/user'; import { Cart } from '../../../shared/modal/cart'; import { Customer, ICreditProfile } from '../../../shared/modal/customer'; import { SharedService } from '../../../shared/shared.service'; import { UserService } from '../../../services/user.service'; import { CartService } from '../../../services/cart.service'; import { CatalogService } from '../../../services/catalog.service'; import { CustomerService } from '../../../services/customer.service'; import { MoreDetailsService } from './../../../shared/more-details-modal.service'; declare var jQuery: any; @Component( { moduleId: module.id, selector: 'mi-rateplans-cmp', templateUrl: 'mi-rateplans.component.html', styleUrls: ['mi-rateplans.component.css'], // changeDetection: ChangeDetectionStrategy.OnPush }) export class MIRateplansComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'MIRateplansComponent'; categoryId: number = Constants.CATEGORY_ID_PLAN; storeId: number; // update storeid creditType: string = Constants.CREDIT_CHECK; groupByCount: number = jQuery(window).width() <= 991 ? 2 : 3; cardsPerPage: number = Constants.CARDS_PER_PAGE; // header section veriables lineRange: number = 1; // for range slider searchText: string = ''; // search text sortByKey: string = ''; sortByOptions: IKeyValue[]; // order by price and alphabet rangeLineCount: number = 1; // body section veriables rateplans: IRateplan[]; filters: IFilterList[]; individualPlanFilters: IFilter[]; familyPlanFilters: IFilter[]; // sorted rateplans for display sortedRateplans: Array>; // pagination allItems: any[]; // array of all items to be paged pager: any = {};  // pager object pagedItems: any[]; // paged items // added for expand and collapse expandedProductId: number; // adding item to cart functionality packageType: string = Constants.PACKAGE_TYPE_DATA; user: User; customer: Customer; creditProfile: ICreditProfile; subscription: any; cart: Cart; // getting active package item package: IPackage; disableAddToCart: boolean = false; isFinanceOrder: boolean = false; isNCFPlanInCart: boolean = false; isTIPlanInCart: boolean = false; isPooledPlanInCart: boolean = false; isTIPlanInAccount: boolean = false; isPooledPlanInAccount: boolean = false; numberOfVoiceLines: number = 0; KarmaTestResult: any = {}; constructor( public sharedService: SharedService, public userService: UserService, public cartService: CartService, public catalogService: CatalogService, public customerService: CustomerService, public moreDetailsService: MoreDetailsService) { } /** * 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.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Loading MI rateplans'); this.sharedService.updateErrorMessage(null); this.sortByOptions = SORT_BY_OPTIONS; if (this.sortByOptions) { this.sortByKey = this.sortByOptions[0].key; } this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); this.sharedService.creditChoice.subscribe((val: string) => { this.creditType = val; this.updateActivePackage(); }); this.groupByCount = Utils.groupByProductCount(); this.cardsPerPage = Utils.totalCardsPerPage(); this.user = this.userService.getUser(); // getting current cart/customer this.customer = this.customerService.getCustomer(); this.cart = this.cartService.getCart(); // getting cart changes... this.subscription = this.cartService.hasUpdate.subscribe((item) => { if (item) { this.cart = this.cartService.getCart(); } this.updateActivePackage(); console.log('Cart got updated..'); // filter rateplans based on customer // if(this.cart && this.cart.customer) {this.filterByCustomer();} //DE 486033 }); // console.log('getting the master rateplans') // this.rateplans = this.catalogService.getMIRateplans(); if (!this.catalogService.getMIRateplans()) { console.log('MIRateplansComponent.ngOnInit()>>Getting the master rateplans.'); this.sharedService.initializeCatalog(); } console.log('getting the master rateplans') this.filters = this.catalogService.getMIRateplanFiletrs(); if (!this.filters) { console.log('MIRateplansComponent.ngOnInit()>>Getting the master rateplans.'); this.sharedService.initializeCatalog(); } else { this.resetRateplanFilters(); } // get active package this.updateActivePackage(); // filter rateplans based on customer this.filterByCustomer(); } /** * 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.rateplans = null; this.sortByOptions = null; this.sortedRateplans = null; this.filters = null; this.customer = null; this.cart = null; this.user = null; this.KarmaTestResult = null; this.package = null; this.individualPlanFilters = null; this.familyPlanFilters = null; this.subscription.unsubscribe(); this.creditProfile = null; this.allItems = null; this.pager = null; this.pagedItems = null; } /** * This function is used to update the package including package type, active package id, * active line id.Also getting the customer details including credit profile and credit types * @return void */ updateActivePackage(): void { const METHOD_NAME: string = 'updateActivePackage()'; // getting the active package from cart this.package = CartUtils.getActivePackage(this.cart, this.packageType); if (!this.package) { // if there are no active voice package avaible, select first one. this.package = CartUtils.getFirstPackage(this.cart, this.packageType); if (this.package) { this.cart.activePackageId = this.package.packageId; this.cart.activeLineId = this.package.lineId; } } // initilizing local veriables this.isFinanceOrder = CartUtils.isFinanceOrder(this.cart); this.isNCFPlanInCart = CartUtils.isNCFPlanInCart(this.cart); this.isTIPlanInCart = CartUtils.isTIPlanInCart(this.cart); this.isPooledPlanInCart = CartUtils.isPooledPlanInCart(this.cart); this.numberOfVoiceLines = CartUtils.numberOfVoiceLines(this.cart, this.customer); // getting the customer; if (!this.customer && this.cart && this.cart.customer) { this.customer = this.cart.customer; } if (this.customer && this.customer.creditProfile) { this.creditProfile = this.customer.creditProfile; if (this.customer.creditType) { if (this.customer.creditType === Constants.NOCREDIT_CHECK) { this.creditType = Constants.NOCREDIT_CHECK; } else if (this.customer.creditType === Constants.AWESOME_CREDIT || this.customer.creditType === Constants.CREDIT_CHECK) { this.creditType = Constants.CREDIT_CHECK; } } } if (this.creditProfile && this.creditProfile.accountNumber) { this.isTIPlanInAccount = CartUtils.isTIPlanInAccount(this.customer); this.isPooledPlanInAccount = CartUtils.isPooledPlanInAccount(this.customer); if ((this.creditProfile.maxDataLines - this.creditProfile.activeDataLines) <= 0) { this.disableAddToCart = true; this.sharedService.showErrorMessage('_ERR_MAX_LINE_LIMIT_EXCEEDED_ACCOUNT', false); } if (this.creditProfile.accountNumber && !CartUtils.hasSubscribersInAccount(this.customer)) { this.disableAddToCart = true; this.sharedService.showErrorMessage('_ERR_SUBSCRIBERS_EMPTY', false); } // checking the enable/diable add to cart button for aal path if (this.creditProfile.taxTreatment === Constants.MIXED_TAX_TREATMENT || this.creditProfile.isDelinquent || this.creditProfile.effectiveDate || (this.creditProfile.accountType === Constants.ACCOUNT_TYPE_I && this.creditProfile.accountSubType === Constants.ACCOUNT_SUB_TYPE_S)) { this.disableAddToCart = true; if ((this.creditProfile.accountType === Constants.ACCOUNT_TYPE_I && this.creditProfile.accountSubType === Constants.ACCOUNT_SUB_TYPE_S) ) { this.sharedService.showErrorMessage('_ERR_SOLE_PROPRIETOR', false); } else if (this.creditProfile.isDelinquent) { this.sharedService.showErrorMessage('_ERR_DELINQUENT_CUSTOMER', false); } else if (this.creditProfile.taxTreatment === Constants.MIXED_TAX_TREATMENT || this.creditProfile.effectiveDate) { this.sharedService.showErrorMessage('_ERR_FUTURE_DATED_TAX_TREATMENT', false); } } } // applying the custom sorting this.applyCustomSorting(); } /** * This function is used to add rateplan to the cart through createRateplan function of cart service. * @param {IRateplan} rateplan - contains rateplan that has to be added to the cart. * @returns void */ addRateplan(rateplan: IRateplan): void { const METHOD_NAME: string = 'addRateplan()'; console.log('[start]- adding rateplan to cart.'); this.searchText = ''; // making sure there was cart in progress this.addItemPreprocess(rateplan); // adding product into cart/package if (this.cart && this.package) { // console.log('Adding a MI rateplan to cart...'); this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Adding a MI rateplan to cart:' + this.cart.orderId); const inputData: any = CartUtils.createRateplanInput(this.packageType, rateplan); this.sharedService.showSpinner(true); // spinner this.cartService.createRateplan(this.storeId, this.cart.orderId, this.package.packageId, this.package.lineId, inputData ).subscribe(result => { this.KarmaTestResult = result; this.sharedService.showSpinner(false); // spinner this.cart = CartUtils.replaceRequired(this.cart, result); this.cartService.setCart(this.cart); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } // console.log('[end]- adding rateplan to cart.'); } /** * This function is used to prepare the cart before adding the rateplan to cart * @param {IRateplan} rateplan - Object contains rateplan information * @return void */ addItemPreprocess(rateplan: IRateplan): void { const METHOD_NAME: string = 'addItemPreprocess()'; console.log('[start]- preprocess of adding item to cart.'); if (!this.cart) { // making sure there was cart in progress this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Creating a cart'); const inputData: any = CartUtils.createCartInput(this.storeId, this.user); this.sharedService.showSpinner(true); // spinner this.cartService.createCartDetails(this.storeId, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.cart = result; // calling back add to rateplan method again... this.addRateplan(rateplan); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); }else if(this.cart && !this.cart.customer && this.customer){ this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Associating the customer to cart:' + this.cart.orderId); //adding order notes if (this.customer.orderNotes) { this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, this.customer.orderNotes); this.customer.orderNotes = null; } this.customer.orderId = this.cart.orderId; this.sharedService.showSpinner(true); // spinner this.customerService.createCustomer(this.storeId, this.customer).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.cart.customer = Object.assign({}, this.customer); this.cart.customer.addressId = result.addressId; this.customer = null; this.customerService.setCustomer(null); this.cartService.setCart(this.cart); // calling back add to rateplan method again... this.addRateplan(rateplan); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); }else if (this.cart && !this.package) { // making sure there was an active package this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Creating a package to cart:' + this.cart.orderId); const inputData = CartUtils.createPackageInput(this.packageType, rateplan.selectedLines, null); this.sharedService.showSpinner(true); // spinner this.cartService.createPackageDetails(this.storeId, this.cart.orderId, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner const packages: IPackage[] = result; for (const pkg of packages) { pkg.packageType = this.packageType; } // setting active package#&line# this.package = packages[0]; this.cart = CartUtils.addPackage(this.cart, packages); this.cart.activePackageId = this.package.packageId; this.cart.activeLineId = this.package.lineId; this.cartService.setCart(this.cart); // calling back to add to rateplan again this.addRateplan(rateplan); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } // console.log('[end]- adding rateplan to cart.'); } /** * This function is used to update the rateplan to the cart through updateRateplan function of cart service. * @param {IRateplan} rateplan - Object contains rateplan information * @returns void */ updateRateplan(rateplan: IRateplan): void { const METHOD_NAME: string = 'updateRateplan()'; this.searchText = ''; this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Updating MI rateplan to cart:' + this.cart.orderId); if (this.cart && this.package && this.package.plan) { const inputData: any = CartUtils.createRateplanInput(this.packageType, rateplan); this.sharedService.showSpinner(true); // spinner this.cartService.updateRateplan( this.storeId, this.cart.orderId, this.package.packageId, this.package.lineId, this.package.plan.orderItemId, inputData ).subscribe(result => { this.KarmaTestResult = result; // this.sharedService.showSpinner(false);//spinner // this.cart = CartUtils.replaceRequired(this.cart, result); // this.cartService.setCart(this.cart); // console.log('Rateplan updated successfully.'); this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(getCartSummaryResult => { this.sharedService.showSpinner(false); // spinner this.cart = CartUtils.replaceRequired(this.cart, getCartSummaryResult); this.cartService.setCart(this.cart); // console.log('Rateplan updated successfully.'); }, error => { this.sharedService.showSpinner(false); // spinner console.error('error=>' + error); this.sharedService.showErrorMessage(error, true); }); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error) }); } } /** * This function is used to remove the rateplan from the cart through deleteRateplan function of cart service. * @param {IRateplan} rateplan - Object contains rateplan information * @returns void */ removeRateplan(rateplan: IRateplan): void { const METHOD_NAME: string = 'removeRateplan()'; this.searchText = ''; this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Removing MI rateplan from cart:' + this.cart.orderId); if (this.cart && this.package && this.package.plan) { this.sharedService.showSpinner(true); // spinner this.cartService.deleteRateplan( this.storeId, this.cart.orderId, this.package.packageId, this.package.lineId, this.package.plan.orderItemId ).subscribe(result => { this.KarmaTestResult = result; this.sharedService.showSpinner(false); // spinner this.cart = CartUtils.replaceRequired(this.cart, result); this.cartService.setCart(this.cart); // console.log('Rateplan deleted successfully.'); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error) }); } } /** * This function is used to sync the cart updates * @param {number} orderId - orderId of the user * @returns void */ syncCartUpdates(orderId: number): void { const METHOD_NAME: string = 'syncCartUpdates()'; this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, orderId).subscribe(result => { this.KarmaTestResult = result; this.sharedService.showSpinner(false); // spinner // making sure active package/line shouldn't be remove let cart: Cart = result; if (cart && cart.packages) { const activePackageId = this.cart.activePackageId; const activeLineId = this.cart.activeLineId; if (activePackageId && activeLineId >= 0) { let activePackage: IPackage; cart.packages.forEach((item) => { if (item.packageId === activePackageId && item.lineId === activeLineId) { activePackage = item; } }); if (activePackage) { cart.activePackageId = activePackage.packageId; cart.activeLineId = activePackage.lineId; cart = CartUtils.updatePackage(cart, activePackage); } } this.cartService.setCart(cart); // updating the list this.applyCustomSorting(); } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } /** * This function is used to filter the rateplan based on customer's zipCode. * @returns void */ filterByCustomer(): void { const METHOD_NAME: string = 'filterByCustomer()'; if (this.disableAddToCart) { return; } // filter rateplans based on customer let zipCode: string = Constants.DEFAULT_ZIP_CODE; if (this.customer || (this.cart && this.cart.customer)) { if (this.cart && this.cart.customer) { zipCode = this.cart.customer.zipCode ? this.cart.customer.zipCode : Constants.DEFAULT_ZIP_CODE; } else { zipCode = this.customer.zipCode ? this.customer.zipCode : Constants.DEFAULT_ZIP_CODE; } } let accountNumber: number = null; let accountType: string = null; let isNCFPlan: boolean = null; let isTIPlan: boolean = null; let hasDuplicateLines: boolean = null; if (this.cart || this.customer) { if (this.cart) { accountNumber = this.creditProfile ? this.creditProfile.accountNumber : null; accountType = this.creditProfile ? this.creditProfile.accountType : null; if (CartUtils.hasPlanInCart(this.cart)) { isNCFPlan = this.isNCFPlanInCart; isTIPlan = this.isTIPlanInCart; } } else if (this.customer) { accountNumber = this.creditProfile ? this.creditProfile.accountNumber : null; accountType = this.creditProfile ? this.creditProfile.accountType : null; isNCFPlan = this.customer.creditType && this.customer.creditType === 'NC' ? true : false; isTIPlan = this.isTIPlanInAccount; hasDuplicateLines = this.customer.existingDuplicateLines > 0 ? true : false; } } // calling rateplan filter this.sharedService.showSpinner(true); // spinner this.catalogService.getRateplansByZipCode( this.storeId, zipCode, null, // marketCode Constants.PRODUCT_TYPE_DATA, this.package && this.package.device ? this.package.device.deviceSKU : null, // deviceSKU, accountNumber, // accountNumber, accountType, // accountType, isNCFPlan, /**isNCFPlan*/ isTIPlan, /**isTIPlan*/ this.numberOfVoiceLines, hasDuplicateLines, this.customer && this.customer.creditProfile && this.customer.creditProfile.dateOfBirth ? this.customer.creditProfile.dateOfBirth : null, /**dateOfBirth*/ this.cart ? this.cart.orderId : null ).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (this.catalogService.getMIRateplans()) { this.rateplans = this.catalogService.getMIRateplans(); this.rateplans = this.rateplans.filter((product) => { return result.includes(product.productId); }); // resetting the filters; this.resetRateplanFilters(); // applying the custom sorting this.applyCustomSorting(); } }, error => { this.rateplans = null; this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } /** * This function is used to apply the custom sorting for rateplan items. * @return void */ applyCustomSorting(): void { const METHOD_NAME: string = 'applyCustomSorting()'; if (this.rateplans && this.rateplans.length > 0) { let sortedList = this.rateplans; // current cart related filter if (CartUtils.hasPlanInCart(this.cart)) { // isNCFPlan sortedList = sortedList.filter((product) => { return product.isNCFPlan === this.isNCFPlanInCart; }); // isTIPlanInCart sortedList = sortedList.filter((product) => { return product.isTaxInclusivePlan === this.isTIPlanInCart; }); // let isPooledPlanInCart = CartUtils.isPooledPlanInCart(this.cart); // //isPooledPlan // sortedList = sortedList.filter((product) => { // return product.isPooledPlan === isPooledPlanInCart; // }); } else { if (this.isFinanceOrder) { sortedList = sortedList.filter((product) => { return product.isNCFPlan === false; }); } // credit type filter sortedList = sortedList.filter((product) => { if (this.creditType === Constants.AWESOME_CREDIT || this.creditType === Constants.CREDIT_CHECK) { return (product.isNCFPlan === false); } else if (this.creditType === Constants.NOCREDIT_CHECK) { return product.isNCFPlan; } else { return true; } }); if (this.creditProfile && this.creditProfile.accountNumber) { // isTIPlanInAccount sortedList = sortedList.filter((product) => { return product.isTaxInclusivePlan === this.isTIPlanInAccount; // Customer is on a grandfathered plan and can only add a line to their existing plan. // To change plan,follow the plan migration process prior to adding a line. }); } } sortedList = Utils.serachFilter(sortedList, this.filters); sortedList = Utils.serachSortBy(sortedList, this.sortByKey); sortedList = Utils.serachProducts(sortedList, this.searchText); if (sortedList) { // support products with minimum line limit. if (this.rangeLineCount === 1) { this.allItems = sortedList; } else { this.allItems = sortedList.filter((product) => { return this.rangeLineCount <= product.maximumLines && this.rangeLineCount >= product.minimumLines; }); } } else { this.pager = {}; this.allItems = []; this.pagedItems = []; } // initialize to page 1 this.setPage(1); } } /** * This function is used to get the index for pagination * @param {number} page - variable contains the page number * @return void */ setPage(page: number): void { const METHOD_NAME: string = 'setPage()'; if (page < 1 || page > this.pager.totalPages) { return; } if (this.allItems && this.allItems.length > 0) { // get pager object from service this.pager = Utils.getPager(this.allItems.length, page, this.cardsPerPage); // get current page of items this.pagedItems = this.allItems.slice(this.pager.startIndex, this.pager.endIndex + 1); // grouping 3 products per row this.sortedRateplans = Utils.groupProducts(this.pagedItems, this.groupByCount); } else { this.sortedRateplans = null; } } /** * This function is used to create array for minMaxLines of rateplan. * @param {IRateplan} rateplan - Object contains rateplan information * @returns Array */ minMaxLineNumbers(rateplan: IRateplan): Array { const METHOD_NAME: string = 'minMaxLineNumbers()'; const minMaximum: Array = []; if (rateplan.isPooledPlan) { // rateplan.selectedLines = rateplan.minimumLines; for (let i = rateplan.minimumLines; i <= rateplan.maximumLines; i++) { minMaximum.push(i); } } return minMaximum; } /** * This function is used to calculate monthly price of a rateplan. * @param {IRateplan} rateplan - Object contains rateplan information * @returns number */ calculateMonthlyPrice(rateplan: IRateplan): number { const METHOD_NAME: string = 'calculateMonthlyPrice()'; let monthlyPrice: number = rateplan.monthlyPrice; let selectedLines: number = this.rangeLineCount < rateplan.selectedLines ? rateplan.selectedLines : this.rangeLineCount; if (selectedLines === rateplan.minimumLines) { monthlyPrice = rateplan.monthlyPrice; } else { let monthly = rateplan.monthlyPrice; if (selectedLines > rateplan.maximumLines) { selectedLines = rateplan.maximumLines; } for (let i = rateplan.minimumLines; i < selectedLines; i++) { monthly += rateplan.aalFee; // console.log(rateplan.monthlyPrice + ">>" + i + ">" + rateplan.aalFee); } monthlyPrice = monthly; } return monthlyPrice; } /** * This function is used to calculate discount for monthly price of a rateplan. * @param {IRateplan} rateplan - Object contains rateplan information * @returns number */ discountedMonthlyPrice(rateplan: IRateplan): number { const METHOD_NAME: string = 'discountedMonthlyPrice()'; let monthlyPrice: number = 0; if (rateplan.autoPayCreditAmount > 0) { let monthly = rateplan.monthlyPrice; let discount: number = 0; const selectedLines: number = this.rangeLineCount < rateplan.selectedLines ? rateplan.selectedLines : this.rangeLineCount; for (let i = rateplan.minimumLines; i < selectedLines; i++) { monthly += rateplan.aalFee; } if (selectedLines <= rateplan.autoPayCreditLines) { discount = rateplan.autoPayCreditAmount * selectedLines; } else { discount = rateplan.autoPayCreditAmount * rateplan.autoPayCreditLines; } monthlyPrice = monthly - discount; } return monthlyPrice; } /** * This function is used to get the status of button which is enabled/disabled. * @param {string} rateplanSOC - contains rateplanSOC of selected rateplan. * @returns string */ buttonState(rateplanSOC: string): string { const METHOD_NAME: string = 'buttonState()'; let state: string = Constants.BTN_DISABLE; if (!this.disableAddToCart) { state = Constants.BTN_ADD; if (this.cart && this.package && this.package.plan) { state = this.package.plan.rateplanSOC === rateplanSOC ? Constants.BTN_REMOVE : Constants.BTN_UPDATE; } } return state; } /** * This function is used to reset the applied rateplan filters. * @returns void */ resetRateplanFilters(): void { const METHOD_NAME: string = 'resetRateplanFilters()'; if (this.filters) { this.filters.forEach((element) => { if (element.type === Constants.RATEPLAN_GRP_NAME_IND) { this.individualPlanFilters = element.items; } if (element.type === Constants.RATEPLAN_GRP_NAME_FMY) { this.familyPlanFilters = element.items; } }); if (this.rateplans) { this.filters = new Array(); this.individualPlanFilters = Utils.matchFiltersProducts(this.individualPlanFilters, this.rateplans); if (this.individualPlanFilters) { this.filters.push( { type: Constants.RATEPLAN_GRP_NAME_IND, items: this.individualPlanFilters }); } this.familyPlanFilters = Utils.matchFiltersProducts(this.familyPlanFilters, this.rateplans); if (this.familyPlanFilters) { this.filters.push( { type: Constants.RATEPLAN_GRP_NAME_FMY, items: this.familyPlanFilters }); } } } } /** * This function determines whether any of the devices are selected or not. * @returns boolean */ atleastOneChecked(): boolean { const METHOD_NAME: string = 'atleastOneChecked()'; if (this.filters) { for (const filter of this.filters) { if (filter && filter.items) { for (const item of filter.items) { if (item.isChecked) { return true; } } } } } return false; } /** * This function is used to clear all the filters. * @returns void */ clearAllFilters(): void { const METHOD_NAME: string = 'clearAllFilters()'; for (const filter of this.filters) { for (const item of filter.items !== null && filter.items) { item.isChecked = false; } } if (this.sortByOptions) { this.sortByKey = this.sortByOptions[0].key; } this.searchText = ''; this.rangeLineCount = 1; // applying the custom sorting this.applyCustomSorting(); } /** * This function is used to get count for maximum lines of rateplan. * @returns number */ get maximumLineLimit(): number { const METHOD_NAME: string = 'maximumLineLimit()'; let maxLimit: number = 0; if (this.rateplans && this.rateplans.length > 0) { for (const product of this.rateplans) { if (maxLimit < product.maximumLines) { maxLimit = product.maximumLines; } } } return maxLimit; } /** * This function is used to display the additional details of particular rateplan. * @param {number} productId - productId of particular rateplan. */ expandDetails(productId: number) { const METHOD_NAME: string = 'expandDetails()'; if (this.expandedProductId && this.expandedProductId === productId) { this.expandedProductId = null; } else { this.expandedProductId = productId; } } sendMoreDetailsModalInfo(show: string, productItem: any){ this.moreDetailsService.product = productItem; this.moreDetailsService.setMessage(show); } }