This commit is contained in:
2021-05-13 19:47:56 +00:00
parent af8a1b8aef
commit 5d670daaab

View File

@@ -414,17 +414,39 @@ namespace AyaNova.Biz
{ {
//contract has changed, update entire graph pricing and potentially response time stuff as well here now //contract has changed, update entire graph pricing and potentially response time stuff as well here now
//iterate graph calling *SetListPrice on each item //iterate graph calling *SetListPrice on each item
var wo = await WorkOrderGetAsync(woId, false, false); var wo = await ct.WorkOrder
.Include(s => s.States)
.Include(w => w.Items.OrderBy(item => item.Sequence))
.ThenInclude(wi => wi.Expenses)
.Include(w => w.Items)
.ThenInclude(wi => wi.Labors)
.Include(w => w.Items)
.ThenInclude(wi => wi.Loans)
.Include(w => w.Items)
.ThenInclude(wi => wi.Parts)
.Include(w => w.Items)
.ThenInclude(wi => wi.PartRequests)
.Include(w => w.Items)
.ThenInclude(wi => wi.ScheduledUsers)
.Include(w => w.Items)
.ThenInclude(wi => wi.Tasks)
.Include(w => w.Items)
.ThenInclude(wi => wi.Travels)
.Include(w => w.Items)
.ThenInclude(wi => wi.Units)
.Include(w => w.Items)
.ThenInclude(wi => wi.OutsideServices)
.SingleOrDefaultAsync(z => z.Id == woId);
foreach (WorkOrderItem wi in wo.Items) foreach (WorkOrderItem wi in wo.Items)
{ {
foreach (WorkOrderItemLabor o in wi.Labors) foreach (WorkOrderItemLabor o in wi.Labors)
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;
@@ -1833,10 +1855,10 @@ namespace AyaNova.Biz
//Pricing //Pricing
if (SetPrice) if (SetPrice)
{ {
var Contract = await GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, newObj.WorkOrderItemId); var Contract = await GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, newObj.WorkOrderItemId);
await LaborSetPrice(newObj, Contract); await LaborSetPrice(newObj, Contract);
} }
} }
@@ -1846,22 +1868,22 @@ namespace AyaNova.Biz
//(called by woitemlabor save and also by header save on change of contract) //(called by woitemlabor save and also by header save on change of contract)
private async Task LaborSetPrice(WorkOrderItemLabor o, Contract c) private async Task LaborSetPrice(WorkOrderItemLabor o, Contract c)
{ {
//default in case nothing to apply //default in case nothing to apply
o.Cost = 0; o.Cost = 0;
o.ListPrice = 0; o.ListPrice = 0;
o.Price = 0; o.Price = 0;
//in v7 it was ok to have no service rate selected //in v7 it was ok to have no service rate selected
//not sure why but carried forward to v8 so.. //not sure why but carried forward to v8 so..
if (o.ServiceRateId != null) if (o.ServiceRateId != null)
{
var s = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.ServiceRateId);
if (s != null)
{ {
var s = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.ServiceRateId); o.Cost = s.Cost;
if (s != null) o.ListPrice = s.Charge;
{
o.Cost = s.Cost;
o.ListPrice = s.Charge;
}
} }
}
if (c == null || c.ServiceRatesOverridePct == 0) if (c == null || c.ServiceRatesOverridePct == 0)
{ {