This commit is contained in:
2021-05-13 19:29:12 +00:00
parent 4b4426e1ec
commit af8a1b8aef
2 changed files with 35 additions and 25 deletions

View File

@@ -410,7 +410,7 @@ namespace AyaNova.Biz
//CONTRACT CHANGE HANDLER
//
//
private async Task 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
@@ -418,14 +418,15 @@ namespace AyaNova.Biz
foreach (WorkOrderItem wi in wo.Items)
{
foreach (WorkOrderItemLabor o in wi.Labors)
LaborSetListPrice(o, mContractInEffect);
LaborSetPrice(o, mContractInEffect);
foreach (WorkOrderItemTravel o in wi.Travels)
TravelSetListPrice(o, mContractInEffect);
foreach (WorkOrderItemPart o in wi.Parts)
PartSetListPrice(o, mContractInEffect);
}
await ct.SaveChangesAsync();
return wo;
}
@@ -1794,7 +1795,7 @@ namespace AyaNova.Biz
//by default apply all automatic actions with further restrictions possible below
bool ApplyTax = true;
bool ApplyPricingUpdate = true;
bool SetPrice = true;
//if modifed, see what has changed and should be re-applied
if (ayaEvent == AyaEvent.Modified)
@@ -1802,7 +1803,7 @@ namespace AyaNova.Biz
//If it wasn't a service rate change there is no need to set pricing
if (newObj.ServiceRateId == oldObj.ServiceRateId)
{
ApplyPricingUpdate = false;
SetPrice = false;
}
//If taxes haven't change then no need to update taxes
if (newObj.TaxCodeSaleId == oldObj.TaxCodeSaleId)
@@ -1830,26 +1831,12 @@ namespace AyaNova.Biz
}
//Pricing
if (ApplyPricingUpdate)
if (SetPrice)
{
//default in case nothing to apply
newObj.Cost = 0;
newObj.ListPrice = 0;
newObj.Price = 0;
var Contract = await GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, newObj.WorkOrderItemId);
await LaborSetPrice(newObj, Contract);
//in v7 it was ok to have no service rate selected
//not sure why but carried forward to v8 so..
if (newObj.ServiceRateId != null)
{
var s = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.ServiceRateId);
if (s != null)
{
newObj.Cost = s.Cost;
newObj.ListPrice = s.Charge;
var Contract = await GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, newObj.WorkOrderItemId);
LaborSetListPrice(newObj, Contract);
}
}
}
}
@@ -1857,8 +1844,25 @@ namespace AyaNova.Biz
// SET PER UNIT LIST PRICE
//
//(called by woitemlabor save and also by header save on change of contract)
private static void LaborSetListPrice(WorkOrderItemLabor o, Contract c)
private async Task LaborSetPrice(WorkOrderItemLabor o, Contract c)
{
//default in case nothing to apply
o.Cost = 0;
o.ListPrice = 0;
o.Price = 0;
//in v7 it was ok to have no service rate selected
//not sure why but carried forward to v8 so..
if (o.ServiceRateId != null)
{
var s = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.ServiceRateId);
if (s != null)
{
o.Cost = s.Cost;
o.ListPrice = s.Charge;
}
}
if (c == null || c.ServiceRatesOverridePct == 0)
{
o.Price = o.ListPrice;//default with no contract