| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -25,6 +25,7 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        private Timer m_timer { get; set; } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        private ApexChart<ProductPriceChange> chart; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        private Random m_random = new Random(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        private int tries = 10; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        protected override void OnInitialized() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            base.OnInitialized(); | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -37,35 +38,61 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        private void TimerElapsed(object sender, ElapsedEventArgs e) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            tries = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // Code to execute every 10 seconds
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            InvokeAsync(async () => | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                await GetPriceChange(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                StateHasChanged(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                await chart.RenderAsync(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        private async Task GetPriceChange() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            tries++; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (m_productHistory.Count > 0) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                int randomNumber = m_random.Next(ProductHistory.Count); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    m_currentProduct = ProductHistory[randomNumber].Pcode; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                m_productHistory = ProductHistory.Where(t => t.Pcode == m_currentProduct).ToList(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                ProductPriceChange change = m_productHistory.First(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                double actualChange = (double)((change.CurrentPrice - change.PreviousPrice)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (actualChange == 0) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    // if randomly selected doesn't have any product change history
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if (!string.IsNullOrEmpty(m_currentProduct)) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        return; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    else | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        if (tries < 3) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            GetPriceChange(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        return; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                else | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    m_percentage = (double)((change.CurrentPrice - change.PreviousPrice) / change.PreviousPrice > 0 ? change.PreviousPrice * 100 : 1); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                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"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    StateHasChanged(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    await chart.RenderAsync(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        public void Dispose() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // Dispose of the timer when the component is disposed
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            m_timer?.Stop(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            m_timer?.Dispose(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        protected override void OnParametersSet() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        protected override async void OnParametersSet() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (!IsLoading) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            { | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -101,21 +128,8 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            }; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                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 > 0 ? change.PreviousPrice * 100 : 1); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    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"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                await GetPriceChange(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            base.OnParametersSet(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |