[#46] Windows: Add PaymentAdjustmentWindow
All checks were successful
Test / Run tests (push) Successful in 2m13s
All checks were successful
Test / Run tests (push) Successful in 2m13s
This commit is contained in:
92
Elwig/Windows/PaymentAdjustmentWindow.xaml.cs
Normal file
92
Elwig/Windows/PaymentAdjustmentWindow.xaml.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class PaymentAdjustmentWindow : ContextWindow {
|
||||
|
||||
public readonly int Year;
|
||||
public readonly bool SeasonLocked;
|
||||
|
||||
public PaymentAdjustmentWindow(int year) {
|
||||
InitializeComponent();
|
||||
Year = year;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
SeasonLocked = ctx.Seasons.Find(Year + 1) != null;
|
||||
}
|
||||
Title = $"Auszahlung anpassen - Lese {Year} - Elwig";
|
||||
}
|
||||
|
||||
protected override async Task OnRenewContext(AppDbContext ctx) {
|
||||
MemberList.ItemsSource = await ctx.MemberHistory
|
||||
.Where(h => h.DateString.CompareTo($"{Year}-01-01") >= 0 && h.DateString.CompareTo($"{Year}-12-31") <= 0 && h.Type == "auto" && h.BusinessShares > 0)
|
||||
.GroupBy(h => h.Member)
|
||||
.Select(h => new {
|
||||
h.Key.MgNr,
|
||||
h.Key.FamilyName,
|
||||
h.Key.GivenName,
|
||||
BusinessShares = h.Sum(g => g.BusinessShares),
|
||||
})
|
||||
.OrderBy(h => h.FamilyName)
|
||||
.ThenBy(h => h.GivenName)
|
||||
.ThenBy(h => h.MgNr)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private async void AutoAdjustBsButton_Click(object sender, RoutedEventArgs evt) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
int? kg = AllowanceKgInput.Text == "" ? null : int.Parse(AllowanceKgInput.Text);
|
||||
double? bs = AllowanceBsInput.Text == "" ? null : double.Parse(AllowanceBsInput.Text);
|
||||
int? kgPerBs = AllowanceKgPerBsInput.Text == "" ? null : int.Parse(AllowanceKgPerBsInput.Text);
|
||||
double? percent = AllowancePercentInput.Text == "" ? null : double.Parse(AllowancePercentInput.Text);
|
||||
int? minBs = MinBsInput.Text == "" ? null : int.Parse(MinBsInput.Text);
|
||||
|
||||
var b = new Billing(Year);
|
||||
await b.AutoAdjustBusinessShares(new DateOnly(Year, 11, 30), kg ?? default, bs ?? default, kgPerBs ?? default, percent / 100.0 ?? default, minBs ?? default);
|
||||
await App.HintContextChange();
|
||||
} 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;
|
||||
MessageBox.Show(str, "GA Nachzeichnen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
private async void UnAdjustBsButton_Click(object sender, RoutedEventArgs evt) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
var b = new Billing(Year);
|
||||
await b.UnAdjustBusinessShares();
|
||||
await App.HintContextChange();
|
||||
} 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;
|
||||
MessageBox.Show(str, "GA Nachzeichnen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
private void SeasonButton_Click(object sender, RoutedEventArgs evt) {
|
||||
App.FocusBaseDataSeason(Year);
|
||||
}
|
||||
|
||||
private void KgInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
Validator.CheckInteger((TextBox)sender, false, 6);
|
||||
}
|
||||
|
||||
private void BsInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
Validator.CheckInteger((TextBox)sender, false, 3);
|
||||
}
|
||||
|
||||
private void PercentInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
Validator.CheckDecimal((TextBox)sender, false, 3, 2);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user