Benjamin Arhen
2 years ago
7 changed files with 219 additions and 80 deletions
@ -0,0 +1,18 @@ |
|||||
|
@using Biskilog_Accounting.Shared.CustomModels; |
||||
|
@using Biskilog_Accounting.Shared.Interfaces; |
||||
|
@inject ICalculator m_calculator |
||||
|
@if (!IsLoading) |
||||
|
{ |
||||
|
<div class="card"> |
||||
|
<ApexChart TItem="ProductPriceChange" Options="options" Title="@m_title"> |
||||
|
|
||||
|
<ApexPointSeries TItem="ProductPriceChange" Items="m_productHistory" Name="@m_subtitle" |
||||
|
SeriesType="SeriesType.Area" XValue="@(e => e.ChangeDate.Value.ToString("dd MMM,yy"))" |
||||
|
YValue="@(e => e.CurrentPrice)" /> |
||||
|
</ApexChart> |
||||
|
</div> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
|
||||
|
} |
@ -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<ProductPriceChange> ProductHistory { get; set; } |
||||
|
[Parameter] |
||||
|
public bool IsLoading { get; set; } = true; |
||||
|
private List<ProductPriceChange> m_productHistory { get; set; } = new List<ProductPriceChange>(); |
||||
|
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<ProductPriceChange> options = new ApexChartOptions<ProductPriceChange>(); |
||||
|
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<string> { "#f4c414" }; |
||||
|
|
||||
|
options.Fill = new Fill |
||||
|
{ |
||||
|
Type = new List<FillType> { FillType.Gradient, FillType.Gradient }, |
||||
|
Gradient = new FillGradient |
||||
|
{ |
||||
|
ShadeIntensity = 1, |
||||
|
OpacityFrom = 0.2, |
||||
|
OpacityTo = 0.9, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
options.Yaxis = new List<YAxis> |
||||
|
{ |
||||
|
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(); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue