Documents: Add DeliveryDepreciationList
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:
@ -24,7 +24,7 @@ namespace Elwig.Services {
|
||||
public static class DeliveryService {
|
||||
|
||||
public enum ExportSubject {
|
||||
FromFilters, FromToday, FromSeasonAndBranch, Selected,
|
||||
FromFilters, FromToday, FromSeason, FromSeasonAndBranch, Selected,
|
||||
};
|
||||
|
||||
public static async Task<Member?> GetMemberAsync(int mgnr) {
|
||||
@ -809,6 +809,71 @@ namespace Elwig.Services {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
public static async Task GenerateDeliveryDepreciationList(this DeliveryAdminViewModel vm, ExportSubject subject, ExportMode mode) {
|
||||
using var ctx = new AppDbContext();
|
||||
IQueryable<DeliveryPart> query;
|
||||
List<string> filterNames = [];
|
||||
if (subject == ExportSubject.FromFilters) {
|
||||
var (f, _, q, _, _) = await vm.GetFilters(ctx);
|
||||
query = q;
|
||||
filterNames.AddRange(f);
|
||||
} else if (subject == ExportSubject.FromSeason) {
|
||||
var year = vm.FilterSeason ?? Utils.CurrentLastSeason;
|
||||
query = ctx.DeliveryParts
|
||||
.Where(p => p.Year == year);
|
||||
filterNames.Add($"{year}");
|
||||
} else {
|
||||
throw new ArgumentException("Invalid value for ExportSubject");
|
||||
}
|
||||
|
||||
query = query
|
||||
.Where(p => p.QualId == "WEI")
|
||||
.OrderBy(p => p.Delivery.MgNr)
|
||||
.ThenBy(p => p.Delivery.DateString)
|
||||
.ThenBy(p => p.Delivery.TimeString)
|
||||
.ThenBy(p => p.Delivery.LsNr)
|
||||
.ThenBy(p => p.DPNr);
|
||||
filterNames.Remove("abgewertet");
|
||||
|
||||
if (mode == ExportMode.SaveList) {
|
||||
var d = new SaveFileDialog() {
|
||||
FileName = $"{DeliveryDepreciationList.Name}-{vm.FilterSeason ?? Utils.CurrentLastSeason}.ods",
|
||||
DefaultExt = "ods",
|
||||
Filter = "OpenDocument Format Spreadsheet (*.ods)|*.ods",
|
||||
Title = $"{DeliveryDepreciationList.Name} speichern unter - Elwig"
|
||||
};
|
||||
if (d.ShowDialog() == true) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
using var ods = new OdsFile(d.FileName);
|
||||
var tblTotal = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
tblTotal.FullName = DeliveryDepreciationList.Name;
|
||||
tblTotal.Name = "Gesamt";
|
||||
await ods.AddTable(tblTotal);
|
||||
foreach (var branch in await ctx.Branches.OrderBy(b => b.Name).ToListAsync()) {
|
||||
var tbl = await DeliveryJournalData.FromQuery(query.Where(p => p.Delivery.ZwstId == branch.ZwstId), filterNames);
|
||||
tbl.FullName = DeliveryDepreciationList.Name;
|
||||
tbl.Name = branch.Name;
|
||||
await ods.AddTable(tbl);
|
||||
}
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
var data = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
using var doc = new DeliveryDepreciationList(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddToolTipCell(Grid grid, string text, int row, int col, int colSpan = 1, bool bold = false, bool alignRight = false, bool alignCenter = false) {
|
||||
var tb = new TextBlock() {
|
||||
Text = text,
|
||||
|
Reference in New Issue
Block a user