Browse Source

Refactoring

pull/1748/head
Thomas 3 years ago
parent
commit
543c656635
  1. 14
      apps/client/src/app/pages/portfolio/fire/fire-page.component.ts
  2. 2
      apps/client/src/locales/messages.nl.xlf
  3. 30
      libs/ui/src/lib/fire-calculator/fire-calculator.component.ts

14
apps/client/src/app/pages/portfolio/fire/fire-page.component.ts

@ -91,9 +91,12 @@ export class FirePageComponent implements OnDestroy, OnInit {
});
}
public onSavingsRateChange(savingsRate: number) {
public onRetirementDateChange(retirementDate: Date) {
this.dataService
.putUserSetting({ savingsRate })
.putUserSetting({
retirementDate: retirementDate.toISOString(),
projectedTotalAmount: null
})
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => {
this.userService.remove();
@ -109,12 +112,9 @@ export class FirePageComponent implements OnDestroy, OnInit {
});
}
public onRetirementDateChange(retirementDate: Date) {
public onSavingsRateChange(savingsRate: number) {
this.dataService
.putUserSetting({
retirementDate: retirementDate.toISOString(),
projectedTotalAmount: null
})
.putUserSetting({ savingsRate })
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => {
this.userService.remove();

2
apps/client/src/locales/messages.nl.xlf

@ -3507,7 +3507,7 @@
</trans-unit>
<trans-unit id="46d3a0f17b741c93f9e61aa7157820da41506f53" datatype="html">
<source>Target Net Worth</source>
<target state="new">Beoogd Netto Vermogen</target>
<target state="translated">Beoogd Netto Vermogen</target>
<context-group purpose="location">
<context context-type="sourcefile">libs/ui/src/lib/fire-calculator/fire-calculator.component.html</context>
<context context-type="linenumber">38</context>

30
libs/ui/src/lib/fire-calculator/fire-calculator.component.ts

@ -201,16 +201,16 @@ export class FireCalculatorComponent
if (this.hasPermissionToUpdateUserSettings === true) {
this.calculatorForm.get('paymentPerPeriod').enable({ emitEvent: false });
this.calculatorForm.get('retirementDate').enable({ emitEvent: false });
this.calculatorForm
.get('projectedTotalAmount')
.enable({ emitEvent: false });
this.calculatorForm.get('retirementDate').enable({ emitEvent: false });
} else {
this.calculatorForm.get('paymentPerPeriod').disable({ emitEvent: false });
this.calculatorForm.get('retirementDate').disable({ emitEvent: false });
this.calculatorForm
.get('projectedTotalAmount')
.disable({ emitEvent: false });
this.calculatorForm.get('retirementDate').disable({ emitEvent: false });
}
}
@ -218,12 +218,12 @@ export class FireCalculatorComponent
normalizedMonthAndYear: Date,
datepicker: MatDatepicker<Date>
) {
const ctrlValue = this.calculatorForm.get('retirementDate').value;
const newDate = setMonth(
setYear(ctrlValue, normalizedMonthAndYear.getFullYear()),
const retirementDate = this.calculatorForm.get('retirementDate').value;
const newRetirementDate = setMonth(
setYear(retirementDate, normalizedMonthAndYear.getFullYear()),
normalizedMonthAndYear.getMonth()
);
this.calculatorForm.get('retirementDate').setValue(newDate);
this.calculatorForm.get('retirementDate').setValue(newRetirementDate);
datepicker.close();
}
@ -381,7 +381,7 @@ export class FireCalculatorComponent
for (let period = 1; period <= t; period++) {
const periodInMonths =
period * this.CONTRIBUTION_PERIOD - monthsPassedInCurrentYear;
const { interest, principal, totalAmount } =
const { interest, principal } =
this.fireCalculatorService.calculateCompoundInterest({
P,
periodInMonths,
@ -404,14 +404,6 @@ export class FireCalculatorComponent
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({
@ -435,6 +427,10 @@ export class FireCalculatorComponent
}
}
private getPMT() {
return this.savingsRate ?? 0;
}
private getProjectedTotalAmount() {
if (this.projectedTotalAmount) {
return this.projectedTotalAmount || 0;
@ -451,6 +447,10 @@ export class FireCalculatorComponent
}
}
private getR() {
return this.calculatorForm.get('annualInterestRate').value / 100;
}
private getRetirementDate(): Date {
const monthsToRetire = this.periodsToRetire % 12;
const yearsToRetire = Math.floor(this.periodsToRetire / 12);

Loading…
Cancel
Save