import { Component } from '@angular/core'; import { PaymentUpdateImport } from '@core/typings/payment.typing'; import { PaymentStatus } from '@core/typings/status.typing'; import { FileService, OrganizedError } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { YCModalComponent } from '@yourcause/common/modals'; import { PaymentImportModel, PaymentProcessingService } from '../payment-processing.service'; @Component({ selector: 'gc-import-ap-payments-modal', templateUrl: './import-ap-payments-modal.component.html', styleUrls: ['./import-ap-payments-modal.component.scss'] }) export class ImportAPPaymentsModalComponent extends YCModalComponent { ValidationModel = PaymentImportModel; payments: PaymentUpdateImport[]; errors: OrganizedError[]; importValid: boolean; constructor ( private fileService: FileService, private paymentProcessingService: PaymentProcessingService, private analyticsService: AnalyticsService ) { super(); } handlePaymentsSet (payments: PaymentImportModel[]) { this.payments = payments.map((payment) => { return { gcPaymentId: payment['GC Payment ID'] || null, paymentStatus: PaymentStatus[payment['Payment Status']] as number, externalPaymentId: payment['AP System Payment ID'], paymentDate: payment['Payment Date'], paymentNumber: '' + payment['Payment Number'], paymentType: this.paymentProcessingService.getPaymentTypeFromImport( payment['Payment Type'] ), statusDate: payment['Status Date'] }; }); } handlePrimaryClick () { this.closeModal.emit(this.payments); this.analyticsService.emitEvent({ eventName: 'Import AP payments', eventType: EventType.Click, extras: null }); } handleSecondaryClick () { const csv = this.fileService.convertObjectArrayToCSVString(this.errors); this.fileService.downloadString(csv, 'text/csv', 'PaymentImportModel_errors.csv'); this.analyticsService.emitEvent({ eventName: 'Download AP payments import errors', eventType: EventType.Click, extras: null }); } handleCancel () { this.closeModal.emit(); } }