From 588011480fdef709b25e4cee17e1a4a7a81ca926 Mon Sep 17 00:00:00 2001 From: barhen Date: Thu, 1 Jun 2023 18:29:29 -0500 Subject: [PATCH 1/2] Dashboard WIP Commit 1 --- .editorconfig | 4 + Biskilog Accounting.sln | 5 + Client/Biskilog Accounting.Client.csproj | 9 +- Client/Elements/Sidebar.razor | 18 +-- Client/Elements/Sidebar.razor.cs | 25 +++++ Client/Models/NavItem.cs | 105 ++++++++++++++---- Client/Pages/Dashboard/Dashboard.razor | 28 +---- Client/Pages/Dashboard/Dashboard.razor.cs | 19 ++++ .../Dashboard/Elements/WelcomeCard.razor | 25 +++++ .../Dashboard/Elements/WelcomeCard.razor.cs | 40 +++++++ Client/Program.cs | 6 + Server/Biskilog Accounting.Server.csproj | 1 + Shared/Biskilog Accounting.Shared.csproj | 1 + Shared/Interfaces/ICalculator.cs | 16 +++ Shared/ServiceRepo/CalculatorService.cs | 39 +++++++ Shared/ServiceRepo/TokenService.cs | 4 +- 16 files changed, 277 insertions(+), 68 deletions(-) create mode 100644 .editorconfig create mode 100644 Client/Elements/Sidebar.razor.cs create mode 100644 Client/Pages/Dashboard/Dashboard.razor.cs create mode 100644 Client/Pages/Dashboard/Elements/WelcomeCard.razor create mode 100644 Client/Pages/Dashboard/Elements/WelcomeCard.razor.cs create mode 100644 Shared/Interfaces/ICalculator.cs create mode 100644 Shared/ServiceRepo/CalculatorService.cs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6f2e6a4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# IDE0021: Use block body for constructor +csharp_style_expression_bodied_constructors = when_on_single_line diff --git a/Biskilog Accounting.sln b/Biskilog Accounting.sln index 06dd1e5..74a9539 100644 --- a/Biskilog Accounting.sln +++ b/Biskilog Accounting.sln @@ -9,6 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Biskilog Accounting.Client" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Biskilog Accounting.Shared", "Shared\Biskilog Accounting.Shared.csproj", "{48490CB4-D5CE-46FE-9A7A-FBC91980D262}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{84405340-FCB0-46CB-B730-10E47D9F54C2}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/Client/Biskilog Accounting.Client.csproj b/Client/Biskilog Accounting.Client.csproj index 199aeff..fd65417 100644 --- a/Client/Biskilog Accounting.Client.csproj +++ b/Client/Biskilog Accounting.Client.csproj @@ -8,8 +8,13 @@ $(AssemblyName.Replace(' ', '_')) + + + + + @@ -23,8 +28,4 @@ - - - - diff --git a/Client/Elements/Sidebar.razor b/Client/Elements/Sidebar.razor index efc9935..f58ab0b 100644 --- a/Client/Elements/Sidebar.razor +++ b/Client/Elements/Sidebar.razor @@ -1,5 +1,5 @@ @using Biskilog_Accounting.Client.Models; - \ No newline at end of file diff --git a/Client/Elements/Sidebar.razor.cs b/Client/Elements/Sidebar.razor.cs new file mode 100644 index 0000000..f12dd31 --- /dev/null +++ b/Client/Elements/Sidebar.razor.cs @@ -0,0 +1,25 @@ +namespace Biskilog_Accounting.Client.Elements +{ + public partial class Sidebar + { + private double m_activeId = 1; + private string m_class { get; set; } = "layout-menu"; + + private void HandleMenuClick(double a_selectedId) + { + m_activeId = a_selectedId; + StateHasChanged(); + } + private void Collapse() + { + if (m_class == "layout-menu") + { + m_class = "layout-menu-collapsed"; + } + else + { + m_class = "layout-menu"; + } + } + } +} diff --git a/Client/Models/NavItem.cs b/Client/Models/NavItem.cs index 238c149..3438146 100644 --- a/Client/Models/NavItem.cs +++ b/Client/Models/NavItem.cs @@ -46,53 +46,112 @@ Link = "", Title = "Dashboard" }, - new NavItem() + new NavItem() + { + Id = 2, + Description = "Transactions", + Title = "Transactions", + Icon = "bxs-cart", + Children = new List { - Id = 2, - Description = "Customers", - Icon = "bx-users", - Link = "customers", - Title = "Customers" + new NavItem() + { + Id = 2.1, + Title = "Sales", + }, + new NavItem() + { + Id = 2.2, + Title = "Cancelled Sales", + }, + new NavItem() + { + Id = 2.3, + Title = "Statistics", + }, + }, }, - new NavItem() + new NavItem() { Id = 3, - Description = "Employees", - Icon = "bx-users", - Link = "employees", - Title = "Employees" - }, - new NavItem() - { - Id = 4, Description = "Products", Icon = "bx-box", - Link = "", Title = "Products", Children = new List { new NavItem { - Id = 4.1, + Id = 3.1, + Description = "Brands", + Title = "Brands", + Link = "", + }, + new NavItem + { + Id = 3.2, + Description = "Category", + Title = "Category", + Link = "", + }, + new NavItem + { + Id = 3.3, Description = "Inventory", - Title = "Inventory" + Title = "Inventory", + Link = "", }, new NavItem { - Id = 4.2, + Id = 3.4, Description = "Inventory", - Title = "Bulk Price Changes" + Title = "Bulk Price Changes", + Link = "", }, new NavItem { - Id = 4.3, + Id = 3.5, Description = "Inventory", Title = "Products Statistics", - Icon = "bx-detail" + Link = "", } } }, - }; + + + new NavItem() + { + Id = 4, + Description = "Customers", + Icon = "bxs-user", + Link = "customers", + Title = "Customers" + }, + new NavItem() + { + Id = 5, + Description = "Employees", + Icon = "bxs-user-account", + Link = "employees", + Title = "Employees" + }, + new NavItem() + { + Id = 6, + Description = "Warehouse Management", + Icon = "bxs-factory", + Title = "Warehouse Management", + Children = new List { + new NavItem(){ + Id = 6.1, + Description = "Item Inventory for the warehouse", + Title = "Inventory", + Link = "", + }, + + }, + }, + + }; var uniqueIds = new HashSet(); diff --git a/Client/Pages/Dashboard/Dashboard.razor b/Client/Pages/Dashboard/Dashboard.razor index 60ce9da..c053a1a 100644 --- a/Client/Pages/Dashboard/Dashboard.razor +++ b/Client/Pages/Dashboard/Dashboard.razor @@ -1,32 +1,10 @@ -@page "/" +@using Biskilog_Accounting.Client.Pages.Dashboard.Elements; +@page "/"
-
-
-
-
-
Congratulations John! 🎉
-

- You have done 72% more sales today. Check your new badge in - your profile. -

- - View Badges -
-
-
-
- View Badge User -
-
-
-
+
diff --git a/Client/Pages/Dashboard/Dashboard.razor.cs b/Client/Pages/Dashboard/Dashboard.razor.cs new file mode 100644 index 0000000..d81f9bc --- /dev/null +++ b/Client/Pages/Dashboard/Dashboard.razor.cs @@ -0,0 +1,19 @@ +using Biskilog_Accounting.Shared.Interfaces; + +namespace Biskilog_Accounting.Client.Pages.Dashboard +{ + public partial class Dashboard + { + private readonly ITokenService m_tokenService; + private double CurrentTradeSale = 7000; + private double PreviousTradeSale = 2000.80; + private string username { get; set; } + public Dashboard() { } + public Dashboard(ITokenService a_tokenService) => m_tokenService = a_tokenService; + protected override void OnInitialized() + { + username = "username"; + base.OnInitialized(); + } + } +} diff --git a/Client/Pages/Dashboard/Elements/WelcomeCard.razor b/Client/Pages/Dashboard/Elements/WelcomeCard.razor new file mode 100644 index 0000000..5ce377e --- /dev/null +++ b/Client/Pages/Dashboard/Elements/WelcomeCard.razor @@ -0,0 +1,25 @@ +@using Biskilog_Accounting.Shared.Interfaces; +@inject ICalculator m_calculator; + +
+
+
+
+
@(CurrentTradeSales > PreviousTradeSales ? "Congratulations 🎉" : "Tough shift there") @Username!
+

+ @m_remarks +

+ View Trade Summary +
+
+
+
+ View Badge User +
+
+
+
\ No newline at end of file diff --git a/Client/Pages/Dashboard/Elements/WelcomeCard.razor.cs b/Client/Pages/Dashboard/Elements/WelcomeCard.razor.cs new file mode 100644 index 0000000..c57e63e --- /dev/null +++ b/Client/Pages/Dashboard/Elements/WelcomeCard.razor.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Components; + +namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements +{ + public partial class WelcomeCard + { + [Parameter] + public string Username { get; set; } = string.Empty; + + [Parameter] + public double CurrentTradeSales { get; set; } = 0; + [Parameter] + public double PreviousTradeSales { get; set; } = 0; + + private string m_remarks { get; set; } = ""; + + protected override void OnInitialized() + { + CalculateStatistic(); + + base.OnInitialized(); + } + private void CalculateStatistic() + { + if (CurrentTradeSales > PreviousTradeSales) + { + double change = (CurrentTradeSales / (CurrentTradeSales + PreviousTradeSales)) * 100; + string changePercent = change.ToString("0.00") + "%"; + m_remarks = $"You made a total of {m_calculator.FormatMoneyWithCurrency(CurrentTradeSales)} in the current trade, {changePercent} more than the previous trade sales"; + } + else if (PreviousTradeSales > CurrentTradeSales) { + double change = (CurrentTradeSales / (CurrentTradeSales + PreviousTradeSales)) * -100; + string changePercent = change.ToString("0.00") + "%"; + m_remarks = $"You made a total of {m_calculator.FormatMoneyWithCurrency(CurrentTradeSales)} in the current trade, {changePercent} less than the previous trade sales"; + } else { + m_remarks = $"You made a total of {m_calculator.FormatMoneyWithCurrency(CurrentTradeSales)} in the current trade, same as the previous trade sales"; + } + } + } +} diff --git a/Client/Program.cs b/Client/Program.cs index fef3761..5dd5c37 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -1,4 +1,7 @@ using Biskilog_Accounting.Client; +using Biskilog_Accounting.ServiceRepo; +using Biskilog_Accounting.Shared.Interfaces; +using Biskilog_Accounting.Shared.ServiceRepo; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; @@ -11,4 +14,7 @@ builder.Services.AddHttpClient("Biskilog_Accounting.ServerAPI", client => client // Supply HttpClient instances that include access tokens when making requests to the server project builder.Services.AddScoped(sp => sp.GetRequiredService().CreateClient("Biskilog_Accounting.ServerAPI")); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + await builder.Build().RunAsync(); diff --git a/Server/Biskilog Accounting.Server.csproj b/Server/Biskilog Accounting.Server.csproj index 57e689c..f9a3317 100644 --- a/Server/Biskilog Accounting.Server.csproj +++ b/Server/Biskilog Accounting.Server.csproj @@ -9,6 +9,7 @@ + diff --git a/Shared/Biskilog Accounting.Shared.csproj b/Shared/Biskilog Accounting.Shared.csproj index b5a3a0f..b9802df 100644 --- a/Shared/Biskilog Accounting.Shared.csproj +++ b/Shared/Biskilog Accounting.Shared.csproj @@ -8,6 +8,7 @@ + diff --git a/Shared/Interfaces/ICalculator.cs b/Shared/Interfaces/ICalculator.cs new file mode 100644 index 0000000..d23d93d --- /dev/null +++ b/Shared/Interfaces/ICalculator.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Biskilog_Accounting.Shared.Interfaces +{ + public interface ICalculator + { + double CalculatePercentage(); + string FormatMoneyWithCurrency(double a_amount); + NumberFormatInfo GetCurrencyCode(); + } +} diff --git a/Shared/ServiceRepo/CalculatorService.cs b/Shared/ServiceRepo/CalculatorService.cs new file mode 100644 index 0000000..eab3246 --- /dev/null +++ b/Shared/ServiceRepo/CalculatorService.cs @@ -0,0 +1,39 @@ +using Biskilog_Accounting.Shared.Interfaces; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Biskilog_Accounting.Shared.ServiceRepo +{ + public class CalculatorService : ICalculator + { + public double CalculatePercentage() + { + throw new NotImplementedException(); + } + + public string FormatMoneyWithCurrency(double a_amount) + { + return string.Format(GetCurrencyCode(), "{0:C2}", a_amount); + } + + public NumberFormatInfo GetCurrencyCode() + { + //TODO have a better implementation + + // Specify the locale for Ghana + string locale = "en-GH"; + + // Get the NumberFormatInfo for the specified locale + NumberFormatInfo numberFormatInfo = new CultureInfo(locale).NumberFormat; + + // Set the currency symbol to Ghanaian cedi + numberFormatInfo.CurrencySymbol = "GH₵"; + + return numberFormatInfo; + } + } +} diff --git a/Shared/ServiceRepo/TokenService.cs b/Shared/ServiceRepo/TokenService.cs index d86df04..94e22b8 100644 --- a/Shared/ServiceRepo/TokenService.cs +++ b/Shared/ServiceRepo/TokenService.cs @@ -12,9 +12,11 @@ namespace Biskilog_Accounting.ServiceRepo public class TokenService : ITokenService { private IConfiguration m_configuration { get; } - public TokenService(IConfiguration a_configuration) + private readonly Blazored.SessionStorage.ISessionStorageService m_sessionStorage; + public TokenService(IConfiguration a_configuration, Blazored.SessionStorage.ISessionStorageService sessionStorage) { m_configuration = a_configuration; + m_sessionStorage = sessionStorage; } /// -- 2.25.1 From 8a92ae36b47a378e3193d9551ec9a658b13b9286 Mon Sep 17 00:00:00 2001 From: barhen Date: Fri, 2 Jun 2023 09:46:40 -0500 Subject: [PATCH 2/2] Dashboard WIP Commit 2 --- Client/Biskilog Accounting.Client.csproj | 1 + Client/Elements/Footer.razor | 2 +- Client/Elements/Sidebar.razor.cs | 16 +-- Client/Layouts/MainLayout.razor | 36 +++--- Client/Layouts/MainLayout.razor.cs | 24 ++++ Client/Pages/Auth/Login.razor | 13 +- Client/Pages/Auth/Login.razor.cs | 109 +++++++++++++++- Client/Pages/Dashboard/Dashboard.razor | 119 ++---------------- Client/Pages/Dashboard/Dashboard.razor.cs | 42 +++++-- .../Elements/AnalyticsItemSmall.razor | 28 +++++ .../Elements/AnalyticsItemSmall.razor.cs | 16 +++ .../Dashboard/Elements/WelcomeCard.razor | 2 +- .../Dashboard/Elements/WelcomeCard.razor.cs | 17 +-- Client/Program.cs | 4 + Client/wwwroot/assets/vendor/css/core.css | 22 ++-- .../assets/vendor/css/theme-default.css | 20 +-- Server/Biskilog Accounting.Server.csproj | 3 +- Server/Controllers/AnalyticsController.cs | 9 ++ Server/Services/AnalyticalService.cs | 42 +++++++ Shared/Biskilog Accounting.Shared.csproj | 1 + Shared/CustomModels/TradeSummary.cs | 16 +++ Shared/Interfaces/IAnalytics.cs | 6 +- Shared/Interfaces/ITokenService.cs | 4 + Shared/ServiceRepo/CalculatorService.cs | 2 +- Shared/ServiceRepo/TokenService.cs | 43 ++++++- 25 files changed, 413 insertions(+), 184 deletions(-) create mode 100644 Client/Layouts/MainLayout.razor.cs create mode 100644 Client/Pages/Dashboard/Elements/AnalyticsItemSmall.razor create mode 100644 Client/Pages/Dashboard/Elements/AnalyticsItemSmall.razor.cs create mode 100644 Shared/CustomModels/TradeSummary.cs diff --git a/Client/Biskilog Accounting.Client.csproj b/Client/Biskilog Accounting.Client.csproj index fd65417..f344a0f 100644 --- a/Client/Biskilog Accounting.Client.csproj +++ b/Client/Biskilog Accounting.Client.csproj @@ -14,6 +14,7 @@ + diff --git a/Client/Elements/Footer.razor b/Client/Elements/Footer.razor index 2a99ca9..34fb85e 100644 --- a/Client/Elements/Footer.razor +++ b/Client/Elements/Footer.razor @@ -1,4 +1,4 @@ -