# 10 — Billing / Invoices

← [Back to index](README.md)

Simplified invoices (amount + status). Created on booking (paid/pending per a UI toggle)
and from the Billing tab.

---

## Invoice object
```json
{
  "id": "inv1",
  "patientName": "محمد علي حسن",
  "amountPiastres": 30000,
  "status": "pending",
  "createdAt": "2026-05-22T10:15:00Z",
  "description": "كشف أول"
}
```
- `status`: [InvoiceStatus](11-enums.md) — `pending` / `paid` only.
- `description` nullable (usually the visit-type label).
- The model is **patient-name based** (denormalized); there's no hard `patientId` link in
  the current contract. Add one server-side for integrity if you like — optional.

---

## Endpoints
| Endpoint | Notes |
|---|---|
| `GET /invoices` | array of Invoice, **most recent first** |
| `POST /invoices` | create (body below) → `201` Invoice |
| `PUT /invoices/{id}` | update; used to mark paid (app sends the full invoice with `status: "paid"`) → `200` |
| `DELETE /invoices/{id}` | `200`/`204` |

### `POST /invoices` body
```json
{ "patientName": "محمد علي حسن", "amountPiastres": 30000, "status": "paid", "description": "كشف أول" }
```
Server sets `id`, `createdAt`.

> **Outstanding total** is computed client-side from the list (sum of `pending`) — no
> separate endpoint needed.

---

## Field contract — `Invoice`
`id`, `patientName` (req), `amountPiastres` (int, req), `status` ([InvoiceStatus](11-enums.md), req),
`createdAt` (datetime, server-set), `description?`.
