BillingData: Preserve all settings when using FromGraphEntries()
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -92,6 +93,14 @@ namespace Elwig.Helpers.Billing {
|
||||
Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster;
|
||||
}
|
||||
|
||||
public BillingData() {
|
||||
Data = new JsonObject {
|
||||
["mode"] = "elwig",
|
||||
["version"] = 1,
|
||||
};
|
||||
Mode = CalculationMode.Elwig;
|
||||
}
|
||||
|
||||
protected static JsonObject ParseJson(string json) {
|
||||
if (Schema == null) throw new InvalidOperationException("Schema has to be initialized first");
|
||||
try {
|
||||
@@ -107,6 +116,10 @@ namespace Elwig.Helpers.Billing {
|
||||
return new(ParseJson(json));
|
||||
}
|
||||
|
||||
public string ToJsonString(JsonSerializerOptions? options = null) {
|
||||
return Data.ToJsonString(options);
|
||||
}
|
||||
|
||||
protected JsonArray GetCurvesEntry() {
|
||||
return Data[Mode == CalculationMode.Elwig ? "curves" : "Kurven"]?.AsArray() ?? throw new InvalidOperationException();
|
||||
}
|
||||
@@ -412,7 +425,7 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonObject FromGraphEntries(
|
||||
public static BillingData FromGraphEntries(
|
||||
IEnumerable<GraphEntry> graphEntries,
|
||||
BillingData? origData = null,
|
||||
IEnumerable<RawVaribute>? vaributes = null,
|
||||
@@ -449,37 +462,30 @@ namespace Elwig.Helpers.Billing {
|
||||
CollapsePaymentData(payment, payment.DeepClone().AsObject(), vaributes ?? payment.Select(e => new RawVaribute(e.Key)).ToList(), useDefaultPayment);
|
||||
CollapsePaymentData(qualityWei, qualityWei.DeepClone().AsObject(), vaributes ?? qualityWei.Select(e => new RawVaribute(e.Key)).ToList(), useDefaultQuality);
|
||||
|
||||
var data = new JsonObject {
|
||||
["mode"] = "elwig",
|
||||
["version"] = 1,
|
||||
};
|
||||
|
||||
if (origData?.ConsiderDelieryModifiers == true)
|
||||
data["consider_delivery_modifiers"] = true;
|
||||
if (origData?.ConsiderContractPenalties == true)
|
||||
data["consider_contract_penalties"] = true;
|
||||
if (origData?.ConsiderTotalPenalty == true)
|
||||
data["consider_total_penalty"] = true;
|
||||
if (origData?.ConsiderAutoBusinessShares == true)
|
||||
data["consider_auto_business_shares"] = true;
|
||||
BillingData data;
|
||||
if (origData != null && origData.Mode == CalculationMode.Elwig) {
|
||||
data = new BillingData((JsonObject)origData.Data.DeepClone());
|
||||
} else {
|
||||
data = new BillingData();
|
||||
}
|
||||
|
||||
if (payment.Count == 0) {
|
||||
data["payment"] = 0;
|
||||
data.Data["payment"] = 0;
|
||||
} else if (payment.Count == 1 && payment.First().Key == "default") {
|
||||
data["payment"] = payment.Single().Value?.DeepClone();
|
||||
data.Data["payment"] = payment.Single().Value?.DeepClone();
|
||||
} else {
|
||||
data["payment"] = payment;
|
||||
data.Data["payment"] = payment;
|
||||
}
|
||||
if (qualityWei.Count == 1 && qualityWei.First().Key == "default") {
|
||||
data["quality"] = new JsonObject() {
|
||||
data.Data["quality"] = new JsonObject() {
|
||||
["WEI"] = qualityWei.Single().Value?.DeepClone()
|
||||
};
|
||||
} else if (qualityWei.Count >= 1) {
|
||||
data["quality"] = new JsonObject() {
|
||||
data.Data["quality"] = new JsonObject() {
|
||||
["WEI"] = qualityWei
|
||||
};
|
||||
}
|
||||
data["curves"] = curves;
|
||||
data.Data["curves"] = curves;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user