Overview
The Invoice Management feature provides comprehensive functionality for registering and managing company invoices that will be used for factoring and bundled into investment opportunities. The system automatically generates unique invoice codes in the format F-001, F-002, etc., and tracks invoice lifecycle from creation through payment.Key Capabilities
Auto-Generated Codes
Automatic invoice numbering with F-XXX format for easy identification and tracking
Company Association
Link each invoice to a specific company for organized management
Date Tracking
Track both emission and payment dates for complete lifecycle visibility
Status Management
Enable/disable invoices based on availability for investment opportunities
Data Model
TheFactura entity contains the following key fields:
| Field | Type | Description |
|---|---|---|
idFactura | int | Unique identifier (auto-generated) |
codFactura | String | Invoice code (F-001, F-002, etc.) - auto-generated |
monto | double | Invoice amount |
fechaEmision | Date | Date invoice was issued (auto-set to current date) |
fechaPago | Date | Expected or actual payment date |
enable | String | Status: “Activo” (available) or “No Activo” (used/disabled) |
descripcion | String | Invoice description or notes |
empresa | Empresa | Associated company entity |
When an invoice is bundled into an investment opportunity, its
enable status is automatically changed to “No Activo” to prevent reuse.Workflow
Invoice Registration Process
The system follows this automated workflow when registering a new invoice:-
Validate Company
- System verifies the company exists by
idEmpresa - Returns error if company not found
- System verifies the company exists by
-
Generate Invoice Code
- Query database for the last invoice number
- Increment by 1
- Format as “F-XXX” (e.g., F-001, F-015, F-123)
-
Set Automatic Fields
fechaEmisionset to current dateenableset to “Activo”codFacturaassigned the generated code
-
Save Invoice
- Persist to database with all associations
- Return complete invoice object with generated ID
See Code Example: Invoice Registration
See Code Example: Invoice Registration
FacturaController.java:160-200Main API Endpoints
Invoice CRUD Operations
- Create Invoice
- Update Invoice
- Delete Invoice
fechaEmision, codFactura, and enable are automatically set by the system.Search and Filter Endpoints
- List All Invoices
- List Active Invoices
- Paginated List
- Search by Code
FacturaController.java:145-150Company-Specific Endpoints
List Invoices by Company
List Invoices by Company
idEmpresa- Company ID
FacturaController.java:87-109List Active Invoices by Company
List Active Invoices by Company
idEmpresa- Company ID
FacturaController.java:112-134Date Range Search
Search by Date Range
Search by Date Range
fechaEmision.Path Parameters:fechaInicio- Start date (yyyy-MM-dd)fechaFin- End date (yyyy-MM-dd)
FacturaController.java:45-60Invoice Status Lifecycle
Invoices move through the following status transitions:Created with Activo Status
New invoices are automatically set to “Activo” upon registration, making them available for use in investment opportunities.
Changed to No Activo
When an invoice is bundled into an investment opportunity, the system automatically changes its status to “No Activo” to prevent double-use.This happens in
OportunidadInversionController.java:228-234Use Cases
Use Case 1: Registering a New Invoice
Scenario: Company “TechCorp Solutions” completed a project and needs to register an invoice for factoring.- Admin verifies the company exists (idEmpresa = 5)
- Admin calls
POST /api/registrarFacturawith:monto: 15000.0fechaPago: 2026-06-30descripcion: “Q1 2026 professional services”empresa.idEmpresa: 5
- System:
- Queries last invoice number (41)
- Generates code “F-042”
- Sets
fechaEmisionto current date (2026-03-05) - Sets
enableto “Activo” - Saves invoice
- System returns complete invoice with ID 42 and code F-042
Use Case 2: Finding Available Invoices for an Opportunity
Scenario: Admin wants to create an investment opportunity using TechCorp’s invoices.- Admin calls
GET /api/facturas/activas/5 - System returns all invoices for company 5 with
enable= “Activo” - Admin sees invoice F-042 for $15,000 is available
- Admin uses
/api/addFacturato add F-042 to the opportunity bundle - When opportunity is created, F-042’s status changes to “No Activo”
Use Case 3: Tracking Invoices by Date Range
Scenario: Admin needs to generate a Q1 2026 invoice report.- Admin calls
GET /api/facturas/2026-01-01/2026-03-31 - System returns all invoices with
fechaEmisionin Q1 2026 - Admin can analyze:
- Total invoices registered: count
- Total amount: sum of
monto - Companies involved: unique
idEmpresavalues - Active vs. used: count by
enablestatus
Use Case 4: Updating Invoice Details
Scenario: Invoice F-042’s payment date needs to be extended.- Admin retrieves invoice:
GET /api/buscarfac/F-042 - Admin modifies the response, changing:
fechaPagofrom 2026-06-30 to 2026-07-15montofrom 15000.0 to 16500.0 (scope change)
- Admin calls
PUT /api/actualizarFacturawith updated data - System updates only modifiable fields, preserving:
codFactura(F-042)fechaEmision(2026-03-05)enable(current status)
Best Practices
Company Validation
Always verify the company exists before creating invoices to maintain data integrity.
Descriptive Notes
Use the descripcion field to provide context about the invoice for future reference.
Date Accuracy
Ensure fechaPago is realistic and allows sufficient time for investment opportunity funding.
Status Monitoring
Monitor invoice status transitions to understand which invoices are being used in active opportunities.
Integration Points
With Investment Opportunities
Invoices are the building blocks of investment opportunities:- Selection: Admin selects active invoices to bundle
- Linking: System creates
OportunidadFacturajunction records - Status Update: Invoice status changes to “No Activo” when bundled
- Tracking: Invoices can be queried by opportunity ID
With Company Management
Each invoice must be associated with a company:- Validation: Company existence verified during invoice creation
- Association: Foreign key relationship via
empresafield - Filtering: Invoices can be filtered by company for reporting
Error Handling
Common error scenarios and responses:| Scenario | HTTP Status | Response |
|---|---|---|
| Company not found | 404 NOT_FOUND | {"mensaje": "No se encontró la empresa con el id: X"} |
| Invoice not found | 404 NOT_FOUND | {"mensaje": "No se encontró la factura con el código: F-XXX"} |
| Update non-existent invoice | 409 CONFLICT | {"mensaje": "No existe factura con id: X"} |
| Database error | 500 INTERNAL_SERVER_ERROR | {"mensaje": "Error...", "error": "details..."} |
Related Features
- Investment Opportunities - Bundle invoices into investment products
- User Management - Control who can create and manage invoices