[#32] PaymentVariantsWindow: Add export options for Summary
This commit is contained in:
@ -12,6 +12,7 @@ using Elwig.Helpers.Billing;
|
||||
using Elwig.Helpers.Export;
|
||||
using Microsoft.Win32;
|
||||
using System.Text.Json;
|
||||
using Elwig.Documents;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class PaymentVariantsWindow : ContextWindow {
|
||||
@ -24,8 +25,17 @@ namespace Elwig.Windows {
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOpt = new() { WriteIndented = true };
|
||||
|
||||
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)]);
|
||||
private readonly RoutedCommand CtrlÜ = new("CtrlÜ", typeof(MemberAdminWindow), [new KeyGesture(Key.Oem1, ModifierKeys.Control)]);
|
||||
private readonly RoutedCommand CtrlShiftP = new("CtrlShiftP", typeof(MemberAdminWindow), [new KeyGesture(Key.P, ModifierKeys.Control | ModifierKeys.Shift)]);
|
||||
|
||||
public PaymentVariantsWindow(int year) {
|
||||
InitializeComponent();
|
||||
CommandBindings.Add(new CommandBinding(CtrlL, Menu_ExportSave_Click));
|
||||
CommandBindings.Add(new CommandBinding(CtrlP, Menu_SummaryShow_Click));
|
||||
CommandBindings.Add(new CommandBinding(CtrlÜ, Menu_EbicsSave_Click));
|
||||
CommandBindings.Add(new CommandBinding(CtrlShiftP, Menu_SummaryPrint_Click));
|
||||
Year = year;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
SeasonLocked = ctx.Seasons.Find(Year + 1) != null;
|
||||
@ -62,6 +72,10 @@ namespace Elwig.Windows {
|
||||
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;
|
||||
@ -115,6 +129,10 @@ namespace Elwig.Windows {
|
||||
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 = "";
|
||||
@ -289,6 +307,60 @@ namespace Elwig.Windows {
|
||||
w.AddCreditNote(Array.IndexOf(vars, pv.AvNr));
|
||||
}
|
||||
|
||||
private async void Menu_SummaryExport_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
var d = new SaveFileDialog() {
|
||||
FileName = $"Variantendaten-{v.Name.Trim().Replace(' ', '-')}.ods",
|
||||
DefaultExt = "ods",
|
||||
Filter = "OpenDocument Format Spreadsheet (*.ods)|*.ods",
|
||||
Title = $"Variantendaten {v.Name} speichern unter - Elwig"
|
||||
};
|
||||
if (d.ShowDialog() == false)
|
||||
return;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
using var ctx = new AppDbContext();
|
||||
var data = await PaymentVariantSummaryData.ForPaymentVariant(v, ctx.PaymentVariantSummaryRows);
|
||||
using var ods = new OdsFile(d.FileName);
|
||||
await ods.AddTable(data);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
private async void Menu_SummaryShow_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
await 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);
|
||||
}
|
||||
|
||||
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(v, data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
private async void CommitButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v)
|
||||
return;
|
||||
|
Reference in New Issue
Block a user