This commit is contained in:
2023-08-03 08:58:53 +03:00
parent c82f8e3537
commit ad31d3ffce
30 changed files with 697 additions and 24 deletions
@@ -4,6 +4,7 @@ using MyOffice.Services.Dashboard.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Core.Extensions;
@@ -34,11 +35,11 @@ public class DashboardService
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)),
@@ -62,4 +63,38 @@ public class DashboardService
return result;
}
public DashboardIncomeData GetDashboardIncomeData(Guid userId, DateTime from, DateTime to, Guid? category)
{
var data = category.HasValue
? _accountRepository.GetIncomeByCategory(userId, category.Value, from.ToUtc(), to.ToUtc())
: _accountRepository.GetIncomeByCategories(userId, from.ToUtc(), to.ToUtc());
return new DashboardIncomeData
{
Data = data.Select(x => new DashboardIncomeDataItem
{
Id = x.Id?.ToShort(),
Name = x.Name,
Value = x.Amount,
}).ToList()
};
}
public DashboardIncomeData GetDashboardOutcomeData(Guid userId, DateTime from, DateTime to, Guid? category)
{
var data = category.HasValue
? _accountRepository.GetOutcomeByCategory(userId, category.Value, from.ToUtc(), to.ToUtc())
: _accountRepository.GetOutcomeByCategories(userId, from.ToUtc(), to.ToUtc());
return new DashboardIncomeData
{
Data = data.Select(x => new DashboardIncomeDataItem
{
Id = x.Id?.ToShort(),
Name = x.Name,
Value = x.Amount,
}).ToList()
};
}
}