From 25184e9edc87c9b0ff26e1fbbe8b7bbc0017b213 Mon Sep 17 00:00:00 2001 From: Alexandr Sulimov Date: Fri, 4 Aug 2023 21:32:40 +0300 Subject: [PATCH] fix --- .../Account/AccountRepository.cs | 3 +- .../dashboard/income/dashboard.component.html | 10 ++- .../dashboard/income/dashboard.component.ts | 3 + .../outcome/dashboard.component.html | 10 ++- .../dashboard/outcome/dashboard.component.ts | 3 + .../Dashboard/DashboardService.cs | 80 ++++++++++++++----- 6 files changed, 83 insertions(+), 26 deletions(-) diff --git a/MyOffice.Data.Repositories/Account/AccountRepository.cs b/MyOffice.Data.Repositories/Account/AccountRepository.cs index 515cc05..92a1e54 100644 --- a/MyOffice.Data.Repositories/Account/AccountRepository.cs +++ b/MyOffice.Data.Repositories/Account/AccountRepository.cs @@ -223,6 +223,7 @@ public class AccountRepository : AppRepository, IAccountRepository { return _context.Motions .Where(x => x.DateTime >= from && x.DateTime <= to) + .Where(x => x.Item.Category!.UserId == userId) .Where(x => x.Item.CategoryId == categoryId) .Where(x => !x.Item.Category!.IsInternal) .Where(x => x.Item.Category!.UserId == userId) @@ -235,9 +236,9 @@ public class AccountRepository : AppRepository, IAccountRepository }) .Select(x => new MotionTotalSimple { + Name = x.Key.Name, CurrencyId = x.Key.CurrencyId, CurrencyName = x.Key.CurrencyName, - Name = x.Key.Name, Amount = x.Sum(a => a.AmountPlus), }) .ToList(); diff --git a/MyOffice.SPA/src/app/dashboard/income/dashboard.component.html b/MyOffice.SPA/src/app/dashboard/income/dashboard.component.html index 2a68e28..0a55e51 100644 --- a/MyOffice.SPA/src/app/dashboard/income/dashboard.component.html +++ b/MyOffice.SPA/src/app/dashboard/income/dashboard.component.html @@ -50,8 +50,14 @@ - - + + + + + + + +
{{item.currency}}{{item.value | number: '1.2'}} ({{item.valueRaw}}) {{item.name}}{{item.valueRaw | number: '1.2'}}{{item.value | number: '1.2'}}
{{'TOTAL' | translate}}{{total | number: '1.2'}}
diff --git a/MyOffice.SPA/src/app/dashboard/income/dashboard.component.ts b/MyOffice.SPA/src/app/dashboard/income/dashboard.component.ts index f22d37b..6ad6d33 100644 --- a/MyOffice.SPA/src/app/dashboard/income/dashboard.component.ts +++ b/MyOffice.SPA/src/app/dashboard/income/dashboard.component.ts @@ -41,6 +41,7 @@ export class DashboardIncomeComponent implements OnInit { @ViewChild("chart") chart!: ChartComponent; public chartOptions!: Partial; dashboardModel?: DashboardInOutModel; + total?: number; public dateFrom: Date = moment(new Date).add(-30, 'days').toDate(); public dateTo: Date = moment(new Date).add(0, 'days').toDate(); @@ -91,6 +92,8 @@ export class DashboardIncomeComponent implements OnInit { }); } + this.total = response.data.reduce((sum, current) => sum + current.value, 0); + if (update) { this.chart.updateSeries([{ data: series diff --git a/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.html b/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.html index 82fcc1f..d372db6 100644 --- a/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.html +++ b/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.html @@ -50,8 +50,14 @@ - - + + + + + + + +
{{item.currency}}{{item.value | number: '1.2'}} ({{item.valueRaw}}) {{item.name}}{{item.valueRaw | number: '1.2'}}{{item.value | number: '1.2'}}
{{'TOTAL' | translate}}{{total | number: '1.2'}}
diff --git a/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.ts b/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.ts index 8c23296..8d1e872 100644 --- a/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.ts +++ b/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.ts @@ -42,6 +42,7 @@ export class DashboardOutcomeComponent implements OnInit { @ViewChild("chart") chart!: ChartComponent; public chartOptions!: Partial; dashboardModel?: DashboardInOutModel; + total?: number; public dateFrom: Date = moment(new Date).add(-30, 'days').toDate(); public dateTo: Date = moment(new Date).add(0, 'days').toDate(); @@ -97,6 +98,8 @@ export class DashboardOutcomeComponent implements OnInit { }); } + this.total = response.data.reduce((sum, current) => sum + current.value, 0); + if (update) { this.chart.updateSeries([{ data: series diff --git a/MyOffice.Services/Dashboard/DashboardService.cs b/MyOffice.Services/Dashboard/DashboardService.cs index f5efa24..125c47b 100644 --- a/MyOffice.Services/Dashboard/DashboardService.cs +++ b/MyOffice.Services/Dashboard/DashboardService.cs @@ -53,8 +53,8 @@ public class DashboardService Id = x.Id, Name = x.Name, Balance = x.Balance, - CurrencyName = x.CurrencyName, - CurrencyShortName = x.CurrencyShortName, + CurrencyName = x.CurrencyName!, + CurrencyShortName = x.CurrencyShortName!, CurrencyRate = x.CurrencyRate, CurrencyQuantity = x.CurrencyQuantity, }) @@ -76,7 +76,6 @@ public class DashboardService .ToList(); var currencies = data - .Where(x => x.Amount != 0) .Select(x => x.CurrencyId) .Distinct() .ToList(); @@ -87,29 +86,49 @@ public class DashboardService return new DashboardIncomeData { - Data = data.Select(x => new + Data = data.Select(x => new { Id = x.Id.ToShort(), Name = x.Name, + ValueRaw = x.Amount, Value = (x.Amount * rates.FirstOrDefault(r => r.Key == x.CurrencyId).Value), }) - .GroupBy(x => new { x.Id, x.Name }) - .Select( x => new DashboardIncomeDataItem + .GroupBy(x => new + { + x.Id, + x.Name, + }) + .Select(x => new DashboardIncomeDataItem { Id = x.Key.Id, Name = x.Key.Name, Value = x.Sum(s => s.Value), + ValueRaw = x.Sum(s => s.ValueRaw), }) + .OrderBy(x => x.Name) .ToList(), - Details = data.Select(x => new DashboardIncomeDataItem + Details = data.Select(x => new { - Id = x.Id.ToShort(), - Currency = x.CurrencyId, - Name = x.Name, + Id = x.CurrencyId, + Name = x.CurrencyName, ValueRaw = x.Amount, Value = (x.Amount * rates.FirstOrDefault(r => r.Key == x.CurrencyId).Value), - }).ToList() + }) + .GroupBy(x => new + { + x.Id, + x.Name, + }) + .Select(x => new DashboardIncomeDataItem + { + Id = x.Key.Id, + Name = x.Key.Name, + Value = x.Sum(s => s.Value), + ValueRaw = x.Sum(s => s.ValueRaw), + }) + .OrderBy(x => x.Name) + .ToList(), }; } @@ -124,7 +143,6 @@ public class DashboardService .ToList(); var currencies = data - .Where(x => x.Amount != 0) .Select(x => x.CurrencyId) .Distinct() .ToList(); @@ -139,25 +157,45 @@ public class DashboardService { Id = x.Id.ToShort(), Name = x.Name, + ValueRaw = x.Amount, Value = (x.Amount * rates.FirstOrDefault(r => r.Key == x.CurrencyId).Value), }) - .GroupBy(x => new { x.Id, x.Name }) + .GroupBy(x => new + { + x.Id, + x.Name, + }) .Select(x => new DashboardIncomeDataItem { Id = x.Key.Id, Name = x.Key.Name, Value = x.Sum(s => s.Value), + ValueRaw = x.Sum(s => s.ValueRaw), }) + .OrderBy(x => x.Name) .ToList(), - Details = data.Select(x => new DashboardIncomeDataItem - { - Id = x.Id.ToShort(), - Currency = x.CurrencyId, - Name = x.Name, - ValueRaw = x.Amount, - Value = (x.Amount * rates.FirstOrDefault(r => r.Key == x.CurrencyId).Value), - }).ToList() + Details = data.Select(x => new + { + Id = x.CurrencyId, + Name = x.CurrencyName, + ValueRaw = x.Amount, + Value = (x.Amount * rates.FirstOrDefault(r => r.Key == x.CurrencyId).Value), + }) + .GroupBy(x => new + { + x.Id, + x.Name, + }) + .Select(x => new DashboardIncomeDataItem + { + Id = x.Key.Id, + Name = x.Key.Name, + Value = x.Sum(s => s.Value), + ValueRaw = x.Sum(s => s.ValueRaw), + }) + .OrderBy(x => x.Name) + .ToList(), }; } }