using AccountsBLL.AccountReports.BSReport; 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/BalanceSheetHorizontal // endpoint — MREPORT -1399975249 "Balance Sheet Horizontal", live menus AC20084 (Schedule)/ // AC20085 (Group)/AC20086 (Account). Cut over via MWEBSERVICE.SECONDURITEMPLATE — see the // companion migration and BSVerticalHorizontalReportQB.cs's class header. public class BSHorizontalReport : BaseReportEndpoint { private readonly IBSReportBLL _bll; public BSHorizontalReport(IBSReportBLL bll) { _bll = bll; } public override void Configure() { Post("/AccountReports/BSHorizontalReport"); AllowAnonymous(); } public record BSHorizontalReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, // String, not int — matches the live {GroupType} substitution on AC20084/85/86's own // MMENU.URIPARAMETERVALUE ('ACCOUNTSCHEDULE'/'ACCOUNTGROUP'/'ACCOUNT'). Note the // placeholder name genuinely differs from BSVerticalReport's "Type" — confirmed live, // not a typo. [property: QueryParam] string? GroupType, [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( BSHorizontalReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var rows = await _bll.GetBSHorizontal( ToGroupType(req.GroupType), req.ReportCallingDTO.CriteriaDTO, req.ReportCallingDTO.MenuId, login).ConfigureAwait(false); foreach (var row in rows) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( BSHorizontalReportParameter req, LoginDTO login, CancellationToken ct) { try { var rows = await _bll.GetBSHorizontal( ToGroupType(req.GroupType), 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); } } } }