> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chift.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# Invoice amounts validation and corrections

> Understand how invoice amounts are validated and how to handle rounding corrections when using the Unified API.

## Invoice amounts validation and corrections

When creating invoices through the Unified API, several **automatic validations** are applied to ensure data consistency between line items and totals.\
These checks prevent rounding mismatches and enforce coherent invoice structures across all connected accounting tools.

***

### 🔍 1. Total-level validation

At the invoice level, the following rules apply:

* **Line count check:** An invoice must contain **at least one line**.
* **Total amount check:** The total must be **greater than or equal to 0**.
* **Sum consistency:**\
  The **sum of all line totals** must match the **invoice total**, within a precision of **4 decimals**.

If there’s a mismatch:

* Difference **> €0.01** → ❌ Rejected
* Difference **≤ €0.01** and **no correction lines provided** → ❌ Rejected
* Difference **≤ €0.01** and **correction lines provided** → ✅ Accepted (corrections applied automatically)

***

### 🔍 2. Line-level validation

Each invoice line is validated individually:

* `untaxed_amount + tax_amount` must equal `total`
* `unit_price × quantity` must equal `untaxed_amount`
* `untaxed_amount × tax_rate` must equal `tax_amount`

***

### ⚙️ 3. About `regroup_lines`

The `regroup_lines` parameter defines whether lines are **grouped** before validation and posting.

| Parameter       | Default | Behavior                                                                               |
| --------------- | ------- | -------------------------------------------------------------------------------------- |
| `regroup_lines` | `true`  | Lines are grouped by account, tax code, and analytical distribution before validation. |

**When regrouping is enabled:**

* Lines sharing the same account, tax code, or analytical distribution are **merged**.
* Amounts are **recalculated and rounded to 2 decimals**.
* A new total is computed, and a correction line may be added if needed.

**When regrouping is disabled (`regroup_lines = false`):**

* Each line is validated individually.
* We recommend **disabling regrouping** unless it’s explicitly required by your accounting logic.

👉 **Best practice:**\
Set `regroup_lines = false` to keep full control over your invoice line structure and amounts.

***

### 🧾 4. Invoice corrections

When small rounding differences remain after regrouping or amount calculations, the Unified API can automatically create a **correction line** to ensure that the invoice total matches the sum of all lines exactly.

You activate this feature by filling in the [`invoice_correction` object](https://docs.chift.eu/api-reference/endpoints/accounting/create-salepurchase-entry-multiple-plans#body-invoice-correction).

When this object is provided, the Unified API uses the account numbers and tax codes you define to generate the correction line automatically.

#### Example — `invoice_correction` object

```json theme={null}
"invoice_correction": {
  "sale_invoice_correction_tax_code": "FR_0",
  "purchase_invoice_correction_tax_code": "FR_0",
  "invoice_correction_credit_account_number": "758000",
  "invoice_correction_debit_account_number": "658000"
}
```
