PaymentVariantsWindow: Impelment BillingVariant
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
using Elwig.Models.Entities;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -5,18 +8,23 @@ using System.Threading.Tasks;
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class BillingVariant : Billing {
|
||||
|
||||
private readonly int AvNr;
|
||||
protected readonly int AvNr;
|
||||
protected readonly PaymentVar PaymentVariant;
|
||||
|
||||
public BillingVariant(int year, int avnr) : base(year) {
|
||||
AvNr = avnr;
|
||||
PaymentVariant = Context.PaymentVariants.Find(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found");
|
||||
}
|
||||
|
||||
public async Task Calculate() {
|
||||
await DeleteInDb();
|
||||
await SetCalcTime();
|
||||
await CalculatePrices();
|
||||
await CalculateModifiers();
|
||||
await CalculateMemberModifiers();
|
||||
using var cnx = await AppDbContext.ConnectAsync();
|
||||
using var tx = await cnx.BeginTransactionAsync();
|
||||
await DeleteInDb(cnx);
|
||||
await SetCalcTime(cnx);
|
||||
await CalculatePrices(cnx);
|
||||
await CalculateModifiers(cnx);
|
||||
await CalculateMemberModifiers(cnx);
|
||||
await tx.CommitAsync();
|
||||
}
|
||||
|
||||
public async Task Commit() {
|
||||
@ -68,15 +76,13 @@ namespace Elwig.Helpers.Billing {
|
||||
""");
|
||||
}
|
||||
|
||||
protected async Task SetCalcTime() {
|
||||
using var cnx = await AppDbContext.ConnectAsync();
|
||||
protected async Task SetCalcTime(SqliteConnection cnx) {
|
||||
await AppDbContext.ExecuteBatch(cnx, $"""
|
||||
UPDATE payment_variant SET calc_time = UNIXEPOCH() WHERE (year, avnr) = ({Year}, {AvNr})
|
||||
""");
|
||||
}
|
||||
|
||||
protected async Task DeleteInDb() {
|
||||
using var cnx = await AppDbContext.ConnectAsync();
|
||||
protected async Task DeleteInDb(SqliteConnection cnx) {
|
||||
await AppDbContext.ExecuteBatch(cnx, $"""
|
||||
DELETE FROM payment_delivery_part_bucket WHERE (year, avnr) = ({Year}, {AvNr});
|
||||
DELETE FROM payment_delivery_part WHERE (year, avnr) = ({Year}, {AvNr});
|
||||
@ -85,8 +91,7 @@ namespace Elwig.Helpers.Billing {
|
||||
""");
|
||||
}
|
||||
|
||||
protected async Task CalculateMemberModifiers() {
|
||||
using var cnx = await AppDbContext.ConnectAsync();
|
||||
protected async Task CalculateMemberModifiers(SqliteConnection cnx) {
|
||||
if (App.Client.IsMatzen) {
|
||||
var lastYears = 3;
|
||||
var multiplier = 0.50;
|
||||
@ -113,13 +118,22 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task CalculatePrices() {
|
||||
using var cnx = await AppDbContext.ConnectAsync();
|
||||
protected async Task CalculatePrices(SqliteConnection cnx) {
|
||||
var jsonData = PaymentVariant.Data;
|
||||
var attrVariants = Context.DeliveryParts
|
||||
.Where(d => d.Year == Year)
|
||||
.Select(d => $"{d.SortId}{d.AttrId}")
|
||||
.Distinct()
|
||||
.ToList()
|
||||
.Union(Context.WineVarieties.Select(v => v.SortId))
|
||||
.ToList();
|
||||
|
||||
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string Discr, int Value, bool MinQuw, double Oe, double Kmw)>();
|
||||
var data = BillingData.FromJson(jsonData, attrVariants);
|
||||
|
||||
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string Discr, int Value, double Oe, double Kmw, string QualId)>();
|
||||
using (var cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = $"""
|
||||
SELECT d.year, d.did, d.dpnr, b.bktnr, d.sortid, b.discr, b.value, d.min_quw, d.oe, d.kmw
|
||||
SELECT d.year, d.did, d.dpnr, b.bktnr, d.sortid, b.discr, b.value, d.oe, d.kmw, d.qualid
|
||||
FROM delivery_part_bucket b
|
||||
JOIN v_delivery d ON (d.year, d.did, d.dpnr) = (b.year, b.did, b.dpnr)
|
||||
WHERE b.year = {Year}
|
||||
@ -129,18 +143,17 @@ namespace Elwig.Helpers.Billing {
|
||||
parts.Add((
|
||||
reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3),
|
||||
reader.GetString(4), reader.GetString(5), reader.GetInt32(6),
|
||||
reader.GetBoolean(7), reader.GetDouble(8), reader.GetDouble(9)
|
||||
reader.GetDouble(7), reader.GetDouble(8), reader.GetString(9)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
var inserts = new List<(int Year, int DId, int DPNr, int BktNr, long Price, long Amount)>();
|
||||
foreach (var part in parts) {
|
||||
var price = !part.MinQuw ? 0.5m : ((part.BktNr == 2 ? 0.8m : (part.BktNr == 1 ? 0.7m : 0.6m)) + ((decimal)(part.Oe - 73) * 0.005m)); // TODO
|
||||
price += (AvNr - 1) * 0.2m;
|
||||
var priceL = Utils.DecToDb(price, 4);
|
||||
var amount = Utils.DecToDb(price * part.Value, 4);
|
||||
inserts.Add((part.Year, part.DId, part.DPNr, part.BktNr, priceL, amount));
|
||||
var attrId = (part.Discr == "_" || part.Discr == "") ? null : part.Discr;
|
||||
var price = data.CalculatePrice(part.SortId, attrId, part.QualId, part.Discr != "_", part.Oe, part.Kmw);
|
||||
var priceL = PaymentVariant.Season.DecToDb(price);
|
||||
inserts.Add((part.Year, part.DId, part.DPNr, part.BktNr, priceL, priceL * part.Value));
|
||||
}
|
||||
|
||||
await AppDbContext.ExecuteBatch(cnx, $"""
|
||||
@ -149,8 +162,7 @@ namespace Elwig.Helpers.Billing {
|
||||
""");
|
||||
}
|
||||
|
||||
protected async Task CalculateModifiers() {
|
||||
using var cnx = await AppDbContext.ConnectAsync();
|
||||
protected async Task CalculateModifiers(SqliteConnection cnx) {
|
||||
await AppDbContext.ExecuteBatch(cnx, $"""
|
||||
INSERT INTO payment_delivery_part (year, did, dpnr, avnr, net_amount, mod_abs, mod_rel)
|
||||
SELECT d.year, d.did, d.dpnr, {AvNr}, 0, COALESCE(m.abs, 0), COALESCE(m.rel, 0)
|
||||
|
@ -6,7 +6,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Elwig.Windows"
|
||||
mc:Ignorable="d"
|
||||
Title="Auszahlungsvarianten - Elwig" Height="450" Width="800" MinHeight="400" MinWidth="700">
|
||||
Title="Auszahlungsvarianten - Elwig" Height="500" Width="820" MinHeight="500" MinWidth="820">
|
||||
<Window.Resources>
|
||||
<Style TargetType="Label">
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
@ -41,8 +41,8 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="200"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="200"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListBox x:Name="PaymentVariantList" Margin="10,10,35,10" Grid.RowSpan="2" SelectionChanged="PaymentVariantList_SelectionChanged">
|
||||
@ -66,37 +66,55 @@
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Width="25" Height="25" Margin="5,60,5,0" Grid.RowSpan="2"/>
|
||||
|
||||
<Label Content="Name:" Margin="10,10,0,0" Grid.Column="1"/>
|
||||
<TextBox x:Name="NameInput" Width="200" Grid.Column="2" HorizontalAlignment="Left" Margin="0,10,0,0"/>
|
||||
<TextBox x:Name="NameInput" Width="200" Grid.Column="2" HorizontalAlignment="Left" Margin="0,10,0,0"
|
||||
TextChanged="NameInput_TextChanged"/>
|
||||
|
||||
<Label Content="Beschreibung:" Margin="10,40,0,0" Grid.Column="1"/>
|
||||
<TextBox x:Name="CommentInput" Grid.Column="2" HorizontalAlignment="Stretch" Margin="0,40,10,0"/>
|
||||
<TextBox x:Name="CommentInput" Grid.Column="2" HorizontalAlignment="Stretch" Margin="0,40,10,0"
|
||||
TextChanged="CommentInput_TextChanged"/>
|
||||
|
||||
<Label Content="Erstellt am:" Margin="10,70,0,0" Grid.Column="1"/>
|
||||
<TextBox x:Name="DateInput" Grid.Column="2" Width="77" HorizontalAlignment="Left" Margin="0,70,10,0"/>
|
||||
<TextBox x:Name="DateInput" Grid.Column="2" Width="77" HorizontalAlignment="Left" Margin="0,70,10,0" IsReadOnly="True"/>
|
||||
|
||||
<Label Content="Überwiesen am:" Margin="10,100,0,0" Grid.Column="1"/>
|
||||
<TextBox x:Name="TransferDateInput" Grid.Column="2" Width="77" HorizontalAlignment="Left" Margin="0,100,10,0"/>
|
||||
<TextBox x:Name="TransferDateInput" Grid.Column="2" Width="77" HorizontalAlignment="Left" Margin="0,100,10,0"
|
||||
TextChanged="TransferDateInput_TextChanged"/>
|
||||
|
||||
<TextBox x:Name="DataInput" Margin="82,70,10,42" Grid.Column="2"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="auto"
|
||||
AcceptsReturn="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto"
|
||||
FontFamily="Cascadia Code Light" FontSize="13"
|
||||
TextChanged="DataInput_TextChanged"/>
|
||||
|
||||
<Button x:Name="SaveButton" Content="Speichern" Grid.Column="1" Grid.ColumnSpan="2"
|
||||
Click="SaveButton_Click"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Center" Width="100" Margin="10,10,325,10"/>
|
||||
<Button x:Name="CommitButton" Content="Festsetzen" Grid.Column="1" Grid.ColumnSpan="2"
|
||||
Click="CommitButton_Click"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Center" Width="100" Margin="10,10,115,10"/>
|
||||
<Button x:Name="RevertButton" Content="Freigeben" Grid.Column="1" Grid.ColumnSpan="2"
|
||||
Click="RevertButton_Click"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Center" Width="100" Margin="10,10,115,10"/>
|
||||
<Button x:Name="CalculateButton" Content="Berechnen" Grid.Column="1" Grid.ColumnSpan="2"
|
||||
Click="CalculateButton_Click"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="100" Margin="10,10,115,10"/>
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Center" Width="100" Margin="115,10,10,10"/>
|
||||
<Button x:Name="EditButton" Content="Bearbeiten" Grid.Column="1" Grid.ColumnSpan="2"
|
||||
Click="EditButton_Click"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="100" Margin="10,10,10,10"/>
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Center" Width="100" Margin="325,10,10,10"/>
|
||||
|
||||
<GroupBox Header="Abschluss" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="10,0,10,10">
|
||||
<Grid Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="250"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<GroupBox Header="Abschluss" Margin="10,0,5,10">
|
||||
<Grid>
|
||||
<Button x:Name="CommitButton" FontSize="12" Width="160" Height="40" Margin="0,0,10,55"
|
||||
Click="CommitButton_Click"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Right">
|
||||
<TextBlock TextAlignment="Center">Traubengutschriften<LineBreak/>erstellen</TextBlock>
|
||||
</Button>
|
||||
<Button x:Name="RevertButton" FontSize="12" Width="160" Height="40" Margin="0,0,10,10"
|
||||
Click="RevertButton_Click"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Right">
|
||||
<TextBlock TextAlignment="Center">Traubengutschriften<LineBreak/>löschen</TextBlock>
|
||||
</Button>
|
||||
<Button x:Name="ExportButton" Content="Exportieren" FontSize="14" Width="180" Margin="10,10,10,10" Height="27" IsEnabled="False"
|
||||
Click="ExportButton_Click"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left"/>
|
||||
|
||||
<ProgressBar x:Name="ProgressBar" Margin="10,0,0,74" Height="27" Width="180"
|
||||
<ProgressBar x:Name="ProgressBar" Margin="10,10,10,74" Height="27" Width="180"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
|
||||
<Button x:Name="ShowButton" Content="Vorschau" FontSize="14" Width="180" Margin="10,10,10,42" Height="27" Tag="Print" IsEnabled="False"
|
||||
Click="ShowButton_Click"
|
||||
@ -106,5 +124,38 @@
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Ergebnis" Margin="5,0,10,10" Grid.Column="1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.Resources>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Grid.Column" Value="1"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="TextAlignment" Value="Right"/>
|
||||
</Style>
|
||||
</Grid.Resources>
|
||||
|
||||
<Label Content="Zu-/Abschläge:" Margin="10,10,0,0"/>
|
||||
<TextBlock x:Name="ModifierSum" Margin="0,12,10,0"/>
|
||||
|
||||
<Label Content="Gesamtbeträge:" Margin="10,40,0,0"/>
|
||||
<TextBlock x:Name="TotalSum" Margin="0,42,10,0"/>
|
||||
|
||||
<Label Content="Mehrwertsteuer:" Margin="10,70,0,0"/>
|
||||
<TextBlock x:Name="VatSum" Margin="0,72,10,0"/>
|
||||
|
||||
<Label Content="Abzüge:" Margin="10,100,0,0"/>
|
||||
<TextBlock x:Name="DeductionSum" Margin="0,102,10,0"/>
|
||||
|
||||
<Label Content="Auszuzahlen:" Margin="10,130,0,0"/>
|
||||
<TextBlock x:Name="PaymentSum" Margin="0,132,10,0"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</local:ContextWindow>
|
||||
|
@ -11,16 +11,25 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Helpers.Export;
|
||||
using Microsoft.Win32;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class PaymentVariantsWindow : ContextWindow {
|
||||
|
||||
public readonly int Year;
|
||||
private bool DataValid, DataChanged, NameChanged, CommentChanged, TransferDateValid, TransferDateChanged;
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOpt = new() { WriteIndented = true };
|
||||
|
||||
public PaymentVariantsWindow(int year) {
|
||||
InitializeComponent();
|
||||
Year = year;
|
||||
Title = $"Auszahlungsvarianten - Lese {Year} - Elwig";
|
||||
if (!App.Config.Debug) {
|
||||
DataInput.Visibility = Visibility.Hidden;
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnRenewContext() {
|
||||
@ -34,26 +43,74 @@ namespace Elwig.Windows {
|
||||
DeleteButton.IsEnabled = !locked;
|
||||
CalculateButton.IsEnabled = !locked;
|
||||
CommitButton.IsEnabled = !locked;
|
||||
CommitButton.Visibility = !locked ? Visibility.Visible : Visibility.Hidden;
|
||||
RevertButton.IsEnabled = locked;
|
||||
RevertButton.Visibility = locked ? Visibility.Visible : Visibility.Hidden;
|
||||
CopyButton.IsEnabled = true;
|
||||
EditButton.IsEnabled = true;
|
||||
EditButton.Content = locked ? "Ansehen" : "Bearbeiten";
|
||||
ShowButton.IsEnabled = true;
|
||||
PrintButton.IsEnabled = true;
|
||||
ExportButton.IsEnabled = locked;
|
||||
|
||||
NameInput.Text = v.Name;
|
||||
CommentInput.Text = v.Comment;
|
||||
DateInput.Text = $"{v.Date:dd.MM.yyyy}";
|
||||
TransferDateInput.Text = $"{v.TransferDate:dd.MM.yyyy}";
|
||||
try {
|
||||
var json = BillingData.ParseJson(v.Data);
|
||||
DataInput.Text = JsonSerializer.Serialize(json, JsonOpt);
|
||||
} catch {
|
||||
DataInput.Text = v.Data;
|
||||
}
|
||||
} else {
|
||||
EditButton.IsEnabled = false;
|
||||
EditButton.Content = "Bearbeiten";
|
||||
CopyButton.IsEnabled = false;
|
||||
CalculateButton.IsEnabled = false;
|
||||
CommitButton.IsEnabled = false;
|
||||
CommitButton.Visibility = Visibility.Visible;
|
||||
RevertButton.IsEnabled = false;
|
||||
RevertButton.Visibility = Visibility.Hidden;
|
||||
DeleteButton.IsEnabled = false;
|
||||
ShowButton.IsEnabled = false;
|
||||
PrintButton.IsEnabled = false;
|
||||
ExportButton.IsEnabled = false;
|
||||
|
||||
NameInput.Text = "";
|
||||
CommentInput.Text = "";
|
||||
DateInput.Text = "";
|
||||
TransferDateInput.Text = "";
|
||||
DataInput.Text = "";
|
||||
}
|
||||
UpdateSums();
|
||||
UpdateSaveButton();
|
||||
}
|
||||
|
||||
private void UpdateSaveButton() {
|
||||
SaveButton.IsEnabled = PaymentVariantList.SelectedItem != null &&
|
||||
((DataChanged && DataValid) || NameChanged || CommentChanged ||
|
||||
(TransferDateChanged && TransferDateValid));
|
||||
}
|
||||
|
||||
private void UpdateSums() {
|
||||
if (PaymentVariantList.SelectedItem is PaymentVar v) {
|
||||
var sym = v.Season.Currency.Symbol;
|
||||
ModifierSum.Text = $"{v.DeliveryPartPayments.Sum(p => p.Amount - p.NetAmount):N2} {sym}";
|
||||
TotalSum.Text = $"{v.MemberPayments.Sum(p => p.Amount):N2} {sym}";
|
||||
if (v.Credits.Count == 0) {
|
||||
VatSum.Text = $"- {sym}";
|
||||
DeductionSum.Text = $"- {sym}";
|
||||
PaymentSum.Text = $"- {sym}";
|
||||
} else {
|
||||
VatSum.Text = $"{v.Credits.Sum(c => c.VatAmount):N2} {sym}";
|
||||
DeductionSum.Text = $"{-v.Credits.Sum(c => c.Modifiers ?? 0):N2} {sym}";
|
||||
PaymentSum.Text = $"{v.Credits.Sum(c => c.Amount):N2} {sym}";
|
||||
}
|
||||
} else {
|
||||
ModifierSum.Text = "-";
|
||||
TotalSum.Text = "-";
|
||||
VatSum.Text = "-";
|
||||
DeductionSum.Text = "-";
|
||||
PaymentSum.Text = "-";
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,8 +135,13 @@ namespace Elwig.Windows {
|
||||
return;
|
||||
CalculateButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
var b = new BillingVariant(v.Year, v.AvNr);
|
||||
await b.Calculate();
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Berechnungsfehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
await App.HintContextChange();
|
||||
Mouse.OverrideCursor = null;
|
||||
CalculateButton.IsEnabled = true;
|
||||
}
|
||||
@ -98,7 +160,7 @@ namespace Elwig.Windows {
|
||||
await Generate(2);
|
||||
}
|
||||
|
||||
private async void CommitButton_Click(object sender, RoutedEventArgs e) {
|
||||
private async void CommitButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedValue is not PaymentVar v)
|
||||
return;
|
||||
CommitButton.IsEnabled = false;
|
||||
@ -107,19 +169,140 @@ namespace Elwig.Windows {
|
||||
await b.Commit();
|
||||
Mouse.OverrideCursor = null;
|
||||
RevertButton.IsEnabled = true;
|
||||
await HintContextChange();
|
||||
await App.HintContextChange();
|
||||
}
|
||||
|
||||
private async void RevertButton_Click(object sender, RoutedEventArgs e) {
|
||||
private async void RevertButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedValue is not PaymentVar v)
|
||||
return;
|
||||
var res = MessageBox.Show(
|
||||
"Sollen wirklich alle festgesetzten Traubengutschriften der ausgewählten Auszahlungsvariante unwiderruflich gelöscht werden?\n\n" +
|
||||
"Dies ist im Allgemeinen nie empfohlen. Handelt es sich um die aktuellste Auszahlungsvariante könnte das eine Ausnahme sein.",
|
||||
"Traubengutschriften löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (res != MessageBoxResult.Yes)
|
||||
return;
|
||||
RevertButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
var b = new BillingVariant(v.Year, v.AvNr);
|
||||
await b.Revert();
|
||||
Mouse.OverrideCursor = null;
|
||||
CommitButton.IsEnabled = true;
|
||||
await App.HintContextChange();
|
||||
}
|
||||
|
||||
private async void ExportButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedValue 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;
|
||||
}
|
||||
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) {
|
||||
ExportButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
using var e = new Ebics(v, d.FileName);
|
||||
await e.ExportAsync(Transaction.FromPaymentVariant(v));
|
||||
Mouse.OverrideCursor = null;
|
||||
ExportButton.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async void SaveButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) return;
|
||||
try {
|
||||
v.Name = NameInput.Text;
|
||||
v.Comment = (CommentInput.Text != "") ? CommentInput.Text : null;
|
||||
v.TransferDateString = (TransferDateInput.Text != "") ? string.Join("-", TransferDateInput.Text.Split(".").Reverse()) : null;
|
||||
if (App.Config.Debug) v.Data = JsonSerializer.Serialize(BillingData.ParseJson(DataInput.Text));
|
||||
Context.Update(v);
|
||||
await Context.SaveChangesAsync();
|
||||
await App.HintContextChange();
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
private void NameInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
ControlUtils.ClearInputState(NameInput);
|
||||
return;
|
||||
}
|
||||
if (NameInput.Text != v.Name) {
|
||||
ControlUtils.SetInputChanged(NameInput);
|
||||
NameChanged = true;
|
||||
} else {
|
||||
ControlUtils.ClearInputState(NameInput);
|
||||
NameChanged = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
}
|
||||
|
||||
private void CommentInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
ControlUtils.ClearInputState(CommentInput);
|
||||
return;
|
||||
}
|
||||
if (CommentInput.Text != (v.Comment ?? "")) {
|
||||
ControlUtils.SetInputChanged(CommentInput);
|
||||
CommentChanged = true;
|
||||
} else {
|
||||
ControlUtils.ClearInputState(CommentInput);
|
||||
CommentChanged = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
}
|
||||
|
||||
private void TransferDateInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
ControlUtils.ClearInputState(TransferDateInput);
|
||||
return;
|
||||
}
|
||||
var res = Validator.CheckDate(TransferDateInput, false);
|
||||
if (!res.IsValid) {
|
||||
ControlUtils.SetInputInvalid(TransferDateInput);
|
||||
TransferDateValid = false;
|
||||
} else if (TransferDateInput.Text != $"{v.TransferDate:dd.MM.yyyy}") {
|
||||
ControlUtils.SetInputChanged(TransferDateInput);
|
||||
TransferDateValid = true;
|
||||
TransferDateChanged = true;
|
||||
} else {
|
||||
ControlUtils.ClearInputState(TransferDateInput);
|
||||
TransferDateValid = true;
|
||||
TransferDateChanged = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
}
|
||||
|
||||
private void DataInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (PaymentVariantList.SelectedItem is not PaymentVar v) {
|
||||
ControlUtils.ClearInputState(DataInput);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var json = BillingData.ParseJson(DataInput.Text);
|
||||
var origJson = BillingData.ParseJson(v.Data);
|
||||
DataValid = true;
|
||||
if (JsonSerializer.Serialize(json) != JsonSerializer.Serialize(origJson)) {
|
||||
ControlUtils.SetInputChanged(DataInput);
|
||||
DataChanged = true;
|
||||
} else {
|
||||
ControlUtils.ClearInputState(DataInput);
|
||||
DataChanged = false;
|
||||
}
|
||||
} catch {
|
||||
ControlUtils.SetInputInvalid(DataInput);
|
||||
DataValid = false;
|
||||
}
|
||||
UpdateSaveButton();
|
||||
}
|
||||
|
||||
private async Task Generate(int mode) {
|
||||
|
Reference in New Issue
Block a user