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
+11 -4
View File
@@ -1,6 +1,7 @@
namespace MyOffice.Services.Currency;
using Core;
using Core.Extensions;
using Data.Models.Currencies;
using Data.Repositories.Currency;
using MyOffice.Services.Currency.Domain;
@@ -37,7 +38,7 @@ public class CurrencyService
var list = _currencyRepository.GetAll(userId);
return list.ToDictionary(
x => x,
x => _currencyRateRepository.GetLastRates(x.Id, 1).FirstOrDefault()
x => _currencyRateRepository.GetLastRates(x.Id).FirstOrDefault()
);
}
@@ -113,13 +114,13 @@ public class CurrencyService
var result = new Exec<CurrencyRate, CurrencyAddRateStatus>(CurrencyAddRateStatus.success);
var exists = _currencyRepository.Get(userId, currencyId);
if (exists == null)
var currency = _currencyRepository.Get(userId, currencyId);
if (currency == null)
{
return result.Set(CurrencyAddRateStatus.not_found);
}
currencyRate.CurrencyId = exists.Id;
currencyRate.CurrencyId = currency.Id;
currencyRate.DateTime = currencyRate.DateTime.Date;
var rates = _currencyRateRepository.GetAtDate(currencyRate.CurrencyId, currencyRate.DateTime);
@@ -132,6 +133,12 @@ public class CurrencyService
}
rate = currencyRate;
if (rate.DateTime.EndOfDay() <= DateTime.UtcNow.EndOfDay())
{
currency.CurrentRateId = rate.Id;
_currencyRepository.Update(currency);
}
}
return result.Set(rate);
+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;
}
}
@@ -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);
}