Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/eme2dev/Eme2App/llms.txt

Use this file to discover all available pages before exploring further.

Delivery notes (albaranes) sit between a quote and an invoice in the sales workflow. They confirm that goods or services have been delivered before a formal invoice is raised, which is common practice in Spanish B2B billing. Eme2App supports creating albaranes from scratch, generating them directly from an accepted quote, and converting one or several albaranes into a single invoice — keeping a full traceability chain from quote through delivery to invoice.

Albarán Lifecycle

editable ──► entregado ──► facturado
EstadoMeaning
editableDraft — can be updated or deleted
entregadoMarked as delivered to the client
facturadoConverted to an invoice; no further edits or deletion allowed
Once an albarán reaches facturado state, it cannot be deleted. If the associated invoice is later deleted, the backend automatically reverts all linked albaranes back to editable.

Auto-Numbering

GET /api/albaranes/proximo-numero
{ "proximo_numero": 7 }
Numbers are company-scoped. Unlike invoices, albaranes do not use series by default.

Creating an Albarán from Scratch

POST /api/albaranes Required fields:
FieldTypeNotes
cliente_idstringMust belong to the company
numerointegerUnique within the company
lineasarrayAt least one line
Optional fields: fecha, serie_id, notas. Line item fields:
FieldTypeNotes
articulo_idstringRequired for non-comment lines
descripcionstringFree-text description
cantidadnumberQuantity
precio_unitarionumberUnit price before tax
es_comentariobooleanText-only line when true
linea_ordenintegerDisplay order
Totals (subtotal, iva_total, irpf_monto, total) are computed server-side from the article’s iva_id and the client’s regimen_irpf.
// POST /api/albaranes — example request body
{
  "cliente_id": "abc123",
  "numero": 7,
  "fecha": "2025-06-18",
  "notas": "Entrega en almacén central",
  "lineas": [
    {
      "articulo_id": "art-001",
      "descripcion": "Servidor rack 2U",
      "cantidad": 2,
      "precio_unitario": 1200.00
    }
  ]
}
// 201 Created
{ "id": "<albaran_uuid>", "mensaje": "Albarán creado exitosamente" }

Creating an Albarán from a Quote

POST /api/albaranes/desde-presupuesto/:presupuestoId This endpoint converts an existing presupuesto into an albarán in a single operation. The system:
  1. Loads the presupuesto and its detail lines.
  2. Creates an albarán with the next auto-incremented number and today’s date.
  3. Copies all detail lines (quantities, prices, IVA amounts).
  4. Sets presupuesto_origen_id on the albarán for traceability.
  5. Marks the presupuesto as convertida.
The presupuesto must not be in cancelada, convertida, or aceptada state.
// 201 Created
{
  "id": "<albaran_uuid>",
  "numero": 7,
  "mensaje": "Presupuesto convertido a albarán exitosamente",
  "albaran": { ... }
}
If you later delete this albarán and it was the only one linked to the presupuesto, the presupuesto is automatically restored to borrador state.

Updating an Albarán

PUT /api/albaranes/:id Only albaranes in editable state can be updated. All existing lines are replaced atomically. Send the complete updated line set:
{
  "cliente_id": "abc123",
  "fecha": "2025-06-19",
  "notas": "Entrega aplazada un día",
  "lineas": [ ... ]
}

Updating Albarán State

PUT /api/albaranes/:id/estado
{ "estado": "entregado" }
Valid states: editable, entregado, facturado. The facturado state is set automatically by the invoicing endpoints — avoid setting it manually.

Sending an Albarán by Email

POST /api/albaranes/:id/enviar-email
{
  "destino": "cliente@empresa.es",
  "pdf_base64": "<base64-string>",
  "pdf_nombre": "albaran-7.pdf"
}
Uses the company’s SMTP configuration. Optionally supply asunto and texto to override the default subject and body.

Invoicing a Single Albarán

POST /api/albaranes/:id/facturar Converts one albarán into an invoice. The albaran_linea_origen_id is stored in each detalles_facturas row for traceability. Required in body:
FieldTypeNotes
numerointegerTarget invoice number
forma_pago_idstringPayment method UUID
Optional: fecha, serie_id, estado_factura ("borrador" or "confirmada", defaults to "confirmada").
// POST /api/albaranes/:id/facturar
{
  "numero": 42,
  "fecha": "2025-06-20",
  "serie_id": "uuid-serie-A",
  "forma_pago_id": "uuid-forma-pago",
  "estado_factura": "confirmada"
}
// 201 Created
{
  "id": "<factura_uuid>",
  "numero": 42,
  "fecha": "2025-06-20",
  "mensaje": "Albarán facturado exitosamente"
}
If estado_factura is "confirmada", the backend also auto-generates facturas_vencimientos from the forma_pago template in the same operation. The albarán is marked facturado on success.

Grouped Invoicing (Facturación Agrupada)

POST /api/albaranes/facturar-agrupado Group multiple albaranes — from the same client — into a single invoice. All line items from every albarán are merged in order, with a global linea_orden counter maintaining their sequence. Required in body:
FieldTypeNotes
albaran_idsstring[]At least one albarán UUID
numerointegerTarget invoice number
forma_pago_idstringPayment method UUID
Optional: fecha, serie_id, estado_factura ("borrador" or "confirmada"). Validation rules:
  • All albaranes must belong to the same company.
  • All albaranes must share the same cliente_id.
  • None of the albaranes may already be in facturado state.
// POST /api/albaranes/facturar-agrupado
{
  "albaran_ids": ["<uuid-1>", "<uuid-2>", "<uuid-3>"],
  "numero": 43,
  "fecha": "2025-06-30",
  "serie_id": "uuid-serie-A",
  "forma_pago_id": "uuid-forma-pago",
  "estado_factura": "confirmada"
}
// 201 Created
{
  "id": "<factura_uuid>",
  "numero": 43,
  "fecha": "2025-06-30",
  "albaranes_facturados": 3,
  "mensaje": "Albaranes facturados exitosamente"
}

Grouped Billing Workflow

1

Deliver goods or services

Create one albarán per delivery (POST /api/albaranes) and set state to entregado when physically dispatched.
2

Get the next invoice number

Call GET /api/facturas/proximo-numero (optionally with ?serie=A) to get the next available invoice number.
3

Group and invoice

Call POST /api/albaranes/facturar-agrupado with all albarán IDs, the invoice number, and the forma de pago. Set estado_factura to "confirmada" to generate vencimientos immediately.
4

Review the merged invoice

Call GET /api/facturas/:id to inspect the created invoice. All line items from every albarán are listed in order with their albaran_linea_origen_id references.
5

Send and collect

Send the invoice by email (POST /api/facturas/:id/enviar-email) and register collections via the Invoices module when payment arrives.

API Quick Reference

MethodEndpointDescription
GET/api/albaranes/proximo-numeroNext available albarán number
GET/api/albaranesPaginated list (filters: cliente_id, estado, desde, hasta)
GET/api/albaranes/:idAlbarán detail with lines
POST/api/albaranesCreate an albarán
PUT/api/albaranes/:idUpdate an albarán (editable only)
PUT/api/albaranes/:id/estadoUpdate albarán state
DELETE/api/albaranes/:idDelete an albarán (not facturado)
POST/api/albaranes/desde-presupuesto/:presupuestoIdCreate from a quote
POST/api/albaranes/:id/facturarInvoice a single albarán
POST/api/albaranes/facturar-agrupadoInvoice multiple albaranes together
POST/api/albaranes/:id/enviar-emailSend PDF by email

Build docs developers (and LLMs) love