This commit is contained in:
2023-07-23 20:27:23 +03:00
parent d0cdaa85b6
commit 96eca795ab
62 changed files with 2934 additions and 847 deletions
+27 -11
View File
@@ -27,21 +27,37 @@ public class DashboardService
public DashboardData GetDashboardRestData(Guid userId)
{
/*var lastDaysStart = DateTime.UtcNow.AddMonths(-3).StartOfDay();
var lastDaysEnd = lastDaysStart.AddMonths(3).EndOfDay();
var previousDaysStart = lastDaysStart.AddMonths(-3).StartOfDay();
var previousDaysEnd = previousDaysStart.AddMonths(3).EndOfDay();*/
var rests = _accountRepository.GetRestAtDate(userId, DateTime.UtcNow);
var result = new DashboardData
{
//IncomeLast = _accountRepository.GetPeriodIncome(userId, lastDaysStart, lastDaysEnd),
//IncomePrevious = _accountRepository.GetPeriodIncome(userId, previousDaysStart, previousDaysEnd),
//OutcomeLast = _accountRepository.GetPeriodOutcome(userId, lastDaysStart, lastDaysEnd),
//OutcomePrevious = _accountRepository.GetPeriodOutcome(userId, previousDaysStart, previousDaysEnd),
Balance = rests.Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)),
BalanceDebit = rests.Where(x => x.Balance > 0).Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)),
BalanceCredit = rests.Where(x => x.Balance < 0).Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)),
Balance = rests
.Where(x => (x.Type == AccountAccessTypeEnum.balance || x.Type == AccountAccessTypeEnum.credit) && x.CurrencyRate.HasValue)
.Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)),
BalanceDebit = rests
.Where(x => x.Type == AccountAccessTypeEnum.balance && x.CurrencyRate.HasValue)
.Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)),
BalanceCredit = rests
.Where(x => x.Type == AccountAccessTypeEnum.credit && x.CurrencyRate.HasValue)
.Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)),
BalanceRests = rests
.Where(x => x.Type == AccountAccessTypeEnum.balance)
.Where(x => x.CurrencyRate.HasValue && x.Balance.HasValue && x.Balance != 0)
.Select(x => new DashboardRestData
{
Id = x.Id,
Name = x.Name,
Balance = x.Balance,
CurrencyName = x.CurrencyName,
CurrencyShortName = x.CurrencyShortName,
CurrencyRate = x.CurrencyRate,
CurrencyQuantity = x.CurrencyQuantity,
})
.OrderByDescending(x => x.BalanceAtRate)
.ToList(),
};
return result;