From 70edf34cf63606747ba6977ae5bc17ef48f05e2b Mon Sep 17 00:00:00 2001 From: Alexandr Sulimov Date: Fri, 4 Aug 2023 17:53:15 +0300 Subject: [PATCH] fix --- .../Account/AccountRepository.cs | 48 +++++++++++---- .../Currency/CurrencyRateRepository.cs | 18 ++++-- .../Currency/ICurrencyRateRepository.cs | 2 +- .../authentication/locked/locked.component.ts | 2 +- .../dashboard/income/dashboard.component.html | 55 ++++++------------ .../dashboard/income/dashboard.component.ts | 23 +++++++- .../outcome/dashboard.component.html | 13 +++++ .../dashboard/outcome/dashboard.component.ts | 5 -- .../src/app/layout/header/header.component.ts | 2 +- .../app/layout/sidebar/sidebar.component.html | 2 +- MyOffice.SPA/src/app/model/dashboard.model.ts | 3 + .../settings/currency/currency.component.html | 3 + .../settings/currency/currency.component.ts | 58 ++++++++++++++----- MyOffice.Services/Currency/CurrencyService.cs | 18 ++++++ .../Dashboard/DashboardService.cs | 44 +++++++++++++- .../Dashboard/Domain/DashboardData.cs | 5 +- .../Controllers/CurrencyController.cs | 21 +++++++ 17 files changed, 236 insertions(+), 86 deletions(-) diff --git a/MyOffice.Data.Repositories/Account/AccountRepository.cs b/MyOffice.Data.Repositories/Account/AccountRepository.cs index 70f7ae6..e2dabc6 100644 --- a/MyOffice.Data.Repositories/Account/AccountRepository.cs +++ b/MyOffice.Data.Repositories/Account/AccountRepository.cs @@ -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, IAccountRepository @@ -184,8 +185,8 @@ public class AccountRepository : AppRepository, 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, 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, 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, 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(); } diff --git a/MyOffice.Data.Repositories/Currency/CurrencyRateRepository.cs b/MyOffice.Data.Repositories/Currency/CurrencyRateRepository.cs index ddbcd08..f51f3bb 100644 --- a/MyOffice.Data.Repositories/Currency/CurrencyRateRepository.cs +++ b/MyOffice.Data.Repositories/Currency/CurrencyRateRepository.cs @@ -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, ICurrencyRate .ToList(); } - public List GetLastRates(List currencyIds) + public Dictionary GetLastRates(Guid userId, List 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) diff --git a/MyOffice.Data.Repositories/Currency/ICurrencyRateRepository.cs b/MyOffice.Data.Repositories/Currency/ICurrencyRateRepository.cs index e8806ac..b8efda4 100644 --- a/MyOffice.Data.Repositories/Currency/ICurrencyRateRepository.cs +++ b/MyOffice.Data.Repositories/Currency/ICurrencyRateRepository.cs @@ -5,7 +5,7 @@ using Models.Currencies; public interface ICurrencyRateRepository { List GetLastRates(Guid currencyId, DateTime? before = null, int count = 1); - List GetLastRates(List currencyIds); + Dictionary GetLastRates(Guid userId, List currencyIds, DateTime? before = null); bool AddRate(CurrencyRate currencyRate); List GetAtDate(Guid currencyId, DateTime date); } \ No newline at end of file diff --git a/MyOffice.SPA/src/app/authentication/locked/locked.component.ts b/MyOffice.SPA/src/app/authentication/locked/locked.component.ts index 0fff4d2..0f970f6 100644 --- a/MyOffice.SPA/src/app/authentication/locked/locked.component.ts +++ b/MyOffice.SPA/src/app/authentication/locked/locked.component.ts @@ -45,7 +45,7 @@ export class LockedComponent implements OnInit { if (this.authForm.invalid) { return; } else { - this.router.navigate(['/dashboard/dashboard']); + this.router.navigate(['/dashboard/rests']); } } } diff --git a/MyOffice.SPA/src/app/dashboard/income/dashboard.component.html b/MyOffice.SPA/src/app/dashboard/income/dashboard.component.html index 5792652..f24e952 100644 --- a/MyOffice.SPA/src/app/dashboard/income/dashboard.component.html +++ b/MyOffice.SPA/src/app/dashboard/income/dashboard.component.html @@ -5,50 +5,20 @@ -
@@ -73,10 +43,19 @@ [dataLabels]="chartOptions.dataLabels!" [plotOptions]="chartOptions.plotOptions!" [title]="chartOptions.title!" - [legend]="chartOptions.legend!" - > + [legend]="chartOptions.legend!">
+
+ + + + + + + +
{{item.currency}}{{item.value | number: '1.2'}} ({{item.valueRaw}})
+
diff --git a/MyOffice.SPA/src/app/dashboard/income/dashboard.component.ts b/MyOffice.SPA/src/app/dashboard/income/dashboard.component.ts index 309c6fc..1a165f6 100644 --- a/MyOffice.SPA/src/app/dashboard/income/dashboard.component.ts +++ b/MyOffice.SPA/src/app/dashboard/income/dashboard.component.ts @@ -16,6 +16,7 @@ import { ApexPlotOptions, ApexLegend } from "ng-apexcharts"; +import * as moment from 'moment' // app import { ApiRoutes } from '../../api-routes'; @@ -40,6 +41,8 @@ export class DashboardIncomeComponent implements OnInit { @ViewChild("chart") chart!: ChartComponent; public chartOptions!: Partial; dashboardModel?: DashboardInOutModel; + public dateFrom: Date = moment(new Date).add(-30, 'days').toDate(); + public dateTo: Date = moment(new Date).add(0, 'days').toDate(); colors: string[] = ["#fd7f6f", "#7eb0d5", "#b2e061", "#bd7ebe", "#ffb55a", "#ffee65", "#beb9db", "#fdcce5", "#8bd3c7"]; @@ -51,15 +54,29 @@ export class DashboardIncomeComponent implements OnInit { } ngOnInit() { + this.loadData(); + } + + onChangePeriod(dates: Date[]) { + this.dateFrom = dates[0]; + this.dateTo = dates[1]; + this.loadData(); + } + + loadData(update?: boolean, category?: string) { let params = new HttpParams() - .set('from', '2023-07-01') - .set('to', '2023-08-01'); + .set('from', moment(this.dateFrom).format('YYYY-MM-DD')) + .set('to', moment(this.dateTo).format('YYYY-MM-DD')) + .set('category', category || '') + ; this.httpClient .get(ApiRoutes.DashboardIncome, { params: params }) .subscribe(response => { + this.dashboardModel = response; + var series = response.data.map(x => ({ - x: x.name + '(' + this._decimalPipe.transform(x.value, '1.2-2') || "" + ')', + x: x.name + '(' + (this._decimalPipe.transform(x.value, '1.2-2') || "") + ')', y: x.value })); var min = Math.min(...response.data.map(x => x.value)); diff --git a/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.html b/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.html index db2d6f1..67f76fe 100644 --- a/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.html +++ b/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.html @@ -19,6 +19,7 @@ +
@@ -45,9 +46,21 @@ [title]="chartOptions.title!" [legend]="chartOptions.legend!"> +
+ + + + + + + +
{{item.name}}{{item.value | number: '1.2'}} ({{item.currency}})
+
+ + diff --git a/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.ts b/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.ts index 0d7800f..eaa8473 100644 --- a/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.ts +++ b/MyOffice.SPA/src/app/dashboard/outcome/dashboard.component.ts @@ -6,8 +6,6 @@ import { HttpClient } from '@angular/common/http'; import { HttpParams } from '@angular/common/http'; import { DecimalPipe } from '@angular/common'; import { UntypedFormBuilder } from '@angular/forms'; -import { UntypedFormGroup } from '@angular/forms'; -import { Validators } from '@angular/forms'; // libs import { @@ -44,7 +42,6 @@ export class DashboardOutcomeComponent implements OnInit { @ViewChild("chart") chart!: ChartComponent; public chartOptions!: Partial; dashboardModel?: DashboardInOutModel; - public form!: UntypedFormGroup; public dateFrom: Date = moment(new Date).add(-30, 'days').toDate(); public dateTo: Date = moment(new Date).add(0, 'days').toDate(); @@ -58,8 +55,6 @@ export class DashboardOutcomeComponent implements OnInit { } ngOnInit() { - this.form = this.fb.group({ - }); this.loadData(); } diff --git a/MyOffice.SPA/src/app/layout/header/header.component.ts b/MyOffice.SPA/src/app/layout/header/header.component.ts index b5ba8d3..2416df2 100644 --- a/MyOffice.SPA/src/app/layout/header/header.component.ts +++ b/MyOffice.SPA/src/app/layout/header/header.component.ts @@ -126,7 +126,7 @@ export class HeaderComponent extends UnsubscribeOnDestroyAdapter implements OnIn this.setUser(); - this.homePage = 'dashboard/dashboard'; + this.homePage = 'dashboard/rests'; this.langStoreValue = localStorage.getItem('lang') as string; const val = this.listLang.filter((x) => x.lang === this.langStoreValue); diff --git a/MyOffice.SPA/src/app/layout/sidebar/sidebar.component.html b/MyOffice.SPA/src/app/layout/sidebar/sidebar.component.html index 5b37059..aa8d3f3 100644 --- a/MyOffice.SPA/src/app/layout/sidebar/sidebar.component.html +++ b/MyOffice.SPA/src/app/layout/sidebar/sidebar.component.html @@ -4,7 +4,7 @@