# Bulk Operations

Update or delete multiple records at once from the chat. All bulk operations require **explicit confirmation** before execution.

## Available Tools

| Tool | What it does | Affected records |
|-------------|----------|---------------------|
| `bulkUpdateInvoices` | Changes the status of multiple invoices | Invoices |
| `bulkUpdateExpenses` | Changes the category of multiple expenses | Expenses |
| `bulkDeleteDrafts` | Deletes invoice or quote drafts | Draft invoices, draft quotes |

## Update Invoices in Bulk

### Mark as Paid

```
"Marca como pagadas todas las facturas de enero"
```

The assistant:

1. Searches for all January invoices with `sent` or `overdue` status
2. Shows a summary: number of invoices, total amount, list of clients
3. Asks for confirmation
4. Updates the status to `paid` and records the collection date

### Change Status

```
"Cambia a enviadas todas las facturas en borrador de Acme SL"
```

The assistant searches for the drafts of the specified client, shows the summary, and waits for confirmation.

### Filters you can use

- **By period**: "from January", "from Q1", "of this month"
- **By client**: "from Acme SL", "from Juan Garcia"
- **By status**: "in draft", "pending", "overdue"
- **By amount**: "over 500 euros", "under 100 euros"

## Update Expenses in Bulk

### Change Category

```
"Cambia todos los gastos de 'Otros' a 'Software'"
```

The assistant:

1. Searches for all expenses with category "Otros"
2. Shows how many there are and the total amount
3. Asks for confirmation
4. Updates the category of all to "Software"

### Other examples

```
"Marca como deducibles todos los gastos de transporte"
```

```
"Cambia la categoría de los gastos de 'Servicios' de enero a 'Consultoría'"
```

## Delete Drafts

### Delete Draft Invoices

```
"Elimina todos los borradores de facturas"
```

The assistant:

1. Counts existing drafts
2. Shows the list with client, amount, and date
3. Asks for confirmation with a clear message: "X draft invoices totaling Y EUR will be deleted"
4. Deletes after your confirmation

### Delete Draft Quotes

```
"Elimina todos los presupuestos en borrador"
```

Same flow: list, summary, confirmation, execution.

## Confirmation Flow

All bulk operations follow this flow:

1. **The assistant searches** for records matching your request
2. **Shows a summary** with the quantity, total amount, and affected records
3. **Asks for explicit confirmation** — "Do you confirm this operation?"
4. **Executes the operation** only after you confirm
5. **Shows the result** — how many records were updated or deleted

If you do not confirm, the operation is canceled without changes.

### Example Dialog

```
Tú: "Marca como pagadas todas las facturas de febrero"

Asistente: "He encontrado 8 facturas de febrero por un total de 12.340,00 EUR:
- F-2026-012 — Acme SL — 3.200,00 EUR
- F-2026-013 — Design Co — 1.500,00 EUR
- ...
¿Confirmas marcar las 8 como pagadas?"

Tú: "Sí"

Asistente: "Hecho. 8 facturas marcadas como pagadas."
```

## Undo

Bulk operations **cannot be undone automatically**. If you need to revert a change, you can:

- Use the same command with the previous status: "Change February invoices to sent"
- Edit each record individually from the interface

Draft deletions are permanent. The assistant warns you before executing.

## Security

- Only records in **draft** status can be deleted (never sent, paid, or canceled invoices)
- Invoices with an active VeriFactu chain cannot be deleted
- Explicit confirmation is required in all cases
- The activity log records who executed the operation and when

---

**Next step:** [Upload documents to chat](./subir-documentos)
