This commit is contained in:
@@ -152,20 +152,20 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get count of PartWarehouses
|
||||
/// </summary>
|
||||
/// <returns>Total number of part warehouses (active or not)</returns>
|
||||
[HttpGet("count")]
|
||||
public async Task<IActionResult> GetCount()
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
// /// <summary>
|
||||
// /// Get count of PartWarehouses
|
||||
// /// </summary>
|
||||
// /// <returns>Total number of part warehouses (active or not)</returns>
|
||||
// [HttpGet("count")]
|
||||
// public async Task<IActionResult> GetCount()
|
||||
// {
|
||||
// if (!serverState.IsOpen)
|
||||
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
if (!Authorized.HasSelectRole(HttpContext.Items, AyaType.PartWarehouse))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
return Ok(ApiOkResponse.Response(await ct.PartWarehouse.CountAsync()));
|
||||
}
|
||||
// if (!Authorized.HasSelectRole(HttpContext.Items, AyaType.PartWarehouse))
|
||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
// return Ok(ApiOkResponse.Response(await ct.PartWarehouse.CountAsync()));
|
||||
// }
|
||||
|
||||
|
||||
//------------
|
||||
|
||||
@@ -102,27 +102,78 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//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);
|
||||
//populate names for client ui
|
||||
|
||||
foreach (PurchaseOrderItem item in ret.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.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();
|
||||
}
|
||||
await SetDisplayFields(ret);
|
||||
|
||||
|
||||
if (logTheGetEvent && ret != null)
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct);
|
||||
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
|
||||
//
|
||||
|
||||
@@ -42,6 +42,11 @@ namespace AyaNova.Models
|
||||
[NotMapped, JsonIgnore]
|
||||
public AyaType AyaType { get => AyaType.PurchaseOrder; }
|
||||
|
||||
[NotMapped]
|
||||
public bool DisplayWarehouses { get; set; }
|
||||
[NotMapped]
|
||||
public bool DisplayPartRequest { get; set; }
|
||||
|
||||
}//eoc
|
||||
|
||||
}//eons
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace AyaNova.Models
|
||||
public PurchaseOrder PurchaseOrder { get; set; }
|
||||
|
||||
|
||||
//mirror fields to save a roundtrip to the UI, not persisted
|
||||
//server populated fields not db fields
|
||||
[NotMapped]
|
||||
public string DisplayPartNumber { get; set; }
|
||||
[NotMapped]
|
||||
@@ -46,6 +46,16 @@ namespace AyaNova.Models
|
||||
[NotMapped]
|
||||
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; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user