Billing: Fixes
This commit is contained in:
@ -258,7 +258,7 @@ namespace Elwig.Helpers.Billing {
|
||||
return curve;
|
||||
}
|
||||
|
||||
protected static void CollapsePaymentData(JsonObject data) {
|
||||
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) {
|
||||
@ -274,18 +274,18 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
if (!data.ContainsKey("default")) {
|
||||
foreach (var (v, ks) in rev1) {
|
||||
if (ks.Count >= data.Count / 2.0) {
|
||||
if (ks.Count >= attributeVariants.Count() / 2.0) {
|
||||
foreach (var k in ks) data.Remove(k);
|
||||
data["default"] = v;
|
||||
CollapsePaymentData(data);
|
||||
CollapsePaymentData(data, attributeVariants);
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach (var (v, ks) in rev2) {
|
||||
if (ks.Count >= data.Count / 2.0) {
|
||||
if (ks.Count >= attributeVariants.Count() / 2.0) {
|
||||
foreach (var k in ks) data.Remove(k);
|
||||
data["default"] = v;
|
||||
CollapsePaymentData(data);
|
||||
CollapsePaymentData(data, attributeVariants);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -297,7 +297,7 @@ namespace Elwig.Helpers.Billing {
|
||||
.Distinct()
|
||||
.ToList();
|
||||
foreach (var idx in attributes) {
|
||||
var len = data.Count(e => e.Key.EndsWith(idx));
|
||||
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) {
|
||||
@ -315,7 +315,7 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonObject FromGraphEntries(IEnumerable<GraphEntry> graphEntries, BillingData? origData = null) {
|
||||
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();
|
||||
@ -341,8 +341,8 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
|
||||
CollapsePaymentData(payment);
|
||||
CollapsePaymentData(qualityWei);
|
||||
CollapsePaymentData(payment, attributeVariants ?? payment.Select(e => e.Key).ToList());
|
||||
CollapsePaymentData(qualityWei, attributeVariants ?? qualityWei.Select(e => e.Key).ToList());
|
||||
|
||||
var data = new JsonObject {
|
||||
["mode"] = "elwig",
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
public async Task Calculate() {
|
||||
|
@ -1,7 +1,5 @@
|
||||
using Elwig.Models.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class ContractSelection : IComparable<ContractSelection> {
|
||||
@ -16,18 +14,6 @@ namespace Elwig.Helpers.Billing {
|
||||
Attribute = attr;
|
||||
}
|
||||
|
||||
public static List<ContractSelection> GetContractsForYear(AppDbContext context, int year) {
|
||||
return context.DeliveryParts
|
||||
.Where(p => p.Year == year)
|
||||
.Select(d => new ContractSelection(d.Variant, d.Attribute))
|
||||
.Distinct()
|
||||
.ToList()
|
||||
.Union(context.WineVarieties.Select(v => new ContractSelection(v, null)))
|
||||
.DistinctBy(c => c.Listing)
|
||||
.Order()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return Listing;
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ namespace Elwig.Helpers.Billing {
|
||||
if (!dict1.ContainsKey(idx)) dict1[idx] = [];
|
||||
dict1[idx].Add("default");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var virtOffset = dict1.Count > 0 ? dict1.Max(e => e.Key) + 1 : 1;
|
||||
@ -98,15 +97,21 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
} else if (q is JsonValue qualityVal) {
|
||||
var idx = qualityVal.GetValue<decimal>();
|
||||
if (!dict2.ContainsKey(idx)) dict2[idx] = [];
|
||||
dict2[idx].Add($"{qualid}/");
|
||||
if (qualityVal.TryGetValue<decimal>(out var price)) {
|
||||
if (!dict2.ContainsKey(price)) dict2[price] = [];
|
||||
dict2[price].Add("default");
|
||||
} else if (qualityVal.TryGetValue<string>(out var curve)) {
|
||||
var idx = int.Parse(curve.Split(":")[1] ?? "0");
|
||||
if (!dict1.ContainsKey(idx)) dict1[idx] = [];
|
||||
dict1[idx].Add("default");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
List<GraphEntry> list = [];
|
||||
// set abgewertet = true
|
||||
|
||||
return list;
|
||||
}
|
||||
|
@ -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,27 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
return output.OrderByDescending(l => l.Count());
|
||||
}
|
||||
|
||||
public static List<string> GetAttributeVarieties(AppDbContext ctx, int year, bool withSlash = false) {
|
||||
return ctx.DeliveryParts
|
||||
.Where(d => d.Year == year)
|
||||
.Select(d => $"{d.SortId}{(withSlash ? "/" : "")}{d.AttrId}")
|
||||
.Distinct()
|
||||
.ToList()
|
||||
.Union(ctx.WineVarieties.Select(v => v.SortId))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static List<ContractSelection> GetContractsForYear(AppDbContext ctx, int year) {
|
||||
return ctx.DeliveryParts
|
||||
.Where(p => p.Year == year)
|
||||
.Select(d => new ContractSelection(d.Variant, d.Attribute))
|
||||
.Distinct()
|
||||
.ToList()
|
||||
.Union(ctx.WineVarieties.Select(v => new ContractSelection(v, null)))
|
||||
.DistinctBy(c => c.Listing)
|
||||
.Order()
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ using ScottPlot.Plottables;
|
||||
using ScottPlot;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
using ScottPlot.Control;
|
||||
using LinqKit;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class ChartWindow : ContextWindow {
|
||||
@ -85,18 +86,13 @@ namespace Elwig.Windows {
|
||||
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");
|
||||
|
||||
var attrVariants = (await Context.DeliveryParts
|
||||
.Where(d => d.Year == Year)
|
||||
.Select(d => $"{d.SortId}{d.AttrId}")
|
||||
.Distinct()
|
||||
.ToListAsync())
|
||||
.Union(Context.WineVarieties.Select(v => v.SortId))
|
||||
.Order()
|
||||
.ToList();
|
||||
var data = EditBillingData.FromJson(PaymentVar.Data, attrVariants);
|
||||
GraphEntries = [ ..data.GetPaymentGraphEntries(Context, Season), ..data.GetQualityGraphEntries(Context, Season)];
|
||||
var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetAttributeVarieties(Context, Year));
|
||||
GraphEntries = [
|
||||
..data.GetPaymentGraphEntries(Context, Season),
|
||||
..data.GetQualityGraphEntries(Context, Season)
|
||||
];
|
||||
|
||||
var contracts = ContractSelection.GetContractsForYear(Context, Year);
|
||||
var contracts = Utils.GetContractsForYear(Context, Year);
|
||||
FillingInputs = true;
|
||||
ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.Listing);
|
||||
FillingInputs = false;
|
||||
@ -638,7 +634,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void SaveButton_Click(object sender, RoutedEventArgs e) {
|
||||
var origData = BillingData.FromJson(PaymentVar.Data);
|
||||
var data = BillingData.FromGraphEntries(GraphEntries, origData);
|
||||
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetAttributeVarieties(Context, Year, true));
|
||||
|
||||
EntityEntry<PaymentVar>? tr = null;
|
||||
try {
|
||||
|
Reference in New Issue
Block a user