Elwig: Rename buchführend, funktionär, volllieferant, and gebunden
This commit is contained in:
@@ -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")
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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(), []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -641,10 +641,10 @@ namespace Elwig.Helpers.Export {
|
||||
["ooc_id"] = m.OrganicOperatorId,
|
||||
["org_auth_code"] = m.OrganicAuthorityCode,
|
||||
["juridical_pers"] = m.IsJuridicalPerson,
|
||||
["volllieferant"] = m.IsVollLieferant,
|
||||
["buchführend"] = m.IsBuchführend,
|
||||
["full_delivery"] = m.IsFullDelivery,
|
||||
["accounting"] = m.IsAccounting,
|
||||
["organic"] = m.IsOrganic,
|
||||
["funktionär"] = m.IsFunktionär,
|
||||
["officer"] = m.IsOfficer,
|
||||
["active"] = m.IsActive,
|
||||
["deceased"] = m.IsDeceased,
|
||||
["iban"] = m.Iban,
|
||||
@@ -715,10 +715,10 @@ namespace Elwig.Helpers.Export {
|
||||
OrganicOperatorId = json["ooc_id"]?.AsValue().GetValue<string>(),
|
||||
OrganicAuthorityCode = json["org_auth_code"]?.AsValue().GetValue<string>(),
|
||||
IsJuridicalPerson = json["juridical_pers"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsVollLieferant = json["volllieferant"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsBuchführend = json["buchführend"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsFullDelivery = json["full_delivery"]?.AsValue().GetValue<bool>() ?? json["volllieferant"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsAccounting = json["accounting"]?.AsValue().GetValue<bool>() ?? json["buchführend"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsOrganic = json["organic"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsFunktionär = json["funktionär"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsOfficer = json["officer"]?.AsValue().GetValue<bool>() ?? json["funktionär"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsActive = json["active"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsDeceased = json["deceased"]?.AsValue().GetValue<bool>() ?? false,
|
||||
Iban = json["iban"]?.AsValue().GetValue<string>(),
|
||||
@@ -961,7 +961,7 @@ namespace Elwig.Helpers.Export {
|
||||
};
|
||||
if (p.IsSplCheck) obj["spl_check"] = p.IsSplCheck;
|
||||
if (p.IsHandPicked != null) obj["hand_picked"] = p.IsHandPicked;
|
||||
if (p.IsGebunden != null) obj["gebunden"] = p.IsGebunden;
|
||||
if (p.IsContracted != null) obj["contracted"] = p.IsContracted;
|
||||
if (p.Unloading != null) obj["unloading"] = p.Unloading;
|
||||
if (p.Temperature != null) obj["temperature"] = p.Temperature;
|
||||
if (p.Acid != null) obj["acid"] = p.Acid;
|
||||
@@ -1035,7 +1035,7 @@ namespace Elwig.Helpers.Export {
|
||||
Comment = p["comment"]?.AsValue().GetValue<string>(),
|
||||
IsSplCheck = p["spl_check"]?.AsValue().GetValue<bool>() ?? false,
|
||||
IsHandPicked = p["hand_picked"]?.AsValue().GetValue<bool>(),
|
||||
IsGebunden = p["gebunden"]?.AsValue().GetValue<bool>(),
|
||||
IsContracted = p["contracted"]?.AsValue().GetValue<bool>() ?? p["gebunden"]?.AsValue().GetValue<bool>(),
|
||||
Unloading = p["unloading"]?.AsValue().GetValue<string>() ?? ((p["lesewagen"]?.AsValue().GetValue<bool>() ?? false) ? DeliveryPart.Pumped : null),
|
||||
Temperature = p["temperature"]?.AsValue().GetValue<double>(),
|
||||
Acid = p["acid"]?.AsValue().GetValue<double>(),
|
||||
|
||||
Reference in New Issue
Block a user