import { Component, Input, OnInit } from '@angular/core'; import { BudgetDetail, BudgetFundingSource } from '@core/typings/budget.typing'; import { BudgetAssignmentsService } from '@features/budget-assignments/budget-assignments.service'; import { ProgramService } from '@features/programs/program.service'; import { YCModalComponent } from '@yourcause/common/modals'; @Component({ selector: 'gc-budget-summary-modal', templateUrl: './budget-summary-modal.component.html', styleUrls: ['./budget-summary-modal.component.scss'] }) export class BudgetSummaryModalComponent extends YCModalComponent implements OnInit { @Input() budget: BudgetDetail; @Input() budgetFundingSource: BudgetFundingSource; @Input() programId: number; @Input() amountRequested: number; @Input() applicationId: number; @Input() isReserved: boolean; unableToFund = 0; ready = false; constructor ( private programService: ProgramService, private budgetAssignmentService: BudgetAssignmentsService ) { super(); } get programMap () { return this.programService.get('configureProgramMap'); } get program () { return this.programMap[this.programId]; } async ngOnInit () { await this.getUnableToFund(); this.ready = true; } async getUnableToFund () { const availableFromBudgetFs = this.budgetFundingSource.amountRemaining; // If we are currently reserved, we don't need any more funds reserved const additionalReservedAmount = this.isReserved ? 0 : await this.budgetAssignmentService.getReservedAmountForApplication( this.applicationId, this.amountRequested ); // if there is enough from the budget/fs to cover the reserved amount on the application, then we show 0 if (availableFromBudgetFs > additionalReservedAmount) { this.unableToFund = 0; } else { // otherwise, we show the difference between what the budget/fs has and what is currently reserved this.unableToFund = additionalReservedAmount - availableFromBudgetFs; } } }