import { Component, Input, OnInit } from '@angular/core'; import { CurrencyService } from '@core/services/currency.service'; import { StatusService } from '@core/services/status.service'; import { FundingSourceTypes } from '@core/typings/budget.typing'; import { Payment } from '@core/typings/payment.typing'; import { PaymentStatus } from '@core/typings/status.typing'; import { AwardService } from '@features/awards/award.service'; import { AwardFromApi } from '@features/awards/typings/award.typing'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; @Component({ selector: 'gc-view-payments-modal', templateUrl: './view-payments-modal.component.html', styleUrls: ['./view-payments-modal.component.scss'] }) export class ViewPaymentsModalComponent extends YCModalComponent implements OnInit { @Input() award: AwardFromApi; @Input() showInDefault: boolean; @Input() currencyRequested: string; @Input() isArchived: boolean; modalSubHeader = ''; total: string; paymentStatusMap = this.statusService.paymentStatusMap; PaymentStatus = PaymentStatus; paymentSubStatusMap = this.statusService.paymentSubStatusMap; cashString = this.i18n.translate( 'GLOBAL:textCash' ); inKindString = this.i18n.translate( 'GLOBAL:textInKind', {}, 'In-Kind' ); loaded: boolean; FundingSourceTypes = FundingSourceTypes; constructor ( private i18n: I18nService, private currencyService: CurrencyService, private statusService: StatusService, private awardService: AwardService, private clientSettingsService: ClientSettingsService ) { super(); } async ngOnInit () { const payments: Partial[] = this.award.payments.map((pay) => { return { statusId: pay.status, typeId: pay.fundingSourceType, currencyRequestedAmountEquivalent: pay.currencyRequestedAmountEquivalent, fundingSource: pay.fundingSourceId, amount: pay.totalAmount }; }); const returnDefault = this.showInDefault || this.award.awardType === FundingSourceTypes.UNITS; const total = this.awardService.sumPayments( payments, returnDefault ); const currency = returnDefault ? this.clientSettingsService.defaultCurrency : this.award.currencyRequested; this.total = this.currencyService.formatMoney(total, currency) + ` ${ currency}`; this.modalSubHeader = this.i18n.translate( 'GLOBAL:textAwardForAmount', { awardAmount: this.currencyService.formatMoney(this.award.amount) }, 'Award amount: __awardAmount__' ); this.loaded = true; } onCancel () { this.closeModal.emit(); } }