Skip to main content

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:
FieldTypeRequiredMax LengthDescription
idIntegerAuto-Unique identifier
nombreStringYes100 charsWarehouse name (must be unique)
descripcionStringNo-Optional description
fecha_creacionDateTimeAuto-Creation timestamp
fecha_actualizacionDateTimeAuto-Last update timestamp

User Workflows

Creating a Warehouse

1

Open the create dialog

Click the Nueva Bodega button in the top-right corner of the warehouse management page.
2

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
3

Save the warehouse

Click Guardar to create the warehouse. The system will validate:
  • Name is not empty
  • Name doesn’t exceed 100 characters
  • Name is unique across all warehouses
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

1

Locate the warehouse

Use the search bar to filter warehouses or browse the list of warehouse cards.
2

Open edit mode

Click the Editar button on the warehouse card you want to modify.
3

Update details

Modify the name or description as needed. The same validation rules apply as when creating.
4

Save changes

Click Guardar to update the warehouse information.

Deleting a Warehouse

You cannot delete a warehouse that has products associated with it. You must first reassign or remove all products before deletion.
1

Select warehouse

Click the Eliminar button on the warehouse card you want to remove.
2

Confirm deletion

A confirmation modal will display the warehouse name. Review carefully and click Confirmar to proceed.
3

Validation check

The system checks for associated products:
  • If products exist, deletion is blocked with an error message showing the count
  • If no products exist, the warehouse is permanently deleted

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    /database/bodega.php      # List all warehouses
POST   /database/bodega.php      # Create new warehouse
PUT    /database/bodega.php      # Update warehouse
DELETE /database/bodega.php      # Delete warehouse (if no products)

Get All Warehouses

const response = await fetch('database/bodega.php?_=' + Date.now(), {
  cache: 'no-store'
});

Create Warehouse

const response = await fetch('database/bodega.php', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    nombre: 'Nueva Bodega',
    descripcion: 'Descripción opcional'
  })
});

Update Warehouse

const response = await fetch('database/bodega.php', {
  method: 'PUT',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    id: 1,
    nombre: 'Bodega Actualizada',
    descripcion: 'Nueva descripción'
  })
});

Delete Warehouse

const response = await fetch('database/bodega.php', {
  method: 'DELETE',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ id: 1 })
});

Validation Rules

The system enforces the following validation rules:
  • Required: Cannot be empty
  • Max Length: 100 characters
  • Uniqueness: Must be unique across all warehouses
  • Whitespace: Leading and trailing spaces are automatically trimmed
  • Optional: Can be left empty
  • No Length Limit: Backend doesn’t enforce a character limit
  • Whitespace: Leading and trailing spaces are automatically trimmed
  • 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:
┌─────────────────────────────┐
│     📦 Warehouse Icon       │
│                             │
│  No hay bodegas registradas │
│ Comienza creando tu primera │
│          bodega             │
└─────────────────────────────┘

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 MessageCauseSolution
”El nombre es obligatorio”Empty name fieldProvide a warehouse name
”El nombre no puede superar 100 caracteres”Name too longShorten the warehouse name
”Ya existe una bodega con este nombre”Duplicate nameChoose a unique name
”Bodega no encontrada”Invalid ID on update/deleteRefresh the page and try again
”No se puede eliminar. Tiene X producto(s) asociado(s)“Products existReassign or delete products first
”Error de conexión”Network or server issueCheck connection and try again

Build docs developers (and LLMs) love