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, "Stock Movement" tile. Fresh design against TSTOCKLEDGER -- // see InventoryReportsQB's provenance comment (legacy's HQL equivalent has no portable SQL). // Composite dashboard object (DailyTrend+BySource+TopMovers); export streams DailyTrend rows, // same "yield the row-level section" convention as AccountBRSDashboardReport. public class GetStockMovementDashboard : BaseReportEndpoint { private readonly IInventoryReportsBLL _bll; public GetStockMovementDashboard(IInventoryReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/InventoryReports/GetStockMovementDashboard"); AllowAnonymous(); } public record GetStockMovementDashboardParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int OuId, [property: QueryParam] DateTime? PeriodFromDate, [property: QueryParam] DateTime? PeriodToDate, [property: QueryParam] int? TopN ); protected override async IAsyncEnumerable ExecuteReportAsync( GetStockMovementDashboardParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetStockMovementDashboard( req.OuId, req.PeriodFromDate, req.PeriodToDate, req.TopN, login, ct).ConfigureAwait(false); foreach (var row in result.DailyTrend) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetStockMovementDashboardParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetStockMovementDashboard( req.OuId, req.PeriodFromDate, req.PeriodToDate, req.TopN, 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); } } } }