From a3b49ed102812f92b47ef212cfc3961fe9d3c0fd Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 17 May 2021 23:58:44 +0000 Subject: [PATCH] --- server/AyaNova/biz/WorkOrderBiz.cs | 54 ++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index 9b2ef737..c0e187bc 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -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