diff --git a/Client/Pages/Dashboard/Dashboard.razor b/Client/Pages/Dashboard/Dashboard.razor index 5fc6670..56240e1 100644 --- a/Client/Pages/Dashboard/Dashboard.razor +++ b/Client/Pages/Dashboard/Dashboard.razor @@ -35,23 +35,7 @@
-
-
-
-
-
-
Profile Report
- Year 2021 -
-
- 68.2% -

$84,686k

-
-
-
-
-
-
+
@@ -59,7 +43,7 @@
- +
diff --git a/Client/Pages/Dashboard/Dashboard.razor.cs b/Client/Pages/Dashboard/Dashboard.razor.cs index 8e6c70c..913556d 100644 --- a/Client/Pages/Dashboard/Dashboard.razor.cs +++ b/Client/Pages/Dashboard/Dashboard.razor.cs @@ -12,26 +12,48 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard private List m_recentTransaction { get; set; } = new List { }; private List m_mostPurchased { get; set; } = new List { }; private List m_lowstock { get; set; } = new List { }; + private List m_ProductPriceChanges { get; set; } = new List { }; private double m_cancelledWeeklySale { get; set; } = 0; private double m_cancelledPercentage { get; set; } = 0; private double m_totalDebt { get; set; } = 0; private string m_username { get; set; } = string.Empty; private bool loadWeeklySales = true; + private bool loadingPriceHistory = true; private bool m_loadingMostPurchased { get; set; } = true; + protected override async Task OnInitializedAsync() { m_username = m_tokenService.GetUserNameFromToken(await m_tokenService.GetToken())!; + await Task.Delay(2500); await GetTradeSummary(); - await GetWeeklySales(); - await GetCancelledSales(); - await GetDebtSummary(); - await GetRecentTransactions(); - await GetMostPurchased(); - await GetLowStockItems(); + // Start the tasks without blocking the UI + _ = Task.Run(async () => + { + var weeklySalesTask = GetWeeklySales(); + var cancelledSalesTask = GetCancelledSales(); + var debtSummaryTask = GetDebtSummary(); + var recentTransactionsTask = GetRecentTransactions(); + var mostPurchasedTask = GetMostPurchased(); + var lowStockItemsTask = GetLowStockItems(); + var productPriceChangeHistoryTask = GetProductPriceChangeHistory(); + + // Wait for all tasks to complete + await Task.WhenAll( + weeklySalesTask, + cancelledSalesTask, + debtSummaryTask, + recentTransactionsTask, + mostPurchasedTask, + lowStockItemsTask, + productPriceChangeHistoryTask + ); + }); + + // Rest of the code... + return; } - // {a_limit - //} + /// /// Gets the trade summary /// @@ -168,9 +190,10 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard { try { + m_loadingMostPurchased = true; string start = m_tradeSummary.LastTradeDate.ToString("yyyy-MM-dd"); string end = m_tradeSummary.CurrentTradeDate.ToString("yyyy-MM-dd"); - var response = await m_http.GetAsync($"api/analytics/mostpurchaseditem/{start}/{end}"); + var response = await m_http.GetAsync($"api/analytics/mostpurchaseditem/" + start + "/" + end); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); @@ -201,7 +224,31 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard StateHasChanged(); } } - catch (Exception ex) { + catch (Exception ex) + { + } + } + /// + /// Gets a collection of items that are low on stock + /// + /// + async Task GetProductPriceChangeHistory() + { + try + { + var response = await m_http.GetAsync($"api/analytics/pricechanges/product/history/{5}"); + if (response.IsSuccessStatusCode) + { + var jsonContent = await response.Content.ReadAsStringAsync(); + var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; + var recent = JsonSerializer.Deserialize>(jsonContent, options); + m_ProductPriceChanges = recent; + loadingPriceHistory = false; + StateHasChanged(); + } + } + catch (Exception ex) + { } } } diff --git a/Client/Pages/Dashboard/Elements/MostPurchasedElement.razor b/Client/Pages/Dashboard/Elements/MostPurchasedElement.razor index f5156cd..56f4a08 100644 --- a/Client/Pages/Dashboard/Elements/MostPurchasedElement.razor +++ b/Client/Pages/Dashboard/Elements/MostPurchasedElement.razor @@ -4,58 +4,33 @@ @if (!IsLoading) { - @if (MostPurchasedItems.Count() > 5) - { -
-
-
-
-
-
Top 50 most purchased items
-
-
- @foreach (MostPurchasedItem purchasedItem in m_items.Take(5)) - { - - @($"{purchasedItem.ProductName} x{purchasedItem.NbrTimesSold}") -
- } -
-
- - - - -
-
- - - - - - - -
+
+
+
+
Top 50 most purchased items
- } +
+ + + + + + + +
+
} else { @@ -77,4 +52,4 @@ else justify-content: space-between; flex-wrap: wrap; } - \ No newline at end of file + diff --git a/Client/Pages/Dashboard/Elements/ProductPriceHistory.razor b/Client/Pages/Dashboard/Elements/ProductPriceHistory.razor new file mode 100644 index 0000000..eb03db0 --- /dev/null +++ b/Client/Pages/Dashboard/Elements/ProductPriceHistory.razor @@ -0,0 +1,18 @@ +@using Biskilog_Accounting.Shared.CustomModels; +@using Biskilog_Accounting.Shared.Interfaces; +@inject ICalculator m_calculator +@if (!IsLoading) +{ +
+ + + + +
+} +else +{ + +} \ No newline at end of file diff --git a/Client/Pages/Dashboard/Elements/ProductPriceHistory.razor.cs b/Client/Pages/Dashboard/Elements/ProductPriceHistory.razor.cs new file mode 100644 index 0000000..7a83d41 --- /dev/null +++ b/Client/Pages/Dashboard/Elements/ProductPriceHistory.razor.cs @@ -0,0 +1,75 @@ +using ApexCharts; +using Biskilog_Accounting.Shared.CustomModels; +using Microsoft.AspNetCore.Components; + +namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements +{ + public partial class ProductPriceHistory + { + [Parameter] + public List ProductHistory { get; set; } + [Parameter] + public bool IsLoading { get; set; } = true; + private List m_productHistory { get; set; } = new List(); + private string m_currentProduct = string.Empty; + private double m_percentage { get; set; } = 0; + private bool m_increase { get; set; } = false; + private double m_currentPrice { get; set; } = 0; + private ApexChartOptions options = new ApexChartOptions(); + private string m_productName { get; set; }= string.Empty; + private string m_subtitle { get;set; } = string.Empty; + private string m_title { get;set; } = string.Empty; + protected override void OnInitialized() + { + + base.OnInitialized(); + } + protected override void OnParametersSet() + { + if (!IsLoading) + { + options.Colors = new List { "#f4c414" }; + + options.Fill = new Fill + { + Type = new List { FillType.Gradient, FillType.Gradient }, + Gradient = new FillGradient + { + ShadeIntensity = 1, + OpacityFrom = 0.2, + OpacityTo = 0.9, + } + }; + + options.Yaxis = new List + { + new YAxis + { + Labels = new YAxisLabels + { + Formatter = @"function (value, index, w) { + return Number(value).toLocaleString();}" + } + } + }; + + Random random = new Random(); + int randomNumber = random.Next(ProductHistory.Count); + m_currentProduct = ProductHistory[randomNumber].Pcode; + m_productHistory = ProductHistory.Where(t => t.Pcode == m_currentProduct).ToList(); + + if (m_productHistory.Count > 0) + { + ProductPriceChange change = m_productHistory.First(); + m_percentage = (double)((change.CurrentPrice - change.PreviousPrice) / change.PreviousPrice * 100); + m_increase = change.CurrentPrice > change.PreviousPrice; + m_currentPrice = (double)change.CurrentPrice; + m_productName = change.ProductName; + m_subtitle = $"Price :{m_calculator.GetCurrencyCode().CurrencySymbol}"; + m_title = $"{m_productName} Price Changes"; + } + } + base.OnParametersSet(); + } + } +} diff --git a/Server/Controllers/AnalyticsController.cs b/Server/Controllers/AnalyticsController.cs index a51a433..912a5b8 100644 --- a/Server/Controllers/AnalyticsController.cs +++ b/Server/Controllers/AnalyticsController.cs @@ -132,5 +132,14 @@ namespace Biskilog_Accounting.Server.Controllers { return m_analyticService.GetRecentPriceChanges(a_limit); } + /// + /// Endpoint to return analysis on product price change history + /// + [Authorize] + [HttpGet, Route("pricechanges/product/history/{a_limit}")] + public IEnumerable GetPriceChangeHistory(int a_limit) + { + return m_analyticService.GetProductPriceChangeHistory(a_limit); + } } } diff --git a/Server/Services/AnalyticalService.cs b/Server/Services/AnalyticalService.cs index 82a1fe9..3140718 100644 --- a/Server/Services/AnalyticalService.cs +++ b/Server/Services/AnalyticalService.cs @@ -181,7 +181,38 @@ namespace Biskilog_Accounting.Server.Services public IEnumerable GetProductPriceChangeHistory(int a_limit) { - throw new NotImplementedException(); + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + command.CommandText = "CALL GetProductPriceChangeHistory(@p0,@p1)"; + command.Parameters.Add(new MySqlParameter("@p0", string.Join(", ", accessiblebranches.ToArray()))); + command.Parameters.Add(new MySqlParameter("@p1", a_limit)); + + m_context.Database.OpenConnection(); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + yield return new ProductPriceChange + { + Pcode = reader.GetString(0), + ProductName = reader.GetString(1), + PreviousPrice = reader.GetDecimal(2), + CurrentPrice = reader.GetDecimal(3), + ChangeDate = reader.GetDateTime(4), + BranchId = reader.GetString(5), + CountId = reader.GetString(6), + }; + } + } + } + } } public IEnumerable GetRecentPriceChanges(int a_limit)