|
@ -123,18 +123,18 @@ export class FireCalculatorComponent |
|
|
.subscribe((savingsRate) => { |
|
|
.subscribe((savingsRate) => { |
|
|
this.savingsRateChanged.emit(savingsRate); |
|
|
this.savingsRateChanged.emit(savingsRate); |
|
|
}); |
|
|
}); |
|
|
this.calculatorForm |
|
|
|
|
|
.get('retirementDate') |
|
|
|
|
|
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe((retirementDate) => { |
|
|
|
|
|
this.retirementDateChanged.emit(retirementDate); |
|
|
|
|
|
}); |
|
|
|
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('projectedTotalAmount') |
|
|
.get('projectedTotalAmount') |
|
|
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe((projectedTotalAmount) => { |
|
|
.subscribe((projectedTotalAmount) => { |
|
|
this.projectedTotalAmountChanged.emit(projectedTotalAmount); |
|
|
this.projectedTotalAmountChanged.emit(projectedTotalAmount); |
|
|
}); |
|
|
}); |
|
|
|
|
|
this.calculatorForm |
|
|
|
|
|
.get('retirementDate') |
|
|
|
|
|
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe((retirementDate) => { |
|
|
|
|
|
this.retirementDateChanged.emit(retirementDate); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngAfterViewInit() { |
|
|
public ngAfterViewInit() { |
|
@ -143,12 +143,12 @@ export class FireCalculatorComponent |
|
|
// Wait for the chartCanvas
|
|
|
// Wait for the chartCanvas
|
|
|
this.calculatorForm.patchValue( |
|
|
this.calculatorForm.patchValue( |
|
|
{ |
|
|
{ |
|
|
principalInvestmentAmount: this.getP(), |
|
|
|
|
|
paymentPerPeriod: this.getPMT(), |
|
|
paymentPerPeriod: this.getPMT(), |
|
|
retirementDate: |
|
|
principalInvestmentAmount: this.getP(), |
|
|
this.getRetirementDate() ?? this.DEFAULT_RETIREMENT_DATE, |
|
|
|
|
|
projectedTotalAmount: |
|
|
projectedTotalAmount: |
|
|
Number(this.getProjectedTotalAmount().toFixed(2)) ?? 0 |
|
|
Number(this.getProjectedTotalAmount().toFixed(2)) ?? 0, |
|
|
|
|
|
retirementDate: |
|
|
|
|
|
this.getRetirementDate() ?? this.DEFAULT_RETIREMENT_DATE |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
emitEvent: false |
|
|
emitEvent: false |
|
@ -162,17 +162,16 @@ export class FireCalculatorComponent |
|
|
|
|
|
|
|
|
if (this.hasPermissionToUpdateUserSettings === true) { |
|
|
if (this.hasPermissionToUpdateUserSettings === true) { |
|
|
this.calculatorForm.get('paymentPerPeriod').enable({ emitEvent: false }); |
|
|
this.calculatorForm.get('paymentPerPeriod').enable({ emitEvent: false }); |
|
|
this.calculatorForm.get('retirementDate').enable({ emitEvent: false }); |
|
|
|
|
|
|
|
|
|
|
|
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.get('retirementDate').disable({ emitEvent: false }); |
|
|
|
|
|
this.calculatorForm |
|
|
this.calculatorForm |
|
|
.get('projectedTotalAmount') |
|
|
.get('projectedTotalAmount') |
|
|
.disable({ emitEvent: false }); |
|
|
.disable({ emitEvent: false }); |
|
|
|
|
|
this.calculatorForm.get('retirementDate').disable({ emitEvent: false }); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -325,69 +324,6 @@ export class FireCalculatorComponent |
|
|
this.isLoading = false; |
|
|
this.isLoading = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getP() { |
|
|
|
|
|
return this.fireWealth || 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getPMT() { |
|
|
|
|
|
return this.savingsRate ?? 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getR() { |
|
|
|
|
|
return this.calculatorForm.get('annualInterestRate').value / 100; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getProjectedTotalAmount() { |
|
|
|
|
|
if (this.projectedTotalAmount) { |
|
|
|
|
|
return this.projectedTotalAmount || 0; |
|
|
|
|
|
} else { |
|
|
|
|
|
const { totalAmount } = |
|
|
|
|
|
this.fireCalculatorService.calculateCompoundInterest({ |
|
|
|
|
|
P: this.getP(), |
|
|
|
|
|
periodInMonths: this.periodsToRetire, |
|
|
|
|
|
PMT: this.getPMT(), |
|
|
|
|
|
r: this.getR() |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return totalAmount.toNumber(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getPeriodsToRetire(): number { |
|
|
|
|
|
if (this.projectedTotalAmount) { |
|
|
|
|
|
const periods = this.fireCalculatorService.calculatePeriodsToRetire({ |
|
|
|
|
|
P: this.getP(), |
|
|
|
|
|
totalAmount: this.projectedTotalAmount, |
|
|
|
|
|
PMT: this.getPMT(), |
|
|
|
|
|
r: this.getR() |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return periods; |
|
|
|
|
|
} else { |
|
|
|
|
|
const today = new Date(); |
|
|
|
|
|
const retirementDate = |
|
|
|
|
|
this.retirementDate ?? this.DEFAULT_RETIREMENT_DATE; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
12 * (retirementDate.getFullYear() - today.getFullYear()) + |
|
|
|
|
|
retirementDate.getMonth() - |
|
|
|
|
|
today.getMonth() |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getRetirementDate(): Date { |
|
|
|
|
|
const monthsToRetire = this.periodsToRetire % 12; |
|
|
|
|
|
const yearsToRetire = Math.floor(this.periodsToRetire / 12); |
|
|
|
|
|
|
|
|
|
|
|
return startOfMonth( |
|
|
|
|
|
add(new Date(), { |
|
|
|
|
|
months: monthsToRetire, |
|
|
|
|
|
years: yearsToRetire |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getChartData() { |
|
|
private getChartData() { |
|
|
const currentYear = new Date().getFullYear(); |
|
|
const currentYear = new Date().getFullYear(); |
|
|
const labels = []; |
|
|
const labels = []; |
|
@ -463,4 +399,67 @@ export class FireCalculatorComponent |
|
|
datasets: [datasetDeposit, datasetSavings, datasetInterest] |
|
|
datasets: [datasetDeposit, datasetSavings, datasetInterest] |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getP() { |
|
|
|
|
|
return this.fireWealth || 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getPMT() { |
|
|
|
|
|
return this.savingsRate ?? 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getR() { |
|
|
|
|
|
return this.calculatorForm.get('annualInterestRate').value / 100; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getPeriodsToRetire(): number { |
|
|
|
|
|
if (this.projectedTotalAmount) { |
|
|
|
|
|
const periods = this.fireCalculatorService.calculatePeriodsToRetire({ |
|
|
|
|
|
P: this.getP(), |
|
|
|
|
|
totalAmount: this.projectedTotalAmount, |
|
|
|
|
|
PMT: this.getPMT(), |
|
|
|
|
|
r: this.getR() |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return periods; |
|
|
|
|
|
} else { |
|
|
|
|
|
const today = new Date(); |
|
|
|
|
|
const retirementDate = |
|
|
|
|
|
this.retirementDate ?? this.DEFAULT_RETIREMENT_DATE; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
12 * (retirementDate.getFullYear() - today.getFullYear()) + |
|
|
|
|
|
retirementDate.getMonth() - |
|
|
|
|
|
today.getMonth() |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getProjectedTotalAmount() { |
|
|
|
|
|
if (this.projectedTotalAmount) { |
|
|
|
|
|
return this.projectedTotalAmount || 0; |
|
|
|
|
|
} else { |
|
|
|
|
|
const { totalAmount } = |
|
|
|
|
|
this.fireCalculatorService.calculateCompoundInterest({ |
|
|
|
|
|
P: this.getP(), |
|
|
|
|
|
periodInMonths: this.periodsToRetire, |
|
|
|
|
|
PMT: this.getPMT(), |
|
|
|
|
|
r: this.getR() |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return totalAmount.toNumber(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getRetirementDate(): Date { |
|
|
|
|
|
const monthsToRetire = this.periodsToRetire % 12; |
|
|
|
|
|
const yearsToRetire = Math.floor(this.periodsToRetire / 12); |
|
|
|
|
|
|
|
|
|
|
|
return startOfMonth( |
|
|
|
|
|
add(new Date(), { |
|
|
|
|
|
months: monthsToRetire, |
|
|
|
|
|
years: yearsToRetire |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|