Skip to main content

Overview

The inventory management system provides a comprehensive view of all products in your store. Browse through your entire catalog with advanced search and sorting capabilities, and manage products with full CRUD operations.
The inventory automatically displays real-time stock levels that are updated through the Stock Movements module.

Main Inventory View

The main inventory page (index.php) displays all products in a sortable, searchable table:

Dynamic Sorting

Click any column header to sort by ID, name, price, stock, category, size, or color

Multi-field Search

Search across product names, categories, colors, sizes, prices, and IDs simultaneously

Real-time Stock

View current stock levels with automatic updates from stock movements

Quick Actions

Edit or delete products directly from the inventory table

Database Query

The inventory view pulls data from multiple related tables:
$sql = "SELECT p.*, c.nombre as cat_nom, t.talla as talla_nom, col.nombre as color_nom 
        FROM prenda p
        JOIN categoria c ON p.id_categoria = c.id_categoria
        JOIN talla t ON p.id_talla = t.id_talla
        JOIN color col ON p.id_color = col.id_color";

Search Implementation

The search feature queries multiple fields simultaneously:
if (!empty($search)) {
    $sql .= " WHERE p.nombre LIKE :busqueda 
              OR c.nombre LIKE :busqueda 
              OR col.nombre LIKE :busqueda 
              OR t.talla LIKE :busqueda 
              OR p.precio LIKE :busqueda 
              OR p.id_prenda = :busqueda_exacta";
}
The search supports both partial matches (using LIKE) and exact ID lookups for precise filtering.

Sortable Columns

The inventory table supports sorting by the following columns:
ColumnDatabase FieldSort Type
IDp.id_prendaNumeric
Nombrep.nombreAlphabetic
Preciop.precioNumeric
Stockp.stock_actualNumeric
Categoríac.nombreAlphabetic
Tallat.tallaAlphabetic
Colorcol.nombreAlphabetic

Column Configuration

Allowed sortable columns are defined in a whitelist:
$columnas_permitidas = [
    'id' => 'p.id_prenda',
    'nombre' => 'p.nombre',
    'precio' => 'p.precio',
    'stock' => 'p.stock_actual',
    'categoria' => 'c.nombre',
    'talla' => 't.talla',
    'color' => 'col.nombre'
];

Sort Direction Toggle

The header link function maintains both search and sort state:
function getHeaderLink($col_key, $label, $current_sort, $current_order, $current_search) {
    $next_order = ($current_sort === $col_key && $current_order === 'ASC') ? 'desc' : 'asc';
    $icon = ($current_sort === $col_key) ? ($current_order === 'ASC' ? ' ▲' : ' ▼') : '';
    
    $url = "?sort={$col_key}&order={$next_order}";
    if (!empty($current_search)) {
        $url .= "&search=" . urlencode($current_search);
    }
    
    return "<a href='{$url}'>{$label}{$icon}</a>";
}

Search & Filter Workflow

1

Enter Search Term

Type a search query in the search box (e.g., “Camisa”, “Azul”, “M”, or a specific price)
2

Submit Search

Click “Buscar” to filter results. The current sort order is maintained during search.
3

View Results

The table displays all matching products. If no results are found, a friendly message appears.
4

Clear Search

Click “Limpiar” to reset and view the full inventory again.

Product Data Structure

Each product (prenda) contains the following fields:
CREATE TABLE `prenda` (
  `id_prenda` int(11) NOT NULL,
  `nombre` varchar(100) NOT NULL,
  `precio` decimal(10,2) NOT NULL,
  `stock_actual` int(11) DEFAULT 0,
  `id_categoria` int(11) NOT NULL,
  `id_talla` int(11) NOT NULL,
  `id_color` int(11) NOT NULL
);
  • id_prenda: Unique product identifier (auto-increment)
  • nombre: Product name (e.g., “Camisa Oxford Slim”)
  • precio: Current price in decimal format (10,2)
  • stock_actual: Real-time inventory count

Quick Actions

Each product row includes action buttons:

Edit Button

<a href='editar.php?id={$row['id_prenda']}' class='btn btn-sm btn-outline-warning'>
  Editar
</a>

Delete Button

<a href='eliminar.php?id={$row['id_prenda']}' 
   class='btn btn-sm btn-outline-danger' 
   onclick='return confirm("¿Eliminar?")'>
  Borrar
</a>
Deleting a product with associated records (stock movements, price updates) will fail due to foreign key constraints. This prevents orphaned data.

Empty State

When no products match the search criteria:
if ($stmt->rowCount() > 0) {
    // Display results
} else {
    echo "<tr><td colspan='8' class='text-center py-4 text-muted'>" .
         "No se encontraron prendas que coincidan con la búsqueda." .
         "</td></tr>";
}

Catalog Management

Manage categories, colors, and sizes used in inventory

Stock Movements

Track entries, exits, and adjustments that affect stock levels

Price Updates

View historical price changes for products

Build docs developers (and LLMs) love