[#46] PaymentAdjustmentWindow: Refine DataGrid
All checks were successful
Test / Run tests (push) Successful in 1m55s
All checks were successful
Test / Run tests (push) Successful in 1m55s
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Models.Dtos;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@ -24,19 +26,55 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
protected override async Task OnRenewContext(AppDbContext ctx) {
|
||||
MemberList.ItemsSource = await ctx.MemberHistory
|
||||
var members = await ctx.Members
|
||||
.Select(m => new {
|
||||
m.MgNr,
|
||||
m.FamilyName,
|
||||
m.GivenName,
|
||||
m.BusinessShares,
|
||||
})
|
||||
.OrderBy(m => m.FamilyName)
|
||||
.ThenBy(m => m.GivenName)
|
||||
.ThenBy(m => m.MgNr)
|
||||
.ToListAsync();
|
||||
var season = (await ctx.Seasons.FindAsync(Year))!;
|
||||
|
||||
var tbl = await OverUnderDeliveryData.ForSeason(ctx.OverUnderDeliveryRows, Year);
|
||||
var weight = tbl.Rows.ToDictionary(r => r.MgNr, r => r.Weight);
|
||||
|
||||
var history = 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),
|
||||
.ToDictionaryAsync(h => h.Key.MgNr, h => h.Sum(g => g.BusinessShares));
|
||||
|
||||
var list = members
|
||||
.Select(m => new {
|
||||
m.MgNr,
|
||||
m.FamilyName,
|
||||
m.GivenName,
|
||||
BusinessShares = m.BusinessShares - history.GetValueOrDefault(m.MgNr, 0),
|
||||
DeliveryObligation = (m.BusinessShares - history.GetValueOrDefault(m.MgNr, 0)) * season.MinKgPerBusinessShare,
|
||||
DeliveryRight = (m.BusinessShares - history.GetValueOrDefault(m.MgNr, 0)) * season.MaxKgPerBusinessShare,
|
||||
})
|
||||
.OrderBy(h => h.FamilyName)
|
||||
.ThenBy(h => h.GivenName)
|
||||
.ThenBy(h => h.MgNr)
|
||||
.ToListAsync();
|
||||
.Select(m => new {
|
||||
m.MgNr,
|
||||
m.FamilyName,
|
||||
m.GivenName,
|
||||
m.BusinessShares,
|
||||
OverUnder = weight.TryGetValue(m.MgNr, out int v1) ?
|
||||
(v1 < m.DeliveryObligation ? (int?)v1 - m.DeliveryObligation :
|
||||
v1 > m.DeliveryRight ? (int?)v1 - m.DeliveryRight : null)
|
||||
: null,
|
||||
Adjust = history.TryGetValue(m.MgNr, out int v2) ? (int?)v2 : null
|
||||
})
|
||||
.Where(m => m.OverUnder != null || m.Adjust != null)
|
||||
.OrderByDescending(m => m.OverUnder)
|
||||
.ThenBy(m => m.FamilyName)
|
||||
.ThenBy(m => m.GivenName)
|
||||
.ThenBy(m => m.MgNr)
|
||||
.ToList();
|
||||
|
||||
MemberList.ItemsSource = list;
|
||||
}
|
||||
|
||||
private async void AutoAdjustBsButton_Click(object sender, RoutedEventArgs evt) {
|
||||
|
Reference in New Issue
Block a user