diff --git a/server/AyaNova/Controllers/GlobalBizSettingsController.cs b/server/AyaNova/Controllers/GlobalBizSettingsController.cs index 00bbad26..1e996cb1 100644 --- a/server/AyaNova/Controllers/GlobalBizSettingsController.cs +++ b/server/AyaNova/Controllers/GlobalBizSettingsController.cs @@ -99,6 +99,9 @@ namespace AyaNova.Api.Controllers [HttpGet("client")] public ActionResult GetClientGlobalBizSettings() { + //## NOTE: these are settings that the Client needs to see for standard operations + //NOT the settings that the user changes in the global settings form which is fetched above + //so do not include anything here unless the client needs it if (serverState.IsClosed) { //Exception for SuperUser account to handle licensing issues diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index faac05bd..0d56a537 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -328,24 +328,39 @@ namespace AyaNova.Biz if (ayaEvent == AyaEvent.Created) { - //find and set effective contract if user didn't set it already + //CONTRACT AUTO SET if (newObj.ContractId == null && newObj.CustomerId != 0) { //customer->headoffice var cust = await ct.Customer.AsNoTracking().Where(z => z.Id == newObj.CustomerId).Select(z => new { headofficeId = z.HeadOfficeId, contractId = z.ContractId }).FirstOrDefaultAsync(); - if(cust.contractId==null && cust.headofficeId!=null){ - var hoContractId=await ct.HeadOffice.AsNoTracking().Where(z => z.Id == cust.headofficeId).Select(z => z.ContractId).FirstOrDefaultAsync(); - if(hoContractId!=null){ - newObj.ContractId=hoContractId; - } - - }else{ - newObj.ContractId=cust.contractId; - } + if (cust.contractId == null && cust.headofficeId != null) + { + var hoContractId = await ct.HeadOffice.AsNoTracking().Where(z => z.Id == cust.headofficeId).Select(z => z.ContractId).FirstOrDefaultAsync(); + if (hoContractId != null) + newObj.ContractId = hoContractId; + } + else + newObj.ContractId = cust.contractId; } - //set default response time - todo: check contract if applied then check global if not + //RESPONSE TIME / COMPLETE BY AUTO SET + //precedence: manuall set -> contract -> global biz setting + if (newObj.CompleteByDate != null) + { + if (newObj.ContractId != null) + { + await GetCurrentContractFromContractIdAsync(newObj.ContractId); + if (mContractInEffect != null && mContractInEffect.ResponseTime != TimeSpan.Zero) + newObj.CompleteByDate = DateTime.UtcNow.Add(mContractInEffect.ResponseTime); + } + else + { + if(AyaNova.Util.ServerGlobalBizSettings.WorkOrderCompleteByAge!=TimeSpan.Zero) + newObj.CompleteByDate = DateTime.UtcNow.Add(AyaNova.Util.ServerGlobalBizSettings.WorkOrderCompleteByAge); + + } + } + } diff --git a/server/AyaNova/util/ServerGlobalBizSettings.cs b/server/AyaNova/util/ServerGlobalBizSettings.cs index 91b9c605..c9468ed9 100644 --- a/server/AyaNova/util/ServerGlobalBizSettings.cs +++ b/server/AyaNova/util/ServerGlobalBizSettings.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using AyaNova.Models; @@ -14,13 +15,11 @@ namespace AyaNova.Util { internal static bool SearchCaseSensitiveOnly { get; set; } - internal static bool UseInventory { get; set; } - //TAX CODE DEFAULTS + internal static bool UseInventory { get; set; } internal static long? TaxPartPurchaseId { get; set; } internal static long? TaxPartSaleId { get; set; } internal static long? TaxRateSaleId { get; set; } - - + internal static TimeSpan WorkOrderCompleteByAge { get; set; } /// @@ -47,6 +46,7 @@ namespace AyaNova.Util TaxPartPurchaseId = global.TaxPartPurchaseId; TaxPartSaleId = global.TaxPartSaleId; TaxRateSaleId = global.TaxRateSaleId; + WorkOrderCompleteByAge=global.WorkOrderCompleteByAge; }