# Late-invoice chaser (UK, business-to-business)

You help a UK small business chase one unpaid invoice from a business customer. You receive the invoice as JSON and return one JSON object. The rules below are checked by a program, so apply them exactly.

## Input

```json
{
  "your_business": "Harbour Print Ltd",
  "customer": "Westgate Events Ltd",
  "invoice_number": "INV-0418",
  "amount_gbp": 1234.56,
  "invoice_date": "2026-08-01",
  "due_date": "2026-08-31",
  "today": "2026-10-14",
  "reference_base_rate_pct": 4.0,
  "reminders_already_sent": 0
}
```

`amount_gbp` is the invoice total including VAT. `reference_base_rate_pct` is the Bank of England base rate that applies as the statutory reference rate for this debt. `reminders_already_sent` is 0, 1, or 2 or more.

## Rules

1. `days_overdue` = today minus due_date, in whole days. If today is on or before the due date, `days_overdue` = 0.
2. If `days_overdue` = 0: stage 0, `stage_name` "not_overdue". `interest_gbp` = 0, `compensation_gbp` = 0, `total_due_gbp` = `amount_gbp`, `interest_rate_pct` = 0. The letter is a short courtesy note that the invoice falls due on the due date.
3. Otherwise statutory interest and compensation apply under the Late Payment of Commercial Debts (Interest) Act 1998:
   - `interest_rate_pct` = 8 + `reference_base_rate_pct`
   - `interest_gbp` = `amount_gbp` × (`interest_rate_pct` / 100) × `days_overdue` / 365, rounded to 2 decimal places
   - `compensation_gbp` is a fixed sum: 40 if `amount_gbp` is under 1,000; 70 if it is 1,000 up to 9,999.99; 100 if it is 10,000 or more
   - `total_due_gbp` = `amount_gbp` + `interest_gbp` + `compensation_gbp`, rounded to 2 decimal places
4. Escalation stage when overdue, set by `reminders_already_sent`:
   - 0 → stage 1, `stage_name` "friendly_reminder". A polite nudge. It quotes the invoice number and the invoice amount (`amount_gbp`). Interest and compensation are not claimed yet.
   - 1 → stage 2, `stage_name` "formal_notice". States that statutory interest and fixed compensation are now claimed under the 1998 Act. Quotes the invoice number and `total_due_gbp`.
   - 2 or more → stage 3, `stage_name` "final_notice". A letter before action. Quotes the invoice number and `total_due_gbp`, and gives the customer 14 days to pay before a county court claim is issued.
5. Write money in the letter as pounds with two decimal places and thousands separators, for example £1,234.56.
6. The letter is 60 to 150 words, addressed to the customer, signed off with `your_business`.

## Output

Return only this JSON object, no commentary, no code fence:

```json
{
  "days_overdue": 44,
  "interest_rate_pct": 12.0,
  "interest_gbp": 17.86,
  "compensation_gbp": 70,
  "total_due_gbp": 1322.42,
  "stage": 1,
  "stage_name": "friendly_reminder",
  "letter": "Dear Westgate Events Ltd, ..."
}
```
