This commit is contained in:
2021-05-10 22:09:21 +00:00
parent 7a0e12728d
commit 9abf0fb76b

View File

@@ -96,6 +96,7 @@ namespace AyaNova.Util
throw new System.NotSupportedException(msg); throw new System.NotSupportedException(msg);
} }
TimeZoneOffset = timeZoneOffset;
apiServerState.SetOpsOnly("Seeding database"); apiServerState.SetOpsOnly("Seeding database");
ServerBootConfig.SEEDING = true; ServerBootConfig.SEEDING = true;
@@ -528,6 +529,20 @@ namespace AyaNova.Util
long TCSales = 0, TCGoods = 0, TCBoth = 0; long TCSales = 0, TCGoods = 0, TCBoth = 0;
public Decimal TimeZoneOffset = 0;
//this is supposed to output the correct UTC
//value to save to db to match the desired time input
//taking into account the timezoneoffset specified for generating data
//so for example if the tzoffset is -7 utc and a input of 9:00am
//then it should figure out what 9am in a -7 time zone is in UTC
//and return that value
public DateTime DesiredTimeInUtc(DateTime dt)
{
return dt.AddHours(0 - (double)TimeZoneOffset);
}
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//Seed known / expected test data for tests/development //Seed known / expected test data for tests/development
// //
@@ -2421,15 +2436,19 @@ namespace AyaNova.Util
// //
public async Task SeedWorkOrderAsync(ILogger log, int count) public async Task SeedWorkOrderAsync(ILogger log, int count)
{ {
DateTime seedStartWindow = DateTime.Now.AddMonths(-9); DateTime seedStartWindow = DateTime.UtcNow.AddMonths(-9);
DateTime seedEndWindow = DateTime.Now.AddMonths(3); DateTime seedEndWindow = DateTime.UtcNow.AddMonths(3);
for (int x = 0; x < count; x++) for (int x = 0; x < count; x++)
{ {
WorkOrder o = new WorkOrder(); WorkOrder o = new WorkOrder();
o.Notes = Fake.Lorem.Sentence(); o.Notes = Fake.Lorem.Sentence();
o.Tags = RandomTags(); o.Tags = RandomTags();
var woDate = Fake.Date.Between(seedStartWindow, seedEndWindow); var tempDate = Fake.Date.Between(seedStartWindow, seedEndWindow);
o.CompleteByDate = woDate.AddDays(5).ToUniversalTime(); var tempHour=Fake.Random.Int(9,17);//9am to 5 pm (except some times may be in different dst state so this will be out by an hour for example depending on time of year and time zone in question)
var woDate = DesiredTimeInUtc(new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempHour, 0, 0));
o.CompleteByDate = woDate.AddDays(5);
o.CustomerContactName = "contact name here"; o.CustomerContactName = "contact name here";
o.CustomerId = Fake.Random.Long(1, TotalSeededCustomers); o.CustomerId = Fake.Random.Long(1, TotalSeededCustomers);
@@ -2467,7 +2486,7 @@ namespace AyaNova.Util
o.CustomerReferenceNumber = "crf-" + Fake.Finance.Account(4); o.CustomerReferenceNumber = "crf-" + Fake.Finance.Account(4);
o.InternalReferenceNumber = "irf-" + Fake.Finance.Account(4); o.InternalReferenceNumber = "irf-" + Fake.Finance.Account(4);
o.ServiceDate = woDate.ToUniversalTime(); o.ServiceDate = woDate;
int woItemCount = Fake.Random.Int(1, 6); int woItemCount = Fake.Random.Int(1, 6);
for (int y = 0; y < woItemCount; y++) for (int y = 0; y < woItemCount; y++)
@@ -2477,21 +2496,25 @@ namespace AyaNova.Util
Sequence = y + 1, Sequence = y + 1,
Notes = $"itemnotes - {y} ", Notes = $"itemnotes - {y} ",
TechNotes = $"technotes - {y}", TechNotes = $"technotes - {y}",
RequestDate = woDate.ToUniversalTime().AddMinutes(y) RequestDate = woDate.AddMinutes(y)
}; };
//add two users for testing //add two users for testing
var woItemScheduledUser = new WorkOrderItemScheduledUser() var woItemScheduledUser = new WorkOrderItemScheduledUser()
{ {
UserId = RandomServiceTechUserId(), UserId = RandomServiceTechUserId(),
EstimatedQuantity = 1 EstimatedQuantity = 1,
StartDate = woDate,
StopDate = woDate.AddHours(1)
}; };
woItem.ScheduledUsers.Add(woItemScheduledUser); woItem.ScheduledUsers.Add(woItemScheduledUser);
woItemScheduledUser = new WorkOrderItemScheduledUser() woItemScheduledUser = new WorkOrderItemScheduledUser()
{ {
UserId = RandomServiceTechUserId(), UserId = RandomServiceTechUserId(),
EstimatedQuantity = 2 EstimatedQuantity = 2,
StartDate = woDate,
StopDate = woDate.AddHours(1)
}; };
woItem.ScheduledUsers.Add(woItemScheduledUser); woItem.ScheduledUsers.Add(woItemScheduledUser);