This commit is contained in:
@@ -387,24 +387,27 @@ namespace AyaNova.Biz
|
|||||||
mFetchedContractAlready = false;
|
mFetchedContractAlready = false;
|
||||||
|
|
||||||
//CONTRACT AUTO SET
|
//CONTRACT AUTO SET
|
||||||
|
//failsafe
|
||||||
|
newObj.ContractId = null;
|
||||||
|
|
||||||
if (newObj.CustomerId != 0)
|
if (newObj.CustomerId != 0)
|
||||||
{
|
{
|
||||||
//unit->customer->headoffice
|
//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 }).FirstOrDefaultAsync();
|
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();
|
||||||
|
|
||||||
|
//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)
|
||||||
|
newObj.ContractId = cust.contractId;
|
||||||
|
|
||||||
if (cust.contractId == null && cust.headofficeId != null)
|
if (cust.contractId == null && cust.headofficeId != null)
|
||||||
{
|
{
|
||||||
var hoContractId = await ct.HeadOffice.AsNoTracking().Where(z => z.Id == cust.headofficeId).Select(z => z.ContractId).FirstOrDefaultAsync();
|
var head = await ct.HeadOffice.AsNoTracking().Where(z => z.Id == cust.headofficeId).Select(z => new { contractId = z.ContractId, contractExpires = z.ContractExpires }).FirstOrDefaultAsync();
|
||||||
if (hoContractId != null)
|
if (head.contractId != null && head.contractExpires < DateTime.UtcNow)
|
||||||
newObj.ContractId = hoContractId;
|
newObj.ContractId = head.contractId;
|
||||||
}
|
}
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//RESPONSE TIME / COMPLETE BY AUTO SET
|
//RESPONSE TIME / COMPLETE BY AUTO SET
|
||||||
//precedence: manually pre-set -> contract -> global biz
|
//precedence: manually pre-set -> contract -> global biz
|
||||||
if (newObj.CompleteByDate != null)
|
if (newObj.CompleteByDate != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user