Compare commits

..

14 Commits

27 changed files with 350 additions and 212 deletions

View File

@@ -65,22 +65,27 @@ namespace Elwig {
MainDispatcher = Dispatcher;
Scales = Array.Empty<IScale>();
CurrentApp = this;
OverrideCulture();
}
protected override async void OnStartup(StartupEventArgs evt) {
var locale = new CultureInfo("de-AT");
locale.NumberFormat.CurrencyGroupSeparator = "\u202f";
locale.NumberFormat.NumberGroupSeparator = "\u202f";
locale.NumberFormat.PercentGroupSeparator = "\u202f";
private static void OverrideCulture() {
var locale = new CultureInfo("de-AT", false);
locale.NumberFormat.CurrencyGroupSeparator = Utils.GroupSeparator;
locale.NumberFormat.NumberGroupSeparator = Utils.GroupSeparator;
locale.NumberFormat.PercentGroupSeparator = Utils.GroupSeparator;
CultureInfo.CurrentCulture = locale;
CultureInfo.CurrentUICulture = locale;
Thread.CurrentThread.CurrentCulture = locale;
Thread.CurrentThread.CurrentUICulture = locale;
CultureInfo.DefaultThreadCurrentCulture = locale;
CultureInfo.DefaultThreadCurrentUICulture = locale;
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name))
);
}
protected override async void OnStartup(StartupEventArgs evt) {
Version = typeof(App).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split("+")[0] ?? "0.0.0";
try {

View File

@@ -12,7 +12,7 @@ namespace Elwig.Dialogs {
InitializeComponent();
TextLsNr.Text = lsnr;
TextMember.Text = name;
TextWeight.Text = $"{weight:N0}\u202fkg";
TextWeight.Text = $"{weight:N0}{Utils.UnitSeparator}kg";
}
private void ConfirmButton_Click(object sender, RoutedEventArgs evt) {

View File

@@ -1,5 +1,4 @@
using Elwig.Helpers;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
@@ -14,7 +13,7 @@ namespace Elwig.Dialogs {
private void ConfirmButton_Click(object sender, RoutedEventArgs evt) {
DialogResult = true;
Price = double.Parse(PriceInput.Text.Replace("\u202f", ""));
Price = double.Parse(PriceInput.Text.Replace(Utils.GroupSeparator, ""));
Close();
}

View File

@@ -7,7 +7,7 @@
<UseWPF>true</UseWPF>
<PreserveCompilationContext>true</PreserveCompilationContext>
<ApplicationIcon>Resources\Images\Elwig.ico</ApplicationIcon>
<Version>0.5.1</Version>
<Version>0.6.0</Version>
<SatelliteResourceLanguages>de-AT</SatelliteResourceLanguages>
</PropertyGroup>
@@ -25,11 +25,11 @@
<ItemGroup>
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" />
<PackageReference Include="LinqKit" Version="1.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.25" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.26" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="8.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2151.40" />
<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" />

View File

@@ -13,7 +13,6 @@ namespace Elwig.Helpers.Billing {
public enum CalculationMode { Elwig, WgMaster }
public enum CurveMode { Oe, Kmw }
public record struct Curve(CurveMode Mode, Dictionary<double, decimal> Normal, Dictionary<double, decimal>? Gebunden);
public static JsonSchema? Schema { get; private set; }
@@ -24,11 +23,7 @@ namespace Elwig.Helpers.Billing {
}
public readonly JsonObject Data;
private readonly CalculationMode Mode;
private readonly Dictionary<int, Curve> Curves;
private readonly Dictionary<string, Curve> PaymentData;
private readonly Dictionary<string, Curve> QualityData;
public readonly CalculationMode Mode;
public bool ConsiderDelieryModifiers {
get => GetConsider("consider_delivery_modifiers");
@@ -61,18 +56,13 @@ namespace Elwig.Helpers.Billing {
}
}
public BillingData(JsonObject data, IEnumerable<string> attributeVariants) {
if (attributeVariants.Any(e => e.Any(c => c < 'A' || c > 'Z')))
throw new ArgumentException("Invalid attributeVariants");
public BillingData(JsonObject data) {
Data = data;
var mode = Data["mode"]?.GetValue<string>();
Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster;
Curves = GetCurves(Data, Mode);
PaymentData = GetPaymentData(attributeVariants);
QualityData = GetQualityData(attributeVariants);
}
public static JsonObject ParseJson(string json) {
protected static JsonObject ParseJson(string json) {
if (Schema == null) throw new InvalidOperationException("Schema has to be initialized first");
try {
var errors = Schema.Validate(json);
@@ -84,11 +74,19 @@ namespace Elwig.Helpers.Billing {
}
public static BillingData FromJson(string json) {
return FromJson(json, []);
return new(ParseJson(json));
}
public static BillingData FromJson(string json, IEnumerable<string> attributeVariants) {
return new(ParseJson(json), attributeVariants);
protected JsonArray GetCurvesEntry() {
return Data[Mode == CalculationMode.Elwig ? "curves" : "Kurven"]?.AsArray() ?? throw new InvalidOperationException();
}
protected JsonNode GetPaymentEntry() {
return Data[Mode == CalculationMode.Elwig ? "payment" : "AuszahlungSorten"] ?? throw new InvalidOperationException();
}
protected JsonObject? GetQualityEntry() {
return Data[Mode == CalculationMode.Elwig ? "quality" : "AuszahlungSortenQualitätsstufe"]?.AsObject();
}
private static Dictionary<double, decimal> GetCurveData(JsonObject data, CurveMode mode) {
@@ -119,9 +117,9 @@ namespace Elwig.Helpers.Billing {
return dict;
}
public static Dictionary<int, Curve> GetCurves(JsonObject data, CalculationMode mode) {
protected Dictionary<int, Curve> GetCurves() {
var dict = new Dictionary<int, Curve>();
var curves = data[mode == CalculationMode.Elwig ? "curves" : "Kurven"]?.AsArray() ?? throw new InvalidOperationException();
var curves = GetCurvesEntry();
foreach (var c in curves) {
var obj = c?.AsObject() ?? throw new InvalidOperationException();
var id = obj["id"]?.GetValue<int>() ?? throw new InvalidOperationException();
@@ -147,108 +145,5 @@ namespace Elwig.Helpers.Billing {
}
return dict;
}
private Dictionary<string, Curve> GetData(JsonObject data, IEnumerable<string> attributeVariants) {
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;
}
public Dictionary<string, Curve> GetPaymentData(IEnumerable<string> attributeVariants) {
var p = Data[Mode == CalculationMode.Elwig ? "payment" : "AuszahlungSorten"];
if (p is JsonValue val) {
var c = LookupCurve(val);
return attributeVariants.ToDictionary(e => e, _ => c);
}
return GetData(p?.AsObject() ?? throw new InvalidOperationException(), attributeVariants);
}
public Dictionary<string, Curve> GetQualityData(IEnumerable<string> attributeVariants) {
var q = Data[Mode == CalculationMode.Elwig ? "quality" : "AuszahlungSortenQualitätsstufe"]?.AsObject();
Dictionary<string, Curve> dict = [];
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(), attributeVariants);
}
foreach (var (idx, d) in qualDict) {
dict[$"{qualid}/{idx}"] = d;
}
}
return dict;
}
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;
}
private Curve LookupCurve(JsonValue val) {
if (val.TryGetValue(out string? curve)) {
var curveId = int.Parse(curve.Split(":")[1]);
return Curves[curveId];
} else if (val.TryGetValue(out decimal value)) {
return new(CurveMode.Oe, new() { { 73, value } }, null);
}
throw new InvalidOperationException();
}
public Curve GetCurve(string sortid, string? attrid) {
return PaymentData[$"{sortid}{attrid ?? ""}"];
}
public Curve? GetQualityCurve(string qualid, string sortid, string? attrid) {
return QualityData.TryGetValue($"{qualid}/{sortid}{attrid ?? ""}", out var curve) ? curve : null;
}
}
}

View File

@@ -10,7 +10,7 @@ namespace Elwig.Helpers.Billing {
protected readonly int AvNr;
protected readonly PaymentVar PaymentVariant;
protected readonly BillingData Data;
protected readonly PaymentBillingData Data;
public BillingVariant(int year, int avnr) : base(year) {
AvNr = avnr;
@@ -22,7 +22,7 @@ namespace Elwig.Helpers.Billing {
.ToList()
.Union(Context.WineVarieties.Select(v => v.SortId))
.ToList();
Data = BillingData.FromJson(PaymentVariant.Data, attrVariants);
Data = PaymentBillingData.FromJson(PaymentVariant.Data, attrVariants);
}
public async Task Calculate() {

View File

@@ -0,0 +1,90 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
namespace Elwig.Helpers.Billing {
public class EditBillingData : BillingData {
protected readonly IEnumerable<string> AttributeVariants;
public EditBillingData(JsonObject data, IEnumerable<string> attributeVariants) :
base(data) {
AttributeVariants = attributeVariants;
}
public static EditBillingData FromJson(string json, IEnumerable<string> attributeVariants) {
return new(ParseJson(json), attributeVariants);
}
public IEnumerable<GraphEntry> GetPaymentGraphEntries() {
Dictionary<int, List<string>> dict1 = [];
Dictionary<decimal, List<string>> dict2 = [];
var p = GetPaymentEntry();
if (p is JsonObject paymentObj) {
foreach (var (selector, node) in paymentObj) {
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 (p is JsonValue paymentVal) {
var idx = paymentVal.GetValue<decimal>();
if (!dict2.ContainsKey(idx)) dict2[idx] = [];
dict2[idx].Add("default");
}
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);
}
Dictionary<int, List<string>> dict3 = [];
return dict3.Select(e => new GraphEntry(e.Key, curves[e.Key], 50, 120)).ToList();
}
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}/");
}
}
// TODO
List<GraphEntry> list = [];
return list;
}
}
}

View File

@@ -3,7 +3,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
using System.Windows.Documents;
namespace Elwig.Helpers.Billing {
public class Graph : ICloneable {

View File

@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
namespace Elwig.Helpers.Billing {
public class GraphEntry {
@@ -26,12 +22,20 @@ namespace Elwig.Helpers.Billing {
Contracts = [];
}
public GraphEntry(int id, BillingData.CurveMode mode, Dictionary<double, decimal> data, int minX, int maxX) : this(id, mode, minX, maxX) {
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, BillingData.Curve curve, int minX, int maxX) :
this(id, curve.Mode, minX, maxX) {
DataGraph = new Graph(curve.Normal, 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) {
decimal? gebundenFlatPrice, List<string> contracts, int minX, int maxX) {
Id = id;
Mode = mode;
MinX = minX;

View File

@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.Json.Nodes;
namespace Elwig.Helpers.Billing {
public class PaymentBillingData : BillingData {
protected readonly Dictionary<int, Curve> Curves;
protected readonly Dictionary<string, Curve> PaymentData;
protected readonly Dictionary<string, Curve> QualityData;
protected readonly IEnumerable<string> AttributeVariants;
public PaymentBillingData(JsonObject data, IEnumerable<string> attributeVariants) :
base(data) {
if (attributeVariants.Any(e => e.Any(c => c < 'A' || c > 'Z')))
throw new ArgumentException("Invalid attributeVariants");
AttributeVariants = attributeVariants;
Curves = GetCurves();
PaymentData = GetPaymentData();
QualityData = GetQualityData();
}
public static PaymentBillingData FromJson(string json, IEnumerable<string> attributeVariants) {
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;
}
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());
}
protected Dictionary<string, Curve> GetQualityData() {
Dictionary<string, Curve> dict = [];
var q = GetQualityEntry();
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) {
dict[$"{qualid}/{idx}"] = d;
}
}
return dict;
}
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;
}
private Curve LookupCurve(JsonValue val) {
if (val.TryGetValue(out string? curve)) {
var curveId = int.Parse(curve.Split(":")[1]);
return Curves[curveId];
} else if (val.TryGetValue(out decimal value)) {
return new(CurveMode.Oe, new() { { 73, value } }, null);
}
throw new InvalidOperationException();
}
protected Curve GetCurve(string sortid, string? 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;
}
}
}

View File

@@ -24,9 +24,9 @@ namespace Elwig.Helpers {
public void Read() {
var config = new ConfigurationBuilder().AddIniFile(FileName).Build();
DatabaseFile = Utils.GetAbsolutePath(config["database:file"] ?? "database.sqlite3", App.DataPath);
DatabaseFile = Path.Combine(App.DataPath, config["database:file"] ?? "database.sqlite3");
var log = config["database:log"];
DatabaseLog = log != null ? Utils.GetAbsolutePath(log, App.DataPath) : null;
DatabaseLog = log != null ? Path.Combine(App.DataPath, log) : null;
Branch = config["general:branch"];
Debug = trueValues.Contains(config["general:debug"]?.ToLower());
@@ -35,7 +35,7 @@ namespace Elwig.Helpers {
Scales = ScaleList;
foreach (var s in scales) {
string? scaleLog = config[$"scale.{s}:log"];
if (scaleLog != null) scaleLog = Utils.GetAbsolutePath(scaleLog, App.DataPath);
if (scaleLog != null) scaleLog = Path.Combine(App.DataPath, scaleLog);
ScaleList.Add([
s, config[$"scale.{s}:type"], config[$"scale.{s}:model"], config[$"scale.{s}:connection"],
config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"], scaleLog

View File

@@ -48,6 +48,9 @@ namespace Elwig.Helpers {
[GeneratedRegex(@"^(.*?) +([0-9].*)$", RegexOptions.Compiled)]
private static partial Regex GeneratedAddressRegex();
public static readonly string GroupSeparator = "\u202F";
public static readonly string UnitSeparator = "\u00A0";
public static readonly KeyValuePair<string, string>[] PhoneNrTypes = [
new("landline", "Tel.-Nr. (Festnetz)"),
new("mobile", "Tel.-Nr. (mobil)"),
@@ -356,9 +359,5 @@ namespace Elwig.Helpers {
}
return output.OrderByDescending(l => l.Count());
}
public static string GetAbsolutePath(string path, string basePath) {
return (path.Length > 1 && (path[1] == ':' || path[0] == '/' || path[0] == '\\')) ? Path.Combine(basePath, path) : path;
}
}
}

View File

@@ -26,6 +26,10 @@ namespace Elwig.Models.Dtos {
MgNr = m.MgNr;
}
public static DeliveryConfirmationData CreateEmpty(int year, Member m) {
return new([], year, m);
}
public static async Task<IDictionary<int, DeliveryConfirmationData>> ForSeason(DbSet<DeliveryPart> table, int year) {
return (await FromDbSet(table, year))
.GroupBy(

View File

@@ -9,7 +9,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishDir>bin\Publish</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>

View File

@@ -125,6 +125,7 @@ namespace Elwig.Windows {
if (old != null) _branches[old] = id;
branch.ZwstId = id;
branch.Name = BranchNameInput.Text;
branch.CountryNum = 40;
branch.PostalDestId = (BranchOrtInput.SelectedItem as AT_PlzDest)?.Id;
branch.Address = BranchAddressInput.Text;
branch.PhoneNr = BranchPhoneNrInput.Text;

View File

@@ -52,13 +52,13 @@ namespace Elwig.Windows {
var year = (SeasonList.SelectedItem as Season)?.Year;
foreach (var (modid, _) in _mods.Where(m => m.Value == null)) {
Context.Remove(Context.Modifiers.Find(new object?[] { year, modid }));
Context.Remove(Context.Modifiers.Find(year, modid));
}
foreach (var (mod, old) in _modIds) {
mod.ModId = old;
}
foreach (var (old, modid) in _mods.Where(m => m.Value != null)) {
Context.Update(Context.Modifiers.Find(new object?[] { year, old }));
Context.Update(Context.Modifiers.Find(year, old));
}
await Context.SaveChangesAsync();
@@ -102,8 +102,9 @@ namespace Elwig.Windows {
if (_modList == null || SeasonList.SelectedItem is not Season s) return;
_modChanged = true;
var idx = (SeasonModifierList.SelectedIndex != -1) ? SeasonModifierList.SelectedIndex + 1 : _modList.Count;
var item = Context.CreateProxy<Modifier>();
item.Year = s.Year;
var item = new Modifier {
Year = s.Year
};
_modList.Insert(idx, item);
SeasonModifierList.SelectedIndex = idx;
UpdateButtons();

View File

@@ -264,6 +264,8 @@ namespace Elwig.Windows {
ClearInputStates();
FillInputs(App.Client);
LockInputs();
await HintContextChange();
}
private void FillInputs(ClientParameters p) {

View File

@@ -59,24 +59,7 @@ namespace Elwig.Windows {
await RefreshGraphListQuery();
}
private static JsonObject? ParseData(PaymentVar variant) {
try {
return BillingData.ParseJson(variant.Data);
} catch (ArgumentException) {
return null;
}
}
private async Task RefreshGraphListQuery(bool updateSort = false) {
var data = ParseData(PaymentVar);
if (data == null) return;
var curves = BillingData.GetCurves(data, BillingData.CalculationMode.Elwig);
foreach (var (id, curve) in curves) {
GraphEntries.Add(new GraphEntry(id, curve.Mode, curve.Normal, MinOechsle, MaxOechsle));
}
private async Task RefreshGraphListQuery() {
var attrVariants = Context.DeliveryParts
.Where(d => d.Year == Year)
.Select(d => $"{d.SortId}{d.AttrId}")
@@ -85,12 +68,12 @@ namespace Elwig.Windows {
.Union(Context.WineVarieties.Select(v => v.SortId))
.Order()
.ToList();
ControlUtils.RenewItemsSource(AppliedInput, attrVariants, g => (g as GraphEntry)?.Id);
var data = EditBillingData.FromJson(PaymentVar.Data, attrVariants);
GraphEntries.AddRange(data.GetPaymentGraphEntries());
GraphEntries.AddRange(data.GetQualityGraphEntries());
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id);
if (GraphEntries.Count == 1) {
GraphList.SelectedIndex = 0;
}
ControlUtils.RenewItemsSource(AppliedInput, attrVariants, g => g);
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, null, ControlUtils.RenewSourceDefault.IfOnly);
RefreshInputs();
}
@@ -98,7 +81,6 @@ namespace Elwig.Windows {
private string ParseContracts(JsonObject auszahlungsSorten, int num) {
return "";
}
private void RefreshInputs(bool validate = false) {
ResetPlot();

View File

@@ -100,7 +100,8 @@
<LineBreak/>
Filtern nach:<LineBreak/>
<Bold>Sorte</Bold>: z.B. GV, ZW, rr, sa, !gv (ausgenommen GV), ...<LineBreak/>
<Bold>Qualitätsstufe</Bold>: z.B. QUW, kab, ldw, ...<LineBreak/>
<Bold>Rot/Weiß</Bold>: z.B. r, Rot, w, weiß, ...<LineBreak/>
<Bold>Qualitätsstufe</Bold>: z.B. QUW, kab, !ldw (ausgenommen LDW), ...<LineBreak/>
<Bold>Gradation</Bold>: z.B. &gt;73, &lt;15, 17-18, 15-, &gt;17,5, 62-75, ...<LineBreak/>
<Bold>Mitglied</Bold>: z.B. 1234, 987, ...<LineBreak/>
<Bold>Saison</Bold>: z.B. 2020, &gt;2015, 2017-2019, &lt;2005, 2019-, ...<LineBreak/>

View File

@@ -326,6 +326,7 @@ namespace Elwig.Windows {
var filterVar = new List<string>();
var filterNotVar = new List<string>();
var filterQual = new List<string>();
var filterNotQual = new List<string>();
var filterMgNr = new List<int>();
var filterZwst = new List<string>();
var filterAttr = new List<string>();
@@ -346,7 +347,15 @@ namespace Elwig.Windows {
for (int i = 0; i < filter.Count; i++) {
var e = filter[i];
if (e.Length == 2 && var.ContainsKey(e.ToUpper())) {
if (e.ToLower() is "r" or "rot") {
filterVar.AddRange(var.Values.Where(v => v.IsRed).Select(v => v.SortId));
filter.RemoveAt(i--);
filterNames.Add("Rotweinsorten");
} else if (e.ToLower() is "w" or "weiß" or "weiss") {
filterVar.AddRange(var.Values.Where(v => v.IsWhite).Select(v => v.SortId));
filter.RemoveAt(i--);
filterNames.Add("Weißweinsorten");
} else if (e.Length == 2 && var.ContainsKey(e.ToUpper())) {
filterVar.Add(e.ToUpper());
filter.RemoveAt(i--);
filterNames.Add(var[e.ToUpper()].Name);
@@ -358,6 +367,10 @@ namespace Elwig.Windows {
filterQual.Add(e.ToUpper());
filter.RemoveAt(i--);
filterNames.Add(qual[e.ToUpper()].Name);
} else if (e[0] == '!' && qual.ContainsKey(e[1..].ToUpper())) {
filterNotQual.Add(e[1..].ToUpper());
filter.RemoveAt(i--);
filterNames.Add("außer " + qual[e[1..].ToUpper()].Name);
} else if (e.All(char.IsAsciiDigit) && mgnr.TryGetValue(e, out var member)) {
filterMgNr.Add(int.Parse(e));
filter.RemoveAt(i--);
@@ -492,9 +505,10 @@ namespace Elwig.Windows {
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 || !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);
@@ -875,7 +889,7 @@ namespace Elwig.Windows {
p.Acid = (AcidInput.Text == "") ? null : double.Parse(AcidInput.Text);
p.Comment = (PartCommentInput.Text == "") ? null : PartCommentInput.Text;
p.Weight = int.Parse(WeightInput.Text.Replace("\u202f", ""));
p.Weight = int.Parse(WeightInput.Text.Replace(Utils.GroupSeparator, ""));
p.ManualWeighing = ManualWeighingInput.IsChecked ?? false;
p.ScaleId = ScaleId;
p.WeighingId = WeighingId;

View File

@@ -76,7 +76,7 @@ namespace Elwig.Dialogs {
IEnumerable<Member> list = await members.ToListAsync();
var data = await DeliveryConfirmationData.ForSeason(Context.DeliveryParts, Year);
using var doc = Document.Merge(list.Select(m =>
new DeliveryConfirmation(Context, Year, m, data[m.MgNr]) {
new DeliveryConfirmation(Context, Year, m, data.TryGetValue(m.MgNr, out var d) ? d : DeliveryConfirmationData.CreateEmpty(Year, m)) {
//DoubleSided = true
}
));

View File

@@ -259,8 +259,12 @@ namespace Elwig.Windows {
return;
CommitButton.IsEnabled = false;
Mouse.OverrideCursor = Cursors.AppStarting;
var b = new BillingVariant(v.Year, v.AvNr);
await b.Commit();
try {
var b = new BillingVariant(v.Year, v.AvNr);
await b.Commit();
} catch (Exception exc) {
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
Mouse.OverrideCursor = null;
RevertButton.IsEnabled = true;
await App.HintContextChange();
@@ -396,13 +400,13 @@ namespace Elwig.Windows {
return;
}
try {
var json = BillingData.ParseJson(DataInput.Text);
var data = BillingData.FromJson(DataInput.Text);
var origJson = v.Data;
try {
origJson = JsonSerializer.Serialize(BillingData.ParseJson(v.Data));
origJson = JsonSerializer.Serialize(BillingData.FromJson(v.Data).Data);
} catch { }
DataValid = true;
if (JsonSerializer.Serialize(json) != origJson) {
if (JsonSerializer.Serialize(data.Data) != origJson) {
ControlUtils.SetInputChanged(DataInput);
DataChanged = true;
} else {

View File

@@ -86,7 +86,7 @@ namespace Elwig.Windows {
private async void AutoBusinessSharesButton_Click(object sender, RoutedEventArgs evt) {
if (SeasonInput.Value is not int year)
return;
if (App.Client.IsMatzen) {
if (false && App.Client.IsMatzen) {
AutoBusinessSharesButton.IsEnabled = false;
Mouse.OverrideCursor = Cursors.AppStarting;

View File

@@ -60,6 +60,6 @@
<None Include="Files\config.ini" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Heat" Version="4.0.1" />
<PackageReference Include="WixToolset.Heat" Version="4.0.3" />
</ItemGroup>
</Project>
</Project>

View File

@@ -13,7 +13,7 @@
</Target>
<ItemGroup>
<ProjectReference Include="..\Installer\Installer.wixproj" />
<PackageReference Include="WixToolset.Bal.wixext" Version="4.0.1" />
<PackageReference Include="WixToolset.Util.wixext" Version="4.0.1" />
<PackageReference Include="WixToolset.Bal.wixext" Version="4.0.3" />
<PackageReference Include="WixToolset.Util.wixext" Version="4.0.3" />
</ItemGroup>
</Project>
</Project>

View File

@@ -26,14 +26,14 @@ namespace Tests.Helpers {
};
}
private static void TestCalcOe(BillingData data, string bucket, double oe, decimal expected, string? qualid = null, bool geb = false) {
private static void TestCalcOe(PaymentBillingData data, string bucket, double oe, decimal expected, string? qualid = null, bool geb = false) {
var (sortid, attrid) = GetSortIdAttrId(bucket);
var kmw = Utils.OeToKmw(oe);
var v = data.CalculatePrice(sortid, attrid, qualid ?? GetQualId(kmw), geb, oe, kmw);
Assert.That(Math.Round(v, 6), Is.EqualTo(expected));
}
private static void TestCalcKmw(BillingData data, string bucket, double kmw, decimal expected, string? qualid = null, bool geb = false) {
private static void TestCalcKmw(PaymentBillingData data, string bucket, double kmw, decimal expected, string? qualid = null, bool geb = false) {
var (sortid, attrid) = GetSortIdAttrId(bucket);
var oe = Utils.KmwToOe(kmw);
var v = data.CalculatePrice(sortid, attrid, qualid ?? GetQualId(kmw), geb, oe, kmw);
@@ -42,7 +42,7 @@ namespace Tests.Helpers {
[Test]
public void Test_01_Flatrate() {
var data = BillingData.FromJson("""
var data = PaymentBillingData.FromJson("""
{
"mode": "elwig",
"version": 1,
@@ -58,7 +58,7 @@ namespace Tests.Helpers {
[Test]
public void Test_02_Simple() {
var data = BillingData.FromJson("""
var data = PaymentBillingData.FromJson("""
{
"mode": "elwig",
"version": 1,
@@ -93,7 +93,7 @@ namespace Tests.Helpers {
[Test]
public void Test_03_GreaterThanAndLessThan() {
var data = BillingData.FromJson("""
var data = PaymentBillingData.FromJson("""
{
"mode": "elwig",
"version": 1,
@@ -132,7 +132,7 @@ namespace Tests.Helpers {
[Test]
public void Test_04_VariantsAndAttributes() {
var data = BillingData.FromJson("""
var data = PaymentBillingData.FromJson("""
{
"mode": "elwig",
"version": 1,
@@ -162,7 +162,7 @@ namespace Tests.Helpers {
[Test]
public void Test_05_QualityLevel() {
var data = BillingData.FromJson("""
var data = PaymentBillingData.FromJson("""
{
"mode": "elwig",
"version": 1,
@@ -193,7 +193,7 @@ namespace Tests.Helpers {
[Test]
public void Test_06_ModeOeAndKmw() {
var data = BillingData.FromJson("""
var data = PaymentBillingData.FromJson("""
{
"mode": "elwig",
"version": 1,
@@ -235,7 +235,7 @@ namespace Tests.Helpers {
[Test]
public void Test_07_MultipleCurves() {
var data = BillingData.FromJson("""
var data = PaymentBillingData.FromJson("""
{
"mode": "elwig",
"version": 1,
@@ -304,7 +304,7 @@ namespace Tests.Helpers {
[Test]
public void Test_08_WgMaster() {
var data = BillingData.FromJson("""
var data = PaymentBillingData.FromJson("""
{
"mode": "wgmaster",
"Grundbetrag": 0.033,

View File

@@ -18,11 +18,17 @@
</Target>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.10.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>