/** * @Component Name: ManualReviewComponent * @Module: Home * @Module Functionality : To display the block review * @Creation Date: November 29,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnInit, Output, EventEmitter, OnDestroy } from '@angular/core'; import * as Constants from '../../../../shared/constants'; import { ORDER_STATUS } from '../../../../shared/form.constants' import { User } from '../../../../shared/modal/user'; import { Cart } from '../../../../shared/modal/cart'; 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'; @Component({ moduleId: module.id, selector: 'block-review-cmp', templateUrl: 'block-review.component.html', styleUrls: ['block-review.component.css'] }) export class BlockReviewComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'BlockReviewComponent'; visible: boolean = false; visibleAnimate: boolean = false; karmaTestResult: any = {}; storeId: number; reviewNotes: string; user: User; @Input() cart: any; @Output() canRefreshCart: EventEmitter = new EventEmitter(); orderStatusP2 = Constants.ORDER_STATUS_P2; constructor( public sharedService: SharedService, public userService: UserService, public lookupService: LookupService, 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()'; } /** * 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 function is used to display the object. * @return {void} */ public show(): void { const METHOD_NAME: string = 'show()'; this.visible = true; setTimeout(() => this.visibleAnimate = true, 100); this.sharedService.storeId.subscribe((val: number) => {this.storeId = val; }); } /** * This function is used to hide the object. * @returns void */ public hide(): void { const METHOD_NAME: string = 'hide()'; this.visibleAnimate = false; setTimeout(() => this.visible = false, 300); } /** * This function is used to hide the object when nouse event performed * @param {MouseEvent} event - contains valid mouse event * @returns void */ public onContainerClicked(event: MouseEvent): void { const METHOD_NAME: string = 'onContainerClicked()'; if ((event.target).classList.contains('modal')) { this.hide(); } } /** * 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()'; for (const item of ORDER_STATUS) { if (item.key === status) { return item.value; } } return Constants.NOT_FOUND; } unblockOrder(): void { const METHOD_NAME: string = 'unblockOrder()'; this.user = this.userService.getUser(); this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Release the order'); const sapStatus = (this.cart && this.cart.status === Constants.ORDER_STATUS_P8) ? true : false; const inputData: any = { agentId: this.user.logonId, description: this.reviewNotes, isSubmitToSap: sapStatus }; inputData.subject = (this.cart && this.cart.status === this.orderStatusP2) ? 'Order Verification' : 'Block Review'; this.sharedService.showSpinner(true); // spinner this.lookupService.releaseOrder(this.storeId, this.cart.orderId, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (result.serviceStatus && result.serviceStatus.code === 100) { // inputData.description = Constants.SUCCESS_DESC; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); // clearing order details from local storage this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.lookupService.setOrder(result); this.canRefreshCart.emit(true); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error) }); } else { inputData.description = Constants.FAILURE; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); this.sharedService.showErrorMessage('_ERR_MANUAL_REVIEW_SERVER', false); } this.hide(); }, error => { inputData.description = Constants.FAILURE; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); this.hide(); }); } cancelOrder(): void { const METHOD_NAME: string = 'cancelOrder()'; this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Cancel the order'); this.user = this.userService.getUser(); const inputData: any = { agentId: this.user.logonId, subject: 'Cancel the order' }; this.sharedService.showSpinner(true); // spinner this.lookupService.cancelOrder(this.storeId, this.cart.orderId).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner if (result) { this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.lookupService.setOrder(result); inputData.description = Constants.SUCCESS_DESC; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); if(this.cart && this.cart.status === this.orderStatusP2 && this.cart.customer && this.cart.customer.creditProfile && this.cart.customer.creditProfile.accountNumber){ this.postFraudRejectMemo(this.cart.customer.creditProfile.accountNumber); } this.canRefreshCart.emit(true); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); inputData.description = Constants.FAILURE; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); }); } else { inputData.description = Constants.FAILURE; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); this.sharedService.showErrorMessage('_ERR_CANCEL_ORDER_FAILED', false); } this.hide(); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); inputData.description = Constants.FAILURE; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); }); } /** * This funcation is used to resubmit * @returns void */ releaseOrder(): void { this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (result.status === this.cart.status) { this.unblockOrder(); } else { this.sharedService.showErrorMessage('_ERR_GENERIC', false); } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error) }); } /** * This function is used to post SAMSON memo for fraud reject * @return {boolean} */ postFraudRejectMemo(accountNumber: number):void { const METHOD_NAME: string = 'writeFraudRejectMemo()'; //writting memo into samson let inputData: any = { orderId: this.cart.fullOrderId }; inputData.accountNumber = accountNumber; inputData.dealerCode = this.cart.dealerCode ? this.cart.dealerCode: this.user.dealerCode; if(inputData.dealerCode && inputData.dealerCode.length > 7) { inputData.dealerCode = inputData.dealerCode.substring(1); } let memoText:string = Constants.SAMSON_MEMO_TEXT_FRAUD_REJECT; inputData.memoText = memoText.replace('', this.cart.fullOrderId); inputData.memoCode = Constants.SAMSON_MEMO_CODE_FRAUD_REJECT; inputData.memoCodeValue = Constants.SAMSON_MEMO_CODE_TEXT_FRAUD_REJECT; inputData.orderCreateDate = this.cart.createdByDate; this.sharedService.showSpinner(true); // spinner this.customerService.generateMemo(this.storeId, this.cart.orderId, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner console.log('Memo has created successfully in billing system.'); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage('_ERR_CREATE_SAMSON_MEMO', false); // console.error('error=>' + error); }); } }