Overview
The product management system serves as the core of Pro Stock Tool’s inventory tracking capabilities. While the source code doesn’t include a dedicatedproductos.js controller, the database schema and related modules reveal a comprehensive product tracking system integrated with warehouses, categories, suppliers, and status parameters.
Key Features
- Centralized product database
- Integration with warehouses (bodegas)
- Category and subcategory classification
- Supplier association
- Status parameter tracking
- Product count tracking across all modules
- Foreign key relationships for data integrity
Data Structure
Based on the integration points in the source code, products have the following relationships:Product Fields
| Field | Type | Description | Reference |
|---|---|---|---|
id | Integer | Unique product identifier | Auto-generated |
bodega_id | Integer | Warehouse location | FK to bodegas table |
categoria_id | Integer | Product category | FK to categorias table |
subcategoria_id | Integer | Product subcategory | FK to subcategorias table |
proveedor_id | Integer | Supplier reference | FK to proveedores table |
parametro_id | Integer | Product status | FK to parametros table |
The products table uses flexible foreign key naming. The system checks for multiple column name variants:
categoria_id, id_categoria, categoria, or categoriaId.Integration Points
Products are integrated throughout the system:Warehouse Integration
Source Reference:bodega.php:236-249
Before deleting a warehouse, the system checks:
Category Integration
Source Reference:categorias.php:256-289
The category system uses dynamic FK detection:
Supplier Integration
Source Reference:proveedores.php:20
Suppliers track product counts:
proveedores.js:153
Status Parameter Integration
Source Reference:parametros.php:16-27
Parameters track which products use each status:
parametros.php:98-101
Expected Product Workflows
While the dedicated product controller isn’t in the provided source, we can infer the workflows from the system architecture:Creating a Product
Updating Product Location
Products can be moved between warehouses by updating the
bodega_id field. This enables inventory transfers and location tracking.Deleting Products
Products should be deletable without constraints from other tables, as all foreign keys point FROM products TO other entities (not vice versa).Product Counts and Statistics
The system tracks product counts across multiple dimensions:By Warehouse
By Category
By Supplier
By Status Parameter
Only the parameters module currently implements live product counting via SQL JOIN. Other modules have the UI prepared but show static counts.
Database Schema Relationships
Validation and Constraints
Based on the related modules, products enforce:Referential Integrity
Referential Integrity
- Warehouse: Must reference valid
bodegas.id - Category: Must reference valid
categorias.id - Supplier: Must reference valid
proveedores.id - Status: Must reference valid
parametros.id - Protection: Parent records cannot be deleted while products exist
Orphan Prevention
Orphan Prevention
The system prevents orphaned products by:
- Blocking warehouse deletion if products exist
- Blocking category deletion if products exist
- Blocking parameter deletion if products exist
- Showing exact count of blocking products in error messages
Flexible Schema
Flexible Schema
- Column Detection: Supports multiple FK naming conventions
- Null Handling: Some fields may be optional (implementation-dependent)
- Table Existence: Checks if productos table exists before validation
API Patterns
Based on the consistent patterns across all modules, the products API likely follows:Expected GET Response
Expected CREATE Request
UI Components
Based on the consistent UI patterns across modules, products likely use:Product Cards or Table Rows
Showing:- Product name and SKU
- Warehouse badge with color
- Category badge with color
- Supplier name
- Status badge with parameter color
- Stock quantity
- Edit and delete actions
Filtering and Search
Status Badges
Using parameter colors for visual status indication:Best Practices
Complete Classification
Always assign warehouse, category, and status to products for proper organization
Supplier Tracking
Link products to suppliers for better procurement and vendor management
Status Updates
Use status parameters to track product lifecycle (active, discontinued, etc.)
Warehouse Transfers
Update bodega_id when moving products between locations
Category Hierarchy
Utilize both category and subcategory for granular classification
Data Integrity
Ensure all foreign keys reference existing records before saving
Technical Notes
Foreign Key Detection
Source:categorias.php:264-273
The system uses intelligent FK detection:
Count Aggregation
Source:parametros.php:18-22
Example of proper product counting:
Cache Busting
All modules use timestamp-based cache busting:Common Error Messages
| Error Message | Cause | Solution |
|---|---|---|
| ”Bodega no encontrada” | Invalid warehouse ID | Select a valid warehouse |
| ”Categoría no encontrada” | Invalid category ID | Select an existing category |
| ”Proveedor no encontrado” | Invalid supplier ID | Choose a valid supplier |
| ”Parámetro no encontrado” | Invalid status ID | Select an active parameter |
| ”No se puede eliminar bodega: tiene productos” | Deleting warehouse with products | Reassign products first |
| ”No se puede eliminar categoría: tiene productos” | Deleting category with products | Recategorize products first |
| ”No se puede eliminar parámetro: tiene productos” | Deleting status with products | Update product statuses first |