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.
Overview
TheDevolucionModel class handles all database operations related to product returns and deviations. It manages the complete lifecycle from initial registration by auxiliary users to review and approval by administrators, and provides statistical data for the dashboard.
Database Table: devoluciones
Key Responsibilities:
- Register new product returns with customer and product information
- Retrieve pending returns for administrative review
- Process approval/rejection decisions with admin codes
- Generate statistics by date and status
- Provide available dates for filtering
Constructor
Conexion::Conectar().
Methods
guardar()
devoluciones table. This method is used by auxiliary users to register returns, shortages, or overages.
Associative array containing all return information:
Customer tax identification number
Customer name
Customer delivery address
Product item code (references
producto.item)Product description
Unit of measurement (e.g., “Paquete”, “Caja”)
Weight per unit in kilograms
Reason code: “Devolucion”, “Faltante”, or “Sobrante”
Quantity in units
Total weight in kilograms
Auxiliary user observations
Username of the auxiliary user creating the record
Base64-encoded image or file path for evidence (optional)
bool - true on successful insertion, false on failure
Automatic Fields:
estadois set to"Pendiente"by defaultfecha_creacionis set toNOW()timestamp
The
evidencia field supports null values using the null coalescing operator (??). If no evidence is provided, it will be stored as NULL in the database.obtenerPendientes()
estado = 'Pendiente' status, ordered by creation date (oldest first). This method is used by administrators to view returns awaiting review.
Returns: array - Array of associative arrays containing all columns from the devoluciones table
Returned Fields:
id- Primary keynit,nombre_cliente,direccion- Customer informationitem_producto,descripcion_producto,unidad,kg- Product detailsmotivo- Reason code (Devolucion/Faltante/Sobrante)cantidad_und,cantidad_kg- Quantitiesobservacion- Auxiliary observationsusuario_creador- Creator usernameestado- Will be “Pendiente”fecha_creacion- Creation timestampevidencia- Evidence datacodigo_admin,observacion_admin,usuario_revisor,fecha_revision- Admin fields (will be NULL)
procesarRevision()
Primary key of the return record to process
Administrative decision:
"Aprobado" or "Rechazado"Administrative code assigned to this return (e.g., “DEV-2024-001”)
Administrator observations or rejection reason
Username of the administrator processing the review
bool - true on successful update with commit, false on failure with rollback
Transaction Behavior:
- Begins database transaction before update
- Commits on success
- Rolls back on exception
estado- Set to $accion valuecodigo_admin- Set to $codigoobservacion_admin- Set to $obsusuario_revisor- Set to $revisorfecha_revision- Set toNOW()
Optional Feature: Notifications
Optional Feature: Notifications
The code includes a commented placeholder for creating notifications:This allows future implementation of a notification system to alert auxiliary users when their returns are reviewed.
obtenerEstadisticas()
Optional date filter in
YYYY-MM-DD format. If null, returns statistics for all records.array - Associative array with the following keys:
Total number of return records
Sum of all
cantidad_kg values (0 if no records)Sum of all
cantidad_und values (0 if no records)Count of records with
estado = 'Pendiente'Count of records with
estado = 'Aprobado'Count of records with
estado = 'Rechazado'Count of records with
motivo = 'Devolucion'Count of records with
motivo = 'Faltante'Count of records with
motivo = 'Sobrante'Uses
COALESCE() to ensure numeric fields return 0 instead of NULL when no records match. This prevents null pointer issues in dashboard calculations.obtenerFechas()
array - Indexed array of date strings in YYYY-MM-DD format
Database Schema
Table:devoluciones
| Column | Type | Description |
|---|---|---|
id | INT (PK, AUTO_INCREMENT) | Primary key |
nit | VARCHAR | Customer tax ID |
nombre_cliente | VARCHAR | Customer name |
direccion | VARCHAR | Delivery address |
item_producto | VARCHAR | Product item code |
descripcion_producto | VARCHAR | Product description |
unidad | VARCHAR | Unit of measurement |
kg | DECIMAL | Weight per unit |
motivo | VARCHAR | Devolucion/Faltante/Sobrante |
cantidad_und | INT | Quantity in units |
cantidad_kg | DECIMAL | Total weight |
observacion | TEXT | Auxiliary observations |
usuario_creador | VARCHAR | Creating user |
estado | VARCHAR | Pendiente/Aprobado/Rechazado |
fecha_creacion | DATETIME | Creation timestamp |
evidencia | TEXT | Evidence data |
codigo_admin | VARCHAR | Admin code |
observacion_admin | TEXT | Admin observations |
usuario_revisor | VARCHAR | Reviewing admin |
fecha_revision | DATETIME | Review timestamp |
State Machine
Related Models
- ProductoModel - Product catalog integration
- UsuarioModel - User management for creators and reviewers