The expenses module covers the inbound side of your company’s finances — everything you pay out, from supplier invoices to operational costs. Each expense record stores a supplier reference, date, one or more concept lines with their base amounts and VAT breakdown, and an optional link to a registeredDocumentation 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.
proveedores entry. Because expenses feed directly into Eme2App’s VAT summary and reporting engine, keeping them accurate is essential for quarterly tax filings.
What Expenses Cover
Eme2App uses the term “gastos” to encompass both formal facturas de compra (purchase invoices from suppliers) and general gastos operativos (operating costs such as utilities, subscriptions, or professional fees). Both types share the same data model and API.The same router is mounted at two paths:
/api/gastos and /api/facturas-compra. Both are fully interchangeable — use whichever is more semantically appropriate in your frontend code.Data Model
Agastos record contains header-level fields plus one or more detalles_gastos lines:
Header fields (gastos table):
| Field | Type | Notes |
|---|---|---|
fecha | date | Expense date (YYYY-MM-DD) — required |
proveedor_id | string (UUID) | Optional link to a registered supplier |
proveedor | string | Free-text supplier name (required if no proveedor_id) |
referencia_proveedor | string | Supplier’s document reference — max 20 chars, required |
estado | boolean | Active/inactive flag |
base_imponible | Decimal(10,2) | Aggregate taxable base (header-level summary) |
cuota_iva | Decimal(10,2) | Aggregate VAT amount |
total | Decimal(10,2) | Total including VAT |
detalles_gastos):
| Field | Type | Notes |
|---|---|---|
concepto | string | Line description — required |
base_imponible | number | Taxable base for this line — must be > 0 |
iva_id | string | Optional link to an iva record |
cuota_iva | number | Computed or entered VAT amount |
total | number | Base + cuota_iva |
modo_calculo | string | "base" / "total" / "persistido" — controls how totals are derived |
linea_orden | integer | Display order |
Creating an Expense
POST /api/gastos
The backend accepts two input shapes:
Multi-line (using detalles array):
detalles array automatically.
Validation rules enforced server-side:
fechamust be inYYYY-MM-DDformat.- Either
proveedor_idorproveedor(free text) must be present. referencia_proveedoris required and may not exceed 20 characters.- Every detail line must have a non-empty
concepto. - Every detail line must have a
base_imponiblegreater than 0.
Listing Expenses
GET /api/gastos
Returns a paginated list of expenses for the authenticated company. Query parameters:
| Parameter | Description |
|---|---|
page | Page number (default: 1) |
pageSize | Results per page (defaults to empresa.pagesize_default) |
Retrieving a Single Expense
GET /api/gastos/:id
Returns the expense header and all its detalles_gastos lines.
Updating an Expense
PUT /api/gastos/:id
The request body follows the same shape as the create call. All existing detail lines are replaced. The same validation rules apply.
Deleting an Expense
DELETE /api/gastos/:id
Permanently deletes the expense and all its detail lines (cascade). There are no state restrictions — any expense can be deleted.
VAT Breakdown and Reports Integration
Everydetalles_gastos line is linked to an iva record via iva_id. This enables the reporting engine to:
- Aggregate
base_imponibleandcuota_ivaby VAT rate across all expenses in a period. - Include purchase-side VAT in the quarterly Modelo 303 summary (IVA soportado).
- Cross-reference against income invoices for the net VAT position.
Expense IVA calculation modes
Expense IVA calculation modes
The
Use
modo_calculo field in each detalles_gastos line controls how the backend derives amounts when saving:| Mode | Behaviour |
|---|---|
"base" | cuota_iva = base_imponible × iva.porcentaje / 100; total = base + cuota_iva |
"total" | Back-calculates base_imponible from a known total including VAT |
"persistido" | Stores the values exactly as supplied; no recalculation |
"persistido" when importing historical invoices where the exact amounts are known and must not be altered.Roles and Access
All expense endpoints require a valid JWT via theverificarAutenticacion middleware. The empresaId is resolved from the authenticated session — users only see expenses belonging to their own company.
Unlike invoices (where only admins can delete), expense deletion is available to all authenticated users. If you need to restrict deletions to admin roles, configure the appropriate permission in
menu_items_permisos.API Quick Reference
| Method | Endpoint | Also available at | Description |
|---|---|---|---|
GET | /api/gastos | /api/facturas-compra | Paginated expense list |
GET | /api/gastos/:id | /api/facturas-compra/:id | Single expense detail |
POST | /api/gastos | /api/facturas-compra | Create an expense |
PUT | /api/gastos/:id | /api/facturas-compra/:id | Update an expense |
DELETE | /api/gastos/:id | /api/facturas-compra/:id | Delete an expense |