This commit is contained in:
2021-07-29 22:27:48 +00:00
parent 80ff52ef0c
commit 4bf86da75e

View File

@@ -5228,7 +5228,7 @@ namespace AyaNova.Biz
//Success
//Calculate next service date
DateTime dtNewNextServiceDate = CalculateNewDateFromSpanAndUnit(p.NextServiceDate, p.RepeatUnit, p.RepeatInterval);
DateTime NewNextServiceDate = CalculateNewDateFromSpanAndUnit(p.NextServiceDate, p.RepeatUnit, p.RepeatInterval);
//Check Exclusions and adjust
if ((int)p.ExcludeDaysOfWeek != 0)
@@ -5243,14 +5243,14 @@ namespace AyaNova.Biz
if (p.ExcludeDaysOfWeek.HasFlag(AyaDaysOfWeek.Saturday)) excluded.Add(DayOfWeek.Saturday);
if (p.ExcludeDaysOfWeek.HasFlag(AyaDaysOfWeek.Sunday)) excluded.Add(DayOfWeek.Sunday);
while (excluded.Contains(dtNewNextServiceDate.DayOfWeek))
dtNewNextServiceDate = dtNewNextServiceDate.AddDays(1);
while (excluded.Contains(NewNextServiceDate.DayOfWeek))
NewNextServiceDate = NewNextServiceDate.AddDays(1);
}
TimeSpan tsAdd = dtNewNextServiceDate - p.NextServiceDate;
TimeSpan tsAdd = NewNextServiceDate - p.NextServiceDate;
//Stop generating date reached??
if (p.StopGeneratingDate != null && p.StopGeneratingDate < dtNewNextServiceDate)
if (p.StopGeneratingDate != null && p.StopGeneratingDate < NewNextServiceDate)
{
p.Active = false;
await ct.SaveChangesAsync();
@@ -5258,7 +5258,28 @@ namespace AyaNova.Biz
return;
}
//add the new timespan to all dates in pm
//Re-schedule PM
p.NextServiceDate = NewNextServiceDate;
SetGenerateDate(p);
foreach (PMItem pmi in p.Items)
{
pmi.RequestDate = addts(pmi.RequestDate, tsAdd);
foreach (PMItemScheduledUser pmsu in pmi.ScheduledUsers)
{
pmsu.StartDate = addts(pmsu.StartDate, tsAdd);
pmsu.StopDate = addts(pmsu.StopDate, tsAdd);
}
foreach (PMItemLoan pml in pmi.Loans)
{
pml.DueDate = addts(pml.DueDate, tsAdd);
pml.OutDate = addts(pml.OutDate, tsAdd);
pml.ReturnDate = addts(pml.ReturnDate, tsAdd);
}
}
//note p is ready to modify and save here as it's tracked
@@ -5266,6 +5287,14 @@ namespace AyaNova.Biz
}
}
private static DateTime? addts(DateTime? dt, TimeSpan ts)
{
if (dt == null) return null;
return ((DateTime)dt).Add(ts);
}
internal static async Task<bool> NewServiceWorkOrderFromPMAsync(PM p, AyContext ct, ILogger log)
{