Overview
The warehouse management system allows you to create and manage multiple storage locations (bodegas) for organizing your inventory. Each warehouse has a unique name and optional description to help you track products across different physical locations.Key Features
- Create and manage multiple warehouses
- Search and filter warehouses by name or description
- Track products associated with each warehouse
- Real-time statistics and counts
- Validation to prevent deletion of warehouses with products
Data Structure
Each warehouse contains the following fields:| Field | Type | Required | Max Length | Description |
|---|---|---|---|---|
id | Integer | Auto | - | Unique identifier |
nombre | String | Yes | 100 chars | Warehouse name (must be unique) |
descripcion | String | No | - | Optional description |
fecha_creacion | DateTime | Auto | - | Creation timestamp |
fecha_actualizacion | DateTime | Auto | - | Last update timestamp |
User Workflows
Creating a Warehouse
Open the create dialog
Click the Nueva Bodega button in the top-right corner of the warehouse management page.
Enter warehouse details
Fill in the required fields:
- Nombre (required): A unique name for the warehouse
- Descripción (optional): Additional details about the warehouse location
Warehouse names must be unique. If you try to create a warehouse with an existing name, you’ll receive an error message.
Editing a Warehouse
Update details
Modify the name or description as needed. The same validation rules apply as when creating.
Deleting a Warehouse
Confirm deletion
A confirmation modal will display the warehouse name. Review carefully and click Confirmar to proceed.
Searching Warehouses
The search feature filters warehouses in real-time:- Type in the search input at the top of the page
- Results filter by name or description
- Search is case-insensitive
- Clear the search to show all warehouses
API Reference
The warehouse API endpoint is located at:Get All Warehouses
- Request
- Response
Create Warehouse
- Request
- Success Response
- Error Response
Update Warehouse
- Request
- Success Response
Delete Warehouse
- Request
- Success Response
- Error Response (Has Products)
Validation Rules
The system enforces the following validation rules:Name Validation
Name Validation
- Required: Cannot be empty
- Max Length: 100 characters
- Uniqueness: Must be unique across all warehouses
- Whitespace: Leading and trailing spaces are automatically trimmed
Description Validation
Description Validation
- Optional: Can be left empty
- No Length Limit: Backend doesn’t enforce a character limit
- Whitespace: Leading and trailing spaces are automatically trimmed
Deletion Validation
Deletion Validation
- Product Check: Automatically counts associated products
- Blocked if Products Exist: Cannot delete if
COUNT(productos) > 0 - Error Message: Shows exact count of blocking products
UI Components
Warehouse Card
Each warehouse is displayed as a card showing:- Header: Warehouse name
- Details: Description (if provided)
- Actions: Edit and Delete buttons
- Visual: Warehouse icon for easy identification
Empty State
When no warehouses exist, the system displays:Statistics
The page header shows:- Total Warehouses: Real-time count of all warehouses in the system
Best Practices
Use Descriptive Names
Choose clear, unique names that identify the physical location (e.g., “Main Warehouse”, “North Storage”, “Retail Floor”)
Add Descriptions
Include location details, capacity info, or usage notes in the description field
Plan Before Deleting
Always check product associations before attempting to delete a warehouse
Regular Audits
Periodically review your warehouse list and remove unused locations
Technical Implementation
Frontend (bodega.js)
Key Functions:cargarBodegas()- Fetches all warehouses from the API (line 87)crearBodega(datos)- Creates new warehouse (line 106)actualizarBodega(id, datos)- Updates existing warehouse (line 131)eliminarBodega()- Deletes warehouse after validation (line 156)filtrarBodegas()- Real-time search filtering (line 247)
Backend (bodega.php)
Database Table:bodegas
Key Operations:
- Line 23: SELECT with DESC ordering for recent-first display
- Line 77: Unique name validation check
- Line 89: INSERT with automatic timestamp
- Line 165: Delete validation - checks producto count
- Line 236: Foreign key relationship check with productos table
The API uses cache-busting with
?_=${Date.now()} to ensure fresh data on every request.Common Error Messages
| Error Message | Cause | Solution |
|---|---|---|
| ”El nombre es obligatorio” | Empty name field | Provide a warehouse name |
| ”El nombre no puede superar 100 caracteres” | Name too long | Shorten the warehouse name |
| ”Ya existe una bodega con este nombre” | Duplicate name | Choose a unique name |
| ”Bodega no encontrada” | Invalid ID on update/delete | Refresh the page and try again |
| ”No se puede eliminar. Tiene X producto(s) asociado(s)“ | Products exist | Reassign or delete products first |
| ”Error de conexión” | Network or server issue | Check connection and try again |