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 1 -- "Procurement Spend Overview". Actual-spend-only // (no Plan vs Actual -- see the Procurement dashboard plan for why). ExecutePagedAsync returns // the full composite {KPIs, MonthlyTrend, CategoryBreakdown, ContractTypeSplit} object, same // pattern as AccountBRSDashboardReport/AccountProfitLossDashboardReport. public class GetProcurementSpendOverview : BaseReportEndpoint { private readonly IMMReportsBLL _bll; public GetProcurementSpendOverview(IMMReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/MMReports/GetProcurementSpendOverview"); AllowAnonymous(); } public record GetProcurementSpendOverviewParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] string BizTransactionClassIds ); protected override async IAsyncEnumerable ExecuteReportAsync( GetProcurementSpendOverviewParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetProcurementSpendOverview( req.BizTransactionClassIds, req.ReportCallingDTO.CriteriaDTO, login, ct).ConfigureAwait(false); foreach (var row in result.CategoryBreakdown) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetProcurementSpendOverviewParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetProcurementSpendOverview( req.BizTransactionClassIds, 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); } } } }