Documentation Index
Fetch the complete documentation index at: https://mintlify.com/obando1998/Proyecto_UCP/llms.txt
Use this file to discover all available pages before exploring further.
ConsultaModel
Models/ConsultaModel.php
The ConsultaModel provides read-only database access for querying the return history. Itβs used by ConsultaController to retrieve historical return records and individual return details.
Overview
- Purpose: Query return history from devoluciones table
- Database Table:
devoluciones - Connection: PDO via
Conexion::Conectar() - Operations: Read-only (SELECT queries)
Class Structure
ConsultaModel.php
Methods
__construct()
Initializes database connection using the PDO singleton pattern. Behavior:Config/Conexion.php.
obtenerHistorial()
Retrieves a limited list of recent return records, ordered by creation date.Maximum number of records to return. Uses PDO::PARAM_INT for type safety.
[] on error.
Return Record Structure:
Each record contains all fields from the devoluciones table:
Auto-increment primary key
Customer tax ID (VARCHAR 20)
Customer name (VARCHAR 255)
Customer address (TEXT)
Product SKU or code (VARCHAR 50)
Product description (TEXT)
Unit of measure (VARCHAR 20)
Weight in kilograms (DECIMAL 10,2)
Return reason: βdevolucionβ, βfaltanteβ, or βsobranteβ (ENUM)
Quantity in units (INT)
Quantity in kilograms (DECIMAL 10,2)
Path to uploaded evidence file (VARCHAR 255, nullable)
User observations (TEXT)
Current status: βpendienteβ, βaprobadoβ, or βrechazadoβ (ENUM, default βpendienteβ)
Administrator review notes (TEXT, nullable)
Authorization code from admin (VARCHAR 50, nullable)
Record creation timestamp (TIMESTAMP, defaults to CURRENT_TIMESTAMP)
Review/approval timestamp (TIMESTAMP, nullable)
Username who created the return (VARCHAR 50, references usuarios.USR)
Username who reviewed the return (VARCHAR 50, nullable)
obtenerPorId()
Retrieves a single return record by its unique ID.Primary key of the return record to retrieve
false if not found.
Return Structure:
Same fields as obtenerHistorial() - see above for complete field list.
SQL Query:
This method does NOT use try-catch error handling like
obtenerHistorial(). If the query fails, PDO will throw an exception that must be caught by the calling code.Usage Examples
Retrieve Recent History (Default Limit)
Retrieve Last 50 Returns
Get Specific Return Details
Integration Points
ConsultaController
ConsultaController uses this model for all history queries:AdminController
AdminController also uses ConsultaModel for viewing history:Performance Considerations
Current Limitations
- SELECT * queries: Retrieves all columns even if not needed
- No pagination: Only LIMIT, no OFFSET support for pagination
- No filtering: Cannot filter by status, date range, or user
- No sorting options: Always sorts by fecha_creacion DESC
Recommended Enhancements
Add Pagination Support
Add Pagination Support
Add Filtering Options
Add Filtering Options
Add Count Method
Add Count Method
Comparison with DevolucionModel
| Feature | ConsultaModel | DevolucionModel |
|---|---|---|
| Purpose | Read-only queries | Full CRUD operations |
| Methods | obtenerHistorial(), obtenerPorId() | guardar(), obtenerPendientes(), procesarRevision(), obtenerEstadisticas() |
| Filtering | None (all records) | By status (estado = 'Pendiente') |
| Statistics | No | Yes (obtenerEstadisticas()) |
| Write Operations | No | Yes (INSERT, UPDATE) |
| Used By | ConsultaController, AdminController | PanelController, AdminController, HomeController |
Related Components
- ConsultaController - Uses this model for history views
- DevolucionModel - Full-featured return management model
- Database Schema - Complete devoluciones table structure