Billing: Allow users to add custom member modifiers before VAT
All checks were successful
Test / Run tests (push) Successful in 2m8s

This commit is contained in:
2024-08-13 14:43:12 +02:00
parent f52c11b91e
commit 4d89a17e80
11 changed files with 139 additions and 30 deletions

View File

@ -103,7 +103,7 @@ namespace Elwig.Windows {
}).Sum() : (decimal?)null,
m.Adjust,
m.AdjustAmount,
Custom = CustomPayments!.GetValueOrDefault(m.MgNr, null)?.Amount,
Custom = CustomPayments!.GetValueOrDefault(m.MgNr, null),
})
.Select(m => new {
m.MgNr, m.Name, m.GivenName,
@ -112,23 +112,25 @@ namespace Elwig.Windows {
PenaltyAc = m.PenaltyAc == null ? (decimal?)null : Math.Round((decimal)m.PenaltyAc, 2),
m.Adjust,
AdjustAmount = m.AdjustAmount == null ? (decimal?)null : Math.Round((decimal)m.AdjustAmount, 2),
m.Custom
CustomAmount = m.Custom?.Amount,
ModAbs = m.Custom?.ModAbs,
ModRel = m.Custom?.ModRel,
})
.Select(m => new {
m.MgNr, m.Name, m.GivenName,
m.BusinessShares, m.Weight, m.OverUnder,
m.PenaltyBs, m.PenaltyAc, m.Adjust, m.AdjustAmount, m.Custom,
Total = (m.PenaltyBs ?? 0) + (m.PenaltyAc ?? 0) + (m.AdjustAmount ?? 0) + (m.Custom ?? 0),
m.PenaltyBs, m.PenaltyAc, m.Adjust, m.AdjustAmount, m.CustomAmount, m.ModAbs, m.ModRel,
Total = (m.PenaltyBs ?? 0) + (m.PenaltyAc ?? 0) + (m.AdjustAmount ?? 0) + (m.CustomAmount ?? 0),
})
.Select(m => new {
m.MgNr, m.Name, m.GivenName,
m.BusinessShares, m.Weight, m.OverUnder,
m.PenaltyBs, m.PenaltyAc, m.Adjust, m.AdjustAmount, m.Custom,
m.PenaltyBs, m.PenaltyAc, m.Adjust, m.AdjustAmount, m.CustomAmount, m.ModAbs, m.ModRel,
m.Total,
Background = m.Weight == 0 ? Brushes.Orange : m.Weight / 2 < -m.Total ? Brushes.Red : Brushes.White,
Foreground = m.Total == 0 ? Brushes.Gray : Brushes.Black,
})
.Where(m => m.OverUnder != null || m.Adjust != null || m.PenaltyBs != null || m.PenaltyAc != null || m.Custom != null)
.Where(m => m.OverUnder != null || m.Adjust != null || m.PenaltyBs != null || m.PenaltyAc != null || m.CustomAmount != null || m.ModAbs != null || m.ModRel != null)
.OrderByDescending(m => m.OverUnder ?? 0)
.ThenBy(m => m.Name)
.ThenBy(m => m.GivenName)
@ -141,7 +143,7 @@ namespace Elwig.Windows {
PenaltyBusinessShares.Text = $"{list.Count(r => r.PenaltyBs != null && r.PenaltyBs != 0)} Mg. / {list.Sum(r => r.PenaltyBs):N2} {sym}";
PenaltyAreaCommitments.Text = $"{list.Count(r => r.PenaltyAc != null && r.PenaltyAc != 0)} Mg. / {list.Sum(r => r.PenaltyAc):N2} {sym}";
AutoBusinessShareAdjustment.Text = $"{list.Count(r => r.Adjust > 0)} Mg. / {list.Sum(r => r.Adjust)} GA / {list.Sum(r => r.AdjustAmount):N2} {sym}";
CustomModifiers.Text = $"{list.Count(r => r.Custom != null)} Mg. / {list.Sum(r => r.Custom):N2} {sym}";
CustomModifiers.Text = $"{list.Count(r => r.CustomAmount != null)} Mg. / {list.Sum(r => r.CustomAmount):N2} {sym}";
TotalModifiers.Text = $"{list.Count(r => r.Total != 0)} Mg. / {list.Sum(r => r.Total):N2} {sym}";
NonDeliveries.Text = $"{list.Count(r => r.Weight == 0):N0}";
@ -239,13 +241,22 @@ namespace Elwig.Windows {
MemberList.ScrollIntoView(MemberList.SelectedItem);
if (CustomPayments?.TryGetValue(m.MgNr, out var p) == true) {
CustomModAbsInput.Text = $"{p.ModAbs:N2}";
CustomModRelInput.Text = $"{p.ModRel * 100:N2}";
CustomModCommentInput.Text = p.ModComment ?? "";
CustomAmountInput.Text = $"{p.Amount:N2}";
CustomCommentInput.Text = p.Comment ?? "";
} else {
CustomModAbsInput.Text = "";
CustomModRelInput.Text = "";
CustomModCommentInput.Text = "";
CustomAmountInput.Text = "";
CustomCommentInput.Text = "";
}
} else {
CustomModAbsInput.Text = "";
CustomModRelInput.Text = "";
CustomModCommentInput.Text = "";
CustomAmountInput.Text = "";
CustomCommentInput.Text = "";
}
@ -256,6 +267,14 @@ namespace Elwig.Windows {
App.FocusMember(m.MgNr);
}
private void CustomModAbsInput_TextChanged(object sender, TextChangedEventArgs evt) {
Validator.CheckDecimal((TextBox)sender, false, 4, 2, true);
}
private void CustomModRelInput_TextChanged(object sender, TextChangedEventArgs evt) {
Validator.CheckDecimal((TextBox)sender, false, 3, 2, true);
}
private void CustomAmountInput_TextChanged(object sender, TextChangedEventArgs evt) {
Validator.CheckDecimal((TextBox)sender, false, 4, 2, true);
}
@ -268,12 +287,19 @@ namespace Elwig.Windows {
if (CustomPayments?.TryGetValue(m.MgNr, out var p) == true) {
ctx.Remove(p);
}
if (sender == SaveCustomButton && decimal.TryParse(CustomAmountInput.Text, out var num)) {
if (sender == SaveCustomButton) {
var modAbs = decimal.TryParse(CustomModAbsInput.Text, out var n1) ? (decimal?)n1 : null;
var modRel = decimal.TryParse(CustomModRelInput.Text, out var n2) ? (decimal?)n2 / 100 : null;
var amount = decimal.TryParse(CustomAmountInput.Text, out var n3) ? (decimal?)n3 : null;
var modText = CustomModCommentInput.Text.Trim();
var text = CustomCommentInput.Text.Trim();
ctx.Add(new PaymentCustom {
MgNr = m.MgNr,
Year = Year,
Amount = num,
ModAbs = modAbs,
ModRel = modRel,
ModComment = modText == "" ? null : modText,
Amount = amount,
Comment = text == "" ? null : text,
});
}