PaymentVariantWindow: Fix sum calculation and crash on export
This commit is contained in:
@ -158,7 +158,7 @@ namespace Elwig.Windows {
|
||||
private async Task UpdateSums() {
|
||||
if (PaymentVariantList.SelectedItem is PaymentVar v) {
|
||||
using var ctx = new AppDbContext();
|
||||
var sym = v.Season.Currency.Symbol;
|
||||
var sym = v.Season.Currency.Symbol ?? v.Season.Currency.Code;
|
||||
var modSum = await ctx.PaymentDeliveryParts
|
||||
.Where(p => p.Year == v.Year && p.AvNr == v.AvNr)
|
||||
.SumAsync(p => p.AmountValue - p.NetAmountValue);
|
||||
@ -173,9 +173,10 @@ namespace Elwig.Windows {
|
||||
DeductionSum.Text = $"- {sym}";
|
||||
PaymentSum.Text = $"- {sym}";
|
||||
} else {
|
||||
VatSum.Text = $"{v.Season.DecFromDb(await credits.SumAsync(c => c.VatAmountValue)):N2} {sym}";
|
||||
DeductionSum.Text = $"{-v.Season.DecFromDb(await credits.SumAsync(c => c.ModifiersValue ?? 0)):N2} {sym}";
|
||||
PaymentSum.Text = $"{v.Season.DecFromDb(await credits.SumAsync(c => c.AmountValue)):N2} {sym}";
|
||||
// all values in the credit table are stored with precision 2!
|
||||
VatSum.Text = $"{Utils.DecFromDb(await credits.SumAsync(c => c.VatAmountValue), 2):N2} {sym}";
|
||||
DeductionSum.Text = $"{-Utils.DecFromDb(await credits.SumAsync(c => c.ModifiersValue ?? 0), 2):N2} {sym}";
|
||||
PaymentSum.Text = $"{Utils.DecFromDb(await credits.SumAsync(c => c.AmountValue), 2):N2} {sym}";
|
||||
}
|
||||
} else {
|
||||
ModifierSum.Text = "-";
|
||||
@ -254,7 +255,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void CalculateButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedValue is not PaymentVar v)
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
CalculateButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
@ -289,7 +290,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void CommitButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedValue is not PaymentVar v)
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
CommitButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
@ -305,7 +306,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void RevertButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedValue is not PaymentVar v)
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
var res = MessageBox.Show(
|
||||
"Sollen wirklich alle festgesetzten Traubengutschriften der ausgewählten Auszahlungsvariante unwiderruflich gelöscht werden?\n\n" +
|
||||
@ -323,13 +324,16 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void ExportButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedValue is not PaymentVar v) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
return;
|
||||
} else if (v.TransferDate == null) {
|
||||
MessageBox.Show("Überweisungsdatum muss gesetzt sein!", "Exportieren nicht möglich", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
using var ctx = new AppDbContext();
|
||||
v = (await ctx.PaymentVariants.FindAsync(v.Year, v.AvNr))!;
|
||||
|
||||
var withoutIban = v.Credits.Count(c => c.Member.Iban == null);
|
||||
if (withoutIban > 0) {
|
||||
var r = MessageBox.Show($"Achtung: Für {withoutIban} Mitglieder ist kein IBAN hinterlegt.\nDiese werden NICHT exportiert.",
|
||||
@ -358,7 +362,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void TransactionButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedValue is not PaymentVar v) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
return;
|
||||
}
|
||||
var d = new SaveFileDialog() {
|
||||
|
Reference in New Issue
Block a user