/** * @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, 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: 'summary-cmp', moduleId: module.id, templateUrl: 'summary.component.html', styleUrls: ['./summary.component.css'] }) export class SummaryComponent implements OnInit, OnChanges, OnDestroy { private COMPONENT_NAME: string = 'SummaryComponent'; errorMessage: string; refTypeExchange: string = Constants.REF_TYPE_EXCHANGE; showSummary: boolean = true; showSpinner: boolean = false; @Input() cart: any; @Input() enrollAutopay: boolean = false; storeId: number; returnCart: Cart; isEIPOnlyOrder: boolean = false; 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. * @return {void} */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; this.isEIPOnlyOrder = CartUtils.isEIPOnlyOrder(this.cart); } /** * This function is called whenever one or more data-bound input properties change * @return {void} */ ngOnChanges(): void { const METHOD_NAME: string = 'ngOnChanges()'; // this.sharedService.storeId.subscribe((val: number) => { // this.storeId = val; // }); // if(this.cart && this.cart.refType == Constants.REF_TYPE_EXCHANGE && this.cart.relatedOrderId) { // this.sharedService.showSpinner(true);//spinner // this.cartService.getCartSummary(this.storeId, this.cart.relatedOrderId).subscribe(result => { // this.sharedService.showSpinner(false);//spinner // this.returnCart = result; // }, error => { // this.sharedService.showSpinner(false);//spinner // this.sharedService.showErrorMessage(error, null); // console.error('error=>' + error) // }); // } } /** * 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.returnCart = null; } /** * 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 { if ((this.cart && this.cart.enrollAutopay) || this.enrollAutopay) { return CartUtils.totalDiscountsDueMonthly(this.cart, true); } else { 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); } /** * 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 { if ((this.cart && this.cart.enrollAutopay) || this.enrollAutopay) { return CartUtils.totalDueMonthly(this.cart, true); } else { return CartUtils.totalDueMonthly(this.cart, false); } } /** * this function is used to calculate the total due today. * @returns number */ get totalDueToday(): number { return CartUtils.totalDueToday(this.cart); } }