This commit is contained in:
2021-05-18 14:12:45 +00:00
parent bdc3ca533d
commit 91cfa66143

View File

@@ -394,15 +394,15 @@ namespace AyaNova.Biz
{
//precedence: unit->customer->headoffice
var cust = await ct.Customer.AsNoTracking().Where(z => z.Id == newObj.CustomerId).Select(z => new { headofficeId = z.HeadOfficeId, contractId = z.ContractId, contractExpires = z.ContractExpires }).FirstOrDefaultAsync();
//var testCust = await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z=>z.Id==newObj.CustomerId);
//first set it to the customer one if available in case the ho one has expired then set the ho if applicable
if (cust.contractId != null && cust.contractExpires < DateTime.UtcNow)
if (cust.contractId != null && cust.contractExpires > DateTime.UtcNow)
newObj.ContractId = cust.contractId;
if (cust.contractId == null && cust.headofficeId != null)
{
var head = await ct.HeadOffice.AsNoTracking().Where(z => z.Id == cust.headofficeId).Select(z => new { contractId = z.ContractId, contractExpires = z.ContractExpires }).FirstOrDefaultAsync();
if (head.contractId != null && head.contractExpires < DateTime.UtcNow)
if (head.contractId != null && head.contractExpires > DateTime.UtcNow)
newObj.ContractId = head.contractId;
}
}