# AccountReports: Reference

Lookup tables and glossary for developers actively working in this code. Keep this file in sync —
add a row every time a new report joins this catalog.

## Glossary

| Term | Meaning |
|---|---|
| **MREPORT** | Legacy-inherited master table — one row per "report" (e.g. "Outstanding Detail"), identified by `REPORTID`. |
| **MREPORTVIEW** | A named, configurable "view" of a report — controls layout/menu-linkage/default sort. Presentation-only; does not select which query runs. |
| **MREPORTVIEWFIELDS** | The column layout for one view — which fields show, order, width, format. |
| **MREPORTVSFIELDS** | The catalog of fields a given `REPORTID` *could* show. Field names are unique per `REPORTID` (a real `UNIQUE(REPORTID, FIELDNAME)` constraint — hit live once when a migration tried to insert a field name that already existed under a different ID). |
| **`ReportCallingDTO`** | The request envelope every `BaseReportEndpoint`-derived endpoint takes — carries `ReportViewId`, `MenuId`, and the `CriteriaDTO` filter payload. |
| **`CriteriaDTO`** | The generic filter-payload shape (`SectionCriteriaList` → `AttributesCriteriaList` → `FieldName`/`FieldValue` pairs) that every report's criteria are parsed from. |
| **`AccountReportCriteria`** | The single, shared, strongly-typed C# class every AccountReports family parses its `CriteriaDTO` into — see the full field table below. |
| **`FNPENDINGBILL`** | Live SQL Server table function computing as-of-date pending bill balance. The building block for Outstanding, Ageing, and Collection/Payment Projection. |
| **`FNAGESLAB`** | Live SQL Server function testing whether a bill-age falls within a given day-range. Used by Ageing's bucket logic. |
| **`VPENDINGBILL` / `VPENDINGBILLDETAIL`** | Undated views — always "as of right now." Do **not** use for anything that needs to answer "as of a past date"; use `FNPENDINGBILL` instead. |
| **`MV_PENDINGBILL`** | A physical, incrementally-maintained snapshot table (via `POST2PENDINGBILL`/`BULKPOST2PENDINGBILL`). The fast "current position only" path — not used by any report in this catalog, reserved for things like credit-check/dashboards that only ever need "right now." |
| **`TBILLALLOCATION.ALLOCATIONTYPE`** | 0=New, 1=Advance, 2=Against, 3=Unadjusted, 4=Batch. |
| **OU-access ceiling** | The `MUSERACCESSRIGHTS`/`MORGANIZATIONGROUPDETAIL` union-subquery pattern every report applies on `V.OUID`, enforcing the caller's actual organizational-unit access regardless of any explicit OU filter they pass. |

## REPORTID reference

| Report | `MREPORT.REPORTNAME` | `REPORTID` |
|---|---|---|
| Account Register (Detail) | *not recorded in code — confirm live* | *unknown — open item, see Catalog* |
| Account Register Summary | *not recorded in code — confirm live* | *unknown — open item, see Catalog* |
| Account Ledger / Summary | Statement of Account | `-1399975210` |
| Outstanding Detail | Outstanding Detail | `-1399995571` |
| Outstanding Summary | Outstanding Summary | `-1399995293` |
| Ageing Detail | Ageing Detail | `-1399976528` |
| Ageing Summary | Ageing Summary | `-1399976724` |
| Settlement Register | Settlement Register | `-1399946537` |
| Settlement Register With Rate | Settlement Register With Rate | `-1399936759` |
| Collection/Payment Projection | Outstanding Analysis Report | `-1399926003` |

## BizTransactionClassId reference (used across multiple reports)

| Class | `BIZTRANSACTIONCLASSID` | Used by |
|---|---|---|
| Sales Invoice | `-1799999904` | Collection Projection's `QtrAvg`/`NewSaleDebit` |
| Purchase Invoice | `-1799999923` | (available; not currently used by any report in this catalog) |
| Receipt (Bank/Cash Receipt, Receipt Voucher) | `-1399999988` | Collection Projection's `QtrCollAvg` |
| Payment (Bank/Cash Payment) | `-1399999997` | Collection Projection's `QtrPayAvg` |
| Debit Note (both variants) | `-1399999993`, `-1399999949` | Collection Projection's `DebitNote` |
| "Informational" class (excluded by default) | see `AccountReportsQB.INFORMATIONAL_BIZ_TRANSACTION_CLASS_ID` | `AccountReportFilterBuilder.Build()`'s `IncludeInformational` filter |

These are live values on GB5DEMO, confirmed via `MBIZTRANSACTIONTYPE`. Don't assume they're identical
on every client database — legacy migrations sometimes reseed these per-client with different IDs;
re-verify before reusing on a new environment.

## `AccountReportCriteria` — full field list

Shared by every report family. Source: `GB5Solution/Accounts/AccountsDAL/DTO/AccountsReports/AccountReportCriteria.cs`.

| Field | Type | Used by | Note |
|---|---|---|---|
| `PeriodFromDate` / `PeriodToDate` | `DateTime` | Register, Ledger, Settlement | Mandatory for `EnforceAsync`-gated reports. |
| `FinanceBookId` | `int` | shared | `-1` is the real "no book" sentinel, not `0`. |
| `BizTransactionTypeId` / `BizTransactionClassId` / `BizTransactionSubClassId` | `int` | shared | Exact voucher-type/class/subclass filters. |
| `VoucherDetailAccountIds` | `List<int>` | shared | Restrict to specific account(s). |
| `OUIds` | `List<int>` | shared | Additional OU narrowing, on top of the mandatory access-rights ceiling. |
| `OUGroupId` | `int`, default `-1` | shared | `-1` = not applicable (checked via `!= -1`). |
| `DetailType` | `int`, default `-1` | shared | 0=Debit/1=Credit; `-1` = both. |
| `CostCenterId` | `int` | shared | Matches direct `VD.COSTCENTERID` or a split-cost-center row. |
| `IncludeInformational` | `bool` | shared | Default excludes the "informational" voucher class. |
| `NeedBillAllocation` / `NeedCostCenter` / `NeedInstrument` / `NeedAddon` / `NeedTDS` | `int` | Register (Detail) | `>0` triggers a second query attaching that child-row type. |
| `CurrencyId` | `int` | shared | Exact-currency filter. |
| `PeriodId` | `int` | shared | Exact accounting-period filter. |
| `FromDocumentNumber` / `ToDocumentNumber` | `string` | shared | Voucher-number range. |
| `FromDocumentId` / `ToDocumentId` | `int?` | shared | Voucher-ID range. |
| `FromAmount` / `ToAmount` | `decimal?` | shared | Voucher-amount range. |
| `V1Id`…`V5Id` | `int` | Register/Ledger (Detail only) | Business-dimension filters; not joined by any Summary query. |
| `VoucherStatus` | `int?` | shared | Exact status filter. |
| `ModeOfPayment` | `List<int>` | Register/Ledger (Detail only) | `TMMHEAD.MODEOFPAYMENT`; not joined by Summary. |
| `ControlAccountId` | `int` | shared | |
| `AccountGroupId` | `int` | shared | Real values are large negative sentinels — check `!= 0`. |
| `CurrencyBasis` | `int` | Ledger only | 0=OU/base, 1=Transaction, 2=Customer/party, 3=Group. |
| `ReportCurrencyId` | `int` | Ledger only | Target currency for on-the-fly conversion; `0` = none. |
| `AsOnDate` | `DateTime` | Outstanding, Ageing, Collection Projection | Feeds `FNPENDINGBILL`. |
| `GroupType` | `int` | Outstanding/Ageing Summary | 0=Account/1=AccountGroup/2=ControlAccount/3=InCharge/4=PriceCategory/5=Route/6=OU (Ageing lacks AccountGroup/OU). |
| `Overdue` | `int`, default `2` | Outstanding, Ageing | 0=overdue-only/1=not-yet-due/2=all. |
| `ReportType` | `int`, default `2` | Outstanding, Ageing | 0=Receivable/1=Payable/2=Both. |
| `InChargeId` / `PriceCategoryId` / `RouteId` | `int` | Outstanding, Ageing | |
| `NumberOfAge` | `int`, default `5` | Ageing only | 1-9 buckets. |
| `AgeBoundaries` | `int[9]`, default `{15,30,45,60,75,90,105,120,135}` | Ageing only | Upper day-boundary per bucket. |
| `BillAllocationLineId` | `int` | Settlement only | Narrows to one original bill. |
| `OverallDays` | `int`, default `90` | Collection Projection only | Age threshold (from real current date) for the `OverallAmount` flag. |

## Shared C# builder methods

`AccountReportFilterBuilder.cs`:
| Method | Aliases assumed | Used by |
|---|---|---|
| `Build(criteria, loginDTO)` | `V/VD/ACC/BTT` | Register, Ledger (base filter for every other Build* too where aliases match) |
| `BuildDetailOnly(criteria)` | `MH`, `VS2`/`TD2` | Register Detail, Ledger Detail/Stream (never Summary) |
| `BuildOutstandingOnly(criteria)` | `PB/VBILL` | Outstanding, Ageing |
| `BuildSettlementOnly(criteria)` | `C/A/TYP/B/VB/AV` | Settlement Register (own alias set — doesn't call `Build()`) |

`AccountReportSortBuilder.cs` — one `Build<Report><View>OrderBy` method per report/view, each backed
by a private allow-list dictionary (never string-interpolates a caller-supplied field name).

`AccountReportAccessControlBLL.cs` (`IAccountReportAccessControlBLL`):
| Method | Requires | Used by |
|---|---|---|
| `EnforceAsync` | Real `PeriodFromDate`/`PeriodToDate`, not inverted | Register, Ledger, Settlement |
| `EnforceForAsOnDateAsync` | `AsOnDate` only, no period range | Outstanding, Ageing, Collection Projection |

Both also enforce `MROLEVSMENU.DaysLimit`/`RecordsLimit` (fail-open if no row exists for the
role/menu pair) and `MUSERACCESSRIGHTS.NOOFREADPERIOD=1`'s "don't read before your current work
period" rule.
