Utils: Replace Utils.Today with DateTime.Today and adapt DeliveryService filters
Test / Run tests (push) Successful in 2m51s
Test / Run tests (push) Successful in 2m51s
This commit is contained in:
@@ -45,7 +45,7 @@ namespace Elwig.Services {
|
||||
deliveryAncmtQuery = deliveryAncmtQuery.Where(a => a.Year == s.Year && a.DsNr == s.DsNr);
|
||||
filterNames.Add($"{s.Date:dd.MM.yyyy} – {s.Branch.Name} – {s.Description}");
|
||||
} else {
|
||||
deliveryAncmtQuery = deliveryAncmtQuery.Where(a => a.Year == vm.FilterSeason && (!vm.FilterOnlyUpcoming || a.Schedule.DateString.CompareTo(Utils.Today.ToString("yyyy-MM-dd")) >= 0));
|
||||
deliveryAncmtQuery = deliveryAncmtQuery.Where(a => a.Year == vm.FilterSeason && (!vm.FilterOnlyUpcoming || a.Schedule.DateString.CompareTo(DateTime.Today.ToString("yyyy-MM-dd")) >= 0));
|
||||
filterNames.Add($"{vm.FilterSeason}");
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace Elwig.Services {
|
||||
filterNames.Add($"{vm.FilterSeason}");
|
||||
}
|
||||
if (vm.FilterOnlyUpcoming) {
|
||||
deliveryScheduleQuery = deliveryScheduleQuery.Where(s => s.DateString.CompareTo(Utils.Today.ToString("yyyy-MM-dd")) >= 0);
|
||||
filterNames.Add($"ab {Utils.Today:dd.MM.yyyy}");
|
||||
deliveryScheduleQuery = deliveryScheduleQuery.Where(s => s.DateString.CompareTo(DateTime.Today.ToString("yyyy-MM-dd")) >= 0);
|
||||
filterNames.Add($"ab {DateTime.Today:dd.MM.yyyy}");
|
||||
}
|
||||
|
||||
var filterVar = new List<string>();
|
||||
|
||||
@@ -72,6 +72,31 @@ namespace Elwig.Services {
|
||||
vm.ManualWeighingReason = p.WeighingReason;
|
||||
}
|
||||
|
||||
private static async Task<(Expression<Func<Delivery, bool>>, string)> GetFilterToday(AppDbContext ctx) {
|
||||
var today = DateTime.Today;
|
||||
var timestamps = (await ctx.Deliveries
|
||||
.Where(d => d.DateString.CompareTo(today.AddDays(-1).ToString("yyyy-MM-dd")) >= 0)
|
||||
.OrderBy(d => d.DateString).ThenBy(d => d.TimeString)
|
||||
.Select(d => d.DateString + " " + d.TimeString)
|
||||
.ToListAsync())
|
||||
.Select(s => DateTime.TryParseExact(s, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt) ? (DateTime?)dt : null)
|
||||
.Where(t => t.HasValue)
|
||||
.Cast<DateTime>()
|
||||
.ToArray();
|
||||
if (timestamps.Length > 0) {
|
||||
var latest = timestamps.Last();
|
||||
var since = timestamps.Cast<DateTime>().Reverse().Aggregate(latest, (s, c) => s.Subtract(c).TotalHours <= 6 ? c : s);
|
||||
latest += new TimeSpan(0, 1, -latest.Minute, -latest.Second, -latest.Millisecond, -latest.Microsecond);
|
||||
since += new TimeSpan(0, 0, -since.Minute, -since.Second, -since.Millisecond, -since.Microsecond);
|
||||
|
||||
return (d => (d.DateString == since.ToString("yyyy-MM-dd") && (d.TimeString == null || d.TimeString.CompareTo(since.ToString("HH:mm:ss")) >= 0)) ||
|
||||
(d.DateString.CompareTo(since.ToString("yyyy-MM-dd")) > 0),
|
||||
since.Date == latest.Date ? since.ToString("dd.MM.yyyy") : $"{since:dd.MM.yyyy \\a\\b HH:mm} / {latest:dd.MM.yyyy \\b\\i\\s HH:mm}");
|
||||
} else {
|
||||
return (_ => false, today.ToString("dd.MM.yyyy"));
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<(List<string>, IQueryable<Delivery>, IQueryable<DeliveryPart>, Predicate<DeliveryPart>, List<string>)> GetFilters(this DeliveryAdminViewModel vm, AppDbContext ctx) {
|
||||
List<string> filterNames = [];
|
||||
IQueryable<Delivery> deliveryQuery = ctx.Deliveries;
|
||||
@@ -84,10 +109,9 @@ namespace Elwig.Services {
|
||||
filterNames.Add(vm.FilterMember.AdministrativeName);
|
||||
}
|
||||
if (vm.FilterTodayOnly) {
|
||||
deliveryQuery = deliveryQuery
|
||||
.Where(d => (d.DateString == Utils.Today.ToString("yyyy-MM-dd") && (d.TimeString == null || d.TimeString.CompareTo("03:00:00") > 0)) ||
|
||||
(d.DateString == Utils.Today.AddDays(1).ToString("yyyy-MM-dd") && (d.TimeString == null || d.TimeString.CompareTo("03:00:00") <= 0)));
|
||||
filterNames.Add(Utils.Today.ToString("dd.MM.yyyy"));
|
||||
var (pred, name) = await GetFilterToday(ctx);
|
||||
deliveryQuery = deliveryQuery.Where(pred);
|
||||
filterNames.Add(name);
|
||||
} else if (!vm.FilterAllSeasons) {
|
||||
deliveryQuery = deliveryQuery.Where(d => d.Year == vm.FilterSeason);
|
||||
filterNames.Add($"{vm.FilterSeason}");
|
||||
@@ -730,10 +754,9 @@ namespace Elwig.Services {
|
||||
query = q;
|
||||
filterNames.AddRange(f);
|
||||
} else if (subject == ExportSubject.FromToday) {
|
||||
var date = $"{Utils.Today:yyyy-MM-dd}";
|
||||
query = ctx.DeliveryParts
|
||||
.Where(p => p.Delivery.DateString == date);
|
||||
filterNames.Add($"{Utils.Today:dd.MM.yyyy}");
|
||||
var (pred, name) = await GetFilterToday(ctx);
|
||||
query = ctx.Deliveries.Where(pred).SelectMany(d => d.Parts);
|
||||
filterNames.Add(name);
|
||||
} else if (subject == ExportSubject.FromSeasonAndBranch) {
|
||||
query = ctx.DeliveryParts
|
||||
.Where(p => p.Year == Utils.CurrentLastSeason && p.Delivery.ZwstId == App.ZwstId);
|
||||
@@ -805,10 +828,9 @@ namespace Elwig.Services {
|
||||
query = q;
|
||||
filterNames.AddRange(f);
|
||||
} else if (subject == ExportSubject.FromToday) {
|
||||
var date = $"{Utils.Today:yyyy-MM-dd}";
|
||||
query = ctx.DeliveryParts
|
||||
.Where(p => p.Delivery.DateString == date);
|
||||
filterNames.Add($"{Utils.Today:dd.MM.yyyy}");
|
||||
var (pred, name) = await GetFilterToday(ctx);
|
||||
query = ctx.Deliveries.Where(pred).SelectMany(d => d.Parts);
|
||||
filterNames.Add(name);
|
||||
} else {
|
||||
throw new ArgumentException("Invalid value for ExportSubject");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using Elwig.Models;
|
||||
using Elwig.Models.Entities;
|
||||
using Elwig.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -11,7 +12,7 @@ namespace Elwig.Services {
|
||||
|
||||
public static async Task InitInputs(this MemberBusinessSharesViewModel vm) {
|
||||
using var ctx = new AppDbContext();
|
||||
vm.DateNoticeString = $"{Utils.Today:dd.MM.yyyy}";
|
||||
vm.DateNoticeString = $"{DateTime.Today:dd.MM.yyyy}";
|
||||
vm.ValuePerShare = (await ctx.Seasons.OrderBy(s => s.Year).LastOrDefaultAsync())?.BusinessShareValue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user