diff --git a/FaKrosnoApi/Controllers/CustomerOrdersController.cs b/FaKrosnoApi/Controllers/CustomerOrdersController.cs index ebf620c..72dfa81 100644 --- a/FaKrosnoApi/Controllers/CustomerOrdersController.cs +++ b/FaKrosnoApi/Controllers/CustomerOrdersController.cs @@ -55,6 +55,13 @@ namespace FaKrosnoApi.Controllers await service.GetByCustomerAndPo(customerNumber, customerSequence, poNumber); return customerOrder != null ? Ok(customerOrder) : NotFound(); } + + [HttpGet("by-po")] + public async Task> GetByPo([FromQuery] string poNumber) + { + CustomerOrderDto? customerOrder = await service.GetByPo(poNumber); + return customerOrder != null ? Ok(customerOrder) : NotFound(); + } [HttpGet("list-by-customer-and-po")] public async Task>> GetListByCustomerAndPo( diff --git a/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs b/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs index 0d0b09c..912bfea 100644 --- a/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs +++ b/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs @@ -72,6 +72,13 @@ namespace SytelineSaAppEfDataModel.Services .Where(x => x.CustNum == customerNumber && x.CustSeq == customerSequence && x.CustPo == poNumber) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); } + + public async Task GetByPo(string poNumber) + { + return await context.CustomerOrders.Where(x => x.CustPo == poNumber && x.Stat == "O") + .OrderByDescending(x => x.CreateDate).Select(x => mapper.Map(x)) + .FirstOrDefaultAsync(); + } public async Task> GetListByCustomerAndPo(string customerNumber, int customerSequence, string poNumber) diff --git a/SytelineSaAppEfDataModel/Services/ICustomerOrderService.cs b/SytelineSaAppEfDataModel/Services/ICustomerOrderService.cs index b30d3fc..784e881 100644 --- a/SytelineSaAppEfDataModel/Services/ICustomerOrderService.cs +++ b/SytelineSaAppEfDataModel/Services/ICustomerOrderService.cs @@ -17,6 +17,7 @@ namespace SytelineSaAppEfDataModel.Services Task> GetListByCustomerAndPo(string customerNumber, int customerSequence, string poNumber); + Task GetByPo(string poNumber); Task> GetListByCustomer(string customerNumber, int customerSequence); Task?> GetLinesByCoNumber(string customerOrderNumber); Task?> GetItemsByCoNumber(string customerOrderNumber);