/** * @Component Name: SummaryComponent * @Module: Checkout * @Module Functionality : To display the order summarysection * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnInit, OnChanges, Output, EventEmitter, OnDestroy} from '@angular/core'; import * as Constants from '../../../shared/constants' import CartUtils from '../../../shared/cart.utils'; import { IPackage } from '../../../shared/modal/common'; import { Cart } from '../../../shared/modal/cart'; import { SharedService } from '../../../shared/shared.service'; import { CartService } from '../../../services/cart.service'; @Component({ selector: 'compact-cmp', moduleId: module.id, templateUrl: 'compact.component.html', styleUrls: ['./compact.component.css'] }) export class CompactComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'CompactComponent'; storeId: number; refTypeExchange: string = Constants.REF_TYPE_EXCHANGE; cart: Cart; subscription: any; switchView: boolean = true; @Output() onViewChange = new EventEmitter(); rtStoreId: number = Constants.STORE_ID_RT; constructor(public sharedService: SharedService, 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.updateErrorMessage(null); this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); this.cart = this.cartService.getCart(); this.subscription = this.cartService.hasUpdate.subscribe((item) => { if (item) { this.cart = Object.assign(this.cart, this.cartService.getCart()); } }); } /** * 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.subscription.unsubscribe(); } /** * this function is used to calculate the total products due today. * @returns number */ get totalProductsDueToday(): number { return CartUtils.totalProductsDueToday(this.cart); } /** * this function is used to calculate the total service due monthly. * @returns number */ get totalServicesDueMonthly(): number { return CartUtils.totalServicesDueMonthly(this.cart); } /** * this function is used to calculate the total finance due monthly. * @returns number */ get totalFinancesDueMonthly(): number { return CartUtils.totalFinancesDueMonthly(this.cart); } /** * this function is used to calculate the total discount due monthly. * @returns number */ get totalDiscountsDueMonthly(): number { return CartUtils.totalDiscountsDueMonthly(this.cart, true); } /** * this function is used to calculate the total discounts due today. * @returns number */ get totalDiscountsDueToday(): number { return CartUtils.totalDiscountsDueToday(this.cart); } /** * this function is used to calculate the total deposit due today. * @returns number */ get totalDepositsDueToday(): number { return CartUtils.totalDepositsDueToday(this.cart); } /** * this function is used to calculate the total shipping due today. * @returns number */ get totalShippingDueToday(): number { return CartUtils.totalShippingDueToday(this.cart); } /** * this function is used to calculate the total tax due today. * @returns number */ get totalTaxDueToday(): number { return CartUtils.totalTaxDueToday(this.cart); } /** * this function is used to calculate the total due monthly. * @returns number */ get totalDueMonthly(): number { return CartUtils.totalDueMonthly(this.cart, true); } /** * this function is used to calculate the total due today. * @returns number */ get totalDueToday(): number { return CartUtils.totalDueToday(this.cart); } }