# Brix Accounting API — Inventory transactions hub

Unified read API for a QuickBooks-style **Inventory Valuation Detail** page: FIFO receipts (from bill receive), sales (from invoice post), and quantity adjustments — plus summary totals.

Stock increases from bills use [bills](./bills.md) (receive). Stock decreases from sales use [invoices](./invoices.md) (post). Manual corrections use [inventory adjustments](./inventory-adjustments.md). **Negative stock / oversell:** see [negative-stock.md](./negative-stock.md) for `BACKORDER_SALE` and `COGS_TRUE_UP` movement types.

See also: [inventory-api-checklist.md](../inventory-api-checklist.md)

---

## Base URL

```
{BASE_URL}/api/v1/inventory-transactions
```

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

---

## Authentication

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

**Middleware:** `auth:sanctum`, `company`

---

## Role permissions

| Action | ADMIN | ACCOUNTANT | MANAGER | CASHIER |
|--------|-------|------------|---------|---------|
| List inventory transactions | ✓ | ✓ | ✓ | ✓ |

Row-level `available_actions` respect bill, invoice, and adjustment policies.

---

## List inventory transactions

```
GET /inventory-transactions
```

### Query parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `type` | string | `receipt,sale,adjustment_in,adjustment_out` | Comma-separated movement filters |
| `item_id` | integer | — | Filter by inventory item |
| `start_date` | date | 365 days ago | Minimum movement date |
| `end_date` | date | today | Maximum movement date |
| `search` | string | — | Match SKU, item name, bill/invoice/adjustment number, memo, or counterparty |
| `recent_days` | integer | `30` | Window for `summary.received_recent` and `summary.sold_recent` |
| `include_running_balance` | boolean | `true` | Include `qty_on_hand_after` per row (chronological per item) |
| `per_page` | integer | `25` | Page size (1–100) |
| `page` | integer | `1` | Page number |

**Valid `type` values**

| Filter value | `movement_type` in response | Source |
|--------------|----------------------------|--------|
| `receipt` | `RECEIPT` | Bill receive → `inventory_cost_layers` (bill-linked layers) or bill lines that only cleared backorders |
| `sale` | `SALE` | Invoice post → `invoice_line_layers` |
| `adjustment_in` | `ADJUSTMENT_IN` | Quantity increase → `inventory_adjustment_lines` (`change_in_qty > 0`) |
| `adjustment_out` | `ADJUSTMENT_OUT` | Quantity decrease → `inventory_adjustment_lines` (`change_in_qty < 0`) |
| `backorder_sale` | `BACKORDER_SALE` | Oversell (negative stock) → `invoice_line_backorder_allocations` |
| `cogs_true_up` | `COGS_TRUE_UP` | COGS adjustment when backorder cleared at different cost → `inventory_backorder_clearances` |

**Movement notes**

- `RECEIPT` — created when a bill is received into inventory (`inventory_cost_layers` with a `bill_line_id`, or bill lines that only cleared backorders with no FIFO layer). When the bill cleared open backorders, `qty_change` is the **full bill line qty** (QBO-style), with `qty_applied_to_backorder` and `qty_added_to_stock` showing the split; `memo` summarizes e.g. `10.0000 applied to backorder · 5.0000 to stock`
- `SALE` — created when an invoice is posted and FIFO layers are consumed (`invoice_line_layers`); one invoice line may produce multiple rows when FIFO spans cost batches
- `ADJUSTMENT_IN` / `ADJUSTMENT_OUT` — created when an [inventory adjustment](./inventory-adjustments.md) is posted; increase layers in `inventory_cost_layers` have `bill_line_id = null` and do **not** appear as `RECEIPT` rows
- `BACKORDER_SALE` — created when an invoice is posted with `allow_negative_stock` and qty exceeds on-hand; estimated COGS at sale date (see [invoices](./invoices.md))
- `COGS_TRUE_UP` — created when a bill receive or positive inventory adjustment clears a backorder at a unit cost different from the sale-time estimate; `qty_change` is always `0` (financial adjustment only)
- `STARTING_VALUE` — created when [starting value](./inventory-starting-value.md) is set on an item (`inventory_starting_values` + FIFO layer with `bill_line_id = null`)

### Row fields (all movement types)

| Field | Type | Description |
|-------|------|-------------|
| `movement_type` | string | See valid `type` values above |
| `qty_change` | string | Quantity impact on running balance (4 decimals) |
| `unit_cost` | string \| null | Unit cost when applicable |
| `value_change` | string | Inventory value impact |
| `qty_on_hand_after` | string \| null | Running balance per item when `include_running_balance=true` |
| `qty_applied_to_backorder` | string \| null | **RECEIPT only** — qty from this bill line used to clear oversell backorders |
| `qty_added_to_stock` | string \| null | **RECEIPT only** — qty added to FIFO / on-hand after backorder clearance |
| `memo` | string \| null | Adjustment memo, backorder note, or receipt split summary |

### Example requests

```http
GET /api/v1/inventory-transactions?item_id=1&per_page=25
Authorization: Bearer {token}
Accept: application/json
```

```http
GET /api/v1/inventory-transactions?type=adjustment_in,adjustment_out&item_id=1
Authorization: Bearer {token}
Accept: application/json
```

### Success response — `200 OK`

```json
{
  "summary": {
    "on_hand": {
      "item_count": 1,
      "total_qty": "7.0000",
      "total_value": "350.0000"
    },
    "received_recent": {
      "count": 1,
      "total_qty": "10.0000",
      "total_value": "500.0000",
      "days": 30
    },
    "sold_recent": {
      "count": 1,
      "total_qty": "5.0000",
      "total_cogs": "250.0000",
      "days": 30
    },
    "low_stock": {
      "count": 0
    }
  },
  "data": [
    {
      "movement_type": "ADJUSTMENT_OUT",
      "id": 2,
      "item_id": 1,
      "item_sku": "WDG-001",
      "item_name": "Widget",
      "txn_date": "2026-06-13",
      "created_at": "2026-06-13T14:30:00.000000Z",
      "qty_change": "-3.0000",
      "unit_cost": null,
      "value_change": "-150.0000",
      "qty_on_hand_after": "7.0000",
      "reference_type": "INVENTORY_ADJUSTMENT",
      "reference_id": 1,
      "reference_number": "IADJ-0001",
      "transaction_id": null,
      "counterparty_name": null,
      "memo": "Physical count",
      "available_actions": ["view_adjustment"]
    },
    {
      "movement_type": "SALE",
      "id": 3,
      "item_id": 1,
      "item_sku": "WDG-001",
      "item_name": "Widget",
      "txn_date": "2026-06-10",
      "created_at": "2026-06-10T09:15:00.000000Z",
      "qty_change": "-5.0000",
      "unit_cost": "50.0000",
      "value_change": "-250.0000",
      "qty_on_hand_after": "10.0000",
      "reference_type": "INVOICE",
      "reference_id": 8,
      "reference_number": "INV-0003",
      "transaction_id": 95,
      "counterparty_name": "John Doe Corp",
      "memo": null,
      "available_actions": ["view_invoice", "view_journal"]
    },
    {
      "movement_type": "RECEIPT",
      "id": 42,
      "item_id": 1,
      "item_sku": "WDG-001",
      "item_name": "Widget",
      "txn_date": "2026-06-01",
      "created_at": "2026-06-01T14:32:00.000000Z",
      "qty_change": "10.0000",
      "unit_cost": "50.0000",
      "value_change": "500.0000",
      "qty_on_hand_after": "10.0000",
      "reference_type": "BILL",
      "reference_id": 12,
      "reference_number": "BILL-0001",
      "transaction_id": 88,
      "counterparty_name": "Acme Suppliers",
      "memo": null,
      "available_actions": ["view_bill", "view_journal"]
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 25,
    "total": 3,
    "last_page": 1
  },
  "links": {
    "first": "http://127.0.0.1:8000/api/v1/inventory-transactions?page=1",
    "last": "http://127.0.0.1:8000/api/v1/inventory-transactions?page=1",
    "prev": null,
    "next": null
  }
}
```

### Row actions → API endpoints

| `available_actions` | Endpoint |
|---------------------|----------|
| `view_bill` | `GET /bills/{reference_id}` |
| `view_invoice` | `GET /invoices/{reference_id}` |
| `view_adjustment` | `GET /inventory-adjustments/{reference_id}` |
| `void` | `POST /inventory-adjustments/{reference_id}/void` (ADMIN, open only) |
| `view_journal` | `GET /journal-entries?reference_transaction_id={transaction_id}` |

> Adjustment rows use `reference_type: INVENTORY_ADJUSTMENT` and `reference_id` as the adjustment header id. `transaction_id` is the adjustment spine transaction id. Voided adjustments are excluded from the hub.

---

## Related endpoints

| Purpose | Endpoint |
|---------|----------|
| Item catalog | `GET /items` |
| Receive stock | `POST /bills/{id}/receive` |
| Sell stock | `POST /invoices/{id}/post` |
| Quantity adjustment | `POST /inventory-adjustments` |
| View adjustment | `GET /inventory-adjustments/{id}` |
| Void adjustment | `POST /inventory-adjustments/{id}/void` |
| Valuation snapshot | `GET /reports/inventory/stock-value` |
| Low stock | `GET /reports/inventory/low-stock` |

---

## Error responses

| Status | Condition |
|--------|-----------|
| `401` | Missing or invalid token |
| `422` | Invalid query parameters (e.g. unknown `type` value) |
