# Duplicate invoice numbers

> How Alya Books keeps invoice numbers unique, what happens when a number is already used, and how to avoid gaps.

Source: /help/en/invoices/duplicate-invoice-numbers

Every invoice number must be unique within your organization. Alya Books allocates numbers from a series when you save, so duplicates only arise when a number is imported or typed by hand (possible only when **Allow manual document numbers** is on).

## How numbers are allocated

1. The editor pre-fills the number from the series for the document kind (invoice, credit note, debit note) using the template in **Settings → Outgoing invoices → Document Numbering** (tokens `{YYYY}`, `{YY}`, `{MM}`, `{DD}`, `{n}`).
2. The number is fixed when you save. If the next number in the series already exists, the series skips ahead automatically.
3. By default the number field is read-only, so every invoice takes the next number in order. If **Allow manual document numbers** is switched on (**Settings → Outgoing invoices → Numbers, terms and editing**) and you type a number yourself, the counter moves to that number so later invoices continue after it.

## When a number is already used

- Saving an invoice with a number that exists fails with a "Failed to create invoice" error naming the duplicate. Change the number or clear it so the series assigns the next one (only possible with manual numbers on; otherwise the next free number is taken automatically).
- CSV imports skip rows whose number already exists and list them in the import result.
- Through the API, a reused `invoiceNumber` returns a validation error; `GET /invoices/verify-number` checks a number before you use it.
- Incoming invoices with the same supplier TRN and number as an existing one are rejected as duplicates.

Good to know:

- A rejected invoice keeps its number. After you fix and resubmit it, the new attempt uses the same number; the previous attempt stays visible on the **E-invoicing Submissions** card.
- **Duplicate** in the invoice menu copies the content into a new draft with a new number; it never reuses the original number.
- Credit notes, debit notes and proformas have their own series and prefixes, so `CN-0001` and `INV-0001` do not conflict.
- Do not renumber issued invoices. They are locked, and the FTA has already received the number.
- If you need a gap-free sequence, keep **Allow manual document numbers** off and avoid deleting drafts that already received a number (or switch off **Reserve invoice numbers for drafts**).

Related:

- [Create a tax invoice](/help/en/invoices/create-a-tax-invoice)
- [Recurring invoices](/help/en/invoices/recurring-invoices)
