/** * @Component Name: RegularComponent * @Module: Home * @Module Functionality : To display the minicart * @Creation Date: October 18,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnInit, OnChanges, OnDestroy, ViewChild } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; // import { STATE_TAXES } from '../../../shared/form.constants'; import { ERROR_LIST } from '../../../shared/error.constants'; import { IKeyValue } from '../../../shared/modal/key.value'; import CartUtils from '../../../shared/cart.utils'; import * as Constants from '../../../shared/constants'; import { User } from '../../../shared/modal/user'; import { Cart } from '../../../shared/modal/cart'; import { Customer } from '../../../shared/modal/customer'; import { IPackage, IRateplan } from '../../../shared/modal/common'; import { SharedService } from '../../../shared/shared.service'; import { UserService } from '../../../services/user.service'; import { CustomerService } from '../../../services/customer.service'; import { CartService } from '../../../services/cart.service'; @Component({ moduleId: module.id, selector: 'regular-cmp', templateUrl: 'regular.component.html', styleUrls: ['regular.component.css'] }) export class RegularComponent implements OnInit, OnChanges, OnDestroy { private COMPONENT_NAME: string = 'RegularComponent'; storeId: number; // update storeid packageTypes: string[] = [ Constants.PACKAGE_TYPE_VOICE, Constants.PACKAGE_TYPE_DATA, Constants.PACKAGE_TYPE_PREPAID, Constants.PACKAGE_TYPE_ACCESSORY ]; refTypeExchange: string = Constants.REF_TYPE_EXCHANGE; maxVoiceLines: number = Constants.MAX_VOICE_LINES_DEFAULT; maxDataLines: number = Constants.MAX_DATA_LINES_DEFAULT; accLevelFeature: string = Constants.FEATURE_GRP_NAME_ACC; subLevelFeature: string = Constants.FEATURE_GRP_NAME_SUB; prodLevelFeature: string = Constants.FEATURE_GRP_NAME_PROD; taxRate: number = 0; expandPackage: boolean = false; user: User; customer: Customer; @Input() cart: Cart; deleteOption: boolean = false; coverageStatus: boolean = false; // added for pooled rateplan remove // @ViewChild('removeRateplanModel') removeRateplanModel: any; // tempRateplanOrderItemId: number; karmaTestResult: any = {}; rtStoreId: number = Constants.STORE_ID_RT; constructor( public router: Router, public sharedService: SharedService, public userService: UserService, public customerService: CustomerService, public cartService: CartService) { } /** * 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.sharedService.coverageStatus.subscribe((val: boolean) => { this.coverageStatus = val; }); this.user = this.userService.getUser(); this.customer = this.customerService.getCustomer(); } /** * This function is called whenever one or more data-bound input properties change * @returns void */ ngOnChanges(): void { const METHOD_NAME: string = 'ngOnChanges()'; if (this.cart && this.cart.refType === Constants.REF_TYPE_NEW) { console.log(`ngOnChanges - data is $ {this.cart}`); // if(CartUtils.hasTaxCalculated(this.cart)) { // this.cart.taxRate= CartUtils.getTaxRate(this.cart); // } } // else { // //if (!this.cart) this.cart.taxRate = 0; // } } /** * Cleanup just before Angular destroys the directive/component. * Unsubscribe Observables and detach event handlers to avoid memory leaks. */ ngOnDestroy() { const METHOD_NAME: string = 'ngOnDestroy()'; this.cart = null; this.customer = null; this.user = null; this.karmaTestResult = null; this.packageTypes = null; } get isFullCartPage(): boolean { const METHOD_NAME: string = 'isFullCartPage()'; if (window.location.pathname.indexOf('fullcart') > -1) { return true; } return false; } /** * This function is used to display current finance type. * @param {string} financeType - contains Loan or Lease type of finance */ getDisplayFinanceType(financeType: string) { const METHOD_NAME: string = 'getDisplayFinanceType()'; if (financeType && financeType === Constants.FINANCE_TYPE_LOAN) { return '-EIP'; } else if (financeType && financeType === Constants.FINANCE_TYPE_LEASE) { return '-JOD'; } return 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.packageType === type) }); } /** * This function is used to update the active package to the cart. * active line id. * @param {number} packageId - contains active packageId. * @param {number} lineId - contains active lineId. * @returns void */ activePackage(packageId: number, lineId: number): void { const METHOD_NAME: string = 'activePackage()'; this.cart.activePackageId = packageId; this.cart.activeLineId = lineId; this.cartService.setCart(this.cart); } /** * This function is used to determine if package added to cart is valid. * @param {IPackage} packge - contains package information * @returns boolean - if package is valid. */ isValidPackage(packge: IPackage): boolean { const METHOD_NAME: string = 'isValidPackage()'; if (packge && packge.packageType) { if (packge.packageType === Constants.PACKAGE_TYPE_VOICE || packge.packageType === Constants.PACKAGE_TYPE_DATA) { return (!packge.plan || !packge.device); } else if (packge.packageType === Constants.PACKAGE_TYPE_PREPAID) { return (!packge.device); } if (packge.packageType === Constants.PACKAGE_TYPE_ACCESSORY) { return (!packge.accessories); } } return true; } showEca(): boolean { let showDeviceEca = false; if (this.cart && this.cart.packages) { this.cart.packages.forEach((item) => { if (item.packageId === this.cart.activePackageId && item.device && (item.device.financeType === 'LOAN' || item.device.financeType === 'LEASE')) { showDeviceEca = true; } }); } return showDeviceEca; } /** * This function is used to get customer's voice and data lines. * @returns void */ getCustomerMaxMin(): void { const METHOD_NAME: string = 'getCustomerMaxMin()'; const customer = (!this.cart) ? this.customerService.getCustomer() : this.cart.customer; if (customer && customer.creditProfile) { if (customer.creditProfile.maxVoiceLines >= 0) { this.maxVoiceLines = (customer.creditProfile.maxVoiceLines - customer.creditProfile.activeVoiceLines); } if (customer.creditProfile.maxDataLines >= 0) { this.maxDataLines = (customer.creditProfile.maxDataLines - customer.creditProfile.activeDataLines); } } else { this.maxVoiceLines = Constants.MAX_VOICE_LINES_DEFAULT; this.maxDataLines = Constants.MAX_DATA_LINES_DEFAULT; } } get inCartVoiceCount(): number { const METHOD_NAME: string = 'inCartVoiceCount()'; this.getCustomerMaxMin(); return CartUtils.voicePackageCount(this.cart); } get inCartDataCount(): number { const METHOD_NAME: string = 'inCartDataCount()'; return CartUtils.miPackageCount(this.cart); } /** * this function is used to calculate the due monthly. * @returns number */ get totalDueMonthly(): number { const METHOD_NAME: string = 'totalDueMonthly()'; return CartUtils.totalDueMonthly(this.cart, true); } /** * this function is used to calculate the estimated today. * @returns number */ get totalProductsDueToday(): number { const METHOD_NAME: string = 'totalProductsDueToday()'; return CartUtils.totalProductsDueToday(this.cart); } /** * this function is used to calculate the estimated tax. * @returns number */ get estTotalTaxDueToday(): number { const METHOD_NAME: string = 'estTotalTaxDueToday()'; return (this.cart) ? CartUtils.estTotalTaxDueToday(this.cart, this.cart.taxRate) : 0; } /** * this function is used to calculate the estimated total due today. * @returns number */ get estTotalDueToday(): number { const METHOD_NAME: string = 'estTotalDueToday()'; return CartUtils.estTotalDueToday(this.cart); } /** * This function is used to add a package to the cart through createcartDetails function of cart service. * @param {string} packageType - type of package */ addAPackage(packageType: string) { const METHOD_NAME: string = 'addAPackage()'; if (this.cart) { this.createAPackage(this.cart.orderId, packageType); } else { console.log('Creating a cart for save the customer data.'); this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Creating a cart'); const cartInputData: any = CartUtils.createCartInput(this.storeId, this.user); this.sharedService.showSpinner(true); // spinner this.cartService.createCartDetails(this.storeId, cartInputData).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner const cart: Cart = result; this.cartService.setCart(cart); this.createAPackage(cart.orderId, packageType); }, error => { this.sharedService.showSpinner(false); // spinner console.error('error=>' + error); this.sharedService.showErrorMessage(error, true); }); } } /** * This function is used to delete a package from the cart through deletePackageDetails function of cart service. * @param {string} packageType - type of package * @param {number} packgeId - packageId of the package. * @param {number} lineId - lineId of the package. */ deletePackage(packageType: string, packgeId: number, lineId: number) { const METHOD_NAME: string = 'deletePackage()'; if (this.cart) { this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Deleting a package from cart:' + this.cart.orderId); this.sharedService.showSpinner(true); // spinner this.cartService.deletePackageDetails(this.storeId, this.cart.orderId, packgeId, lineId).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner // sync cart updates this.updateCartSummary(this.cart.orderId); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } } /** * This function is used to create a package through createPackageDetails function of cart service. * @param {number} orderId - orderId of the user * @param {string} packageType - type of package * @returns void */ createAPackage(orderId: number, packageType: string): void { const METHOD_NAME: string = 'createAPackage()'; let inCartCount: number = 0; let maxAllowedCount: number = 0; if (packageType === Constants.PACKAGE_TYPE_VOICE) { maxAllowedCount = Constants.MAX_VOICE_LINES_DEFAULT; inCartCount = CartUtils.voicePackageCount(this.cart); if (this.cart && this.cart.customer) { maxAllowedCount = CartUtils.getMaxVoiceLines(this.cart.customer); } } else if (packageType === Constants.PACKAGE_TYPE_DATA) { maxAllowedCount = Constants.MAX_DATA_LINES_DEFAULT; inCartCount = CartUtils.miPackageCount(this.cart); if (this.cart && this.cart.customer) { maxAllowedCount = CartUtils.getMaxDataLines(this.cart.customer); } } else if (packageType === Constants.PACKAGE_TYPE_ACCESSORY) { inCartCount = CartUtils.accessoryPackageCount(this.cart); maxAllowedCount = Constants.MAX_ACC_LINES_DEFAULT; } if (inCartCount < maxAllowedCount) { const packagee: IPackage = CartUtils.getFirstPackage(this.cart, packageType); let packageId: number = null; let isPooled: boolean = false; if (packagee && packagee.plan && packagee.plan.isPooledPlan) { packageId = packagee.packageId; isPooled = true; } const inputData = CartUtils.createPackageInput(packageType, 1, packageId); inputData.isPooled = isPooled; this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Creating a package to cart:' + orderId); this.sharedService.showSpinner(true); // spinner this.cartService.createPackageDetails(this.storeId, orderId, inputData).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner const packages: IPackage[] = result; for (const pkg of packages) { if (isPooled === true) { pkg.plan = packagee.plan; } pkg.packageType = packageType; } this.cart = CartUtils.addPackage(this.cart, packages); if (isPooled) { this.updateCartSummary(this.cart.orderId); } this.activePackage(packages[0].packageId, packages[0].lineId); this.cartService.setCart(this.cart); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } else { this.sharedService.showErrorMessage('_ERR_NOT_ELIGIBLE', false); } } /** * This function helps in copying of packages in the cart. * @returns void */ copyPackage(): void { const METHOD_NAME: string = 'copyPackage()'; const packge: IPackage = CartUtils.getCurrentPackage(this.cart); if (packge) { if (packge.packageType !== Constants.PACKAGE_TYPE_ACCESSORY) { this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Copying a package to cart:' + this.cart.orderId); this.sharedService.showSpinner(true); // spinner this.cartService.copyPackage( this.storeId, this.cart.orderId, packge.packageId, packge.lineId, { packageType: packge.packageType } ).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner // let packages: IPackage[] = [result]; // this.cart = CartUtils.addPackage(this.cart, packages); // this.cartService.setCart(this.cart); // sync cart updates this.updateCartSummary(this.cart.orderId); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } else { this.sharedService.showErrorMessage('_ERR_ACCESSORY_COPY', false); } } else { this.sharedService.showErrorMessage('_ERR_NO_ACTIVE_PACKAGE_TO_COPY', false); } } /** * This function is used to delete rateplan from the cart using deleteRateplan function of cart service. * @param {number} orderItemId - contains orderItemId of the package. * @returns void */ deleteRateplan(orderItemId: number): void { const METHOD_NAME: string = 'deleteRateplan()'; if (orderItemId) { this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Deleting rateplan from cart:' + this.cart.orderId); this.sharedService.showSpinner(true); // spinner this.cartService.deleteRateplan( this.storeId, this.cart.orderId, this.cart.activePackageId, this.cart.activeLineId, orderItemId ).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); }); } } /** * This function is used to delete device from the cart using deleteDevice function of cart service. * @param {number} packageId - contains packageId of package * @param {number} lineId - contains lineId of package * @param {number} orderItemId - contains orderItemId of package * @returns void */ deleteDevice(packageId: number, lineId: number, orderItemId: number): void { const METHOD_NAME: string = 'deleteDevice()'; if (orderItemId) { this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Deleting device from cart:' + this.cart.orderId); this.sharedService.showSpinner(true); // spinner this.cartService.deleteDevice( this.storeId, this.cart.orderId, packageId, lineId, orderItemId ).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner // this.tempRateplanOrderItemId = null; this.cart = CartUtils.replaceRequired(this.cart, result); this.cartService.setCart(this.cart); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } } /** * This function is used to show the popup of deleted rateplan. * @param {number} orderItemId - contains orderItemId of package * @returns void */ showRemoveRateplanModel(orderItemId: number): void { // this.tempRateplanOrderItemId = orderItemId; // this.removeRateplanModel.show(); } /** * This function is used to delete feature from the cart using deleteFeature function of cart service. * @param {number} orderItemId - contains orderItemId of package * @returns void */ deleteFeature(orderItemId: number): void { const METHOD_NAME: string = 'deleteFeature()'; if (orderItemId) { this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Deleting feature from cart:' + this.cart.orderId); this.sharedService.showSpinner(true); // spinner this.cartService.deleteFeature( this.storeId, this.cart.orderId, this.cart.activePackageId, this.cart.activeLineId, orderItemId ).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); }); } } /** * This function is used to delete accessory from the cart using deleteAccessory function of cart service. * @param {number} orderItemId - contains orderItemId of package * @returns void */ deleteAccessory(orderItemId: number): void { const METHOD_NAME: string = 'deleteAccessory()'; if (orderItemId) { this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Deleting accessory from cart:' + this.cart.orderId); this.sharedService.showSpinner(true); // spinner this.cartService.deleteAccessory( this.storeId, this.cart.orderId, this.cart.activePackageId, this.cart.activeLineId, orderItemId ).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); }); } } /** * This function used to synchronously update the changes to the cart through getCartSummary function of cart service. * @param {number} orderId - contains orderItemId of package * @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) { 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); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } /** * This function used to update the changes to the cart through getCartSummary function of cart service. * @param {number} orderId - orderId of the user. * @returns void */ updateCartSummary(orderId: number): void { const METHOD_NAME: string = 'updateCartSummary()'; // clearing order details from local storage this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, orderId).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner this.cart = CartUtils.replaceRequired(this.cart, result); if(result.packages){ this.activePackage(result.packages[(result.packages).length - 1].packageId, result.packages[(result.packages).length - 1].lineId); } this.cartService.setCart(this.cart); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } /** * @param {number} orderId - orderId of the user * @returns void */ convertFullPrice(orderId: number): void { const METHOD_NAME: string = 'convertFullPrice()'; this.sharedService.showSpinner(true); // spinner this.cartService.convertFullPrice(this.storeId, orderId, {}).subscribe(result => { this.karmaTestResult = result; // this.sharedService.showSpinner(false);//spinner // this.sharedService.showSpinner(true);//spinner // tslint:disable-next-line:no-shadowed-variable this.cartService.getCartSummary(this.storeId, orderId).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner this.cart = CartUtils.replaceRequired(this.cart, result); this.cartService.setCart(this.cart); this.sharedService.showErrorMessage('_ERR_EIP_ESTIMATE_ERROR', false); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } /** * This function is used to checkout the existing cart. * @returns void */ checkoutNow(): void { const METHOD_NAME: string = 'checkoutNow()'; if (this.cart && this.cart.packages) { this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Checkout from mini cart:' + this.cart.orderId); if (this.sharedService.getTradeInValidate()) { let reqParams: any = { validateCreditCheck:true }; if(this.storeId == Constants.STORE_ID_RT) { reqParams.validateCreditCheck = false; } this.sharedService.showSpinner(true); // spinner this.cartService.validateCart(this.storeId, this.cart.orderId, reqParams).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner if (result.readyForCheckout) { // clearing order details from local storage this.sharedService.showSpinner(true); // spinner let inputData: any = { actions: 'SYNCELIGIBLEDISCOUNTS' }; const isFinanceOrder: boolean = CartUtils.isFinanceOrder(this.cart); if (!this.customer && this.cart && this.cart.customer){ this.customer = this.cart.customer; } if (isFinanceOrder && this.customer && this.customer.creditProfile && this.customer.creditProfile.creditClass) { inputData = {actions: 'SYNCELIGIBLEDISCOUNTS,EIPESTIMATE'}; } // tslint:disable-next-line:no-shadowed-variable this.cartService.calculate(this.storeId, this.cart.orderId, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner const hostName = window.location.hostname; if (!isFinanceOrder || (hostName != null && hostName.includes('training')) || (inputData && inputData.actions && inputData.actions === 'SYNCELIGIBLEDISCOUNTS')) { if(this.storeId === Constants.STORE_ID_RT) { this.router.navigate(['estimate']); } else { this.router.navigate(['checkout']); } } else { const output: any = result.output; if (output && output['EIPESTIMATE.status'] === Constants.EIP_ESTIMATE_STATUS) { if(this.storeId === Constants.STORE_ID_RT) { this.router.navigate(['estimate']); } else { this.router.navigate(['checkout']); } } else { this.sharedService.showErrorMessage('_ERR_EIP_ESTIMATE_ERROR', false); this.convertFullPrice(this.cart.orderId); } } }, error => { const hostName = window.location.hostname; if (!isFinanceOrder || (hostName != null && hostName.includes('training'))) { if (this.storeId === Constants.STORE_ID_RT) { this.router.navigate(['estimate']); } else { this.router.navigate(['checkout']); } } this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } else { const errorMessages: any = ERROR_LIST.filter((errorCode) => { return errorCode.key === result.failureReason; }); if (errorMessages && errorMessages.length > 0) { this.sharedService.showErrorMessage(errorMessages[0].key, false); } else { this.sharedService.showErrorMessage('_ERR_INVAID_CART', false); } } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } else { this.sharedService.showErrorMessage('_ERR_SERACH_QUATION_TRADEIN', false); } } else { this.sharedService.showErrorMessage('_ERR_INVAID_CART', false); } } /** This function is used to restrict user from navigating to shopping cart if cart is empty. * @returns void */ showShoppingCart(): void { const METHOD_NAME: string = 'showShoppingCart()'; if (this.cart) { this.router.navigate(['/home/fullcart']); } else { this.sharedService.showErrorMessage('_ERR_EMPTY_CART', false); } } /** * 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 disable the checkout or send estimate button in case of invalid or empty cart * @returns Boolean */ checkInvalidPackage(){ let inValid = false; // Checking whether credit check or BAN Lookup done let isCreditChecked = this.cart && this.cart.customer && this.cart.customer.creditProfile && (this.cart.customer.creditProfile.accountNumber || (this.cart.customer.creditType && this.cart.customer.creditProfile.creditClass)); let isAccessoryOnlyPackage: boolean = false; if(this.cart && this.cart.packages){ let packages = this.cart.packages; // Checking whether the cart contains only accessory packages or not isAccessoryOnlyPackage = (packages.filter((eachPackage)=>{ return eachPackage.packageType === 'accessory'; })).length === this.cart.packages.length; let inValidPackage = packages.filter((packagee) => { if(packagee.packageType != 'accessory'){ return (!packagee.plan || !packagee.device) } else{ if(packagee.accessories) { packagee.accessories.filter((acc) => { return (!acc.accessorySKU) }); } else { return true; } } }); inValid = ((inValidPackage && inValidPackage.length) !==0) ? true : false; } else { inValid = true; } // If the cart contains only accessory packages , bypassing the credit check validation return isAccessoryOnlyPackage ? inValid : isCreditChecked ? inValid : true; } }