PaymentVariantsWindow: Add possibility to switch options on/off
This commit is contained in:
@ -23,12 +23,44 @@ namespace Elwig.Helpers.Billing {
|
||||
Schema = await JsonSchema.FromJsonAsync(stream ?? throw new ArgumentException("JSON schema not found"));
|
||||
}
|
||||
|
||||
public readonly JsonObject Data;
|
||||
|
||||
private readonly CalculationMode Mode;
|
||||
private readonly JsonObject Data;
|
||||
private readonly Dictionary<int, Curve> Curves;
|
||||
private readonly Dictionary<string, Curve> PaymentData;
|
||||
private readonly Dictionary<string, Curve> QualityData;
|
||||
|
||||
public bool ConsiderDelieryModifiers {
|
||||
get => GetConsider("consider_delivery_modifiers");
|
||||
set => SetConsider(value, "consider_delivery_modifiers");
|
||||
}
|
||||
public bool ConsiderContractPenalties {
|
||||
get => GetConsider("consider_contract_penalties");
|
||||
set => SetConsider(value, "consider_contract_penalties");
|
||||
}
|
||||
public bool ConsiderTotalPenalty {
|
||||
get => GetConsider("consider_total_penalty");
|
||||
set => SetConsider(value, "consider_total_penalty");
|
||||
}
|
||||
public bool ConsiderAutoBusinessShares {
|
||||
get => GetConsider("consider_auto_business_shares");
|
||||
set => SetConsider(value, "consider_total_penalty");
|
||||
}
|
||||
|
||||
private bool GetConsider(string name, string? wgMasterName = null) {
|
||||
return ((Mode == CalculationMode.Elwig) ? Data[name] : Data[wgMasterName ?? ""])?.AsValue().GetValue<bool>() ?? false;
|
||||
}
|
||||
|
||||
private void SetConsider(bool value, string name, string? wgMasterName = null) {
|
||||
if (Mode == CalculationMode.WgMaster && wgMasterName == null) {
|
||||
return;
|
||||
} else if (value) {
|
||||
Data[(Mode == CalculationMode.Elwig) ? name : wgMasterName ?? ""] = value;
|
||||
} else {
|
||||
Data.Remove((Mode == CalculationMode.Elwig) ? name : wgMasterName ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
public BillingData(JsonObject data, IEnumerable<string> attributeVariants) {
|
||||
if (attributeVariants.Any(e => e.Any(c => c < 'A' || c > 'Z')))
|
||||
throw new ArgumentException("Invalid attributeVariants");
|
||||
@ -51,6 +83,10 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
|
||||
public static BillingData FromJson(string json) {
|
||||
return FromJson(json, []);
|
||||
}
|
||||
|
||||
public static BillingData FromJson(string json, IEnumerable<string> attributeVariants) {
|
||||
return new(ParseJson(json), attributeVariants);
|
||||
}
|
||||
|
Reference in New Issue
Block a user