This commit is contained in:
2023-07-21 23:01:56 +03:00
parent fa5a8a9001
commit d0cdaa85b6
18 changed files with 863 additions and 178 deletions
+15 -21
View File
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Core.Extensions;
using Data.Repositories.Account;
using Data.Repositories.Currency;
using MyOffice.Data.Models.Accounts;
public class DashboardService
{
@@ -26,30 +27,23 @@ public class DashboardService
public DashboardData GetDashboardRestData(Guid userId)
{
var lastDaysStart = DateTime.UtcNow.AddDays(-7).StartOfDay();
var lastDaysEnd = lastDaysStart.AddDays(7).EndOfDay();
var previousDaysStart = lastDaysStart.AddDays(-7).StartOfDay();
var previousDaysEnd = previousDaysStart.AddDays(7).EndOfDay();
/*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 currencyIds = rests
.Select(x => x.CurrencyId)
.Distinct()
.ToList();
var lastrates = _currencyRateRepository.GetLastRates(currencyIds);
foreach (var rest in rests)
var result = new DashboardData
{
//var rate = lastrates.FirstOrDefault(x => x.CurrencyId == rest.CurrencyId)
}
return new DashboardData
{
IncomeLastWeek = _accountRepository.GetPeriodIncome(userId, lastDaysStart, lastDaysEnd),
IncomePreviousWeek = _accountRepository.GetPeriodIncome(userId, previousDaysStart, previousDaysEnd),
OutcomeLastWeek = _accountRepository.GetPeriodOutcome(userId, lastDaysStart, lastDaysEnd),
OutcomePreviousWeek = _accountRepository.GetPeriodOutcome(userId, previousDaysStart, previousDaysEnd),
Rests = rests,
//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)),
};
return result;
}
}