This commit is contained in:
@@ -58,7 +58,9 @@ namespace AyaNova.Biz
|
||||
AuthorizationRoles.BizAdmin,
|
||||
UserType.NotService);//picked not service arbitrarily, probably a non-factor
|
||||
}
|
||||
|
||||
//request cache for viz fields
|
||||
private VizCache vc = new VizCache();
|
||||
private ObjectCache oc = new ObjectCache();
|
||||
|
||||
/*
|
||||
██████╗ ███╗ ███╗
|
||||
@@ -880,36 +882,67 @@ namespace AyaNova.Biz
|
||||
|
||||
//Alert notes
|
||||
//Customer notes first then others below
|
||||
var custInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == o.CustomerId).Select(x => new { x.AlertNotes, x.TechNotes, x.Name, x.Phone1, x.Phone2, x.Phone3, x.Phone4, x.Phone5, x.EmailAddress }).FirstOrDefaultAsync();
|
||||
if (!string.IsNullOrWhiteSpace(custInfo.AlertNotes))
|
||||
{
|
||||
o.AlertViz = $"{await Translate("Customer")} - {await Translate("AlertNotes")}\n{custInfo.AlertNotes}\n\n";
|
||||
if (vc.Get("wocustname", o.CustomerId) == null)//will always be present so no need to check other values
|
||||
{
|
||||
var custInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == o.CustomerId).Select(x => new { x.AlertNotes, x.TechNotes, x.Name, x.Phone1, x.Phone2, x.Phone3, x.Phone4, x.Phone5, x.EmailAddress }).FirstOrDefaultAsync();
|
||||
vc.Add(custInfo.Name, "wocustname", o.CustomerId);
|
||||
if (!string.IsNullOrWhiteSpace(custInfo.AlertNotes))
|
||||
{
|
||||
vc.Add($"{await Translate("Customer")} - {await Translate("AlertNotes")}\n{custInfo.AlertNotes}\n\n", "woalert", o.CustomerId);
|
||||
}
|
||||
else
|
||||
{
|
||||
vc.Add(string.Empty, "woalert", o.CustomerId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(custInfo.TechNotes))
|
||||
{
|
||||
vc.Add($"{await Translate("CustomerTechNotes")}\n{custInfo.TechNotes}\n\n", "custtechnotes", o.CustomerId);
|
||||
}
|
||||
|
||||
vc.Add(custInfo.Phone1, "custphone1", o.CustomerId);
|
||||
vc.Add(custInfo.Phone2, "custphone2", o.CustomerId);
|
||||
vc.Add(custInfo.Phone3, "custphone3", o.CustomerId);
|
||||
vc.Add(custInfo.Phone4, "custphone4", o.CustomerId);
|
||||
vc.Add(custInfo.Phone5, "custphone5", o.CustomerId);
|
||||
vc.Add(custInfo.EmailAddress, "custemail", o.CustomerId);
|
||||
}
|
||||
o.CustomerViz = vc.Get("wocustname", o.CustomerId);
|
||||
o.AlertViz = vc.Get("woalert", o.CustomerId);
|
||||
o.CustomerTechNotesViz = vc.Get("custtechnotes", o.CustomerId);
|
||||
o.CustomerPhone1Viz = vc.Get("custphone1", o.CustomerId);
|
||||
o.CustomerPhone2Viz = vc.Get("custphone2", o.CustomerId);
|
||||
o.CustomerPhone3Viz = vc.Get("custphone3", o.CustomerId);
|
||||
o.CustomerPhone4Viz = vc.Get("custphone4", o.CustomerId);
|
||||
o.CustomerPhone5Viz = vc.Get("custphone5", o.CustomerId);
|
||||
o.CustomerEmailAddressViz = vc.Get("custemail", o.CustomerId);
|
||||
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(custInfo.TechNotes))
|
||||
{
|
||||
o.CustomerTechNotesViz = $"{await Translate("CustomerTechNotes")}\n{custInfo.TechNotes}\n\n";
|
||||
}
|
||||
|
||||
o.CustomerViz = custInfo.Name;
|
||||
o.CustomerPhone1Viz = custInfo.Phone1;
|
||||
o.CustomerPhone2Viz = custInfo.Phone2;
|
||||
o.CustomerPhone3Viz = custInfo.Phone3;
|
||||
o.CustomerPhone4Viz = custInfo.Phone4;
|
||||
o.CustomerPhone5Viz = custInfo.Phone5;
|
||||
o.CustomerEmailAddressViz = custInfo.EmailAddress;
|
||||
|
||||
if (o.ProjectId != null)
|
||||
o.ProjectViz = await ct.Project.AsNoTracking().Where(x => x.Id == o.ProjectId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
|
||||
{
|
||||
string value = vc.Get("projname", o.ProjectId);
|
||||
if (value == null)
|
||||
{
|
||||
value = await ct.Project.AsNoTracking().Where(x => x.Id == o.ProjectId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
vc.Add(value, "projname", o.ProjectId);
|
||||
}
|
||||
o.ProjectViz = value;
|
||||
}
|
||||
|
||||
if (o.ContractId != null)
|
||||
{
|
||||
var contractVizFields = await ct.Contract.AsNoTracking().Where(x => x.Id == o.ContractId).Select(x => new { Name = x.Name, AlertNotes = x.AlertNotes }).FirstOrDefaultAsync();
|
||||
o.ContractViz = contractVizFields.Name;
|
||||
if (!string.IsNullOrWhiteSpace(contractVizFields.AlertNotes))
|
||||
if (vc.Get("ctrctname", o.ContractId) == null)
|
||||
{
|
||||
o.AlertViz += $"{await Translate("Contract")}\n{contractVizFields.AlertNotes}\n\n";
|
||||
var contractVizFields = await ct.Contract.AsNoTracking().Where(x => x.Id == o.ContractId).Select(x => new { Name = x.Name, AlertNotes = x.AlertNotes }).FirstOrDefaultAsync();
|
||||
vc.Add(contractVizFields.Name, "ctrctname", o.ContractId);
|
||||
vc.Add(contractVizFields.AlertNotes, "ctrctalrt", o.ContractId);
|
||||
}
|
||||
o.ContractViz = vc.Get("ctrctname", o.ContractId);//contractVizFields.Name;
|
||||
var alrtNotes = vc.Get("ctrctalrt", o.ContractId);
|
||||
if (!string.IsNullOrWhiteSpace(alrtNotes))
|
||||
{
|
||||
o.AlertViz += $"{await Translate("Contract")}\n{alrtNotes}\n\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1352,16 +1385,41 @@ namespace AyaNova.Biz
|
||||
{
|
||||
if (o.WorkOrderItemStatusId != null)
|
||||
{
|
||||
var StatusInfo = await ct.WorkOrderItemStatus.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.WorkOrderItemStatusId);
|
||||
o.WorkOrderItemStatusNameViz = StatusInfo.Name;
|
||||
o.WorkOrderItemStatusColorViz = StatusInfo.Color;
|
||||
string value = vc.Get("woistatname", o.WorkOrderItemStatusId);
|
||||
if (value == null)
|
||||
{
|
||||
var StatusInfo = await ct.WorkOrderItemStatus.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.WorkOrderItemStatusId);
|
||||
|
||||
vc.Add(StatusInfo.Name, "woistatname", o.WorkOrderItemStatusId);
|
||||
vc.Add(StatusInfo.Color, "woistatcolor", o.WorkOrderItemStatusId);
|
||||
o.WorkOrderItemStatusNameViz = StatusInfo.Name;
|
||||
o.WorkOrderItemStatusColorViz = StatusInfo.Color;
|
||||
}
|
||||
else
|
||||
{
|
||||
o.WorkOrderItemStatusNameViz = value;
|
||||
o.WorkOrderItemStatusColorViz = vc.Get("woistatcolor", o.WorkOrderItemStatusId);
|
||||
}
|
||||
}
|
||||
|
||||
if (o.WorkOrderItemPriorityId != null)
|
||||
{
|
||||
var PriorityInfo = await ct.WorkOrderItemPriority.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.WorkOrderItemPriorityId);
|
||||
o.WorkOrderItemPriorityNameViz = PriorityInfo.Name;
|
||||
o.WorkOrderItemPriorityColorViz = PriorityInfo.Color;
|
||||
string value = vc.Get("woipriorityname", o.WorkOrderItemPriorityId);
|
||||
if (value == null)
|
||||
{
|
||||
var PriorityInfo = await ct.WorkOrderItemPriority.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.WorkOrderItemPriorityId);
|
||||
vc.Add(PriorityInfo.Name, "woipriorityname", o.WorkOrderItemPriorityId);
|
||||
vc.Add(PriorityInfo.Color, "woiprioritycolor", o.WorkOrderItemPriorityId);
|
||||
|
||||
o.WorkOrderItemPriorityNameViz = PriorityInfo.Name;
|
||||
o.WorkOrderItemPriorityColorViz = PriorityInfo.Color;
|
||||
}
|
||||
else
|
||||
{
|
||||
o.WorkOrderItemPriorityNameViz = value;
|
||||
o.WorkOrderItemPriorityColorViz = vc.Get("woiprioritycolor", o.WorkOrderItemPriorityId);
|
||||
|
||||
}
|
||||
}
|
||||
foreach (var v in o.Expenses)
|
||||
await ExpensePopulateVizFields(v);
|
||||
@@ -1635,11 +1693,26 @@ namespace AyaNova.Biz
|
||||
if (calculateTotalsOnly == false)
|
||||
{
|
||||
if (o.UserId != null)
|
||||
o.UserViz = await ct.User.AsNoTracking().Where(x => x.Id == o.UserId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
{
|
||||
if (!vc.Has("user", o.UserId))
|
||||
{
|
||||
vc.Add(await ct.User.AsNoTracking().Where(x => x.Id == o.UserId).Select(x => x.Name).FirstOrDefaultAsync(), "user", o.UserId);
|
||||
}
|
||||
o.UserViz = vc.Get("user", o.UserId);
|
||||
}
|
||||
}
|
||||
TaxCode Tax = null;
|
||||
if (o.ChargeTaxCodeId != null)
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.ChargeTaxCodeId);
|
||||
{
|
||||
if (!oc.Has("tax", o.ChargeTaxCodeId))
|
||||
{
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.ChargeTaxCodeId);
|
||||
oc.Add(Tax, "tax", o.ChargeTaxCodeId);
|
||||
}
|
||||
else
|
||||
Tax = (TaxCode)oc.Get("tax", o.ChargeTaxCodeId);
|
||||
}
|
||||
|
||||
if (Tax != null)
|
||||
o.TaxCodeViz = Tax.Name;
|
||||
|
||||
@@ -1653,17 +1726,17 @@ namespace AyaNova.Biz
|
||||
{
|
||||
if (Tax.TaxAPct != 0)
|
||||
{
|
||||
o.TaxAViz = o.ChargeAmount * (Tax.TaxAPct / 100);
|
||||
o.TaxAViz = MoneyUtil.Round(o.ChargeAmount * (Tax.TaxAPct / 100));
|
||||
}
|
||||
if (Tax.TaxBPct != 0)
|
||||
{
|
||||
if (Tax.TaxOnTax)
|
||||
{
|
||||
o.TaxBViz = (o.ChargeAmount + o.TaxAViz) * (Tax.TaxBPct / 100);
|
||||
o.TaxBViz = MoneyUtil.Round((o.ChargeAmount + o.TaxAViz) * (Tax.TaxBPct / 100));
|
||||
}
|
||||
else
|
||||
{
|
||||
o.TaxBViz = o.ChargeAmount * (Tax.TaxBPct / 100);
|
||||
o.TaxBViz = MoneyUtil.Round(o.ChargeAmount * (Tax.TaxBPct / 100));
|
||||
}
|
||||
}
|
||||
o.LineTotalViz = o.ChargeAmount + o.TaxAViz + o.TaxBViz;
|
||||
@@ -1979,17 +2052,40 @@ namespace AyaNova.Biz
|
||||
if (calculateTotalsOnly == false)
|
||||
{
|
||||
if (o.UserId != null)
|
||||
o.UserViz = await ct.User.AsNoTracking().Where(x => x.Id == o.UserId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
{
|
||||
if (!vc.Has("user", o.UserId))
|
||||
{
|
||||
vc.Add(await ct.User.AsNoTracking().Where(x => x.Id == o.UserId).Select(x => x.Name).FirstOrDefaultAsync(), "user", o.UserId);
|
||||
}
|
||||
o.UserViz = vc.Get("user", o.UserId);
|
||||
}
|
||||
}
|
||||
ServiceRate Rate = null;
|
||||
if (o.ServiceRateId != null)
|
||||
{
|
||||
Rate = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.ServiceRateId);
|
||||
if (!oc.Has("servicerate", o.ServiceRateId))
|
||||
{
|
||||
Rate = await ct.ServiceRate.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.ServiceRateId);
|
||||
oc.Add(Rate, "servicerate", o.ServiceRateId);
|
||||
}
|
||||
else
|
||||
Rate = (ServiceRate)oc.Get("servicerate", o.ServiceRateId);
|
||||
o.ServiceRateViz = Rate.Name;
|
||||
}
|
||||
|
||||
|
||||
TaxCode Tax = null;
|
||||
if (o.TaxCodeSaleId != null)
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxCodeSaleId);
|
||||
{
|
||||
if (!oc.Has("tax", o.TaxCodeSaleId))
|
||||
{
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxCodeSaleId);
|
||||
oc.Add(Tax, "tax", o.TaxCodeSaleId);
|
||||
}
|
||||
else
|
||||
Tax = (TaxCode)oc.Get("tax", o.TaxCodeSaleId);
|
||||
}
|
||||
|
||||
if (Tax != null)
|
||||
o.TaxCodeViz = Tax.Name;
|
||||
|
||||
@@ -2348,7 +2444,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VIZ POPULATE
|
||||
//
|
||||
private async Task LoanPopulateVizFields(PMItemLoan o, List<NameIdItem> loanUnitRateEnumList = null, bool calculateTotalsOnly = false)
|
||||
private async Task LoanPopulateVizFields(PMItemLoan o, bool calculateTotalsOnly = false)
|
||||
{
|
||||
if (calculateTotalsOnly == false)
|
||||
{
|
||||
@@ -2360,16 +2456,27 @@ namespace AyaNova.Biz
|
||||
o.UnitOfMeasureViz = loanUnitRateEnumList.Where(x => x.Id == (long)o.Rate).Select(x => x.Name).First();
|
||||
}
|
||||
|
||||
LoanUnit loanUnit = await ct.LoanUnit.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.LoanUnitId);
|
||||
o.LoanUnitViz = loanUnit.Name;
|
||||
if (!vc.Has("loanunit", o.LoanUnitId))
|
||||
vc.Add(await ct.LoanUnit.AsNoTracking().Where(x => x.Id == o.LoanUnitId).Select(x => x.Name).FirstOrDefaultAsync(), "loanunit", o.LoanUnitId);
|
||||
o.LoanUnitViz = vc.Get("loanunit", o.LoanUnitId);
|
||||
|
||||
|
||||
TaxCode Tax = null;
|
||||
if (o.TaxCodeId != null)
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxCodeId);
|
||||
{
|
||||
if (!oc.Has("tax", o.TaxCodeId))
|
||||
{
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxCodeId);
|
||||
oc.Add(Tax, "tax", o.TaxCodeId);
|
||||
}
|
||||
else
|
||||
Tax = (TaxCode)oc.Get("tax", o.TaxCodeId);
|
||||
}
|
||||
|
||||
|
||||
if (Tax != null)
|
||||
o.TaxCodeViz = Tax.Name;
|
||||
|
||||
|
||||
//manual price overrides anything
|
||||
o.PriceViz = o.ListPrice;
|
||||
if (o.PriceOverride != null)
|
||||
@@ -2406,8 +2513,8 @@ namespace AyaNova.Biz
|
||||
//RESTRICTED COST FIELD??
|
||||
if (!UserCanViewLoanerCosts)
|
||||
o.Cost = 0;//cost already used in calcs and will not be updated on any update operation so this ensures the cost isn't sent over the wire
|
||||
|
||||
}
|
||||
private List<NameIdItem> loanUnitRateEnumList = null;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//BIZ ACTIONS
|
||||
@@ -2743,16 +2850,39 @@ namespace AyaNova.Biz
|
||||
if (calculateTotalsOnly == false)
|
||||
{
|
||||
if (o.UnitId != 0)
|
||||
o.UnitViz = await ct.Unit.AsNoTracking().Where(x => x.Id == o.UnitId).Select(x => x.Serial).FirstOrDefaultAsync();
|
||||
{
|
||||
if (!vc.Has("unitserial", o.UnitId))
|
||||
vc.Add(await ct.Unit.AsNoTracking().Where(x => x.Id == o.UnitId).Select(x => x.Serial).FirstOrDefaultAsync(), "unitserial", o.UnitId);
|
||||
o.UnitViz = vc.Get("unitserial", o.UnitId);
|
||||
}
|
||||
|
||||
if (o.VendorSentToId != null)
|
||||
o.VendorSentToViz = await ct.Vendor.AsNoTracking().Where(x => x.Id == o.VendorSentToId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
{
|
||||
if (!vc.Has("vendorname", o.VendorSentToId))
|
||||
vc.Add(await ct.Vendor.AsNoTracking().Where(x => x.Id == o.VendorSentToId).Select(x => x.Name).FirstOrDefaultAsync(), "vendorname", o.VendorSentToId);
|
||||
o.VendorSentToViz = vc.Get("vendorname", o.VendorSentToId);
|
||||
}
|
||||
|
||||
if (o.VendorSentViaId != null)
|
||||
o.VendorSentViaViz = await ct.Vendor.AsNoTracking().Where(x => x.Id == o.VendorSentViaId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
{
|
||||
if (!vc.Has("vendorname", o.VendorSentViaId))
|
||||
vc.Add(await ct.Vendor.AsNoTracking().Where(x => x.Id == o.VendorSentViaId).Select(x => x.Name).FirstOrDefaultAsync(), "vendorname", o.VendorSentViaId);
|
||||
o.VendorSentViaViz = vc.Get("vendorname", o.VendorSentViaId);
|
||||
}
|
||||
}
|
||||
|
||||
TaxCode Tax = null;
|
||||
if (o.TaxCodeId != null)
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxCodeId);
|
||||
{
|
||||
if (!oc.Has("tax", o.TaxCodeId))
|
||||
{
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxCodeId);
|
||||
oc.Add(Tax, "tax", o.TaxCodeId);
|
||||
}
|
||||
else
|
||||
Tax = (TaxCode)oc.Get("tax", o.TaxCodeId);
|
||||
}
|
||||
|
||||
if (Tax != null)
|
||||
o.TaxCodeViz = Tax.Name;
|
||||
|
||||
@@ -3072,21 +3202,42 @@ namespace AyaNova.Biz
|
||||
if (calculateTotalsOnly == false)
|
||||
{
|
||||
if (o.PartWarehouseId != 0)
|
||||
o.PartWarehouseViz = await ct.PartWarehouse.AsNoTracking().Where(x => x.Id == o.PartWarehouseId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
{
|
||||
if (!vc.Has("partwarehouse", o.PartWarehouseId))
|
||||
vc.Add(await ct.PartWarehouse.AsNoTracking().Where(x => x.Id == o.PartWarehouseId).Select(x => x.Name).FirstOrDefaultAsync(), "partwarehouse", o.PartWarehouseId);
|
||||
o.PartWarehouseViz = vc.Get("partwarehouse", o.PartWarehouseId);
|
||||
}
|
||||
}
|
||||
Part part = null;
|
||||
if (o.PartId != 0)
|
||||
part = await ct.Part.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.PartId);
|
||||
{
|
||||
if (!oc.Has("part", o.PartId))
|
||||
{
|
||||
part = await ct.Part.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.PartId);
|
||||
oc.Add(part, "part", o.PartId);
|
||||
}
|
||||
else
|
||||
part = (Part)oc.Get("part", o.PartId);
|
||||
}
|
||||
else
|
||||
return;//this should never happen but this is insurance in case it does
|
||||
|
||||
o.PartDescriptionViz = part.Description;
|
||||
o.PartNameViz = part.Name;
|
||||
o.UpcViz = part.UPC;
|
||||
|
||||
|
||||
TaxCode Tax = null;
|
||||
if (o.TaxPartSaleId != null)
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxPartSaleId);
|
||||
{
|
||||
if (!oc.Has("tax", o.TaxPartSaleId))
|
||||
{
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxPartSaleId);
|
||||
oc.Add(Tax, "tax", o.TaxPartSaleId);
|
||||
}
|
||||
else
|
||||
Tax = (TaxCode)oc.Get("tax", o.TaxPartSaleId);
|
||||
}
|
||||
|
||||
if (Tax != null)
|
||||
o.TaxCodeViz = Tax.Name;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user