/** * @Component Name: OrderDetailComponent * @Module: Home * @Module Functionality : To display the order details * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, ChangeDetectionStrategy, Input, OnInit, ViewChild, OnDestroy, AfterViewInit } from '@angular/core'; import { Router } from '@angular/router'; import * as Constants from '../../../shared/constants'; import { User } from '../../../shared/modal/user'; import { Cart } from '../../../shared/modal/cart'; import { Customer, ICreditProfile } from '../../../shared/modal/customer'; import * as FormConstants from '../../../shared/form.constants'; import { SharedService } from '../../../shared/shared.service'; import { LookupService } from '../../../services/lookup.service'; import { CartService } from '../../../services/cart.service'; import { UserService } from '../../../services/user.service'; import { CustomerService } from '../../../services/customer.service'; import { IOrderList, IOrder, IPayment, IShipping, IPromotion, IFinance, IDormantProperties } from '../../../shared/modal/common'; import { IfObservable } from 'rxjs/observable/IfObservable'; import { error } from 'protractor'; declare var $: any; @Component({ selector: 'order-detail-cmp', moduleId: module.id, templateUrl: 'order-detail.component.html', styleUrls: ['order-detail.component.css'], // changeDetection: ChangeDetectionStrategy.OnPush }) export class OrderDetailComponent implements OnInit, OnDestroy, AfterViewInit { private COMPONENT_NAME: string = 'OrderDetailComponent'; showOrderPromoResponse: IPromotion[]; showOrderFinanceComponent: IFinance; showOrderShippingData: IShipping; showOrderPaymentResponse: IPayment; orderStatusItems: any[]; user: User; cart: Cart = new Cart(); @ViewChild('conflictModel') conflictModel: any; @ViewChild('manualReviewModel') manualReviewModel: any; @ViewChild('releaseBlockModel') releaseBlockModel: any; @ViewChild('authenticateModel') authenticateModel: any; storeId: number; // update storeid orderList: IOrderList; customer: Customer; associatedOrders: any; creditProfile: ICreditProfile; identifierType: string = 'SSN'; identifier: string; forwardTo: string = 'fullcart'; canResumeOrder: boolean = false; canReleaseOrder: boolean = false; manualReviewOrder: boolean = false; isDashOrder: boolean = true; isCreditOrder: boolean = false; isReturnOrder: boolean = false; isBlindOrder: boolean = false; isBYOSOrder: boolean = false; orderNotesCount: number; canRedirectToPayReview: boolean = false; dormanProperties: IDormantProperties; rtStoreId: number = Constants.STORE_ID_RT; rtStoreIdStr: string = Constants.STORE_ID_RT_STR; disableResumeButton: boolean = false; isOrderNotesVisible: boolean = false; constructor( public router: Router, public sharedService: SharedService, public lookupService: LookupService, public userService: UserService, public cartService: CartService, public customerService: CustomerService) { } /** * 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.dormanProperties = this.sharedService.getDormantProperties(); // Start-Switch Channel-Store id update this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); // End-Switch Channel-Store id update this.user = this.userService.getUser(); this.cart = this.lookupService.getOrder(); this.orderList = this.lookupService.getOrderList(); // this.customer = this.customerService.getCustomer(); if (this.cart && this.cart.fullOrderId) { this.isCreditOrder = false; this.isBlindOrder = false; const orderId: number = Number(this.cart.orderId); this.isDashOrder = this.cart.isDashOrder ? true : false; this.isBYOSOrder = this.cart.isBYOSOrder ? true : false; if (this.cart.refType && this.cart.refType === Constants.BLIND_ORDER_REF) { this.isBlindOrder = true; } if (this.cart.refType && this.cart.refType === Constants.REF_TYPE_CREDIT) { this.isReturnOrder = true; } if (!this.cart.customer) { console.log('Order# for shipping details:' + orderId); this.showOrderCustomer(orderId) } else { this.customer = this.cart.customer; } if (!this.isCreditOrder && !this.cart.shippingInfo && !this.isBlindOrder) { console.log('Order# for shipping details:' + orderId); this.showOrderShipping(orderId); } if (!this.isCreditOrder && !this.cart.financeInfo && !this.isBlindOrder) { console.log('Order# for finance details:' + orderId); this.showOrderFinance(orderId); } // added additional check to skip if there is only ccAuthCounter if (!this.cart.paymentInfo || (this.cart.paymentInfo && !this.cart.paymentInfo.paymentMethod)) { console.log('Order# for payment details:' + orderId); this.showOrderPayment(orderId); } if (!this.isCreditOrder && !this.cart.promotionInfo && !this.isBlindOrder) { console.log('Order# for promo details:' + orderId); this.showOrderPromo(orderId); } if (!this.associatedOrders) { console.log('Order# for assosiated order details:' + orderId); this.showAssociatedOrders(orderId); } //Disabling Resume Button for Home Internet if(this.cart && this.cart.isHomeInternetOrder && this.user.permissions.canAccessHomeInternet == false && Number(this.cart.storeId) == this.storeId){ this.disableResumeButton = true; } if (Number(this.cart.storeId) !== this.storeId) { this.sharedService.showErrorMessage('_ERR_SWITCH_CHANNEL', false); } else if (this.cart.isDashOrder) { this.canResumeOrder = false; this.canReleaseOrder = false; this.manualReviewOrder = false; if (this.cart.status === Constants.ORDER_STATUS_P || this.cart.status === Constants.ORDER_STATUS_P20) { if (this.cart.status === Constants.ORDER_STATUS_P20) { this.canRedirectToPayReview = true; } this.canResumeOrder = true; } else if (this.cart.status === Constants.ORDER_STATUS_P1) { if (this.user.permissions.canManualReview) { this.manualReviewOrder = true }; } else if (this.cart.status === Constants.ORDER_STATUS_P2 || this.cart.status === Constants.ORDER_STATUS_P3 || this.cart.status === Constants.ORDER_STATUS_P4 || this.cart.status === Constants.ORDER_STATUS_P5 || this.cart.status === Constants.ORDER_STATUS_P8) { if (this.cart.status === Constants.ORDER_STATUS_P2 || this.cart.status === Constants.ORDER_STATUS_P3 || this.cart.status === Constants.ORDER_STATUS_P5) { this.canRedirectToPayReview = true; } if (this.cart.status === Constants.ORDER_STATUS_P2) { if (this.user.permissions.canRiskReview) { this.canReleaseOrder = true; } } else { this.canReleaseOrder = true; } } } } this.addOrderDetailsNote(); this.lookupService.getOrderNotes(this.storeId, this.cart.orderId).subscribe(result => { this.orderNotesCount = result.orderNotesCount; this.isOrderNotesVisible = this.orderNotesCount > 0 ? true : false; this.lookupService.setOrderNotesIndicatorData({ totalNonFootprintOrderNotes: this.orderNotesCount, isOrderNotesVisible: this.isOrderNotesVisible}); }, error => { console.error('error=>' + error); }); } /** * Cleanup just before Angular destroys the directive/component. * Unsubscribe Observables and detach event handlers to avoid memory leaks. */ ngOnDestroy(): void { const METHOD_NAME: string = 'ngOnDestroy()'; this.sharedService.tradeInValidate = []; this.cart = null; this.showOrderFinanceComponent = null; this.showOrderShippingData = null; this.showOrderPaymentResponse = null; this.user = null; this.customer = null; this.creditProfile = null; this.showOrderPromoResponse = null; this.orderStatusItems = null; this.orderList = null; this.lookupService.setOrderNotesIndicatorData(null); } /** * This function is used to respond after Angular initializes the component's views * and child views / the view that a directive is in. * @returns void */ ngAfterViewInit() { if (this.cart && !this.cart.isDashOrder && this.cart.refType !== Constants.BLIND_ORDER_REF) { this.sharedService.showErrorMessage('_ERR_NOT_DASH_ORDER', false); } if (Number(this.cart.storeId) !== this.storeId) { this.sharedService.showErrorMessage('_ERR_SWITCH_CHANNEL', false); } if(this.cart && this.cart.isHomeInternetOrder && this.user.permissions.canAccessHomeInternet == false && this.disableResumeButton == true && this.canResumeOrder){ this.sharedService.showErrorMessage('_ERR_NON_PERMISSIONED_AGENT', false); } } /** * This function is used to resume the order and proceed to checkout. * @returns void */ resumeThisOrder(): void { const METHOD_NAME: string = 'resumeThisOrder()'; this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Resume the order'); console.log('Resuming the order...'); // showing conflict model identifierType , identifier if (this.cartService.getCart()) { this.conflictModel.show(); } else { if (this.cart) { if (this.storeId === this.rtStoreId && this.user.permissions.canAccessRTS) { this.lookupService.setOrder(null); this.customerService.setCustomer(null); this.cartService.setCart(this.cart); this.router.navigate(['home/fullcart']); } else if (this.cart.customer && this.cart.customer.creditProfile && this.cart.customer.creditProfile.creditClass) { this.authenticateModel.show(); } else { this.lookupService.setOrder(null); this.customerService.setCustomer(null); this.cartService.setCart(this.cart); if (this.canRedirectToPayReview) { this.router.navigate(['checkout/pay-review']); } else { this.router.navigate(['home/fullcart']); } } } } } /** * This function is used to get the value of status label from key value pair * @param {string} status * @returns string */ getStatusLabel(status: string): string { const METHOD_NAME: string = 'getStatusLabel()'; for (const item of this.orderStatusItems) { if (item.key === status) { return item.value; } } return Constants.NOT_FOUND; } /** * This function is used to getCustomerProfile from customer service. * @param {number} orderId contains valid order number. * @returns void */ showOrderCustomer(orderId: number): void { const METHOD_NAME: string = 'showOrderCustomer()'; console.log('OrderDetailComponent.showOrderCustomer()>>Start.'); this.sharedService.showSpinner(true); // spinner this.customerService.getCustomerProfile(this.storeId, orderId, null).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (this.cart) { this.customer = result; this.cart.customer = result; this.lookupService.setOrder(this.cart); } }, error => { this.sharedService.showSpinner(false); // spinner // this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); console.error('Error occurred while loading the customer details for order:' + orderId); }); } /** * This function is used to get the order shipment details. * @param {number} orderId - orderId of the user. * @returns void */ showOrderShipping(orderId: number): void { const METHOD_NAME: string = 'showOrderShipping()'; console.log('OrderDetailComponent.showOrderShipping()>>Start.'); // this.sharedService.showSpinner(true);// spinner this.cartService.getCartShipping(this.storeId, orderId).subscribe(result => { this.showOrderShippingData = result; // this.sharedService.showSpinner(false);// spinner if (this.cart) { this.cart.shippingInfo = result; // this.cart.shippingInfo.trackingStatus = ''; this.lookupService.setOrder(this.cart); } }, error => { // this.sharedService.showSpinner(false);// spinner // this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); console.error('Error occurred while loading the shipping details for order:' + orderId); }); } /** * This function is used to get the order payment details. * @param {number} orderId - orderId of the user. * @returns void */ showOrderPayment(orderId: number): void { const METHOD_NAME: string = 'showOrderPayment()'; console.log('OrderDetailComponent.showOrderPayment()>>Start.'); // this.sharedService.showSpinner(true);// spinner this.cartService.getCartPayment(this.storeId, orderId).subscribe(result => { this.showOrderPaymentResponse = result; // this.sharedService.showSpinner(false);// spinner if (this.cart) { // this.cart.paymentInfo = result; this.cart = Object.assign(this.cart, result); this.lookupService.setOrder(this.cart); } }, error => { // this.sharedService.showSpinner(false);// spinner // this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); console.error('Error occurred while loading the payment details for order:' + orderId); }); } /** * This function is used to get the order finance details. * @param {number} orderId - orderId of the user. * @returns void */ showOrderFinance(orderId: number): void { const METHOD_NAME: string = 'showOrderFinance()'; console.log('OrderDetailComponent.showOrderFinance()>>Start.'); // this.sharedService.showSpinner(true);// spinner this.cartService.getCartFinance(this.storeId, orderId).subscribe(result => { this.showOrderFinanceComponent = result; // this.sharedService.showSpinner(false);// spinner if (this.cart) { this.cart.financeInfo = result; this.lookupService.setOrder(this.cart); } }, error => { // this.sharedService.showSpinner(false);// spinner // this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); console.error('Error occurred while loading the finance details for order:' + orderId); }); } /** * This function is used to get the order promo details. * @param {number} orderId - orderId of the user. * @returns void */ showOrderPromo(orderId: number): void { const METHOD_NAME: string = 'showOrderPromo()'; console.log('OrderDetailComponent.showOrderPromo()>>Start.'); // this.sharedService.showSpinner(true);// spinner this.cartService.getCartPromo(this.storeId, orderId).subscribe(result => { this.showOrderPromoResponse = result; // this.sharedService.showSpinner(false);// spinner if (this.cart) { this.cart.promotionInfo = result; this.lookupService.setOrder(this.cart); } }, error => { // this.sharedService.showSpinner(false);// spinner // this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); console.error('Error occurred while loading the promo details for order:' + orderId); }); } /** * This function is used to get the order assosiated order details. * @param {number} orderId - orderId of the user. * @returns void */ showAssociatedOrders(orderId: number): void { const METHOD_NAME: string = 'showAssociatedOrders()'; this.sharedService.showSpinner(true); // spinner this.cartService.getAssociatedOrders(this.storeId, orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (result && result.associatedOrders) { for (let i = 0; i < result.associatedOrders.length; i++) { if (result.associatedOrders[i].orderId === orderId && this.cart.refType !== Constants.BLIND_ORDER_REF) { result.associatedOrders.splice(i, 1); } } this.associatedOrders = result.associatedOrders; } // add blind(sap) orders in existing associated order list if (this.cart.refType !== Constants.BLIND_ORDER_REF) { this.showBlindAssociatedOrders(this.cart.fullOrderId); } }, error => { this.sharedService.showSpinner(false); // spinner // this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); console.error('Error occurred while loading the associated orders for order:' + orderId); }); } /** * This function is used to display conflict popup * @returns void */ resolveConflicts(): void { const METHOD_NAME: string = 'resolveConflicts()'; this.conflictModel.hide(); this.cartService.setCart(null); this.cartService.setReturnCart(null); this.resumeThisOrder(); } /** * This function is used to add order notes for an order. * @returns void */ addOrderDetailsNote(): void { const METHOD_NAME: string = 'addOrderDetailsNote()'; if (this.cart && this.cart.orderId) { const inputData: any = { agentId: this.user.logonId, subject: FormConstants.FOOTPRINT }; inputData.description = FormConstants.ORDER_ACCESSED; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); } } /** * This function is used to add order notes for an order. * @param {boolean} flag - orderId of the user. * @returns void */ refreshCart(flag: boolean): void { this.associatedOrders = null; this.ngOnInit(); } /** * This function is used to navigate back to search page. * @returns void */ navigateToSearch(): void { const METHOD_NAME: string = 'navigateToSearch()'; if (this.orderList || this.customer) { if (this.orderList) { if ((this.orderList && this.orderList.orders && this.orderList.orders.length <= 1) || this.orderList.totalCount === 0) { this.router.navigate(['/home/search']); } else { if (this.cart.refType && this.cart.refType === Constants.BLIND_ORDER_REF) { this.router.navigate(['/home/search']); } else { this.router.navigate(['/home/search/order-list']); } } } else if (this.customer) { this.router.navigate(['/home/customer']); } } else { this.router.navigate(['/home/search']); } } /** * This function is used to get the sap blind order details. * @param {number} orderId - orderId of the user. * @returns void */ showBlindAssociatedOrders(fullOrderId: string): void { const METHOD_NAME: string = 'showAssociatedOrders()'; // this.sharedService.showSpinner(true);// spinner this.cartService.getSapOrderList(this.storeId, fullOrderId).subscribe(result => { // this.sharedService.showSpinner(false);// spinner if (result && result.associatedOrders) { //this.associatedOrders = this.associatedOrders.concat(result.associatedOrders); for(let associatedOrder of result.associatedOrders) { //now we are getting Happy RA and RAOTF order. so we need to add only RAOTF if(associatedOrder.isSAPReturnOrder) this.associatedOrders = this.associatedOrders.concat(associatedOrder); } } this.cartService.setSAPBlindCart(result); }, error => { // this.sharedService.showSpinner(false);// spinner // this.sharedService.showErrorMessage(error, true); console.error('Error occurred while loading the blind associated orders for order:' + fullOrderId); }); } }