namespace Lux.UI.Components.Pages { public partial class OffStats { protected override async Task OnInitializedAsync() { isLoading = true; await ReloadDataAsync(); isLoading = false; } [Inject] private IJSRuntime JSRuntime { get; set; } = null!; [Inject] private IOfferService OffService { get; set; } = default!; private List AllOfferRecords { get; set; } = new(); private bool isLoading = false; //private Dictionary FillColors = new(); //private Dictionary BorderColors = new(); //private Dictionary DatasetCount = new(); //private Dictionary FillDealerColors = new(); //private Dictionary BorderDealerColors = new(); //private Dictionary DatasetDealerCount = new(); private bool needReload = false; private EgwCoreLib.Utils.DtUtils.Periodo periodoLimit = new EgwCoreLib.Utils.DtUtils.Periodo(EgwCoreLib.Utils.DtUtils.PeriodSet.LastYear); ////private EgwCoreLib.Utils.DtUtils.Periodo periodoSel = new EgwCoreLib.Utils.DtUtils.Periodo(DateTime.Today.AddHours(DateTime.Now.Hour - 24 * 7), DateTime.Today.AddHours(DateTime.Now.Hour + 1)); private EgwCoreLib.Utils.DtUtils.Periodo periodoSel = new EgwCoreLib.Utils.DtUtils.Periodo(DateTime.Today.AddMonths(-5), DateTime.Today.AddHours(DateTime.Now.Hour + 1)); private string btnReload => needReload ? "btn-primary" : "btn-secondary"; private async Task ReloadDataAsync() { await OffService.CheckExpiredAsync(); AllOfferRecords = await OffService.GetFiltAsync(periodoSel.Inizio, periodoSel.Fine); } /// /// Caricamento dati /// /// private Task DoReload() { return ReloadDataAsync(); } private DateTime dtFrom { get => periodoSel.Inizio; set { if (periodoSel.Inizio != value) { periodoSel.Inizio = value; needReload = true; } } } private DateTime dtTo { get => periodoSel.Fine; set { if (periodoSel.Fine != value) { periodoSel.Fine = value; needReload = true; } } } //private double MargineMedio() //{ // var filtRecord = AllRecords.Where(x => x.OffertState.Equals(OfferStates.Confirmed)); // return Math.Round((filtRecord.Sum(x=>x.TotalPrice) - filtRecord.Sum(x => x.TotalCost)) / filtRecord.Sum(x => x.TotalPrice) * 100, 2); //} //private double NumFinestreMedio() //{ // var filtRecord = AllRecords.Where(x => x.OffertState.Equals(OfferStates.Confirmed)); // return Math.Ceiling(filtRecord.Sum(x => x.NumItems) / filtRecord.Count()); //} ///// ///// Caricamento dati ///// ///// //private async Task DoReload() //{ // await ReloadDataAsync(); // ReloadStats(); // ReloadDealerStats(); // needReload = false; //} //private void ReloadStats() //{ // var allStates = Enum.GetNames(typeof(Enums.OfferStates)).ToList(); // FillColors.Clear(); // BorderColors.Clear(); // for (int i = 0; i < allStates.Count; i++) // { // switch (allStates[i]) // { // case "Open": // FillColors[allStates[i]] = "hsla(180, 70%, 50%, 0.5)"; // break; // case "Confirmed": // FillColors[allStates[i]] = "hsla(90, 70%, 50%, 0.5)"; // break; // case "Expired": // FillColors[allStates[i]] = "hsla(0, 70%, 50%, 0.5)"; // break; // case "Lost": // FillColors[allStates[i]] = "hsla(270, 70%, 50%, 0.5)"; // break; // } // //FillColors[allStates[i]] = palette[i]; // BorderColors[allStates[i]] = ColorHelper.ToOpaque(FillColors[allStates[i]]); // } // DatasetCount = AllRecords // .Where(p => p.OffertState != null) // .GroupBy(p => p.OffertState.ToString()) // .ToDictionary(g => g.Key, g => (double)g.Count()); // if (DatasetCount == null || DatasetCount.Count == 0) // DatasetCount = new Dictionary { ["Nessuna Offerta"] = 1 }; //} //private void ReloadDealerStats() //{ // var allDealer = AllRecords.Select(x=>x.DealerNav.LastName).Distinct().ToList(); // var palette = ColorHelper.GeneratePalette(allDealer.Count, 0.5); // FillDealerColors.Clear(); // BorderDealerColors.Clear(); // for (int i = 0; i < allDealer.Count; i++) // { // FillDealerColors[allDealer[i]] = palette[i]; // BorderDealerColors[allDealer[i]] = ColorHelper.ToOpaque(palette[i]); // } // DatasetDealerCount = AllRecords // .Where(p => p.OffertState != null) // .GroupBy(p => p.DealerNav.LastName) // .ToDictionary(g => g.Key, g => (double)g.Count()); // if (DatasetDealerCount == null || DatasetDealerCount.Count == 0) // DatasetDealerCount = new Dictionary { ["Nessun venditore"] = 1 }; //} } }