BillingData: Implement WG Master parsing
This commit is contained in:
@ -35,7 +35,7 @@ namespace Elwig.Helpers.Billing {
|
||||
Data = data;
|
||||
var mode = Data["mode"]?.GetValue<string>();
|
||||
Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster;
|
||||
Curves = GetCurves(data);
|
||||
Curves = GetCurves(Data, Mode);
|
||||
PaymentData = GetPaymentData(attributeVariants);
|
||||
QualityData = GetQualityData(attributeVariants);
|
||||
}
|
||||
@ -83,9 +83,9 @@ namespace Elwig.Helpers.Billing {
|
||||
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 curves = data["curves"]?.AsArray() ?? throw new InvalidOperationException();
|
||||
var curves = data[mode == CalculationMode.Elwig ? "curves" : "Kurven"]?.AsArray() ?? throw new InvalidOperationException();
|
||||
foreach (var c in curves) {
|
||||
var obj = c?.AsObject() ?? 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) {
|
||||
// TODO parse wgmaster
|
||||
var p = Data["payment"];
|
||||
var p = Data[Mode == CalculationMode.Elwig ? "payment" : "AuszahlungSorten"];
|
||||
if (p is JsonValue val) {
|
||||
var c = LookupCurve(val);
|
||||
return attributeVariants.ToDictionary(e => e, _ => c);
|
||||
@ -155,8 +154,7 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
|
||||
public Dictionary<string, Curve> GetQualityData(IEnumerable<string> attributeVariants) {
|
||||
// TODO parse wgmaster
|
||||
var q = Data["quality"]?.AsObject();
|
||||
var q = Data[Mode == CalculationMode.Elwig ? "quality" : "AuszahlungSortenQualitätsstufe"]?.AsObject();
|
||||
Dictionary<string, Curve> dict = [];
|
||||
if (q == null) return dict;
|
||||
|
||||
|
@ -8,25 +8,45 @@
|
||||
"properties": {
|
||||
"mode": {"enum": ["elwig"]},
|
||||
"version": {"enum": [1]},
|
||||
"payment": {
|
||||
"type": ["number", "string", "object"],
|
||||
"pattern": "^curve:[0-9]+$",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"default": {
|
||||
"type": ["number", "string"],
|
||||
"pattern": "^curve:[0-9]+$"
|
||||
}
|
||||
},
|
||||
"patternProperties": {
|
||||
"^([A-Z]{2})?(\/[A-Z]*)?$": {
|
||||
"type": ["number", "string"],
|
||||
"pattern": "^curve:[0-9]+$"
|
||||
}
|
||||
"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"],
|
||||
"pattern": "^curve:[0-9]+$",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"default": {
|
||||
"type": ["number", "string"],
|
||||
"pattern": "^curve:[0-9]+$"
|
||||
}
|
||||
},
|
||||
"quality": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^([A-Z]{2})?(\/[A-Z]*)?$": {
|
||||
"type": ["number", "string"],
|
||||
"pattern": "^curve:[0-9]+$"
|
||||
}
|
||||
}
|
||||
},
|
||||
"quality_1": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"patternProperties": {
|
||||
"^[A-Z]{3}$": {
|
||||
@ -47,58 +67,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"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": {
|
||||
"type": "object",
|
||||
"required": ["id", "mode", "data"],
|
||||
@ -111,15 +80,15 @@
|
||||
"mode": {"enum": ["oe", "kmw"]},
|
||||
"data": {
|
||||
"anyOf": [
|
||||
{"type": "number" },
|
||||
{"type": "number"},
|
||||
{"$ref": "#/definitions/curve_data"}
|
||||
]
|
||||
]
|
||||
},
|
||||
"geb": {
|
||||
"anyOf": [
|
||||
{"type": "number"},
|
||||
{"$ref": "#/definitions/curve_data"}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -301,5 +301,49 @@ namespace Tests.Helpers {
|
||||
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