This commit is contained in:
@@ -256,52 +256,68 @@ namespace AyaNova.Api.Controllers
|
||||
var u = await ct.Unit.AsNoTracking().Where(x => x.Id == id).FirstOrDefaultAsync();
|
||||
if (u == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
UnitServiceWarrantyInfo ret = new UnitServiceWarrantyInfo();
|
||||
ret.PurchaseReceiptNumber = u.Receipt;
|
||||
ret.PurchaseDate = u.PurchasedDate;
|
||||
ret.PurchaseFromVendorId = u.PurchasedFromVendorId;
|
||||
if (u.PurchasedFromVendorId != null)
|
||||
ret.PurchasedFromVendor = await ct.Vendor.AsNoTracking().Where(x => x.Id == u.PurchasedFromVendorId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
|
||||
//Warranty terms
|
||||
//WarrantyLength is in months
|
||||
//UnitModel warranty has precedence always except when Unit OverrideModelWarranty is true or there is no unitmodel set
|
||||
UnitModel unitModel = null;
|
||||
if (u.UnitModelId != null)
|
||||
unitModel = await ct.UnitModel.AsNoTracking().Where(x => x.Id == u.UnitModelId).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
if (u.OverrideModelWarranty || unitModel == null)
|
||||
{
|
||||
|
||||
//get warranty terms from the unit itself
|
||||
ret.LifeTimeWarranty = u.LifeTimeWarranty;
|
||||
ret.WarrantyTerms = u.WarrantyTerms;
|
||||
if (!u.LifeTimeWarranty && u.WarrantyLength != null && u.PurchasedDate != null)
|
||||
ret.WarrantyExpiryDate = ((DateTime)u.PurchasedDate).AddMonths((int)u.WarrantyLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//get warranty terms from the unit model
|
||||
ret.LifeTimeWarranty = unitModel.LifeTimeWarranty;
|
||||
ret.WarrantyTerms = unitModel.WarrantyTerms;
|
||||
if (!unitModel.LifeTimeWarranty && unitModel.WarrantyLength != null && u.PurchasedDate != null)
|
||||
ret.WarrantyExpiryDate = ((DateTime)u.PurchasedDate).AddMonths((int)unitModel.WarrantyLength);
|
||||
}
|
||||
|
||||
//last workorders
|
||||
List<RecentWorkOrder> recentWorkOrders=new List<RecentWorkOrder>();
|
||||
var lastWoItemIds = await ct.WorkOrderItemUnit.AsNoTracking().Where(z => z.UnitId == id).OrderByDescending(z => z.Id).Take(3).Select(z => z.WorkOrderItemId).ToListAsync();
|
||||
//Recent workorders
|
||||
//arbitrarily returning last 3 work orders to account for one of them being the current active work order and not wanting to try to filter in closed status workorders for reasons
|
||||
//limiting to three because there is already an all workorders option from unit itself if they are really researching the history and it's about three clicks away from this info
|
||||
|
||||
foreach (long woitemid in lastWoItemIds){
|
||||
var woid=await ct.WorkOrderItem.AsNoTracking().Where(x => x.Id == woitemid).OrderByDescending(x=>x.WorkOrderId).Select(x => x.WorkOrderId).FirstOrDefaultAsync();
|
||||
recentWorkOrders.Add(
|
||||
await ct.WorkOrder.AsNoTracking().Where(x=>x.Id==woid).Select(x=>new RecentWorkOrder(x.Serial,x.Id,x.ServiceDate)).FirstOrDefaultAsync();
|
||||
List<RecentWorkOrder> RecentWorkOrders = new List<RecentWorkOrder>();
|
||||
var lastWoItemIds = await ct.WorkOrderItemUnit.AsNoTracking().Where(z => z.UnitId == id).OrderByDescending(z => z.Id).Take(3).Select(z => z.WorkOrderItemId).ToListAsync();
|
||||
foreach (long woitemid in lastWoItemIds)
|
||||
{
|
||||
var woid = await ct.WorkOrderItem.AsNoTracking().Where(x => x.Id == woitemid).OrderByDescending(x => x.WorkOrderId).Select(x => x.WorkOrderId).FirstOrDefaultAsync();
|
||||
ret.RecentWorkOrders.Add(
|
||||
await ct.WorkOrder.AsNoTracking().Where(x => x.Id == woid).Select(x => new RecentWorkOrder(x.Serial, x.Id, x.ServiceDate)).FirstOrDefaultAsync()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return Ok(ApiOkResponse.Response(new
|
||||
{
|
||||
unit = new AddressRecord(u.Serial, u.Address, u.City, u.Region, u.Country, u.Latitude, u.Longitude)
|
||||
}));
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
}
|
||||
|
||||
private record RecentWorkOrder(long? Serial, long? Id, DateTime? ServiceDate);
|
||||
internal record RecentWorkOrder(long? Serial, long? Id, DateTime? ServiceDate);
|
||||
|
||||
private record UnitServiceWarrantyInfo(
|
||||
List<RecentWorkOrder> RecentWorkOrders,
|
||||
DateTime? PurchaseDate,
|
||||
string PurchasedFromVendor,
|
||||
long? PurchaseFromVendorId,
|
||||
string PurchaseReceiptNumber,
|
||||
bool LifeTimeWarranty,
|
||||
DateTime? WarrantyExpiryDate,
|
||||
string WarrantyTerms
|
||||
);
|
||||
internal class UnitServiceWarrantyInfo
|
||||
{
|
||||
internal List<RecentWorkOrder> RecentWorkOrders { get; set; }
|
||||
internal DateTime? PurchaseDate { get; set; }
|
||||
internal string PurchasedFromVendor { get; set; }
|
||||
internal long? PurchaseFromVendorId { get; set; }
|
||||
internal string PurchaseReceiptNumber { get; set; }
|
||||
internal bool LifeTimeWarranty { get; set; }
|
||||
internal DateTime? WarrantyExpiryDate { get; set; }
|
||||
internal string WarrantyTerms { get; set; }
|
||||
}
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
@@ -45,7 +45,7 @@ namespace AyaNova.Models
|
||||
[NotMapped]
|
||||
public string ReplacedByUnitViz { get; set; }
|
||||
public bool OverrideModelWarranty { get; set; }
|
||||
public int? WarrantyLength { get; set; }
|
||||
public int? WarrantyLength { get; set; }//MONTHS
|
||||
public string WarrantyTerms { get; set; }
|
||||
// public bool UsesBanking { get; set; }
|
||||
public long? ContractId { get; set; }
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace AyaNova.Models
|
||||
public DateTime? IntroducedDate { get; set; }
|
||||
public bool Discontinued { get; set; }
|
||||
public DateTime? DiscontinuedDate { get; set; }
|
||||
public int? WarrantyLength { get; set; }
|
||||
public int? WarrantyLength { get; set; }//MONTHS
|
||||
public string WarrantyTerms { get; set; }
|
||||
|
||||
public UnitModel()
|
||||
|
||||
Reference in New Issue
Block a user