/** * @Component Name: OrderPaymentComponent * @Module: Home * @Module Functionality : To display the order payment section * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnDestroy, OnInit, OnChanges } from '@angular/core'; import * as Constants from '../../../../shared/constants'; import { IFinance } from '../../../../shared/modal/common'; import { ICreateAgreement, IResendSAEmail } from '../../../../shared/modal/customer'; import { SharedService } from '../../../../shared/shared.service'; import { CustomerService } from '../../../../services/customer.service'; import { LookupService } from '../../../../services/lookup.service'; import { User } from '../../../../shared/modal/user'; import { UserService } from '../../../../services/user.service'; import CartUtils from '../../../../shared/cart.utils'; @Component({ selector: 'order-payment-cmp', moduleId: module.id, templateUrl: 'order-payment.component.html', styleUrls: ['order-payment.component.css'] }) export class OrderPaymentComponent implements OnInit, OnDestroy, OnChanges { private COMPONENT_NAME: string = 'OrderPaymentComponent'; @Input() finance: IFinance; @Input() cart: any; showPaymentInfo: boolean = false; storeId: number; emailAddressBilling: string; emailAddressPayment: string; languagePreferred: string = 'ENGLISH'; emailAgreementSent: boolean; emailDisclosureSent: boolean; isFinanceOrder: boolean = false; isCreditOrder: boolean = false; isBlindOrder: boolean = false; karmaTestResult: any = {}; user: User; auFirstName: string; auLastName: string; isEdit:boolean = false; sendNames: boolean = false; rtStoreId: number = Constants.STORE_ID_RT; constructor( public sharedService: SharedService, public customerService: CustomerService, public lookupService: LookupService, public userService: UserService ) { } /** * 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.storeId.subscribe((val: number) => { this.storeId = val; }); this.cart = this.lookupService.getOrder(); this.isCreditOrder = false; // this.isBlindOrder = false; this.user = this.userService.getUser(); } ngOnChanges() { this.user = this.userService.getUser(); this.isBlindOrder = false; if (this.cart.refType && this.cart.refType === Constants.REF_TYPE_CREDIT) { this.isCreditOrder = true; } if (this.cart.refType && this.cart.refType === Constants.BLIND_ORDER_REF) { this.isBlindOrder = true; } if (!this.isCreditOrder) { if (this.cart && this.cart.customer && this.cart.customer.email1) { this.emailAddressPayment = this.cart.customer.email1; this.emailAddressBilling = this.cart.customer.email1; } this.isFinanceOrder = CartUtils.isFinanceOrder(this.cart); } } /** * 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.finance = null; } onEdit() { if(!this.isEdit){ this.isEdit = !this.isEdit; this.auFirstName = this.cart.customer.personCompleteAgreement[0].firstName; this.auLastName = this.cart.customer.personCompleteAgreement[0].lastName; } } onSave() { this.isEdit = !this.isEdit; this.sendNames = true; this.cart.customer.personCompleteAgreement[0].firstName = this.auFirstName; this.cart.customer.personCompleteAgreement[0].lastName = this.auLastName; } /** * This function is used to send the agreement through e-mail. * @returns void */ sendAgreement(): void { const METHOD_NAME: string = 'sendAgreement()'; this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Sending email agreement'); const inputparams: IResendSAEmail = {}; inputparams.preferedLanguage = this.languagePreferred; inputparams.emailId = this.emailAddressPayment; inputparams.orderId = this.cart.orderId; inputparams.orderId = this.cart.orderId; this.sharedService.showSpinner(true); // spinner this.customerService.resendSAEmail(this.storeId, this.cart.orderId, inputparams).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner this.emailAgreementSent = (result.statusCode === 'success') ? true : false; const inputData: any = { agentId: this.user.logonId, subject: 'Service Agreement' }; inputData.description = 'Service Agreement was resent to ' + inputparams.emailId; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); }, error => { this.sharedService.showSpinner(false); // spinner console.error('error=>' + error); this.sharedService.showErrorMessage(error, true); }); } /** * This function is used to send the disclosure agreement through e-mail. * @returns void */ sendDisclosureAgreement(): void { const METHOD_NAME: string = 'sendDisclosureAgreement()'; const inputparams: ICreateAgreement = {}; inputparams.languagePreference = this.languagePreferred; inputparams.emailAddress = this.emailAddressBilling; inputparams.emailOption = Constants.EMAIL_OPTION; if(this.sendNames){ inputparams.auFirstName = this.auFirstName; inputparams.auLastName = this.auLastName; } this.sharedService.showSpinner(true); // spinner this.customerService.resendDiscloserEmail(this.storeId, this.cart.orderId, inputparams).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner this.emailDisclosureSent = (result.statusCode === 'Success') ? true : false; const inputData: any = { agentId: this.user.logonId, subject: 'E-Signature Agreement' }; inputData.description = 'E-Signature Agreement was resent to ' + inputparams.emailAddress; this.sharedService.addOrderNotes(this.storeId, this.cart.orderId, inputData); }, error => { this.sharedService.showSpinner(false); // spinner console.error('error=>' + error); this.sharedService.showErrorMessage(error, true); }); } /** * This function is used to find Order status for SAResend Email from OrderLookup P6,P10,P3,P5,C,S. * @returns boolean */ get canSendSAEmail(): boolean { const METHOD_NAME: string = 'canSendSAEmail()'; if (this.cart && (this.cart.status === Constants.ORDER_STATUS_S || this.cart.status === Constants.ORDER_STATUS_P6 || this.cart.status === Constants.ORDER_STATUS_P10 || this.cart.status === Constants.ORDER_STATUS_P3 || this.cart.status === Constants.ORDER_STATUS_C || this.cart.status === Constants.ORDER_STATUS_P5 || this.cart.status === Constants.ORDER_STATUS_B || this.cart.status === Constants.ORDER_STATUS_DC )) { return true; } return false; } /** * This function is used to send Esig agreement. * @returns boolean */ get canSendEsigAgreement(): boolean { const METHOD_NAME: string = 'canSendEsigAgreement()'; // Added P21 to show send esig option for eip disclosure error orders if (this.cart.status === Constants.ORDER_STATUS_P6 || this.cart.status === Constants.ORDER_STATUS_P21) { return true; } return false; } /** * This function is used to get Esig status of pending/expired/completed. * @returns string */ getStatus(): string { const METHOD_NAME: string = 'getStatus()'; if (this.cart.financeInfo && this.cart.financeInfo.financeInfo.eSignStatus === Constants.ORDER_STATUS_C) { return Constants.STATUS_COMPLETED; } else if (this.cart.financeInfo && this.cart.financeInfo.financeInfo.eSignStatus === Constants.ORDER_STATUS_P) { return Constants.STATUS_PENDING; } else if (this.cart.financeInfo && this.cart.financeInfo.financeInfo.eSignStatus === Constants.ORDER_STATUS_X) { return Constants.STATUS_CANCELLED; }else if (this.cart.financeInfo && this.cart.financeInfo.financeInfo.eSignStatus === Constants.ORDER_STATUS_DC) { return Constants.STATUS_SAPCCDECLINE; }else { return Constants.STATUS_NOT_AVAILABLE; } } }