This commit is contained in:
2021-05-17 23:58:44 +00:00
parent 699f4b9afe
commit a3b49ed102

View File

@@ -328,6 +328,7 @@ namespace AyaNova.Biz
if (ayaEvent == AyaEvent.Created)
{
await AutoSetContractAsync(newObj);
await AutoSetAddressAsync(newObj);
return;
}
@@ -338,10 +339,47 @@ namespace AyaNova.Biz
if (newObj.CustomerId != oldObj.CustomerId)
{
await AutoSetContractAsync(newObj);
}
await AutoSetAddressAsync(newObj);
}
}
}
private async Task AutoSetAddressAsync(WorkOrder newObj)
{
if (newObj.CustomerId == 0)
return;
var cust = await ct.Customer.AsNoTracking().Where(z => z.Id == newObj.CustomerId).FirstOrDefaultAsync();
if (cust == null)
return;
newObj.PostAddress = cust.PostAddress;
newObj.PostCity = cust.PostCity;
newObj.PostRegion = cust.PostRegion;
newObj.PostCountry = cust.PostCountry;
newObj.PostCode = cust.PostCode;
newObj.Address = cust.Address;
newObj.City = cust.City;
newObj.Region = cust.Region;
newObj.Country = cust.Country;
newObj.Latitude = cust.Latitude;
newObj.Longitude = cust.Longitude;
if (cust.BillHeadOffice == true && cust.HeadOfficeId != null)
{
var head = await ct.HeadOffice.AsNoTracking().Where(z => z.Id == cust.HeadOfficeId).FirstOrDefaultAsync();
if (head == null)
return;
newObj.PostAddress = head.PostAddress;
newObj.PostCity = head.PostCity;
newObj.PostRegion = head.PostRegion;
newObj.PostCountry = head.PostCountry;
newObj.PostCode = head.PostCode;
}
}
private async Task AutoSetContractAsync(WorkOrder newObj)
{
//first reset contract fetched flag so a fresh copy is taken
@@ -361,8 +399,10 @@ namespace AyaNova.Biz
}
else
newObj.ContractId = cust.contractId;//if ultimately no contract for this customer or ho then it's set to null anyway which is what we want
}else{
newObj.ContractId=null;//no customer then contract
}
else
{
newObj.ContractId = null;//no customer then contract
}
//RESPONSE TIME / COMPLETE BY AUTO SET
@@ -739,10 +779,10 @@ namespace AyaNova.Biz
//popup Alert notes
//Customer notes first then others below
var customerAlert = await ct.Customer.AsNoTracking().Where(x => x.Id == o.CustomerId).Select(x => new{ PopUpNotes=x.PopUpNotes,Name= x.Name}).FirstOrDefaultAsync();
if (!string.IsNullOrWhiteSpace(customerAlert.PopUpNotes))
var customerAlert = await ct.Customer.AsNoTracking().Where(x => x.Id == o.CustomerId).Select(x => x.PopUpNotes).FirstOrDefaultAsync();
if (!string.IsNullOrWhiteSpace(customerAlert))
{
o.AlertViz = $"{await Translate("Customer")} {customerAlert.Name}:\n{customerAlert.PopUpNotes}\n\n";
o.AlertViz = $"{await Translate("Customer")}\n{customerAlert}\n\n";
}
if (o.ProjectId != null)
@@ -754,7 +794,7 @@ namespace AyaNova.Biz
o.ContractViz = contractVizFields.Name;
if (!string.IsNullOrWhiteSpace(contractVizFields.AlertNotes))
{
o.AlertViz += $"{await Translate("Contract")} {contractVizFields.Name}:\n{contractVizFields.AlertNotes}\n\n";
o.AlertViz += $"{await Translate("Contract")}\n{contractVizFields.AlertNotes}\n\n";
}
}
else