using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Report; using GB5Shared.FastEndPoint; using MMBLL.InventoryReports; using MMDAL.DTO.InventoryReports; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.InventoryReports { // Inventory Overview Dashboard, Tile "Reorder Breach / Demand-Supply Netting". Ported from // legacy GB4's RegisterQueryBuilder.GET_BELOW_ROL_STORE_SKU_REPORT (Type 2) -- see // InventoryReportsQB.GET_REORDER_BREACH_REPORT for the reparameterized SQL and provenance. public class GetReorderBreachReport : BaseReportEndpoint { private readonly IInventoryReportsBLL _bll; public GetReorderBreachReport(IInventoryReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/InventoryReports/GetReorderBreachReport"); AllowAnonymous(); } public record GetReorderBreachReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int OuId, [property: QueryParam] int? StoreId, [property: QueryParam] int? ItemCategoryId, [property: QueryParam] int SupplyBizTransactionClassId ); protected override async IAsyncEnumerable ExecuteReportAsync( GetReorderBreachReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetReorderBreachReport( req.OuId, req.StoreId, req.ItemCategoryId, req.SupplyBizTransactionClassId, login, ct).ConfigureAwait(false); foreach (var row in result) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetReorderBreachReportParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetReorderBreachReport( req.OuId, req.StoreId, req.ItemCategoryId, req.SupplyBizTransactionClassId, login, ct).ConfigureAwait(false); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, login).ConfigureAwait(false); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500).ConfigureAwait(false); } } } }