Skip to content

Commit

Permalink
Nidi/add simulation pension plan (#55)
Browse files Browse the repository at this point in the history
* catch exception if web api is not available

* add tax account

* add investment account

* finalize investment account simulation

* FIX UNIT TESTS

* DO PACKAGE UPGRADE


* use feature flag for full revision support

---------

Co-authored-by: Dieter Niggeler <dniggeler@MacBook-Air-von-Maria.local>
  • Loading branch information
dniggeler and Dieter Niggeler committed Jun 29, 2024
1 parent f5cf499 commit af10b46
Show file tree
Hide file tree
Showing 42 changed files with 256 additions and 145 deletions.
4 changes: 2 additions & 2 deletions src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<ItemGroup>
<PackageReference Include="LanguageExt.Core" Version="4.4.8" />
<PackageReference Include="FluentValidation" Version="11.9.1" />
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="FluentValidation" Version="11.9.2" />
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Application/Bvg/BvgCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private Either<string, BvgCalculationResult> CalculateInternal(int calculationYe
Either<string, BvgCalculationResult> result = new BvgCalculationResult
{
DateOfRetirement = GetRetirementDate(person.DateOfBirth, person.Gender),
RetirementAge = GetRetirementAge(person.Gender, person.DateOfBirth),
EffectiveSalary = salary.EffectiveSalary,
InsuredSalary = salary.InsuredSalary,
RetirementCredit = retirementCredit,
Expand Down
21 changes: 3 additions & 18 deletions src/Application/Bvg/BvgCapitalCalculationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,9 @@ public static IReadOnlyCollection<RetirementCapital> GetRetirementCapitalSequenc

if (retirementDate <= endOfFinancialYear)
{
decimal aghEoYProRata = retirementCapitalEndOfYear;

RetirementCapital aghProRataBoY =
new RetirementCapital(beginOfFinancialYear,
decimal.Zero,
decimal.Zero);
RetirementCapital aghProRataEoY =
new RetirementCapital(endOfFinancialYear,
aghEoYProRata,
aghEoYProRata);

RetirementCapital aghProRataEndOfPeriod =
aghProRataBoY
.Interpolate(true, retirementDate, aghProRataEoY)
.Round60()
.Round();

return List(aghProRataEndOfPeriod);
return [new RetirementCapital(retirementDate,
retirementCapitalEndOfYear,
retirementCapitalEndOfYear)];
}

RetirementCapital retirementCapitalItem = new (endOfFinancialYear, retirementCapitalEndOfYear, retirementCapitalEndOfYear);
Expand Down
5 changes: 3 additions & 2 deletions src/Application/Bvg/BvgRevisionCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,18 @@ private Either<string, BvgCalculationResult> CalculateInternal(int calculationYe
not null => finalRetirementCapital.ValueWithoutInterest
};

decimal retirementPension = RetirementPension(finalRetirementCapitalWithInterest, retirementDate, CurrentBvgCalculatorFunc(retirementCredit));
decimal retirementPension = RetirementPension(finalRetirementCapitalWithInterest, retirementDate, CurrentBvgCalculatorFunc(actualRetirementCapitalEndOfYear));

// reset risk benefits to 0 if below salary threshold
decimal disabilityPension = DisabilityPension(finalRetirementCapitalWithoutInterest, retirementDate, CurrentBvgCalculatorFunc(retirementCredit));
decimal disabilityPension = DisabilityPension(finalRetirementCapitalWithoutInterest, retirementDate, CurrentBvgCalculatorFunc(actualRetirementCapitalEndOfYear));
decimal partnerPension = disabilityPension * Bvg.FactorPartnersPension;
decimal childPension = disabilityPension * Bvg.FactorChildPension;
decimal orphanPension = childPension;

Either<string, BvgCalculationResult> result = new BvgCalculationResult
{
DateOfRetirement = GetRetirementDate(person.DateOfBirth, person.Gender),
RetirementAge = GetRetirementAge(person.Gender, person.DateOfBirth),
EffectiveSalary = person.ReportedSalary,
InsuredSalary = insuredSalary,
RetirementCredit = retirementCredit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage.TestExtensions" Version="4.5.0" />
<PackageReference Include="bunit" Version="1.27.17" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PackageReference Include="bunit" Version="1.28.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorApp.Services.Tests/BlazorApp.Services.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Snapshooter.Xunit" Version="0.14.1" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions src/BlazorApp/BlazorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="LanguageExt.Core" Version="4.4.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.5" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.5" PrivateAssets="all" />
<PackageReference Include="MudBlazor" Version="6.20.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.6" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

Expand Down
7 changes: 4 additions & 3 deletions src/BlazorBvgRevisionApp/BlazorBvgRevisionApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.19.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.FeatureManagement" Version="3.4.0" />
<PackageReference Include="MudBlazor" Version="6.20.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.6" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
27 changes: 16 additions & 11 deletions src/BlazorBvgRevisionApp/MyComponents/BvgPersonForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
@using Domain.Enums

<MudGrid>
<MudItem md="3" xs="6">
<MudNumericField T="int" Label="VA Gültigkeitsjahrdatum" Min="2023" Step="1" @bind-Value="@Person.ValidityYearCertificate" Placeholder="Gültigkeitsjahr" />
<MudItem md="4" xs="12">
<MudNumericField T="int" Label="Ausstellungsjahr" Min="2023" Step="1" @bind-Value="@Person.ValidityYearCertificate"
HelperText="Gültigkeit der Werte auf dem Vorsorgeausweis"
HelperTextOnFocus="true"
Placeholder="Gültigkeitsjahr"/>
</MudItem>

<MudItem md="3" xs="6">
<MudTextField Required="true" RequiredError="" Label="Name" Variant="Variant.Text" @bind-Value="@Person.Name" />
</MudItem>

<MudItem md="3" xs="6">

<MudItem md="4" xs="12">
<MudDatePicker Label="Geburtsdatum" Editable="true" @bind-Date="@Person.DateOfBirth" DateFormat="yyyy-MM-dd" Required="true" RequiredError="" Placeholder="Geburtstag" Mask="@(new DateMask("0000-00-00"))"/>
</MudItem>

<MudItem md="3" xs="6">
<MudItem md="4" xs="12">
<GenderSelector Label="Geschlecht" SelectedGender="@gender" OnSelected="@(SetGender)" />
</MudItem>

Expand All @@ -24,11 +23,17 @@
</MudItem>

<MudItem md="4">
<MudNumericField Label="BVG Alterguthaben Ende des Jahres" Format="n0" Min="0" Step="1000" @bind-Value="Person.BvgRetirementCapitalEndOfYear" Culture="CultureInfo.InvariantCulture"/>
<MudNumericField Label="Kapital Ende Jahr" Format="n0" Min="0" Step="1000" @bind-Value="Person.BvgRetirementCapitalEndOfYear"
HelperTextOnFocus="true"
HelperText="Gesamtes Altersguthaben gemäss BVG"
Culture="CultureInfo.InvariantCulture" />
</MudItem>

<MudItem md="4">
<MudNumericField Label="Alterguthaben PK im Schlussalter" Format="n0" Min="0" Step="1000" @bind-Value="Person.FinalRetirementCapital" Culture="CultureInfo.InvariantCulture"/>
<MudNumericField Label="PK Kapital Schlussalter" Format="n0" Min="0" Step="1000" @bind-Value="Person.FinalRetirementCapital"
HelperTextOnFocus="true"
HelperText="Gesamtes Altersguthaben bei Ihrer Pensionskasse bei Pensionierung"
Culture="CultureInfo.InvariantCulture" />
</MudItem>

</MudGrid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

public class PensionPlanViewModel
{
public decimal InsuredSalary { get; set; }
public decimal? BvgInsuredSalary { get; set; }

public decimal RetirementCapitalEndOfYear { get; set; }
public decimal? BvgRetirementCapitalEndOfYear { get; set; }

public decimal? InsuredSalary { get; set; }

public decimal? RetirementCapitalEndOfYear { get; set; }

public decimal ProjectionInterestRate { get; set; }

Expand Down
41 changes: 33 additions & 8 deletions src/BlazorBvgRevisionApp/MyComponents/PensionPlanForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@
@using BlazorBvgRevisionApp.Pages.Converters

<MudGrid>
<MudItem md="3">
<MudNumericField Label="Versicherter Lohn" Format="n0" Min="0" Step="1000" @bind-Value="PensionPlan.InsuredSalary" Culture="CultureInfo.InvariantCulture" />
<MudItem md="3" xs="12">
<MudNumericField Label="Versicherter Lohn" Format="n0" Min="0" Step="1000" @bind-Value="PensionPlan.InsuredSalary"
HelperTextOnFocus="true"
HelperText="Lohn für die jährlichen Altersgutschriften"
Placeholder=""
Culture="CultureInfo.InvariantCulture" />
</MudItem>

<MudItem md="3">
<MudNumericField Label="PK Guthaben Ende Jahr" Format="n0" Min="0" Step="1000" @bind-Value="PensionPlan.RetirementCapitalEndOfYear" Culture="CultureInfo.InvariantCulture" />
<MudItem md="3" xs="12">
<MudNumericField Label="Guthaben Ende Jahr" Format="n0" Min="0" Step="1000" @bind-Value="PensionPlan.RetirementCapitalEndOfYear"
HelperTextOnFocus="true"
HelperText="Gesamtes Altersguthaben gemäss BVG"
Culture="CultureInfo.InvariantCulture"/>
</MudItem>

<MudItem md="3">
<MudNumericField T="decimal" Label="Projektionszins" Converter="@PercentConverter.DecimalConverter" Format="P2" Min="0M" Step="0.005M" @bind-Value="PensionPlan.ProjectionInterestRate" Culture="CultureInfo.InvariantCulture" />
<MudItem md="3" xs="12">
<MudNumericField T="decimal" Label="Projektionszins" Converter="@PercentConverter.DecimalConverter"
Format="P2"
Min="0M" Max="0.05M" Step="0.005M" @bind-Value="PensionPlan.ProjectionInterestRate"
HelperTextOnFocus="true"
HelperText="Nicht garantierter (fiktiver) Zins auf dem Altersguthaben"
Culture="CultureInfo.InvariantCulture" />
</MudItem>

<MudItem md="3">
<MudNumericField T="decimal" Label="Umwandlungssatz" Converter="@PercentConverter.DecimalConverter" Format="P2" Min="0M" Step="0.005M" @bind-Value="PensionPlan.ConversionRate" Culture="CultureInfo.InvariantCulture" />
<MudItem md="3" xs="12">
<MudNumericField T="decimal" Label="Umwandlungssatz" Converter="@PercentConverter.DecimalConverter" Format="P2" Min="0M" Step="0.001M" @bind-Value="PensionPlan.ConversionRate" Culture="CultureInfo.InvariantCulture" />
</MudItem>

<MudItem md="12">
Expand All @@ -40,4 +52,17 @@

@code {
[Parameter] public required PensionPlanViewModel PensionPlan { get; set; }

protected override void OnParametersSet()
{
if (PensionPlan is { BvgInsuredSalary: not null, InsuredSalary: null })
{
PensionPlan.InsuredSalary = PensionPlan.BvgInsuredSalary;
}

if (PensionPlan is { BvgRetirementCapitalEndOfYear: not null, RetirementCapitalEndOfYear: null })
{
PensionPlan.RetirementCapitalEndOfYear = PensionPlan.BvgRetirementCapitalEndOfYear;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@if (Benefits is not null)
{
<MudTable Items="Benefits" Class="mt-4" Dense="true">
<MudTable Items="Benefits" Class="mt-4" Dense="true" Style="background-color: lightgrey">
<HeaderContent>
<MudTh></MudTh>
<MudTh Style="text-align:right">mit Reform</MudTh>
Expand Down
Loading

0 comments on commit af10b46

Please sign in to comment.