using AccountsBLL.AccountReports.PAndLReport; using AccountsDAL.DTO.Reports; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Report; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.AccountReports { // GB5-native replacement for the GB4 legacy gb4/as/AccountsReports.svc/PLHorizontal endpoint — // MREPORT -1399975830 "P and L Horizontal", live menus AC20091 (Schedule)/AC20092 (Group)/ // AC20093 (Account), each passing its own GroupType (2/1/0 respectively). Same rows as // PAndLVerticalReport — see PAndLReportQB.cs class header — Horizontal only differs in how the // frontend renders them (Income|Expense side by side rather than stacked). Cut over via // MWEBSERVICE.SECONDURITEMPLATE, not by replacing the legacy URITEMPLATE — see the companion // migration. public class PAndLHorizontalReport : BaseReportEndpoint { private readonly IPAndLReportBLL _bll; public PAndLHorizontalReport(IPAndLReportBLL bll) { _bll = bll; } public override void Configure() { Post("/AccountReports/PAndLHorizontalReport"); AllowAnonymous(); } public record PAndLHorizontalReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, // String, not int — matches the {Type} substitution convention already configured live // on MMENU.URIPARAMETERVALUE for AC20091/92/93 ('ACCOUNTSCHEDULE'/'ACCOUNTGROUP'/ // 'ACCOUNT'), same as PAndLVerticalReport's Type parameter. [property: QueryParam] string? Type, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); private static int ToGroupType(string? type) => type?.ToUpperInvariant() switch { "ACCOUNTGROUP" => 1, "ACCOUNTSCHEDULE" => 2, _ => 0, }; protected override async IAsyncEnumerable ExecuteReportAsync( PAndLHorizontalReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var rows = await _bll.GetPAndLHorizontal( ToGroupType(req.Type), req.ReportCallingDTO.CriteriaDTO, req.ReportCallingDTO.MenuId, login).ConfigureAwait(false); foreach (var row in rows) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( PAndLHorizontalReportParameter req, LoginDTO login, CancellationToken ct) { try { var rows = await _bll.GetPAndLHorizontal( ToGroupType(req.Type), req.ReportCallingDTO.CriteriaDTO, req.ReportCallingDTO.MenuId, login).ConfigureAwait(false); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( rows, 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); } } } }