This commit is contained in:
@@ -1719,97 +1719,90 @@ namespace AyaNova.Biz
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//BIZ ACTIONS
|
//BIZ ACTIONS
|
||||||
//
|
//
|
||||||
//automatic actions on record change, called AFTER validation
|
|
||||||
// also called when contract changes
|
|
||||||
//
|
//
|
||||||
private async Task LaborBizActionsAsync(AyaEvent ayaEvent, WorkOrderItemLabor newObj, WorkOrderItemLabor oldObj, IDbContextTransaction transaction, bool contractChanged=false)
|
private async Task LaborBizActionsAsync(AyaEvent ayaEvent, WorkOrderItemLabor newObj, WorkOrderItemLabor oldObj, IDbContextTransaction transaction)
|
||||||
{
|
{
|
||||||
|
//automatic actions on record change, called AFTER validation
|
||||||
|
|
||||||
//currently no processing required except for created or modified at this time
|
//currently no processing required except for created or modified at this time
|
||||||
if (ayaEvent != AyaEvent.Created && ayaEvent != AyaEvent.Modified)
|
if (ayaEvent != AyaEvent.Created && ayaEvent != AyaEvent.Modified)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//SET COST / TAX / PRICE
|
//SET TAXES AND PRICING
|
||||||
|
|
||||||
var Contract = await GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, newObj.WorkOrderItemId);
|
|
||||||
|
|
||||||
//by default apply all automatic actions with further restrictions possible below
|
//by default apply all automatic actions with further restrictions possible below
|
||||||
bool ApplyTax = true;
|
bool ApplyTax = true;
|
||||||
bool ApplyListPricing = true;
|
bool ApplyPricingUpdate = true;
|
||||||
bool ApplyContractPrice = true;
|
|
||||||
|
|
||||||
//NOTE: If contract itself was changed, that will trigger this from the header change and forceFullUpdate will be in effect
|
|
||||||
|
|
||||||
//if modifed, see what has changed and should be re-applied
|
//if modifed, see what has changed and should be re-applied
|
||||||
if (ayaEvent == AyaEvent.Modified)
|
if (ayaEvent == AyaEvent.Modified)
|
||||||
{
|
{
|
||||||
//If it was a service rate change it's like a new record and list pricing and contract applies
|
//If it wasn't a service rate change there is no need to set pricing
|
||||||
//so only potentially restrict what applies if that hasn't changed
|
|
||||||
if (newObj.ServiceRateId == oldObj.ServiceRateId)
|
if (newObj.ServiceRateId == oldObj.ServiceRateId)
|
||||||
{
|
{
|
||||||
if (newObj.Price != oldObj.Price)//user manually overrode the price
|
ApplyPricingUpdate = false;
|
||||||
{
|
|
||||||
ApplyListPricing = false;
|
|
||||||
ApplyContractPrice = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//If taxes haven't change then no need to update taxes
|
||||||
//same taxes
|
|
||||||
if (newObj.TaxCodeSaleId == oldObj.TaxCodeSaleId)
|
if (newObj.TaxCodeSaleId == oldObj.TaxCodeSaleId)
|
||||||
ApplyTax = false;
|
ApplyTax = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Tax code
|
//Tax code
|
||||||
if (ApplyTax && newObj.TaxCodeSaleId != null)
|
if (ApplyTax)
|
||||||
{
|
{
|
||||||
|
//Default in case nothing to apply
|
||||||
|
newObj.TaxAPct = 0;
|
||||||
|
newObj.TaxBPct = 0;
|
||||||
|
newObj.TaxOnTax = false;
|
||||||
|
|
||||||
var t = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.TaxCodeSaleId);
|
if (newObj.TaxCodeSaleId != null)
|
||||||
if (t != null)
|
|
||||||
{
|
{
|
||||||
newObj.TaxAPct = t.TaxAPct;
|
var t = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.TaxCodeSaleId);
|
||||||
newObj.TaxBPct = t.TaxBPct;
|
if (t != null)
|
||||||
newObj.TaxOnTax = t.TaxOnTax;
|
{
|
||||||
}
|
newObj.TaxAPct = t.TaxAPct;
|
||||||
else
|
newObj.TaxBPct = t.TaxBPct;
|
||||||
{
|
newObj.TaxOnTax = t.TaxOnTax;
|
||||||
newObj.TaxAPct = 0;
|
}
|
||||||
newObj.TaxBPct = 0;
|
|
||||||
newObj.TaxOnTax = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Pricing
|
//Pricing
|
||||||
if (ApplyListPricing && newObj.ServiceRateId != null)
|
if (ApplyPricingUpdate)
|
||||||
{
|
{
|
||||||
var s = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.ServiceRateId);
|
//default in case nothing to apply
|
||||||
if (s != null)
|
newObj.Cost = 0;
|
||||||
|
newObj.ListPrice = 0;
|
||||||
|
newObj.Price = 0;
|
||||||
|
|
||||||
|
//in v7 it was ok to have no service rate selected
|
||||||
|
//not sure why but carried forward to v8 so..
|
||||||
|
if (newObj.ServiceRateId != null)
|
||||||
{
|
{
|
||||||
newObj.Cost = s.Cost;
|
var s = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.ServiceRateId);
|
||||||
newObj.ListPrice = s.Charge;
|
if (s != null)
|
||||||
}
|
{
|
||||||
else
|
newObj.Cost = s.Cost;
|
||||||
{
|
newObj.ListPrice = s.Charge;
|
||||||
newObj.Cost = 0;
|
var Contract = await GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, newObj.WorkOrderItemId);
|
||||||
newObj.ListPrice = 0;
|
LaborApplyContract(newObj, Contract);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Contract
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
if (ApplyContractPrice && Contract != null)
|
// APPLY CONTRACT PER UNIT PRICING
|
||||||
{
|
//
|
||||||
//update discount pricing
|
//(called by woitemlabor save and also by header save on change of contract)
|
||||||
if (Contract.ServiceRatesOverridePct != 0)
|
private static void LaborApplyContract(WorkOrderItemLabor o, Contract c)
|
||||||
{
|
{
|
||||||
if (Contract.ServiceRatesOverrideType == ContractOverrideType.CostMarkup)
|
if (c == null || c.ServiceRatesOverridePct == 0)
|
||||||
newObj.Price = newObj.Cost + (newObj.Cost * Contract.ServiceRatesOverridePct);
|
return;
|
||||||
else if (Contract.ServiceRatesOverrideType == ContractOverrideType.PriceDiscount)
|
if (c.ServiceRatesOverrideType == ContractOverrideType.CostMarkup)
|
||||||
newObj.Price = newObj.ListPrice - (newObj.ListPrice * Contract.ServiceRatesOverridePct);
|
o.Price = o.Cost + (o.Cost * c.ServiceRatesOverridePct);
|
||||||
}
|
else if (c.ServiceRatesOverrideType == ContractOverrideType.PriceDiscount)
|
||||||
}
|
o.Price = o.ListPrice - (o.ListPrice * c.ServiceRatesOverridePct);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user