[#40] Billing: Add Rebelzuschlag

This commit is contained in:
2024-03-09 20:24:49 +01:00
parent 34ebc8fa34
commit dc83e64db6
9 changed files with 130 additions and 16 deletions

View File

@ -20,6 +20,7 @@ namespace Elwig.Windows {
public readonly bool SeasonLocked;
private bool DataValid, DataChanged, NameChanged, CommentChanged, TransferDateValid, TransferDateChanged;
private BillingData? BillingData;
private bool WeightModifierChanged = false;
private static readonly JsonSerializerOptions JsonOpt = new() { WriteIndented = true };
@ -70,6 +71,13 @@ namespace Elwig.Windows {
ConsiderPenaltiesInput.IsChecked = BillingData.ConsiderContractPenalties;
ConsiderPenaltyInput.IsChecked = BillingData.ConsiderTotalPenalty;
ConsiderAutoInput.IsChecked = BillingData.ConsiderAutoBusinessShares;
if (BillingData.NetWeightModifier != 0) {
WeightModifierInput.Text = $"{Math.Round(BillingData.NetWeightModifier * 100.0, 8)}";
} else if (BillingData.GrossWeightModifier != 0) {
WeightModifierInput.Text = $"{Math.Round(BillingData.GrossWeightModifier * 100.0, 8)}";
} else {
WeightModifierInput.Text = "";
}
DataInput.Text = JsonSerializer.Serialize(BillingData.Data, JsonOpt);
} catch {
BillingData = null;
@ -77,8 +85,10 @@ namespace Elwig.Windows {
ConsiderPenaltiesInput.IsChecked = false;
ConsiderPenaltyInput.IsChecked = false;
ConsiderAutoInput.IsChecked = false;
WeightModifierInput.Text = "";
DataInput.Text = v.Data;
}
WeightModifierInput.TextBox.IsReadOnly = false;
ConsiderModifiersInput.IsEnabled = !locked;
ConsiderPenaltiesInput.IsEnabled = !locked;
ConsiderPenaltyInput.IsEnabled = !locked;
@ -109,6 +119,8 @@ namespace Elwig.Windows {
DateInput.IsReadOnly = true;
TransferDateInput.Text = "";
TransferDateInput.IsReadOnly = true;
WeightModifierInput.Text = "";
WeightModifierInput.TextBox.IsReadOnly = true;
ConsiderModifiersInput.IsChecked = false;
ConsiderModifiersInput.IsEnabled = false;
ConsiderPenaltiesInput.IsChecked = false;
@ -131,7 +143,8 @@ namespace Elwig.Windows {
(ConsiderModifiersInput.IsChecked != BillingData?.ConsiderDelieryModifiers) ||
(ConsiderPenaltiesInput.IsChecked != BillingData?.ConsiderContractPenalties) ||
(ConsiderPenaltyInput.IsChecked != BillingData?.ConsiderTotalPenalty) ||
(ConsiderAutoInput.IsChecked != BillingData?.ConsiderAutoBusinessShares));
(ConsiderAutoInput.IsChecked != BillingData?.ConsiderAutoBusinessShares) ||
WeightModifierChanged);
CalculateButton.IsEnabled = !SaveButton.IsEnabled && PaymentVariantList.SelectedItem is PaymentVar { TestVariant: true };
CommitButton.IsEnabled = CalculateButton.IsEnabled;
}
@ -362,6 +375,10 @@ namespace Elwig.Windows {
d.ConsiderContractPenalties = ConsiderPenaltiesInput.IsChecked ?? false;
d.ConsiderTotalPenalty = ConsiderPenaltyInput.IsChecked ?? false;
d.ConsiderAutoBusinessShares = ConsiderAutoInput.IsChecked ?? false;
var modVal = WeightModifierInput.Text.Length > 0 ? double.Parse(WeightModifierInput.Text) : 0;
d.NetWeightModifier = modVal > 0 ? modVal / 100.0 : 0;
d.GrossWeightModifier = modVal < 0 ? modVal / 100.0 : 0;
WeightModifierChanged = false;
v.Data = JsonSerializer.Serialize(d.Data);
Context.Update(v);
await Context.SaveChangesAsync();
@ -371,6 +388,7 @@ namespace Elwig.Windows {
ConsiderPenaltiesInput_Changed(null, null);
ConsiderPenaltyInput_Changed(null, null);
ConsiderAutoInput_Changed(null, null);
WeightModifierInput_TextChanged(null, null);
} catch (Exception exc) {
await HintContextChange();
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
@ -511,5 +529,27 @@ namespace Elwig.Windows {
}
UpdateSaveButton();
}
private void WeightModifierInput_TextChanged(object? sender, TextChangedEventArgs? evt) {
var res = Validator.CheckDecimal(WeightModifierInput.TextBox, false, 3, 2, true);
if (BillingData == null) {
ControlUtils.ClearInputState(WeightModifierInput.TextBox);
return;
}
var val = WeightModifierInput.Text.Length > 0 && res.IsValid ? double.Parse(WeightModifierInput.Text) : 0;
WeightModifierChanged = (val != Math.Round(BillingData.NetWeightModifier * 100.0, 8) && val != Math.Round(BillingData.GrossWeightModifier * 100.0, 8)) ||
(val == 0 && (BillingData.NetWeightModifier != 0 || BillingData.GrossWeightModifier != 0));
if (WeightModifierChanged) {
ControlUtils.SetInputChanged(WeightModifierInput.TextBox);
} else {
ControlUtils.ClearInputState(WeightModifierInput.TextBox);
}
UpdateSaveButton();
}
private void WeightModifierInput_LostFocus(object sender, RoutedEventArgs evt) {
if (WeightModifierInput.Text.EndsWith(','))
WeightModifierInput.Text = WeightModifierInput.Text[..^1];
}
}
}