# Brix Accounting API — Reports

API reference for financial reports.

---

## Base URL

```
{BASE_URL}/api/v1/reports
```

| Environment | Example |
|-------------|---------|
| Local | `http://127.0.0.1:8000/api/v1/reports` |

---

## Authentication

All endpoints require:

| Header | Value |
|--------|-------|
| `Authorization` | `Bearer {token}` |
| `Accept` | `application/json` |

Obtain a token via `POST /api/v1/login`. See [auth-and-users.md](./auth-and-users.md).

**Middleware:** `auth:sanctum`, `company` — results are scoped to the authenticated user's company.

---

## Trial balance

Returns cumulative debit and credit balances for each active account as of a given date. Each account appears in either the debit or credit column (not both). Grand totals should match when the ledger is balanced.

### Request

```
GET /api/v1/reports/trial-balance
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Include journal entries on or before this date. Defaults to today. |
| `include_zero_balances` | boolean | No | When `true`, include active accounts with no balance. Defaults to `false`. |

#### Example

```http
GET /api/v1/reports/trial-balance?as_of=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "is_balanced": true,
    "totals": {
      "debit": "168.0000",
      "credit": "168.0000"
    },
    "accounts": [
      {
        "account_id": 3,
        "account_number": "1000",
        "name": "CASH",
        "account_type": "ASSET",
        "account_sub_type": "CASH",
        "debit": "118.0000",
        "credit": "0.0000"
      },
      {
        "account_id": 7,
        "account_number": "4000",
        "name": "Sales Revenue",
        "account_type": "INCOME",
        "account_sub_type": "SALES_REVENUE",
        "debit": "0.0000",
        "credit": "100.0000"
      }
    ]
  }
}
```

#### Response fields

| Field | Description |
|-------|-------------|
| `as_of` | Report cutoff date |
| `is_balanced` | `true` when total debits equal total credits |
| `totals.debit` | Sum of debit column (4 decimal places) |
| `totals.credit` | Sum of credit column (4 decimal places) |
| `accounts` | Active accounts with non-zero balances (unless `include_zero_balances` is set) |
| `accounts[].debit` | Net debit balance for the account |
| `accounts[].credit` | Net credit balance for the account |

### Validation errors `422`

Invalid `as_of` date or `include_zero_balances` value returns standard Laravel validation errors.

---

## Balance sheet

Returns cumulative balances for `ASSET`, `LIABILITY`, and `EQUITY` accounts as of a given date. Income and expense activity is rolled into equity as **Current Period Earnings** so the statement balances (`assets = liabilities + equity`) when the ledger is in balance.

### Request

```
GET /api/v1/reports/balance-sheet
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Include journal entries on or before this date. Defaults to today. |
| `include_zero_balances` | boolean | No | When `true`, include active accounts with no balance and show zero current-period earnings. Defaults to `false`. |

#### Example

```http
GET /api/v1/reports/balance-sheet?as_of=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "is_balanced": true,
    "assets": {
      "total": "68.0000",
      "accounts": [
        {
          "account_id": 3,
          "account_number": "1000",
          "name": "CASH",
          "account_type": "ASSET",
          "account_sub_type": "CASH",
          "amount": "118.0000"
        },
        {
          "account_id": 4,
          "account_number": "1200",
          "name": "Inventory",
          "account_type": "ASSET",
          "account_sub_type": "INVENTORY_ASSET",
          "amount": "-50.0000"
        }
      ]
    },
    "liabilities": {
      "total": "18.0000",
      "accounts": [
        {
          "account_id": 6,
          "account_number": "2100",
          "name": "VAT_PAYABLE",
          "account_type": "LIABILITY",
          "account_sub_type": "VAT_PAYABLE",
          "amount": "18.0000"
        }
      ]
    },
    "equity": {
      "current_period_earnings": "50.0000",
      "total": "50.0000",
      "accounts": [
        {
          "account_id": null,
          "account_number": null,
          "name": "Current Period Earnings",
          "account_type": "EQUITY",
          "account_sub_type": "CURRENT_PERIOD_EARNINGS",
          "amount": "50.0000"
        }
      ]
    },
    "totals": {
      "assets": "68.0000",
      "liabilities_and_equity": "68.0000"
    }
  }
}
```

#### Response fields

| Field | Description |
|-------|-------------|
| `as_of` | Report cutoff date |
| `is_balanced` | `true` when total assets equal liabilities plus equity |
| `assets.accounts` | Active asset accounts with signed balances (debits minus credits) |
| `liabilities.accounts` | Active liability accounts with signed balances (credits minus debits) |
| `equity.accounts` | Active equity accounts plus a synthetic **Current Period Earnings** line |
| `equity.current_period_earnings` | Cumulative net income through `as_of` (income minus expenses) |
| `totals.assets` | Sum of asset account amounts |
| `totals.liabilities_and_equity` | Sum of liabilities and equity (including current-period earnings) |
| `accounts[].detail_url` | Link to [Balance sheet detail](#balance-sheet-detail) for that account; Current Period Earnings links to cumulative [Profit and loss detail](#profit-and-loss-detail) |

### Validation errors `422`

Invalid `as_of` date or `include_zero_balances` value returns standard Laravel validation errors.

---

## Balance sheet detail

Returns journal entry lines grouped by balance-sheet account through `as_of`, with a running balance per line. Use after [Balance sheet](#balance-sheet) or call directly with `account_id`.

### Request

```
GET /api/v1/reports/balance-sheet-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Include journal entries on or before this date. Defaults to today. |
| `account_id` | integer | No | Limit to one `ASSET`, `LIABILITY`, or `EQUITY` account in your company. |
| `per_page` | integer | No | Page size when listing all accounts (1–100). Defaults to `50`. |
| `page` | integer | No | Page number when listing all accounts. Defaults to `1`. |

When `account_id` is set, all matching lines for that account are returned without pagination.

#### Example

```http
GET /api/v1/reports/balance-sheet-detail?as_of=2026-06-30&account_id=3
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "accounts": [
      {
        "account_id": 3,
        "account_number": "1000",
        "name": "CASH",
        "account_type": "ASSET",
        "account_sub_type": "CASH",
        "amount": "118.0000",
        "transactions": [
          {
            "journal_entry_id": 2,
            "je_number": "JE-0002",
            "txn_date": "2026-06-11",
            "posting_type": "DEBIT",
            "amount": "118.0000",
            "description": "Payment PAY-0001",
            "source": {
              "type": "PAYMENT",
              "id": 1,
              "number": "PAY-0001",
              "transaction_id": 6
            },
            "source_url": "/api/v1/customer-payments/1",
            "running_balance": "118.0000"
          }
        ]
      }
    ]
  }
}
```

**Drill-down:** Follow `source_url` on each transaction to the source document (`/invoices`, `/bills`, `/customer-payments`, etc.).

Per-account `amount` matches the same account on the [Balance sheet](#balance-sheet) summary for the same `as_of`.

---

## Profit and loss

Returns income and expense activity for a date range, derived from journal entries on `INCOME` and `EXPENSE` accounts, filtered by **`journal_entries.txn_date`**. Balance-sheet activity (cash, A/R, A/P, inventory) is excluded. Net income is `total income − total expenses`.

**Void and amend:** For invoices, bills, and payments in an **open** fiscal year, reversal JEs use each reversed entry's `txn_date` (for bills this includes COGS true-up JEs), so period P&L and inventory activity net correctly within that month. For documents whose `txn_date` is in a **closed** year (on or before [company `books_closed_through`](./company.md)), reversals are dated **today** and appear in the current period. Payment void only — amend posts delta JEs at `payment.txn_date` and is unchanged. See [invoices — GL reversal dating](./invoices.md#gl-reversal-dating-void-and-amend) and [bills — GL reversal dating](./bills.md#gl-reversal-dating-void-and-amend).

**Income by customer:** That report excludes `VOIDED` invoices by status and uses `invoice.txn_date` with document line amounts (`line_total − tax_amount` and `cogs_amount`). It may differ from P&L for voids, true-ups in other periods, or non-invoice P&L activity.

### Request

```
GET /api/v1/reports/profit-and-loss
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date (`YYYY-MM-DD`) | No | First day to include. Defaults to the first day of the month containing `end_date`. |
| `end_date` | date (`YYYY-MM-DD`) | No | Last day to include. Defaults to today. Must be on or after `start_date`. |
| `include_zero_balances` | boolean | No | When `true`, include active income/expense accounts with no activity in the period. Defaults to `false`. |

#### Example

```http
GET /api/v1/reports/profit-and-loss?start_date=2026-06-01&end_date=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "income": {
      "total": "100.0000",
      "accounts": [
        {
          "account_id": 7,
          "account_number": "4000",
          "name": "Sales Revenue",
          "account_type": "INCOME",
          "account_sub_type": "SALES_REVENUE",
          "amount": "100.0000"
        }
      ]
    },
    "expenses": {
      "total": "50.0000",
      "accounts": [
        {
          "account_id": 9,
          "account_number": "5000",
          "name": "COGS",
          "account_type": "EXPENSE",
          "account_sub_type": "COGS",
          "amount": "50.0000"
        }
      ]
    },
    "net_income": "50.0000"
  }
}
```

#### Response fields

| Field | Description |
|-------|-------------|
| `start_date` | First date included in the report |
| `end_date` | Last date included in the report |
| `income.accounts` | Active `INCOME` accounts with period activity |
| `income.total` | Sum of income account amounts |
| `expenses.accounts` | Active `EXPENSE` accounts with period activity |
| `expenses.total` | Sum of expense account amounts |
| `net_income` | `income.total − expenses.total` |
| `accounts[].amount` | Net activity for the period (credits minus debits for income; debits minus credits for expenses) |
| `accounts[].detail_url` | Link to [Profit and loss detail](#profit-and-loss-detail) for that account and date range |

### Validation errors `422`

Invalid dates or `end_date` before `start_date` returns standard Laravel validation errors.

---

## Profit and loss detail

Returns journal entry lines grouped by income or expense account for a date range. Use after [Profit and loss](#profit-and-loss) or call directly with `account_id`.

### Request

```
GET /api/v1/reports/profit-and-loss-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date (`YYYY-MM-DD`) | No | First day to include. Defaults to the first day of the month containing `end_date`. Ignored when `from_inception=true`. |
| `end_date` | date (`YYYY-MM-DD`) | No | Last day to include. Defaults to today. |
| `from_inception` | boolean | No | When `true`, include all journal activity through `end_date` with no lower date bound. Used by Current Period Earnings drill-down from the balance sheet. |
| `account_id` | integer | No | Limit to one income or expense account in your company. |
| `per_page` | integer | No | Page size when listing all accounts (1–100). Defaults to `50`. |
| `page` | integer | No | Page number when listing all accounts. Defaults to `1`. |

When `from_inception=true`, `start_date` in the response is `null`.

#### Example

```http
GET /api/v1/reports/profit-and-loss-detail?start_date=2026-06-01&end_date=2026-06-30&account_id=7
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "accounts": [
      {
        "account_id": 7,
        "account_number": "4000",
        "name": "Sales Revenue",
        "account_type": "INCOME",
        "account_sub_type": "SALES_REVENUE",
        "amount": "100.0000",
        "transactions": [
          {
            "journal_entry_id": 1,
            "je_number": "JE-0001",
            "txn_date": "2026-06-10",
            "posting_type": "CREDIT",
            "amount": "100.0000",
            "description": "Invoice INV-0001",
            "source": {
              "type": "INVOICE",
              "id": 1,
              "number": "INV-0001",
              "transaction_id": 5
            },
            "source_url": "/api/v1/invoices/1"
          }
        ]
      }
    ]
  }
}
```

**Drill-down:** Follow `source_url` on each transaction to the source document.

Per-account `amount` matches the same account on the [Profit and loss](#profit-and-loss) summary for the same date range.

---

## Inventory reports

Inventory reports live under `/api/v1/reports/inventory`. They use the same authentication and company scoping as financial reports. Any authenticated user who can list items may access these endpoints.

### Stock valuation

Returns FIFO-based inventory value per item, using remaining quantities on each cost layer (`qty_remaining × unit_cost`).

#### Request

```
GET /api/v1/reports/inventory/stock-value
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `item_id` | integer | No | Limit the report to a single inventory item (must belong to your company). |
| `active_only` | boolean | No | When `true`, include only active items. Defaults to `true`. |
| `include_zero_qty` | boolean | No | When `true`, include inventory items with no remaining FIFO layers. Defaults to `false`. |
| `include_layers` | boolean | No | When `true`, include FIFO layer detail per item. Defaults to `false`. |

#### Example

```http
GET /api/v1/reports/inventory/stock-value?include_layers=1
Authorization: Bearer {token}
Accept: application/json
```

#### Response `200 OK`

```json
{
  "data": {
    "valuation_method": "FIFO",
    "totals": {
      "qty_on_hand": "14.0000",
      "total_value": "650.0000"
    },
    "items": [
      {
        "item_id": 1,
        "sku": "WDG-001",
        "name": "Widget",
        "unit_of_measure": "UNIT",
        "qty_on_hand": "9.0000",
        "layer_qty": "9.0000",
        "average_unit_cost": "50.0000",
        "total_value": "450.0000",
        "detail_url": "/api/v1/reports/inventory-valuation-detail?item_id=1",
        "layers": [
          {
            "layer_id": 1,
            "date_acquired": "2026-06-01",
            "qty_remaining": "9.0000",
            "unit_cost": "50.0000",
            "layer_value": "450.0000"
          }
        ]
      }
    ]
  }
}
```

#### Response fields

| Field | Description |
|-------|-------------|
| `valuation_method` | Always `FIFO` |
| `totals.qty_on_hand` | Sum of remaining layer quantities across included items |
| `totals.total_value` | Total FIFO inventory value |
| `items[].qty_on_hand` | Quantity on the item record |
| `items[].layer_qty` | Sum of `qty_remaining` on FIFO layers (used for valuation) |
| `items[].average_unit_cost` | `total_value ÷ layer_qty` |
| `items[].total_value` | FIFO value for the item |
| `items[].detail_url` | Link to `inventory-valuation-detail` filtered for this item |
| `items[].layers` | Present when `include_layers=true` |

---

### Inventory valuation detail

Returns FIFO cost layers for inventory items with remaining stock, optionally filtered to a single item.

#### Request

```
GET /api/v1/reports/inventory-valuation-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `item_id` | integer | No | Limit to a single item. When omitted, all items with layers are returned (paginated). |
| `per_page` | integer | No | Items per page when `item_id` is not specified (default `50`, max `100`). |
| `page` | integer | No | Page number (default `1`). |

#### Example

```http
GET /api/v1/reports/inventory-valuation-detail?item_id=1
Authorization: Bearer {token}
Accept: application/json
```

#### Response `200 OK`

```json
{
  "data": {
    "valuation_method": "FIFO",
    "totals": {
      "qty_on_hand": "9.0000",
      "total_value": "450.0000"
    },
    "items": [
      {
        "item_id": 1,
        "sku": "WDG-001",
        "name": "Widget",
        "qty_on_hand": "9.0000",
        "total_value": "450.0000",
        "movements_url": "/api/v1/inventory-transactions?item_id=1",
        "layers": [
          {
            "layer_id": 1,
            "date_acquired": "2026-06-01",
            "qty_remaining": "9.0000",
            "unit_cost": "50.0000",
            "layer_value": "450.0000",
            "source_url": "/api/v1/bills/1"
          }
        ]
      }
    ]
  }
}
```

When `item_id` is omitted, a `meta` pagination block is included:

```json
{
  "data": {
    "valuation_method": "FIFO",
    "totals": { "qty_on_hand": "14.0000", "total_value": "650.0000" },
    "items": [ ... ],
    "meta": {
      "current_page": 1,
      "per_page": 50,
      "total": 2,
      "last_page": 1
    }
  }
}
```

#### Response fields

| Field | Description |
|-------|-------------|
| `valuation_method` | Always `FIFO` |
| `totals.qty_on_hand` | Sum of layer `qty_remaining` across all included items |
| `totals.total_value` | Total FIFO inventory value |
| `items[].movements_url` | Link to `/api/v1/inventory-transactions?item_id={id}` |
| `items[].layers[].layer_id` | Primary key of the cost layer |
| `items[].layers[].date_acquired` | Date the layer was created (bill receive date) |
| `items[].layers[].qty_remaining` | Remaining quantity in this layer |
| `items[].layers[].unit_cost` | Unit cost at acquisition |
| `items[].layers[].layer_value` | `qty_remaining × unit_cost` |
| `items[].layers[].source_url` | Link to the originating bill, or `null` for opening-balance layers |

---

## AR aging

Returns outstanding customer invoices (`OPEN` / `PARTIAL` with `balance > 0`) bucketed by days past due relative to `as_of`.

### Request

```
GET /api/v1/reports/ar-aging
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Aging cutoff date. Defaults to today. |
| `customer_id` | integer | No | Limit to a single customer in your company. |

#### Example

```http
GET /api/v1/reports/ar-aging?as_of=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "totals": {
      "current": "118.0000",
      "days_1_30": "118.0000",
      "days_31_60": "0.0000",
      "days_61_90": "0.0000",
      "days_over_90": "0.0000",
      "total": "236.0000"
    },
    "customers": [
      {
        "customer_id": 1,
        "display_name": "John Doe Corp",
        "balance": "236.0000",
        "totals": {
          "current": "118.0000",
          "days_1_30": "118.0000",
          "days_31_60": "0.0000",
          "days_61_90": "0.0000",
          "days_over_90": "0.0000",
          "total": "236.0000"
        },
        "invoices": [
          {
            "invoice_id": 1,
            "invoice_number": "INV-0001",
            "txn_date": "2026-06-10",
            "due_date": "2026-07-10",
            "total_amount": "118.0000",
            "balance": "118.0000",
            "days_overdue": 0,
            "bucket": "current"
          }
        ]
      }
    ]
  }
}
```

#### Buckets

| Bucket | Days past due |
|--------|----------------|
| `current` | Not yet due (`due_date` ≥ `as_of`) |
| `days_1_30` | 1–30 days |
| `days_31_60` | 31–60 days |
| `days_61_90` | 61–90 days |
| `days_over_90` | More than 90 days |

Paid and voided invoices are excluded.

---

## AP aging

Returns outstanding vendor bills (`OPEN` / `PARTIAL` with `balance > 0`) bucketed by days past due relative to `as_of`. Same bucket rules as AR aging.

### Request

```
GET /api/v1/reports/ap-aging
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Aging cutoff date. Defaults to today. |
| `vendor_id` | integer | No | Limit to a single vendor in your company. |

#### Example

```http
GET /api/v1/reports/ap-aging?as_of=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "totals": {
      "current": "590.0000",
      "days_1_30": "0.0000",
      "days_31_60": "0.0000",
      "days_61_90": "0.0000",
      "days_over_90": "0.0000",
      "total": "590.0000"
    },
    "vendors": [
      {
        "vendor_id": 1,
        "display_name": "Acme Suppliers",
        "balance": "590.0000",
        "totals": {
          "current": "590.0000",
          "days_1_30": "0.0000",
          "days_31_60": "0.0000",
          "days_61_90": "0.0000",
          "days_over_90": "0.0000",
          "total": "590.0000"
        },
        "bills": [
          {
            "bill_id": 1,
            "bill_number": "BILL-0001",
            "txn_date": "2026-06-11",
            "due_date": "2026-07-11",
            "total_amount": "590.0000",
            "balance": "590.0000",
            "days_overdue": 0,
            "bucket": "current"
          }
        ]
      }
    ]
  }
}
```

Paid and voided bills are excluded.

---

## Customer balance summary

Returns total open receivables per customer. Complements [AR aging](#ar-aging) with a simpler balance-only view and drill-down links.

Only invoices with `txn_date` on or before `as_of` are included. Balances reflect current open amounts on each invoice (not a historical point-in-time replay).

### Request

```
GET /api/v1/reports/customer-balance-summary
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Include invoices with `txn_date` on or before this date. Defaults to today. |
| `include_zero_balances` | boolean | No | When `true`, include active customers with no open balance. Defaults to `false`. |
| `customer_id` | integer | No | Limit to a single customer in your company. |

#### Example

```http
GET /api/v1/reports/customer-balance-summary?as_of=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "totals": {
      "balance": "236.0000",
      "customer_count": 1
    },
    "customers": [
      {
        "customer_id": 1,
        "display_name": "John Doe Corp",
        "balance": "236.0000",
        "open_invoice_count": 2,
        "detail_url": "/api/v1/reports/customer-balance-detail?customer_id=1&as_of=2026-06-30"
      }
    ]
  }
}
```

**Drill-down:** Follow `detail_url` on each customer row to [Customer balance detail](#customer-balance-detail).

Paid and voided invoices are excluded.

---

## Customer balance detail

Returns open invoices grouped by customer. Use after [Customer balance summary](#customer-balance-summary) or call directly with `customer_id`.

### Request

```
GET /api/v1/reports/customer-balance-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Same cutoff as summary. Defaults to today. |
| `customer_id` | integer | No | Limit to one customer. |
| `per_page` | integer | No | Page size when listing all customers (1–100). Defaults to `50`. |
| `page` | integer | No | Page number when listing all customers. Defaults to `1`. |

When `customer_id` is set, all matching invoices for that customer are returned without pagination.

#### Example

```http
GET /api/v1/reports/customer-balance-detail?as_of=2026-06-30&customer_id=1
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "totals": {
      "balance": "236.0000"
    },
    "customers": [
      {
        "customer_id": 1,
        "display_name": "John Doe Corp",
        "balance": "236.0000",
        "invoices": [
          {
            "invoice_id": 1,
            "invoice_number": "INV-0001",
            "txn_date": "2026-06-10",
            "due_date": "2026-07-10",
            "total_amount": "118.0000",
            "balance": "118.0000",
            "status": "OPEN",
            "source_url": "/api/v1/invoices/1"
          }
        ]
      }
    ]
  }
}
```

When listing all customers without `customer_id`, the response includes a `meta` object with `current_page`, `per_page`, `total`, and `last_page`.

**Drill-down:** Follow `source_url` on each invoice to `GET /api/v1/invoices/{id}` for full document and line items.

---

## Vendor balance summary

Returns total open payables per vendor. Complements [AP aging](#ap-aging) with a balance-only view and drill-down links.

Only bills with `txn_date` on or before `as_of` are included. Balances reflect current open amounts on each bill.

### Request

```
GET /api/v1/reports/vendor-balance-summary
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Include bills with `txn_date` on or before this date. Defaults to today. |
| `include_zero_balances` | boolean | No | When `true`, include active vendors with no open balance. Defaults to `false`. |
| `vendor_id` | integer | No | Limit to a single vendor in your company. |

#### Example

```http
GET /api/v1/reports/vendor-balance-summary?as_of=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "totals": {
      "balance": "590.0000",
      "vendor_count": 1
    },
    "vendors": [
      {
        "vendor_id": 1,
        "display_name": "Acme Suppliers",
        "balance": "590.0000",
        "open_bill_count": 1,
        "detail_url": "/api/v1/reports/vendor-balance-detail?vendor_id=1&as_of=2026-06-30"
      }
    ]
  }
}
```

**Drill-down:** Follow `detail_url` on each vendor row to [Vendor balance detail](#vendor-balance-detail).

Paid and voided bills are excluded.

---

## Vendor balance detail

Returns open bills grouped by vendor. Use after [Vendor balance summary](#vendor-balance-summary) or call directly with `vendor_id`.

### Request

```
GET /api/v1/reports/vendor-balance-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `as_of` | date (`YYYY-MM-DD`) | No | Same cutoff as summary. Defaults to today. |
| `vendor_id` | integer | No | Limit to one vendor. |
| `per_page` | integer | No | Page size when listing all vendors (1–100). Defaults to `50`. |
| `page` | integer | No | Page number when listing all vendors. Defaults to `1`. |

When `vendor_id` is set, all matching bills for that vendor are returned without pagination.

#### Example

```http
GET /api/v1/reports/vendor-balance-detail?as_of=2026-06-30&vendor_id=1
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "as_of": "2026-06-30",
    "totals": {
      "balance": "590.0000"
    },
    "vendors": [
      {
        "vendor_id": 1,
        "display_name": "Acme Suppliers",
        "balance": "590.0000",
        "bills": [
          {
            "bill_id": 1,
            "bill_number": "BILL-0001",
            "txn_date": "2026-06-11",
            "due_date": "2026-07-11",
            "total_amount": "590.0000",
            "balance": "590.0000",
            "status": "OPEN",
            "source_url": "/api/v1/bills/1"
          }
        ]
      }
    ]
  }
}
```

When listing all vendors without `vendor_id`, the response includes a `meta` object with pagination fields.

**Drill-down:** Follow `source_url` on each bill to `GET /api/v1/bills/{id}` for full document and line items.

---

## Sales by customer summary

Returns total sales (`total_amount`) per customer for posted invoices in a date range. Includes `OPEN`, `PARTIAL`, and `PAID` invoices; excludes `DRAFT` and `VOIDED`.

### Request

```
GET /api/v1/reports/sales-by-customer-summary
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date (`YYYY-MM-DD`) | No | Period start. Defaults to the first day of the month containing `end_date`. |
| `end_date` | date (`YYYY-MM-DD`) | No | Period end. Defaults to today. Must be on or after `start_date`. |
| `customer_id` | integer | No | Limit to one customer. |
| `include_zero_balances` | boolean | No | When `true`, include active customers with no sales in the period. |

#### Example

```http
GET /api/v1/reports/sales-by-customer-summary?start_date=2026-06-01&end_date=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "totals": {
      "customer_count": 2,
      "total_sales": "354.0000",
      "invoice_count": 3
    },
    "customers": [
      {
        "customer_id": 1,
        "display_name": "John Doe Corp",
        "total_sales": "236.0000",
        "invoice_count": 2,
        "detail_url": "/api/v1/reports/sales-by-customer-detail?customer_id=1&start_date=2026-06-01&end_date=2026-06-30"
      }
    ]
  }
}
```

**Drill-down:** Follow `detail_url` on each customer row to [Sales by customer detail](#sales-by-customer-detail).

---

## Sales by customer detail

Returns invoices per customer for the period. Optionally includes line items when `include_lines=true`.

### Request

```
GET /api/v1/reports/sales-by-customer-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date | No | Same defaults as summary. |
| `end_date` | date | No | Same defaults as summary. |
| `customer_id` | integer | No | Limit to one customer. When omitted, customers are paginated. |
| `include_lines` | boolean | No | When `true`, each invoice includes a `lines` array. |
| `per_page` | integer | No | Page size when listing all customers (1–100). Defaults to `50`. |
| `page` | integer | No | Page number when listing all customers. |

When `customer_id` is set, all matching invoices for that customer are returned without pagination.

#### Example

```http
GET /api/v1/reports/sales-by-customer-detail?start_date=2026-06-01&end_date=2026-06-30&customer_id=1&include_lines=1
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "totals": {
      "total_sales": "236.0000"
    },
    "customers": [
      {
        "customer_id": 1,
        "display_name": "John Doe Corp",
        "total_sales": "236.0000",
        "invoices": [
          {
            "invoice_id": 1,
            "invoice_number": "INV-0001",
            "txn_date": "2026-06-10",
            "total_amount": "118.0000",
            "status": "OPEN",
            "source_url": "/api/v1/invoices/1",
            "lines": [
              {
                "line_number": 1,
                "item_id": 1,
                "item_name": "Widget",
                "description": null,
                "qty": "1.0000",
                "unit_price": "100.0000",
                "line_total": "118.0000"
              }
            ]
          }
        ]
      }
    ]
  }
}
```

**Drill-down:** Follow `source_url` on each invoice to `GET /api/v1/invoices/{id}`.

---

## Income by customer summary

Returns **invoice gross profit** per customer for a date range. Amounts come from posted invoice **documents**, not from GL journal entries.

| Field | Source |
|-------|--------|
| Revenue | Sum of `line_total − tax_amount` (pre-tax) |
| COGS | Sum of `invoice_lines.cogs_amount` (FIFO at post, updated by cost corrections) |
| Income | `revenue − cogs` (gross profit, not full P&L net income) |

Only invoices with status `OPEN`, `PARTIAL`, or `PAID` are included, filtered by **`invoice.txn_date`**. Amended invoices and cost-corrected COGS reflect current line amounts. This report does **not** require `active_journal_entry_id`.

It may diverge from [Profit and loss](#profit-and-loss) when non-invoice P&L activity exists, or when COGS true-up journal entries land in a different period (e.g. closed books). That is by design: P&L is GL; this report is document gross profit.

### Request

```
GET /api/v1/reports/income-by-customer-summary
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date (`YYYY-MM-DD`) | No | Period start. Defaults to the first day of the month containing `end_date`. |
| `end_date` | date (`YYYY-MM-DD`) | No | Period end. Defaults to today. Must be on or after `start_date`. |
| `customer_id` | integer | No | Limit to one customer. |
| `include_zero_balances` | boolean | No | When `true`, include active customers with no invoice activity in the period. |

#### Example

```http
GET /api/v1/reports/income-by-customer-summary?start_date=2026-06-01&end_date=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "totals": {
      "customer_count": 1,
      "revenue": "2500.0000",
      "cogs": "1500.0000",
      "income": "1000.0000"
    },
    "customers": [
      {
        "customer_id": 1,
        "display_name": "Red Rock Diner",
        "revenue": "2500.0000",
        "cogs": "1500.0000",
        "income": "1000.0000",
        "invoice_count": 1,
        "detail_url": "/api/v1/reports/income-by-customer-detail?customer_id=1&start_date=2026-06-01&end_date=2026-06-30"
      }
    ]
  }
}
```

**Drill-down:** Follow `detail_url` on each customer row to [Income by customer detail](#income-by-customer-detail).

---

## Income by customer detail

Returns per-invoice gross profit rows for each customer: `invoice_number`, `revenue`, `cogs`, and `income` (gross profit). Amounts use the same **invoice line aggregates** as the [summary](#income-by-customer-summary).

### Request

```
GET /api/v1/reports/income-by-customer-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date | No | Same defaults as summary. |
| `end_date` | date | No | Same defaults as summary. |
| `customer_id` | integer | No | Limit to one customer. When omitted, customers are paginated. |
| `per_page` | integer | No | Page size when listing all customers (1–100). Defaults to `50`. |
| `page` | integer | No | Page number when listing all customers. |

When `customer_id` is set, all matching invoices for that customer are returned without pagination.

#### Example

```http
GET /api/v1/reports/income-by-customer-detail?start_date=2026-06-01&end_date=2026-06-30&customer_id=1
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "totals": {
      "revenue": "2500.0000",
      "cogs": "1500.0000",
      "income": "1000.0000"
    },
    "customers": [
      {
        "customer_id": 1,
        "display_name": "Red Rock Diner",
        "revenue": "2500.0000",
        "cogs": "1500.0000",
        "income": "1000.0000",
        "invoices": [
          {
            "invoice_id": 1,
            "invoice_number": "INV-001",
            "txn_date": "2026-06-10",
            "revenue": "2500.0000",
            "cogs": "1500.0000",
            "income": "1000.0000",
            "lines_url": "/api/v1/reports/income-by-customer-invoice-detail?invoice_id=1",
            "source_url": "/api/v1/invoices/1"
          }
        ]
      }
    ]
  }
}
```

When listing all customers without `customer_id`, the response includes a `meta` object with pagination fields.

**Drill-down:** Follow `lines_url` on each invoice for [line-level gross profit](#income-by-customer-invoice-detail). Follow `source_url` for the full invoice document (`GET /api/v1/invoices/{id}`).

---

## Income by customer invoice detail

Returns per-line gross profit for one posted invoice: item name, pre-tax `revenue`, FIFO `cogs`, and `income` (gross profit per line). Invoice-level `totals` match the same invoice row on [income by customer detail](#income-by-customer-detail).

Only invoices with status `OPEN`, `PARTIAL`, or `PAID` are included. Draft invoices return `404`.

**Line revenue** = `line_total − tax_amount` (pre-tax net). **Line COGS** = `cogs_amount` from FIFO at post (updated by later cost corrections; `0` for service lines). **Unit price** is the selling price per unit; **unit cost** is average FIFO cost per unit (`cogs ÷ qty`).

### Request

```
GET /api/v1/reports/income-by-customer-invoice-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `invoice_id` | integer | Yes | Posted invoice in the current company |

#### Example

```http
GET /api/v1/reports/income-by-customer-invoice-detail?invoice_id=1
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "invoice_id": 1,
    "invoice_number": "INV-001",
    "txn_date": "2026-06-10",
    "customer_id": 1,
    "display_name": "Red Rock Diner",
    "totals": {
      "revenue": "100.0000",
      "cogs": "50.0000",
      "income": "50.0000"
    },
    "lines": [
      {
        "line_number": 1,
        "item_id": 5,
        "item_name": "Widget",
        "description": null,
        "qty": "1.0000",
        "unit_price": "100.0000",
        "unit_cost": "50.0000",
        "revenue": "100.0000",
        "cogs": "50.0000",
        "income": "50.0000"
      }
    ],
    "source_url": "/api/v1/invoices/1"
  }
}
```

**Drill-down:** Follow `source_url` for the full invoice (payments, tax, memo, etc.).

---

## Sales by product summary

Returns revenue and quantity sold per item (from `invoice_lines.line_total` and `qty`) for posted invoices in a date range. Lines without `item_id` are grouped by `description`.

### Request

```
GET /api/v1/reports/sales-by-product-summary
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date | No | Period start. Defaults to the first day of the month containing `end_date`. |
| `end_date` | date | No | Period end. Defaults to today. |
| `item_id` | integer | No | Limit to one inventory item. |
| `include_zero_balances` | boolean | No | When `true`, include active items with no sales in the period. |

#### Example

```http
GET /api/v1/reports/sales-by-product-summary?start_date=2026-06-01&end_date=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "totals": {
      "product_count": 2,
      "total_sales": "295.0000",
      "total_qty": "3.0000",
      "invoice_count": 1
    },
    "products": [
      {
        "item_id": 1,
        "item_name": "Widget",
        "total_sales": "236.0000",
        "total_qty": "2.0000",
        "invoice_count": 1,
        "detail_url": "/api/v1/reports/sales-by-product-detail?item_id=1&start_date=2026-06-01&end_date=2026-06-30"
      }
    ]
  }
}
```

**Drill-down:** Follow `detail_url` on each product row to [Sales by product detail](#sales-by-product-detail). For non-item lines, the URL includes a `description` query parameter instead of `item_id`.

---

## Sales by product detail

Returns individual invoice lines per item for the period.

### Request

```
GET /api/v1/reports/sales-by-product-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date | No | Same defaults as summary. |
| `end_date` | date | No | Same defaults as summary. |
| `item_id` | integer | No | Filter to one item. When omitted, products are paginated. |
| `description` | string | No | Filter non-item lines by description (use when `item_id` is absent). |
| `per_page` | integer | No | Page size when listing all products (1–100). Defaults to `50`. |
| `page` | integer | No | Page number when listing all products. |

When `item_id` or `description` is set, matching lines are returned without pagination.

#### Example

```http
GET /api/v1/reports/sales-by-product-detail?start_date=2026-06-01&end_date=2026-06-30&item_id=1
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "totals": {
      "total_sales": "236.0000",
      "total_qty": "2.0000"
    },
    "products": [
      {
        "item_id": 1,
        "item_name": "Widget",
        "total_sales": "236.0000",
        "total_qty": "2.0000",
        "lines": [
          {
            "invoice_id": 1,
            "invoice_number": "INV-0001",
            "txn_date": "2026-06-10",
            "customer_id": 1,
            "customer_name": "John Doe Corp",
            "line_number": 1,
            "description": null,
            "qty": "2.0000",
            "unit_price": "100.0000",
            "line_total": "236.0000",
            "source_url": "/api/v1/invoices/1"
          }
        ]
      }
    ]
  }
}
```

**Drill-down:** Follow `source_url` on each line to `GET /api/v1/invoices/{id}`.

---

## Expenses by vendor summary

Returns total expenses (`total_amount`) per vendor for posted bills in a date range. Includes `OPEN`, `PARTIAL`, and `PAID` bills; excludes `DRAFT` and `VOIDED`.

### Request

```
GET /api/v1/reports/expenses-by-vendor-summary
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date (`YYYY-MM-DD`) | No | Period start. Defaults to the first day of the month containing `end_date`. |
| `end_date` | date (`YYYY-MM-DD`) | No | Period end. Defaults to today. Must be on or after `start_date`. |
| `vendor_id` | integer | No | Limit to one vendor. |
| `include_zero_balances` | boolean | No | When `true`, include active vendors with no bills in the period. |

#### Example

```http
GET /api/v1/reports/expenses-by-vendor-summary?start_date=2026-06-01&end_date=2026-06-30
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "totals": {
      "vendor_count": 1,
      "total_expenses": "590.0000",
      "bill_count": 1
    },
    "vendors": [
      {
        "vendor_id": 1,
        "display_name": "Acme Suppliers",
        "total_expenses": "590.0000",
        "bill_count": 1,
        "detail_url": "/api/v1/reports/expenses-by-vendor-detail?vendor_id=1&start_date=2026-06-01&end_date=2026-06-30"
      }
    ]
  }
}
```

**Drill-down:** Follow `detail_url` on each vendor row to [Expenses by vendor detail](#expenses-by-vendor-detail).

---

## Expenses by vendor detail

Returns bills per vendor for the period. Optionally includes line items when `include_lines=true`.

### Request

```
GET /api/v1/reports/expenses-by-vendor-detail
```

#### Query parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date | No | Same defaults as summary. |
| `end_date` | date | No | Same defaults as summary. |
| `vendor_id` | integer | No | Limit to one vendor. When omitted, vendors are paginated. |
| `include_lines` | boolean | No | When `true`, each bill includes a `lines` array. |
| `per_page` | integer | No | Page size when listing all vendors (1–100). Defaults to `50`. |
| `page` | integer | No | Page number when listing all vendors. |

When `vendor_id` is set, all matching bills for that vendor are returned without pagination.

#### Example

```http
GET /api/v1/reports/expenses-by-vendor-detail?start_date=2026-06-01&end_date=2026-06-30&vendor_id=1&include_lines=1
Authorization: Bearer {token}
Accept: application/json
```

### Response `200 OK`

```json
{
  "data": {
    "start_date": "2026-06-01",
    "end_date": "2026-06-30",
    "totals": {
      "total_expenses": "590.0000"
    },
    "vendors": [
      {
        "vendor_id": 1,
        "display_name": "Acme Suppliers",
        "total_expenses": "590.0000",
        "bills": [
          {
            "bill_id": 1,
            "bill_number": "BILL-0001",
            "txn_date": "2026-06-10",
            "total_amount": "590.0000",
            "status": "OPEN",
            "source_url": "/api/v1/bills/1",
            "lines": [
              {
                "line_number": 1,
                "item_id": 1,
                "item_name": "Widget",
                "description": null,
                "qty": "10.0000",
                "unit_price": "50.0000",
                "line_total": "590.0000"
              }
            ]
          }
        ]
      }
    ]
  }
}
```

When listing all vendors without `vendor_id`, the response includes a `meta` object with pagination fields.

**Drill-down:** Follow `source_url` on each bill to `GET /api/v1/bills/{id}` for full document and line items.
