Elwig: Rename buchführend, funktionär, volllieferant, and gebunden

This commit is contained in:
2026-09-30 12:14:25 +02:00
parent 4988081bfd
commit 5f2788eb9e
40 changed files with 393 additions and 355 deletions
+6 -6
View File
@@ -77,13 +77,13 @@ namespace Elwig.Helpers.Billing {
}
public async Task CalculateBuckets(
bool? honorGebundenField = null,
bool? honorContractedField = null,
bool? allowAttributesIntoLower = null,
bool? avoidUnderDeliveries = null,
SqliteConnection? cnx = null
) {
using var ctx = new AppDbContext();
var honorGebunden = honorGebundenField ?? Season.Billing_HonorGebunden;
var honorContracted = honorContractedField ?? Season.Billing_HonorContracted;
var allowAttrsIntoLower = allowAttributesIntoLower ?? Season.Billing_AllowAttrsIntoLower;
var avoidUnderDlvrs = avoidUnderDeliveries ?? Season.Billing_AvoidUnderDeliveries;
var attrVals = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => (a.IsStrict, a.FillLower));
@@ -96,10 +96,10 @@ namespace Elwig.Helpers.Billing {
var deliveries = new List<(int, int, int, string, int, double, string, string?, string[], bool?)>();
using (var cmd = cnx.CreateCommand()) {
cmd.CommandText = $"""
SELECT mgnr, did, dpnr, sortid, weight, kmw, qualid, attrid, modifiers, gebunden
SELECT mgnr, did, dpnr, sortid, weight, kmw, qualid, attrid, modifiers, contracted
FROM v_delivery
WHERE year = {Year}
ORDER BY mgnr, sortid, abgewertet ASC, {(honorGebunden ? "gebunden IS NOT NULL DESC, gebunden DESC," : "")}
ORDER BY mgnr, sortid, abgewertet ASC, {(honorContracted ? "contracted IS NOT NULL DESC, contracted DESC," : "")}
attribute_prio DESC, COALESCE(attrid, '~'), kmw DESC, lsnr, dpnr
""";
using var reader = await cmd.ExecuteReaderAsync();
@@ -117,12 +117,12 @@ namespace Elwig.Helpers.Billing {
int lastMgNr = 0;
Dictionary<string, AreaComBucket>? rightsAndObligations = null;
Dictionary<string, int> used = [];
foreach (var (mgnr, did, dpnr, sortid, weight, kmw, qualid, attrid, modifiers, gebunden) in deliveries) {
foreach (var (mgnr, did, dpnr, sortid, weight, kmw, qualid, attrid, modifiers, contracted) in deliveries) {
if (lastMgNr != mgnr) {
rightsAndObligations = await ctx.GetMemberAreaCommitmentBuckets(Year, mgnr);
used = [];
}
if ((honorGebunden && gebunden == false) ||
if ((honorContracted && contracted == false) ||
rightsAndObligations == null || rightsAndObligations.Count == 0 ||
qualid == "WEI" || qualid == "RSW" || qualid == "LDW")
{
+10 -10
View File
@@ -14,7 +14,7 @@ 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 record struct Curve(CurveMode Mode, Dictionary<double, decimal> Normal, Dictionary<double, decimal>? Contracted);
public static JsonSchema? Schema { get; private set; }
@@ -179,10 +179,10 @@ namespace Elwig.Helpers.Billing {
} else {
throw new InvalidOperationException();
}
var geb = obj["geb"];
if (geb is JsonObject) {
c2 = GetCurveData(geb.AsObject(), cMode);
} else if (geb?.AsValue().TryGetValue(out decimal v) == true) {
var ctrd = obj["ctrd"] ?? obj["geb"];
if (ctrd is JsonObject) {
c2 = GetCurveData(ctrd.AsObject(), cMode);
} else if (ctrd?.AsValue().TryGetValue(out decimal v) == true) {
var splitVal = GetCurveValueAt(c1, quw);
c2 = c1.ToDictionary(e => e.Key, e => e.Value + (e.Key >= quw ? v : 0));
c2[quw] = splitVal + v;
@@ -274,7 +274,7 @@ namespace Elwig.Helpers.Billing {
protected static JsonNode GraphEntryToJson(GraphEntry entry) {
try {
if (entry.GebundenFlatBonus == null) {
if (entry.ContractedFlatBonus == null) {
return JsonValue.Create((decimal)entry.DataGraph.DataY.Distinct().Single());
}
} catch { }
@@ -286,10 +286,10 @@ namespace Elwig.Helpers.Billing {
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());
if (entry.ContractedFlatBonus != null) {
curve["ctrd"] = (decimal)entry.ContractedFlatBonus;
} else if (entry.ContractedGraph != null) {
curve["ctrd"] = GraphToJson(entry.ContractedGraph, entry.Mode.ToString().ToLower());
}
return curve;
+6 -6
View File
@@ -37,11 +37,11 @@ namespace Elwig.Helpers.Billing {
return new BillingVariant(year, avnr, season, attributes, modifiers, areaComTypes, paymentVar, data);
}
public async Task Calculate(bool strictPrices = true, bool? honorGebunden = null, bool? allowAttrsIntoLower = null, bool? avoidUnderDeliveries = null) {
public async Task Calculate(bool strictPrices = true, bool? honorContracted = null, bool? allowAttrsIntoLower = null, bool? avoidUnderDeliveries = null) {
if (PaymentVariant == null || Data == null) throw new Exception("Call Load before Calculate");
using var cnx = await AppDbContext.ConnectAsync();
using var tx = await cnx.BeginTransactionAsync();
await CalculateBuckets(honorGebunden, allowAttrsIntoLower, avoidUnderDeliveries, cnx);
await CalculateBuckets(honorContracted, allowAttrsIntoLower, avoidUnderDeliveries, cnx);
await DeleteInDb(cnx);
await SetCalcTime(cnx);
KeyNotFoundException? exception = null;
@@ -73,7 +73,7 @@ namespace Elwig.Helpers.Billing {
v.avnr,
ROUND(p.amount / POW(10, s.precision - 2)) AS net_amount,
IIF(lc.amount < 0, 0, ROUND(lp.amount / POW(10, s.precision - 2))) AS prev_net_amount,
IIF(m.buchführend, s.vat_normal, s.vat_flatrate) AS vat,
IIF(m.accounting, s.vat_normal, s.vat_flatrate) AS vat,
ROUND(IIF({Data.ConsiderTotalPenalty}, COALESCE(b.total_penalty, 0), 0) / POW(10, s.precision - 2)) +
ROUND(IIF({Data.ConsiderContractPenalties}, COALESCE(u.total_penalty, 0), 0) / POW(10, 4 - 2)) +
ROUND(IIF({Data.ConsiderAutoBusinessShares}, -COALESCE(a.total_amount, 0), 0)) +
@@ -195,13 +195,13 @@ namespace Elwig.Helpers.Billing {
foreach (var part in parts) {
if (part.Value == 0)
continue;
var ungeb = part.Discr == "_";
var unctrd = part.Discr == "_";
var payAttrId = (part.Discr is "" or "_") ? null : part.Discr;
var attrId = part.AttrAreaCom ? payAttrId : part.AttrId;
var geb = !ungeb && (payAttrId == attrId || !part.AttrAreaCom);
var ctrd = !unctrd && (payAttrId == attrId || !part.AttrAreaCom);
decimal price = 0;
try {
price = Data.CalculatePrice(part.SortId, attrId, part.CultId, part.QualId, geb, part.Oe, part.Kmw);
price = Data.CalculatePrice(part.SortId, attrId, part.CultId, part.QualId, ctrd, part.Oe, part.Kmw);
} catch (KeyNotFoundException e) {
invalid.Add(e.Message.Split('\'')[1]);
}
+17 -17
View File
@@ -7,7 +7,7 @@ namespace Elwig.Helpers.Billing {
public class GraphEntry {
public const int MinX = 50;
public const int MinXGeb = 73;
public const int MinXCtrd = 73;
public const int MaxX = 120;
public int Id { get; set; }
@@ -15,11 +15,11 @@ namespace Elwig.Helpers.Billing {
public bool Abgewertet { get; set; }
public Graph DataGraph { get; set; }
public Graph? GebundenGraph { get; set; }
public double? GebundenFlatBonus {
public Graph? ContractedGraph { get; set; }
public double? ContractedFlatBonus {
get {
try {
var val = GebundenGraph?.DataX.Zip(GebundenGraph.DataY)
var val = ContractedGraph?.DataX.Zip(ContractedGraph.DataY)
.Select(e => Math.Round(e.Second - DataGraph.GetPriceAtOe(e.First), Precision))
.Distinct()
.Single();
@@ -30,10 +30,10 @@ namespace Elwig.Helpers.Billing {
}
set {
if (value is not double v) return;
var values = Enumerable.Range(MinXGeb, MaxX - MinXGeb + 1)
var values = Enumerable.Range(MinXCtrd, MaxX - MinXCtrd + 1)
.Select(i => Math.Round(DataGraph.GetPriceAtOe(i) + v, Precision))
.ToArray();
GebundenGraph = new Graph(values, Precision, MinXGeb, MaxX);
ContractedGraph = new Graph(values, Precision, MinXCtrd, MaxX);
}
}
@@ -52,39 +52,39 @@ namespace Elwig.Helpers.Billing {
Vaributes = [];
}
public GraphEntry(int id, int precision, BillingData.CurveMode mode, Dictionary<double, decimal> data, Dictionary<double, decimal>? gebunden) :
public GraphEntry(int id, int precision, BillingData.CurveMode mode, Dictionary<double, decimal> data, Dictionary<double, decimal>? contracted) :
this(id, precision, mode) {
DataGraph = new Graph(data, precision, MinX, MaxX);
if (gebunden != null) GebundenGraph = new Graph(gebunden, precision, MinXGeb, MaxX);
if (contracted != null) ContractedGraph = new Graph(contracted, precision, MinXCtrd, MaxX);
}
public GraphEntry(int id, int precision, BillingData.Curve curve, List<Varibute> vaributes) :
this(id, precision, curve.Mode) {
DataGraph = new Graph(curve.Normal, precision, MinX, MaxX);
if (curve.Gebunden != null)
GebundenGraph = new Graph(curve.Gebunden, precision, MinXGeb, MaxX);
if (curve.Contracted != null)
ContractedGraph = new Graph(curve.Contracted, precision, MinXCtrd, MaxX);
Vaributes = vaributes;
}
private GraphEntry(int id, int precision, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph, List<Varibute> vaributes) {
private GraphEntry(int id, int precision, BillingData.CurveMode mode, Graph dataGraph, Graph? contractedGraph, List<Varibute> vaributes) {
Id = id;
Precision = precision;
Mode = mode;
DataGraph = dataGraph;
GebundenGraph = gebundenGraph;
ContractedGraph = contractedGraph;
Vaributes = vaributes;
}
public void AddGebundenGraph() {
GebundenGraph ??= new Graph(Precision, MinXGeb, MaxX);
public void AddContractedGraph() {
ContractedGraph ??= new Graph(Precision, MinXCtrd, MaxX);
}
public void RemoveGebundenGraph() {
GebundenGraph = null;
public void RemoveContractedGraph() {
ContractedGraph = null;
}
public GraphEntry Copy(int id) {
return new GraphEntry(id, Precision, Mode, (Graph)DataGraph.Clone(), (Graph?)GebundenGraph?.Clone(), []);
return new GraphEntry(id, Precision, Mode, (Graph)DataGraph.Clone(), (Graph?)ContractedGraph?.Clone(), []);
}
}
}
+2 -2
View File
@@ -45,9 +45,9 @@ namespace Elwig.Helpers.Billing {
return dict;
}
public decimal CalculatePrice(string sortid, string? attrid, string? cultid, string qualid, bool gebunden, double oe, double kmw) {
public decimal CalculatePrice(string sortid, string? attrid, string? cultid, string qualid, bool contracted, double oe, double kmw) {
var curve = GetQualityCurve(qualid, sortid, attrid, cultid) ?? GetCurve(sortid, attrid, cultid);
return GetCurveValueAt((gebunden ? curve.Gebunden : null) ?? curve.Normal, curve.Mode == CurveMode.Oe ? oe : kmw);
return GetCurveValueAt((contracted ? curve.Contracted : null) ?? curve.Normal, curve.Mode == CurveMode.Oe ? oe : kmw);
}
private Curve LookupCurve(JsonValue val) {