using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using AccountsDAL.CustomCode.AccountReports.AccountVoucherReport; using AccountsDAL.DTO.AccountsReports; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.Telemetry; namespace AccountsBLL.AccountReports.AccountVoucherReport { // Hosts all four consolidated Voucher report methods — matches this session's own "one DAL/BLL // hosting multiple related report methods" precedent (e.g. Cash Flow Direct+Indirect). All four // are period-range reports (PeriodFromDate/PeriodToDate), same family as Register/Ledger — uses // EnforceAsync, not EnforceForAsOnDateAsync (that's for Outstanding/Ageing's AsOnDate family). public class AccountVoucherReportBLL : IAccountVoucherReportBLL { private const int DEFAULT_MAX_RESULT_CAP = 500; private readonly IAccountVoucherReportDAL _dal; private readonly IAccountReportAccessControlBLL _accessControlBLL; public AccountVoucherReportBLL(IAccountVoucherReportDAL dal, IAccountReportAccessControlBLL accessControlBLL) { _dal = dal; _accessControlBLL = accessControlBLL; } public async Task GetVoucherStatusReport( int firstNumber, int maxResult, CriteriaDTO criteriaDTO, int menuId, LoginDTO loginDTO, CancellationToken ct) { try { GB5Trace.Step("parse-criteria-voucher-status", new { firstNumber, maxResult, menuId }); var criteria = AccountReportCriteriaParser.Parse(criteriaDTO, loginDTO); var cappedMaxResult = maxResult > 0 ? Math.Min(maxResult, DEFAULT_MAX_RESULT_CAP) : DEFAULT_MAX_RESULT_CAP; await _accessControlBLL.EnforceAsync(criteria, cappedMaxResult, menuId, loginDTO).ConfigureAwait(false); GB5Trace.Step("query-voucher-status", new { firstNumber, cappedMaxResult }); return await _dal.GetVoucherStatusReport(firstNumber, cappedMaxResult, criteria, loginDTO, ct).ConfigureAwait(false); } catch (Exception ex) { GB5Trace.MarkFailed("voucher-status-report-failed", ex); throw; } } public async Task GetVoucherSummaryReport( int firstNumber, int maxResult, int groupType, CriteriaDTO criteriaDTO, int menuId, LoginDTO loginDTO, CancellationToken ct) { try { GB5Trace.Step("parse-criteria-voucher-summary", new { firstNumber, maxResult, groupType, menuId }); var criteria = AccountReportCriteriaParser.Parse(criteriaDTO, loginDTO); var cappedMaxResult = maxResult > 0 ? Math.Min(maxResult, DEFAULT_MAX_RESULT_CAP) : DEFAULT_MAX_RESULT_CAP; await _accessControlBLL.EnforceAsync(criteria, cappedMaxResult, menuId, loginDTO).ConfigureAwait(false); GB5Trace.Step("query-voucher-summary", new { firstNumber, cappedMaxResult, groupType }); return await _dal.GetVoucherSummaryReport(firstNumber, cappedMaxResult, groupType, criteria, loginDTO, ct).ConfigureAwait(false); } catch (Exception ex) { GB5Trace.MarkFailed("voucher-summary-report-failed", ex); throw; } } public async Task GetVoucherListClassReport( int firstNumber, int maxResult, CriteriaDTO criteriaDTO, int menuId, LoginDTO loginDTO, CancellationToken ct) { try { GB5Trace.Step("parse-criteria-voucher-list-class", new { firstNumber, maxResult, menuId }); var criteria = AccountReportCriteriaParser.Parse(criteriaDTO, loginDTO); var cappedMaxResult = maxResult > 0 ? Math.Min(maxResult, DEFAULT_MAX_RESULT_CAP) : DEFAULT_MAX_RESULT_CAP; await _accessControlBLL.EnforceAsync(criteria, cappedMaxResult, menuId, loginDTO).ConfigureAwait(false); GB5Trace.Step("query-voucher-list-class", new { firstNumber, cappedMaxResult }); return await _dal.GetVoucherListClassReport(firstNumber, cappedMaxResult, criteria, loginDTO, ct).ConfigureAwait(false); } catch (Exception ex) { GB5Trace.MarkFailed("voucher-list-class-report-failed", ex); throw; } } public async Task GetVoucherListAccountReport( int firstNumber, int maxResult, CriteriaDTO criteriaDTO, int menuId, LoginDTO loginDTO, CancellationToken ct) { try { GB5Trace.Step("parse-criteria-voucher-list-account", new { firstNumber, maxResult, menuId }); var criteria = AccountReportCriteriaParser.Parse(criteriaDTO, loginDTO); if (criteria.VoucherDetailAccountIds == null || criteria.VoucherDetailAccountIds.Count == 0) throw new ArgumentException("VoucherDetailAccountId is required for the account-paired voucher list."); var cappedMaxResult = maxResult > 0 ? Math.Min(maxResult, DEFAULT_MAX_RESULT_CAP) : DEFAULT_MAX_RESULT_CAP; await _accessControlBLL.EnforceAsync(criteria, cappedMaxResult, menuId, loginDTO).ConfigureAwait(false); GB5Trace.Step("query-voucher-list-account", new { firstNumber, cappedMaxResult }); return await _dal.GetVoucherListAccountReport(firstNumber, cappedMaxResult, criteria, loginDTO, ct).ConfigureAwait(false); } catch (Exception ex) { GB5Trace.MarkFailed("voucher-list-account-report-failed", ex); throw; } } public async Task> GetVoucherPeriodTypeReport( CriteriaDTO criteriaDTO, int menuId, LoginDTO loginDTO, CancellationToken ct) { try { GB5Trace.Step("parse-criteria-voucher-periodtype", new { menuId }); var criteria = AccountReportCriteriaParser.Parse(criteriaDTO, loginDTO); await _accessControlBLL.EnforceAsync(criteria, DEFAULT_MAX_RESULT_CAP, menuId, loginDTO).ConfigureAwait(false); GB5Trace.Step("query-voucher-periodtype", new { criteria.PeriodType }); return await _dal.GetVoucherPeriodTypeReport(criteria, loginDTO, ct).ConfigureAwait(false); } catch (Exception ex) { GB5Trace.MarkFailed("voucher-periodtype-report-failed", ex); throw; } } } }