2b4cad4234
- Inserito filtro in offerte in base allo stato
144 lines
5.4 KiB
C#
144 lines
5.4 KiB
C#
using System.Linq;
|
|
using static EgwCoreLib.Lux.Core.Enums;
|
|
|
|
namespace Lux.UI.Components.Compo.Stats
|
|
{
|
|
public partial class OfferStats
|
|
{
|
|
[Parameter]
|
|
public List<OfferModel> AllRecords { get; set; } = new();
|
|
|
|
[Inject] private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
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();
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
isLoading = true;
|
|
ReloadStats();
|
|
ReloadDealerStats();
|
|
isLoading = false;
|
|
}
|
|
|
|
|
|
private double MargineMedio()
|
|
{
|
|
double ans = 0;
|
|
var filtRecord = AllRecords.Where(x => x.OffertState.Equals(OfferStates.Confirmed));
|
|
if(filtRecord != null && filtRecord.Count() > 0)
|
|
ans = Math.Round((filtRecord.Sum(x => x.TotalPrice) - filtRecord.Sum(x => x.TotalCost)) / filtRecord.Sum(x => x.TotalPrice) * 100, 2);
|
|
return ans;
|
|
}
|
|
|
|
private double MargineMin()
|
|
{
|
|
double ans = 0;
|
|
var filtRecord = AllRecords.Where(x => x.OffertState.Equals(OfferStates.Confirmed));
|
|
if (filtRecord != null && filtRecord.Count() > 0)
|
|
ans = Math.Round(filtRecord.Min(x=>x.MaxDiscount) * 100, 2);
|
|
return ans;
|
|
}
|
|
|
|
private double MargineMax()
|
|
{
|
|
double ans = 0;
|
|
var filtRecord = AllRecords.Where(x => x.OffertState.Equals(OfferStates.Confirmed));
|
|
if (filtRecord != null && filtRecord.Count() > 0)
|
|
ans = Math.Round(filtRecord.Max(x => x.MaxDiscount) * 100, 2);
|
|
return ans;
|
|
}
|
|
|
|
private double NumFinestreMedio()
|
|
{
|
|
double ans = 0;
|
|
var filtRecord = AllRecords.Where(x => x.OffertState.Equals(OfferStates.Confirmed));
|
|
if (filtRecord != null && filtRecord.Count() > 0)
|
|
ans = Math.Ceiling(filtRecord.Sum(x => x.NumItems) / filtRecord.Count());
|
|
return ans;
|
|
}
|
|
|
|
private double NumFinestreMin()
|
|
{
|
|
double ans = 0;
|
|
var filtRecord = AllRecords.Where(x => x.OffertState.Equals(OfferStates.Confirmed));
|
|
if (filtRecord != null && filtRecord.Count() > 0)
|
|
ans = filtRecord.Min(x => x.NumItems);
|
|
return ans;
|
|
}
|
|
|
|
private double NumFinestreMax()
|
|
{
|
|
double ans = 0;
|
|
var filtRecord = AllRecords.Where(x => x.OffertState.Equals(OfferStates.Confirmed));
|
|
if (filtRecord != null && filtRecord.Count() > 0)
|
|
ans = filtRecord.Max(x => x.NumItems);
|
|
return ans;
|
|
}
|
|
|
|
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(90, 70%, 50%, 0.5)";
|
|
break;
|
|
case "Confirmed":
|
|
FillColors[allStates[i]] = "hsla(180, 70%, 50%, 0.5)";
|
|
break;
|
|
case "Expired":
|
|
FillColors[allStates[i]] = "hsla(60, 70%, 50%, 0.5)";
|
|
break;
|
|
case "Lost":
|
|
FillColors[allStates[i]] = "hsla(0, 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 };
|
|
}
|
|
}
|
|
} |