using AccountsBLL.AccountReports.AccountOutstanding; 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 { // Wired to the existing legacy MREPORT row REPORTID = -1399995571 ("Outstanding Detail") — already // has 33 MREPORTVIEW rows live (Account/AccountGroup/InCharge/PriceCategory/Route/OU groupings, // Receivable/Payable splits, etc.), confirmed via sqlcmd before this endpoint was written. New // GB5-backed views are added as siblings under the same REPORTID, not a new REPORT row. public class AccountOutstandingDetailReport : BaseReportEndpoint { private readonly IAccountOutstandingReportBLL _bll; public AccountOutstandingDetailReport(IAccountOutstandingReportBLL bll) { _bll = bll; } public override void Configure() { Post("/AccountReports/AccountOutstandingDetailReport"); AllowAnonymous(); } public record AccountOutstandingDetailReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); protected override async IAsyncEnumerable ExecuteReportAsync( AccountOutstandingDetailReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { // No dedicated streaming DAL path yet for Outstanding (unlike AccountLedger) — export reuses // the same paged query at a high cap. Outstanding result sets are bounded by distinct // pending bills, not raw transaction volume, so this is acceptable for phase 1. var result = await _bll.GetOutstandingDetailReport( 1, int.MaxValue, req.ReportCallingDTO.CriteriaDTO, sortBy: null, req.ReportCallingDTO.MenuId, login).ConfigureAwait(false); foreach (var row in result.Items) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( AccountOutstandingDetailReportParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetOutstandingDetailReport( 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); } } } }