using AccountsBLL.AccountReports.AccountLedger; using AccountsDAL.DTO.AccountsReports; 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 { // Normal + Detail views share this one endpoint/query — they're genuinely just different // MREPORTVIEWFIELDS column layouts of the same running-balance transaction-level rows (see the // AccountLedger migration plan's MetaReport/ReportView section). ReportViewId in ReportCallingDTO // drives presentation only; it isn't read here, matching GetDayBooks.cs's precedent. public class AccountLedgerReport : BaseReportEndpoint { private readonly IAccountLedgerReportBLL _bll; public AccountLedgerReport(IAccountLedgerReportBLL bll) { _bll = bll; } public override void Configure() { Post("/AccountReports/AccountLedgerReport"); AllowAnonymous(); } public record AccountLedgerReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); // Export/NDJSON path — full unbounded stream, no account-count cap (that cap exists to protect // the interactive paged path; export is the documented answer for a legitimate wide/general- // ledger pull). protected override IAsyncEnumerable ExecuteReportAsync( AccountLedgerReportParameter req, LoginDTO login, CancellationToken ct) => _bll.GetAccountLedgerDetailStream(req.ReportCallingDTO.CriteriaDTO, login, ct); // UI table path — paged with totals, access-control limits, and the account-count cap enforced. protected override async Task> ExecutePagedAsync( AccountLedgerReportParameter req, LoginDTO login, CancellationToken ct) { try { // ReportCallingDTO (the shared, cross-report shape BaseReportEndpoint expects) has no // slot for a caller-supplied sort list the way AccountRegister's own AccountReportRequestDTO // does — sort here defaults to AccountReportSortBuilder.BuildLedgerOrderBy's chronological // per-account order. Per-view ordering can still be driven by MREPORTVIEW.OrderByFields at // the presentation/export layer without a backend change. var result = await _bll.GetAccountLedgerDetailReport( req.FirstNumber, req.MaxResult, req.ReportCallingDTO.CriteriaDTO, sortBy: null, req.ReportCallingDTO.MenuId, login).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); } } } }