|  | @ -25,6 +25,7 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements | 
			
		
	
		
		
			
				
					|  |  |         private Timer m_timer { get; set; } |  |  |         private Timer m_timer { get; set; } | 
			
		
	
		
		
			
				
					|  |  |         private ApexChart<ProductPriceChange> chart; |  |  |         private ApexChart<ProductPriceChange> chart; | 
			
		
	
		
		
			
				
					|  |  |         private Random m_random = new Random(); |  |  |         private Random m_random = new Random(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         private int tries = 10; | 
			
		
	
		
		
			
				
					|  |  |         protected override void OnInitialized() |  |  |         protected override void OnInitialized() | 
			
		
	
		
		
			
				
					|  |  |         { |  |  |         { | 
			
		
	
		
		
			
				
					|  |  |             base.OnInitialized(); |  |  |             base.OnInitialized(); | 
			
		
	
	
		
		
			
				
					|  | @ -37,35 +38,61 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         private void TimerElapsed(object sender, ElapsedEventArgs e) |  |  |         private void TimerElapsed(object sender, ElapsedEventArgs e) | 
			
		
	
		
		
			
				
					|  |  |         { |  |  |         { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             tries = 0; | 
			
		
	
		
		
			
				
					|  |  |             // Code to execute every 10 seconds
 |  |  |             // Code to execute every 10 seconds
 | 
			
		
	
		
		
			
				
					|  |  |             InvokeAsync(async () => |  |  |             InvokeAsync(async () => | 
			
		
	
		
		
			
				
					|  |  |             { |  |  |             { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 await GetPriceChange(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 StateHasChanged(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 await chart.RenderAsync(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         private async Task GetPriceChange() | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             tries++; | 
			
		
	
		
		
			
				
					|  |  |             if (m_productHistory.Count > 0) |  |  |             if (m_productHistory.Count > 0) | 
			
		
	
		
		
			
				
					|  |  |             { |  |  |             { | 
			
		
	
		
		
			
				
					|  |  |                 int randomNumber = m_random.Next(ProductHistory.Count); |  |  |                 int randomNumber = m_random.Next(ProductHistory.Count); | 
			
		
	
		
		
			
				
					
					|  |  |                     m_currentProduct = ProductHistory[randomNumber].Pcode; |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |                 m_productHistory = ProductHistory.Where(t => t.Pcode == m_currentProduct).ToList(); |  |  |                 m_productHistory = ProductHistory.Where(t => t.Pcode == m_currentProduct).ToList(); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |                 ProductPriceChange change = m_productHistory.First(); |  |  |                 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_percentage = (double)((change.CurrentPrice - change.PreviousPrice) / change.PreviousPrice > 0 ? change.PreviousPrice * 100 : 1); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |                 m_increase = change.CurrentPrice > change.PreviousPrice; |  |  |                 m_increase = change.CurrentPrice > change.PreviousPrice; | 
			
		
	
		
		
			
				
					|  |  |                 m_currentPrice = (double)change.CurrentPrice; |  |  |                 m_currentPrice = (double)change.CurrentPrice; | 
			
		
	
		
		
			
				
					|  |  |                 m_productName = change.ProductName; |  |  |                 m_productName = change.ProductName; | 
			
		
	
		
		
			
				
					|  |  |                 m_subtitle = $"Price :{m_calculator.GetCurrencyCode().CurrencySymbol}"; |  |  |                 m_subtitle = $"Price :{m_calculator.GetCurrencyCode().CurrencySymbol}"; | 
			
		
	
		
		
			
				
					|  |  |                 m_title = $"{m_productName} Price Changes"; |  |  |                 m_title = $"{m_productName} Price Changes"; | 
			
		
	
		
		
			
				
					|  |  |                     StateHasChanged(); |  |  |  | 
			
		
	
		
		
			
				
					|  |  |                     await chart.RenderAsync(); |  |  |  | 
			
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |             }); |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         public void Dispose() |  |  |         public void Dispose() | 
			
		
	
		
		
			
				
					|  |  |         { |  |  |         { | 
			
		
	
		
		
			
				
					|  |  |             // Dispose of the timer when the component is disposed
 |  |  |             // Dispose of the timer when the component is disposed
 | 
			
		
	
		
		
			
				
					|  |  |             m_timer?.Stop(); |  |  |             m_timer?.Stop(); | 
			
		
	
		
		
			
				
					|  |  |             m_timer?.Dispose(); |  |  |             m_timer?.Dispose(); | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |         protected override void OnParametersSet() |  |  |         protected override async void OnParametersSet() | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         { |  |  |         { | 
			
		
	
		
		
			
				
					|  |  |             if (!IsLoading) |  |  |             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) |  |  |                 await GetPriceChange(); | 
			
				
				
			
		
	
		
		
			
				
					|  |  |                 { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |                     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"; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |                 } |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |             base.OnParametersSet(); |  |  |             base.OnParametersSet(); | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
	
		
		
			
				
					|  | 
 |