diff --git a/Elwig/Helpers/Billing/BillingData.cs b/Elwig/Helpers/Billing/BillingData.cs index b5bb84c..0073b42 100644 --- a/Elwig/Helpers/Billing/BillingData.cs +++ b/Elwig/Helpers/Billing/BillingData.cs @@ -287,27 +287,41 @@ namespace Elwig.Helpers.Billing { var attributes = data .Select(e => e.Key) - .Where(k => !k.StartsWith('/') && k.Contains('/')) + .Where(k => k.Length > 3 && k.Contains('/')) .Select(k => k.Split('/')[1]) .Distinct() .ToList(); foreach (var idx in attributes) { - var len = vaributes.Count(e => e.AttrId == idx); + var len = vaributes.Count(e => $"{e.AttrId}{(e.CultId != null && e.CultId != "" ? "-" : "")}{e.CultId}" == idx); foreach (var (v, ks) in rev1) { var myKs = ks.Where(k => k.EndsWith($"/{idx}")).ToList(); if (myKs.Count > 1 && ((myKs.Count >= len * 0.5 && useDefault) || myKs.Count == len)) { foreach (var k in myKs) data.Remove(k); - data[(idx.StartsWith('-') ? "" : "/") + idx] = v; + data[(idx.StartsWith('-') && !useDefault ? "" : "/") + idx] = v; } } foreach (var (v, ks) in rev2) { var myKs = ks.Where(k => k.EndsWith($"/{idx}")).ToList(); if (myKs.Count > 1 && ((myKs.Count >= len * 0.5 && useDefault) || myKs.Count == len)) { foreach (var k in myKs) data.Remove(k); - data[(idx.StartsWith('-') ? "" : "/") + idx] = v; + data[(idx.StartsWith('-') && !useDefault ? "" : "/") + idx] = v; } } } + + if (!useDefault) + return; + + var keys = data.Select(p => p.Key).ToList(); + foreach (var k in keys) { + if (k.Length == 3 && k.EndsWith('/') && !keys.Contains(k[..2])) { + data.Remove(k, out var val); + data.Add(k[..2], val); + } else if (k.Contains("/-")) { + data.Remove(k, out var val); + data.Add(k.Replace("/-", "-"), val); + } + } } public static JsonObject FromGraphEntries( diff --git a/Elwig/Resources/Sql/17-18.sql b/Elwig/Resources/Sql/17-18.sql index d8a7551..4368b34 100644 --- a/Elwig/Resources/Sql/17-18.sql +++ b/Elwig/Resources/Sql/17-18.sql @@ -76,7 +76,7 @@ GROUP BY b.year, b.mgnr, b.sortid ORDER BY year, mgnr, bucket; PRAGMA schema_version = 1701; -PRAGMA writable_schame = OFF; +PRAGMA writable_schema = OFF; ---------------------------------------------------------------- @@ -89,4 +89,4 @@ DELETE FROM area_commitment_type WHERE attrid = 'B'; UPDATE delivery_part SET cultid = 'B', attrid = NULL WHERE attrid = 'B'; DELETE FROM wine_attribute WHERE attrid = 'B'; -UPDATE payment_variant SET data = REPLACE(REPLACE(data, '/B', '/-B'), '"/-B"', '"-B"'); +UPDATE payment_variant SET data = REPLACE(REPLACE(REPLACE(data, '/B', '-B'), '/"', '"'), '/-', '-'); diff --git a/Elwig/Windows/ChartWindow.xaml.cs b/Elwig/Windows/ChartWindow.xaml.cs index 40bf85e..f978412 100644 --- a/Elwig/Windows/ChartWindow.xaml.cs +++ b/Elwig/Windows/ChartWindow.xaml.cs @@ -126,7 +126,7 @@ namespace Elwig.Windows { Vaributes = Utils.GetVaributeList(Context, Year); GraphEntries.ForEach(e => { e.Vaributes.ForEach(v => { - var found = Vaributes.Find(a => a.Attribute?.AttrId == v.Attribute?.AttrId && a.Variety?.SortId == v.Variety?.SortId); + var found = Vaributes.Find(a => a.Variety?.SortId == v.Variety?.SortId && a.Attribute?.AttrId == v.Attribute?.AttrId && a.Cultivation?.CultId == v.Cultivation?.CultId); if (found == null) return; if (e.Abgewertet) { found.AssignedAbgewGraphId = e.Id; diff --git a/Tests/HelperTests/BillingDataTest.cs b/Tests/HelperTests/BillingDataTest.cs index c13eba4..954ee66 100644 --- a/Tests/HelperTests/BillingDataTest.cs +++ b/Tests/HelperTests/BillingDataTest.cs @@ -490,8 +490,8 @@ namespace Tests.HelperTests { "mode": "elwig", "version": 1, "payment": { - "WR/": 0.75, - "default": "curve:1" + "default": "curve:1", + "WR": 0.75 }, "curves": [ { @@ -528,10 +528,10 @@ namespace Tests.HelperTests { "mode": "elwig", "version": 1, "payment": { - "BP/": "curve:2", - "SA/": "curve:2", "default": 0.75, - "/K": "curve:1" + "/K": "curve:1", + "BP": "curve:2", + "SA": "curve:2" }, "curves": [ { @@ -576,9 +576,9 @@ namespace Tests.HelperTests { "mode": "elwig", "version": 1, "payment": { - "BP/": "curve:2", - "SA/": "curve:2", "default": 0.75, + "BP": "curve:2", + "SA": "curve:2", "-B": "curve:1" }, "curves": [ @@ -627,8 +627,8 @@ namespace Tests.HelperTests { "payment": { "default": 0.75, "/S": 0.3, - "-B": 0.2, - "/S-B": 0.4 + "/S-B": 0.4, + "-B": 0.2 }, "curves": [] }