This commit is contained in:
2021-02-19 16:13:41 +00:00
parent d8e5f73823
commit b8a35b1eb2
4 changed files with 93 additions and 27 deletions

View File

@@ -152,20 +152,20 @@ namespace AyaNova.Api.Controllers
/// <summary> // /// <summary>
/// Get count of PartWarehouses // /// Get count of PartWarehouses
/// </summary> // /// </summary>
/// <returns>Total number of part warehouses (active or not)</returns> // /// <returns>Total number of part warehouses (active or not)</returns>
[HttpGet("count")] // [HttpGet("count")]
public async Task<IActionResult> GetCount() // public async Task<IActionResult> GetCount()
{ // {
if (!serverState.IsOpen) // if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); // return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!Authorized.HasSelectRole(HttpContext.Items, AyaType.PartWarehouse)) // if (!Authorized.HasSelectRole(HttpContext.Items, AyaType.PartWarehouse))
return StatusCode(403, new ApiNotAuthorizedResponse()); // return StatusCode(403, new ApiNotAuthorizedResponse());
return Ok(ApiOkResponse.Response(await ct.PartWarehouse.CountAsync())); // return Ok(ApiOkResponse.Response(await ct.PartWarehouse.CountAsync()));
} // }
//------------ //------------

View File

@@ -102,27 +102,78 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//GET //GET
// //
internal async Task<PurchaseOrder> GetAsync(long id, bool populateNames, bool logTheGetEvent) internal async Task<PurchaseOrder> GetAsync(long id, bool populateDisplayFields, bool logTheGetEvent)
{ {
var ret = await ct.PurchaseOrder.Include(z => z.Items).AsNoTracking().SingleOrDefaultAsync(z => z.Id == id); var ret = await ct.PurchaseOrder.Include(z => z.Items).AsNoTracking().SingleOrDefaultAsync(z => z.Id == id);
//populate names for client ui
foreach (PurchaseOrderItem item in ret.Items) await SetDisplayFields(ret);
{
item.DisplayPartNumber = await ct.Part.AsNoTracking().Where(x => x.Id == item.PartId).Select(x => x.PartNumber).SingleAsync();
item.DisplayWarehouse = await ct.PartWarehouse.AsNoTracking().Where(x => x.Id == item.PartWarehouseId).Select(x => x.Name).SingleAsync();
if (item.PartRequestedById != null)
item.DisplayRequestUser = await ct.User.AsNoTracking().Where(x => x.Id == item.PartRequestedById).Select(x => x.Name).SingleAsync();
if (item.WorkorderItemPartRequestId != null)
item.DisplayRequestWorkorder = "todo:woidfromleafnode";//MIGRATE_OUTSTANDING routine to get wo id from the woitempartrequestid
if (item.PurchaseTaxCodeId != null)
item.DisplayTaxCode = await ct.TaxCode.AsNoTracking().Where(x => x.Id == item.PurchaseTaxCodeId).Select(x => x.Name).SingleAsync();
}
if (logTheGetEvent && ret != null) if (logTheGetEvent && ret != null)
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct);
return ret; return ret;
} }
////////////////////////////////////////////////////////////////////////////////////////////////
//DISPLAY FIELDS
//
private async Task SetDisplayFields(PurchaseOrder po)
{
if (po == null) return;
//populate server fields for client ui
//Show Warehouses
po.DisplayWarehouses = await ct.PartWarehouse.CountAsync() > 1;
//Show PartRequest fields?
po.DisplayPartRequest = false;
foreach (PurchaseOrderItem item in po.Items)
{
item.DisplayPartNumber = await ct.Part.AsNoTracking().Where(x => x.Id == item.PartId).Select(x => x.PartNumber).SingleAsync();
item.DisplayWarehouse = await ct.PartWarehouse.AsNoTracking().Where(x => x.Id == item.PartWarehouseId).Select(x => x.Name).SingleAsync();
if (item.WorkorderItemPartRequestId != null)
{
po.DisplayPartRequest = true;
item.DisplayRequestWorkorder = "todo:woidfromleafnode";//MIGRATE_OUTSTANDING routine to get wo id from the woitempartrequestid
if (item.PartRequestedById != null)
item.DisplayRequestUser = await ct.User.AsNoTracking().Where(x => x.Id == item.PartRequestedById).Select(x => x.Name).SingleAsync();
}
TaxCode tax = null;
if (item.PurchaseTaxCodeId != null)
{
tax = await ct.TaxCode.AsNoTracking().Where(x => x.Id == item.PurchaseTaxCodeId).SingleAsync();
item.DisplayTaxCode = tax.Name;
}
//Calculate line totals
if (item.QuantityOrdered != 0 && item.PurchaseOrderCost != 0)
{
decimal dNet = item.QuantityOrdered * item.PurchaseOrderCost;
decimal dTaxA = 0M;
decimal dTaxB = 0M;
if (tax != null)
{
//Tax A is always just tax A percent times net...
dTaxA = tax.TaxA * dNet;
//Tax B on the other hand could be simple or tax on tax...
if (!tax.TaxOnTax)
dTaxB = tax.TaxB * dNet;//simple
else
dTaxB = (dNet + dTaxA) * tax.TaxB;//tax on tax
}
//set line total and taxes display values
item.DisplayTaxA = dTaxA;
item.DisplayTaxB = dTaxB;
item.DisplayNetTotal = dNet;
item.DisplayLineTotal = dNet + dTaxA + dTaxB;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE //UPDATE
// //

View File

@@ -42,6 +42,11 @@ namespace AyaNova.Models
[NotMapped, JsonIgnore] [NotMapped, JsonIgnore]
public AyaType AyaType { get => AyaType.PurchaseOrder; } public AyaType AyaType { get => AyaType.PurchaseOrder; }
[NotMapped]
public bool DisplayWarehouses { get; set; }
[NotMapped]
public bool DisplayPartRequest { get; set; }
}//eoc }//eoc
}//eons }//eons

View File

@@ -34,7 +34,7 @@ namespace AyaNova.Models
public PurchaseOrder PurchaseOrder { get; set; } public PurchaseOrder PurchaseOrder { get; set; }
//mirror fields to save a roundtrip to the UI, not persisted //server populated fields not db fields
[NotMapped] [NotMapped]
public string DisplayPartNumber { get; set; } public string DisplayPartNumber { get; set; }
[NotMapped] [NotMapped]
@@ -46,6 +46,16 @@ namespace AyaNova.Models
[NotMapped] [NotMapped]
public string DisplayTaxCode { get; set; } public string DisplayTaxCode { get; set; }
[NotMapped]
public decimal DisplayNetTotal { get; set; }
[NotMapped]
public decimal DisplayTaxA { get; set; }
[NotMapped]
public decimal DisplayTaxB { get; set; }
[NotMapped]
public decimal DisplayLineTotal { get; set; }