This commit is contained in:
2021-05-28 19:48:07 +00:00
parent 20fde18014
commit ca1f92a53c
2 changed files with 63 additions and 62 deletions

View File

@@ -80,7 +80,10 @@ namespace AyaNova.Biz
if (newObject.Items.Count > 0)//our front end will post the header alone on new so this indicates a fully populated wo was saved if (newObject.Items.Count > 0)//our front end will post the header alone on new so this indicates a fully populated wo was saved
{ {
await GetCurrentContractFromContractIdAsync(newObject.ContractId); await GetCurrentContractFromContractIdAsync(newObject.ContractId);
await ProcessChangeOfContractAsync(newObject.Id);
if (mContractInEffect != null && mContractInEffect.ResponseTime != TimeSpan.Zero)
newObject.CompleteByDate = DateTime.UtcNow.Add(mContractInEffect.ResponseTime);
//GRANDCHILD BIZ ACTIONS //GRANDCHILD BIZ ACTIONS
foreach (WorkOrderItem wi in newObject.Items) foreach (WorkOrderItem wi in newObject.Items)
@@ -166,7 +169,7 @@ namespace AyaNova.Biz
//https://docs.microsoft.com/en-us/ef/core/querying/related-data //https://docs.microsoft.com/en-us/ef/core/querying/related-data
//docs say this will not query twice but will recognize the duplicate woitem bit which is required for multiple grandchild collections //docs say this will not query twice but will recognize the duplicate woitem bit which is required for multiple grandchild collections
var ret = var ret =
await ct.WorkOrder.AsNoTracking() await ct.WorkOrder.AsSplitQuery().AsNoTracking()
.Include(s => s.States) .Include(s => s.States)
.Include(w => w.Items.OrderBy(item => item.Sequence)) .Include(w => w.Items.OrderBy(item => item.Sequence))
.ThenInclude(wi => wi.Expenses) .ThenInclude(wi => wi.Expenses)
@@ -190,6 +193,7 @@ namespace AyaNova.Biz
.ThenInclude(wi => wi.OutsideServices) .ThenInclude(wi => wi.OutsideServices)
.SingleOrDefaultAsync(z => z.Id == id); .SingleOrDefaultAsync(z => z.Id == id);
//todo: set isLocked from state //todo: set isLocked from state
var stat = await GetCurrentWorkOrderStatusFromRelatedAsync(BizType, ret.Id); var stat = await GetCurrentWorkOrderStatusFromRelatedAsync(BizType, ret.Id);
ret.IsLockedAtServer = stat.Locked; ret.IsLockedAtServer = stat.Locked;
@@ -235,12 +239,13 @@ namespace AyaNova.Biz
return null; return null;
await WorkOrderBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null); await WorkOrderBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
bool contractChanged = false;
long? newContractId = null; long? newContractId = null;
if (putObject.ContractId != dbObject.ContractId)//manual change of contract if (putObject.ContractId != dbObject.ContractId)//manual change of contract
{ {
contractChanged = true;
newContractId = putObject.ContractId; newContractId = putObject.ContractId;
await GetCurrentContractFromContractIdAsync(newContractId);
if (mContractInEffect != null && mContractInEffect.ResponseTime != TimeSpan.Zero)
putObject.CompleteByDate = DateTime.UtcNow.Add(mContractInEffect.ResponseTime);
} }
ct.Replace(dbObject, putObject); ct.Replace(dbObject, putObject);
@@ -259,11 +264,6 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
await WorkOrderSearchIndexAsync(putObject, false); await WorkOrderSearchIndexAsync(putObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
if (contractChanged)
{
await GetCurrentContractFromContractIdAsync(newContractId);
await ProcessChangeOfContractAsync(putObject.Id);
}
await WorkOrderPopulateVizFields(putObject, true);//doing this here ahead of notification because notification may require the viz field lookup anyway and afaict no harm in it await WorkOrderPopulateVizFields(putObject, true);//doing this here ahead of notification because notification may require the viz field lookup anyway and afaict no harm in it
await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject); await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
return putObject; return putObject;
@@ -555,61 +555,62 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// //NOTE: REMOVED WHEN REMOVED STATIC PRICING
//CONTRACT CHANGE HANDLER // ////////////////////////////////////////////////////////////////////////////////////////////////
// // //CONTRACT CHANGE HANDLER
// // //
private async Task<WorkOrder> ProcessChangeOfContractAsync(long woId) // //
{ // private async Task<WorkOrder> ProcessChangeOfContractAsync(long woId)
//contract has changed, update entire graph pricing and potentially response time stuff as well here now // {
//iterate graph calling *SetListPrice on each item // //contract has changed, update entire graph pricing and potentially response time stuff as well here now
var wo = await ct.WorkOrder // //iterate graph calling *SetListPrice on each item
.Include(s => s.States) // var wo = await ct.WorkOrder.AsSplitQuery()
.Include(w => w.Items.OrderBy(item => item.Sequence)) // .Include(s => s.States)
.ThenInclude(wi => wi.Expenses) // .Include(w => w.Items.OrderBy(item => item.Sequence))
.Include(w => w.Items) // .ThenInclude(wi => wi.Expenses)
.ThenInclude(wi => wi.Labors) // .Include(w => w.Items)
.Include(w => w.Items) // .ThenInclude(wi => wi.Labors)
.ThenInclude(wi => wi.Loans) // .Include(w => w.Items)
.Include(w => w.Items) // .ThenInclude(wi => wi.Loans)
.ThenInclude(wi => wi.Parts) // .Include(w => w.Items)
.Include(w => w.Items) // .ThenInclude(wi => wi.Parts)
.ThenInclude(wi => wi.PartRequests) // .Include(w => w.Items)
.Include(w => w.Items) // .ThenInclude(wi => wi.PartRequests)
.ThenInclude(wi => wi.ScheduledUsers) // .Include(w => w.Items)
.Include(w => w.Items) // .ThenInclude(wi => wi.ScheduledUsers)
.ThenInclude(wi => wi.Tasks.OrderBy(t => t.Sequence)) // .Include(w => w.Items)
.Include(w => w.Items) // .ThenInclude(wi => wi.Tasks.OrderBy(t => t.Sequence))
.ThenInclude(wi => wi.Travels) // .Include(w => w.Items)
.Include(w => w.Items) // .ThenInclude(wi => wi.Travels)
.ThenInclude(wi => wi.Units) // .Include(w => w.Items)
.Include(w => w.Items) // .ThenInclude(wi => wi.Units)
.ThenInclude(wi => wi.OutsideServices) // .Include(w => w.Items)
.SingleOrDefaultAsync(z => z.Id == woId); // .ThenInclude(wi => wi.OutsideServices)
// .SingleOrDefaultAsync(z => z.Id == woId);
//If Contract has response time then set CompleteByDate // //If Contract has response time then set CompleteByDate
if (mContractInEffect != null && mContractInEffect.ResponseTime != TimeSpan.Zero) // if (mContractInEffect != null && mContractInEffect.ResponseTime != TimeSpan.Zero)
{ // {
wo.CompleteByDate = DateTime.UtcNow.Add(mContractInEffect.ResponseTime); // wo.CompleteByDate = DateTime.UtcNow.Add(mContractInEffect.ResponseTime);
} // }
// //update pricing // // //update pricing
// foreach (WorkOrderItem wi in wo.Items) // // foreach (WorkOrderItem wi in wo.Items)
// { // // {
// // foreach (WorkOrderItemLabor o in wi.Labors) // // // foreach (WorkOrderItemLabor o in wi.Labors)
// // await LaborSetPrice(o, mContractInEffect); // // // await LaborSetPrice(o, mContractInEffect);
// foreach (WorkOrderItemTravel o in wi.Travels) // // foreach (WorkOrderItemTravel o in wi.Travels)
// TravelSetListPrice(o, mContractInEffect); // // TravelSetListPrice(o, mContractInEffect);
// foreach (WorkOrderItemPart o in wi.Parts) // // foreach (WorkOrderItemPart o in wi.Parts)
// PartSetListPrice(o, mContractInEffect); // // PartSetListPrice(o, mContractInEffect);
// } // // }
await ct.SaveChangesAsync(); // await ct.SaveChangesAsync();
return wo; // return wo;
} // }
@@ -1199,7 +1200,7 @@ namespace AyaNova.Biz
//https://docs.microsoft.com/en-us/ef/core/querying/related-data //https://docs.microsoft.com/en-us/ef/core/querying/related-data
//docs say this will not query twice but will recognize the duplicate woitem bit which is required for multiple grandchild collections //docs say this will not query twice but will recognize the duplicate woitem bit which is required for multiple grandchild collections
var ret = var ret =
await ct.WorkOrderItem.AsNoTracking() await ct.WorkOrderItem.AsSplitQuery().AsNoTracking()
.Include(wi => wi.Expenses) .Include(wi => wi.Expenses)
.Include(wi => wi.Labors) .Include(wi => wi.Labors)
.Include(wi => wi.Loans) .Include(wi => wi.Loans)
@@ -5140,7 +5141,7 @@ namespace AyaNova.Biz
if (id == null) return null; if (id == null) return null;
if (mFetchedContractAlready == false) if (mFetchedContractAlready == false)
{ {
mContractInEffect = await ct.Contract.AsNoTracking() mContractInEffect = await ct.Contract.AsSplitQuery().AsNoTracking()
.Include(c => c.ServiceRateItems) .Include(c => c.ServiceRateItems)
.Include(c => c.TravelRateItems) .Include(c => c.TravelRateItems)
.Include(c => c.ContractPartOverrideItems) .Include(c => c.ContractPartOverrideItems)

View File

@@ -243,7 +243,7 @@ namespace AyaNova.Util
await SeedPartAsync(log, 20, 5); await SeedPartAsync(log, 20, 5);
await SeedPartAssemblyAsync(log, 5); await SeedPartAssemblyAsync(log, 5);
await SeedPurchaseOrderAsync(log, 20); await SeedPurchaseOrderAsync(log, 20);
await SeedWorkOrderAsync(log, 20); await SeedWorkOrderAsync(log, 3);
//PERF //PERF
watch.Stop(); watch.Stop();
@@ -2559,7 +2559,7 @@ namespace AyaNova.Util
o.InternalReferenceNumber = "irf-" + Fake.Finance.Account(4); o.InternalReferenceNumber = "irf-" + Fake.Finance.Account(4);
o.ServiceDate = woDate; o.ServiceDate = woDate;
int woItemCount = Fake.Random.Int(1, 3); int woItemCount = 10;//Fake.Random.Int(2, 10);
for (int y = 0; y < woItemCount; y++) for (int y = 0; y < woItemCount; y++)
{ {
var woItem = new WorkOrderItem() var woItem = new WorkOrderItem()