This commit is contained in:
2021-08-16 20:03:35 +00:00
parent 48447c9a0b
commit 023dfa5ab6

View File

@@ -121,7 +121,7 @@ namespace AyaNova.Api.Controllers
PartBiz biz = PartBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
var o = await biz.PutAsync(updatedObject);
var o = await biz.PutAsync(updatedObject);
if (o == null)
{
if (biz.Errors.Exists(z => z.Code == ApiErrorCode.CONCURRENCY_CONFLICT))
@@ -258,7 +258,7 @@ namespace AyaNova.Api.Controllers
return Ok(ApiOkResponse.Response(o));
}
/// <summary>
/// <summary>
/// Update part cost for part
/// </summary>
/// <param name="newCost">new cost of part</param>
@@ -274,7 +274,7 @@ namespace AyaNova.Api.Controllers
PartBiz biz = PartBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (await biz.PutPartCostAsync(id, newCost) == false)
{
if (biz.Errors.Exists(z => z.Code == ApiErrorCode.CONCURRENCY_CONFLICT))
@@ -286,13 +286,15 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Get on hand inventory values in all warehouses for part id specified
/// <summary>
/// Get most recent Part inventory records in all warehouses for part id specified
/// most recent is the latest "end" of the inventory chain containing the current balance as of the point in time this is fetched
/// these values are required to make inventory adjustments
/// </summary>
/// <param name="partId"></param>
/// <returns>Array of part on hand inventory levels by warehouse</returns>
[HttpGet("on-hand-inventory/{partId}")]
public async Task<IActionResult> GetPartOnHandInventory([FromRoute] long partId)
/// <returns>List of part inventory records for each warehouse</returns>
[HttpGet("latest-inventory/{partId}")]
public async Task<IActionResult> GetLatestInventory([FromRoute] long partId)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
@@ -303,21 +305,19 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
//get all warehouses
var allWhs=await ct.PartWarehouse.AsNoTracking().ToListAsync();
var allWhs = await ct.PartWarehouse.AsNoTracking().ToListAsync();
//iterate them and compile the last inventory for each warehouse for this part
foreach(PartWarehouse pw in allWhs){
}
var LastEntry = await ct.PartInventory.OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == newDtObject.PartId && m.PartWarehouseId == newDtObject.PartWarehouseId);
var o = await ct.PartStockLevel.AsNoTracking().Where(z => z.PartId == partId).OrderBy(z => z.PartWarehouseId).ToListAsync();
foreach (PartStockLevel ps in o)
List<PartInventory> ret = new List<PartInventory>();
foreach (PartWarehouse pw in allWhs)
{
ps.PartWarehouseDisplay = await ct.PartWarehouse.AsNoTracking().Where(z => z.Id == ps.PartWarehouseId).Select(z => z.Name).FirstOrDefaultAsync();
var LastEntry = await ct.PartInventory.AsNoTracking().OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == partId && m.PartWarehouseId == pw.Id);
if (LastEntry != null)
{
ret.Add(LastEntry);
}
}
return Ok(ApiOkResponse.Response(o));
return Ok(ApiOkResponse.Response(ret));
}