Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
31b0ae245d | |||
46498ce337 | |||
0fff698a5d | |||
a71c6685f0 | |||
ab41702f6c | |||
2bbf4dd1fd | |||
8909b4a3a8 | |||
f8d776c028 | |||
2154e253ad | |||
df83430c35 | |||
d59a713a8c | |||
5e48d8e8d1 | |||
4f95d3fe16 | |||
ce3185842a | |||
e1d19fd9e5 | |||
3931a4084c | |||
1a492e4eff | |||
58a13eb3cc | |||
d5124829de | |||
37658869e4 | |||
24a43ff37d | |||
16cf055834 | |||
ef0b913063 | |||
05909919e2 | |||
3642c5ac07 | |||
6cee604448 | |||
89d20f4c42 | |||
182b367811 | |||
a2bb09cfbd | |||
b981b5f895 | |||
9dc2e8a59a | |||
1dc05e47cf | |||
21cc20ee63 | |||
491c41b239 | |||
47658a72ae | |||
8b0a4d7979 | |||
9ee7f6baf1 | |||
ecbc9c2d82 | |||
bf90543ad8 | |||
6a5676f916 | |||
75e9d756d2 | |||
ee161b149b | |||
0cb7b4bfc8 | |||
4a49a17b6a | |||
741ccaacae | |||
19f4300440 | |||
954c7a8bdb | |||
626724fe87 |
@ -7,7 +7,7 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
<ApplicationIcon>Resources\Images\Elwig.ico</ApplicationIcon>
|
||||
<Version>0.6.0</Version>
|
||||
<Version>0.6.1</Version>
|
||||
<SatelliteResourceLanguages>de-AT</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2210.55" />
|
||||
<PackageReference Include="NJsonSchema" Version="11.0.0" />
|
||||
<PackageReference Include="RazorLight" Version="2.3.1" />
|
||||
<PackageReference Include="ScottPlot.WPF" Version="4.1.68" />
|
||||
<PackageReference Include="ScottPlot.WPF" Version="5.0.19" />
|
||||
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
@ -124,6 +124,7 @@ namespace Elwig.Helpers.Billing {
|
||||
var obj = c?.AsObject() ?? throw new InvalidOperationException();
|
||||
var id = obj["id"]?.GetValue<int>() ?? throw new InvalidOperationException();
|
||||
var cMode = (obj["mode"]?.GetValue<string>() == "kmw") ? CurveMode.Kmw : CurveMode.Oe;
|
||||
double quw = cMode == CurveMode.Oe ? 73 : 15;
|
||||
|
||||
Dictionary<double, decimal> c1;
|
||||
Dictionary<double, decimal>? c2 = null;
|
||||
@ -131,7 +132,7 @@ namespace Elwig.Helpers.Billing {
|
||||
if (norm is JsonObject) {
|
||||
c1 = GetCurveData(norm.AsObject(), cMode);
|
||||
} else if (norm?.AsValue().TryGetValue(out decimal v) == true) {
|
||||
c1 = new() { { cMode == CurveMode.Oe ? 73 : 15, v } };
|
||||
c1 = new() { { quw, v } };
|
||||
} else {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
@ -139,11 +140,242 @@ namespace Elwig.Helpers.Billing {
|
||||
if (geb is JsonObject) {
|
||||
c2 = GetCurveData(geb.AsObject(), cMode);
|
||||
} else if (geb?.AsValue().TryGetValue(out decimal v) == true) {
|
||||
c2 = c1.ToDictionary(e => e.Key, e => e.Value + v);
|
||||
var splitVal = GetCurveValueAt(c1, quw);
|
||||
c2 = c1.ToDictionary(e => e.Key, e => e.Value + (e.Key >= quw ? v : 0));
|
||||
c2[quw] = splitVal + v;
|
||||
c2[Math.BitDecrement(quw)] = splitVal;
|
||||
}
|
||||
dict.Add(id, new(cMode, c1, c2));
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
protected static Dictionary<string, JsonValue> GetSelection(JsonNode value, IEnumerable<string> attributeVariants) {
|
||||
if (value is JsonValue flatRate) {
|
||||
return attributeVariants.ToDictionary(e => e, _ => flatRate);
|
||||
} if (value is not JsonObject data) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
Dictionary<string, JsonValue> dict;
|
||||
if (data["default"] is JsonValue def) {
|
||||
dict = attributeVariants.ToDictionary(e => e, _ => def);
|
||||
} else {
|
||||
dict = [];
|
||||
}
|
||||
|
||||
var variants = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length == 2);
|
||||
var attributes = data.Where(p => p.Key.StartsWith('/'));
|
||||
var others = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length > 2 && p.Key != "default");
|
||||
foreach (var (idx, v) in variants) {
|
||||
var curve = v?.AsValue() ?? throw new InvalidOperationException();
|
||||
foreach (var i in attributeVariants.Where(e => e.StartsWith(idx[..^1]))) {
|
||||
dict[i] = curve;
|
||||
}
|
||||
}
|
||||
foreach (var (idx, v) in attributes) {
|
||||
var curve = v?.AsValue() ?? throw new InvalidOperationException();
|
||||
foreach (var i in attributeVariants.Where(e => e[2..] == idx[1..])) {
|
||||
dict[i] = curve;
|
||||
}
|
||||
}
|
||||
foreach (var (idx, v) in others) {
|
||||
var curve = v?.AsValue() ?? throw new InvalidOperationException();
|
||||
dict[idx.Replace("/", "")] = curve;
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
public static decimal GetCurveValueAt(Dictionary<double, decimal> curve, double key) {
|
||||
if (curve.Count == 1) return curve.First().Value;
|
||||
|
||||
var lt = curve.Keys.Where(v => v <= key);
|
||||
var gt = curve.Keys.Where(v => v >= key);
|
||||
if (!lt.Any()) {
|
||||
return curve[gt.Min()];
|
||||
} else if (!gt.Any()) {
|
||||
return curve[lt.Max()];
|
||||
}
|
||||
|
||||
var max = lt.Max();
|
||||
var min = gt.Min();
|
||||
if (max == min) return curve[key];
|
||||
|
||||
var p1 = ((decimal)key - (decimal)min) / ((decimal)max - (decimal)min);
|
||||
var p2 = 1 - p1;
|
||||
return curve[min] * p2 + curve[max] * p1;
|
||||
}
|
||||
|
||||
protected static JsonObject GraphToJson(Graph graph, string mode) {
|
||||
var x = graph.DataX;
|
||||
var y = graph.DataY;
|
||||
var prec = graph.Precision;
|
||||
|
||||
try {
|
||||
return new JsonObject() {
|
||||
["15kmw"] = Math.Round(y.Distinct().Single(), prec)
|
||||
};
|
||||
} catch { }
|
||||
|
||||
var data = new JsonObject();
|
||||
if (y[0] != y[1]) {
|
||||
data[$"{x[0]}{mode}"] = Math.Round(y[0], prec);
|
||||
}
|
||||
for (int i = 1; i < x.Length - 1; i++) {
|
||||
var d1 = Math.Round(y[i] - y[i - 1], prec);
|
||||
var d2 = Math.Round(y[i + 1] - y[i], prec);
|
||||
if (d1 != d2) {
|
||||
data[$"{x[i]}{mode}"] = Math.Round(y[i], prec);
|
||||
}
|
||||
}
|
||||
if (y[^1] != y[^2]) {
|
||||
data[$"{x[^1]}{mode}"] = Math.Round(y[^1], prec);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
protected static JsonNode GraphEntryToJson(GraphEntry entry) {
|
||||
try {
|
||||
if (entry.GebundenFlatBonus == null) {
|
||||
return JsonValue.Create((decimal)entry.DataGraph.DataY.Distinct().Single());
|
||||
}
|
||||
} catch { }
|
||||
|
||||
var curve = new JsonObject {
|
||||
["id"] = entry.Id,
|
||||
["mode"] = entry.Mode.ToString().ToLower(),
|
||||
};
|
||||
|
||||
curve["data"] = GraphToJson(entry.DataGraph, entry.Mode.ToString().ToLower());
|
||||
|
||||
if (entry.GebundenFlatBonus != null) {
|
||||
curve["geb"] = (decimal)entry.GebundenFlatBonus;
|
||||
} else if (entry.GebundenGraph != null) {
|
||||
curve["geb"] = GraphToJson(entry.GebundenGraph, entry.Mode.ToString().ToLower());
|
||||
}
|
||||
|
||||
return curve;
|
||||
}
|
||||
|
||||
protected static void CollapsePaymentData(JsonObject data, IEnumerable<string> attributeVariants) {
|
||||
Dictionary<string, List<string>> rev1 = [];
|
||||
Dictionary<decimal, List<string>> rev2 = [];
|
||||
foreach (var (k, v) in data) {
|
||||
if (k == "default" || k.StartsWith('/') || !k.Contains('/') || v is not JsonValue val) {
|
||||
continue;
|
||||
} else if (val.TryGetValue<decimal>(out var dec)) {
|
||||
rev2[dec] = rev2.GetValueOrDefault(dec) ?? [];
|
||||
rev2[dec].Add(k);
|
||||
} else if (val.TryGetValue<string>(out var cur)) {
|
||||
rev1[cur] = rev1.GetValueOrDefault(cur) ?? [];
|
||||
rev1[cur].Add(k);
|
||||
}
|
||||
}
|
||||
if (!data.ContainsKey("default")) {
|
||||
foreach (var (v, ks) in rev1) {
|
||||
if (ks.Count >= attributeVariants.Count() / 2.0) {
|
||||
foreach (var k in ks) data.Remove(k);
|
||||
data["default"] = v;
|
||||
CollapsePaymentData(data, attributeVariants);
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach (var (v, ks) in rev2) {
|
||||
if (ks.Count >= attributeVariants.Count() / 2.0) {
|
||||
foreach (var k in ks) data.Remove(k);
|
||||
data["default"] = v;
|
||||
CollapsePaymentData(data, attributeVariants);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
var attributes = data
|
||||
.Select(e => e.Key)
|
||||
.Where(k => k.Length > 3 && k.Contains('/'))
|
||||
.Select(k => "/" + k.Split('/')[1])
|
||||
.Distinct()
|
||||
.ToList();
|
||||
foreach (var idx in attributes) {
|
||||
var len = attributeVariants.Count(e => e.EndsWith(idx));
|
||||
foreach (var (v, ks) in rev1) {
|
||||
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
|
||||
if (myKs.Count > 1 && myKs.Count >= len / 2.0) {
|
||||
foreach (var k in myKs) data.Remove(k);
|
||||
data[idx] = v;
|
||||
}
|
||||
}
|
||||
foreach (var (v, ks) in rev2) {
|
||||
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
|
||||
if (myKs.Count > 1 && myKs.Count >= len / 2.0) {
|
||||
foreach (var k in myKs) data.Remove(k);
|
||||
data[idx] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonObject FromGraphEntries(IEnumerable<GraphEntry> graphEntries, BillingData? origData = null, IEnumerable<string>? attributeVariants = null) {
|
||||
var payment = new JsonObject();
|
||||
var qualityWei = new JsonObject();
|
||||
var curves = new JsonArray();
|
||||
int curveId = 0;
|
||||
foreach (var entry in graphEntries) {
|
||||
var curve = GraphEntryToJson(entry);
|
||||
JsonValue node;
|
||||
if (curve is JsonObject obj) {
|
||||
obj["id"] = ++curveId;
|
||||
node = JsonValue.Create($"curve:{curveId}");
|
||||
curves.Add(obj);
|
||||
} else if (curve is JsonValue val && val.TryGetValue<decimal>(out var flat)) {
|
||||
node = JsonValue.Create(flat);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
foreach (var c in entry.Contracts) {
|
||||
if (entry.Abgewertet) {
|
||||
qualityWei[$"{c.Variety?.SortId}/{c.Attribute?.AttrId}"] = node.DeepClone();
|
||||
} else {
|
||||
payment[$"{c.Variety?.SortId}/{c.Attribute?.AttrId}"] = node.DeepClone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CollapsePaymentData(payment, attributeVariants ?? payment.Select(e => e.Key).ToList());
|
||||
CollapsePaymentData(qualityWei, attributeVariants ?? qualityWei.Select(e => e.Key).ToList());
|
||||
|
||||
var data = new JsonObject {
|
||||
["mode"] = "elwig",
|
||||
["version"] = 1,
|
||||
};
|
||||
|
||||
if (origData?.ConsiderDelieryModifiers == true)
|
||||
data["consider_delivery_modifiers"] = true;
|
||||
if (origData?.ConsiderContractPenalties == true)
|
||||
data["consider_contract_penalties"] = true;
|
||||
if (origData?.ConsiderTotalPenalty == true)
|
||||
data["consider_total_penalty"] = true;
|
||||
if (origData?.ConsiderAutoBusinessShares == true)
|
||||
data["consider_auto_business_shares"] = true;
|
||||
|
||||
if (payment.Count == 0) {
|
||||
data["payment"] = 0;
|
||||
} else if (payment.Count == 1) {
|
||||
data["payment"] = payment.Single().Value?.DeepClone();
|
||||
} else {
|
||||
data["payment"] = payment;
|
||||
}
|
||||
if (qualityWei.Count == 1) {
|
||||
data["quality"] = new JsonObject() {
|
||||
["WEI"] = qualityWei.Single().Value?.DeepClone()
|
||||
};
|
||||
} else if (qualityWei.Count > 1) {
|
||||
data["quality"] = new JsonObject() {
|
||||
["WEI"] = qualityWei
|
||||
};
|
||||
}
|
||||
data["curves"] = curves;
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,14 +15,7 @@ namespace Elwig.Helpers.Billing {
|
||||
public BillingVariant(int year, int avnr) : base(year) {
|
||||
AvNr = avnr;
|
||||
PaymentVariant = Context.PaymentVariants.Find(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found");
|
||||
var attrVariants = Context.DeliveryParts
|
||||
.Where(d => d.Year == Year)
|
||||
.Select(d => $"{d.SortId}{d.AttrId}")
|
||||
.Distinct()
|
||||
.ToList()
|
||||
.Union(Context.WineVarieties.Select(v => v.SortId))
|
||||
.ToList();
|
||||
Data = PaymentBillingData.FromJson(PaymentVariant.Data, attrVariants);
|
||||
Data = PaymentBillingData.FromJson(PaymentVariant.Data, Utils.GetAttributeVarieties(Context, Year, onlyDelivered: false));
|
||||
}
|
||||
|
||||
public async Task Calculate() {
|
||||
@ -31,9 +24,10 @@ namespace Elwig.Helpers.Billing {
|
||||
await DeleteInDb(cnx);
|
||||
await SetCalcTime(cnx);
|
||||
await CalculatePrices(cnx);
|
||||
if (Data.ConsiderDelieryModifiers)
|
||||
if (Data.ConsiderDelieryModifiers) {
|
||||
await CalculateDeliveryModifiers(cnx);
|
||||
await CalculateMemberModifiers(cnx);
|
||||
await CalculateMemberModifiers(cnx);
|
||||
}
|
||||
await tx.CommitAsync();
|
||||
}
|
||||
|
||||
@ -146,10 +140,10 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
|
||||
protected async Task CalculatePrices(SqliteConnection cnx) {
|
||||
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string Discr, int Value, double Oe, double Kmw, string QualId)>();
|
||||
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string? AttrId, string Discr, int Value, double Oe, double Kmw, string QualId)>();
|
||||
using (var cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = $"""
|
||||
SELECT d.year, d.did, d.dpnr, b.bktnr, d.sortid, b.discr, b.value, d.oe, d.kmw, d.qualid
|
||||
SELECT d.year, d.did, d.dpnr, b.bktnr, d.sortid, d.attrid, b.discr, b.value, d.oe, d.kmw, d.qualid
|
||||
FROM delivery_part_bucket b
|
||||
JOIN v_delivery d ON (d.year, d.did, d.dpnr) = (b.year, b.did, b.dpnr)
|
||||
WHERE b.year = {Year}
|
||||
@ -158,16 +152,18 @@ namespace Elwig.Helpers.Billing {
|
||||
while (await reader.ReadAsync()) {
|
||||
parts.Add((
|
||||
reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3),
|
||||
reader.GetString(4), reader.GetString(5), reader.GetInt32(6),
|
||||
reader.GetDouble(7), reader.GetDouble(8), reader.GetString(9)
|
||||
reader.GetString(4), reader.IsDBNull(5) ? null : reader.GetString(5), reader.GetString(6),
|
||||
reader.GetInt32(7), reader.GetDouble(8), reader.GetDouble(9), reader.GetString(10)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
var inserts = new List<(int Year, int DId, int DPNr, int BktNr, long Price, long Amount)>();
|
||||
foreach (var part in parts) {
|
||||
var attrId = (part.Discr == "_" || part.Discr == "") ? null : part.Discr;
|
||||
var price = Data.CalculatePrice(part.SortId, attrId, part.QualId, part.Discr != "_", part.Oe, part.Kmw);
|
||||
var ungeb = part.Discr == "_";
|
||||
var payAttrId = (part.Discr is "" or "_") ? null : part.Discr;
|
||||
var geb = !ungeb && payAttrId == part.AttrId;
|
||||
var price = Data.CalculatePrice(part.SortId, part.AttrId, part.QualId, geb, part.Oe, part.Kmw);
|
||||
var priceL = PaymentVariant.Season.DecToDb(price);
|
||||
inserts.Add((part.Year, part.DId, part.DPNr, part.BktNr, priceL, priceL * part.Value));
|
||||
}
|
||||
|
25
Elwig/Helpers/Billing/ContractSelection.cs
Normal file
25
Elwig/Helpers/Billing/ContractSelection.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Elwig.Models.Entities;
|
||||
using System;
|
||||
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class ContractSelection : IComparable<ContractSelection> {
|
||||
|
||||
public WineVar? Variety { get; }
|
||||
public WineAttr? Attribute { get; }
|
||||
public string Listing => $"{Variety?.SortId}{Attribute?.AttrId}";
|
||||
public string FullName => $"{Variety?.Name}" + (Variety != null && Attribute != null ? " " : "") + $"{Attribute?.Name}";
|
||||
|
||||
public ContractSelection(WineVar? var, WineAttr? attr) {
|
||||
Variety = var;
|
||||
Attribute = attr;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return Listing;
|
||||
}
|
||||
|
||||
public int CompareTo(ContractSelection? other) {
|
||||
return Listing.CompareTo(other?.Listing);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Elwig.Models.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
@ -16,11 +18,10 @@ namespace Elwig.Helpers.Billing {
|
||||
return new(ParseJson(json), attributeVariants);
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries() {
|
||||
private (Dictionary<int, Curve>, Dictionary<int, List<string>>) GetGraphEntries(JsonNode root) {
|
||||
Dictionary<int, List<string>> dict1 = [];
|
||||
Dictionary<decimal, List<string>> dict2 = [];
|
||||
var p = GetPaymentEntry();
|
||||
if (p is JsonObject paymentObj) {
|
||||
if (root is JsonObject paymentObj) {
|
||||
foreach (var (selector, node) in paymentObj) {
|
||||
var val = node?.AsValue();
|
||||
if (val == null) {
|
||||
@ -34,56 +35,67 @@ namespace Elwig.Helpers.Billing {
|
||||
dict1[idx].Add(selector);
|
||||
}
|
||||
}
|
||||
} else if (p is JsonValue paymentVal) {
|
||||
var idx = paymentVal.GetValue<decimal>();
|
||||
if (!dict2.ContainsKey(idx)) dict2[idx] = [];
|
||||
dict2[idx].Add("default");
|
||||
} else if (root is JsonValue paymentVal) {
|
||||
if (paymentVal.TryGetValue<decimal>(out var price)) {
|
||||
if (!dict2.ContainsKey(price)) dict2[price] = [];
|
||||
dict2[price].Add("default");
|
||||
} else if (paymentVal.TryGetValue<string>(out var curve)) {
|
||||
var idx = int.Parse(curve.Split(":")[1] ?? "0");
|
||||
if (!dict1.ContainsKey(idx)) dict1[idx] = [];
|
||||
dict1[idx].Add("default");
|
||||
}
|
||||
}
|
||||
|
||||
var virtOffset = dict1.Count > 0 ? dict1.Max(e => e.Key) + 1 : 1;
|
||||
Dictionary<int, Curve> curves = GetCurves();
|
||||
decimal[] virtCurves = [.. dict2.Keys.Order()];
|
||||
for (int i = 0; i < virtCurves.Length; i++) {
|
||||
var idx = virtCurves[i];
|
||||
dict1[1000 + i] = dict2[idx];
|
||||
curves[1000 + i] = new Curve(CurveMode.Oe, new() { { 73, idx } }, null);
|
||||
dict1[i + virtOffset] = dict2[idx];
|
||||
curves[i + virtOffset] = new Curve(CurveMode.Oe, new() { { 73, idx } }, null);
|
||||
}
|
||||
|
||||
Dictionary<int, List<string>> dict3 = [];
|
||||
Dictionary<int, List<string>> dict3 = curves.ToDictionary(c => c.Key, _ => new List<string>());
|
||||
foreach (var (selector, value) in GetSelection(root, AttributeVariants)) {
|
||||
int? idx = null;
|
||||
if (value.TryGetValue<decimal>(out var val)) {
|
||||
idx = Array.IndexOf(virtCurves, val) + virtOffset;
|
||||
} else if (value.TryGetValue<string>(out var str)) {
|
||||
idx = int.Parse(str.Split(":")[1]);
|
||||
}
|
||||
if (idx != null)
|
||||
dict3[(int)idx].Add(selector);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return dict3.Select(e => new GraphEntry(e.Key, curves[e.Key], 50, 120)).ToList();
|
||||
return (curves, dict3);
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetQualityGraphEntries() {
|
||||
Dictionary<int, List<string>> dict1 = [];
|
||||
Dictionary<decimal, List<string>> dict2 = [];
|
||||
foreach (var (qualid, q) in GetQualityEntry() ?? []) {
|
||||
if (q is JsonObject qualityObj) {
|
||||
foreach (var (selector, node) in qualityObj) {
|
||||
var val = node?.AsValue();
|
||||
if (val == null) {
|
||||
continue;
|
||||
} else if (val.TryGetValue<decimal>(out var price)) {
|
||||
if (!dict2.ContainsKey(price)) dict2[price] = [];
|
||||
dict2[price].Add(selector);
|
||||
} else if (val.TryGetValue<string>(out var curve)) {
|
||||
var idx = int.Parse(curve.Split(":")[1] ?? "0");
|
||||
if (!dict1.ContainsKey(idx)) dict1[idx] = [];
|
||||
dict1[idx].Add(selector);
|
||||
}
|
||||
}
|
||||
} else if (q is JsonValue qualityVal) {
|
||||
var idx = qualityVal.GetValue<decimal>();
|
||||
if (!dict2.ContainsKey(idx)) dict2[idx] = [];
|
||||
dict2[idx].Add($"{qualid}/");
|
||||
}
|
||||
private static List<GraphEntry> CreateGraphEntries(AppDbContext ctx, int precision, Dictionary<int, Curve> curves, Dictionary<int, List<string>> entries) {
|
||||
var vars = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
||||
var attrs = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
||||
return entries
|
||||
.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))
|
||||
.ToList()))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext ctx, Season season) {
|
||||
var root = GetPaymentEntry();
|
||||
var (curves, entries) = GetGraphEntries(root);
|
||||
return CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Contracts.Count > 0);
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext ctx, Season season, int idOffset = 0) {
|
||||
var root = GetQualityEntry();
|
||||
if (root == null || root["WEI"] is not JsonNode qualityWei)
|
||||
return [];
|
||||
var (curves, entries) = GetGraphEntries(qualityWei);
|
||||
var list = CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Contracts.Count > 0);
|
||||
foreach (var e in list) {
|
||||
e.Id += idOffset;
|
||||
e.Abgewertet = true;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
List<GraphEntry> list = [];
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -1,107 +1,107 @@
|
||||
using ScottPlot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class Graph : ICloneable {
|
||||
|
||||
public readonly int Precision;
|
||||
public double[] DataX { get; set; }
|
||||
public double[] DataY { get; set; }
|
||||
public int MinX { get; set; }
|
||||
public int MaxX { get; set; }
|
||||
|
||||
public Graph(int minX, int maxX) {
|
||||
DataX = DataGen.Range(minX, maxX + 1);
|
||||
DataY = DataGen.Zeros(maxX - minX + 1);
|
||||
public Graph(int precision, int minX, int maxX) {
|
||||
Precision = precision;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = Enumerable.Range(minX, maxX - minX + 1).Select(n => (double)n).ToArray();
|
||||
DataY = new double[DataX.Length];
|
||||
}
|
||||
|
||||
public Graph(Dictionary<double, decimal> data, int minX, int maxX) {
|
||||
DataX = DataGen.Range(minX, maxX + 1);
|
||||
DataY = DataGen.Zeros(maxX - minX + 1);
|
||||
ParseGraphData(data, minX, maxX);
|
||||
public Graph(Dictionary<double, decimal> data, int precision, int minX, int maxX) {
|
||||
Precision = precision;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = Enumerable.Range(minX, maxX - minX + 1).Select(n => (double)n).ToArray();
|
||||
DataY = DataX.Select(i => (double)BillingData.GetCurveValueAt(data, i)).ToArray();
|
||||
}
|
||||
|
||||
public Graph(double[] dataX, double[] dataY) {
|
||||
public Graph(double[] values, int precision, int minX, int maxX) {
|
||||
Precision = precision;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = Enumerable.Range(MinX, MaxX - MinX + 1).Select(i => (double)i).ToArray();
|
||||
DataY = values;
|
||||
}
|
||||
|
||||
private Graph(double[] dataX, double[] dataY, int precision, int minX, int maxX) {
|
||||
Precision = precision;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = dataX;
|
||||
DataY = dataY;
|
||||
}
|
||||
|
||||
private void ParseGraphData(Dictionary<double, decimal> graphPoints, int minX, int maxX) {
|
||||
if (graphPoints.Keys.Count < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var minKey = graphPoints.Keys.Order().First();
|
||||
var maxKey = graphPoints.Keys.OrderDescending().First();
|
||||
|
||||
if (!graphPoints.ContainsKey(minX)) {
|
||||
graphPoints.Add(minX, graphPoints.GetValueOrDefault(minKey));
|
||||
}
|
||||
if (!graphPoints.ContainsKey(maxX)) {
|
||||
graphPoints.Add(maxX, graphPoints.GetValueOrDefault(maxKey));
|
||||
}
|
||||
|
||||
var keys = graphPoints.Keys.Order().ToArray();
|
||||
|
||||
for (int i = 0; i < keys.Length; i++) {
|
||||
decimal point1Value = graphPoints[keys[i]];
|
||||
if (i + 1 < keys.Length) {
|
||||
decimal point2Value = graphPoints[keys[i + 1]];
|
||||
if (point1Value == point2Value) {
|
||||
for (int j = (int)(keys[i] - minX); j < keys[i + 1] - minX; j++) {
|
||||
DataY[j] = (double)point1Value;
|
||||
}
|
||||
} else {
|
||||
int steps = (int)Math.Abs(keys[i + 1] - keys[i]);
|
||||
decimal step = (point2Value - point1Value) / steps;
|
||||
|
||||
DataY[(int)(keys[i] - minX)] = (double)point1Value;
|
||||
DataY[(int)(keys[i + 1] - minX)] = (double)point2Value;
|
||||
|
||||
for (int j = (int)(keys[i] - minX); j < keys[i + 1] - minX - 1; j++) {
|
||||
DataY[j + 1] = Math.Round(DataY[j] + (double)step, 4); // TODO richtig runden
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int j = (int)(keys[i] - minX); j < DataX.Length; j++) {
|
||||
DataY[j] = (double)point1Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public double GetOechsleAt(int index) {
|
||||
return DataX[index];
|
||||
}
|
||||
|
||||
public void FlattenGraph(int begin, int end, double value) {
|
||||
public void SetOechsleAt(int index, double oechsle) {
|
||||
DataX[index] = oechsle;
|
||||
}
|
||||
|
||||
public void SetPriceAt(int index, double price) {
|
||||
DataY[index] = price;
|
||||
}
|
||||
|
||||
public double GetPriceAt(int index) {
|
||||
return DataY[index];
|
||||
}
|
||||
|
||||
public double GetPriceAtOe(double oe) {
|
||||
return DataY[Array.IndexOf(DataX, oe)];
|
||||
}
|
||||
|
||||
private void FlattenGraph(int begin, int end, double value) {
|
||||
for (int i = begin; i <= end; i++) {
|
||||
DataY[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void LinearIncreaseGraph(int begin, int end, double inc) {
|
||||
public void FlattenGraphLeft(int pointIndex) {
|
||||
FlattenGraph(0, pointIndex, DataY[pointIndex]);
|
||||
}
|
||||
|
||||
public void FlattenGraphRight(int pointIndex) {
|
||||
FlattenGraph(pointIndex, DataY.Length - 1, DataY[pointIndex]);
|
||||
}
|
||||
|
||||
private void LinearIncreaseGraph(int begin, int end, double inc) {
|
||||
for (int i = begin; i < end; i++) {
|
||||
DataY[i + 1] = DataY[i] + inc;
|
||||
DataY[i + 1] = Math.Round(DataY[i] + inc, Precision);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject ToJson(string mode) {
|
||||
var data = new JsonObject();
|
||||
public void LinearIncreaseGraphToEnd(int begin, double inc) {
|
||||
LinearIncreaseGraph(begin, DataY.Length - 1, inc);
|
||||
}
|
||||
|
||||
if (DataY[0] != DataY[1]) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[0] + mode, Math.Round(DataY[0], 4)));
|
||||
public void InterpolateGraph(int firstPoint, int secondPoint) {
|
||||
int steps = Math.Abs(firstPoint - secondPoint);
|
||||
if (firstPoint == -1 || secondPoint == -1 || steps < 2) {
|
||||
return;
|
||||
}
|
||||
for (int i = 1; i < DataX.Length - 1; i++) {
|
||||
if (Math.Round(DataY[i] - DataY[i - 1], 10) != Math.Round(DataY[i + 1] - DataY[i], 10)) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[i] + mode, Math.Round(DataY[i], 4)));
|
||||
}
|
||||
var (lowIndex, highIndex) = firstPoint < secondPoint ? (firstPoint, secondPoint) : (secondPoint, firstPoint);
|
||||
double step = (DataY[highIndex] - DataY[lowIndex]) / steps;
|
||||
|
||||
for (int i = lowIndex; i < highIndex - 1; i++) {
|
||||
DataY[i + 1] = Math.Round(DataY[i] + step, Precision);
|
||||
}
|
||||
if (DataY[^1] != DataY[^2]) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[^1] + mode, Math.Round(DataY[^1], 4)));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public object Clone() {
|
||||
return new Graph((double[])DataX.Clone(), (double[])DataY.Clone());
|
||||
return new Graph((double[])DataX.Clone(), (double[])DataY.Clone(), Precision, MinX, MaxX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +1,88 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Nodes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class GraphEntry {
|
||||
|
||||
public const int MinX = 50;
|
||||
public const int MinXGeb = 73;
|
||||
public const int MaxX = 140;
|
||||
|
||||
public int Id { get; set; }
|
||||
public BillingData.CurveMode Mode { get; set; }
|
||||
public bool Abgewertet { get; set; }
|
||||
|
||||
public Graph DataGraph { get; set; }
|
||||
public Graph? GebundenGraph { get; set; }
|
||||
public decimal? GebundenFlatPrice { get; set; }
|
||||
public List<string> Contracts { get; set; }
|
||||
private int MinX { get; set; }
|
||||
private int MaxX { get; set; }
|
||||
public double? GebundenFlatBonus {
|
||||
get {
|
||||
try {
|
||||
var val = GebundenGraph?.DataX.Zip(GebundenGraph.DataY)
|
||||
.Select(e => Math.Round(e.Second - DataGraph.GetPriceAtOe(e.First), Precision))
|
||||
.Distinct()
|
||||
.Single();
|
||||
return (val == 0) ? null : val;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
set {
|
||||
if (value is not double v) return;
|
||||
var values = Enumerable.Range(MinXGeb, MaxX - MinXGeb + 1)
|
||||
.Select(i => Math.Round(DataGraph.GetPriceAtOe(i) + v, Precision))
|
||||
.ToArray();
|
||||
GebundenGraph = new Graph(values, Precision, MinXGeb, MaxX);
|
||||
}
|
||||
}
|
||||
|
||||
public GraphEntry(int id, BillingData.CurveMode mode, int minX, int maxX) {
|
||||
public List<ContractSelection> Contracts { get; set; }
|
||||
public string ContractsStringSimple => (Abgewertet ? "Abgew.: " : "") + (Contracts.Count != 0 ? (Contracts.Count >= 25 ? "Restliche Sorten" : string.Join(", ", Contracts.Select(c => c.Listing))) : "-");
|
||||
public string ContractsString => Contracts.Count != 0 ? string.Join("\n", Contracts.Select(c => c.FullName)) : "-";
|
||||
public string ContractsStringChange => (Abgewertet ? "A." : "") + string.Join(",", Contracts.Select(c => c.Listing));
|
||||
private readonly int Precision;
|
||||
|
||||
public GraphEntry(int id, int precision, BillingData.CurveMode mode) {
|
||||
Id = id;
|
||||
Precision = precision;
|
||||
Mode = mode;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataGraph = new Graph(minX, maxX);
|
||||
DataGraph = new Graph(precision, MinX, MaxX); ;
|
||||
Contracts = [];
|
||||
}
|
||||
|
||||
public GraphEntry(int id, BillingData.CurveMode mode, Dictionary<double, decimal> data, int minX, int maxX) :
|
||||
this(id, mode, minX, maxX) {
|
||||
DataGraph = new Graph(data, minX, maxX);
|
||||
public GraphEntry(int id, int precision, BillingData.CurveMode mode, Dictionary<double, decimal> data, Dictionary<double, decimal>? gebunden) :
|
||||
this(id, precision, mode) {
|
||||
DataGraph = new Graph(data, precision, MinX, MaxX);
|
||||
if (gebunden != null) GebundenGraph = new Graph(gebunden, precision, MinXGeb, MaxX);
|
||||
}
|
||||
|
||||
public GraphEntry(int id, BillingData.Curve curve, int minX, int maxX) :
|
||||
this(id, curve.Mode, minX, maxX) {
|
||||
DataGraph = new Graph(curve.Normal, minX, maxX);
|
||||
public GraphEntry(int id, int precision, BillingData.Curve curve, List<ContractSelection> contracts) :
|
||||
this(id, precision, curve.Mode) {
|
||||
DataGraph = new Graph(curve.Normal, precision, MinX, MaxX);
|
||||
if (curve.Gebunden != null)
|
||||
GebundenGraph = new Graph(curve.Gebunden, minX, maxX);
|
||||
}
|
||||
|
||||
private GraphEntry(int id, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph,
|
||||
decimal? gebundenFlatPrice, List<string> contracts, int minX, int maxX) {
|
||||
Id = id;
|
||||
Mode = mode;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataGraph = dataGraph;
|
||||
GebundenGraph = gebundenGraph;
|
||||
GebundenFlatPrice = gebundenFlatPrice;
|
||||
GebundenGraph = new Graph(curve.Gebunden, precision, MinXGeb, MaxX);
|
||||
Contracts = contracts;
|
||||
}
|
||||
|
||||
public JsonObject ToJson() {
|
||||
var curve = new JsonObject {
|
||||
["id"] = Id,
|
||||
["mode"] = Mode.ToString().ToLower(),
|
||||
};
|
||||
private GraphEntry(int id, int precision, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph, List<ContractSelection> contracts) {
|
||||
Id = id;
|
||||
Precision = precision;
|
||||
Mode = mode;
|
||||
DataGraph = dataGraph;
|
||||
GebundenGraph = gebundenGraph;
|
||||
Contracts = contracts;
|
||||
}
|
||||
|
||||
curve["data"] = DataGraph.ToJson(Mode.ToString().ToLower());
|
||||
public void AddGebundenGraph() {
|
||||
GebundenGraph ??= new Graph(Precision, MinXGeb, MaxX);
|
||||
}
|
||||
|
||||
if (GebundenFlatPrice != null) {
|
||||
curve["geb"] = GebundenFlatPrice.ToString();
|
||||
} else if (GebundenGraph != null) {
|
||||
curve["geb"] = GebundenGraph.ToJson(Mode.ToString().ToLower());
|
||||
}
|
||||
|
||||
return curve;
|
||||
public void RemoveGebundenGraph() {
|
||||
GebundenGraph = null;
|
||||
}
|
||||
|
||||
public GraphEntry Copy(int id) {
|
||||
return new GraphEntry(id, Mode, (Graph)DataGraph.Clone(), (Graph?)GebundenGraph?.Clone(), GebundenFlatPrice, Contracts, MinX, MaxX);
|
||||
return new GraphEntry(id, Precision, Mode, (Graph)DataGraph.Clone(), (Graph?)GebundenGraph?.Clone(), []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
@ -26,45 +25,12 @@ namespace Elwig.Helpers.Billing {
|
||||
return new(ParseJson(json), attributeVariants);
|
||||
}
|
||||
|
||||
private Dictionary<string, Curve> GetData(JsonObject data) {
|
||||
Dictionary<string, Curve> dict;
|
||||
if (data["default"] is JsonValue def) {
|
||||
var c = LookupCurve(def);
|
||||
dict = AttributeVariants.ToDictionary(e => e, _ => c);
|
||||
} else {
|
||||
dict = [];
|
||||
}
|
||||
|
||||
var variants = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length == 2);
|
||||
var attributes = data.Where(p => p.Key.StartsWith('/'));
|
||||
var others = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length > 2);
|
||||
foreach (var (idx, v) in variants) {
|
||||
var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException());
|
||||
foreach (var i in AttributeVariants.Where(e => e.StartsWith(idx[..^1]))) {
|
||||
dict[i] = curve;
|
||||
}
|
||||
}
|
||||
foreach (var (idx, v) in attributes) {
|
||||
var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException());
|
||||
foreach (var i in AttributeVariants.Where(e => e[2..] == idx[1..])) {
|
||||
dict[i] = curve;
|
||||
}
|
||||
}
|
||||
foreach (var (idx, v) in others) {
|
||||
var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException());
|
||||
dict[idx.Replace("/", "")] = curve;
|
||||
}
|
||||
|
||||
return dict;
|
||||
private Dictionary<string, Curve> GetData(JsonNode data) {
|
||||
return GetSelection(data, AttributeVariants).ToDictionary(e => e.Key, e => LookupCurve(e.Value));
|
||||
}
|
||||
|
||||
protected Dictionary<string, Curve> GetPaymentData() {
|
||||
var p = GetPaymentEntry();
|
||||
if (p is JsonValue val) {
|
||||
var c = LookupCurve(val);
|
||||
return AttributeVariants.ToDictionary(e => e, _ => c);
|
||||
}
|
||||
return GetData(p?.AsObject() ?? throw new InvalidOperationException());
|
||||
return GetData(GetPaymentEntry());
|
||||
}
|
||||
|
||||
protected Dictionary<string, Curve> GetQualityData() {
|
||||
@ -73,14 +39,7 @@ namespace Elwig.Helpers.Billing {
|
||||
if (q == null) return dict;
|
||||
|
||||
foreach (var (qualid, data) in q) {
|
||||
Dictionary<string, Curve> qualDict;
|
||||
if (data is JsonValue val) {
|
||||
var c = LookupCurve(val);
|
||||
qualDict = AttributeVariants.ToDictionary(e => e, _ => c);
|
||||
} else {
|
||||
qualDict = GetData(data?.AsObject() ?? throw new InvalidOperationException());
|
||||
}
|
||||
foreach (var (idx, d) in qualDict) {
|
||||
foreach (var (idx, d) in GetData(data ?? throw new InvalidOperationException())) {
|
||||
dict[$"{qualid}/{idx}"] = d;
|
||||
}
|
||||
}
|
||||
@ -90,25 +49,7 @@ namespace Elwig.Helpers.Billing {
|
||||
|
||||
public decimal CalculatePrice(string sortid, string? attrid, string qualid, bool gebunden, double oe, double kmw) {
|
||||
var curve = GetQualityCurve(qualid, sortid, attrid) ?? GetCurve(sortid, attrid);
|
||||
var d = (gebunden ? curve.Gebunden : null) ?? curve.Normal;
|
||||
if (d.Count == 1) return d.First().Value;
|
||||
|
||||
var r = curve.Mode == CurveMode.Oe ? oe : kmw;
|
||||
var lt = d.Keys.Where(v => v <= r);
|
||||
var gt = d.Keys.Where(v => v >= r);
|
||||
if (!lt.Any()) {
|
||||
return d[gt.Min()];
|
||||
} else if (!gt.Any()) {
|
||||
return d[lt.Max()];
|
||||
}
|
||||
|
||||
var max = lt.Max();
|
||||
var min = gt.Min();
|
||||
if (max == min) return d[r];
|
||||
|
||||
var p1 = ((decimal)r - (decimal)min) / ((decimal)max - (decimal)min);
|
||||
var p2 = 1 - p1;
|
||||
return d[min] * p2 + d[max] * p1;
|
||||
return GetCurveValueAt((gebunden ? curve.Gebunden : null) ?? curve.Normal, curve.Mode == CurveMode.Oe ? oe : kmw);
|
||||
}
|
||||
|
||||
private Curve LookupCurve(JsonValue val) {
|
||||
@ -122,11 +63,11 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
|
||||
protected Curve GetCurve(string sortid, string? attrid) {
|
||||
return PaymentData[$"{sortid}{attrid ?? ""}"];
|
||||
return PaymentData[$"{sortid}{attrid}"];
|
||||
}
|
||||
|
||||
protected Curve? GetQualityCurve(string qualid, string sortid, string? attrid) {
|
||||
return QualityData.TryGetValue($"{qualid}/{sortid}{attrid ?? ""}", out var curve) ? curve : null;
|
||||
return QualityData.TryGetValue($"{qualid}/{sortid}{attrid}", out var curve) ? curve : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,12 +74,16 @@ namespace Elwig.Helpers.Printing {
|
||||
}
|
||||
|
||||
public static async Task Print(string path, int copies = 1) {
|
||||
var p = new Process() { StartInfo = new() { FileName = PdfToPrinter } };
|
||||
p.StartInfo.ArgumentList.Add(path);
|
||||
p.StartInfo.ArgumentList.Add("/s");
|
||||
p.StartInfo.ArgumentList.Add($"copies={copies}");
|
||||
p.Start();
|
||||
await p.WaitForExitAsync();
|
||||
try {
|
||||
var p = new Process() { StartInfo = new() { FileName = PdfToPrinter } };
|
||||
p.StartInfo.ArgumentList.Add(path);
|
||||
p.StartInfo.ArgumentList.Add("/s");
|
||||
p.StartInfo.ArgumentList.Add($"copies={copies}");
|
||||
p.Start();
|
||||
await p.WaitForExitAsync();
|
||||
} catch (Exception e) {
|
||||
MessageBox.Show("Beim Drucken ist ein Fehler aufgetreten:\n\n" + e.Message, "Fehler beim Drucken");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ using System.Text;
|
||||
using System.Numerics;
|
||||
using Elwig.Models.Entities;
|
||||
using System.IO;
|
||||
using ScottPlot.TickGenerators.TimeUnits;
|
||||
using Elwig.Helpers.Billing;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
public static partial class Utils {
|
||||
@ -359,5 +361,23 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
return output.OrderByDescending(l => l.Count());
|
||||
}
|
||||
|
||||
public static List<string> GetAttributeVarieties(AppDbContext ctx, int year, bool withSlash = false, bool onlyDelivered = true) {
|
||||
var varieties = ctx.WineVarieties.Select(v => v.SortId).ToList();
|
||||
var delivered = ctx.DeliveryParts
|
||||
.Where(d => d.Year == year)
|
||||
.Select(d => $"{d.SortId}{(withSlash ? "/" : "")}{d.AttrId}")
|
||||
.Distinct()
|
||||
.ToList();
|
||||
return [.. (onlyDelivered ? delivered : delivered.Union(varieties)).Order()];
|
||||
}
|
||||
|
||||
public static List<ContractSelection> GetContractsForYear(AppDbContext ctx, int year, bool onlyDelivered = true) {
|
||||
var varieties = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
||||
var attributes = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
||||
return GetAttributeVarieties(ctx, year, false, onlyDelivered)
|
||||
.Select(s => new ContractSelection(varieties[s[..2]], s.Length > 2 ? attributes[s[2..]] : null))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,19 +68,32 @@ namespace Elwig.Models.Entities {
|
||||
|
||||
[InverseProperty("Delivery")]
|
||||
public virtual ISet<DeliveryPart> Parts { get; private set; }
|
||||
[NotMapped]
|
||||
public IEnumerable<DeliveryPart> FilteredParts => PartFilter == null ? Parts : Parts.Where(p => PartFilter(p));
|
||||
|
||||
[NotMapped]
|
||||
public Predicate<DeliveryPart>? PartFilter { get; set; }
|
||||
|
||||
public int Weight => Parts.Select(p => p.Weight).Sum();
|
||||
public int FilteredWeight => FilteredParts.Select(p => p.Weight).Sum();
|
||||
|
||||
public IEnumerable<string> SortIds => Parts
|
||||
.GroupBy(p => p.SortId)
|
||||
.OrderByDescending(g => g.Select(p => p.Weight).Sum())
|
||||
.Select(g => g.Select(p => p.SortId).First());
|
||||
.Select(g => g.Key);
|
||||
public IEnumerable<string> FilteredSortIds => FilteredParts
|
||||
.GroupBy(p => p.SortId)
|
||||
.OrderByDescending(g => g.Select(p => p.Weight).Sum())
|
||||
.Select(g => g.Key);
|
||||
|
||||
public string SortIdString => string.Join(", ", SortIds);
|
||||
public string FilteredSortIdString => string.Join(", ", FilteredSortIds);
|
||||
|
||||
public double Kmw => Utils.AggregateDeliveryPartsKmw(Parts);
|
||||
public double FilteredKmw => Utils.AggregateDeliveryPartsKmw(FilteredParts);
|
||||
|
||||
public double Oe => Utils.KmwToOe(Kmw);
|
||||
public double FilteredOe => Utils.KmwToOe(FilteredKmw);
|
||||
|
||||
public int SearchScore(IEnumerable<string> keywords) {
|
||||
var list = new string?[] {
|
||||
|
@ -23,6 +23,13 @@ namespace Elwig.Models.Entities {
|
||||
[Column("fill_lower")]
|
||||
public int FillLower { get; set; }
|
||||
|
||||
public WineAttr() { }
|
||||
|
||||
public WineAttr(string attrId, string name) {
|
||||
AttrId = attrId;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return Name;
|
||||
}
|
||||
|
@ -21,6 +21,13 @@ namespace Elwig.Models.Entities {
|
||||
public bool IsRed => Type == "R";
|
||||
public bool IsWhite => Type == "W";
|
||||
|
||||
public WineVar() { }
|
||||
|
||||
public WineVar(string sortId, string name) {
|
||||
SortId = sortId;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return Name;
|
||||
}
|
||||
|
@ -5,11 +5,13 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Elwig.Windows"
|
||||
xmlns:ctrl="clr-namespace:Elwig.Controls"
|
||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
xmlns:ScottPlot="clr-namespace:ScottPlot;assembly=ScottPlot.WPF"
|
||||
xmlns:ScottPlot="clr-namespace:ScottPlot.WPF;assembly=ScottPlot.WPF"
|
||||
mc:Ignorable="d"
|
||||
Title="Auszahlung - Elwig" Height="700" Width="1500" MinWidth="1000" MinHeight="500"
|
||||
Loaded="Window_Loaded">
|
||||
Loaded="Window_Loaded"
|
||||
Closing="Window_Closing">
|
||||
|
||||
<Window.Resources>
|
||||
<Style TargetType="Label">
|
||||
@ -47,61 +49,63 @@
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="230"/>
|
||||
<ColumnDefinition Width="300"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="200"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">
|
||||
<Grid Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition Width="500"/>
|
||||
<ColumnDefinition Width="560"/>
|
||||
<ColumnDefinition Width="100"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Content="Graph:" Margin="10,0,0,0" FontSize="14" Grid.Column="0" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="GraphNum" Margin="0,0,40,0" FontSize="14" Width="50" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"/>
|
||||
|
||||
<Label Content="Für:" Margin="10,0,0,0" FontSize="14" Grid.Column="1" VerticalAlignment="Center"/>
|
||||
<xctk:CheckComboBox x:Name="AppliedInput" Margin="0,10,10,10" Grid.Column="1"
|
||||
Delimiter=", " AllItemsSelectedContent="Alle"
|
||||
Width="400" HorizontalAlignment="Right">
|
||||
<!--<xctk:CheckComboBox.ItemTemplate>
|
||||
<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"
|
||||
Delimiter=", " AllItemsSelectedContent="Alle" IsEnabled="False" ItemSelectionChanged="ContractInput_Changed"
|
||||
Width="500" Height="25" HorizontalAlignment="Left">
|
||||
<xctk:CheckComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{}" Width="40"/>
|
||||
<TextBlock Text="{Binding Variety.Name}" Width="150"/>
|
||||
<TextBlock Text="{Binding Attribute.Name}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</xctk:CheckComboBox.ItemTemplate>-->
|
||||
</xctk:CheckComboBox.ItemTemplate>
|
||||
</xctk:CheckComboBox>
|
||||
|
||||
<CheckBox x:Name="AbgewertetInput" Content="Abgewertet" IsEnabled="False" Checked="AbgewertetInput_Changed" Unchecked="AbgewertetInput_Changed"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,0,0,0" Grid.Column="1"/>
|
||||
</Grid>
|
||||
|
||||
<ListBox x:Name="GraphList" Margin="10,10,35,50" Grid.Column="0" Grid.Row="1" SelectionChanged="GraphList_SelectionChanged">
|
||||
<ListBox x:Name="GraphList" Margin="10,10,35,42" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" SelectionChanged="GraphList_SelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Id}" Width="40"/>
|
||||
<TextBlock Text="{Binding Contracts}" Width="100"/>
|
||||
<TextBlock Text="{Binding Id}" Width="30"/>
|
||||
<TextBlock Text="{Binding ContractsStringSimple}" ToolTip="{Binding ContractsString}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<Button x:Name="SaveButton" Content="Speichern" IsEnabled="True"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="10,5,35,15" Grid.Column="0" Grid.Row="2"
|
||||
<Button x:Name="SaveButton" Content="Speichern" IsEnabled="False"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="10,5,35,10" Grid.Column="0" Grid.Row="2"
|
||||
Click="SaveButton_Click"/>
|
||||
|
||||
<Button x:Name="AddButton" Content="" FontFamily="Segoe MDL2 Assets" FontSize="11" Padding="0,1.5,0,0" ToolTip="Neue Auszahlungsvariante hinzufügen"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Width="25" Height="25" Margin="5,0,5,60" Grid.Column="0" Grid.Row="1"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Width="25" Height="25" Margin="5,0,5,60" Grid.Column="0" Grid.RowSpan="2" Grid.Row="0"
|
||||
Click="AddButton_Click"/>
|
||||
<Button x:Name="CopyButton" Content="" FontFamily="Segoe MDL2 Assets" FontSize="12" Padding="0,0,0,0" IsEnabled="False" ToolTip="Ausgewählte Auszahlungsvariante duplizieren"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Width="25" Height="25" Margin="0,0,5,0" Grid.Column="0" Grid.Row="1"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Width="25" Height="25" Margin="0,0,5,0" Grid.Column="0" Grid.RowSpan="2" Grid.Row="0"
|
||||
Click="CopyButton_Click"/>
|
||||
<Button x:Name="DeleteButton" Content="" FontFamily="Segoe MDL2 Assets" FontSize="11" Padding="0,1.5,0,0" IsEnabled="False" ToolTip="Ausgewählte Auszahlungsvariante löschen"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Width="25" Height="25" Margin="5,60,5,0" Grid.Column="0" Grid.Row="1"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Width="25" Height="25" Margin="5,60,5,0" Grid.Column="0" Grid.RowSpan="2" Grid.Row="0"
|
||||
Click="DeleteButton_Click"/>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="1">
|
||||
<ScottPlot:WpfPlot x:Name="OechslePricePlot" MouseMove="OechslePricePlot_MouseMove" MouseDown="OechslePricePlot_MouseDown" IsEnabled="False"/>
|
||||
<Grid Grid.Row="1" Grid.Column="1" Margin="0,0,10,10">
|
||||
<ScottPlot:WpfPlot x:Name="OechslePricePlot" IsEnabled="False"
|
||||
MouseWheel="OechslePricePlot_MouseWheel" MouseMove="OechslePricePlot_MouseMove" MouseDown="OechslePricePlot_MouseDown"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="2" Margin="0,0,5,36">
|
||||
@ -121,48 +125,40 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Content="Oechsle:" Margin="10,10,0,0" Grid.Column="0"/>
|
||||
<TextBox x:Name="OechsleInput" Grid.Column="1" HorizontalAlignment="Left" Margin="0,10,0,0" Text="" Width="90" TextChanged="OechsleInput_TextChanged" LostFocus="OechsleInput_LostFocus"/>
|
||||
<ctrl:UnitTextBox x:Name="OechsleInput" Unit="°Oe" TextChanged="OechsleInput_TextChanged" IsEnabled="False" LostFocus="OechsleInput_LostFocus"
|
||||
Grid.Column="1" Width="90" Margin="0,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
||||
|
||||
<Label Content="Preis pro kg:" Margin="10,40,0,0" Grid.Column="0"/>
|
||||
<TextBox x:Name="PriceInput" Grid.Column="1" HorizontalAlignment="Left" Margin="0,40,0,0" Text="" Width="90" TextChanged="PriceInput_TextChanged" LostFocus="PriceInput_LostFocus"/>
|
||||
|
||||
<Label Content="Preis:" Margin="10,40,0,0" Grid.Column="0"/>
|
||||
<ctrl:UnitTextBox x:Name="PriceInput" Unit="€/kg" TextChanged="PriceInput_TextChanged" IsEnabled="False" LostFocus="PriceInput_LostFocus"
|
||||
Grid.Column="1" Width="90" Margin="0,40,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Gebunden" Grid.Row="1" Margin="0,5,5,5">
|
||||
<GroupBox Header="Gebunden Aufschlag" Grid.Row="1" Margin="0,5,5,5">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="85"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Margin="10,10,0,0">
|
||||
<RadioButton GroupName="GebundenType">Fix</RadioButton>
|
||||
<RadioButton GroupName="GebundenType">Graph</RadioButton>
|
||||
<RadioButton GroupName="GebundenType" IsChecked="True">Nein</RadioButton>
|
||||
<RadioButton x:Name="GebundenTypeFixed" GroupName="GebundenType" Checked="GebundenType_Checked" IsEnabled="False">Fix</RadioButton>
|
||||
<RadioButton x:Name="GebundenTypeGraph" GroupName="GebundenType" Checked="GebundenType_Checked" IsEnabled="False">Frei</RadioButton>
|
||||
<RadioButton x:Name="GebundenTypeNone" GroupName="GebundenType" Checked="GebundenType_Checked" IsEnabled="False">Nein</RadioButton>
|
||||
</StackPanel>
|
||||
|
||||
<TextBox x:Name="GebundenBonus" IsReadOnly="True" Grid.Column="1" HorizontalAlignment="Left" Margin="0,12,0,0" Text="" Width="90" TextChanged="GebundenBonus_TextChanged"/>
|
||||
</Grid>
|
||||
<ctrl:UnitTextBox x:Name="GebundenFlatBonus" Unit="€/kg" TextChanged="GebundenFlatBonus_TextChanged" IsEnabled="False"
|
||||
Width="90" Margin="5,5,5,5" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Aktionen" Grid.Row="2" Margin="0,5,5,5">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button x:Name="LeftFlatButton" Content="Links flach" Click="LeftFlatButton_Click" IsEnabled="False"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,10,10,10"/>
|
||||
|
||||
<Button x:Name="RightFlatButton" Content="Rechts flach" Click="RightFlatButton_Click" IsEnabled="False"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,50,10,10"/>
|
||||
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,45,10,10"/>
|
||||
<Button x:Name="InterpolateButton" Content="Interpolieren" Click="InterpolateButton_Click" IsEnabled="False"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,90,10,10"/>
|
||||
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,80,10,10"/>
|
||||
<Button x:Name="LinearIncreaseButton" Content="Linear wachsen" Click="LinearIncreaseButton_Click" IsEnabled="False"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,130,10,10"/>
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,115,10,10"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
|
@ -1,115 +1,158 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Elwig.Controls;
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Models.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using ScottPlot.Plottables;
|
||||
using ScottPlot;
|
||||
using ScottPlot.Plottable;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
using ScottPlot.Control;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class ChartWindow : ContextWindow {
|
||||
|
||||
public static readonly Color ColorUngebunden = Colors.Blue;
|
||||
public static readonly Color ColorGebunden = Colors.Gold;
|
||||
|
||||
public readonly int Year;
|
||||
public readonly int AvNr;
|
||||
private readonly PaymentVar PaymentVar;
|
||||
public Season Season;
|
||||
private PaymentVar PaymentVar;
|
||||
private bool HasChanged = false;
|
||||
|
||||
private ScatterPlot OechslePricePlotScatter;
|
||||
private MarkerPlot HighlightedPoint;
|
||||
private MarkerPlot PrimaryMarkedPoint;
|
||||
private MarkerPlot SecondaryMarkedPoint;
|
||||
private Tooltip Tooltip;
|
||||
private Scatter DataPlot;
|
||||
private Scatter? GebundenPlot;
|
||||
private Marker HighlightedPointPlot;
|
||||
private Marker PrimaryMarkedPointPlot;
|
||||
private Marker SecondaryMarkedPointPlot;
|
||||
private Text TooltipPlot;
|
||||
private LegendItem UngebundenLegend;
|
||||
private LegendItem GebundenLegend;
|
||||
private LegendItem LDWLegend;
|
||||
private LegendItem QUWLegend;
|
||||
private LegendItem KABLegend;
|
||||
|
||||
private int LastHighlightedIndex = -1;
|
||||
private int HighlightedIndex = -1;
|
||||
private int PrimaryMarkedPointIndex = -1;
|
||||
private int SecondaryMarkedPointIndex = -1;
|
||||
private (Graph? graph, int index) LastHighlighted = (null, -1);
|
||||
private (Graph? graph, int index) Highlighted = (null, -1);
|
||||
private Graph? ActiveGraph = null;
|
||||
private int PrimaryMarkedPoint = -1;
|
||||
private int SecondaryMarkedPoint = -1;
|
||||
private bool HoverChanged = false;
|
||||
private bool HoverActive = false;
|
||||
|
||||
private const int MinOechsle = 50;
|
||||
private const int MaxOechsle = 140;
|
||||
private bool FillingInputs = false;
|
||||
|
||||
private List<GraphEntry> GraphEntries = [];
|
||||
private GraphEntry? SelectedGraphEntry;
|
||||
private GraphEntry? SelectedGraphEntry => (GraphEntry)GraphList.SelectedItem;
|
||||
|
||||
public ChartWindow(int year, int avnr) {
|
||||
InitializeComponent();
|
||||
Year = year;
|
||||
AvNr = avnr;
|
||||
Season = Context.Seasons.Find(year) ?? throw new ArgumentException("Season not found");
|
||||
PaymentVar = Context.PaymentVariants.Find(year, avnr) ?? throw new ArgumentException("PaymentVar not found");
|
||||
Title = $"{PaymentVar?.Name} - Lese {year} - Elwig";
|
||||
LockContext = true;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||
OechslePricePlot.IsEnabled = false;
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
|
||||
if (HasChanged) {
|
||||
var r = MessageBox.Show("Soll das Fenster wirklich geschlossen werden? Nicht gespeicherte Änderungen werden NICHT übernommen!", "Schließen bestätigen",
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (r != MessageBoxResult.Yes) {
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetHasChanged(bool hasChanged = true) {
|
||||
HasChanged = hasChanged;
|
||||
SaveButton.IsEnabled = hasChanged;
|
||||
}
|
||||
|
||||
private async Task RefreshGraphList() {
|
||||
await Context.PaymentVariants.LoadAsync();
|
||||
await RefreshGraphListQuery();
|
||||
}
|
||||
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");
|
||||
|
||||
private async Task RefreshGraphListQuery() {
|
||||
var attrVariants = Context.DeliveryParts
|
||||
.Where(d => d.Year == Year)
|
||||
.Select(d => $"{d.SortId}{d.AttrId}")
|
||||
.Distinct()
|
||||
.ToList()
|
||||
.Union(Context.WineVarieties.Select(v => v.SortId))
|
||||
.Order()
|
||||
.ToList();
|
||||
var data = EditBillingData.FromJson(PaymentVar.Data, attrVariants);
|
||||
GraphEntries.AddRange(data.GetPaymentGraphEntries());
|
||||
GraphEntries.AddRange(data.GetQualityGraphEntries());
|
||||
var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetAttributeVarieties(Context, Year));
|
||||
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
||||
GraphEntries = [
|
||||
..paymentEntries,
|
||||
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Max(e => e.Id))
|
||||
];
|
||||
|
||||
ControlUtils.RenewItemsSource(AppliedInput, attrVariants, g => g);
|
||||
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, null, ControlUtils.RenewSourceDefault.IfOnly);
|
||||
var contracts = Utils.GetContractsForYear(Context, Year);
|
||||
FillingInputs = true;
|
||||
ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.Listing);
|
||||
FillingInputs = false;
|
||||
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.ContractsStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
||||
|
||||
RefreshInputs();
|
||||
}
|
||||
|
||||
private string ParseContracts(JsonObject auszahlungsSorten, int num) {
|
||||
return "";
|
||||
}
|
||||
|
||||
private void RefreshInputs(bool validate = false) {
|
||||
private void RefreshInputs() {
|
||||
ResetPlot();
|
||||
if (!PaymentVar.TestVariant) {
|
||||
AddButton.IsEnabled = false;
|
||||
CopyButton.IsEnabled = false;
|
||||
DeleteButton.IsEnabled = false;
|
||||
OechsleInput.IsReadOnly = true;
|
||||
PriceInput.IsReadOnly = true;
|
||||
} else if (SelectedGraphEntry != null) {
|
||||
if (SelectedGraphEntry != null) {
|
||||
CopyButton.IsEnabled = true;
|
||||
DeleteButton.IsEnabled = true;
|
||||
OechsleInput.IsReadOnly = false;
|
||||
GebundenTypeFixed.IsEnabled = true;
|
||||
GebundenTypeGraph.IsEnabled = true;
|
||||
GebundenTypeNone.IsEnabled = true;
|
||||
ContractInput.IsEnabled = true;
|
||||
AbgewertetInput.IsEnabled = true;
|
||||
EnableOptionButtons();
|
||||
FillInputs();
|
||||
} else {
|
||||
CopyButton.IsEnabled = false;
|
||||
DeleteButton.IsEnabled = false;
|
||||
OechsleInput.IsReadOnly = true;
|
||||
DisableUnitTextBox(OechsleInput);
|
||||
DisableOptionButtons();
|
||||
}
|
||||
if (!PaymentVar.TestVariant) {
|
||||
AddButton.IsEnabled = false;
|
||||
CopyButton.IsEnabled = false;
|
||||
DeleteButton.IsEnabled = false;
|
||||
DisableUnitTextBox(OechsleInput);
|
||||
DisableUnitTextBox(PriceInput);
|
||||
GebundenTypeFixed.IsEnabled = false;
|
||||
GebundenTypeGraph.IsEnabled = false;
|
||||
GebundenTypeNone.IsEnabled = false;
|
||||
ContractInput.IsEnabled = false;
|
||||
AbgewertetInput.IsEnabled = false;
|
||||
}
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void FillInputs() {
|
||||
GraphNum.Text = SelectedGraphEntry.Id.ToString();
|
||||
FillingInputs = true;
|
||||
|
||||
AbgewertetInput.IsChecked = SelectedGraphEntry?.Abgewertet;
|
||||
if (SelectedGraphEntry?.GebundenFlatBonus is double bonus) {
|
||||
GebundenTypeFixed.IsChecked = true;
|
||||
GebundenFlatBonus.Text = $"{bonus}";
|
||||
} else if (SelectedGraphEntry?.GebundenGraph != null) {
|
||||
GebundenTypeGraph.IsChecked = true;
|
||||
GebundenFlatBonus.Text = "";
|
||||
} else {
|
||||
GebundenTypeNone.IsChecked = true;
|
||||
GebundenFlatBonus.Text = "";
|
||||
}
|
||||
|
||||
ControlUtils.SelectCheckComboBoxItems(ContractInput, SelectedGraphEntry?.Contracts ?? [], i => (i as ContractSelection)?.Listing);
|
||||
|
||||
InitPlot();
|
||||
OechslePricePlot.IsEnabled = true;
|
||||
FillingInputs = false;
|
||||
}
|
||||
|
||||
protected override async Task OnRenewContext() {
|
||||
@ -117,74 +160,126 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void InitPlot() {
|
||||
OechslePricePlotScatter = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry.DataGraph.DataX, SelectedGraphEntry.DataGraph.DataY);
|
||||
UngebundenLegend = new LegendItem() {
|
||||
Label = "Ungebunden",
|
||||
LineWidth = 1,
|
||||
LineColor = ColorUngebunden,
|
||||
Marker = new MarkerStyle(MarkerShape.FilledCircle, 5, ColorUngebunden)
|
||||
};
|
||||
|
||||
OechslePricePlot.Configuration.DoubleClickBenchmark = false;
|
||||
OechslePricePlotScatter.LineColor = Color.Blue;
|
||||
OechslePricePlotScatter.MarkerColor = Color.Blue;
|
||||
OechslePricePlotScatter.MarkerSize = 9;
|
||||
GebundenLegend = new LegendItem() {
|
||||
Label = "Gebunden",
|
||||
LineWidth = 1,
|
||||
LineColor = ColorGebunden,
|
||||
Marker = new MarkerStyle(MarkerShape.FilledCircle, 5, ColorGebunden)
|
||||
};
|
||||
|
||||
LDWLegend = new LegendItem() {
|
||||
Label = "68 °Oe (LDW)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Red,
|
||||
Marker = MarkerStyle.None
|
||||
};
|
||||
|
||||
QUWLegend = new LegendItem() {
|
||||
Label = "73 °Oe (QUW)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Orange,
|
||||
Marker = MarkerStyle.None
|
||||
};
|
||||
|
||||
KABLegend = new LegendItem() {
|
||||
Label = "84 °Oe (KAB)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Green,
|
||||
Marker = MarkerStyle.None
|
||||
};
|
||||
|
||||
RefreshGradationLines();
|
||||
|
||||
if (SelectedGraphEntry?.GebundenGraph != null) {
|
||||
GebundenPlot = OechslePricePlot.Plot.Add.Scatter(SelectedGraphEntry.GebundenGraph.DataX, SelectedGraphEntry.GebundenGraph.DataY);
|
||||
GebundenPlot.LineStyle.Color = ColorGebunden;
|
||||
GebundenPlot.Color = ColorGebunden;
|
||||
GebundenPlot.MarkerStyle = new MarkerStyle(MarkerShape.FilledCircle, 9, ColorGebunden);
|
||||
}
|
||||
|
||||
DataPlot = OechslePricePlot.Plot.Add.Scatter(SelectedGraphEntry!.DataGraph.DataX, SelectedGraphEntry!.DataGraph.DataY);
|
||||
DataPlot.LineStyle.Color = ColorUngebunden;
|
||||
DataPlot.Color = ColorUngebunden;
|
||||
DataPlot.MarkerStyle = new MarkerStyle(MarkerShape.FilledCircle, 9, ColorUngebunden);
|
||||
|
||||
if (SelectedGraphEntry?.GebundenGraph == null) {
|
||||
ChangeActiveGraph(SelectedGraphEntry?.DataGraph);
|
||||
}
|
||||
|
||||
OechslePricePlot.Interaction.Enable(new PlotActions() {
|
||||
ZoomIn = StandardActions.ZoomIn,
|
||||
ZoomOut = StandardActions.ZoomOut,
|
||||
PanUp = StandardActions.PanUp,
|
||||
PanDown = StandardActions.PanDown,
|
||||
PanLeft = StandardActions.PanLeft,
|
||||
PanRight = StandardActions.PanRight,
|
||||
DragPan = StandardActions.DragPan,
|
||||
DragZoom = StandardActions.DragZoom,
|
||||
DragZoomRectangle = StandardActions.DragZoomRectangle,
|
||||
ZoomRectangleClear = StandardActions.ZoomRectangleClear,
|
||||
ZoomRectangleApply = StandardActions.ZoomRectangleApply,
|
||||
AutoScale = StandardActions.AutoScale,
|
||||
});
|
||||
|
||||
//OechslePricePlot.Plot.XAxis.ManualTickSpacing(1);
|
||||
OechslePricePlot.Plot.YAxis.ManualTickSpacing(0.1);
|
||||
OechslePricePlot.Plot.SetAxisLimits(MinOechsle - 1, MaxOechsle + 1, -0.1, 2);
|
||||
|
||||
OechslePricePlot.Plot.Layout(padding: 0);
|
||||
OechslePricePlot.Plot.XAxis2.Layout(padding: 0);
|
||||
OechslePricePlot.Plot.YAxis.Layout(padding: 0);
|
||||
OechslePricePlot.Plot.YAxis2.Layout(padding: 0);
|
||||
//OechslePricePlot.Plot.YAxis.ManualTickSpacing(0.1);
|
||||
OechslePricePlot.Plot.Axes.SetLimits(Math.Min(GraphEntry.MinX, GraphEntry.MinXGeb) - 1, GraphEntry.MaxX + 1, -0.1, 2);
|
||||
|
||||
HighlightedPoint = OechslePricePlot.Plot.AddPoint(0, 0);
|
||||
HighlightedPoint.Color = Color.Red;
|
||||
HighlightedPoint.MarkerSize = 10;
|
||||
HighlightedPoint.MarkerShape = MarkerShape.openCircle;
|
||||
HighlightedPoint.IsVisible = false;
|
||||
//OechslePricePlot.Plot.Layout(padding: 0);
|
||||
//OechslePricePlot.Plot.XAxis2.Layout(padding: 0);
|
||||
//OechslePricePlot.Plot.YAxis.Layout(padding: 0);
|
||||
//OechslePricePlot.Plot.YAxis2.Layout(padding: 0);
|
||||
|
||||
HighlightedPointPlot = OechslePricePlot.Plot.Add.Marker(0, 0, MarkerShape.OpenCircle, 10, Colors.Red);
|
||||
HighlightedPointPlot.IsVisible = false;
|
||||
|
||||
PrimaryMarkedPointPlot = OechslePricePlot.Plot.Add.Marker(0, 0, MarkerShape.FilledCircle, 6, Colors.Red);
|
||||
PrimaryMarkedPointPlot.IsVisible = false;
|
||||
|
||||
SecondaryMarkedPointPlot = OechslePricePlot.Plot.Add.Marker(0, 0, MarkerShape.FilledCircle, 6, Colors.Red);
|
||||
SecondaryMarkedPointPlot.IsVisible = false;
|
||||
|
||||
PrimaryMarkedPoint = OechslePricePlot.Plot.AddPoint(0, 0);
|
||||
PrimaryMarkedPoint.Color = Color.Red;
|
||||
PrimaryMarkedPoint.MarkerSize = 6;
|
||||
PrimaryMarkedPoint.MarkerShape = MarkerShape.filledCircle;
|
||||
PrimaryMarkedPoint.IsVisible = false;
|
||||
|
||||
SecondaryMarkedPoint = OechslePricePlot.Plot.AddPoint(0, 0);
|
||||
SecondaryMarkedPoint.Color = Color.Red;
|
||||
SecondaryMarkedPoint.MarkerSize = 6;
|
||||
SecondaryMarkedPoint.MarkerShape = MarkerShape.filledCircle;
|
||||
SecondaryMarkedPoint.IsVisible = false;
|
||||
|
||||
OechslePricePlot.Refresh();
|
||||
|
||||
RefreshFreeZoom();
|
||||
RefreshGradationLines();
|
||||
OechslePricePlot.Refresh();
|
||||
}
|
||||
|
||||
private void ResetPlot() {
|
||||
PrimaryMarkedPointIndex = -1;
|
||||
OechslePricePlot.Plot.Remove(OechslePricePlotScatter);
|
||||
PrimaryMarkedPoint = -1;
|
||||
SecondaryMarkedPoint = -1;
|
||||
ChangeActiveGraph(null);
|
||||
HideGradationLines();
|
||||
OechslePricePlot.Plot.Remove(DataPlot);
|
||||
if (GebundenPlot != null) {
|
||||
OechslePricePlot.Plot.Remove(GebundenPlot);
|
||||
GebundenPlot = null;
|
||||
}
|
||||
OechslePricePlot.Plot.Clear();
|
||||
OechslePricePlot.Reset();
|
||||
OechslePricePlot.Refresh();
|
||||
}
|
||||
|
||||
private void ChangeMarker(MarkerPlot point, bool visible, double x = 0, double y = 0) {
|
||||
point.X = x;
|
||||
point.Y = y;
|
||||
private void ChangeMarker(Marker point, bool visible, double x = 0, double y = 0) {
|
||||
point.Location = new Coordinates(x, y);
|
||||
point.IsVisible = visible;
|
||||
}
|
||||
|
||||
private void FlattenGraph(int begin, int end, double value) {
|
||||
SelectedGraphEntry.DataGraph.FlattenGraph(begin, end, value);
|
||||
OechslePricePlot.Render();
|
||||
}
|
||||
|
||||
private void LinearIncreaseGraph(int begin, int end, double inc) {
|
||||
SelectedGraphEntry.DataGraph.LinearIncreaseGraph(begin, end, inc);
|
||||
OechslePricePlot.Render();
|
||||
}
|
||||
|
||||
private void EnableActionButtons() {
|
||||
LeftFlatButton.IsEnabled = true;
|
||||
RightFlatButton.IsEnabled = true;
|
||||
LinearIncreaseButton.IsEnabled = true;
|
||||
if (PaymentVar.TestVariant) {
|
||||
LeftFlatButton.IsEnabled = true;
|
||||
RightFlatButton.IsEnabled = true;
|
||||
LinearIncreaseButton.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void DisableActionButtons() {
|
||||
@ -208,18 +303,32 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void LockZoom() {
|
||||
OechslePricePlot.Plot.XAxis.SetBoundary(MinOechsle - 1, MaxOechsle + 1);
|
||||
OechslePricePlot.Plot.YAxis.SetBoundary(-0.1, 2);
|
||||
OechslePricePlot.Plot.XAxis.SetZoomOutLimit(MaxOechsle - MinOechsle + 2);
|
||||
OechslePricePlot.Plot.YAxis.SetZoomOutLimit(2.1);
|
||||
OechslePricePlot.Plot.SetAxisLimits(MinOechsle - 1, MaxOechsle + 1, -0.1, 2);
|
||||
ScottPlot.AxisRules.MaximumBoundary BoundaryRule = new(
|
||||
xAxis: OechslePricePlot.Plot.Axes.Bottom,
|
||||
yAxis: OechslePricePlot.Plot.Axes.Left,
|
||||
limits: new AxisLimits(GraphEntry.MinX - 1, GraphEntry.MaxX + 1, -0.1, 2));
|
||||
|
||||
ScottPlot.AxisRules.MaximumSpan SpanRule = new(
|
||||
xAxis: OechslePricePlot.Plot.Axes.Bottom,
|
||||
yAxis: OechslePricePlot.Plot.Axes.Left,
|
||||
xSpan: GraphEntry.MaxX - GraphEntry.MinX + 2,
|
||||
ySpan: 2.1);
|
||||
|
||||
OechslePricePlot.Plot.Axes.Rules.Clear();
|
||||
OechslePricePlot.Plot.Axes.Rules.Add(BoundaryRule);
|
||||
OechslePricePlot.Plot.Axes.Rules.Add(SpanRule);
|
||||
OechslePricePlot.Plot.Axes.SetLimits(GraphEntry.MinX - 1, GraphEntry.MaxX + 1, -0.1, 2);
|
||||
}
|
||||
|
||||
private void UnlockZoom() {
|
||||
OechslePricePlot.Plot.XAxis.SetBoundary();
|
||||
OechslePricePlot.Plot.YAxis.SetBoundary();
|
||||
OechslePricePlot.Plot.XAxis.SetZoomOutLimit((MaxOechsle - MinOechsle) * 1.5);
|
||||
OechslePricePlot.Plot.YAxis.SetZoomOutLimit(3.5);
|
||||
ScottPlot.AxisRules.MaximumSpan SpanRule = new(
|
||||
xAxis: OechslePricePlot.Plot.Axes.Bottom,
|
||||
yAxis: OechslePricePlot.Plot.Axes.Left,
|
||||
xSpan: (GraphEntry.MaxX - GraphEntry.MinX) * 1.5,
|
||||
ySpan: 3.5);
|
||||
|
||||
OechslePricePlot.Plot.Axes.Rules.Clear();
|
||||
OechslePricePlot.Plot.Axes.Rules.Add(SpanRule);
|
||||
}
|
||||
|
||||
private void EnableOptionButtons() {
|
||||
@ -239,10 +348,10 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void RefreshGradationLines() {
|
||||
if (GradationLinesInput.IsChecked == true) {
|
||||
if (GradationLinesInput.IsChecked == true && SelectedGraphEntry != null && !OechslePricePlot.Plot.PlottableList.OfType<VerticalLine>().Any()) {
|
||||
ShowGradationLines();
|
||||
ShowLegend();
|
||||
} else {
|
||||
} else if (GradationLinesInput.IsChecked == false) {
|
||||
HideGradationLines();
|
||||
HideLegend();
|
||||
}
|
||||
@ -250,100 +359,119 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void ShowGradationLines() {
|
||||
OechslePricePlot.Plot.AddVerticalLine(68, Color.Red, 2, label: "68 Oechsle (LDW)");
|
||||
OechslePricePlot.Plot.AddVerticalLine(73, Color.Orange, 2, label: "73 Oechsle (QUW)");
|
||||
OechslePricePlot.Plot.AddVerticalLine(84, Color.Green, 2, label: "84 Oechsle (KAB)");
|
||||
OechslePricePlot.Plot.Add.VerticalLine(68, 2, Colors.Red);
|
||||
OechslePricePlot.Plot.Add.VerticalLine(73, 2, Colors.Orange);
|
||||
OechslePricePlot.Plot.Add.VerticalLine(84, 2, Colors.Green);
|
||||
}
|
||||
|
||||
private void HideGradationLines() {
|
||||
OechslePricePlot.Plot.Clear(typeof(VLine));
|
||||
OechslePricePlot.Plot.PlottableList.RemoveAll(p => p is VerticalLine);
|
||||
}
|
||||
|
||||
private void ShowLegend() {
|
||||
OechslePricePlot.Plot.Legend(true, Alignment.UpperRight);
|
||||
OechslePricePlot.Plot.Legend.Location = Alignment.UpperLeft;
|
||||
OechslePricePlot.Plot.Legend.IsVisible = true;
|
||||
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(LDWLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(QUWLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(KABLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(UngebundenLegend);
|
||||
if (SelectedGraphEntry?.GebundenGraph != null) OechslePricePlot.Plot.Legend.ManualItems.Add(GebundenLegend);
|
||||
}
|
||||
|
||||
private void HideLegend() {
|
||||
OechslePricePlot.Plot.Legend(false, Alignment.UpperRight);
|
||||
OechslePricePlot.Plot.Legend.IsVisible = false;
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Clear();
|
||||
}
|
||||
|
||||
private void OechsleInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (ActiveGraph == null || SelectedGraphEntry == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool success = int.TryParse(OechsleInput.Text, out int oechsle);
|
||||
|
||||
SecondaryMarkedPointIndex = -1;
|
||||
ChangeMarker(SecondaryMarkedPoint, false);
|
||||
SecondaryMarkedPoint = -1;
|
||||
ChangeMarker(SecondaryMarkedPointPlot, false);
|
||||
|
||||
if (success) {
|
||||
if (oechsle >= MinOechsle && oechsle <= MaxOechsle) {
|
||||
PrimaryMarkedPointIndex = oechsle - MinOechsle;
|
||||
ChangeMarker(PrimaryMarkedPoint, true, SelectedGraphEntry.DataGraph.DataX[PrimaryMarkedPointIndex], SelectedGraphEntry.DataGraph.DataY[PrimaryMarkedPointIndex]);
|
||||
if (success) {
|
||||
if (oechsle >= ActiveGraph.MinX && oechsle <= ActiveGraph.MaxX) {
|
||||
PrimaryMarkedPoint = oechsle - ActiveGraph.MinX;
|
||||
ChangeMarker(PrimaryMarkedPointPlot, true, ActiveGraph.GetOechsleAt(PrimaryMarkedPoint), ActiveGraph.GetPriceAt(PrimaryMarkedPoint));
|
||||
|
||||
PriceInput.Text = SelectedGraphEntry.DataGraph.DataY[PrimaryMarkedPointIndex].ToString();
|
||||
PriceInput.Text = Math.Round(ActiveGraph.GetPriceAt(PrimaryMarkedPoint), Season.Precision).ToString();
|
||||
|
||||
EnableActionButtons();
|
||||
OechslePricePlot.Render();
|
||||
PriceInput.IsReadOnly = false;
|
||||
OechslePricePlot.Refresh();
|
||||
EnableUnitTextBox(PriceInput);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PrimaryMarkedPointIndex = -1;
|
||||
ChangeMarker(PrimaryMarkedPoint, false);
|
||||
PrimaryMarkedPoint = -1;
|
||||
ChangeMarker(PrimaryMarkedPointPlot, false);
|
||||
DisableActionButtons();
|
||||
PriceInput.Text = "";
|
||||
OechslePricePlot.Render();
|
||||
PriceInput.IsReadOnly = true;
|
||||
DisableUnitTextBox(PriceInput);
|
||||
OechslePricePlot.Refresh();
|
||||
DisableUnitTextBox(PriceInput);
|
||||
}
|
||||
|
||||
private void PriceInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
if (PrimaryMarkedPointIndex != -1) {
|
||||
bool success = Double.TryParse(PriceInput.Text, out double price);
|
||||
|
||||
if (success) {
|
||||
SelectedGraphEntry.DataGraph.DataY[PrimaryMarkedPointIndex] = price;
|
||||
PrimaryMarkedPoint.Y = price;
|
||||
private void PriceInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (PrimaryMarkedPoint != -1 && ActiveGraph != null && PriceInput.IsKeyboardFocusWithin == true) {
|
||||
var res = Validator.CheckDecimal(PriceInput.TextBox, true, 2, Season.Precision);
|
||||
if (res.IsValid && double.TryParse(PriceInput.Text, out double price)) {
|
||||
ActiveGraph.SetPriceAt(PrimaryMarkedPoint, price);
|
||||
PrimaryMarkedPointPlot.Location = new Coordinates(PrimaryMarkedPointPlot.Location.X, price);
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LeftFlatButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PrimaryMarkedPointIndex == -1) {
|
||||
if (PrimaryMarkedPoint == -1 || ActiveGraph == null) {
|
||||
return;
|
||||
}
|
||||
FlattenGraph(0, PrimaryMarkedPointIndex, SelectedGraphEntry.DataGraph.DataY[PrimaryMarkedPointIndex]);
|
||||
ActiveGraph.FlattenGraphLeft(PrimaryMarkedPoint);
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
|
||||
private void RightFlatButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PrimaryMarkedPointIndex == -1) {
|
||||
if (PrimaryMarkedPoint == -1 || ActiveGraph == null) {
|
||||
return;
|
||||
}
|
||||
FlattenGraph(PrimaryMarkedPointIndex, SelectedGraphEntry.DataGraph.DataY.Length - 1, SelectedGraphEntry.DataGraph.DataY[PrimaryMarkedPointIndex]);
|
||||
ActiveGraph.FlattenGraphRight(PrimaryMarkedPoint);
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
|
||||
private void InterpolateButton_Click(object sender, RoutedEventArgs evt) {
|
||||
int steps = Math.Abs(PrimaryMarkedPointIndex - SecondaryMarkedPointIndex);
|
||||
if (PrimaryMarkedPointIndex == -1 || SecondaryMarkedPointIndex == -1 || steps < 2) {
|
||||
if (PrimaryMarkedPoint == SecondaryMarkedPoint || PrimaryMarkedPoint == -1 || SecondaryMarkedPoint == -1 || ActiveGraph == null) {
|
||||
return;
|
||||
}
|
||||
var (lowIndex, highIndex) = PrimaryMarkedPointIndex < SecondaryMarkedPointIndex ? (PrimaryMarkedPointIndex, SecondaryMarkedPointIndex): (SecondaryMarkedPointIndex, PrimaryMarkedPointIndex);
|
||||
|
||||
double step = (SelectedGraphEntry.DataGraph.DataY[highIndex] - SelectedGraphEntry.DataGraph.DataY[lowIndex]) / steps;
|
||||
|
||||
for (int i = lowIndex; i < highIndex - 1; i++) {
|
||||
SelectedGraphEntry.DataGraph.DataY[i + 1] = Math.Round(SelectedGraphEntry.DataGraph.DataY[i] + step, 4); // TODO richtig runden
|
||||
}
|
||||
ActiveGraph.InterpolateGraph(PrimaryMarkedPoint, SecondaryMarkedPoint);
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
|
||||
private void LinearIncreaseButton_Click(object sender, RoutedEventArgs e) {
|
||||
if (PrimaryMarkedPointIndex == -1) {
|
||||
if (PrimaryMarkedPoint == -1 || ActiveGraph == null) {
|
||||
return;
|
||||
}
|
||||
double? priceIncrease = Utils.ShowLinearPriceIncreaseDialog();
|
||||
if (priceIncrease == null) {
|
||||
return;
|
||||
}
|
||||
LinearIncreaseGraph(PrimaryMarkedPointIndex, SelectedGraphEntry.DataGraph.DataY.Length - 1, priceIncrease.Value);
|
||||
ActiveGraph.LinearIncreaseGraphToEnd(PrimaryMarkedPoint, priceIncrease.Value);
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
|
||||
private void OechslePricePlot_MouseDown(object sender, MouseEventArgs e) {
|
||||
@ -352,85 +480,130 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
if (HoverActive) {
|
||||
if (PaymentVar.TestVariant && Keyboard.IsKeyDown(Key.LeftCtrl)) {
|
||||
if (PrimaryMarkedPointIndex == -1) {
|
||||
if (PaymentVar.TestVariant && Keyboard.IsKeyDown(System.Windows.Input.Key.LeftCtrl)) {
|
||||
if (PrimaryMarkedPoint == -1 || ActiveGraph == null || ActiveGraph != Highlighted.graph) {
|
||||
return;
|
||||
}
|
||||
SecondaryMarkedPointIndex = HighlightedIndex;
|
||||
ChangeMarker(SecondaryMarkedPoint, true, SelectedGraphEntry.DataGraph.DataX[SecondaryMarkedPointIndex], SelectedGraphEntry.DataGraph.DataY[SecondaryMarkedPointIndex]);
|
||||
SecondaryMarkedPoint = Highlighted.index;
|
||||
|
||||
ChangeMarker(SecondaryMarkedPointPlot, true, ActiveGraph.GetOechsleAt(SecondaryMarkedPoint), ActiveGraph.GetPriceAt(SecondaryMarkedPoint));
|
||||
|
||||
InterpolateButton.IsEnabled = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PrimaryMarkedPointIndex = HighlightedIndex;
|
||||
ChangeMarker(PrimaryMarkedPoint, true, SelectedGraphEntry.DataGraph.DataX[PrimaryMarkedPointIndex], SelectedGraphEntry.DataGraph.DataY[PrimaryMarkedPointIndex]);
|
||||
PrimaryMarkedPoint = Highlighted.index;
|
||||
if (ActiveGraph != Highlighted.graph) ChangeActiveGraph(Highlighted.graph);
|
||||
|
||||
OechsleInput.Text = SelectedGraphEntry.DataGraph.DataX[HighlightedIndex].ToString();
|
||||
PriceInput.Text = SelectedGraphEntry.DataGraph.DataY[HighlightedIndex].ToString();
|
||||
ChangeMarker(PrimaryMarkedPointPlot, true, ActiveGraph.GetOechsleAt(PrimaryMarkedPoint), ActiveGraph.GetPriceAt(PrimaryMarkedPoint));
|
||||
|
||||
if (PaymentVar.TestVariant) {
|
||||
EnableActionButtons();
|
||||
}
|
||||
OechsleInput.Text = Highlighted.graph.GetOechsleAt(Highlighted.index).ToString();
|
||||
PriceInput.Text = Highlighted.graph.GetPriceAt(Highlighted.index).ToString();
|
||||
|
||||
EnableActionButtons();
|
||||
} else {
|
||||
PrimaryMarkedPointIndex = -1;
|
||||
SecondaryMarkedPointIndex = -1;
|
||||
ChangeMarker(PrimaryMarkedPoint, false);
|
||||
ChangeMarker(SecondaryMarkedPoint, false);
|
||||
PrimaryMarkedPoint = -1;
|
||||
SecondaryMarkedPoint = -1;
|
||||
if (SelectedGraphEntry!.GebundenGraph != null) {
|
||||
ChangeActiveGraph(null);
|
||||
}
|
||||
ChangeMarker(PrimaryMarkedPointPlot, false);
|
||||
ChangeMarker(SecondaryMarkedPointPlot, false);
|
||||
|
||||
OechsleInput.Text = "";
|
||||
PriceInput.Text = "";
|
||||
DisableUnitTextBox(PriceInput);
|
||||
|
||||
DisableActionButtons();
|
||||
}
|
||||
}
|
||||
|
||||
private void OechslePricePlot_MouseMove(object sender, MouseEventArgs e) {
|
||||
MouseChange(e);
|
||||
}
|
||||
|
||||
private void OechslePricePlot_MouseWheel(object sender, MouseWheelEventArgs e) {
|
||||
MouseChange(e);
|
||||
}
|
||||
|
||||
private void MouseChange(MouseEventArgs e) {
|
||||
if (GraphList.SelectedItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
(double mouseCoordX, double mouseCoordY) = OechslePricePlot.GetMouseCoordinates();
|
||||
double xyRatio = OechslePricePlot.Plot.XAxis.Dims.PxPerUnit / OechslePricePlot.Plot.YAxis.Dims.PxPerUnit;
|
||||
(double pointX, double pointY, int pointIndex) = OechslePricePlotScatter.GetPointNearest(mouseCoordX, mouseCoordY, xyRatio);
|
||||
(double x, double y, int index)? mouseOnData = MouseOnPlot(DataPlot, e.GetPosition(OechslePricePlot));
|
||||
(double x, double y, int index)? mouseOnGebunden = MouseOnPlot(GebundenPlot, e.GetPosition(OechslePricePlot));
|
||||
|
||||
(double mousePixelX, double mousePixelY) = OechslePricePlot.GetMousePixel();
|
||||
(double pointPixelX, double pointPixelY) = OechslePricePlot.Plot.GetPixel(pointX, pointY);
|
||||
Highlighted = LastHighlighted;
|
||||
|
||||
HighlightedIndex = LastHighlightedIndex;
|
||||
|
||||
if (Math.Abs(mousePixelX - pointPixelX) < 3 && Math.Abs(mousePixelY - pointPixelY) < 3) {
|
||||
ChangeMarker(HighlightedPoint, true, pointX, pointY);
|
||||
HighlightedPoint.IsVisible = true;
|
||||
if (mouseOnData != null) {
|
||||
ChangeMarker(HighlightedPointPlot, true, mouseOnData.Value.x, mouseOnData.Value.y);
|
||||
HighlightedPointPlot.IsVisible = true;
|
||||
HoverChanged = true ^ HoverActive;
|
||||
HoverActive = true;
|
||||
HandleTooltip(mouseOnData.Value.x, mouseOnData.Value.y, mouseOnData.Value.index, SelectedGraphEntry!.DataGraph, e.GetPosition(OechslePricePlot), e is MouseWheelEventArgs);
|
||||
} else if (mouseOnGebunden != null) {
|
||||
ChangeMarker(HighlightedPointPlot, true, mouseOnGebunden.Value.x, mouseOnGebunden.Value.y);
|
||||
HighlightedPointPlot.IsVisible = true;
|
||||
HoverChanged = true ^ HoverActive;
|
||||
HoverActive = true;
|
||||
HandleTooltip(mouseOnGebunden.Value.x, mouseOnGebunden.Value.y, mouseOnGebunden.Value.index, SelectedGraphEntry!.GebundenGraph!, e.GetPosition(OechslePricePlot), e is MouseWheelEventArgs);
|
||||
} else {
|
||||
ChangeMarker(HighlightedPoint, false);
|
||||
HoverChanged= false ^ HoverActive;
|
||||
HoverActive= false;
|
||||
OechslePricePlot.Plot.Remove(Tooltip);
|
||||
OechslePricePlot.Render();
|
||||
}
|
||||
|
||||
if (LastHighlightedIndex != HighlightedIndex || HoverChanged) {
|
||||
OechslePricePlot.Plot.Remove(Tooltip);
|
||||
if (TooltipInput.IsChecked == true) {
|
||||
Tooltip = OechslePricePlot.Plot.AddTooltip($"Oechsle: {pointX:N2}, Preis: {Math.Round(pointY, 4)})", pointX, pointY);
|
||||
}
|
||||
LastHighlightedIndex = pointIndex;
|
||||
HoverChanged = false;
|
||||
OechslePricePlot.Render();
|
||||
ChangeMarker(HighlightedPointPlot, false);
|
||||
HoverChanged = false ^ HoverActive;
|
||||
HoverActive = false;
|
||||
OechslePricePlot.Plot.PlottableList.Remove(TooltipPlot);
|
||||
OechslePricePlot.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private int getMaxGraphId() {
|
||||
private (double, double, int)? MouseOnPlot(Scatter? plot, Point p) {
|
||||
if (plot == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OechslePricePlot.Refresh();
|
||||
Pixel mousePixel = new(p.X, p.Y);
|
||||
Coordinates mouseLocation = OechslePricePlot.Plot.GetCoordinates(mousePixel);
|
||||
DataPoint nearestPoint = plot.Data.GetNearest(mouseLocation, OechslePricePlot.Plot.LastRender, 3);
|
||||
|
||||
if (nearestPoint.IsReal) {
|
||||
return (nearestPoint.X, nearestPoint.Y, nearestPoint.Index);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleTooltip(double pointX, double pointY, int pointIndex, Graph g, Point p, bool force) {
|
||||
if (force || LastHighlighted != Highlighted || HoverChanged) {
|
||||
OechslePricePlot.Plot.PlottableList.Remove(TooltipPlot);
|
||||
if (TooltipInput.IsChecked == true) {
|
||||
Pixel mousePixel = new(p.X, p.Y - 30);
|
||||
Coordinates mouseLocation = OechslePricePlot.Plot.GetCoordinates(mousePixel);
|
||||
TooltipPlot = OechslePricePlot.Plot.Add.Text($"Oechsle: {pointX:N2}, Preis: {Math.Round(pointY, Season.Precision)}€/kg", mouseLocation.X, mouseLocation.Y);
|
||||
TooltipPlot.Label.FontSize = 12;
|
||||
TooltipPlot.Label.Bold = true;
|
||||
TooltipPlot.Label.BorderColor = Colors.Black;
|
||||
TooltipPlot.Label.BorderWidth = 2;
|
||||
TooltipPlot.Label.BackColor = Colors.White;
|
||||
TooltipPlot.Label.Padding = 10;
|
||||
TooltipPlot.Label.Alignment = Alignment.MiddleLeft;
|
||||
}
|
||||
LastHighlighted = (g, pointIndex);
|
||||
HoverChanged = false;
|
||||
OechslePricePlot.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private int GetMaxGraphId() {
|
||||
return GraphEntries.Count == 0 ? 0 : GraphEntries.Select(g => g.Id).Max();
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, RoutedEventArgs e) {
|
||||
GraphEntry newGraphEntry = new(getMaxGraphId() + 1, BillingData.CurveMode.Oe, MinOechsle, MaxOechsle);
|
||||
GraphEntry newGraphEntry = new(GetMaxGraphId() + 1, Season.Precision, BillingData.CurveMode.Oe);
|
||||
GraphEntries.Add(newGraphEntry);
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
GraphList.SelectedItem = newGraphEntry;
|
||||
}
|
||||
@ -438,8 +611,9 @@ namespace Elwig.Windows {
|
||||
private void CopyButton_Click(object sender, RoutedEventArgs e) {
|
||||
if (SelectedGraphEntry == null) return;
|
||||
|
||||
GraphEntry newGraphEntry = SelectedGraphEntry.Copy(getMaxGraphId() + 1);
|
||||
GraphEntry newGraphEntry = SelectedGraphEntry.Copy(GetMaxGraphId() + 1);
|
||||
GraphEntries.Add(newGraphEntry);
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
GraphList.SelectedItem = newGraphEntry;
|
||||
}
|
||||
@ -448,25 +622,79 @@ namespace Elwig.Windows {
|
||||
if (SelectedGraphEntry == null) return;
|
||||
|
||||
var r = MessageBox.Show(
|
||||
$"Soll der Graph {SelectedGraphEntry.Id} (verwendet in folgenden Verträgen: {SelectedGraphEntry.Contracts}) wirklich gelöscht werden?",
|
||||
$"Soll der Graph {SelectedGraphEntry.Id} (verwendet in folgenden Verträgen: {SelectedGraphEntry.ContractsStringSimple}) wirklich gelöscht werden?",
|
||||
"Graph löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
|
||||
if (r == MessageBoxResult.Yes) {
|
||||
GraphEntries.Remove(SelectedGraphEntry);
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
OechslePricePlot.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e) {
|
||||
//TODO SAVE
|
||||
private async void SaveButton_Click(object sender, RoutedEventArgs e) {
|
||||
var origData = BillingData.FromJson(PaymentVar.Data);
|
||||
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetAttributeVarieties(Context, Year, withSlash: true));
|
||||
|
||||
EntityEntry<PaymentVar>? tr = null;
|
||||
try {
|
||||
PaymentVar.Data = data.ToJsonString();
|
||||
tr = Context.Update(PaymentVar);
|
||||
await Context.SaveChangesAsync();
|
||||
LockContext = false;
|
||||
tr = null;
|
||||
await App.HintContextChange();
|
||||
} catch (Exception exc) {
|
||||
if (tr != null) await tr.ReloadAsync();
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank gespeichert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "Auszahlungsvariante speichern", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
LockContext = true;
|
||||
SetHasChanged(false);
|
||||
}
|
||||
|
||||
private void EnableUnitTextBox(UnitTextBox u) {
|
||||
if (PaymentVar.TestVariant) {
|
||||
u.IsEnabled = true;
|
||||
u.TextBox.IsReadOnly = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void DisableUnitTextBox(UnitTextBox u) {
|
||||
u.IsEnabled = false;
|
||||
u.TextBox.IsReadOnly = true;
|
||||
}
|
||||
|
||||
private void ChangeActiveGraph(Graph? g) {
|
||||
if (g != null && g == SelectedGraphEntry?.DataGraph) {
|
||||
EnableUnitTextBox(OechsleInput);
|
||||
if (SelectedGraphEntry?.GebundenGraph != null) ChangeLineWidth(DataPlot, 4);
|
||||
ChangeLineWidth(GebundenPlot, 1);
|
||||
} else if (g != null && g == SelectedGraphEntry?.GebundenGraph) {
|
||||
EnableUnitTextBox(OechsleInput);
|
||||
ChangeLineWidth(GebundenPlot, 4);
|
||||
ChangeLineWidth(DataPlot, 1);
|
||||
} else {
|
||||
DisableUnitTextBox(OechsleInput);
|
||||
DisableUnitTextBox(PriceInput);
|
||||
OechsleInput.Text = "";
|
||||
PriceInput.Text = "";
|
||||
ChangeLineWidth(DataPlot, 1);
|
||||
ChangeLineWidth(GebundenPlot, 1);
|
||||
}
|
||||
ActiveGraph = g;
|
||||
}
|
||||
|
||||
private void ChangeLineWidth(Scatter? p, double lineWidth) {
|
||||
if (p != null) {
|
||||
p.LineWidth = (float)lineWidth;
|
||||
}
|
||||
}
|
||||
|
||||
private void GraphList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
SelectedGraphEntry = (GraphEntry)GraphList.SelectedItem;
|
||||
RefreshInputs();
|
||||
|
||||
//var x = OechslePricePlot.Plot.GetPlottables().OfType<ScatterPlot>();
|
||||
//MessageBox.Show($"SelectionChanged\nLength: {x.ToList().Count}, Ys: {string.Join(", ", ((ScatterPlot)x.First()).Ys)}");
|
||||
}
|
||||
|
||||
private void PriceInput_LostFocus(object sender, RoutedEventArgs e) {
|
||||
@ -477,8 +705,88 @@ namespace Elwig.Windows {
|
||||
|
||||
}
|
||||
|
||||
private void GebundenBonus_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
private void GebundenFlatBonus_TextChanged(object sender, TextChangedEventArgs e) {
|
||||
if (FillingInputs) return;
|
||||
var r = Validator.CheckDecimal(GebundenFlatBonus.TextBox, true, 2, Season.Precision);
|
||||
if (r.IsValid && SelectedGraphEntry != null) {
|
||||
SelectedGraphEntry.GebundenFlatBonus = double.Parse(GebundenFlatBonus.Text);
|
||||
ResetPlot();
|
||||
InitPlot();
|
||||
}
|
||||
}
|
||||
|
||||
private void ContractInput_Changed(object sender, ItemSelectionChangedEventArgs e) {
|
||||
if (FillingInputs) return;
|
||||
if (e.IsSelected == true) {
|
||||
bool success = RemoveContractFromOtherGraphEntries(e.Item.ToString());
|
||||
if (!success) {
|
||||
ContractInput.SelectedItems.Remove(e.Item);
|
||||
}
|
||||
}
|
||||
var r = ContractInput.SelectedItems.Cast<ContractSelection>();
|
||||
SelectedGraphEntry!.Contracts = r.ToList();
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
}
|
||||
|
||||
private bool RemoveContractFromOtherGraphEntries(string? contract) {
|
||||
if (contract == null) return true;
|
||||
foreach (var ge in GraphEntries) {
|
||||
if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) {
|
||||
var toRemove = ge.Contracts.Where(c => c.Listing.Equals(contract)).ToList();
|
||||
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",
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (r != MessageBoxResult.Yes) {
|
||||
return false;
|
||||
}
|
||||
ge.Contracts.RemoveAll(c => c.Listing.Equals(contract));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AbgewertetInput_Changed(object sender, RoutedEventArgs e) {
|
||||
if (FillingInputs) return;
|
||||
if (SelectedGraphEntry == null) return;
|
||||
SelectedGraphEntry.Abgewertet = AbgewertetInput.IsChecked == true;
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
}
|
||||
|
||||
private void GebundenType_Checked(object sender, RoutedEventArgs e) {
|
||||
if (FillingInputs) return;
|
||||
if (SelectedGraphEntry == null) {
|
||||
DisableUnitTextBox(GebundenFlatBonus);
|
||||
return;
|
||||
}
|
||||
if (GebundenTypeNone.IsChecked == true) {
|
||||
SelectedGraphEntry.RemoveGebundenGraph();
|
||||
DisableUnitTextBox(GebundenFlatBonus);
|
||||
} else if (GebundenTypeFixed.IsChecked == true) {
|
||||
SelectedGraphEntry.GebundenFlatBonus = double.TryParse(GebundenFlatBonus.Text, out var val) ? val : 0.1;
|
||||
SelectedGraphEntry.AddGebundenGraph();
|
||||
EnableUnitTextBox(GebundenFlatBonus);
|
||||
} else if (GebundenTypeGraph.IsChecked == true) {
|
||||
SelectedGraphEntry.AddGebundenGraph();
|
||||
DisableUnitTextBox(GebundenFlatBonus);
|
||||
}
|
||||
SetHasChanged();
|
||||
RefreshInputs();
|
||||
}
|
||||
|
||||
private void CheckGebundenTypeFixed() {
|
||||
FillingInputs = true;
|
||||
if (SelectedGraphEntry?.GebundenFlatBonus is double bonus) {
|
||||
GebundenTypeFixed.IsChecked = true;
|
||||
GebundenFlatBonus.Text = $"{bonus}";
|
||||
EnableUnitTextBox(GebundenFlatBonus);
|
||||
} else if (SelectedGraphEntry?.GebundenGraph != null) {
|
||||
GebundenTypeGraph.IsChecked = true;
|
||||
GebundenFlatBonus.Text = "";
|
||||
DisableUnitTextBox(GebundenFlatBonus);
|
||||
}
|
||||
FillingInputs = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,21 +148,21 @@
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Sorte" Binding="{Binding SortIdString}" Width="50">
|
||||
<DataGridTextColumn Header="Sorte" Binding="{Binding FilteredSortIdString}" Width="50">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
<Style>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Gewicht" Binding="{Binding Weight, StringFormat='{}{0:N0} kg '}" Width="75">
|
||||
<DataGridTextColumn Header="Gewicht" Binding="{Binding FilteredWeight, StringFormat='{}{0:N0} kg '}" Width="75">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
<Style>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Gradation" Binding="{Binding Kmw, StringFormat='{}{0:N1}° '}" Width="50">
|
||||
<DataGridTextColumn Header="Gradation" Binding="{Binding FilteredKmw, StringFormat='{}{0:N1}° '}" Width="50">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
<Style>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
|
||||
|
@ -10,6 +10,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@ -27,7 +28,10 @@ namespace Elwig.Windows {
|
||||
private Member? Member = null;
|
||||
private readonly DispatcherTimer Timer;
|
||||
private List<string> TextFilter = [];
|
||||
private readonly RoutedCommand CtrlF = new();
|
||||
|
||||
private readonly RoutedCommand CtrlF = new("CtrlF", typeof(DeliveryAdminWindow), [new KeyGesture(Key.F, ModifierKeys.Control)]);
|
||||
private readonly RoutedCommand CtrlP = new("CtrlP", typeof(DeliveryAdminWindow), [new KeyGesture(Key.P, ModifierKeys.Control)]);
|
||||
private readonly RoutedCommand CtrlShiftP = new("CtrlShiftP", typeof(DeliveryAdminWindow), [new KeyGesture(Key.P, ModifierKeys.Control | ModifierKeys.Shift)]);
|
||||
|
||||
private string? LastScaleError = null;
|
||||
private string? ManualWeighingReason = null;
|
||||
@ -37,8 +41,9 @@ namespace Elwig.Windows {
|
||||
|
||||
public DeliveryAdminWindow(bool receipt = false) {
|
||||
InitializeComponent();
|
||||
CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
|
||||
CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
|
||||
CommandBindings.Add(new CommandBinding(CtrlP, Menu_Print_ShowDeliveryNote_Click));
|
||||
CommandBindings.Add(new CommandBinding(CtrlShiftP, Menu_Print_PrintDeliveryNote_Click));
|
||||
RequiredInputs = [
|
||||
MgNrInput, MemberInput,
|
||||
LsNrInput, DateInput, BranchInput,
|
||||
@ -168,7 +173,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void Menu_Print_DeliveryJournal_ShowFilter_Click(object sender, RoutedEventArgs evt) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
var (f, _, d, _) = await GetFilters();
|
||||
var (f, _, d, _, _) = await GetFilters();
|
||||
var doc = new DeliveryJournal(string.Join(" / ", f), d);
|
||||
await doc.Generate();
|
||||
Mouse.OverrideCursor = null;
|
||||
@ -177,7 +182,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void Menu_Print_DeliveryJournal_PrintFilter_Click(object sender, RoutedEventArgs evt) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
var (f, _, d, _) = await GetFilters();
|
||||
var (f, _, d, _, _) = await GetFilters();
|
||||
var doc = new DeliveryJournal(string.Join(" / ", f), d);
|
||||
await doc.Generate();
|
||||
Mouse.OverrideCursor = null;
|
||||
@ -296,7 +301,7 @@ namespace Elwig.Windows {
|
||||
await RefreshDeliveryListQuery();
|
||||
}
|
||||
|
||||
private async Task<(List<string>, IQueryable<Delivery>, IQueryable<DeliveryPart>, List<string>)> GetFilters() {
|
||||
private async Task<(List<string>, IQueryable<Delivery>, IQueryable<DeliveryPart>, Predicate<DeliveryPart>, List<string>)> GetFilters() {
|
||||
List<string> filterNames = [];
|
||||
IQueryable<Delivery> deliveryQuery = Context.Deliveries;
|
||||
if (IsReceipt && App.BranchNum > 1) {
|
||||
@ -316,12 +321,8 @@ namespace Elwig.Windows {
|
||||
deliveryQuery = deliveryQuery.Where(d => d.Year == SeasonInput.Value);
|
||||
filterNames.Add(SeasonInput.Value.ToString() ?? "");
|
||||
}
|
||||
IQueryable<DeliveryPart> dpq = deliveryQuery
|
||||
.SelectMany(d => d.Parts)
|
||||
.OrderBy(p => p.Delivery.DateString)
|
||||
.ThenBy(p => p.Delivery.TimeString)
|
||||
.ThenBy(p => p.Delivery.LsNr)
|
||||
.ThenBy(p => p.DPNr);
|
||||
|
||||
Expression<Func<DeliveryPart, bool>> prd = p => true;
|
||||
|
||||
var filterVar = new List<string>();
|
||||
var filterNotVar = new List<string>();
|
||||
@ -487,32 +488,32 @@ namespace Elwig.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
if (filterYearGt > 0) dpq = dpq.Where(p => p.Year >= filterYearGt);
|
||||
if (filterYearLt > 0) dpq = dpq.Where(p => p.Year < filterYearLt);
|
||||
if (filterMgNr.Count > 0) dpq = dpq.Where(p => filterMgNr.Contains(p.Delivery.MgNr));
|
||||
if (filterYearGt > 0) prd = prd.And(p => p.Year >= filterYearGt);
|
||||
if (filterYearLt > 0) prd = prd.And(p => p.Year < filterYearLt);
|
||||
if (filterMgNr.Count > 0) prd = prd.And(p => filterMgNr.Contains(p.Delivery.MgNr));
|
||||
if (filterDate.Count > 0) {
|
||||
var pr = PredicateBuilder.New<DeliveryPart>(false);
|
||||
foreach (var (d1, d2) in filterDate)
|
||||
pr.Or(p => (d1 == null || d1.CompareTo(p.Delivery.DateString.Substring(10 - d1.Length)) <= 0) && (d2 == null || d2.CompareTo(p.Delivery.DateString.Substring(10 - d2.Length)) >= 0));
|
||||
dpq = dpq.Where(pr);
|
||||
prd = prd.And(pr);
|
||||
}
|
||||
if (filterTime.Count > 0) {
|
||||
var pr = PredicateBuilder.New<DeliveryPart>(false);
|
||||
foreach (var (t1, t2) in filterTime)
|
||||
pr.Or(p => (t1 == null || t1.CompareTo(p.Delivery.TimeString) <= 0) && (t2 == null || t2.CompareTo(p.Delivery.TimeString) > 0));
|
||||
dpq = dpq.Where(p => p.Delivery.TimeString != null).Where(pr);
|
||||
prd = prd.And(p => p.Delivery.TimeString != null).And(pr);
|
||||
}
|
||||
if (filterVar.Count > 0) dpq = dpq.Where(p => filterVar.Contains(p.SortId));
|
||||
if (filterNotVar.Count > 0) dpq = dpq.Where(p => !filterNotVar.Contains(p.SortId));
|
||||
if (filterQual.Count > 0) dpq = dpq.Where(p => filterQual.Contains(p.QualId));
|
||||
if (filterNotQual.Count > 0) dpq = dpq.Where(p => !filterNotQual.Contains(p.QualId));
|
||||
if (filterZwst.Count > 0) dpq = dpq.Where(p => filterZwst.Contains(p.Delivery.ZwstId));
|
||||
if (filterAttr.Count > 0) dpq = dpq.Where(p => p.AttrId != null && filterAttr.Contains(p.AttrId));
|
||||
if (filterNotAttr.Count > 0) dpq = dpq.Where(p => p.AttrId == null || !filterNotAttr.Contains(p.AttrId));
|
||||
if (filterKmwGt > 0) dpq = dpq.Where(p => p.Kmw >= filterKmwGt);
|
||||
if (filterKmwLt > 0) dpq = dpq.Where(p => p.Kmw < filterKmwLt);
|
||||
if (filterOeGt > 0) dpq = dpq.Where(p => p.Kmw * (4.54 + 0.022 * p.Kmw) >= filterOeGt);
|
||||
if (filterOeLt > 0) dpq = dpq.Where(p => p.Kmw * (4.54 + 0.022 * p.Kmw) < filterOeLt);
|
||||
if (filterVar.Count > 0) prd = prd.And(p => filterVar.Contains(p.SortId));
|
||||
if (filterNotVar.Count > 0) prd = prd.And(p => !filterNotVar.Contains(p.SortId));
|
||||
if (filterQual.Count > 0) prd = prd.And(p => filterQual.Contains(p.QualId));
|
||||
if (filterNotQual.Count > 0) prd = prd.And(p => !filterNotQual.Contains(p.QualId));
|
||||
if (filterZwst.Count > 0) prd = prd.And(p => filterZwst.Contains(p.Delivery.ZwstId));
|
||||
if (filterAttr.Count > 0) prd = prd.And(p => p.AttrId != null && filterAttr.Contains(p.AttrId));
|
||||
if (filterNotAttr.Count > 0) prd = prd.And(p => p.AttrId == null || !filterNotAttr.Contains(p.AttrId));
|
||||
if (filterKmwGt > 0) prd = prd.And(p => p.Kmw >= filterKmwGt);
|
||||
if (filterKmwLt > 0) prd = prd.And(p => p.Kmw < filterKmwLt);
|
||||
if (filterOeGt > 0) prd = prd.And(p => p.Kmw * (4.54 + 0.022 * p.Kmw) >= filterOeGt);
|
||||
if (filterOeLt > 0) prd = prd.And(p => p.Kmw * (4.54 + 0.022 * p.Kmw) < filterOeLt);
|
||||
|
||||
if (filterYearGt > 0 && filterYearLt > 0) {
|
||||
filterNames.Insert(0, $"{filterYearGt}–{filterYearLt - 1}");
|
||||
@ -537,7 +538,15 @@ namespace Elwig.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
return (filterNames, dpq.Select(p => p.Delivery).Distinct().OrderBy(d => d.DateString).ThenBy(d => d.TimeString), dpq, filter);
|
||||
IQueryable<DeliveryPart> dpq = deliveryQuery
|
||||
.SelectMany(d => d.Parts)
|
||||
.Where(prd)
|
||||
.OrderBy(p => p.Delivery.DateString)
|
||||
.ThenBy(p => p.Delivery.TimeString)
|
||||
.ThenBy(p => p.Delivery.LsNr)
|
||||
.ThenBy(p => p.DPNr);
|
||||
|
||||
return (filterNames, dpq.Select(p => p.Delivery).Distinct().OrderBy(d => d.DateString).ThenBy(d => d.TimeString), dpq, prd.Invoke, filter);
|
||||
}
|
||||
|
||||
private static void AddToolTipCell(Grid grid, string text, int row, int col, int colSpan = 1, bool bold = false, bool alignRight = false, bool alignCenter = false) {
|
||||
@ -573,7 +582,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async Task RefreshDeliveryListQuery(bool updateSort = false) {
|
||||
var (_, deliveryQuery, deliveryPartsQuery, filter) = await GetFilters();
|
||||
var (_, deliveryQuery, deliveryPartsQuery, predicate, filter) = await GetFilters();
|
||||
var deliveries = await deliveryQuery.ToListAsync();
|
||||
deliveries.Reverse();
|
||||
|
||||
@ -589,8 +598,10 @@ namespace Elwig.Windows {
|
||||
.ToList();
|
||||
}
|
||||
|
||||
deliveries.ForEach(d => { d.PartFilter = predicate; });
|
||||
ControlUtils.RenewItemsSource(DeliveryList, deliveries, d => ((d as Delivery)?.Year, (d as Delivery)?.DId),
|
||||
DeliveryList_SelectionChanged, filter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort);
|
||||
await RefreshDeliveryParts();
|
||||
|
||||
var members = deliveries.Select(d => d.Member).DistinctBy(m => m.MgNr).ToList();
|
||||
StatusMembers.Text = $"Mitglieder: {members.Count}" + (members.Count > 0 && members.Count <= 4 ? $" ({string.Join(", ", members.Select(m => m.AdministrativeName))})" : "");
|
||||
@ -722,7 +733,7 @@ namespace Elwig.Windows {
|
||||
Menu_Export_Bki.Items.Clear();
|
||||
foreach (var s in await Context.Seasons.OrderByDescending(s => s.Year).ToListAsync()) {
|
||||
var i = new MenuItem {
|
||||
Header = $"Season {s.Year}",
|
||||
Header = $"Saison {s.Year}",
|
||||
};
|
||||
i.Click += Menu_Export_Bki_Click;
|
||||
Menu_Export_Bki.Items.Add(i);
|
||||
@ -760,7 +771,7 @@ namespace Elwig.Windows {
|
||||
private async Task RefreshDeliveryParts() {
|
||||
if (DeliveryList.SelectedItem is Delivery d) {
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == d.Year).OrderBy(m => m.Ordering).ToListAsync(), i => (i as Modifier)?.ModId);
|
||||
ControlUtils.RenewItemsSource(DeliveryPartList, d.Parts.OrderBy(p => p.DPNr).ToList(), i => ((i as DeliveryPart)?.Year, (i as DeliveryPart)?.DId, (i as DeliveryPart)?.DPNr), DeliveryPartList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(DeliveryPartList, d.FilteredParts.OrderBy(p => p.DPNr).ToList(), i => ((i as DeliveryPart)?.Year, (i as DeliveryPart)?.DId, (i as DeliveryPart)?.DPNr), DeliveryPartList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
||||
} else {
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == Utils.CurrentLastSeason).OrderBy(m => m.Ordering).ToListAsync(), i => (i as Modifier)?.ModId);
|
||||
DeliveryPartList.ItemsSource = null;
|
||||
@ -1134,7 +1145,7 @@ namespace Elwig.Windows {
|
||||
} else {
|
||||
// switch to last delivery part
|
||||
DeliveryPartList.IsEnabled = true;
|
||||
DeliveryPartList.SelectedItem = d.Parts.Last();
|
||||
DeliveryPartList.SelectedItem = d.FilteredParts.Last();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,15 +17,19 @@ namespace Elwig.Windows {
|
||||
public partial class MemberAdminWindow : AdministrationWindow {
|
||||
|
||||
private List<string> TextFilter = [];
|
||||
private readonly RoutedCommand CtrlF = new();
|
||||
private readonly (ComboBox, TextBox, TextBox)[] PhoneNrInputs;
|
||||
|
||||
private readonly RoutedCommand CtrlF = new("CtrlF", typeof(MemberAdminWindow), [new KeyGesture(Key.F, ModifierKeys.Control)]);
|
||||
private readonly RoutedCommand CtrlP = new("CtrlP", typeof(MemberAdminWindow), [new KeyGesture(Key.P, ModifierKeys.Control)]);
|
||||
private readonly RoutedCommand CtrlShiftP = new("CtrlShiftP", typeof(MemberAdminWindow), [new KeyGesture(Key.P, ModifierKeys.Control | ModifierKeys.Shift)]);
|
||||
|
||||
private static ObservableCollection<KeyValuePair<string, string>> PhoneNrTypes { get; set; } = new(Utils.PhoneNrTypes);
|
||||
|
||||
public MemberAdminWindow() {
|
||||
InitializeComponent();
|
||||
CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
|
||||
CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
|
||||
CommandBindings.Add(new CommandBinding(CtrlP, Menu_Show_MemberDataSheet_Click));
|
||||
CommandBindings.Add(new CommandBinding(CtrlShiftP, Menu_Print_MemberDataSheet_Click));
|
||||
ExemptInputs = [
|
||||
SearchInput, ActiveMemberInput, MemberList,
|
||||
];
|
||||
|
@ -52,6 +52,8 @@ namespace Elwig.Windows {
|
||||
Arrow3.Content = locked ? "\xF0B0" : "\xF0AF";
|
||||
CopyButton.IsEnabled = true;
|
||||
EditButton.Content = locked ? "Ansehen" : "Bearbeiten";
|
||||
EditButton.IsEnabled = true;
|
||||
SaveButton.IsEnabled = !locked;
|
||||
ShowButton.IsEnabled = true;
|
||||
PrintButton.IsEnabled = true;
|
||||
ExportButton.IsEnabled = locked;
|
||||
@ -67,30 +69,27 @@ namespace Elwig.Windows {
|
||||
try {
|
||||
BillingData = BillingData.FromJson(v.Data);
|
||||
ConsiderModifiersInput.IsChecked = BillingData.ConsiderDelieryModifiers;
|
||||
ConsiderModifiersInput.IsEnabled = !locked;
|
||||
ConsiderPenaltiesInput.IsChecked = BillingData.ConsiderContractPenalties;
|
||||
ConsiderPenaltiesInput.IsEnabled = !locked;
|
||||
ConsiderPenaltyInput.IsChecked = BillingData.ConsiderTotalPenalty;
|
||||
ConsiderPenaltyInput.IsEnabled = !locked;
|
||||
ConsiderAutoInput.IsChecked = BillingData.ConsiderAutoBusinessShares;
|
||||
ConsiderAutoInput.IsEnabled = !locked;
|
||||
DataInput.Text = JsonSerializer.Serialize(BillingData.Data, JsonOpt);
|
||||
DataInput.IsReadOnly = locked;
|
||||
} catch {
|
||||
BillingData = null;
|
||||
ConsiderModifiersInput.IsChecked = false;
|
||||
ConsiderModifiersInput.IsEnabled = false;
|
||||
ConsiderPenaltiesInput.IsChecked = false;
|
||||
ConsiderPenaltiesInput.IsEnabled = false;
|
||||
ConsiderPenaltyInput.IsChecked = false;
|
||||
ConsiderPenaltyInput.IsEnabled = false;
|
||||
ConsiderAutoInput.IsChecked = false;
|
||||
ConsiderAutoInput.IsEnabled = false;
|
||||
DataInput.Text = v.Data;
|
||||
DataInput.IsEnabled = false;
|
||||
}
|
||||
ConsiderModifiersInput.IsEnabled = !locked;
|
||||
ConsiderPenaltiesInput.IsEnabled = !locked;
|
||||
ConsiderPenaltyInput.IsEnabled = !locked;
|
||||
ConsiderAutoInput.IsEnabled = !locked;
|
||||
DataInput.IsReadOnly = locked;
|
||||
} else {
|
||||
EditButton.Content = "Bearbeiten";
|
||||
EditButton.IsEnabled = false;
|
||||
SaveButton.IsEnabled = false;
|
||||
CopyButton.IsEnabled = false;
|
||||
CalculateButton.IsEnabled = false;
|
||||
CommitButton.IsEnabled = false;
|
||||
@ -130,11 +129,12 @@ namespace Elwig.Windows {
|
||||
private void UpdateSaveButton() {
|
||||
SaveButton.IsEnabled = PaymentVariantList.SelectedItem != null &&
|
||||
((DataChanged && DataValid) || NameChanged || CommentChanged ||
|
||||
(TransferDateChanged && TransferDateValid)) ||
|
||||
(TransferDateChanged && TransferDateValid) ||
|
||||
(ConsiderModifiersInput.IsChecked != BillingData?.ConsiderDelieryModifiers) ||
|
||||
(ConsiderPenaltiesInput.IsChecked != BillingData?.ConsiderContractPenalties) ||
|
||||
(ConsiderPenaltyInput.IsChecked != BillingData?.ConsiderTotalPenalty) ||
|
||||
(ConsiderAutoInput.IsChecked != BillingData?.ConsiderAutoBusinessShares);
|
||||
(ConsiderAutoInput.IsChecked != BillingData?.ConsiderAutoBusinessShares));
|
||||
CalculateButton.IsEnabled = !SaveButton.IsEnabled && PaymentVariantList.SelectedItem is PaymentVar { TestVariant: true };
|
||||
}
|
||||
|
||||
private void UpdateSums() {
|
||||
@ -173,7 +173,7 @@ namespace Elwig.Windows {
|
||||
v.Name = "Neue Auszahlungsvariante";
|
||||
v.TestVariant = true;
|
||||
v.DateString = $"{DateTime.Today:yyyy-MM-dd}";
|
||||
v.Data = "{\"mode\": \"elwig\", \"version\": 1, \"payment\": 1.0, \"curves\": []}";
|
||||
v.Data = "{\"mode\": \"elwig\", \"version\": 1, \"payment\": 1.0, \"quality\": {\"WEI\": 0}, \"curves\": []}";
|
||||
|
||||
await Context.AddAsync(v);
|
||||
await Context.SaveChangesAsync();
|
||||
|
@ -1,5 +1,5 @@
|
||||
::mkdir "C:\Program Files\Elwig"
|
||||
::curl -s "http://www.columbia.edu/~em36/PDFtoPrinter.exe" -z "C:\Program Files\Elwig\PDFtoPrinter.exe" -o "C:\Program Files\Elwig\PDFtoPrinter.exe"
|
||||
::curl -s -L "http://www.columbia.edu/~em36/PDFtoPrinter.exe" -z "C:\Program Files\Elwig\PDFtoPrinter.exe" -o "C:\Program Files\Elwig\PDFtoPrinter.exe"
|
||||
mkdir "C:\ProgramData\Elwig\resources"
|
||||
copy /b /y Documents\*.css "C:\ProgramData\Elwig\resources"
|
||||
copy /b /y Documents\*.cshtml "C:\ProgramData\Elwig\resources"
|
||||
|
@ -25,7 +25,7 @@
|
||||
</Task>
|
||||
</UsingTask>
|
||||
<Target Name="CustomBeforeBuild" BeforeTargets="BeforeBuild">
|
||||
<Exec Command="curl -s "http://www.columbia.edu/~em36/PDFtoPrinter.exe" -z "$(TargetDir)PDFtoPrinter.exe" -o "$(TargetDir)PDFtoPrinter.exe"" />
|
||||
<Exec Command="curl -s -L "http://www.columbia.edu/~em36/PDFtoPrinter.exe" -z "$(TargetDir)PDFtoPrinter.exe" -o "$(TargetDir)PDFtoPrinter.exe"" />
|
||||
<Exec Command="dotnet publish "$(SolutionDir)Elwig\Elwig.csproj" "/p:PublishProfile=$(SolutionDir)\Elwig\Properties\PublishProfiles\FolderProfile.pubxml"" />
|
||||
<GetFileVersion AssemblyPath="..\Elwig\bin\Publish\Elwig.exe">
|
||||
<Output TaskParameter="Version" PropertyName="ElwigFileVersion" />
|
||||
|
@ -5,8 +5,8 @@
|
||||
<Cultures>de-AT</Cultures>
|
||||
</PropertyGroup>
|
||||
<Target Name="CustomBeforeBuild" BeforeTargets="BeforeBuild">
|
||||
<Exec Command='curl -L -s "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -z "$(TargetDir)MicrosoftEdgeWebview2Setup.exe" -o "$(TargetDir)MicrosoftEdgeWebview2Setup.exe"' />
|
||||
<Exec Command='curl -L -s "https://aka.ms/vs/17/release/vc_redist.x86.exe" -z "$(TargetDir)VC_redist.x86.exe" -o "$(TargetDir)VC_redist.x86.exe"' />
|
||||
<Exec Command='curl -s -L "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -z "$(TargetDir)MicrosoftEdgeWebview2Setup.exe" -o "$(TargetDir)MicrosoftEdgeWebview2Setup.exe"' />
|
||||
<Exec Command='curl -s -L "https://aka.ms/vs/17/release/vc_redist.x86.exe" -z "$(TargetDir)VC_redist.x86.exe" -o "$(TargetDir)VC_redist.x86.exe"' />
|
||||
<PropertyGroup>
|
||||
<DefineConstants>ElwigProjectDir=..\Elwig</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
@ -1,10 +1,13 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Models.Entities;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Tests.Helpers {
|
||||
namespace Tests.HelperTests {
|
||||
[TestFixture]
|
||||
public class BillingDataTest {
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };
|
||||
private static readonly string[] AttributeVariants = ["GV", "GVD", "GVK", "GVS", "GVZ", "WR", "WRS", "ZW", "ZWS", "ZWZ"];
|
||||
|
||||
[OneTimeSetUp]
|
||||
@ -41,7 +44,7 @@ namespace Tests.Helpers {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_01_Flatrate() {
|
||||
public void TestRead_01_Flatrate() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -57,7 +60,7 @@ namespace Tests.Helpers {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_02_Simple() {
|
||||
public void TestRead_02_Simple() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -92,7 +95,7 @@ namespace Tests.Helpers {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_03_GreaterThanAndLessThan() {
|
||||
public void TestRead_03_GreaterThanAndLessThan() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -131,7 +134,7 @@ namespace Tests.Helpers {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_04_VariantsAndAttributes() {
|
||||
public void TestRead_04_VariantsAndAttributes() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -161,7 +164,7 @@ namespace Tests.Helpers {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_05_QualityLevel() {
|
||||
public void TestRead_05_QualityLevel() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -192,7 +195,7 @@ namespace Tests.Helpers {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_06_ModeOeAndKmw() {
|
||||
public void TestRead_06_ModeOeAndKmw() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -234,7 +237,7 @@ namespace Tests.Helpers {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_07_MultipleCurves() {
|
||||
public void TestRead_07_MultipleCurves() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -303,7 +306,7 @@ namespace Tests.Helpers {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_08_WgMaster() {
|
||||
public void TestRead_08_WgMaster() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "wgmaster",
|
||||
@ -345,5 +348,162 @@ namespace Tests.Helpers {
|
||||
TestCalcOe(data, "GVK", 115, 0.065m);
|
||||
});
|
||||
}
|
||||
|
||||
private static List<ContractSelection> GetSelection(IEnumerable<string> attVars) {
|
||||
return attVars.Select(s => {
|
||||
var sortid = s[..2];
|
||||
var attrid = s.Length > 2 ? s[2..] : null;
|
||||
return new ContractSelection(
|
||||
new WineVar(sortid, sortid),
|
||||
attrid == null ? null : new WineAttr(attrid, attrid)
|
||||
);
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_01_Empty() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(1, 4, BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m
|
||||
}, null)
|
||||
];
|
||||
var updated = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(updated.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": 0,
|
||||
"curves": []
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_02_Flatrate() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m
|
||||
}, null), GetSelection(["GV"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": 0.5,
|
||||
"curves": []
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_03_SingleCurve() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[83] = 1.0m
|
||||
}, null), GetSelection(["GV"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": "curve:1",
|
||||
"curves": [
|
||||
{
|
||||
"id": 1,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.5,
|
||||
"83oe": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_04_Simple() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[84] = 1.0m
|
||||
}, null), GetSelection(["GV", "ZW"])),
|
||||
new GraphEntry(10, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.75m,
|
||||
}, null), GetSelection(["WR"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": {
|
||||
"WR/": 0.75,
|
||||
"default": "curve:1"
|
||||
},
|
||||
"curves": [
|
||||
{
|
||||
"id": 1,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.5,
|
||||
"84oe": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_05_Attribute() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[84] = 1.0m
|
||||
}, null), GetSelection(["GVB", "ZWB"])),
|
||||
new GraphEntry(2, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.75m,
|
||||
}, null), GetSelection(["WR", "BL", "RR", "FV"])),
|
||||
new GraphEntry(4, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.65m,
|
||||
[84] = 1.2m
|
||||
}, null), GetSelection(["BP", "SA"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": {
|
||||
"BP/": "curve:2",
|
||||
"SA/": "curve:2",
|
||||
"default": 0.75,
|
||||
"/B": "curve:1"
|
||||
},
|
||||
"curves": [
|
||||
{
|
||||
"id": 1,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.5,
|
||||
"84oe": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.65,
|
||||
"84oe": 1.2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""));
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Tests.Helpers {
|
||||
namespace Tests.HelperTests {
|
||||
[TestFixture]
|
||||
public class BillingTest {
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Elwig.Helpers;
|
||||
|
||||
namespace Tests.Helpers {
|
||||
namespace Tests.HelperTests {
|
||||
[TestFixture]
|
||||
public class UtilsTest {
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Elwig.Helpers;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Tests.Helpers {
|
||||
namespace Tests.HelperTests {
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
public class ValidatorTest {
|
@ -13,7 +13,7 @@
|
||||
<EmbeddedResource Include="Resources\*.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
<Target Name="FetchResources" BeforeTargets="BeforeBuild">
|
||||
<Exec Command="call fetch-resources.bat" />
|
||||
</Target>
|
||||
|
||||
|
@ -1 +1 @@
|
||||
curl -s "https://www.necronda.net/elwig/files/create.sql?v=13" -u "elwig:ganzGeheim123!" -o "Resources\Create.sql"
|
||||
curl -s -L "https://www.necronda.net/elwig/files/create.sql?v=13" -u "elwig:ganzGeheim123!" -o "Resources\Create.sql"
|
||||
|
Reference in New Issue
Block a user