private static decimal CalculateTrackedSavingLedgersContributions(StatementModel statement,
IEnumerable<BudgetBucket> trackedSavingsLedgers)
{
decimal savingsToDate = 0;
foreach (var bucket in trackedSavingsLedgers)
{
List<Transaction> transactions = statement.Transactions.Where(t => t.BudgetBucket == bucket).ToList();
// This will give interest earned. This is because the transaction list will contain both debits and credits for transfering the savings around.
savingsToDate += transactions.Sum(t => t.Amount);
// This will give the savings credited.
IEnumerable<IGrouping<decimal, decimal>> amounts = transactions
.Select(t => Math.Abs(t.Amount))
.GroupBy(amount => amount, amount => amount)
.Where(group => @group.Count() > 1);
savingsToDate += amounts.Distinct().Sum(g => g.Key);
}
return savingsToDate;
}