using AccountsBLL.AccountReports.AccountTrialBalance; 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 { // Periodic Trial Balance — Account level, Summary shape, one (account, period-bucket) row per // combination (flat, not a pre-pivoted grid — see TrialBalanceReportQB.cs's // GET_TRIAL_BALANCE_PERIODIC comment). CriteriaDTO's PeriodFromDate/PeriodToDate bound the // overall range to break down (defaults to current-financial-year-to-date if unset); PeriodType // selects the bucket size via MGBPERIOD.PERIODTYPE. public class AccountTrialBalancePeriodicReport : BaseReportEndpoint { private readonly IAccountTrialBalanceReportBLL _bll; public AccountTrialBalancePeriodicReport(IAccountTrialBalanceReportBLL bll) { _bll = bll; } public override void Configure() { Post("/AccountReports/AccountTrialBalancePeriodicReport"); AllowAnonymous(); } public record AccountTrialBalancePeriodicReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); protected override async IAsyncEnumerable ExecuteReportAsync( AccountTrialBalancePeriodicReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetTrialBalancePeriodicReport( 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( AccountTrialBalancePeriodicReportParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetTrialBalancePeriodicReport( 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); } } } }