fix
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
namespace MyOffice.Services.Dashboard.Domain;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using Data.Models.Accounts;
|
||||
|
||||
public class DashboardData
|
||||
{
|
||||
public decimal IncomeLastWeek { get; set; }
|
||||
public decimal IncomePreviousWeek { get; set; }
|
||||
public decimal OutcomeLastWeek { get; set; }
|
||||
public decimal OutcomePreviousWeek { get; set; }
|
||||
public List<AccountSimple>? Rests { get; set; }
|
||||
public decimal? RestTotal => Rests?.Sum(x => x.Rest);
|
||||
public decimal? RestTotalPlus => Rests?.Where(x => x.Rest > 0).Sum(x => x.Rest);
|
||||
public decimal? RestTotalMinus => Rests?.Where(x => x.Rest < 0).Sum(x => x.Rest);
|
||||
public decimal IncomeLast { get; set; }
|
||||
public decimal IncomePrevious { get; set; }
|
||||
public decimal OutcomeLast { get; set; }
|
||||
public decimal OutcomePrevious { get; set; }
|
||||
public decimal? Balance { get; set; }
|
||||
public decimal? BalanceDebit { get; set; }
|
||||
public decimal? BalanceCredit { get; set; }
|
||||
}
|
||||
|
||||
/*public class DashboardRestData
|
||||
public class DashboardRestData
|
||||
{
|
||||
public string AccountId { get; set; }
|
||||
public string AccountName { get; set; }
|
||||
public decimal Rest { get; set; }
|
||||
}*/
|
||||
public AccountSimple AccountSimple { get; set; }
|
||||
public decimal? Balance => AccountSimple.Balance;
|
||||
|
||||
public decimal? BalanceAtRate =>
|
||||
AccountSimple.Balance * (AccountSimple.CurrencyRate * AccountSimple.CurrencyQuantity);
|
||||
}
|
||||
Reference in New Issue
Block a user