This commit is contained in:
1 parent
677217d3cc
commit
a3ca0de95b
42 files changed
+387
-387
No files matched your search
@@ -8,9 +8,9 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Elwig.Services {
|
||||
public static class AreaComService {
|
||||
public static class AreaCmtService {
|
||||
|
||||
public static async Task InitInputs(this AreaComAdminViewModel vm) {
|
||||
public static async Task InitInputs(this AreaCmtAdminViewModel vm) {
|
||||
using var ctx = new AppDbContext();
|
||||
vm.FbNr = await ctx.NextFbNr();
|
||||
vm.MgNr = vm.FilterMember.MgNr;
|
||||
@@ -18,11 +18,11 @@ namespace Elwig.Services {
|
||||
vm.WineCult = null;
|
||||
}
|
||||
|
||||
public static void ClearInputs(this AreaComAdminViewModel vm) {
|
||||
public static void ClearInputs(this AreaCmtAdminViewModel vm) {
|
||||
vm.Period = null;
|
||||
}
|
||||
|
||||
public static void FillInputs(this AreaComAdminViewModel vm, AreaComContract c) {
|
||||
public static void FillInputs(this AreaCmtAdminViewModel vm, AreaCmtContract c) {
|
||||
vm.FbNr = c.FbNr;
|
||||
vm.Period = c.YearTo == null ? $"ab {c.YearFrom}" : $"{c.YearFrom}\u2013{c.YearTo}";
|
||||
vm.Comment = c.Comment;
|
||||
@@ -30,23 +30,23 @@ namespace Elwig.Services {
|
||||
vm.Rd = ControlUtils.GetItemFromSourceWithPk(vm.RdSource, c.KgNr, c.RdNr) as WbRd;
|
||||
}
|
||||
|
||||
public static void FillInputs(this AreaComAdminViewModel vm, AreaCom a) {
|
||||
public static void FillInputs(this AreaCmtAdminViewModel vm, AreaCmt a) {
|
||||
vm.MgNr = a.MgNr;
|
||||
vm.YearFrom = a.YearFrom;
|
||||
vm.YearTo = a.YearTo;
|
||||
vm.AreaComType = ControlUtils.GetItemFromSourceWithPk(vm.AreaComTypeSource, a.VtrgId) as AreaComType;
|
||||
vm.AreaCmtType = ControlUtils.GetItemFromSourceWithPk(vm.AreaCmtTypeSource, a.VtrgId) as AreaCmtType;
|
||||
vm.WineCult = ControlUtils.GetItemFromSourceWithPk(vm.WineCultSource, a.CultId) as WineCult;
|
||||
vm.GstNr = a.GstNr;
|
||||
vm.Area = a.Area;
|
||||
}
|
||||
|
||||
public static async Task<(List<string>, IQueryable<AreaComContract>, IQueryable<AreaCom>, List<string>)> GetFilters(this AreaComAdminViewModel vm, AppDbContext ctx) {
|
||||
public static async Task<(List<string>, IQueryable<AreaCmtContract>, IQueryable<AreaCmt>, List<string>)> GetFilters(this AreaCmtAdminViewModel vm, AppDbContext ctx) {
|
||||
List<string> filterNames = [];
|
||||
IQueryable<AreaCom> areaComQuery = ctx.AreaCommitments.Where(a => a.MgNr == vm.FilterMember.MgNr).OrderBy(a => a.FbNr);
|
||||
IQueryable<AreaCmt> areaCmtQuery = ctx.AreaCommitments.Where(a => a.MgNr == vm.FilterMember.MgNr).OrderBy(a => a.FbNr);
|
||||
filterNames.Add(vm.FilterMember.AdministrativeName);
|
||||
|
||||
if (vm.FilterSeason is int season) {
|
||||
areaComQuery = Utils.ActiveAreaCommitments(areaComQuery, season);
|
||||
areaCmtQuery = Utils.ActiveAreaCommitments(areaCmtQuery, season);
|
||||
filterNames.Add($"laufend {season}");
|
||||
}
|
||||
|
||||
@@ -96,37 +96,37 @@ namespace Elwig.Services {
|
||||
}
|
||||
}
|
||||
|
||||
if (filterVar.Count > 0) areaComQuery = areaComQuery.Where(a => filterVar.Contains(a.AreaComType.WineVar.SortId));
|
||||
if (filterNotVar.Count > 0) areaComQuery = areaComQuery.Where(a => !filterNotVar.Contains(a.AreaComType.WineVar.SortId));
|
||||
if (filterAttr.Count > 0) areaComQuery = areaComQuery.Where(a => a.AreaComType.WineAttr!.AttrId != null && filterAttr.Contains(a.AreaComType.WineAttr.AttrId));
|
||||
if (filterNotAttr.Count > 0) areaComQuery = areaComQuery.Where(a => a.AreaComType.WineAttr!.AttrId == null || !filterNotAttr.Contains(a.AreaComType.WineAttr.AttrId));
|
||||
if (filterVar.Count > 0) areaCmtQuery = areaCmtQuery.Where(a => filterVar.Contains(a.AreaCmtType.WineVar.SortId));
|
||||
if (filterNotVar.Count > 0) areaCmtQuery = areaCmtQuery.Where(a => !filterNotVar.Contains(a.AreaCmtType.WineVar.SortId));
|
||||
if (filterAttr.Count > 0) areaCmtQuery = areaCmtQuery.Where(a => a.AreaCmtType.WineAttr!.AttrId != null && filterAttr.Contains(a.AreaCmtType.WineAttr.AttrId));
|
||||
if (filterNotAttr.Count > 0) areaCmtQuery = areaCmtQuery.Where(a => a.AreaCmtType.WineAttr!.AttrId == null || !filterNotAttr.Contains(a.AreaCmtType.WineAttr.AttrId));
|
||||
}
|
||||
|
||||
IQueryable<AreaComContract> contracts = areaComQuery
|
||||
IQueryable<AreaCmtContract> contracts = areaCmtQuery
|
||||
.Select(c => c.Contract).Distinct()
|
||||
.OrderBy(c => c.FbNr);
|
||||
|
||||
return (filterNames, contracts, areaComQuery, filter);
|
||||
return (filterNames, contracts, areaCmtQuery, filter);
|
||||
}
|
||||
|
||||
public static async Task<(int FbNr, int RevNr)> UpdateAreaCommitment(this AreaComAdminViewModel vm, int? oldFbNr, int? revNr) {
|
||||
public static async Task<(int FbNr, int RevNr)> UpdateAreaCommitment(this AreaCmtAdminViewModel vm, int? oldFbNr, int? revNr) {
|
||||
int newFbNr = vm.FbNr!.Value;
|
||||
|
||||
return await Task.Run(async () => {
|
||||
using var ctx = new AppDbContext();
|
||||
var c = new AreaComContract {
|
||||
var c = new AreaCmtContract {
|
||||
FbNr = oldFbNr ?? newFbNr,
|
||||
Comment = string.IsNullOrWhiteSpace(vm.Comment) ? null : vm.Comment,
|
||||
KgNr = vm.Kg!.KgNr,
|
||||
RdNr = vm.Rd?.RdNr,
|
||||
};
|
||||
var a = new AreaCom {
|
||||
var a = new AreaCmt {
|
||||
FbNr = oldFbNr ?? newFbNr,
|
||||
RevNr = revNr ?? await ctx.NextRevNr(oldFbNr ?? newFbNr),
|
||||
MgNr = vm.MgNr!.Value,
|
||||
YearFrom = vm.YearFrom,
|
||||
YearTo = vm.YearTo,
|
||||
VtrgId = vm.AreaComType!.VtrgId,
|
||||
VtrgId = vm.AreaCmtType!.VtrgId,
|
||||
CultId = vm.WineCult?.CultId,
|
||||
GstNr = vm.GstNr?.Trim() ?? "-",
|
||||
Area = vm.Area!.Value,
|
||||
@@ -168,53 +168,53 @@ namespace Elwig.Services {
|
||||
grid.AddToolTipCell(max == null ? "" : $"{max:N0} kg", row, 4, bold: bold, alignRight: true);
|
||||
}
|
||||
|
||||
public static async Task<(string, (string?, string?, int, int?, int?)[])> GenerateToolTipData(IQueryable<AreaCom> areaComs, int maxKgPerHa) {
|
||||
public static async Task<(string, (string?, string?, int, int?, int?)[])> GenerateToolTipData(IQueryable<AreaCmt> areaCmts, int maxKgPerHa) {
|
||||
var grid = new List<(string?, string?, int, int?, int?)>();
|
||||
var text = "-";
|
||||
|
||||
var area = await areaComs.SumAsync(p => p.Area);
|
||||
var area = await areaCmts.SumAsync(p => p.Area);
|
||||
text = $"{area:N0} m²";
|
||||
grid.Add(("Geb. Fläche", null, area, null, null));
|
||||
|
||||
if (await areaComs.AnyAsync()) {
|
||||
var attrGroups = await areaComs
|
||||
.Where(c => c.AreaComType.WineAttr != null)
|
||||
.GroupBy(c => c.AreaComType.WineAttr!.Name)
|
||||
if (await areaCmts.AnyAsync()) {
|
||||
var attrGroups = await areaCmts
|
||||
.Where(c => c.AreaCmtType.WineAttr != null)
|
||||
.GroupBy(c => c.AreaCmtType.WineAttr!.Name)
|
||||
.Select(g => new {
|
||||
Attr = g.Key,
|
||||
Area = g.Sum(c => c.Area),
|
||||
Min = g.Sum(c => c.Area * (c.AreaComType.MinKgPerHa ?? 0) / 10_000),
|
||||
Max = g.Sum(c => c.Area * (c.AreaComType.WineAttr!.MaxKgPerHa ?? maxKgPerHa) / 10_000),
|
||||
Min = g.Sum(c => c.Area * (c.AreaCmtType.MinKgPerHa ?? 0) / 10_000),
|
||||
Max = g.Sum(c => c.Area * (c.AreaCmtType.WineAttr!.MaxKgPerHa ?? maxKgPerHa) / 10_000),
|
||||
})
|
||||
.OrderByDescending(g => g.Area)
|
||||
.ThenBy(g => g.Attr)
|
||||
.ToListAsync();
|
||||
var groups = await areaComs
|
||||
.Where(c => c.AreaComType.WineAttr != null)
|
||||
var groups = await areaCmts
|
||||
.Where(c => c.AreaCmtType.WineAttr != null)
|
||||
.GroupBy(c => new {
|
||||
Attr = c.AreaComType.WineAttr!.Name,
|
||||
c.AreaComType.SortId,
|
||||
Attr = c.AreaCmtType.WineAttr!.Name,
|
||||
c.AreaCmtType.SortId,
|
||||
})
|
||||
.Select(g => new {
|
||||
g.Key.Attr,
|
||||
g.Key.SortId,
|
||||
Area = g.Sum(c => c.Area),
|
||||
Min = g.Sum(c => c.Area * (c.AreaComType.MinKgPerHa ?? 0) / 10_000),
|
||||
Max = g.Sum(c => c.Area * (c.AreaComType.WineAttr!.MaxKgPerHa ?? maxKgPerHa) / 10_000),
|
||||
Min = g.Sum(c => c.Area * (c.AreaCmtType.MinKgPerHa ?? 0) / 10_000),
|
||||
Max = g.Sum(c => c.Area * (c.AreaCmtType.WineAttr!.MaxKgPerHa ?? maxKgPerHa) / 10_000),
|
||||
})
|
||||
.OrderByDescending(g => g.Area)
|
||||
.ThenBy(g => g.Attr)
|
||||
.ThenBy(g => g.SortId)
|
||||
.ToListAsync();
|
||||
|
||||
var noAttr = await areaComs
|
||||
.Where(c => c.AreaComType.WineAttr == null || !c.AreaComType.WineAttr.IsStrict)
|
||||
.GroupBy(c => c.AreaComType.SortId)
|
||||
var noAttr = await areaCmts
|
||||
.Where(c => c.AreaCmtType.WineAttr == null || !c.AreaCmtType.WineAttr.IsStrict)
|
||||
.GroupBy(c => c.AreaCmtType.SortId)
|
||||
.Select(g => new {
|
||||
SortId = g.Key,
|
||||
Area = g.Sum(c => c.Area),
|
||||
Min = g.Sum(c => c.Area * (c.AreaComType.MinKgPerHa ?? 0) / 10_000),
|
||||
Max = g.Sum(c => c.Area * (c.AreaComType.WineAttr!.MaxKgPerHa ?? maxKgPerHa) / 10_000),
|
||||
Min = g.Sum(c => c.Area * (c.AreaCmtType.MinKgPerHa ?? 0) / 10_000),
|
||||
Max = g.Sum(c => c.Area * (c.AreaCmtType.WineAttr!.MaxKgPerHa ?? maxKgPerHa) / 10_000),
|
||||
})
|
||||
.OrderByDescending(g => g.Area)
|
||||
.ThenBy(g => g.SortId)
|
||||
@@ -254,7 +254,7 @@ namespace Elwig.Services {
|
||||
return grid;
|
||||
}
|
||||
|
||||
public static async Task DeleteAreaCom(int fbnr) {
|
||||
public static async Task DeleteAreaCmt(int fbnr) {
|
||||
await Task.Run(async () => {
|
||||
using var ctx = new AppDbContext();
|
||||
var l = (await ctx.AreaCommitmentContracts.FindAsync(fbnr))!;
|
||||
@@ -263,7 +263,7 @@ namespace Elwig.Services {
|
||||
});
|
||||
}
|
||||
|
||||
public static async Task DeleteAreaComRevision(int fbnr, int revnr) {
|
||||
public static async Task DeleteAreaCmtRevision(int fbnr, int revnr) {
|
||||
await Task.Run(async () => {
|
||||
using var ctx = new AppDbContext();
|
||||
var l = (await ctx.AreaCommitments.FindAsync(fbnr, revnr))!;
|
||||
|
||||
Reference in new issue
Block a user