BillingData: Implement WG Master parsing
This commit is contained in:
@ -35,7 +35,7 @@ namespace Elwig.Helpers.Billing {
|
|||||||
Data = data;
|
Data = data;
|
||||||
var mode = Data["mode"]?.GetValue<string>();
|
var mode = Data["mode"]?.GetValue<string>();
|
||||||
Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster;
|
Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster;
|
||||||
Curves = GetCurves(data);
|
Curves = GetCurves(Data, Mode);
|
||||||
PaymentData = GetPaymentData(attributeVariants);
|
PaymentData = GetPaymentData(attributeVariants);
|
||||||
QualityData = GetQualityData(attributeVariants);
|
QualityData = GetQualityData(attributeVariants);
|
||||||
}
|
}
|
||||||
@ -83,9 +83,9 @@ namespace Elwig.Helpers.Billing {
|
|||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<int, Curve> GetCurves(JsonObject data) {
|
public static Dictionary<int, Curve> GetCurves(JsonObject data, CalculationMode mode) {
|
||||||
var dict = new Dictionary<int, Curve>();
|
var dict = new Dictionary<int, Curve>();
|
||||||
var curves = data["curves"]?.AsArray() ?? throw new InvalidOperationException();
|
var curves = data[mode == CalculationMode.Elwig ? "curves" : "Kurven"]?.AsArray() ?? throw new InvalidOperationException();
|
||||||
foreach (var c in curves) {
|
foreach (var c in curves) {
|
||||||
var obj = c?.AsObject() ?? throw new InvalidOperationException();
|
var obj = c?.AsObject() ?? throw new InvalidOperationException();
|
||||||
var id = obj["id"]?.GetValue<int>() ?? throw new InvalidOperationException();
|
var id = obj["id"]?.GetValue<int>() ?? throw new InvalidOperationException();
|
||||||
@ -145,8 +145,7 @@ namespace Elwig.Helpers.Billing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, Curve> GetPaymentData(IEnumerable<string> attributeVariants) {
|
public Dictionary<string, Curve> GetPaymentData(IEnumerable<string> attributeVariants) {
|
||||||
// TODO parse wgmaster
|
var p = Data[Mode == CalculationMode.Elwig ? "payment" : "AuszahlungSorten"];
|
||||||
var p = Data["payment"];
|
|
||||||
if (p is JsonValue val) {
|
if (p is JsonValue val) {
|
||||||
var c = LookupCurve(val);
|
var c = LookupCurve(val);
|
||||||
return attributeVariants.ToDictionary(e => e, _ => c);
|
return attributeVariants.ToDictionary(e => e, _ => c);
|
||||||
@ -155,8 +154,7 @@ namespace Elwig.Helpers.Billing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, Curve> GetQualityData(IEnumerable<string> attributeVariants) {
|
public Dictionary<string, Curve> GetQualityData(IEnumerable<string> attributeVariants) {
|
||||||
// TODO parse wgmaster
|
var q = Data[Mode == CalculationMode.Elwig ? "quality" : "AuszahlungSortenQualitätsstufe"]?.AsObject();
|
||||||
var q = Data["quality"]?.AsObject();
|
|
||||||
Dictionary<string, Curve> dict = [];
|
Dictionary<string, Curve> dict = [];
|
||||||
if (q == null) return dict;
|
if (q == null) return dict;
|
||||||
|
|
||||||
|
@ -8,7 +8,27 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"mode": {"enum": ["elwig"]},
|
"mode": {"enum": ["elwig"]},
|
||||||
"version": {"enum": [1]},
|
"version": {"enum": [1]},
|
||||||
"payment": {
|
"payment": {"$ref": "#/definitions/payment_1"},
|
||||||
|
"quality": {"$ref": "#/definitions/quality_1"},
|
||||||
|
"curves": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {"$ref": "#/definitions/curve"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"required": ["AuszahlungSorten", "Kurven"],
|
||||||
|
"properties": {
|
||||||
|
"mode": {"enum": ["wgmaster"]},
|
||||||
|
"AuszahlungSorten": {"$ref": "#/definitions/payment_1"},
|
||||||
|
"AuszahlungSortenQualitätsstufe": {"$ref": "#/definitions/quality_1"},
|
||||||
|
"Kurven": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {"$ref": "#/definitions/curve"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"definitions": {
|
||||||
|
"payment_1": {
|
||||||
"type": ["number", "string", "object"],
|
"type": ["number", "string", "object"],
|
||||||
"pattern": "^curve:[0-9]+$",
|
"pattern": "^curve:[0-9]+$",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
@ -25,7 +45,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"quality": {
|
"quality_1": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"patternProperties": {
|
"patternProperties": {
|
||||||
@ -48,57 +68,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"curves": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {"$ref": "#/definitions/curve"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
"properties": {
|
|
||||||
"mode": {"enum": ["wgmaster"]},
|
|
||||||
"AuszahlungSorten": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": false,
|
|
||||||
"required": ["Kurven"],
|
|
||||||
"properties": {
|
|
||||||
"Kurven": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": false,
|
|
||||||
"minProperties": 1,
|
|
||||||
"patternProperties": {
|
|
||||||
"^[0-9]+(\\.[0-9]+)?oe$": {"type": "number"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"patternProperties": {
|
|
||||||
"^[A-Z]{2}$": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": false,
|
|
||||||
"patternProperties": {
|
|
||||||
"^[A-Z]*$": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": false,
|
|
||||||
"properties": {
|
|
||||||
"Gebunden": {
|
|
||||||
"type": "integer",
|
|
||||||
"minimum": 0
|
|
||||||
},
|
|
||||||
"NichtGebunden": {
|
|
||||||
"type": "integer",
|
|
||||||
"minimum": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
"definitions": {
|
|
||||||
"curve": {
|
"curve": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["id", "mode", "data"],
|
"required": ["id", "mode", "data"],
|
||||||
@ -111,7 +80,7 @@
|
|||||||
"mode": {"enum": ["oe", "kmw"]},
|
"mode": {"enum": ["oe", "kmw"]},
|
||||||
"data": {
|
"data": {
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{"type": "number" },
|
{"type": "number"},
|
||||||
{"$ref": "#/definitions/curve_data"}
|
{"$ref": "#/definitions/curve_data"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -301,5 +301,49 @@ namespace Tests.Helpers {
|
|||||||
TestCalcKmw(data, "WRS", 17.0, 0.95m, geb: true);
|
TestCalcKmw(data, "WRS", 17.0, 0.95m, geb: true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_08_WgMaster() {
|
||||||
|
var data = BillingData.FromJson("""
|
||||||
|
{
|
||||||
|
"mode": "wgmaster",
|
||||||
|
"Grundbetrag": 0.033,
|
||||||
|
"GBZS": 0.0,
|
||||||
|
"Ausgabefaktor": 1.0,
|
||||||
|
"Rebelzuschlag": 0.0,
|
||||||
|
"AufschlagVolllieferanten": 0.0,
|
||||||
|
"AuszahlungSorten": {
|
||||||
|
"BL/": 0.097,
|
||||||
|
"BP/": 0.097,
|
||||||
|
"GV/K": "curve:1",
|
||||||
|
"SL/": 0.097,
|
||||||
|
"ZW/": 0.097,
|
||||||
|
"default": "curve:0"
|
||||||
|
},
|
||||||
|
"AuszahlungSortenQualitätsstufe": {
|
||||||
|
"WEI": 0.005
|
||||||
|
},
|
||||||
|
"Kurven": [{
|
||||||
|
"id": 0,
|
||||||
|
"mode": "oe",
|
||||||
|
"data": 0.033,
|
||||||
|
"geb": 0
|
||||||
|
}, {
|
||||||
|
"id": 1,
|
||||||
|
"mode": "oe",
|
||||||
|
"data": {
|
||||||
|
"88oe": 0.032,
|
||||||
|
"89oe": 0.065
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
""", AttributeVariants);
|
||||||
|
Assert.Multiple(() => {
|
||||||
|
TestCalcOe(data, "GVK", 73, 0.032m);
|
||||||
|
TestCalcOe(data, "ZWS", 74, 0.033m);
|
||||||
|
TestCalcOe(data, "GV", 75, 0.005m, qualid: "WEI");
|
||||||
|
TestCalcOe(data, "GVK", 115, 0.065m);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user