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.MMReports; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MMReports { // Procurement Overview Dashboard, Tile 2 -- "PR to PO Tracker". Funnel/aging/open-list stages // are configured by BizTransactionTypeId, resolved by the caller (portlet default-criteria // config) from the tenant's own MBIZTRANSACTIONTYPE/MBIZTRANSACTIONCLASS rows for // PR/Inquiry/Quotation/PO -- never hardcoded here, since those IDs are tenant-specific. public class GetPRToPOTrackerDashboard : BaseReportEndpoint { private readonly IMMReportsBLL _bll; public GetPRToPOTrackerDashboard(IMMReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/MMReports/GetPRToPOTrackerDashboard"); AllowAnonymous(); } public record GetPRToPOTrackerDashboardParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int PrBizTransactionClassId, [property: QueryParam] int InquiryBizTransactionClassId, [property: QueryParam] int QuotationBizTransactionClassId, [property: QueryParam] int PoBizTransactionClassId, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); protected override async IAsyncEnumerable ExecuteReportAsync( GetPRToPOTrackerDashboardParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetPRToPOTrackerDashboard( 1, int.MaxValue, req.PrBizTransactionClassId, req.InquiryBizTransactionClassId, req.QuotationBizTransactionClassId, req.PoBizTransactionClassId, req.ReportCallingDTO.CriteriaDTO, login, ct).ConfigureAwait(false); foreach (var row in result.OpenPRs) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetPRToPOTrackerDashboardParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetPRToPOTrackerDashboard( req.FirstNumber, req.MaxResult, req.PrBizTransactionClassId, req.InquiryBizTransactionClassId, req.QuotationBizTransactionClassId, req.PoBizTransactionClassId, 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); } } } }