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 { // Sales Overview Dashboard, Enquiry->Quotation->Order funnel tile. BizTransactionClassIds are // direct query params, resolved by the caller (portlet default-criteria config) from the // tenant's own MBIZTRANSACTIONCLASS rows for Sales Enquiry/Quotation/Order -- never hardcoded // here, since those IDs are tenant-specific (mirrors GetPRToPOTrackerDashboard's convention). public class GetSalesFunnelDashboard : BaseReportEndpoint { private readonly IMMReportsBLL _bll; public GetSalesFunnelDashboard(IMMReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/MMReports/GetSalesFunnelDashboard"); AllowAnonymous(); } public record GetSalesFunnelDashboardParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int EnquiryBizTransactionClassId, [property: QueryParam] int QuotationBizTransactionClassId, [property: QueryParam] int OrderBizTransactionClassId, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); protected override async IAsyncEnumerable ExecuteReportAsync( GetSalesFunnelDashboardParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetSalesFunnelDashboard( 1, int.MaxValue, req.EnquiryBizTransactionClassId, req.QuotationBizTransactionClassId, req.OrderBizTransactionClassId, req.ReportCallingDTO.CriteriaDTO, login, ct).ConfigureAwait(false); foreach (var row in result.OpenSalesDocuments) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetSalesFunnelDashboardParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetSalesFunnelDashboard( req.FirstNumber, req.MaxResult, req.EnquiryBizTransactionClassId, req.QuotationBizTransactionClassId, req.OrderBizTransactionClassId, 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); } } } }