This commit is contained in:
2023-08-04 17:53:15 +03:00
parent cf89dd6a4d
commit 70edf34cf6
17 changed files with 236 additions and 86 deletions
@@ -3,6 +3,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Models.Accounts;
using MyOffice.Data.Models.Currencies;
using MyOffice.Data.Repositories;
public class AccountRepository : AppRepository<Account>, IAccountRepository
@@ -184,8 +185,8 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
Id = x.Id,
Name = x.Name,
Type = x.Type,
CurrencyName = x.Currency!.Name,
CurrencyShortName = x.Currency!.ShortName,
CurrencyName = x.Currency?.Name,
CurrencyShortName = x.Currency?.ShortName,
CurrencyRate = x.CurrentRate?.Rate,
CurrencyQuantity = x.CurrentRate?.Quantity,
TotalMinus = x.Minus,
@@ -201,12 +202,19 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
.Where(x => x.DateTime >= from && x.DateTime <= to)
.Where(x => x.Item.Category!.UserId == userId)
.Where(x => !x.Item.Category!.IsInternal)
.GroupBy(x => new { x.Item.CategoryId, x.Item.Category!.Name })
.GroupBy(x => new
{
ItemId = x.Item.CategoryId,
ItemName = x.Item.Category!.Name,
CurrencyId = x.Account.CurrencyGlobalId,
CurrencyName = x.Account.CurrencyGlobal!.Name,
})
.Select(x => new MotionTotalSimple
{
Id = x.Key.CategoryId,
Name = x.Key.Name,
Amount = x.Sum(a => a.AmountPlus)
CurrencyId = x.Key.CurrencyId,
CurrencyName = x.Key.CurrencyName,
Name = x.Key.ItemName,
Amount = x.Sum(a => a.AmountPlus),
}).ToList();
}
@@ -217,10 +225,18 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
.Where(x => x.Item.CategoryId == categoryId)
.Where(x => !x.Item.Category!.IsInternal)
.Where(x => x.Item.Category!.UserId == userId)
.GroupBy(x => new { Id = x.Item.ItemGlobalId, x.Item.ItemGlobal.Name })
.GroupBy(x => new
{
ItemId = x.Item.ItemGlobalId,
ItemName = x.Item.ItemGlobal!.Name,
CurrencyId = x.Account.CurrencyGlobalId,
CurrencyName = x.Account.CurrencyGlobal!.Name,
})
.Select(x => new MotionTotalSimple
{
Name = x.Key.Name,
CurrencyId = x.Key.CurrencyId,
CurrencyName = x.Key.CurrencyName,
Name = x.Key.ItemName,
Amount = x.Sum(a => a.AmountPlus),
}).ToList();
}
@@ -232,12 +248,20 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
.Where(x => x.DateTime >= from && x.DateTime <= to)
.Where(x => x.Item.Category!.UserId == userId)
.Where(x => !x.Item.Category!.IsInternal)
.GroupBy(x => new { x.Item.CategoryId, x.Item.Category!.Name })
.GroupBy(x => new
{
ItemId = x.Item.CategoryId,
ItemName = x.Item.Category!.Name,
CurrencyId = x.Account.CurrencyGlobalId,
CurrencyName = x.Account.CurrencyGlobal!.Name,
})
.Select(x => new MotionTotalSimple
{
Id = x.Key.CategoryId,
Name = x.Key.Name,
Amount = x.Sum(a => a.AmountMinus)
Id = x.Key.ItemId,
Name = x.Key.ItemName,
CurrencyId = x.Key.CurrencyId,
CurrencyName = x.Key.CurrencyName,
Amount = x.Sum(a => a.AmountPlus),
}).ToList();
}
@@ -1,5 +1,6 @@
namespace MyOffice.Data.Repositories.Currency;
using System.Xml.Schema;
using Microsoft.EntityFrameworkCore;
using Models.Currencies;
@@ -18,18 +19,23 @@ public class CurrencyRateRepository : AppRepository<CurrencyRate>, ICurrencyRate
.ToList();
}
public List<CurrencyRate> GetLastRates(List<string> currencyIds)
public Dictionary<string, CurrencyRate> GetLastRates(Guid userId, List<string> currencyIds, DateTime? before = null)
{
return _context.CurrencyRates
.Include(x => x.Currency)
.Include(x => x.Currency!.CurrencyGlobal)
.Where(x => x.DateTime <= before)
.Where(x => x.Currency!.UserId == userId)
.Where(x => currencyIds.Contains(x.Currency!.CurrencyGlobalId))
.GroupBy(x => new
{
x.CurrencyId,
//x.Currency!.Name,
//x.Currency!.CurrencyGlobalId,
}, (key, g) => g.OrderByDescending(x => x.DateTime).First())
.ToList();
x.Currency!.CurrencyGlobalId
}, (key, g) => new
{
key.CurrencyGlobalId,
rate = g.OrderByDescending(x => x.DateTime).First()
})
.ToDictionary(x => x.CurrencyGlobalId, x => x.rate);
}
public bool AddRate(CurrencyRate currencyRate)
@@ -5,7 +5,7 @@ using Models.Currencies;
public interface ICurrencyRateRepository
{
List<CurrencyRate> GetLastRates(Guid currencyId, DateTime? before = null, int count = 1);
List<CurrencyRate> GetLastRates(List<string> currencyIds);
Dictionary<string, CurrencyRate> GetLastRates(Guid userId, List<string> currencyIds, DateTime? before = null);
bool AddRate(CurrencyRate currencyRate);
List<CurrencyRate> GetAtDate(Guid currencyId, DateTime date);
}