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, "Inventory Ageing" tile. Fixed 4-bucket (0-30/31-60/61-90/>90 // days) port of legacy GB4's StockAgeingDetailReport -- see // InventoryReportsQB.GET_STOCK_AGEING_REPORT for the full provenance and scope-trim notes. public class GetStockAgeingReport : BaseReportEndpoint { private readonly IInventoryReportsBLL _bll; public GetStockAgeingReport(IInventoryReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/InventoryReports/GetStockAgeingReport"); AllowAnonymous(); } public record GetStockAgeingReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int OuId, [property: QueryParam] int? ItemCategoryId, [property: QueryParam] DateTime? AsOnDate ); protected override async IAsyncEnumerable ExecuteReportAsync( GetStockAgeingReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetStockAgeingReport( req.OuId, req.ItemCategoryId, req.AsOnDate, login, ct).ConfigureAwait(false); foreach (var row in result) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetStockAgeingReportParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetStockAgeingReport( req.OuId, req.ItemCategoryId, req.AsOnDate, 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); } } } }