Skip to content

Commit

Permalink
back pointers: investment, emergencyfund. familydata.ValueInXUnits. l…
Browse files Browse the repository at this point in the history
…astupdated + 15min.
  • Loading branch information
rrelyea committed Mar 7, 2024
1 parent f573af2 commit 0a32877
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 26 deletions.
14 changes: 14 additions & 0 deletions library/Models/FamilyData/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ public string TaxType2 {
}
}

public int TaxTypeOrder
{
get
{
return TaxType2 switch
{
"Pre-Tax" => 1,
"Taxable" => 2,
"Post-Tax" => 3,
_ => 4
};
}
}

public int PortfolioReviewOrder {
get {
var ownerCategory = (Owner + 1) * 7; // 7=Joint, 14=First Person, 21= Second Person
Expand Down
68 changes: 53 additions & 15 deletions library/Models/FamilyData/EmergencyFund.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,62 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;

namespace Models;

public class EmergencyFund {
public class EmergencyFund : INotifyPropertyChanged
{
protected void OnPropertyChanged([CallerMemberName] string? name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public event PropertyChangedEventHandler? PropertyChanged;

[JsonIgnore] internal FamilyData? FamilyData { get; private set; }

public void SetBackPointer(FamilyData familyData) { FamilyData = familyData; }

[Required]
public int? CurrentBalance { get; set; }

[Required]
public int? MonthlyExpenses { get; set;}

public int? AmountToSave {
private int? monthlyExpenses;
public int? MonthlyExpenses
{
get { return monthlyExpenses; }
set
{
monthlyExpenses = value;
OnPropertyChanged();
OnPropertyChanged(nameof(AnnualExpenses));
if (FamilyData != null)
{
FamilyData.UpdateValueInXUnits();
}
}
}

public int? AnnualExpenses { get => MonthlyExpenses * 12; }

public int? AmountToSave
{
get { return TargetMonths * MonthlyExpenses - CurrentBalance; }
}

public string CurrentMonthsString {
get {
public string CurrentMonthsString
{
get
{
return String.Format("{0:#,0.#}", CurrentMonths);
}
}

public double? CurrentMonths {
public double? CurrentMonths
{
get { return (double?)CurrentBalance / (double?)MonthlyExpenses; }
}

public int TargetMonths {get;set;} = 3;
public int TargetMonths { get; set; } = 3;

[DefaultValue(false)]
public bool ShowDollars { get; set; }
Expand All @@ -33,13 +65,19 @@ public double? CurrentMonths {
public string? FreeformAnswer { get; set; } = null;
public string? AnswerType { get; set; }

public string? Answer {
get {
switch (AnswerType) {
public string? Answer
{
get
{
switch (AnswerType)
{
case "months":
if (CurrentMonths != null) {
return $"{CurrentMonths} months";
} else {
if (CurrentMonths != null)
{
return $"{CurrentMonths} months";
}
else
{
return $"missing data";
}
case "dollars":
Expand Down
43 changes: 41 additions & 2 deletions library/Models/FamilyData/FamilyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public FamilyData(IAppData appData)
People = [];
Questions = [];
RetirementData = new();
EmergencyFund = new();

People.Add(new Person() { Identifier = "person 1", FamilyData = this, PersonIndex = 0 });
People.Add(new Person() { Identifier = "person 2", FamilyData = this, PersonIndex = 1 });
Expand All @@ -40,6 +41,8 @@ public void SetBackPointers()
person.PersonIndex = personIndex;
person.SetBackPointers(this);
}

EmergencyFund.SetBackPointer(this);
}

[JsonIgnore]
Expand All @@ -50,7 +53,7 @@ public void SetBackPointers()

public string? Title { get; set; }
public RetirementData RetirementData { get; set; }
public EmergencyFund EmergencyFund { get; set; } = new();
public EmergencyFund EmergencyFund { get; set; }

public bool DebtsComplete
{
Expand All @@ -60,6 +63,8 @@ public bool DebtsComplete
}
}

public double? ValueInXUnits { get { return valueInXUnits; } set { valueInXUnits = value; OnPropertyChanged(); } }

public TriState DebtFree { get; set; }
public List<Debt> Debts { get; set; }

Expand Down Expand Up @@ -256,6 +261,16 @@ public double ActualStockAllocation
}
}

[JsonIgnore] // added in 2/2024...but want to stop now.
public double ActualFixedAssetsAllocation
{
get
{
return ActualBondAllocation + ActualCashAllocation;
}
}


private double _ActualBondAllocation;
[JsonIgnore] // added in 2/2024...but want to stop now.
public double ActualBondAllocation
Expand All @@ -268,6 +283,7 @@ public double ActualBondAllocation
{
_ActualBondAllocation = value;
OnPropertyChanged();
OnPropertyChanged("ActualFixedAssetsAllocation");
}
}

Expand Down Expand Up @@ -298,6 +314,7 @@ public double ActualCashAllocation
{
_ActualCashAllocation = value;
OnPropertyChanged();
OnPropertyChanged("ActualFixedAssetsAllocation");
}
}

Expand Down Expand Up @@ -333,6 +350,7 @@ public double Value
{
_Value = value;
OnPropertyChanged();
UpdateValueInXUnits();
}
}

Expand Down Expand Up @@ -578,6 +596,8 @@ public async Task UpdatePercentagesAsync()
}
Value = totalValue;

UpdateValueInXUnits();

foreach (var account in Accounts)
{
account.Percentage = account.Value / totalValue * 100;
Expand Down Expand Up @@ -703,6 +723,7 @@ public int PersonCount

[JsonIgnore]
public SortedDictionary<string, List<Investment>>? TickersToUpdate;
private double? valueInXUnits;

public async Task RefreshPrices(HttpClient http)
{
Expand Down Expand Up @@ -813,7 +834,14 @@ public static void UpdateInvestmentsPrice(List<Investment> investments, double?
investment.Price = price;
investment.PreviousClose = previousClose;
investment.PercentChange = percentChange;
investment.LastUpdated = lastUpdated;
if (lastUpdated.HasValue)
{
investment.LastUpdated = lastUpdated.Value.AddMinutes(15);
}
else
{
investment.LastUpdated = lastUpdated;
}

investment.UpdateValue();
}
Expand Down Expand Up @@ -943,4 +971,15 @@ private static MarketDay GetMarketDay(DateTime dateTime)
return MarketDay.MarketDay;
}
}

internal void UpdateValueInXUnits()
{
double? valueInXUnits = (double)(Value) / (double)(EmergencyFund.AnnualExpenses ?? 0.0);
if (valueInXUnits.HasValue && (double.IsNaN(valueInXUnits.Value) || double.IsInfinity(valueInXUnits.Value)))
{
valueInXUnits = null;
}

ValueInXUnits = valueInXUnits;
}
}
5 changes: 5 additions & 0 deletions library/Models/FamilyData/Investment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ AssetTypes.InternationalBond or
}
}

[JsonIgnore]
public string? AccountName { get; set; }

public bool IsAccountHeader { get { return AccountName != null; } }

[JsonIgnore]
public bool IsAssetTypeUnknown
{
Expand Down
9 changes: 1 addition & 8 deletions library/Models/Group.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using DocumentFormat.OpenXml.Presentation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models;
namespace Models;

public class Group<T, U>(T groupInfo, List<U> items) : List<U>(items) where U : class
{
Expand Down
2 changes: 1 addition & 1 deletion src.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "src", "src.csproj", "{28B10
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api", "api\api.csproj", "{519B0E10-3FC1-4F2D-9A6D-EC465728C8E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "library", "library\library.csproj", "{EA2E6D14-91D2-4580-8994-A414F18DDDFF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "library", "library\25XLibrary.csproj", "{EA2E6D14-91D2-4580-8994-A414F18DDDFF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit 0a32877

Please sign in to comment.