This commit is contained in:
@@ -300,7 +300,7 @@ namespace AyaNova.Api.Controllers
|
||||
+ $"where aworkorderitemunit.unitid={id} "
|
||||
+ "order by aworkorder.serial DESC "
|
||||
+ "limit 3";
|
||||
using (var cmd = ct.Database.GetDbConnection().CreateCommand())
|
||||
using (var cmd = ct.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
await ct.Database.OpenConnectionAsync();
|
||||
cmd.CommandText = q;
|
||||
@@ -343,5 +343,37 @@ namespace AyaNova.Api.Controllers
|
||||
public string WarrantyTerms { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get Unit Contract name/id if active and not expired
|
||||
/// </summary>
|
||||
/// <param name="id">UnitId</param>
|
||||
/// <returns>Contract name and Id</returns>
|
||||
[HttpGet("active-contract/{id}")]
|
||||
public async Task<IActionResult> GetUnitActiveContract([FromRoute] long id)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Unit))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
var ret = new NameIdItem { Name = string.Empty, Id = 0 };
|
||||
var UnitContractInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == id).Select(x => new { x.ContractId, x.ContractExpires }).FirstOrDefaultAsync();
|
||||
if (UnitContractInfo == null || UnitContractInfo.ContractExpires < DateTime.UtcNow)//none or expired
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
|
||||
var c = await ct.Contract.AsNoTracking().FirstOrDefaultAsync(x => x.Id == UnitContractInfo.ContractId);
|
||||
if (c == null || c.Active == false)
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
|
||||
ret.Name = c.Name;
|
||||
ret.Id = c.Id;
|
||||
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
@@ -5939,9 +5939,7 @@ namespace AyaNova.Biz
|
||||
|
||||
#region WorkOrderItemUnit level
|
||||
|
||||
//this is set by validation for further processing if applicable
|
||||
private long? newOrChangedActiveUnitContractId = null;
|
||||
private long newOrChangedActiveUnitWorkOrderId = 0;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//EXISTS
|
||||
@@ -5975,14 +5973,6 @@ namespace AyaNova.Biz
|
||||
await UnitHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
||||
await UnitPopulateVizFields(newObject);
|
||||
|
||||
//update workorder with new contract??
|
||||
//Note this is determined if applicable and set during validation
|
||||
if (newOrChangedActiveUnitContractId != null && newOrChangedActiveUnitWorkOrderId != 0)
|
||||
{
|
||||
WorkOrder w = await ct.WorkOrder.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newOrChangedActiveUnitWorkOrderId);
|
||||
w.ContractId = newOrChangedActiveUnitContractId;
|
||||
await WorkOrderPutAsync(w);
|
||||
}
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
@@ -6042,14 +6032,7 @@ namespace AyaNova.Biz
|
||||
await UnitHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||
await UnitPopulateVizFields(putObject);
|
||||
|
||||
//update workorder with new contract??
|
||||
//Note this is determined if applicable and set during validation
|
||||
if (newOrChangedActiveUnitContractId != null && newOrChangedActiveUnitWorkOrderId != 0)
|
||||
{
|
||||
WorkOrder w = await ct.WorkOrder.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newOrChangedActiveUnitWorkOrderId);
|
||||
w.ContractId = newOrChangedActiveUnitContractId;
|
||||
await WorkOrderPutAsync(w);
|
||||
}
|
||||
|
||||
return putObject;
|
||||
}
|
||||
|
||||
@@ -6212,60 +6195,60 @@ namespace AyaNova.Biz
|
||||
if (proposedObj.UnitId < 1 || !await ct.Unit.AnyAsync(x => x.Id == proposedObj.UnitId))
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UnitId");
|
||||
|
||||
//Contracted unit? Only one per work order is allowed
|
||||
if (isNew || proposedObj.UnitId != currentObj.UnitId)
|
||||
{
|
||||
bool AlreadyHasAContractedUnit = false;
|
||||
//See if this unit has a contract, if so then see if the contract is active, if so then iterate workorder graph and check all other units for same
|
||||
//if any found then reject this
|
||||
var proposedUnitInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == proposedObj.UnitId).Select(x => new { x.ContractExpires, x.ContractId }).FirstOrDefaultAsync();
|
||||
if (proposedUnitInfo.ContractId != null && proposedUnitInfo.ContractExpires > DateTime.UtcNow)
|
||||
{
|
||||
//added woitemunit has a contract and apparently unexpired so need to check if contract is still active
|
||||
newOrChangedActiveUnitContractId = proposedUnitInfo.ContractId;
|
||||
if (await ct.Contract.AsNoTracking().Where(z => z.Id == proposedUnitInfo.ContractId).Select(x => x.Active).FirstOrDefaultAsync() == true)
|
||||
{
|
||||
//iterate work order and check for other contracted unit
|
||||
var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, proposedObj.WorkOrderItemId, ct);
|
||||
newOrChangedActiveUnitWorkOrderId = woId.WorkOrderId;//save for later contract update if necessary
|
||||
var w = await WorkOrderGetFullAsync(woId.WorkOrderId);
|
||||
// //Contracted unit? Only one per work order is allowed
|
||||
// if (isNew || proposedObj.UnitId != currentObj.UnitId)
|
||||
// {
|
||||
// bool AlreadyHasAContractedUnit = false;
|
||||
// //See if this unit has a contract, if so then see if the contract is active, if so then iterate workorder graph and check all other units for same
|
||||
// //if any found then reject this
|
||||
// var proposedUnitInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == proposedObj.UnitId).Select(x => new { x.ContractExpires, x.ContractId }).FirstOrDefaultAsync();
|
||||
// if (proposedUnitInfo.ContractId != null && proposedUnitInfo.ContractExpires > DateTime.UtcNow)
|
||||
// {
|
||||
// //added woitemunit has a contract and apparently unexpired so need to check if contract is still active
|
||||
// newOrChangedActiveUnitContractId = proposedUnitInfo.ContractId;
|
||||
// if (await ct.Contract.AsNoTracking().Where(z => z.Id == proposedUnitInfo.ContractId).Select(x => x.Active).FirstOrDefaultAsync() == true)
|
||||
// {
|
||||
// //iterate work order and check for other contracted unit
|
||||
// var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, proposedObj.WorkOrderItemId, ct);
|
||||
// newOrChangedActiveUnitWorkOrderId = woId.WorkOrderId;//save for later contract update if necessary
|
||||
// var w = await WorkOrderGetFullAsync(woId.WorkOrderId);
|
||||
|
||||
//iterate, look for *other* woitemunit records, are they contracted already?
|
||||
foreach (WorkOrderItem wi in w.Items)
|
||||
{
|
||||
if (AlreadyHasAContractedUnit) continue;
|
||||
foreach (WorkOrderItemUnit wiu in wi.Units)
|
||||
{
|
||||
if (isNew || wiu.Id != currentObj.Id)
|
||||
{
|
||||
var existingUnitInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == wiu.UnitId).Select(x => new { x.ContractExpires, x.ContractId }).FirstOrDefaultAsync();
|
||||
if (existingUnitInfo != null)
|
||||
{
|
||||
if (existingUnitInfo.ContractId != null && existingUnitInfo.ContractExpires > DateTime.UtcNow)
|
||||
{
|
||||
//Ok, we have a pre-existing contract, is it active?
|
||||
if (await ct.Contract.AsNoTracking().Where(x => x.Id == existingUnitInfo.ContractId).Select(x => x.Active).FirstOrDefaultAsync())
|
||||
{
|
||||
AlreadyHasAContractedUnit = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (AlreadyHasAContractedUnit)
|
||||
{
|
||||
AddError(ApiErrorCode.VALIDATION_WO_MULTIPLE_CONTRACTED_UNITS, "UnitId");
|
||||
return;//this is a completely disqualifying error
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newOrChangedActiveUnitContractId = null;//just in case it's non active but present so later biz actions don't process it
|
||||
}
|
||||
}
|
||||
}
|
||||
// //iterate, look for *other* woitemunit records, are they contracted already?
|
||||
// foreach (WorkOrderItem wi in w.Items)
|
||||
// {
|
||||
// if (AlreadyHasAContractedUnit) continue;
|
||||
// foreach (WorkOrderItemUnit wiu in wi.Units)
|
||||
// {
|
||||
// if (isNew || wiu.Id != currentObj.Id)
|
||||
// {
|
||||
// var existingUnitInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == wiu.UnitId).Select(x => new { x.ContractExpires, x.ContractId }).FirstOrDefaultAsync();
|
||||
// if (existingUnitInfo != null)
|
||||
// {
|
||||
// if (existingUnitInfo.ContractId != null && existingUnitInfo.ContractExpires > DateTime.UtcNow)
|
||||
// {
|
||||
// //Ok, we have a pre-existing contract, is it active?
|
||||
// if (await ct.Contract.AsNoTracking().Where(x => x.Id == existingUnitInfo.ContractId).Select(x => x.Active).FirstOrDefaultAsync())
|
||||
// {
|
||||
// AlreadyHasAContractedUnit = true;
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (AlreadyHasAContractedUnit)
|
||||
// {
|
||||
// AddError(ApiErrorCode.VALIDATION_WO_MULTIPLE_CONTRACTED_UNITS, "UnitId");
|
||||
// return;//this is a completely disqualifying error
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// newOrChangedActiveUnitContractId = null;//just in case it's non active but present so later biz actions don't process it
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2280,5 +2280,6 @@
|
||||
"UnitWarrantyInfo":"Garantieinformationen",
|
||||
"Warranty":"Garantie",
|
||||
"WarrantyExpires":"Gültig bis",
|
||||
"RecentWorkOrders":"Letzte Arbeitsaufträge"
|
||||
"RecentWorkOrders":"Letzte Arbeitsaufträge",
|
||||
"ApplyUnitContract":"Vertrag '{0}' dieser Einheit auf Arbeitsauftrag anwenden?"
|
||||
}
|
||||
@@ -2280,7 +2280,8 @@
|
||||
"UnitWarrantyInfo":"Warranty information",
|
||||
"Warranty":"Warranty",
|
||||
"WarrantyExpires":"Valid until",
|
||||
"RecentWorkOrders":"Recent Work orders"
|
||||
"RecentWorkOrders":"Recent Work orders",
|
||||
"ApplyUnitContract":"Apply this Unit's Contract '{0}' to Work order?"
|
||||
|
||||
|
||||
}
|
||||
@@ -2280,5 +2280,6 @@
|
||||
"UnitWarrantyInfo":"Información de garantía",
|
||||
"Warranty":"Garantía",
|
||||
"WarrantyExpires":"Válido hasta",
|
||||
"RecentWorkOrders":"Órdenes de trabajo recientes"
|
||||
"RecentWorkOrders":"Órdenes de trabajo recientes",
|
||||
"ApplyUnitContract":"¿Aplicar el contrato '{0}' de esta unidad a la orden de trabajo?"
|
||||
}
|
||||
@@ -2280,5 +2280,6 @@
|
||||
"UnitWarrantyInfo":"Informations de garantie",
|
||||
"Warranty":"Garantie",
|
||||
"WarrantyExpires":"Valable jusque",
|
||||
"RecentWorkOrders":"Ordres de travail récents"
|
||||
"RecentWorkOrders":"Ordres de travail récents",
|
||||
"ApplyUnitContract":"Appliquer le contrat '{0}' de cette unité à l'ordre de travail?"
|
||||
}
|
||||
@@ -606,7 +606,7 @@ namespace AyaNova.Util
|
||||
c.Name = "Bronze";
|
||||
c.Active = true;
|
||||
c.Notes = "These are notes providing additional information when users view the contract";
|
||||
c.AlertNotes = "These are alert notes displayed on workorders about this contract";
|
||||
c.AlertNotes = "These are alert notes displayed on workorders about this BRONZE contract";
|
||||
c.PartsOverridePct = 5m;
|
||||
c.PartsOverrideType = ContractOverrideType.PriceDiscount;
|
||||
c.ServiceRatesOverridePct = 5m;
|
||||
@@ -641,7 +641,7 @@ namespace AyaNova.Util
|
||||
c.Name = "Silver";
|
||||
c.Active = true;
|
||||
c.Notes = "These are notes providing additional information when users view the contract";
|
||||
c.AlertNotes = "These are alert notes displayed on workorders about this contract";
|
||||
c.AlertNotes = "These are alert notes displayed on workorders about this SILVER contract";
|
||||
c.PartsOverridePct = 10m;
|
||||
c.PartsOverrideType = ContractOverrideType.PriceDiscount;
|
||||
c.ServiceRatesOverridePct = 10m;
|
||||
@@ -676,7 +676,7 @@ namespace AyaNova.Util
|
||||
c.Name = "Gold";
|
||||
c.Active = true;
|
||||
c.Notes = "These are notes providing additional information when users view the contract";
|
||||
c.AlertNotes = "These are alert notes displayed on workorders about this contract";
|
||||
c.AlertNotes = "These are alert notes displayed on workorders about this GOLD contract";
|
||||
c.PartsOverridePct = 15m;
|
||||
c.PartsOverrideType = ContractOverrideType.PriceDiscount;
|
||||
c.ServiceRatesOverridePct = 15m;
|
||||
|
||||
Reference in New Issue
Block a user