This commit is contained in:
2021-05-26 23:16:44 +00:00
parent 045c078e26
commit 24fb905180

View File

@@ -2541,54 +2541,11 @@ namespace AyaNova.Biz
//manual price overrides anything //manual price overrides anything
o.PriceViz=o.ListPrice;
if (o.PriceOverride != null) if (o.PriceOverride != null)
o.PriceViz = (decimal)o.PriceOverride; o.PriceViz = (decimal)o.PriceOverride;
else //Currently not contract discounted so no further calcs need apply to priceViz
{
//not manual so could potentially have a contract adjustment
var c = await GetCurrentWorkOrderContractFromRelatedAsync(AyaType.WorkOrderItem, o.WorkOrderItemId);
if (c != null)
{
decimal pct = 0;
ContractOverrideType cot = ContractOverrideType.PriceDiscount;
bool TaggedAdjustmentInEffect = false;
//POTENTIAL CONTRACT ADJUSTMENTS
//First check if there is a matching tagged contract discount, that takes precedence
if (c.ContractPartOverrideItems.Count > 0)
{
//Iterate all contract tagged items in order of ones with the most tags first
foreach (var cp in c.ContractPartOverrideItems.OrderByDescending(z => z.Tags.Count))
if (cp.Tags.All(z => part.Tags.Any(x => x == z)))
{
if (cp.OverridePct != 0)
{
pct = cp.OverridePct / 100;
cot = cp.OverrideType;
TaggedAdjustmentInEffect = true;
}
}
}
//Generic discount?
if (!TaggedAdjustmentInEffect && c.ServiceRatesOverridePct != 0)
{
pct = c.ServiceRatesOverridePct / 100;
cot = c.ServiceRatesOverrideType;
}
//apply if discount found
if (pct != 0)
{
if (cot == ContractOverrideType.CostMarkup)
o.PriceViz = o.Cost + (o.Cost * pct);
else if (cot == ContractOverrideType.PriceDiscount)
o.PriceViz = o.ListPrice - (o.ListPrice * pct);
}
}
}
//Calculate totals and taxes //Calculate totals and taxes
//NET //NET
o.NetViz = o.PriceViz * o.Quantity; o.NetViz = o.PriceViz * o.Quantity;
@@ -2636,13 +2593,10 @@ namespace AyaNova.Biz
if (ayaEvent == AyaEvent.Modified) if (ayaEvent == AyaEvent.Modified)
{ {
//If it wasn't a complete part change there is no need to set pricing //If it wasn't a complete part change there is no need to set pricing
if (newObj.LoanUnitId == oldObj.LoanUnitId && newObj.Rate == oldObj.Rate) if (newObj.LoanUnitId == oldObj.LoanUnitId && newObj.Rate == oldObj.Rate)
{ SnapshotPricing = false;
SnapshotPricing = false;
}
} }
//Pricing //Pricing
if (SnapshotPricing) if (SnapshotPricing)
{ {
@@ -2650,22 +2604,40 @@ namespace AyaNova.Biz
newObj.Cost = 0; newObj.Cost = 0;
newObj.ListPrice = 0; newObj.ListPrice = 0;
LoanUnit loanUnit = await ct.LoanUnit.AsNoTracking().FirstOrDefaultAsync(x => x.Id == newObj.LoanUnitId); LoanUnit loanUnit = await ct.LoanUnit.AsNoTracking().FirstOrDefaultAsync(x => x.Id == newObj.LoanUnitId);
if (loanUnit != null) if (loanUnit != null)
{ {
switch (newObj.Rate) switch (newObj.Rate)
{ {
case LoanUnitRateUnit.None: case LoanUnitRateUnit.None:
break; break;
case LoanUnitRateUnit.Hours: case LoanUnitRateUnit.Hours:
newObj.Cost=loanUnit. newObj.Cost = loanUnit.RateHourCost;
newObj.ListPrice = loanUnit.RateHour;
break; break;
case LoanUnitRateUnit.HalfDays:
newObj.Cost = loanUnit.RateHalfDayCost;
newObj.ListPrice = loanUnit.RateHalfDay;
break;
case LoanUnitRateUnit.Days:
newObj.Cost = loanUnit.RateDayCost;
newObj.ListPrice = loanUnit.RateDay;
break;
case LoanUnitRateUnit.Weeks:
newObj.Cost = loanUnit.RateWeekCost;
newObj.ListPrice = loanUnit.RateWeek;
break;
case LoanUnitRateUnit.Months:
newObj.Cost = loanUnit.RateMonthCost;
newObj.ListPrice = loanUnit.RateMonth;
break;
case LoanUnitRateUnit.Years:
newObj.Cost = loanUnit.RateYearCost;
newObj.ListPrice = loanUnit.RateYear;
break;
} }
} }
} }
} }