# Brix Accounting API — Sales transactions hub

Unified read API for a QuickBooks-style **Sales transactions** page: one list of invoices, customer payments, and quotations, plus summary totals (Money Bar).

Create, edit, post, void, and receive payment still use the existing [invoices](./invoices.md) and [customer payments](./payments.md) endpoints. Create and edit quotations use [quotations](./quotations.md). Quotations appear in the list for visibility but do not post to the ledger or affect `summary` totals.

---

## Base URL

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

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

---

## Authentication

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

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

---

## Role permissions

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

Row-level `available_actions` respect invoice, payment, and quotation policies (e.g. only ADMIN can void invoices or delete quotations).

---

## List sales transactions

```
GET /sales-transactions
```

### Query parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `type` | string | `invoice,payment,quotation` | Comma-separated: `invoice`, `payment`, `quotation`. Use `invoice,payment` to exclude quotations. |
| `status` | string | *(all)* | Comma-separated invoice/payment: `draft`, `open`, `partial`, `paid`, `voided`, `overdue`. Quotation-only: `sent`, `accepted`, `rejected`, `expired`. `draft` matches invoice and quotation drafts. |
| `customer_id` | integer | — | Filter by customer |
| `start_date` | date | 365 days ago | Minimum `txn_date` (invoices/payments) or `quote_date` (quotations) |
| `end_date` | date | today | Maximum `txn_date` or `quote_date` |
| `search` | string | — | Match document number, memo (quotations), or customer name |
| `paid_days` | integer | `30` | Window for `summary.paid_recent` |
| `per_page` | integer | `25` | Page size (1–100) |
| `page` | integer | `1` | Page number |

**Status notes**

- `open` — `OPEN` or `PARTIAL` invoice with `balance > 0` (quotations excluded)
- `overdue` — open invoice with `due_date` before today (quotations excluded)
- `paid` on payments — includes `PAYMENT` rows with status `POSTED`
- `sent`, `accepted`, `rejected`, `expired` — quotation statuses only
- `summary` — counts invoices and payments only; quotations never affect Money Bar totals

**Balance meaning (QBO-style)**

| `transaction_type` | `balance` |
|--------------------|-----------|
| `INVOICE` | Remaining amount owed on the invoice |
| `PAYMENT` | Remaining **unapplied** credit (`total_amount − applied allocations`). Fully applied = `0.0000`. Voided = `0.0000`. |
| `QUOTATION` | Always `0.0000` |

UI cue: `PAYMENT` + `balance > 0` means the payment still has customer credit to apply.

**Sort order**

Rows are always sorted by `created_at` descending (newest created first). `txn_date` / `quote_date` does not control list order. When `created_at` ties, `transaction_type` then `id` break the tie.

### Example request

```http
GET /api/v1/sales-transactions?status=open,overdue&per_page=25
Authorization: Bearer {token}
Accept: application/json
```

### Success response — `200 OK`

```json
{
  "summary": {
    "open": { "count": 2, "total": "450.0000" },
    "overdue": { "count": 1, "total": "236.0000" },
    "draft": { "count": 1, "total": "118.0000" },
    "paid_recent": { "count": 3, "total": "708.0000", "days": 30 }
  },
  "data": [
    {
      "transaction_type": "INVOICE",
      "id": 12,
      "transaction_id": 88,
      "number": "INV-0001",
      "customer_id": 3,
      "customer_name": "Acme Corp",
      "txn_date": "2026-06-01",
      "created_at": "2026-06-01T14:32:00.000000Z",
      "due_date": "2026-07-01",
      "total_amount": "236.0000",
      "balance": "236.0000",
      "status": "OPEN",
      "payment_method": null,
      "is_overdue": false,
      "available_actions": ["view", "void", "receive_payment", "view_journal"]
    },
    {
      "transaction_type": "PAYMENT",
      "id": 5,
      "transaction_id": 91,
      "number": "PAY-0001",
      "customer_id": 3,
      "customer_name": "Acme Corp",
      "txn_date": "2026-06-15",
      "created_at": "2026-06-15T09:10:00.000000Z",
      "due_date": null,
      "total_amount": "500.0000",
      "balance": "264.0000",
      "status": "POSTED",
      "payment_method": "CASH",
      "is_overdue": false,
      "available_actions": ["view", "view_journal", "void"]
    },
    {
      "transaction_type": "QUOTATION",
      "id": 7,
      "transaction_id": null,
      "number": "Q-0001",
      "customer_id": 3,
      "customer_name": "Acme Corp",
      "txn_date": "2026-06-24",
      "created_at": "2026-06-24T10:00:00.000000Z",
      "due_date": "2026-07-24",
      "total_amount": "1500.0000",
      "balance": "0.0000",
      "status": "SENT",
      "payment_method": null,
      "is_overdue": false,
      "available_actions": ["view", "edit"]
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 25,
    "total": 2,
    "last_page": 1
  },
  "links": {
    "first": "http://127.0.0.1:8000/api/v1/sales-transactions?page=1",
    "last": "http://127.0.0.1:8000/api/v1/sales-transactions?page=1",
    "prev": null,
    "next": null
  }
}
```

### Row actions → API endpoints

| `available_actions` | Endpoint |
|---------------------|----------|
| `view` | `GET /invoices/{id}`, `GET /customer-payments/{id}`, or `GET /quotations/{id}` |
| `edit` | `PATCH /invoices/{id}` or `PUT /quotations/{id}` |
| `copy` | `POST /invoices/{id}/copy` or `POST /quotations/{id}/copy` |
| `convert_to_invoice` | `POST /quotations/{id}/convert-to-invoice` |
| `post` | `POST /invoices/{id}/post` |
| `void` | `POST /invoices/{id}/void` |
| `delete` | `DELETE /invoices/{id}` or `DELETE /quotations/{id}` |
| `void` (payment) | `POST /customer-payments/{id}/void` |
| `receive_payment` | `POST /customer-payments` |
| `view_journal` | `GET /journal-entries?reference_transaction_id={transaction_id}` (invoices/payments only; `transaction_id` is null on quotations) |

---

## Related endpoints

| Purpose | Endpoint |
|---------|----------|
| Create invoice | `POST /invoices` |
| Create quotation | `POST /quotations` |
| Receive payment | `POST /customer-payments` |
| AR aging detail | `GET /reports/ar-aging` |
| Customer balance summary | `GET /reports/customer-balance-summary` |
| Customer balance detail | `GET /reports/customer-balance-detail` |
| Sales by customer summary | `GET /reports/sales-by-customer-summary` |
| Sales by customer detail | `GET /reports/sales-by-customer-detail` |
| Income by customer summary | `GET /reports/income-by-customer-summary` |
| Income by customer detail | `GET /reports/income-by-customer-detail` |
| Income by customer invoice detail | `GET /reports/income-by-customer-invoice-detail` |
| Sales by product summary | `GET /reports/sales-by-product-summary` |
| Sales by product detail | `GET /reports/sales-by-product-detail` |
| Journal drill-down | `GET /journal-entries` |

---

## Error responses

| Status | Condition |
|--------|-----------|
| `401` | Missing or invalid token |
| `422` | Invalid query parameters |
