Billing: Rename attributeVariants and contracts to vaributes

This commit is contained in:
2024-01-27 11:08:10 +01:00
parent 31b0ae245d
commit dd568b81e8
10 changed files with 81 additions and 81 deletions

View File

@ -150,15 +150,15 @@ namespace Elwig.Helpers.Billing {
return dict; return dict;
} }
protected static Dictionary<string, JsonValue> GetSelection(JsonNode value, IEnumerable<string> attributeVariants) { protected static Dictionary<string, JsonValue> GetSelection(JsonNode value, IEnumerable<string> vaributes) {
if (value is JsonValue flatRate) { if (value is JsonValue flatRate) {
return attributeVariants.ToDictionary(e => e, _ => flatRate); return vaributes.ToDictionary(e => e, _ => flatRate);
} if (value is not JsonObject data) { } if (value is not JsonObject data) {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
Dictionary<string, JsonValue> dict; Dictionary<string, JsonValue> dict;
if (data["default"] is JsonValue def) { if (data["default"] is JsonValue def) {
dict = attributeVariants.ToDictionary(e => e, _ => def); dict = vaributes.ToDictionary(e => e, _ => def);
} else { } else {
dict = []; dict = [];
} }
@ -168,13 +168,13 @@ namespace Elwig.Helpers.Billing {
var others = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length > 2 && p.Key != "default"); var others = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length > 2 && p.Key != "default");
foreach (var (idx, v) in variants) { foreach (var (idx, v) in variants) {
var curve = v?.AsValue() ?? throw new InvalidOperationException(); var curve = v?.AsValue() ?? throw new InvalidOperationException();
foreach (var i in attributeVariants.Where(e => e.StartsWith(idx[..^1]))) { foreach (var i in vaributes.Where(e => e.StartsWith(idx[..^1]))) {
dict[i] = curve; dict[i] = curve;
} }
} }
foreach (var (idx, v) in attributes) { foreach (var (idx, v) in attributes) {
var curve = v?.AsValue() ?? throw new InvalidOperationException(); var curve = v?.AsValue() ?? throw new InvalidOperationException();
foreach (var i in attributeVariants.Where(e => e[2..] == idx[1..])) { foreach (var i in vaributes.Where(e => e[2..] == idx[1..])) {
dict[i] = curve; dict[i] = curve;
} }
} }
@ -257,7 +257,7 @@ namespace Elwig.Helpers.Billing {
return curve; return curve;
} }
protected static void CollapsePaymentData(JsonObject data, IEnumerable<string> attributeVariants) { protected static void CollapsePaymentData(JsonObject data, IEnumerable<string> vaributes) {
Dictionary<string, List<string>> rev1 = []; Dictionary<string, List<string>> rev1 = [];
Dictionary<decimal, List<string>> rev2 = []; Dictionary<decimal, List<string>> rev2 = [];
foreach (var (k, v) in data) { foreach (var (k, v) in data) {
@ -273,18 +273,18 @@ namespace Elwig.Helpers.Billing {
} }
if (!data.ContainsKey("default")) { if (!data.ContainsKey("default")) {
foreach (var (v, ks) in rev1) { foreach (var (v, ks) in rev1) {
if (ks.Count >= attributeVariants.Count() / 2.0) { if (ks.Count >= vaributes.Count() / 2.0) {
foreach (var k in ks) data.Remove(k); foreach (var k in ks) data.Remove(k);
data["default"] = v; data["default"] = v;
CollapsePaymentData(data, attributeVariants); CollapsePaymentData(data, vaributes);
return; return;
} }
} }
foreach (var (v, ks) in rev2) { foreach (var (v, ks) in rev2) {
if (ks.Count >= attributeVariants.Count() / 2.0) { if (ks.Count >= vaributes.Count() / 2.0) {
foreach (var k in ks) data.Remove(k); foreach (var k in ks) data.Remove(k);
data["default"] = v; data["default"] = v;
CollapsePaymentData(data, attributeVariants); CollapsePaymentData(data, vaributes);
return; return;
} }
} }
@ -296,7 +296,7 @@ namespace Elwig.Helpers.Billing {
.Distinct() .Distinct()
.ToList(); .ToList();
foreach (var idx in attributes) { foreach (var idx in attributes) {
var len = attributeVariants.Count(e => e.EndsWith(idx)); var len = vaributes.Count(e => e.EndsWith(idx));
foreach (var (v, ks) in rev1) { foreach (var (v, ks) in rev1) {
var myKs = ks.Where(k => k.EndsWith(idx)).ToList(); var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
if (myKs.Count > 1 && myKs.Count >= len / 2.0) { if (myKs.Count > 1 && myKs.Count >= len / 2.0) {
@ -314,7 +314,7 @@ namespace Elwig.Helpers.Billing {
} }
} }
public static JsonObject FromGraphEntries(IEnumerable<GraphEntry> graphEntries, BillingData? origData = null, IEnumerable<string>? attributeVariants = null) { public static JsonObject FromGraphEntries(IEnumerable<GraphEntry> graphEntries, BillingData? origData = null, IEnumerable<string>? vaributes = null) {
var payment = new JsonObject(); var payment = new JsonObject();
var qualityWei = new JsonObject(); var qualityWei = new JsonObject();
var curves = new JsonArray(); var curves = new JsonArray();
@ -331,7 +331,7 @@ namespace Elwig.Helpers.Billing {
} else { } else {
continue; continue;
} }
foreach (var c in entry.Contracts) { foreach (var c in entry.Vaributes) {
if (entry.Abgewertet) { if (entry.Abgewertet) {
qualityWei[$"{c.Variety?.SortId}/{c.Attribute?.AttrId}"] = node.DeepClone(); qualityWei[$"{c.Variety?.SortId}/{c.Attribute?.AttrId}"] = node.DeepClone();
} else { } else {
@ -340,8 +340,8 @@ namespace Elwig.Helpers.Billing {
} }
} }
CollapsePaymentData(payment, attributeVariants ?? payment.Select(e => e.Key).ToList()); CollapsePaymentData(payment, vaributes ?? payment.Select(e => e.Key).ToList());
CollapsePaymentData(qualityWei, attributeVariants ?? qualityWei.Select(e => e.Key).ToList()); CollapsePaymentData(qualityWei, vaributes ?? qualityWei.Select(e => e.Key).ToList());
var data = new JsonObject { var data = new JsonObject {
["mode"] = "elwig", ["mode"] = "elwig",

View File

@ -15,7 +15,7 @@ namespace Elwig.Helpers.Billing {
public BillingVariant(int year, int avnr) : base(year) { public BillingVariant(int year, int avnr) : base(year) {
AvNr = avnr; AvNr = avnr;
PaymentVariant = Context.PaymentVariants.Find(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found"); PaymentVariant = Context.PaymentVariants.Find(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found");
Data = PaymentBillingData.FromJson(PaymentVariant.Data, Utils.GetAttributeVarieties(Context, Year, onlyDelivered: false)); Data = PaymentBillingData.FromJson(PaymentVariant.Data, Utils.GetVaributes(Context, Year, onlyDelivered: false));
} }
public async Task Calculate() { public async Task Calculate() {

View File

@ -7,15 +7,15 @@ using System.Text.Json.Nodes;
namespace Elwig.Helpers.Billing { namespace Elwig.Helpers.Billing {
public class EditBillingData : BillingData { public class EditBillingData : BillingData {
protected readonly IEnumerable<string> AttributeVariants; protected readonly IEnumerable<string> Vaributes;
public EditBillingData(JsonObject data, IEnumerable<string> attributeVariants) : public EditBillingData(JsonObject data, IEnumerable<string> vaributes) :
base(data) { base(data) {
AttributeVariants = attributeVariants; Vaributes = vaributes;
} }
public static EditBillingData FromJson(string json, IEnumerable<string> attributeVariants) { public static EditBillingData FromJson(string json, IEnumerable<string> vaributes) {
return new(ParseJson(json), attributeVariants); return new(ParseJson(json), vaributes);
} }
private (Dictionary<int, Curve>, Dictionary<int, List<string>>) GetGraphEntries(JsonNode root) { private (Dictionary<int, Curve>, Dictionary<int, List<string>>) GetGraphEntries(JsonNode root) {
@ -56,7 +56,7 @@ namespace Elwig.Helpers.Billing {
} }
Dictionary<int, List<string>> dict3 = curves.ToDictionary(c => c.Key, _ => new List<string>()); Dictionary<int, List<string>> dict3 = curves.ToDictionary(c => c.Key, _ => new List<string>());
foreach (var (selector, value) in GetSelection(root, AttributeVariants)) { foreach (var (selector, value) in GetSelection(root, Vaributes)) {
int? idx = null; int? idx = null;
if (value.TryGetValue<decimal>(out var val)) { if (value.TryGetValue<decimal>(out var val)) {
idx = Array.IndexOf(virtCurves, val) + virtOffset; idx = Array.IndexOf(virtCurves, val) + virtOffset;
@ -75,7 +75,7 @@ namespace Elwig.Helpers.Billing {
var attrs = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a); var attrs = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
return entries return entries
.Select(e => new GraphEntry(e.Key, precision, curves[e.Key], e.Value .Select(e => new GraphEntry(e.Key, precision, curves[e.Key], e.Value
.Select(s => new ContractSelection(vars[s[..2]], s.Length > 2 ? attrs[s[2..]] : null)) .Select(s => new Varibute(vars[s[..2]], s.Length > 2 ? attrs[s[2..]] : null))
.ToList())) .ToList()))
.ToList(); .ToList();
} }
@ -83,7 +83,7 @@ namespace Elwig.Helpers.Billing {
public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext ctx, Season season) { public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext ctx, Season season) {
var root = GetPaymentEntry(); var root = GetPaymentEntry();
var (curves, entries) = GetGraphEntries(root); var (curves, entries) = GetGraphEntries(root);
return CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Contracts.Count > 0); return CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Vaributes.Count > 0);
} }
public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext ctx, Season season, int idOffset = 0) { public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext ctx, Season season, int idOffset = 0) {
@ -91,7 +91,7 @@ namespace Elwig.Helpers.Billing {
if (root == null || root["WEI"] is not JsonNode qualityWei) if (root == null || root["WEI"] is not JsonNode qualityWei)
return []; return [];
var (curves, entries) = GetGraphEntries(qualityWei); var (curves, entries) = GetGraphEntries(qualityWei);
var list = CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Contracts.Count > 0); var list = CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Vaributes.Count > 0);
foreach (var e in list) { foreach (var e in list) {
e.Id += idOffset; e.Id += idOffset;
e.Abgewertet = true; e.Abgewertet = true;

View File

@ -36,10 +36,10 @@ namespace Elwig.Helpers.Billing {
} }
} }
public List<ContractSelection> Contracts { get; set; } public List<Varibute> Vaributes { get; set; }
public string ContractsStringSimple => (Abgewertet ? "Abgew.: " : "") + (Contracts.Count != 0 ? (Contracts.Count >= 25 ? "Restliche Sorten" : string.Join(", ", Contracts.Select(c => c.Listing))) : "-"); public string VaributeStringSimple => (Abgewertet ? "Abgew.: " : "") + (Vaributes.Count != 0 ? (Vaributes.Count >= 25 ? "Restliche Sorten" : string.Join(", ", Vaributes.Select(c => c.Listing))) : "-");
public string ContractsString => Contracts.Count != 0 ? string.Join("\n", Contracts.Select(c => c.FullName)) : "-"; public string VaributeString => Vaributes.Count != 0 ? string.Join("\n", Vaributes.Select(c => c.FullName)) : "-";
public string ContractsStringChange => (Abgewertet ? "A." : "") + string.Join(",", Contracts.Select(c => c.Listing)); public string VaributeStringChange => (Abgewertet ? "A." : "") + string.Join(",", Vaributes.Select(c => c.Listing));
private readonly int Precision; private readonly int Precision;
public GraphEntry(int id, int precision, BillingData.CurveMode mode) { public GraphEntry(int id, int precision, BillingData.CurveMode mode) {
@ -47,7 +47,7 @@ namespace Elwig.Helpers.Billing {
Precision = precision; Precision = precision;
Mode = mode; Mode = mode;
DataGraph = new Graph(precision, MinX, MaxX); ; DataGraph = new Graph(precision, MinX, MaxX); ;
Contracts = []; Vaributes = [];
} }
public GraphEntry(int id, int precision, BillingData.CurveMode mode, Dictionary<double, decimal> data, Dictionary<double, decimal>? gebunden) : public GraphEntry(int id, int precision, BillingData.CurveMode mode, Dictionary<double, decimal> data, Dictionary<double, decimal>? gebunden) :
@ -56,21 +56,21 @@ namespace Elwig.Helpers.Billing {
if (gebunden != null) GebundenGraph = new Graph(gebunden, precision, MinXGeb, MaxX); if (gebunden != null) GebundenGraph = new Graph(gebunden, precision, MinXGeb, MaxX);
} }
public GraphEntry(int id, int precision, BillingData.Curve curve, List<ContractSelection> contracts) : public GraphEntry(int id, int precision, BillingData.Curve curve, List<Varibute> vaributes) :
this(id, precision, curve.Mode) { this(id, precision, curve.Mode) {
DataGraph = new Graph(curve.Normal, precision, MinX, MaxX); DataGraph = new Graph(curve.Normal, precision, MinX, MaxX);
if (curve.Gebunden != null) if (curve.Gebunden != null)
GebundenGraph = new Graph(curve.Gebunden, precision, MinXGeb, MaxX); GebundenGraph = new Graph(curve.Gebunden, precision, MinXGeb, MaxX);
Contracts = contracts; Vaributes = vaributes;
} }
private GraphEntry(int id, int precision, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph, List<ContractSelection> contracts) { private GraphEntry(int id, int precision, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph, List<Varibute> vaributes) {
Id = id; Id = id;
Precision = precision; Precision = precision;
Mode = mode; Mode = mode;
DataGraph = dataGraph; DataGraph = dataGraph;
GebundenGraph = gebundenGraph; GebundenGraph = gebundenGraph;
Contracts = contracts; Vaributes = vaributes;
} }
public void AddGebundenGraph() { public void AddGebundenGraph() {

View File

@ -9,24 +9,24 @@ namespace Elwig.Helpers.Billing {
protected readonly Dictionary<int, Curve> Curves; protected readonly Dictionary<int, Curve> Curves;
protected readonly Dictionary<string, Curve> PaymentData; protected readonly Dictionary<string, Curve> PaymentData;
protected readonly Dictionary<string, Curve> QualityData; protected readonly Dictionary<string, Curve> QualityData;
protected readonly IEnumerable<string> AttributeVariants; protected readonly IEnumerable<string> Vaributes;
public PaymentBillingData(JsonObject data, IEnumerable<string> attributeVariants) : public PaymentBillingData(JsonObject data, IEnumerable<string> vaributes) :
base(data) { base(data) {
if (attributeVariants.Any(e => e.Any(c => c < 'A' || c > 'Z'))) if (vaributes.Any(e => e.Any(c => c < 'A' || c > 'Z')))
throw new ArgumentException("Invalid attributeVariants"); throw new ArgumentException("Invalid vaributes");
AttributeVariants = attributeVariants; Vaributes = vaributes;
Curves = GetCurves(); Curves = GetCurves();
PaymentData = GetPaymentData(); PaymentData = GetPaymentData();
QualityData = GetQualityData(); QualityData = GetQualityData();
} }
public static PaymentBillingData FromJson(string json, IEnumerable<string> attributeVariants) { public static PaymentBillingData FromJson(string json, IEnumerable<string> vaributes) {
return new(ParseJson(json), attributeVariants); return new(ParseJson(json), vaributes);
} }
private Dictionary<string, Curve> GetData(JsonNode data) { private Dictionary<string, Curve> GetData(JsonNode data) {
return GetSelection(data, AttributeVariants).ToDictionary(e => e.Key, e => LookupCurve(e.Value)); return GetSelection(data, Vaributes).ToDictionary(e => e.Key, e => LookupCurve(e.Value));
} }
protected Dictionary<string, Curve> GetPaymentData() { protected Dictionary<string, Curve> GetPaymentData() {

View File

@ -2,14 +2,14 @@
using System; using System;
namespace Elwig.Helpers.Billing { namespace Elwig.Helpers.Billing {
public class ContractSelection : IComparable<ContractSelection> { public class Varibute : IComparable<Varibute> {
public WineVar? Variety { get; } public WineVar? Variety { get; }
public WineAttr? Attribute { get; } public WineAttr? Attribute { get; }
public string Listing => $"{Variety?.SortId}{Attribute?.AttrId}"; public string Listing => $"{Variety?.SortId}{Attribute?.AttrId}";
public string FullName => $"{Variety?.Name}" + (Variety != null && Attribute != null ? " " : "") + $"{Attribute?.Name}"; public string FullName => $"{Variety?.Name}" + (Variety != null && Attribute != null ? " " : "") + $"{Attribute?.Name}";
public ContractSelection(WineVar? var, WineAttr? attr) { public Varibute(WineVar? var, WineAttr? attr) {
Variety = var; Variety = var;
Attribute = attr; Attribute = attr;
} }
@ -18,7 +18,7 @@ namespace Elwig.Helpers.Billing {
return Listing; return Listing;
} }
public int CompareTo(ContractSelection? other) { public int CompareTo(Varibute? other) {
return Listing.CompareTo(other?.Listing); return Listing.CompareTo(other?.Listing);
} }
} }

View File

@ -362,7 +362,7 @@ namespace Elwig.Helpers {
return output.OrderByDescending(l => l.Count()); return output.OrderByDescending(l => l.Count());
} }
public static List<string> GetAttributeVarieties(AppDbContext ctx, int year, bool withSlash = false, bool onlyDelivered = true) { public static List<string> GetVaributes(AppDbContext ctx, int year, bool withSlash = false, bool onlyDelivered = true) {
var varieties = ctx.WineVarieties.Select(v => v.SortId).ToList(); var varieties = ctx.WineVarieties.Select(v => v.SortId).ToList();
var delivered = ctx.DeliveryParts var delivered = ctx.DeliveryParts
.Where(d => d.Year == year) .Where(d => d.Year == year)
@ -372,11 +372,11 @@ namespace Elwig.Helpers {
return [.. (onlyDelivered ? delivered : delivered.Union(varieties)).Order()]; return [.. (onlyDelivered ? delivered : delivered.Union(varieties)).Order()];
} }
public static List<ContractSelection> GetContractsForYear(AppDbContext ctx, int year, bool onlyDelivered = true) { public static List<Varibute> GetVaributesForYear(AppDbContext ctx, int year, bool onlyDelivered = true) {
var varieties = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v); var varieties = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
var attributes = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a); var attributes = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
return GetAttributeVarieties(ctx, year, false, onlyDelivered) return GetVaributes(ctx, year, false, onlyDelivered)
.Select(s => new ContractSelection(varieties[s[..2]], s.Length > 2 ? attributes[s[2..]] : null)) .Select(s => new Varibute(varieties[s[..2]], s.Length > 2 ? attributes[s[2..]] : null))
.ToList(); .ToList();
} }
} }

View File

@ -61,8 +61,8 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label Content="Für:" Margin="10,-2,0,0" FontSize="14" Grid.Column="0" VerticalAlignment="Center"/> <Label Content="Für:" Margin="10,-2,0,0" FontSize="14" Grid.Column="0" VerticalAlignment="Center"/>
<xctk:CheckComboBox x:Name="ContractInput" Margin="50,0,0,0" Grid.Column="0" <xctk:CheckComboBox x:Name="VaributeInput" Margin="50,0,0,0" Grid.Column="0"
Delimiter=", " AllItemsSelectedContent="Alle" IsEnabled="False" ItemSelectionChanged="ContractInput_Changed" Delimiter=", " AllItemsSelectedContent="Alle" IsEnabled="False" ItemSelectionChanged="VaributeInput_Changed"
Width="500" Height="25" HorizontalAlignment="Left"> Width="500" Height="25" HorizontalAlignment="Left">
<xctk:CheckComboBox.ItemTemplate> <xctk:CheckComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -83,7 +83,7 @@
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Id}" Width="30"/> <TextBlock Text="{Binding Id}" Width="30"/>
<TextBlock Text="{Binding ContractsStringSimple}" ToolTip="{Binding ContractsString}"/> <TextBlock Text="{Binding VaributeStringSimple}" ToolTip="{Binding VaributeString}"/>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>

View File

@ -84,18 +84,18 @@ namespace Elwig.Windows {
PaymentVar = await Context.PaymentVariants.FindAsync(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found"); PaymentVar = await Context.PaymentVariants.FindAsync(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found");
Season = await Context.Seasons.FindAsync(Year) ?? throw new ArgumentException("Season not found"); Season = await Context.Seasons.FindAsync(Year) ?? throw new ArgumentException("Season not found");
var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetAttributeVarieties(Context, Year)); var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetVaributes(Context, Year));
var paymentEntries = data.GetPaymentGraphEntries(Context, Season); var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
GraphEntries = [ GraphEntries = [
..paymentEntries, ..paymentEntries,
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Max(e => e.Id)) ..data.GetQualityGraphEntries(Context, Season, paymentEntries.Max(e => e.Id))
]; ];
var contracts = Utils.GetContractsForYear(Context, Year); var vaributes = Utils.GetVaributesForYear(Context, Year);
FillingInputs = true; FillingInputs = true;
ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.Listing); ControlUtils.RenewItemsSource(VaributeInput, vaributes, g => (g as Varibute)?.Listing);
FillingInputs = false; FillingInputs = false;
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.ContractsStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.VaributeStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
RefreshInputs(); RefreshInputs();
} }
@ -108,7 +108,7 @@ namespace Elwig.Windows {
GebundenTypeFixed.IsEnabled = true; GebundenTypeFixed.IsEnabled = true;
GebundenTypeGraph.IsEnabled = true; GebundenTypeGraph.IsEnabled = true;
GebundenTypeNone.IsEnabled = true; GebundenTypeNone.IsEnabled = true;
ContractInput.IsEnabled = true; VaributeInput.IsEnabled = true;
AbgewertetInput.IsEnabled = true; AbgewertetInput.IsEnabled = true;
EnableOptionButtons(); EnableOptionButtons();
FillInputs(); FillInputs();
@ -127,7 +127,7 @@ namespace Elwig.Windows {
GebundenTypeFixed.IsEnabled = false; GebundenTypeFixed.IsEnabled = false;
GebundenTypeGraph.IsEnabled = false; GebundenTypeGraph.IsEnabled = false;
GebundenTypeNone.IsEnabled = false; GebundenTypeNone.IsEnabled = false;
ContractInput.IsEnabled = false; VaributeInput.IsEnabled = false;
AbgewertetInput.IsEnabled = false; AbgewertetInput.IsEnabled = false;
} }
GC.Collect(); GC.Collect();
@ -148,7 +148,7 @@ namespace Elwig.Windows {
GebundenFlatBonus.Text = ""; GebundenFlatBonus.Text = "";
} }
ControlUtils.SelectCheckComboBoxItems(ContractInput, SelectedGraphEntry?.Contracts ?? [], i => (i as ContractSelection)?.Listing); ControlUtils.SelectCheckComboBoxItems(VaributeInput, SelectedGraphEntry?.Vaributes ?? [], i => (i as Varibute)?.Listing);
InitPlot(); InitPlot();
OechslePricePlot.IsEnabled = true; OechslePricePlot.IsEnabled = true;
@ -622,7 +622,7 @@ namespace Elwig.Windows {
if (SelectedGraphEntry == null) return; if (SelectedGraphEntry == null) return;
var r = MessageBox.Show( var r = MessageBox.Show(
$"Soll der Graph {SelectedGraphEntry.Id} (verwendet in folgenden Verträgen: {SelectedGraphEntry.ContractsStringSimple}) wirklich gelöscht werden?", $"Soll der Graph {SelectedGraphEntry.Id} (verwendet in folgenden Verträgen: {SelectedGraphEntry.VaributeStringSimple}) wirklich gelöscht werden?",
"Graph löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); "Graph löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
if (r == MessageBoxResult.Yes) { if (r == MessageBoxResult.Yes) {
@ -635,7 +635,7 @@ namespace Elwig.Windows {
private async void SaveButton_Click(object sender, RoutedEventArgs e) { private async void SaveButton_Click(object sender, RoutedEventArgs e) {
var origData = BillingData.FromJson(PaymentVar.Data); var origData = BillingData.FromJson(PaymentVar.Data);
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetAttributeVarieties(Context, Year, withSlash: true)); var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetVaributes(Context, Year, withSlash: true));
EntityEntry<PaymentVar>? tr = null; EntityEntry<PaymentVar>? tr = null;
try { try {
@ -715,32 +715,32 @@ namespace Elwig.Windows {
} }
} }
private void ContractInput_Changed(object sender, ItemSelectionChangedEventArgs e) { private void VaributeInput_Changed(object sender, ItemSelectionChangedEventArgs e) {
if (FillingInputs) return; if (FillingInputs) return;
if (e.IsSelected == true) { if (e.IsSelected == true) {
bool success = RemoveContractFromOtherGraphEntries(e.Item.ToString()); bool success = RemoveVaributeFromOtherGraphEntries(e.Item.ToString());
if (!success) { if (!success) {
ContractInput.SelectedItems.Remove(e.Item); VaributeInput.SelectedItems.Remove(e.Item);
} }
} }
var r = ContractInput.SelectedItems.Cast<ContractSelection>(); var r = VaributeInput.SelectedItems.Cast<Varibute>();
SelectedGraphEntry!.Contracts = r.ToList(); SelectedGraphEntry!.Vaributes = r.ToList();
SetHasChanged(); SetHasChanged();
GraphList.Items.Refresh(); GraphList.Items.Refresh();
} }
private bool RemoveContractFromOtherGraphEntries(string? contract) { private bool RemoveVaributeFromOtherGraphEntries(string? varibute) {
if (contract == null) return true; if (varibute == null) return true;
foreach (var ge in GraphEntries) { foreach (var ge in GraphEntries) {
if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) { if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) {
var toRemove = ge.Contracts.Where(c => c.Listing.Equals(contract)).ToList(); var toRemove = ge.Vaributes.Where(c => c.Listing.Equals(varibute)).ToList();
if (toRemove.Count == 0) continue; if (toRemove.Count == 0) continue;
var r = MessageBox.Show($"Achtung: {string.Join(", ", toRemove)} ist bereits in Graph {ge.Id} in Verwendung!\nSoll die Zuweisung dort entfernt werden?", "Entfernen bestätigen", var r = MessageBox.Show($"Achtung: {string.Join(", ", toRemove)} ist bereits in Graph {ge.Id} in Verwendung!\nSoll die Zuweisung dort entfernt werden?", "Entfernen bestätigen",
MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
if (r != MessageBoxResult.Yes) { if (r != MessageBoxResult.Yes) {
return false; return false;
} }
ge.Contracts.RemoveAll(c => c.Listing.Equals(contract)); ge.Vaributes.RemoveAll(c => c.Listing.Equals(varibute));
} }
} }
return true; return true;

View File

@ -8,7 +8,7 @@ namespace Tests.HelperTests {
public class BillingDataTest { public class BillingDataTest {
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true }; private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };
private static readonly string[] AttributeVariants = ["GV", "GVD", "GVK", "GVS", "GVZ", "WR", "WRS", "ZW", "ZWS", "ZWZ"]; private static readonly string[] Vaributes = ["GV", "GVD", "GVK", "GVS", "GVZ", "WR", "WRS", "ZW", "ZWS", "ZWZ"];
[OneTimeSetUp] [OneTimeSetUp]
public async Task SetupBilling() { public async Task SetupBilling() {
@ -52,7 +52,7 @@ namespace Tests.HelperTests {
"payment": 0.5, "payment": 0.5,
"curves": [] "curves": []
} }
""", AttributeVariants); """, Vaributes);
Assert.Multiple(() => { Assert.Multiple(() => {
TestCalcOe(data, "GV", 73, 0.5m); TestCalcOe(data, "GV", 73, 0.5m);
TestCalcOe(data, "WRS", 74, 0.5m); TestCalcOe(data, "WRS", 74, 0.5m);
@ -77,7 +77,7 @@ namespace Tests.HelperTests {
"geb": 0.10 "geb": 0.10
}] }]
} }
""", AttributeVariants); """, Vaributes);
Assert.Multiple(() => { Assert.Multiple(() => {
TestCalcOe(data, "GV", 70, 0.25m); TestCalcOe(data, "GV", 70, 0.25m);
TestCalcOe(data, "GV", 72, 0.25m); TestCalcOe(data, "GV", 72, 0.25m);
@ -114,7 +114,7 @@ namespace Tests.HelperTests {
} }
}] }]
} }
""", AttributeVariants); """, Vaributes);
Assert.Multiple(() => { Assert.Multiple(() => {
TestCalcKmw(data, "GV", 13.00, 0.10m); TestCalcKmw(data, "GV", 13.00, 0.10m);
TestCalcKmw(data, "GV", 13.50, 0.10m); TestCalcKmw(data, "GV", 13.50, 0.10m);
@ -148,7 +148,7 @@ namespace Tests.HelperTests {
}, },
"curves": [] "curves": []
} }
""", AttributeVariants); """, Vaributes);
Assert.Multiple(() => { Assert.Multiple(() => {
TestCalcOe(data, "WR", 73, 0.10m); TestCalcOe(data, "WR", 73, 0.10m);
TestCalcOe(data, "WRS", 73, 0.15m); TestCalcOe(data, "WRS", 73, 0.15m);
@ -179,7 +179,7 @@ namespace Tests.HelperTests {
}, },
"curves": [] "curves": []
} }
""", AttributeVariants); """, Vaributes);
Assert.Multiple(() => { Assert.Multiple(() => {
TestCalcOe(data, "GV", 75, 0.30m, qualid: "WEI"); TestCalcOe(data, "GV", 75, 0.30m, qualid: "WEI");
TestCalcOe(data, "ZW", 76, 0.25m, qualid: "WEI"); TestCalcOe(data, "ZW", 76, 0.25m, qualid: "WEI");
@ -221,7 +221,7 @@ namespace Tests.HelperTests {
} }
}] }]
} }
""", AttributeVariants); """, Vaributes);
Assert.Multiple(() => { Assert.Multiple(() => {
TestCalcKmw(data, "GV", 15.0, 2.0m); TestCalcKmw(data, "GV", 15.0, 2.0m);
TestCalcKmw(data, "GV", 15.5, 2.272727m); TestCalcKmw(data, "GV", 15.5, 2.272727m);
@ -281,7 +281,7 @@ namespace Tests.HelperTests {
} }
}] }]
} }
""", AttributeVariants); """, Vaributes);
Assert.Multiple(() => { Assert.Multiple(() => {
TestCalcKmw(data, "GV", 15.0, 0.75m); TestCalcKmw(data, "GV", 15.0, 0.75m);
TestCalcKmw(data, "GVS", 15.0, 0.50m); TestCalcKmw(data, "GVS", 15.0, 0.50m);
@ -340,7 +340,7 @@ namespace Tests.HelperTests {
} }
}] }]
} }
""", AttributeVariants); """, Vaributes);
Assert.Multiple(() => { Assert.Multiple(() => {
TestCalcOe(data, "GVK", 73, 0.032m); TestCalcOe(data, "GVK", 73, 0.032m);
TestCalcOe(data, "ZWS", 74, 0.033m); TestCalcOe(data, "ZWS", 74, 0.033m);
@ -349,11 +349,11 @@ namespace Tests.HelperTests {
}); });
} }
private static List<ContractSelection> GetSelection(IEnumerable<string> attVars) { private static List<Varibute> GetSelection(IEnumerable<string> attVars) {
return attVars.Select(s => { return attVars.Select(s => {
var sortid = s[..2]; var sortid = s[..2];
var attrid = s.Length > 2 ? s[2..] : null; var attrid = s.Length > 2 ? s[2..] : null;
return new ContractSelection( return new Varibute(
new WineVar(sortid, sortid), new WineVar(sortid, sortid),
attrid == null ? null : new WineAttr(attrid, attrid) attrid == null ? null : new WineAttr(attrid, attrid)
); );