using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Report; using GB5Shared.FastEndPoint; using MMBLL.MMReports; using MMDAL.DTO.MMHead; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MMReports { // Procurement Overview Dashboard, Tile 3 -- "Purchase Order Monitoring". Wires up // PurchaseStatusReportDTO's PO->GRN->quality half only for Phase 1 -- payment/voucher tracing // (VoucherId/PJV/MR/MINS fields on that DTO) is intentionally left unpopulated pending live // schema confirmation of TVOUCHER/TBILLALLOCATION/TPAYMENT. See GET_PO_MONITORING_DETAIL in // MMReportsQB.cs for the exact scope. public class GetPOMonitoringDashboard : BaseReportEndpoint { private readonly IMMReportsBLL _bll; public GetPOMonitoringDashboard(IMMReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/MMReports/GetPOMonitoringDashboard"); AllowAnonymous(); } public record GetPOMonitoringDashboardParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] string PoBizTransactionClassIds, [property: QueryParam] int PoBizTransactionClassId, [property: QueryParam] int GrnBizTransactionClassId ); protected override async IAsyncEnumerable ExecuteReportAsync( GetPOMonitoringDashboardParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetPOMonitoringDashboard( req.PoBizTransactionClassIds, req.PoBizTransactionClassId, req.GrnBizTransactionClassId, req.ReportCallingDTO.CriteriaDTO, login, ct).ConfigureAwait(false); foreach (var row in result.OpenPOs) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetPOMonitoringDashboardParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetPOMonitoringDashboard( req.PoBizTransactionClassIds, req.PoBizTransactionClassId, req.GrnBizTransactionClassId, req.ReportCallingDTO.CriteriaDTO, 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); } } } }