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