DeliveryAdminWindow: Fix extraction error
All checks were successful
Test / Run tests (push) Successful in 1m47s

This commit is contained in:
2024-09-25 22:51:06 +02:00
parent 4a7c95e250
commit 8a61747538
3 changed files with 8 additions and 6 deletions

View File

@ -203,10 +203,10 @@ namespace Elwig.Helpers {
return c + 1;
}
public async Task<int> NextLNr(DateOnly date) {
public async Task<int> NextLNr(DateOnly date, string zwstid) {
var dateStr = date.ToString("yyyy-MM-dd");
int c = 0;
(await Deliveries.Where(d => d.DateString == dateStr).Select(d => d.LNr).ToListAsync())
(await Deliveries.Where(d => d.DateString == dateStr && d.ZwstId == zwstid).Select(d => d.LNr).ToListAsync())
.ForEach(a => { if (a <= c + 100) c = a; });
return c + 1;
}

View File

@ -443,7 +443,7 @@ namespace Elwig.Services {
var originalMemberKgNr = oldDelivery?.Member.DefaultKgNr;
var date = DateOnly.ParseExact(vm.Date!, "dd.MM.yyyy");
int? newLnr = (deliveryNew || dateHasChanged) ? await ctx.NextLNr(date) : null;
int? newLnr = (deliveryNew || dateHasChanged) ? await ctx.NextLNr(date, vm.Branch!.ZwstId) : null;
string? newLsNr = (newLnr != null) ? Utils.GenerateLsNr(date, vm.Branch!.ZwstId, newLnr.Value) : null;
string? newTimeString = null;

View File

@ -1072,7 +1072,8 @@ namespace Elwig.Windows {
try {
using var ctx = new AppDbContext();
if (res == "new") {
var lnr = await ctx.NextLNr(delivery.Date);
var lnr = await ctx.NextLNr(delivery.Date, delivery.ZwstId);
var lsnr = Utils.GenerateLsNr(delivery.Date, delivery.ZwstId, lnr);
ctx.Add(new Delivery {
Year = p.Year,
DId = await ctx.NextDId(p.Year),
@ -1082,9 +1083,10 @@ namespace Elwig.Windows {
ZwstId = delivery.ZwstId,
MgNr = delivery.MgNr,
Comment = delivery.Comment,
LsNr = Utils.GenerateLsNr(delivery.Date, delivery.ZwstId, lnr),
LsNr = lsnr,
});
await ctx.SaveChangesAsync();
res = lsnr;
}
Delivery? d = await ctx.Deliveries.Where(d => d.LsNr == res).FirstOrDefaultAsync();
if (d == null) return;
@ -1235,7 +1237,7 @@ namespace Elwig.Windows {
var branch = (Branch)BranchInput.SelectedItem;
var date = DateOnly.ParseExact(ViewModel.Date!, "dd.MM.yyyy");
using var ctx = new AppDbContext();
var lnr = await ctx.NextLNr(date);
var lnr = await ctx.NextLNr(date, branch.ZwstId);
ViewModel.LsNr = Utils.GenerateLsNr(date, branch.ZwstId, lnr);
} catch {
ViewModel.LsNr = "";