2b4cad4234
- Inserito filtro in offerte in base allo stato
156 lines
5.9 KiB
C#
156 lines
5.9 KiB
C#
|
|
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<OfferModel> AllOfferRecords { get; set; } = new();
|
|
|
|
private bool isLoading = false;
|
|
//private Dictionary<string, string> FillColors = new();
|
|
//private Dictionary<string, string> BorderColors = new();
|
|
//private Dictionary<string, double> DatasetCount = new();
|
|
//private Dictionary<string, string> FillDealerColors = new();
|
|
//private Dictionary<string, string> BorderDealerColors = new();
|
|
//private Dictionary<string, double> 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Caricamento dati
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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());
|
|
//}
|
|
|
|
///// <summary>
|
|
///// Caricamento dati
|
|
///// </summary>
|
|
///// <returns></returns>
|
|
//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<string, double> { ["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<string, double> { ["Nessun venditore"] = 1 };
|
|
//}
|
|
}
|
|
} |