PaymentVariantsWindow: Add ViewModel and Service
All checks were successful
Test / Run tests (push) Successful in 1m58s
All checks were successful
Test / Run tests (push) Successful in 1m58s
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
using Elwig.Documents;
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Helpers.Export;
|
||||
using Elwig.Models.Dtos;
|
||||
using Elwig.Models.Entities;
|
||||
using Elwig.Services;
|
||||
using Elwig.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
@ -17,13 +18,10 @@ using System.Windows.Input;
|
||||
namespace Elwig.Windows {
|
||||
public partial class PaymentVariantsWindow : ContextWindow {
|
||||
|
||||
public readonly int Year;
|
||||
public readonly bool SeasonLocked;
|
||||
private bool DataValid, DataChanged, NameChanged, CommentChanged, DateValid, DateChanged, TransferDateValid, TransferDateChanged;
|
||||
private BillingData? BillingData;
|
||||
private bool WeightModifierChanged = false;
|
||||
public PaymentVariantsViewModel ViewModel => (PaymentVariantsViewModel)DataContext;
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOpt = new() { WriteIndented = true };
|
||||
public readonly int Year;
|
||||
private bool DataValid, DataChanged, NameChanged, CommentChanged, DateValid, DateChanged, TransferDateValid, TransferDateChanged;
|
||||
|
||||
private readonly RoutedCommand CtrlL = new("CtrlL", typeof(MemberAdminWindow), [new KeyGesture(Key.L, ModifierKeys.Control)]);
|
||||
private readonly RoutedCommand CtrlP = new("CtrlP", typeof(MemberAdminWindow), [new KeyGesture(Key.P, ModifierKeys.Control)]);
|
||||
@ -38,7 +36,7 @@ namespace Elwig.Windows {
|
||||
CommandBindings.Add(new CommandBinding(CtrlShiftP, Menu_SummaryPrint_Click));
|
||||
Year = year;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
SeasonLocked = ctx.Seasons.Find(Year + 1) != null;
|
||||
ViewModel.SeasonLocked = ctx.Seasons.Find(Year + 1) != null;
|
||||
}
|
||||
Title = $"Auszahlungsvarianten - Lese {Year} - Elwig";
|
||||
if (!App.Config.Debug) {
|
||||
@ -62,220 +60,26 @@ namespace Elwig.Windows {
|
||||
|
||||
private void Update() {
|
||||
if (PaymentVariantList.SelectedItem is PaymentVar v) {
|
||||
var locked = !v.TestVariant;
|
||||
DeleteButton.IsEnabled = !locked;
|
||||
CalculateButton.IsEnabled = !locked;
|
||||
CommitButton.IsEnabled = !locked && !SeasonLocked;
|
||||
CommitButton.Visibility = !locked ? Visibility.Visible : Visibility.Hidden;
|
||||
RevertButton.IsEnabled = locked && !SeasonLocked;
|
||||
RevertButton.Visibility = locked ? Visibility.Visible : Visibility.Hidden;
|
||||
Arrow3.Content = locked ? "\xF0B0" : "\xF0AF";
|
||||
Arrow4.Content = locked ? "\xF0B0" : "\xF0AF";
|
||||
CopyButton.IsEnabled = true;
|
||||
EditButton.Content = locked ? "Ansehen" : "Bearbeiten";
|
||||
EditButton.IsEnabled = true;
|
||||
SaveButton.IsEnabled = !locked;
|
||||
MailButton.IsEnabled = true;
|
||||
Menu_ExportSave.IsEnabled = locked;
|
||||
Menu_EbicsSave.IsEnabled = locked;
|
||||
Menu_SummaryExport.IsEnabled = true;
|
||||
Menu_SummaryShow.IsEnabled = true;
|
||||
Menu_SummarySave.IsEnabled = true;
|
||||
Menu_SummaryPrint.IsEnabled = true;
|
||||
|
||||
NameInput.Text = v.Name;
|
||||
NameInput.IsReadOnly = false;
|
||||
CommentInput.Text = v.Comment;
|
||||
CommentInput.IsReadOnly = false;
|
||||
DateInput.Text = $"{v.Date:dd.MM.yyyy}";
|
||||
DateInput.IsReadOnly = false;
|
||||
TransferDateInput.Text = $"{v.TransferDate:dd.MM.yyyy}";
|
||||
TransferDateInput.IsReadOnly = false;
|
||||
try {
|
||||
BillingData = BillingData.FromJson(v.Data);
|
||||
ConsiderModifiersInput.IsChecked = BillingData.ConsiderDelieryModifiers;
|
||||
ConsiderPenaltiesInput.IsChecked = BillingData.ConsiderContractPenalties;
|
||||
ConsiderPenaltyInput.IsChecked = BillingData.ConsiderTotalPenalty;
|
||||
ConsiderAutoInput.IsChecked = BillingData.ConsiderAutoBusinessShares;
|
||||
ConsiderCustomInput.IsChecked = BillingData.ConsiderCustomModifiers;
|
||||
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;
|
||||
ConsiderModifiersInput.IsChecked = false;
|
||||
ConsiderPenaltiesInput.IsChecked = false;
|
||||
ConsiderPenaltyInput.IsChecked = false;
|
||||
ConsiderAutoInput.IsChecked = false;
|
||||
ConsiderCustomInput.IsChecked = false;
|
||||
WeightModifierInput.Text = "";
|
||||
DataInput.Text = v.Data;
|
||||
}
|
||||
WeightModifierInput.IsReadOnly = false;
|
||||
ConsiderModifiersInput.IsEnabled = !locked;
|
||||
ConsiderPenaltiesInput.IsEnabled = !locked;
|
||||
ConsiderPenaltyInput.IsEnabled = !locked;
|
||||
ConsiderAutoInput.IsEnabled = !locked;
|
||||
ConsiderCustomInput.IsEnabled = !locked;
|
||||
DataInput.IsReadOnly = locked;
|
||||
|
||||
ModifierSum.Text = "...";
|
||||
TotalSum.Text = "...";
|
||||
VatSum.Text = "...";
|
||||
DeductionSum.Text = "...";
|
||||
PaymentSum.Text = "...";
|
||||
Utils.RunBackground("Variantendaten laden", async () => {
|
||||
await UpdateSums(v);
|
||||
});
|
||||
ViewModel.FillInputs(v);
|
||||
} else {
|
||||
EditButton.Content = "Bearbeiten";
|
||||
EditButton.IsEnabled = false;
|
||||
SaveButton.IsEnabled = false;
|
||||
CopyButton.IsEnabled = false;
|
||||
CalculateButton.IsEnabled = false;
|
||||
CommitButton.IsEnabled = false;
|
||||
CommitButton.Visibility = Visibility.Visible;
|
||||
RevertButton.IsEnabled = false;
|
||||
RevertButton.Visibility = Visibility.Hidden;
|
||||
Arrow3.Content = "\xF0AF";
|
||||
Arrow4.Content = "\xF0AF";
|
||||
DeleteButton.IsEnabled = false;
|
||||
MailButton.IsEnabled = false;
|
||||
Menu_ExportSave.IsEnabled = false;
|
||||
Menu_EbicsSave.IsEnabled = false;
|
||||
Menu_SummaryExport.IsEnabled = false;
|
||||
Menu_SummaryShow.IsEnabled = false;
|
||||
Menu_SummarySave.IsEnabled = false;
|
||||
Menu_SummaryPrint.IsEnabled = false;
|
||||
|
||||
BillingData = null;
|
||||
NameInput.Text = "";
|
||||
NameInput.IsReadOnly = true;
|
||||
CommentInput.Text = "";
|
||||
CommentInput.IsReadOnly = true;
|
||||
DateInput.Text = "";
|
||||
DateInput.IsReadOnly = true;
|
||||
TransferDateInput.Text = "";
|
||||
TransferDateInput.IsReadOnly = true;
|
||||
WeightModifierInput.Text = "";
|
||||
WeightModifierInput.IsReadOnly = true;
|
||||
ConsiderModifiersInput.IsChecked = false;
|
||||
ConsiderModifiersInput.IsEnabled = false;
|
||||
ConsiderPenaltiesInput.IsChecked = false;
|
||||
ConsiderPenaltiesInput.IsEnabled = false;
|
||||
ConsiderPenaltyInput.IsChecked = false;
|
||||
ConsiderPenaltyInput.IsEnabled = false;
|
||||
ConsiderAutoInput.IsChecked = false;
|
||||
ConsiderAutoInput.IsEnabled = false;
|
||||
ConsiderCustomInput.IsChecked = false;
|
||||
ConsiderCustomInput.IsEnabled = false;
|
||||
DataInput.Text = "";
|
||||
DataInput.IsReadOnly = true;
|
||||
|
||||
ModifierSum.Text = "-";
|
||||
TotalSum.Text = "-";
|
||||
VatSum.Text = "-";
|
||||
DeductionSum.Text = "-";
|
||||
PaymentSum.Text = "-";
|
||||
ViewModel.ClearInputs();
|
||||
}
|
||||
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void UpdateSaveButton() {
|
||||
SaveButton.IsEnabled = PaymentVariantList.SelectedItem != null &&
|
||||
private void UpdateButtons() {
|
||||
ViewModel.SaveIsEnabled = PaymentVariantList.SelectedItem != null &&
|
||||
((DataChanged && DataValid) || NameChanged || CommentChanged ||
|
||||
(DateChanged && DateValid) ||
|
||||
(TransferDateChanged && TransferDateValid) ||
|
||||
(ConsiderModifiersInput.IsChecked != BillingData?.ConsiderDelieryModifiers) ||
|
||||
(ConsiderPenaltiesInput.IsChecked != BillingData?.ConsiderContractPenalties) ||
|
||||
(ConsiderPenaltyInput.IsChecked != BillingData?.ConsiderTotalPenalty) ||
|
||||
(ConsiderAutoInput.IsChecked != BillingData?.ConsiderAutoBusinessShares) ||
|
||||
(ConsiderCustomInput.IsChecked != BillingData?.ConsiderCustomModifiers) ||
|
||||
WeightModifierChanged);
|
||||
CalculateButton.IsEnabled = !SaveButton.IsEnabled && PaymentVariantList.SelectedItem is PaymentVar { TestVariant: true };
|
||||
CommitButton.IsEnabled = CalculateButton.IsEnabled;
|
||||
}
|
||||
|
||||
private async Task UpdateSums(PaymentVar v) {
|
||||
if (App.MainDispatcher == null)
|
||||
return;
|
||||
var modText = "-";
|
||||
var totalText = "-";
|
||||
var vatText = "-";
|
||||
var deductionText = "-";
|
||||
var paymentText = "-";
|
||||
|
||||
using var ctx = new AppDbContext();
|
||||
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);
|
||||
modText = $"{v.Season.DecFromDb(modSum):N2} {sym}";
|
||||
|
||||
var totalSum = await ctx.MemberPayments
|
||||
.Where(p => p.Year == v.Year && p.AvNr == v.AvNr)
|
||||
.SumAsync(p => p.AmountValue);
|
||||
totalText = $"{v.Season.DecFromDb(totalSum):N2} {sym}";
|
||||
|
||||
await App.MainDispatcher.BeginInvoke(() => {
|
||||
if (PaymentVariantList.SelectedItem != v)
|
||||
return;
|
||||
ModifierSum.Text = modText;
|
||||
TotalSum.Text = totalText;
|
||||
});
|
||||
|
||||
var credits = ctx.Credits.Where(c => c.Year == v.Year && c.AvNr == v.AvNr);
|
||||
if (!credits.Any()) {
|
||||
long lastTotalSum = 0;
|
||||
decimal vatSum = 0;
|
||||
var currentPayments = await ctx.MemberPayments
|
||||
.Where(p => p.Year == v.Year && p.AvNr == v.AvNr)
|
||||
.ToDictionaryAsync(p => p.MgNr);
|
||||
var lastV = await ctx.PaymentVariants
|
||||
.Where(l => l.Year == v.Year && !l.TestVariant)
|
||||
.OrderByDescending(l => l.TransferDateString ?? l.DateString)
|
||||
.ThenByDescending(l => l.AvNr)
|
||||
.FirstOrDefaultAsync();
|
||||
if (lastV != null) {
|
||||
var lastPayments = await ctx.MemberPayments
|
||||
.Where(p => p.Year == v.Year && p.AvNr == lastV.AvNr)
|
||||
.ToDictionaryAsync(p => p.MgNr);
|
||||
lastTotalSum = lastPayments.Sum(e => e.Value.AmountValue);
|
||||
foreach (int mgnr in currentPayments.Keys) {
|
||||
var c = currentPayments[mgnr];
|
||||
var l = lastPayments[mgnr];
|
||||
vatSum += (c.Amount - l.Amount) * (decimal)(c.Member.IsBuchführend ? v.Season.VatNormal : v.Season.VatFlatrate);
|
||||
}
|
||||
} else {
|
||||
vatSum = currentPayments.Sum(e => e.Value.Amount * (decimal)(e.Value.Member.IsBuchführend ? v.Season.VatNormal : v.Season.VatFlatrate));
|
||||
}
|
||||
vatText = $"~{vatSum:N2} {sym}";
|
||||
deductionText = $"- {sym}";
|
||||
paymentText = $"~{v.Season.DecFromDb(totalSum - lastTotalSum) + vatSum:N2} {sym}";
|
||||
} else {
|
||||
// all values in the credit table are stored with precision 2!
|
||||
totalText = $"{Utils.DecFromDb(await credits.SumAsync(c => c.NetAmountValue), 2):N2} {sym}";
|
||||
vatText = $"{Utils.DecFromDb(await credits.SumAsync(c => c.VatAmountValue), 2):N2} {sym}";
|
||||
deductionText = $"{-Utils.DecFromDb(await credits.SumAsync(c => c.ModifiersValue ?? 0), 2):N2} {sym}";
|
||||
paymentText = $"{Utils.DecFromDb(await credits.SumAsync(c => c.AmountValue), 2):N2} {sym}";
|
||||
}
|
||||
|
||||
await App.MainDispatcher.BeginInvoke(() => {
|
||||
if (PaymentVariantList.SelectedItem != v)
|
||||
return;
|
||||
ModifierSum.Text = modText;
|
||||
TotalSum.Text = totalText;
|
||||
VatSum.Text = vatText;
|
||||
DeductionSum.Text = deductionText;
|
||||
PaymentSum.Text = paymentText;
|
||||
});
|
||||
(ViewModel.ConsiderModifiers != ViewModel.BillingData?.ConsiderDelieryModifiers) ||
|
||||
(ViewModel.ConsiderPenalties != ViewModel.BillingData?.ConsiderContractPenalties) ||
|
||||
(ViewModel.ConsiderPenalty != ViewModel.BillingData?.ConsiderTotalPenalty) ||
|
||||
(ViewModel.ConsiderAuto != ViewModel.BillingData?.ConsiderAutoBusinessShares) ||
|
||||
(ViewModel.ConsiderCustom != ViewModel.BillingData?.ConsiderCustomModifiers) ||
|
||||
ViewModel.WeightModifierChanged);
|
||||
ViewModel.CalculateIsEnabled = !ViewModel.SaveIsEnabled && PaymentVariantList.SelectedItem is PaymentVar { TestVariant: true };
|
||||
ViewModel.CommitIsEnabled = ViewModel.CalculateIsEnabled;
|
||||
}
|
||||
|
||||
private void PaymentVariantList_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||
@ -284,23 +88,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void AddButton_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
PaymentVar? v;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
v = new PaymentVar {
|
||||
Year = Year,
|
||||
AvNr = await ctx.NextAvNr(Year),
|
||||
Name = "Neue Auszahlungsvariante",
|
||||
TestVariant = true,
|
||||
DateString = $"{DateTime.Today:yyyy-MM-dd}",
|
||||
Data = "{\"mode\": \"elwig\", \"version\": 1, \"payment\": {}, \"curves\": []}",
|
||||
};
|
||||
|
||||
ctx.Add(v);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
App.HintContextChange();
|
||||
|
||||
var v = await PaymentVariantService.CreatePaymentVariant(Year);
|
||||
ControlUtils.SelectItem(PaymentVariantList, v);
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
@ -312,23 +100,7 @@ namespace Elwig.Windows {
|
||||
private async void CopyButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar orig) return;
|
||||
try {
|
||||
PaymentVar? n;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
n = new PaymentVar {
|
||||
Year = orig.Year,
|
||||
AvNr = await ctx.NextAvNr(Year),
|
||||
Name = $"{orig.Name} (Kopie)",
|
||||
TestVariant = true,
|
||||
DateString = $"{DateTime.Today:yyyy-MM-dd}",
|
||||
Data = orig.Data,
|
||||
};
|
||||
|
||||
ctx.Add(n);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
App.HintContextChange();
|
||||
|
||||
PaymentVar n = await orig.Duplicate();
|
||||
ControlUtils.SelectItem(PaymentVariantList, n);
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
@ -340,11 +112,7 @@ namespace Elwig.Windows {
|
||||
private async void DeleteButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v || !v.TestVariant) return;
|
||||
try {
|
||||
using (var ctx = new AppDbContext()) {
|
||||
ctx.Remove(v);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
App.HintContextChange();
|
||||
await PaymentVariantService.DeletePaymentVariant(v.Year, v.AvNr);
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
@ -355,17 +123,16 @@ namespace Elwig.Windows {
|
||||
private async void CalculateButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
CalculateButton.IsEnabled = false;
|
||||
ViewModel.CalculateIsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
var b = new BillingVariant(v.Year, v.AvNr);
|
||||
await b.Calculate();
|
||||
await PaymentVariantService.Calculate(v.Year, v.AvNr);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Berechnungsfehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
App.HintContextChange();
|
||||
Mouse.OverrideCursor = null;
|
||||
CalculateButton.IsEnabled = true;
|
||||
ViewModel.CalculateIsEnabled = true;
|
||||
}
|
||||
|
||||
private void EditButton_Click(object sender, RoutedEventArgs evt) {
|
||||
@ -417,38 +184,25 @@ namespace Elwig.Windows {
|
||||
private async void Menu_SummaryShow_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
await GenerateSummary(v, ExportMode.Show);
|
||||
await PaymentVariantService.GenerateSummary(v, ExportMode.Show);
|
||||
}
|
||||
|
||||
private async void Menu_SummarySave_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
await GenerateSummary(v, ExportMode.SavePdf);
|
||||
await PaymentVariantService.GenerateSummary(v, ExportMode.SavePdf);
|
||||
}
|
||||
|
||||
private async void Menu_SummaryPrint_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
await GenerateSummary(v, ExportMode.Print);
|
||||
}
|
||||
|
||||
private static async Task GenerateSummary(PaymentVar v, ExportMode mode) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
using var ctx = new AppDbContext();
|
||||
var data = await PaymentVariantSummaryData.ForPaymentVariant(v, ctx.PaymentVariantSummaryRows);
|
||||
using var doc = new PaymentVariantSummary((await ctx.PaymentVariants.FindAsync(v.Year, v.AvNr))!, data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
await PaymentVariantService.GenerateSummary(v, ExportMode.Print);
|
||||
}
|
||||
|
||||
private async void CommitButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
CommitButton.IsEnabled = false;
|
||||
ViewModel.CommitIsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
var b = new BillingVariant(v.Year, v.AvNr);
|
||||
@ -457,7 +211,7 @@ namespace Elwig.Windows {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
RevertButton.IsEnabled = true;
|
||||
ViewModel.RevertIsEnabled = true;
|
||||
App.HintContextChange();
|
||||
}
|
||||
|
||||
@ -470,13 +224,13 @@ namespace Elwig.Windows {
|
||||
"Traubengutschriften löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (res != MessageBoxResult.Yes)
|
||||
return;
|
||||
RevertButton.IsEnabled = false;
|
||||
ViewModel.RevertIsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
var b = new BillingVariant(v.Year, v.AvNr);
|
||||
await b.Revert();
|
||||
App.HintContextChange();
|
||||
Mouse.OverrideCursor = null;
|
||||
CommitButton.IsEnabled = true;
|
||||
ViewModel.CommitIsEnabled = true;
|
||||
}
|
||||
|
||||
private async void Menu_EbicsSave_Click(object sender, RoutedEventArgs evt) {
|
||||
@ -486,107 +240,35 @@ namespace Elwig.Windows {
|
||||
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:N0} Mitglieder ist kein IBAN hinterlegt.\n\nDiese werden NICHT exportiert.",
|
||||
"Mitglieder ohne IBAN", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
|
||||
if (r != MessageBoxResult.OK) return;
|
||||
}
|
||||
var withNegAmount = v.Credits.Count(c => c.Amount <= 0);
|
||||
if (withNegAmount > 0) {
|
||||
var r = MessageBox.Show($"Achtung: Es gibt {withNegAmount:N0} Traubengutschriften mit negativem Betrag.\n\nDiese werden NICHT exportiert.",
|
||||
"Traubengutschriften mit negativem Betrag", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.OK);
|
||||
if (r != MessageBoxResult.OK) return;
|
||||
}
|
||||
|
||||
var d = new SaveFileDialog() {
|
||||
FileName = $"{App.Client.NameToken}-Überweisungsdaten-{v.Year}-{v.Name.Trim().Replace(' ', '-')}.{Ebics.FileExtension}",
|
||||
DefaultExt = Ebics.FileExtension,
|
||||
Filter = "EBICS-Datei (*.xml)|*.xml",
|
||||
Title = $"Überweisungsdaten speichern unter - Elwig",
|
||||
};
|
||||
if (d.ShowDialog() == true) {
|
||||
Menu_EbicsSave.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
using var e = new Ebics(v, d.FileName, App.Client.ExportEbicsVersion, (Ebics.AddressMode)App.Client.ExportEbicsAddress);
|
||||
await e.ExportAsync(Transaction.FromPaymentVariant(v));
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
Menu_EbicsSave.IsEnabled = true;
|
||||
}
|
||||
await PaymentVariantService.GenerateEbics(v.Year, v.AvNr);
|
||||
}
|
||||
|
||||
private async void Menu_ExportSave_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
}
|
||||
var d = new SaveFileDialog() {
|
||||
FileName = $"{App.Client.NameToken}-Buchungsliste-{v.Year}-{v.Name.Trim().Replace(' ', '-')}.ods",
|
||||
DefaultExt = "ods",
|
||||
Filter = "OpenDocument Format Spreadsheet (*.ods)|*.ods",
|
||||
Title = $"Buchungsliste speichern unter - Elwig"
|
||||
};
|
||||
if (d.ShowDialog() == true) {
|
||||
Menu_ExportSave.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
using var ctx = new AppDbContext();
|
||||
var tbl = await CreditNoteData.ForPaymentVariant(ctx, v.Year, v.AvNr);
|
||||
using var ods = new OdsFile(d.FileName);
|
||||
await ods.AddTable(tbl);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
Menu_ExportSave.IsEnabled = true;
|
||||
}
|
||||
await PaymentVariantService.GenerateAccountingList(v.Year, v.AvNr, v.Name);
|
||||
}
|
||||
|
||||
private async void SaveButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v || BillingData == null) return;
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v || ViewModel.BillingData == null) return;
|
||||
try {
|
||||
v.Name = NameInput.Text;
|
||||
v.Comment = (CommentInput.Text != "") ? CommentInput.Text : null;
|
||||
v.DateString = string.Join("-", DateInput.Text.Split(".").Reverse());
|
||||
v.TransferDateString = (TransferDateInput.Text != "") ? string.Join("-", TransferDateInput.Text.Split(".").Reverse()) : null;
|
||||
var d = App.Config.Debug ? BillingData.FromJson(DataInput.Text) : BillingData;
|
||||
d.ConsiderDelieryModifiers = ConsiderModifiersInput.IsChecked ?? false;
|
||||
d.ConsiderContractPenalties = ConsiderPenaltiesInput.IsChecked ?? false;
|
||||
d.ConsiderTotalPenalty = ConsiderPenaltyInput.IsChecked ?? false;
|
||||
d.ConsiderAutoBusinessShares = ConsiderAutoInput.IsChecked ?? false;
|
||||
d.ConsiderCustomModifiers = ConsiderCustomInput.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);
|
||||
|
||||
using (var ctx = new AppDbContext()) {
|
||||
ctx.Update(v);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
App.HintContextChange();
|
||||
CommentInput_TextChanged(null, null);
|
||||
ConsiderModifiersInput_Changed(null, null);
|
||||
ConsiderPenaltiesInput_Changed(null, null);
|
||||
ConsiderPenaltyInput_Changed(null, null);
|
||||
ConsiderAutoInput_Changed(null, null);
|
||||
ConsiderCustomInput_Changed(null, null);
|
||||
WeightModifierInput_TextChanged(null, null);
|
||||
await ViewModel.UpdatePaymentVariant(v.Year, v.AvNr);
|
||||
} catch (Exception exc) {
|
||||
await HintContextChange();
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "Auszahlungsvariante aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
await HintContextChange();
|
||||
CommentInput_TextChanged(null, null);
|
||||
DateInput_TextChanged(null, null);
|
||||
TransferDateInput_TextChanged(null, null);
|
||||
ConsiderModifiersInput_Changed(null, null);
|
||||
ConsiderPenaltiesInput_Changed(null, null);
|
||||
ConsiderPenaltyInput_Changed(null, null);
|
||||
ConsiderAutoInput_Changed(null, null);
|
||||
ConsiderCustomInput_Changed(null, null);
|
||||
WeightModifierInput_TextChanged(null, null);
|
||||
}
|
||||
|
||||
private void ModifierButton_Click(object sender, RoutedEventArgs evt) {
|
||||
@ -605,7 +287,7 @@ namespace Elwig.Windows {
|
||||
ControlUtils.ClearInputState(NameInput);
|
||||
NameChanged = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void CommentInput_TextChanged(object? sender, TextChangedEventArgs? evt) {
|
||||
@ -620,10 +302,10 @@ namespace Elwig.Windows {
|
||||
ControlUtils.ClearInputState(CommentInput);
|
||||
CommentChanged = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void DateInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
private void DateInput_TextChanged(object? sender, TextChangedEventArgs? evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
ControlUtils.ClearInputState(DateInput);
|
||||
return;
|
||||
@ -641,10 +323,10 @@ namespace Elwig.Windows {
|
||||
DateValid = true;
|
||||
DateChanged = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void TransferDateInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
private void TransferDateInput_TextChanged(object? sender, TextChangedEventArgs? evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
ControlUtils.ClearInputState(TransferDateInput);
|
||||
return;
|
||||
@ -662,7 +344,7 @@ namespace Elwig.Windows {
|
||||
TransferDateValid = true;
|
||||
TransferDateChanged = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void DataInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
@ -688,89 +370,89 @@ namespace Elwig.Windows {
|
||||
ControlUtils.SetInputInvalid(DataInput);
|
||||
DataValid = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void ConsiderModifiersInput_Changed(object? sender, RoutedEventArgs? evt) {
|
||||
if (BillingData == null) {
|
||||
if (ViewModel.BillingData == null) {
|
||||
ControlUtils.ClearInputState(ConsiderModifiersInput);
|
||||
return;
|
||||
}
|
||||
if (BillingData.ConsiderDelieryModifiers != ConsiderModifiersInput.IsChecked) {
|
||||
if (ViewModel.BillingData.ConsiderDelieryModifiers != ConsiderModifiersInput.IsChecked) {
|
||||
ControlUtils.SetInputChanged(ConsiderModifiersInput);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(ConsiderModifiersInput);
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void ConsiderPenaltiesInput_Changed(object? sender, RoutedEventArgs? evt) {
|
||||
if (BillingData == null) {
|
||||
if (ViewModel.BillingData == null) {
|
||||
ControlUtils.ClearInputState(ConsiderPenaltiesInput);
|
||||
return;
|
||||
}
|
||||
if (BillingData.ConsiderContractPenalties != ConsiderPenaltiesInput.IsChecked) {
|
||||
if (ViewModel.BillingData.ConsiderContractPenalties != ConsiderPenaltiesInput.IsChecked) {
|
||||
ControlUtils.SetInputChanged(ConsiderPenaltiesInput);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(ConsiderPenaltiesInput);
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void ConsiderPenaltyInput_Changed(object? sender, RoutedEventArgs? evt) {
|
||||
if (BillingData == null) {
|
||||
if (ViewModel.BillingData == null) {
|
||||
ControlUtils.ClearInputState(ConsiderPenaltyInput);
|
||||
return;
|
||||
}
|
||||
if (BillingData.ConsiderTotalPenalty != ConsiderPenaltyInput.IsChecked) {
|
||||
if (ViewModel.BillingData.ConsiderTotalPenalty != ConsiderPenaltyInput.IsChecked) {
|
||||
ControlUtils.SetInputChanged(ConsiderPenaltyInput);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(ConsiderPenaltyInput);
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void ConsiderAutoInput_Changed(object? sender, RoutedEventArgs? evt) {
|
||||
if (BillingData == null) {
|
||||
if (ViewModel.BillingData == null) {
|
||||
ControlUtils.ClearInputState(ConsiderAutoInput);
|
||||
return;
|
||||
}
|
||||
if (BillingData.ConsiderAutoBusinessShares != ConsiderAutoInput.IsChecked) {
|
||||
if (ViewModel.BillingData.ConsiderAutoBusinessShares != ConsiderAutoInput.IsChecked) {
|
||||
ControlUtils.SetInputChanged(ConsiderAutoInput);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(ConsiderAutoInput);
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void ConsiderCustomInput_Changed(object? sender, RoutedEventArgs? evt) {
|
||||
if (BillingData == null) {
|
||||
if (ViewModel.BillingData == null) {
|
||||
ControlUtils.ClearInputState(ConsiderCustomInput);
|
||||
return;
|
||||
}
|
||||
if (BillingData.ConsiderCustomModifiers != ConsiderCustomInput.IsChecked) {
|
||||
if (ViewModel.BillingData.ConsiderCustomModifiers != ConsiderCustomInput.IsChecked) {
|
||||
ControlUtils.SetInputChanged(ConsiderCustomInput);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(ConsiderCustomInput);
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void WeightModifierInput_TextChanged(object? sender, TextChangedEventArgs? evt) {
|
||||
var res = Validator.CheckDecimal(WeightModifierInput, false, 3, 2, true);
|
||||
if (BillingData == null) {
|
||||
if (ViewModel.BillingData == null) {
|
||||
ControlUtils.ClearInputState(WeightModifierInput);
|
||||
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) {
|
||||
ViewModel.WeightModifierChanged = (val != Math.Round(ViewModel.BillingData.NetWeightModifier * 100.0, 8) && val != Math.Round(ViewModel.BillingData.GrossWeightModifier * 100.0, 8)) ||
|
||||
(val == 0 && (ViewModel.BillingData.NetWeightModifier != 0 || ViewModel.BillingData.GrossWeightModifier != 0));
|
||||
if (ViewModel.WeightModifierChanged) {
|
||||
ControlUtils.SetInputChanged(WeightModifierInput);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(WeightModifierInput);
|
||||
}
|
||||
UpdateSaveButton();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void WeightModifierInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
|
Reference in New Issue
Block a user