This commit is contained in:
2021-02-27 20:42:47 +00:00
parent d92774ebdf
commit 8097175314
4 changed files with 66 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ using Microsoft.Extensions.Logging;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace AyaNova.Api.Controllers
@@ -148,7 +150,26 @@ namespace AyaNova.Api.Controllers
return NoContent();
}
/// <summary>
/// Get restock required list for vendor specified or any vendor if no vendor specified
/// </summary>
/// <param name="vendorId">optional vendor id will return matches to Part objects manufacturer, wholesaler or alternative wholesaler</param>
/// <returns>PurchaseOrder</returns>
[HttpGet("restock-by-vendor/{vendorId}")]
public async Task<IActionResult> GetPurchaseOrder([FromRoute] long? vendorId)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
PurchaseOrderBiz biz = PurchaseOrderBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
if (null == vendorId)
return Ok(ApiOkResponse.Response(await ct.ViewRestockRequired.OrderBy(z => z.RequiredQuantity).ToListAsync()));
else
return Ok(ApiOkResponse.Response(await ct.ViewRestockRequired.Where(z => z.ManufacturerId == vendorId || z.WholesalerId == vendorId || z.AlternativeWholesalerId == vendorId).OrderBy(z => z.RequiredQuantity).ToListAsync()));
}

View File

@@ -89,6 +89,8 @@ namespace AyaNova.Models
public virtual DbSet<DashboardView> DashboardView { get; set; }
public virtual DbSet<ServiceBank> ServiceBank { get; set; }
public virtual DbSet<ViewRestockRequired> ViewRestockRequired { get; set; }
//Note: had to add this constructor to work with the code in startup.cs that gets the connection string from the appsettings.json file
@@ -111,7 +113,12 @@ namespace AyaNova.Models
foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
// Replace table names
entity.SetTableName("a" + entity.GetTableName().ToLowerInvariant());
var entityName = entity.GetTableName().ToLowerInvariant();
if (!entityName.StartsWith("view"))
entity.SetTableName("a" + entityName);
else
entity.SetTableName(entityName);
// Replace column names
foreach (var property in entity.GetProperties())

View File

@@ -0,0 +1,34 @@
namespace AyaNova.Models
{
//Note this is how to define a View backed model with no key (id)
[Microsoft.EntityFrameworkCore.Keyless]
public class ViewRestockRequired
{
public long PartId { get; set; }
public long PartWarehouseId { get; set; }
public string PartNumber { get; set; }
public string DisplayWarehouse { get; set; }
public long ManufacturerId { get; set; }
public string DisplayManufacturer { get; set; }
public long WholesalerId { get; set; }
public string DisplayWholesaler { get; set; }
public long AlternativeWholesalerId { get; set; }
public string DisplayAlternativeWholesaler { get; set; }
public decimal MinimumQuantity { get; set; }
public decimal Balance { get; set; }
public decimal OnOrderQuantity { get; set; }
public decimal RequiredQuantity { get; set; }
}//eoc
}//eons
/*
SELECT apart.id AS partid, apartwarehouse.id AS partwarehouseid, apart.partnumber, apartwarehouse.name AS displaywarehouse, "
+ "amanufacturer.id AS manufacturerid, amanufacturer.name AS displaymanufacturer, awholesaler.id AS wholesalerid, awholesaler.name AS displaywholesaler, "
+ "aalternativewholesaler.id AS alternativewholesalerid, aalternativewholesaler.name AS displayalternativewholesaler,"
+ "apartstocklevel.minimumquantity, vpartinventorynow.balance, COALESCE(vpartsonorderuncommitted.quantityonorder,0) AS onorderquantity, "
+ "apartstocklevel.minimumquantity - (COALESCE(vpartinventorynow.balance, 0) + COALESCE(vpartsonorderuncommitted.quantityonorder, 0)) AS requiredquantity "
*/

View File

@@ -810,8 +810,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
+ "FROM apurchaseorderitem WHERE workorderitempartrequestid IS NULL AND (COALESCE(apurchaseorderitem.quantityordered,0)-COALESCE(apurchaseorderitem.quantityreceived,0)) > 0 GROUP BY partid, partwarehouseid");
//VRESTOCKREQUIRED
await ExecQueryAsync("CREATE VIEW vrestockrequired AS SELECT apart.id AS partid, apartwarehouse.id AS partwarehouseid, apart.partnumber, apartwarehouse.name AS displaywarehouse, "
+ "amanufacturer.id AS manufactureid, amanufacturer.name AS displaymanufacturer, awholesaler.id AS wholesalerid, awholesaler.name AS displaywholesaler, "
await ExecQueryAsync("CREATE VIEW viewrestockrequired AS SELECT apart.id AS partid, apartwarehouse.id AS partwarehouseid, apart.partnumber, apartwarehouse.name AS displaywarehouse, "
+ "amanufacturer.id AS manufacturerid, amanufacturer.name AS displaymanufacturer, awholesaler.id AS wholesalerid, awholesaler.name AS displaywholesaler, "
+ "aalternativewholesaler.id AS alternativewholesalerid, aalternativewholesaler.name AS displayalternativewholesaler,"
+ "apartstocklevel.minimumquantity, vpartinventorynow.balance, COALESCE(vpartsonorderuncommitted.quantityonorder,0) AS onorderquantity, "
+ "apartstocklevel.minimumquantity - (COALESCE(vpartinventorynow.balance, 0) + COALESCE(vpartsonorderuncommitted.quantityonorder, 0)) AS requiredquantity "