|
@ -39,7 +39,7 @@ import { |
|
|
sub |
|
|
sub |
|
|
} from 'date-fns'; |
|
|
} from 'date-fns'; |
|
|
import { isNumber } from 'lodash'; |
|
|
import { isNumber } from 'lodash'; |
|
|
import { Subject, takeUntil } from 'rxjs'; |
|
|
import { debounceTime, Subject, takeUntil } from 'rxjs'; |
|
|
|
|
|
|
|
|
import { FireCalculatorService } from './fire-calculator.service'; |
|
|
import { FireCalculatorService } from './fire-calculator.service'; |
|
|
|
|
|
|
|
@ -52,6 +52,7 @@ import { FireCalculatorService } from './fire-calculator.service'; |
|
|
export class FireCalculatorComponent |
|
|
export class FireCalculatorComponent |
|
|
implements AfterViewInit, OnChanges, OnDestroy |
|
|
implements AfterViewInit, OnChanges, OnDestroy |
|
|
{ |
|
|
{ |
|
|
|
|
|
@Input() annualInterestRate = 5; |
|
|
@Input() colorScheme: ColorScheme; |
|
|
@Input() colorScheme: ColorScheme; |
|
|
@Input() currency: string; |
|
|
@Input() currency: string; |
|
|
@Input() deviceType: string; |
|
|
@Input() deviceType: string; |
|
@ -62,6 +63,7 @@ export class FireCalculatorComponent |
|
|
@Input() retirementDate: Date; |
|
|
@Input() retirementDate: Date; |
|
|
@Input() savingsRate = 0; |
|
|
@Input() savingsRate = 0; |
|
|
|
|
|
|
|
|
|
|
|
@Output() annualInterestRateChanged = new EventEmitter<number>(); |
|
|
@Output() projectedTotalAmountChanged = new EventEmitter<number>(); |
|
|
@Output() projectedTotalAmountChanged = new EventEmitter<number>(); |
|
|
@Output() retirementDateChanged = new EventEmitter<Date>(); |
|
|
@Output() retirementDateChanged = new EventEmitter<Date>(); |
|
|
@Output() savingsRateChanged = new EventEmitter<number>(); |
|
|
@Output() savingsRateChanged = new EventEmitter<number>(); |
|
@ -100,7 +102,7 @@ export class FireCalculatorComponent |
|
|
|
|
|
|
|
|
this.calculatorForm.setValue( |
|
|
this.calculatorForm.setValue( |
|
|
{ |
|
|
{ |
|
|
annualInterestRate: 5, |
|
|
annualInterestRate: this.annualInterestRate, |
|
|
paymentPerPeriod: this.savingsRate, |
|
|
paymentPerPeriod: this.savingsRate, |
|
|
principalInvestmentAmount: 0, |
|
|
principalInvestmentAmount: 0, |
|
|
projectedTotalAmount: this.projectedTotalAmount, |
|
|
projectedTotalAmount: this.projectedTotalAmount, |
|
@ -117,21 +119,27 @@ export class FireCalculatorComponent |
|
|
this.initialize(); |
|
|
this.initialize(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.calculatorForm |
|
|
|
|
|
.get('annualInterestRate') |
|
|
|
|
|
.valueChanges.pipe(debounceTime(500), takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe((annualInterestRate) => { |
|
|
|
|
|
this.annualInterestRateChanged.emit(annualInterestRate); |
|
|
|
|
|
}); |
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('paymentPerPeriod') |
|
|
.get('paymentPerPeriod') |
|
|
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.valueChanges.pipe(debounceTime(500), takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe((savingsRate) => { |
|
|
.subscribe((savingsRate) => { |
|
|
this.savingsRateChanged.emit(savingsRate); |
|
|
this.savingsRateChanged.emit(savingsRate); |
|
|
}); |
|
|
}); |
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('projectedTotalAmount') |
|
|
.get('projectedTotalAmount') |
|
|
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.valueChanges.pipe(debounceTime(500), takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe((projectedTotalAmount) => { |
|
|
.subscribe((projectedTotalAmount) => { |
|
|
this.projectedTotalAmountChanged.emit(projectedTotalAmount); |
|
|
this.projectedTotalAmountChanged.emit(projectedTotalAmount); |
|
|
}); |
|
|
}); |
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('retirementDate') |
|
|
.get('retirementDate') |
|
|
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.valueChanges.pipe(debounceTime(500), takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe((retirementDate) => { |
|
|
.subscribe((retirementDate) => { |
|
|
this.retirementDateChanged.emit(retirementDate); |
|
|
this.retirementDateChanged.emit(retirementDate); |
|
|
}); |
|
|
}); |
|
@ -143,10 +151,11 @@ export class FireCalculatorComponent |
|
|
// Wait for the chartCanvas
|
|
|
// Wait for the chartCanvas
|
|
|
this.calculatorForm.patchValue( |
|
|
this.calculatorForm.patchValue( |
|
|
{ |
|
|
{ |
|
|
|
|
|
annualInterestRate: this.annualInterestRate, |
|
|
paymentPerPeriod: this.getPMT(), |
|
|
paymentPerPeriod: this.getPMT(), |
|
|
principalInvestmentAmount: this.getP(), |
|
|
principalInvestmentAmount: this.getP(), |
|
|
projectedTotalAmount: |
|
|
projectedTotalAmount: |
|
|
Number(this.getProjectedTotalAmount().toFixed(2)) ?? 0, |
|
|
Number(this.getProjectedTotalAmount().toFixed(0)) ?? 0, |
|
|
retirementDate: |
|
|
retirementDate: |
|
|
this.getRetirementDate() ?? this.DEFAULT_RETIREMENT_DATE |
|
|
this.getRetirementDate() ?? this.DEFAULT_RETIREMENT_DATE |
|
|
}, |
|
|
}, |
|
@ -165,14 +174,14 @@ export class FireCalculatorComponent |
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('projectedTotalAmount') |
|
|
.get('projectedTotalAmount') |
|
|
.enable({ emitEvent: false }); |
|
|
.enable({ emitEvent: false }); |
|
|
this.calculatorForm.get('retirementDate').enable({ emitEvent: false }); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
this.calculatorForm.get('paymentPerPeriod').disable({ emitEvent: false }); |
|
|
this.calculatorForm.get('paymentPerPeriod').disable({ emitEvent: false }); |
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('projectedTotalAmount') |
|
|
.get('projectedTotalAmount') |
|
|
.disable({ emitEvent: false }); |
|
|
.disable({ emitEvent: false }); |
|
|
this.calculatorForm.get('retirementDate').disable({ emitEvent: false }); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.calculatorForm.get('retirementDate').disable({ emitEvent: false }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnChanges() { |
|
|
public ngOnChanges() { |
|
@ -182,10 +191,11 @@ export class FireCalculatorComponent |
|
|
// Wait for the chartCanvas
|
|
|
// Wait for the chartCanvas
|
|
|
this.calculatorForm.patchValue( |
|
|
this.calculatorForm.patchValue( |
|
|
{ |
|
|
{ |
|
|
|
|
|
annualInterestRate: this.annualInterestRate, |
|
|
principalInvestmentAmount: this.fireWealth, |
|
|
principalInvestmentAmount: this.fireWealth, |
|
|
paymentPerPeriod: this.savingsRate ?? 0, |
|
|
paymentPerPeriod: this.savingsRate ?? 0, |
|
|
projectedTotalAmount: |
|
|
projectedTotalAmount: |
|
|
Number(this.getProjectedTotalAmount().toFixed(2)) ?? 0, |
|
|
Number(this.getProjectedTotalAmount().toFixed(0)) ?? 0, |
|
|
retirementDate: |
|
|
retirementDate: |
|
|
this.getRetirementDate() ?? this.DEFAULT_RETIREMENT_DATE |
|
|
this.getRetirementDate() ?? this.DEFAULT_RETIREMENT_DATE |
|
|
}, |
|
|
}, |
|
@ -204,14 +214,14 @@ export class FireCalculatorComponent |
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('projectedTotalAmount') |
|
|
.get('projectedTotalAmount') |
|
|
.enable({ emitEvent: false }); |
|
|
.enable({ emitEvent: false }); |
|
|
this.calculatorForm.get('retirementDate').enable({ emitEvent: false }); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
this.calculatorForm.get('paymentPerPeriod').disable({ emitEvent: false }); |
|
|
this.calculatorForm.get('paymentPerPeriod').disable({ emitEvent: false }); |
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('projectedTotalAmount') |
|
|
.get('projectedTotalAmount') |
|
|
.disable({ emitEvent: false }); |
|
|
.disable({ emitEvent: false }); |
|
|
this.calculatorForm.get('retirementDate').disable({ emitEvent: false }); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.calculatorForm.get('retirementDate').disable({ emitEvent: false }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public setMonthAndYear( |
|
|
public setMonthAndYear( |
|
|