Skip to content

Commit

Permalink
changes to add transaction support in models
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Jan 5, 2024
1 parent 8301f30 commit 2fe1490
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 15 deletions.
38 changes: 35 additions & 3 deletions Shared/Models/FamilyData/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ public string Title {
public int Owner { get; set; }
public string? Identifier { get; set; }
private string? _AccountType;

public Investment? SettlementInvestment {
get {
foreach (var investment in this.Investments)
{
if (investment.AssetType == AssetType.Cash_MoneyMarket
|| investment.AssetType == AssetType.Cash_BankAccount
|| investment.AssetType == AssetType.Cash)
{
return investment;
}
}

return null;
}
}

public string? AccountType {
get { return _AccountType; }
set {
Expand All @@ -63,6 +80,10 @@ public double Value {
foreach (var investment in Investments)
{
newValue += investment.ValuePIN ?? 0;
foreach (var transaction in investment.Transactions)
{
newValue += transaction.CustomValue(investment) ?? 0;
}
}

return newValue;
Expand All @@ -83,6 +104,19 @@ public string FullName
}
}

public Investment? FindInvestment(string ticker)
{
foreach (var investment in Investments)
{
if (investment.Ticker == ticker)
{
return investment;
}
}

return null;
}

public List<Investment> Investments { get; set; }

public List<Investment> AvailableFunds { get; set; }
Expand Down Expand Up @@ -137,8 +171,7 @@ public void UpdatePercentages(double totalValue, FamilyData familyData)
UpdateInvestmentCategoryTotals(investment, familyData);
foreach (var transaction in investment.Transactions)
{
var fromInvestment = (transaction.FromInvestment == investment);
UpdateInvestmentCategoryTotals(investment, familyData, overrideValue:transaction.Value, useNegative:fromInvestment);
UpdateInvestmentCategoryTotals(investment, familyData, overrideValue:transaction.CustomValue(this.FindInvestment(transaction.HostTicker)));
}

if (investment.ExpenseRatio.HasValue && investment.Value.HasValue) {
Expand All @@ -147,7 +180,6 @@ public void UpdatePercentages(double totalValue, FamilyData familyData)
} else {
familyData.InvestmentsMissingER++;
}

}
}

Expand Down
12 changes: 4 additions & 8 deletions Shared/Models/FamilyData/Investment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
public class Investment
{
public Investment() {
Transactions = new();
}

public Investment(int? pin) : this()
Expand All @@ -12,7 +13,8 @@ public Investment(int? pin) : this()
}

[JsonIgnore]
public string Transaction { get; set; }
public Transaction SelectedTransaction { get; set; }

[JsonIgnore]
public bool Selected { get; set; }

Expand All @@ -29,13 +31,7 @@ public string? Name {
}
}

private List<Transaction> _Transactions = new();
public List<Transaction> Transactions
{
get {
return _Transactions;
}
}
public List<Transaction> Transactions { get; set; }

public bool AutoCompleted { get; set; }
private string? _Ticker;
Expand Down
91 changes: 88 additions & 3 deletions Shared/Models/FamilyData/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,94 @@

public class Transaction
{
public string? HostTicker { get; set; }
public string? OtherTicker { get; set; }

[JsonIgnore]
public Investment FromInvestment { get; set; }
public bool Selected { get; set; }

[JsonIgnore]
public Investment ToInvestment { get; set; }
public double? Value { get; set; }
public bool IsDraft { get; set; }

private double? _Value;
private double? _Shares;
private double? _Price;

public double? CustomValue(Investment investment)
{
var ticker = investment.Ticker;
switch (Type)
{
case "Dividend":
if (investment.AssetType == AssetType.Bond || investment.AssetType == AssetType.Bond_ETF || investment.AssetType == AssetType.Bond_Fund)
{
return HostTicker == ticker ? 0 : -Value;
}
else
{
return HostTicker == ticker ? -Value : Value;
}
case "Buy":
return HostTicker == ticker ? Value : -Value;
case "Sale":
return HostTicker == ticker ? -Value : Value;

}

return null;
}

public string? Type { get; set; }

public double? Value {
set {
_Value = value;
if (_Value != null && _Shares != null && _Price == null)
{
_Price = _Value / _Shares;
}

if (_Value != null && _Shares == null && _Price != null)
{
_Shares = _Value / _Price;
}
}
get {
return _Value;
}
}
public double? Shares {
set {
_Shares = value;
if (_Shares != null && _Value != null && _Price == null)
{
_Price = _Value / _Shares;
}

if (_Shares != null && _Value == null && _Price != null)
{
_Value = _Price * _Shares;
}
}
get {
return _Shares;
}
}
public double? Price {
set {
_Price = value;
if (_Price != null &&_Shares != null && _Value == null)
{
_Value = _Price * _Shares;
}

if (_Price != null && _Shares == null && _Value != null)
{
_Shares = _Value / _Price;
}
}
get {
return _Price;
}
}
}
2 changes: 1 addition & 1 deletion wwwroot/cache.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CACHE MANIFEST

# Version 1.0101
# Version 1.0102

NETWORK:
*

0 comments on commit 2fe1490

Please sign in to comment.