/** * @Component Name: OrderInfoComponent * @Module: Home * @Module Functionality : To display the order information section * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnInit, OnChanges, OnDestroy } from '@angular/core'; import * as Constants from '../../../../shared/constants'; import CartUtils from '../../../../shared/cart.utils'; import { ORDER_STATUS, STORES, ORDER_REFTYPE } from '../../../../shared/form.constants' import { Cart } from '../../../../shared/modal/cart'; import { Customer } from '../../../../shared/modal/customer'; import { SharedService } from '../../../../shared/shared.service'; @Component({ selector: 'order-info-cmp', moduleId: module.id, templateUrl: 'order-info.component.html', styleUrls: ['order-info.component.css'] }) export class OrderInfoComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'OrderInfoComponent'; orderStatusItems: any[]; orderStoresItems: any[]; @Input() cart: Cart; customer: Customer; showOrderInfo: boolean = true; refTypeCredit: string = Constants.REF_TYPE_CREDIT; financeType: string = Constants.FINANCE_TYPE_FRP; dormanProperties: any; storeId: number; rtStoreId: number = Constants.STORE_ID_RT; constructor(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.orderStatusItems = ORDER_STATUS.filter(orderStatusItem => orderStatusItem); this.orderStoresItems = STORES.filter(orderStoreItem => orderStoreItem); this.sharedService.storeId.subscribe((val: number) => {this.storeId = val;}); if (this.cart && this.cart.customer) { this.customer = this.cart.customer; } this.financeType = this.getFinanceType(); this.dormanProperties = this.sharedService.getDormantProperties(); } /** * 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.customer = null; this.orderStatusItems = null; this.orderStoresItems = null; } /** * This function is used to get the value of status label from key value pair * @param {string} status - key/shorthand notation of the order status. * @returns string */ getStatusLabel(status: string): string { const METHOD_NAME: string = 'getStatusLabel()'; let statusLabel: string = Constants.NOT_FOUND; if (status) { if (Number(this.cart.storeId) === this.rtStoreId && this.cart.status === Constants.ORDER_STATUS_C) { statusLabel = Constants.PURCHASE_EST_SENT; } else { for (const item of this.orderStatusItems) { if (item.key.toUpperCase() === status.toUpperCase()) { statusLabel = item.value; } } } } return statusLabel; } /** * This function is used to get channel label from order stores object. * @param {number} storeId * @returns string */ getChannelLabel(storeId: number): string { const METHOD_NAME: string = 'getChannelLabel()'; for (const item of this.orderStoresItems) { if (item.key === storeId) { return item.value; } } return Constants.NOT_FOUND; } /** * This function is used to get the value of ref type label from key value pair. * @param {string} refType - order reference type. * @returns string */ getRefType(refType: string): string { const METHOD_NAME: string = 'getRefType()'; for (const item of ORDER_REFTYPE) { if (item.key === refType) { return item.value; } } return Constants.NOT_FOUND; } getFinanceType(): string { let financeType: string = Constants.FINANCE_TYPE_FRP; if (this.cart && this.cart.packages) { for (const item of this.cart.packages) { if (item.device && item.device.financeType && (item.device.financeType === Constants.FINANCE_TYPE_LOAN || item.device.financeType === Constants.FINANCE_TYPE_LEASE)) { financeType = item.device.financeType; break; } if (item.accessories) { for (const accessory of item.accessories) { if (accessory.financeType && (accessory.financeType === Constants.FINANCE_TYPE_LOAN || accessory.financeType === Constants.FINANCE_TYPE_LEASE)) { financeType = accessory.financeType; break; } } } } } return financeType; } get includeAutoPay(): boolean{ if((this.customer && this.customer.creditProfile && this.customer.creditProfile.autoPayIndicator) || (this.cart && this.cart.customer && this.cart.customer.creditProfile && this.cart.customer.creditProfile.autoPayIndicator) || (this.storeId == this.rtStoreId) ){ return true; } return false; } /** * this function is used to calculate the total due monthly. * @returns number */ get totalDueMonthly(): number { if ((this.storeId == this.rtStoreId) || (this.customer && this.customer.creditProfile && this.customer.creditProfile.autoPayIndicator)) { return CartUtils.totalDueMonthly(this.cart, true); } else { return CartUtils.totalDueMonthly(this.cart, false); } } /** * this function is used to calculate the total discount due monthly. * @returns number */ get totalDiscountsDueMonthly(): number { return CartUtils.totalDiscountsDueMonthly(this.cart, false); } /** * this function is used to calculate the total discounts due today. * @returns number */ get totalDiscountsDueToday(): number { return CartUtils.totalDiscountsDueToday(this.cart); } }