WIP
This commit is contained in:
1 parent
2bfe914c8f
commit
4281924ee5
16 files changed
+369
-76
No files matched your search
@@ -67,6 +67,26 @@ public partial class Home
|
||||
private int RecentTotalPages => (int)Math.Ceiling(FilteredRecent.Count / (double)PageSize);
|
||||
private int UpcomingTotalPages => (int)Math.Ceiling(FilteredUpcoming.Count / (double)PageSize);
|
||||
|
||||
private DateTime? _nextPayday;
|
||||
private Dictionary<int, decimal> _predictedPaydayBalances = new();
|
||||
|
||||
private IEnumerable<IGrouping<DateTime, Transaction>> GroupedRecentPage =>
|
||||
FilteredRecent
|
||||
.Skip((_recentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.GroupBy(t => t.Date.Date)
|
||||
.OrderByDescending(g => g.Key);
|
||||
|
||||
private IEnumerable<IGrouping<DateTime, Transaction>> GroupedUpcomingPage =>
|
||||
FilteredUpcoming
|
||||
.Skip((_upcomingPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.GroupBy(t => t.Date.Date)
|
||||
.OrderBy(g => g.Key);
|
||||
|
||||
private static IOrderedEnumerable<Transaction> OrderGroupByIncomeFirst(IGrouping<DateTime, Transaction> group) =>
|
||||
group.OrderByDescending(t => t.Type == TransactionType.Income).ThenBy(t => t.Description);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||||
@@ -291,14 +311,48 @@ public partial class Home
|
||||
private async Task RefreshData()
|
||||
{
|
||||
if (_userId is null) return;
|
||||
await SalaryService.MaterializeSalaryTransactionsAsync(_userId, _windowEnd);
|
||||
var materializeEnd = _windowEnd > DateTime.Today.AddDays(90) ? _windowEnd : DateTime.Today.AddDays(90);
|
||||
await SalaryService.MaterializeSalaryTransactionsAsync(_userId, materializeEnd);
|
||||
_data = await DashboardService.GetDashboardDataAsync(_userId, _windowStart, _windowEnd);
|
||||
_chartDataVersion++;
|
||||
ComputeProjectedBalances();
|
||||
await ComputeNextPaydayBalance();
|
||||
_recentPage = 1;
|
||||
_upcomingPage = 1;
|
||||
}
|
||||
|
||||
private async Task ComputeNextPaydayBalance()
|
||||
{
|
||||
_nextPayday = null;
|
||||
_predictedPaydayBalances.Clear();
|
||||
if (_data is null || _userId is null) return;
|
||||
|
||||
var salaries = await SalaryService.GetSalariesAsync(_userId);
|
||||
DateTime? soonest = null;
|
||||
foreach (var s in salaries)
|
||||
{
|
||||
var next = await SalaryService.GetNextPaydateAsync(s.Id);
|
||||
if (next.HasValue && next.Value.Date > DateTime.Today)
|
||||
{
|
||||
if (soonest is null || next.Value.Date < soonest.Value.Date)
|
||||
soonest = next.Value.Date;
|
||||
}
|
||||
}
|
||||
_nextPayday = soonest;
|
||||
if (_nextPayday is null) return;
|
||||
|
||||
var txnsToPayday = await TransactionService.GetTransactionsInRangeAsync(
|
||||
_userId, DateTime.Today.AddDays(1), _nextPayday.Value);
|
||||
|
||||
foreach (var account in _data.Accounts)
|
||||
{
|
||||
var balance = account.CurrentBalance;
|
||||
foreach (var t in txnsToPayday.Where(t => t.AccountId == account.Id && !t.IsPaid))
|
||||
balance += t.Type == TransactionType.Income ? t.Amount : -t.Amount;
|
||||
_predictedPaydayBalances[account.Id] = balance;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetWindow(int days)
|
||||
{
|
||||
_windowPreset = days switch { 7 => "7d", 30 => "30d", 90 => "90d", 365 => "1y", _ => "custom" };
|
||||
|
||||
Reference in new issue
Block a user