This commit is contained in:
@@ -1719,97 +1719,90 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//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
|
||||
if (ayaEvent != AyaEvent.Created && ayaEvent != AyaEvent.Modified)
|
||||
return;
|
||||
|
||||
//SET COST / TAX / PRICE
|
||||
|
||||
var Contract = await GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, newObj.WorkOrderItemId);
|
||||
//SET TAXES AND PRICING
|
||||
|
||||
//by default apply all automatic actions with further restrictions possible below
|
||||
bool ApplyTax = true;
|
||||
bool ApplyListPricing = true;
|
||||
bool ApplyContractPrice = true;
|
||||
|
||||
//NOTE: If contract itself was changed, that will trigger this from the header change and forceFullUpdate will be in effect
|
||||
bool ApplyPricingUpdate = true;
|
||||
|
||||
//if modifed, see what has changed and should be re-applied
|
||||
if (ayaEvent == AyaEvent.Modified)
|
||||
{
|
||||
//If it was a service rate change it's like a new record and list pricing and contract applies
|
||||
//so only potentially restrict what applies if that hasn't changed
|
||||
{
|
||||
//If it wasn't a service rate change there is no need to set pricing
|
||||
if (newObj.ServiceRateId == oldObj.ServiceRateId)
|
||||
{
|
||||
if (newObj.Price != oldObj.Price)//user manually overrode the price
|
||||
{
|
||||
ApplyListPricing = false;
|
||||
ApplyContractPrice = false;
|
||||
}
|
||||
ApplyPricingUpdate = false;
|
||||
}
|
||||
|
||||
//same taxes
|
||||
//If taxes haven't change then no need to update taxes
|
||||
if (newObj.TaxCodeSaleId == oldObj.TaxCodeSaleId)
|
||||
ApplyTax = false;
|
||||
}
|
||||
|
||||
|
||||
//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 (t != null)
|
||||
if (newObj.TaxCodeSaleId != null)
|
||||
{
|
||||
newObj.TaxAPct = t.TaxAPct;
|
||||
newObj.TaxBPct = t.TaxBPct;
|
||||
newObj.TaxOnTax = t.TaxOnTax;
|
||||
}
|
||||
else
|
||||
{
|
||||
newObj.TaxAPct = 0;
|
||||
newObj.TaxBPct = 0;
|
||||
newObj.TaxOnTax = false;
|
||||
var t = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.TaxCodeSaleId);
|
||||
if (t != null)
|
||||
{
|
||||
newObj.TaxAPct = t.TaxAPct;
|
||||
newObj.TaxBPct = t.TaxBPct;
|
||||
newObj.TaxOnTax = t.TaxOnTax;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Pricing
|
||||
if (ApplyListPricing && newObj.ServiceRateId != null)
|
||||
if (ApplyPricingUpdate)
|
||||
{
|
||||
var s = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.ServiceRateId);
|
||||
if (s != null)
|
||||
//default in case nothing to apply
|
||||
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;
|
||||
newObj.ListPrice = s.Charge;
|
||||
}
|
||||
else
|
||||
{
|
||||
newObj.Cost = 0;
|
||||
newObj.ListPrice = 0;
|
||||
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);
|
||||
LaborApplyContract(newObj, Contract);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Contract
|
||||
if (ApplyContractPrice && Contract != null)
|
||||
{
|
||||
//update discount pricing
|
||||
if (Contract.ServiceRatesOverridePct != 0)
|
||||
{
|
||||
if (Contract.ServiceRatesOverrideType == ContractOverrideType.CostMarkup)
|
||||
newObj.Price = newObj.Cost + (newObj.Cost * Contract.ServiceRatesOverridePct);
|
||||
else if (Contract.ServiceRatesOverrideType == ContractOverrideType.PriceDiscount)
|
||||
newObj.Price = newObj.ListPrice - (newObj.ListPrice * Contract.ServiceRatesOverridePct);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// APPLY CONTRACT PER UNIT PRICING
|
||||
//
|
||||
//(called by woitemlabor save and also by header save on change of contract)
|
||||
private static void LaborApplyContract(WorkOrderItemLabor o, Contract c)
|
||||
{
|
||||
if (c == null || c.ServiceRatesOverridePct == 0)
|
||||
return;
|
||||
if (c.ServiceRatesOverrideType == ContractOverrideType.CostMarkup)
|
||||
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