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.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -92,6 +93,14 @@ namespace Elwig.Helpers.Billing {
|
|||||||
Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster;
|
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) {
|
protected static JsonObject ParseJson(string json) {
|
||||||
if (Schema == null) throw new InvalidOperationException("Schema has to be initialized first");
|
if (Schema == null) throw new InvalidOperationException("Schema has to be initialized first");
|
||||||
try {
|
try {
|
||||||
@@ -107,6 +116,10 @@ namespace Elwig.Helpers.Billing {
|
|||||||
return new(ParseJson(json));
|
return new(ParseJson(json));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ToJsonString(JsonSerializerOptions? options = null) {
|
||||||
|
return Data.ToJsonString(options);
|
||||||
|
}
|
||||||
|
|
||||||
protected JsonArray GetCurvesEntry() {
|
protected JsonArray GetCurvesEntry() {
|
||||||
return Data[Mode == CalculationMode.Elwig ? "curves" : "Kurven"]?.AsArray() ?? throw new InvalidOperationException();
|
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,
|
IEnumerable<GraphEntry> graphEntries,
|
||||||
BillingData? origData = null,
|
BillingData? origData = null,
|
||||||
IEnumerable<RawVaribute>? vaributes = 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(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);
|
CollapsePaymentData(qualityWei, qualityWei.DeepClone().AsObject(), vaributes ?? qualityWei.Select(e => new RawVaribute(e.Key)).ToList(), useDefaultQuality);
|
||||||
|
|
||||||
var data = new JsonObject {
|
BillingData data;
|
||||||
["mode"] = "elwig",
|
if (origData != null && origData.Mode == CalculationMode.Elwig) {
|
||||||
["version"] = 1,
|
data = new BillingData((JsonObject)origData.Data.DeepClone());
|
||||||
};
|
} else {
|
||||||
|
data = new BillingData();
|
||||||
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;
|
|
||||||
|
|
||||||
if (payment.Count == 0) {
|
if (payment.Count == 0) {
|
||||||
data["payment"] = 0;
|
data.Data["payment"] = 0;
|
||||||
} else if (payment.Count == 1 && payment.First().Key == "default") {
|
} else if (payment.Count == 1 && payment.First().Key == "default") {
|
||||||
data["payment"] = payment.Single().Value?.DeepClone();
|
data.Data["payment"] = payment.Single().Value?.DeepClone();
|
||||||
} else {
|
} else {
|
||||||
data["payment"] = payment;
|
data.Data["payment"] = payment;
|
||||||
}
|
}
|
||||||
if (qualityWei.Count == 1 && qualityWei.First().Key == "default") {
|
if (qualityWei.Count == 1 && qualityWei.First().Key == "default") {
|
||||||
data["quality"] = new JsonObject() {
|
data.Data["quality"] = new JsonObject() {
|
||||||
["WEI"] = qualityWei.Single().Value?.DeepClone()
|
["WEI"] = qualityWei.Single().Value?.DeepClone()
|
||||||
};
|
};
|
||||||
} else if (qualityWei.Count >= 1) {
|
} else if (qualityWei.Count >= 1) {
|
||||||
data["quality"] = new JsonObject() {
|
data.Data["quality"] = new JsonObject() {
|
||||||
["WEI"] = qualityWei
|
["WEI"] = qualityWei
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
data["curves"] = curves;
|
data.Data["curves"] = curves;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user