Compare commits
3 Commits
v1.0.0.2
...
3aebcee324
Author | SHA1 | Date | |
---|---|---|---|
3aebcee324 | |||
4cc082d500 | |||
04761396e1 |
@@ -101,7 +101,7 @@
|
|||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<Button x:Name="SaveButton" Content="Speichern" IsEnabled="False"
|
<Button x:Name="SaveButton" Content="Speichern & Berechnen" IsEnabled="False"
|
||||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="10,5,35,10" Grid.Column="0" Grid.Row="2"
|
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="10,5,35,10" Grid.Column="0" Grid.Row="2"
|
||||||
Click="SaveButton_Click"/>
|
Click="SaveButton_Click"/>
|
||||||
|
|
||||||
|
@@ -651,6 +651,12 @@ namespace Elwig.Windows {
|
|||||||
ctx.Update(PaymentVar);
|
ctx.Update(PaymentVar);
|
||||||
await ctx.SaveChangesAsync();
|
await ctx.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
var b = new BillingVariant(PaymentVar.Year, PaymentVar.AvNr);
|
||||||
|
await b.Calculate();
|
||||||
|
} catch (Exception exc) {
|
||||||
|
MessageBox.Show(exc.Message, "Berechnungsfehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
LockContext = false;
|
LockContext = false;
|
||||||
App.HintContextChange();
|
App.HintContextChange();
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="clr-namespace:Elwig.Windows"
|
xmlns:local="clr-namespace:Elwig.Windows"
|
||||||
Title="Ausgangs-Protokoll - Rundschreiben - Elwig" Height="600" Width="1000">
|
Title="Ausgangs-Protokoll - Rundschreiben - Elwig" Height="600" Width="1000"
|
||||||
|
Loaded="Window_Loaded">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="3*"/>
|
<ColumnDefinition Width="3*"/>
|
||||||
|
@@ -2,6 +2,7 @@ using Elwig.Helpers;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace Elwig.Windows {
|
namespace Elwig.Windows {
|
||||||
@@ -18,8 +19,16 @@ namespace Elwig.Windows {
|
|||||||
FilterInput.TextChanged -= FilterInput_TextChanged;
|
FilterInput.TextChanged -= FilterInput_TextChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||||
|
await Load();
|
||||||
|
}
|
||||||
|
|
||||||
private async void TimeSpanInput_SelectionChanged(object sender, RoutedEventArgs evt) {
|
private async void TimeSpanInput_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||||
if (!IsLoaded) return;
|
if (!IsLoaded) return;
|
||||||
|
await Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Load() {
|
||||||
DateTime? fromDate = DateTime.Now;
|
DateTime? fromDate = DateTime.Now;
|
||||||
if (TimeSpanInput.SelectedIndex == 0) {
|
if (TimeSpanInput.SelectedIndex == 0) {
|
||||||
fromDate = fromDate.Value.AddDays(-7);
|
fromDate = fromDate.Value.AddDays(-7);
|
||||||
|
@@ -1,18 +1,18 @@
|
|||||||
|
using Elwig.Documents;
|
||||||
using Elwig.Helpers;
|
using Elwig.Helpers;
|
||||||
|
using Elwig.Helpers.Billing;
|
||||||
|
using Elwig.Helpers.Export;
|
||||||
using Elwig.Models.Dtos;
|
using Elwig.Models.Dtos;
|
||||||
using Elwig.Models.Entities;
|
using Elwig.Models.Entities;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Win32;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Elwig.Helpers.Billing;
|
|
||||||
using Elwig.Helpers.Export;
|
|
||||||
using Microsoft.Win32;
|
|
||||||
using System.Text.Json;
|
|
||||||
using Elwig.Documents;
|
|
||||||
|
|
||||||
namespace Elwig.Windows {
|
namespace Elwig.Windows {
|
||||||
public partial class PaymentVariantsWindow : ContextWindow {
|
public partial class PaymentVariantsWindow : ContextWindow {
|
||||||
@@ -123,6 +123,15 @@ namespace Elwig.Windows {
|
|||||||
ConsiderAutoInput.IsEnabled = !locked;
|
ConsiderAutoInput.IsEnabled = !locked;
|
||||||
ConsiderCustomInput.IsEnabled = !locked;
|
ConsiderCustomInput.IsEnabled = !locked;
|
||||||
DataInput.IsReadOnly = locked;
|
DataInput.IsReadOnly = locked;
|
||||||
|
|
||||||
|
ModifierSum.Text = "...";
|
||||||
|
TotalSum.Text = "...";
|
||||||
|
VatSum.Text = "...";
|
||||||
|
DeductionSum.Text = "...";
|
||||||
|
PaymentSum.Text = "...";
|
||||||
|
Utils.RunBackground("Variantendaten laden", async () => {
|
||||||
|
await UpdateSums(v);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
EditButton.Content = "Bearbeiten";
|
EditButton.Content = "Bearbeiten";
|
||||||
EditButton.IsEnabled = false;
|
EditButton.IsEnabled = false;
|
||||||
@@ -167,8 +176,14 @@ namespace Elwig.Windows {
|
|||||||
ConsiderCustomInput.IsEnabled = false;
|
ConsiderCustomInput.IsEnabled = false;
|
||||||
DataInput.Text = "";
|
DataInput.Text = "";
|
||||||
DataInput.IsReadOnly = true;
|
DataInput.IsReadOnly = true;
|
||||||
|
|
||||||
|
ModifierSum.Text = "-";
|
||||||
|
TotalSum.Text = "-";
|
||||||
|
VatSum.Text = "-";
|
||||||
|
DeductionSum.Text = "-";
|
||||||
|
PaymentSum.Text = "-";
|
||||||
}
|
}
|
||||||
await UpdateSums();
|
|
||||||
UpdateSaveButton();
|
UpdateSaveButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,37 +202,80 @@ namespace Elwig.Windows {
|
|||||||
CommitButton.IsEnabled = CalculateButton.IsEnabled;
|
CommitButton.IsEnabled = CalculateButton.IsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateSums() {
|
private async Task UpdateSums(PaymentVar v) {
|
||||||
if (PaymentVariantList.SelectedItem is PaymentVar v) {
|
if (App.MainDispatcher == null)
|
||||||
using var ctx = new AppDbContext();
|
return;
|
||||||
var sym = v.Season.Currency.Symbol ?? v.Season.Currency.Code;
|
var modText = "-";
|
||||||
var modSum = await ctx.PaymentDeliveryParts
|
var totalText = "-";
|
||||||
.Where(p => p.Year == v.Year && p.AvNr == v.AvNr)
|
var vatText = "-";
|
||||||
.SumAsync(p => p.AmountValue - p.NetAmountValue);
|
var deductionText = "-";
|
||||||
ModifierSum.Text = $"{v.Season.DecFromDb(modSum):N2} {sym}";
|
var paymentText = "-";
|
||||||
var totalSum = await ctx.MemberPayments
|
|
||||||
.Where(p => p.Year == v.Year && p.AvNr == v.AvNr)
|
using var ctx = new AppDbContext();
|
||||||
.SumAsync(p => p.AmountValue);
|
var sym = v.Season.Currency.Symbol ?? v.Season.Currency.Code;
|
||||||
TotalSum.Text = $"{v.Season.DecFromDb(totalSum):N2} {sym}";
|
|
||||||
var credits = ctx.Credits.Where(c => c.Year == v.Year && c.AvNr == v.AvNr);
|
var modSum = await ctx.PaymentDeliveryParts
|
||||||
if (!credits.Any()) {
|
.Where(p => p.Year == v.Year && p.AvNr == v.AvNr)
|
||||||
VatSum.Text = $"- {sym}";
|
.SumAsync(p => p.AmountValue - p.NetAmountValue);
|
||||||
DeductionSum.Text = $"- {sym}";
|
modText = $"{v.Season.DecFromDb(modSum):N2} {sym}";
|
||||||
PaymentSum.Text = $"- {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 {
|
} else {
|
||||||
// all values in the credit table are stored with precision 2!
|
vatSum = currentPayments.Sum(e => e.Value.Amount * (decimal)(e.Value.Member.IsBuchführend ? v.Season.VatNormal : v.Season.VatFlatrate));
|
||||||
TotalSum.Text = $"{Utils.DecFromDb(await credits.SumAsync(c => c.NetAmountValue), 2):N2} {sym}";
|
|
||||||
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}";
|
|
||||||
}
|
}
|
||||||
|
vatText = $"~{vatSum:N2} {sym}";
|
||||||
|
deductionText = $"- {sym}";
|
||||||
|
paymentText = $"~{v.Season.DecFromDb(totalSum - lastTotalSum) + vatSum:N2} {sym}";
|
||||||
} else {
|
} else {
|
||||||
ModifierSum.Text = "-";
|
// all values in the credit table are stored with precision 2!
|
||||||
TotalSum.Text = "-";
|
totalText = $"{Utils.DecFromDb(await credits.SumAsync(c => c.NetAmountValue), 2):N2} {sym}";
|
||||||
VatSum.Text = "-";
|
vatText = $"{Utils.DecFromDb(await credits.SumAsync(c => c.VatAmountValue), 2):N2} {sym}";
|
||||||
DeductionSum.Text = "-";
|
deductionText = $"{-Utils.DecFromDb(await credits.SumAsync(c => c.ModifiersValue ?? 0), 2):N2} {sym}";
|
||||||
PaymentSum.Text = "-";
|
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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void PaymentVariantList_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
private async void PaymentVariantList_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||||
|
Reference in New Issue
Block a user