Overview
The Transacciones API provides read-only access to transaction records in the POS system. Transactions are automatically created when invoices are approved or canceled, serving as an audit trail for inventory movements.This is a read-only endpoint. Transactions are created automatically by the system during invoice approval and cancellation processes. Manual transaction creation is not supported through this API.
Authentication
usuario and password fields for database connection credentials.
Get All Transactions
/api/pos/transaccion
Example Request
Response
Returns an array of transaction objects ordered bytrn_descripcion.
Transaction code (auto-generated)
Transaction description (typically “Factura “)
200 Success
404 Not Found
500 Server Error
Transaction Records
What are Transactions?
Transactions (transaccion table) serve as a centralized record of all inventory-affecting operations in the POS system. Each transaction:
- Has a unique auto-generated code (
trn_cod) - Contains a description identifying the source operation
- Links to kardex entries for detailed product movements
- Provides an audit trail for inventory changes
When are Transactions Created?
Transactions are automatically created during:-
Invoice Approval - When an invoice transitions from
PENtoAPRstatus- Transaction type: Sale/Outbound
- Description: “Factura ”
- Creates kardex entries for each product with negative quantities (stock decrease)
-
Invoice Cancellation - When an invoice is canceled (transitions to
ANUstatus)- Transaction type: Reversal/Inbound
- Description: “Anulación Factura ”
- Creates kardex entries for each product with positive quantities (stock restore)
Transaction Lifecycle
Related Data Structures
Transaction Table Schema
Thetransaccion table stores transaction headers:
| Column | Type | Description |
|---|---|---|
| trn_cod | VARCHAR | Transaction code (PK, auto-generated) |
| trn_tipo | VARCHAR | Transaction type identifier |
| trn_descripcion | VARCHAR | Human-readable description |
| trn_fecha | TIMESTAMP | Transaction creation date |
Kardex Integration
Each transaction is linked to multiple kardex entries (kardex_prd table):
| Column | Type | Description |
|---|---|---|
| krd_codigo | VARCHAR | Kardex entry code (PK) |
| trn_cod | VARCHAR | Transaction reference (FK) |
| prd_codigo | VARCHAR | Product code (FK) |
| fac_codigo | VARCHAR | Invoice reference (FK) |
| krd_cantidad | INTEGER | Quantity moved (negative for sales) |
| krd_razon | VARCHAR | Reason for movement |
| krd_fechahora | TIMESTAMP | Movement timestamp |
| usr_id | VARCHAR | User who performed action |
Use Cases
Audit Trail
Query transactions to track all inventory-affecting operations:Reconciliation
Use transaction records to reconcile inventory movements with invoice records:- Retrieve all transactions
- Match transaction codes with kardex entries
- Verify stock changes align with invoice details
- Identify discrepancies or missing transactions
Reporting
Generate reports on system activity:- Volume Reports: Count transactions by date range
- Invoice Tracing: Track which invoices generated transactions
- Movement Analysis: Analyze transaction patterns over time
Limitations
- No Pagination: Returns all records. For large datasets, this may cause performance issues.
- No Filtering: Cannot filter by date, type, or invoice code.
- No Detailed Info: Only returns code and description. Full transaction details require additional queries.
- Read-Only: No POST, PUT, or DELETE operations supported.
Recommended Enhancements
For production use, consider implementing:- Pagination: Add
pageandlimitquery parameters - Date Filtering: Filter by
trn_fechadate range - Invoice Lookup: Get transactions by invoice code
- Type Filtering: Filter by transaction type
- Detailed View: Include related kardex entries and stock changes
- Search: Support description search
Error Handling
Common Error Responses
404 No Records Found
transaccion table is empty. This is normal for new systems before any invoices have been approved.
500 Server Error
401 Unauthorized
Implementation Details
Source Code Reference
- Route:
src/routes/pos.transaccion.routes.js:8 - Controller:
src/controllers/pos.transaccion.controller.js:12-27 - Model:
src/models/transaccion.model.js:1-9
Database Query
The endpoint executes a simple SELECT query:Connection Management
Uses JWT-based database credentials:- Extracts credentials from JWT token
- Creates a new database connection pool
- Executes the query
- Closes the connection pool (in finally block)
Integration Examples
Get Transaction History
Filter by Invoice Code
Since the API doesn’t support filtering, implement client-side filtering:Build Transaction Timeline
Related Endpoints
Transactions are created as a result of invoice operations. See related endpoints:- Approve Invoice - Creates transaction and decreases stock
- Cancel Invoice - Creates reversal transaction and restores stock
kardex_prd table directly (not currently exposed via API).
Future Enhancements
Potential improvements for the Transacciones API:1. Pagination Support
2. Date Range Filtering
3. Transaction Details
4. Invoice Lookup
5. Transaction Statistics
These enhancements are not currently implemented. Contact the development team if you need these features for your integration.
Best Practices
1. Cache Transaction Data
Since transactions are immutable (never updated or deleted), cache the results:2. Handle Empty State
New systems won’t have transactions until the first invoice is approved:3. Correlate with Invoices
Cross-reference transactions with invoice data:4. Monitor Transaction Creation
Verify transactions are created after invoice operations:Summary
The Transacciones endpoint provides read-only access to the transaction audit trail:- Purpose: Track inventory-affecting operations
- Creation: Automatic during invoice approval/cancellation
- Access: GET endpoint returning all records
- Limitations: No filtering, pagination, or detailed views
- Use Cases: Audit, reconciliation, reporting