Skip to main content

Overview

The Invoices API provides endpoints for creating, updating, searching, and generating PDF invoices. All endpoints require authentication via session.

Add Product to Invoice (Temporary)

curl -X POST https://your-domain.com/ajax/agregar_facturacion.php \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -H "Cookie: PHPSESSID=your-session-id" \
  -d "id=5" \
  -d "cantidad=2" \
  -d "precio_venta=99.99"
id
integer
required
Product ID to add to invoice
cantidad
integer
required
Quantity of product
precio_venta
float
required
Sale price per unit
html_table
html
Returns HTML table showing current invoice items in temporary storage (tmp table) with:
  • Product code and name
  • Quantity
  • Unit price
  • Total price
  • Subtotal, tax (IVA), and grand total
This endpoint adds products to a temporary session-based storage before the invoice is finalized. Products are stored in the tmp table with the current session ID.

Remove Product from Invoice (Temporary)

curl -X GET "https://your-domain.com/ajax/agregar_facturacion.php?id=10" \
  -H "Cookie: PHPSESSID=your-session-id"
id
integer
required
Temporary item ID (id_tmp) to remove from invoice
html_table
html
Returns updated HTML table with remaining invoice items

Update Invoice

curl -X POST https://your-domain.com/ajax/editar_factura.php \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -H "Cookie: PHPSESSID=your-session-id" \
  -d "id_cliente=5" \
  -d "id_vendedor=1" \
  -d "condiciones=1" \
  -d "estado_factura=1"
id_cliente
integer
required
Client ID associated with the invoice
id_vendedor
integer
required
Vendor/salesperson user ID
condiciones
integer
required
Payment terms/conditions code
estado_factura
integer
required
Invoice status: 1 for paid, 0 for pending
success
html
Returns HTML alert with message: “Factura ha sido actualizada satisfactoriamente.”
error
html
Returns HTML alert with error message if validation fails
The invoice ID is retrieved from the session variable $_SESSION['id_factura']. You must set this session variable before calling this endpoint.

Add Product to Existing Invoice

curl -X POST https://your-domain.com/ajax/editar_facturacion.php \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -H "Cookie: PHPSESSID=your-session-id" \
  -d "id=5" \
  -d "cantidad=3" \
  -d "precio_venta=149.99"
id
integer
required
Product ID to add to invoice
cantidad
integer
required
Quantity of product
precio_venta
float
required
Sale price per unit
html_table
html
Returns HTML table showing updated invoice line items with:
  • Product details
  • Quantities and prices
  • Subtotal, tax, and total
  • Updates the total_venta field in the facturas table
This endpoint adds products to an existing invoice (stored in detalle_factura table). The invoice number is retrieved from $_SESSION['numero_factura'].

Remove Product from Existing Invoice

curl -X GET "https://your-domain.com/ajax/editar_facturacion.php?id=25" \
  -H "Cookie: PHPSESSID=your-session-id"
id
integer
required
Detail ID (id_detalle) to remove from invoice
html_table
html
Returns updated HTML table with remaining invoice line items and recalculated totals

Search Invoices

curl -X GET "https://your-domain.com/ajax/buscar_facturas.php?action=ajax&q=Acme&page=1" \
  -H "Cookie: PHPSESSID=your-session-id"
action
string
required
Must be set to "ajax" to trigger search
q
string
Search term to filter invoices by client name or invoice number. Leave empty to return all invoices.
page
integer
Page number for pagination (default: 1, 10 results per page)
html_table
html
Returns HTML table with invoice data including:
  • numero_factura - Invoice number
  • fecha_factura - Invoice date
  • nombre_cliente - Client name (with phone and email in tooltip)
  • firstname/lastname - Vendor name
  • estado_factura - Status (1 = Paid, 0 = Pending)
  • total_venta - Total sale amount
  • Action buttons for edit, download, and delete

Delete Invoice

curl -X GET "https://your-domain.com/ajax/buscar_facturas.php?id=1001" \
  -H "Cookie: PHPSESSID=your-session-id"
id
integer
required
Invoice number (numero_factura) to delete
success
html
Returns success alert if invoice and all associated line items are deleted
error
html
Returns error alert if deletion fails
Deleting an invoice will also delete all associated line items from the detalle_factura table.

Generate Invoice PDF

curl -X GET "https://your-domain.com/pdf/documentos/factura_pdf.php?id_cliente=5&id_vendedor=1&condiciones=1" \
  -H "Cookie: PHPSESSID=your-session-id" \
  --output invoice.pdf
id_cliente
integer
required
Client ID for the invoice
id_vendedor
integer
required
Vendor/salesperson user ID
condiciones
string
required
Payment terms/conditions
pdf
binary
Returns PDF file named “Factura.pdf” with:
  • Company information from perfil table
  • Client information
  • Invoice items from session’s tmp table
  • Calculated subtotal, tax (IVA), and total
This endpoint:
  1. Creates a new invoice record in the facturas table
  2. Generates a new invoice number (auto-increment from last invoice)
  3. Uses products stored in session’s tmp table
  4. Returns a PDF document using the HTML2PDF library
  5. Will display alert and close window if no products are in temporary storage
Ensure products have been added to the temporary storage (via agregar_facturacion.php) before calling this endpoint, or it will fail.

Build docs developers (and LLMs) love