The inventory management system uses a MySQL database named bd_inventario with three main tables that handle user authentication, product management, and inventory movements.
CREATE TABLE usuarios ( id INT AUTO_INCREMENT PRIMARY KEY, nombre VARCHAR(100) NOT NULL, correo VARCHAR(100) UNIQUE NOT NULL, contraseña VARCHAR(255) NOT NULL, rol ENUM('Admin', 'Empleado') DEFAULT 'Empleado', fecha_registro TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
Columns:
id - Primary key, auto-incremented user identifier
nombre - User’s full name
correo - Email address (unique, used for login)
contraseña - Password (currently stored in plain text)
The current implementation stores passwords in plain text and uses direct password comparison. This should be upgraded to use password_hash() and password_verify() for production use.
Manages the product catalog with pricing and stock information.
Table Structure
CREATE TABLE productos ( id INT AUTO_INCREMENT PRIMARY KEY, nombre VARCHAR(200) NOT NULL, codigo VARCHAR(50) UNIQUE NOT NULL, precio DECIMAL(10,2) NOT NULL DEFAULT 0.00, stock INT NOT NULL DEFAULT 0, fecha_creacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
Columns:
id - Primary key, auto-incremented product identifier
nombre - Product name
codigo - Unique product code/SKU
precio - Product price (decimal with 2 decimal places)
stock - Current stock quantity (updated by movimientos)
$conn->query("UPDATE productos SET nombre='$nombre', codigo='$codigo', precio='$precio' WHERE id=$id");
Delete (productos/eliminar.php:7):
$conn->query("DELETE FROM productos WHERE id=$id");
Stock Updates (automated by movimientos):
// EntradaUPDATE productos SET stock = stock + $cantidad WHERE id = $producto_id// SalidaUPDATE productos SET stock = stock - $cantidad WHERE id = $producto_id
Tracks all inventory movements (entries and exits) with automatic stock updates.
Table Structure
CREATE TABLE movimientos ( id INT AUTO_INCREMENT PRIMARY KEY, producto_id INT NOT NULL, tipo ENUM('entrada', 'salida') NOT NULL, cantidad INT NOT NULL, fecha TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (producto_id) REFERENCES productos(id) ON DELETE CASCADE);
Columns:
id - Primary key, auto-incremented movement identifier
CREATE DATABASE bd_inventario CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;USE bd_inventario;-- Create usuarios tableCREATE TABLE usuarios ( id INT AUTO_INCREMENT PRIMARY KEY, nombre VARCHAR(100) NOT NULL, correo VARCHAR(100) UNIQUE NOT NULL, contraseña VARCHAR(255) NOT NULL, rol ENUM('admin', 'usuario') DEFAULT 'usuario', fecha_registro TIMESTAMP DEFAULT CURRENT_TIMESTAMP);-- Create productos tableCREATE TABLE productos ( id INT AUTO_INCREMENT PRIMARY KEY, nombre VARCHAR(200) NOT NULL, codigo VARCHAR(50) UNIQUE NOT NULL, precio DECIMAL(10,2) NOT NULL DEFAULT 0.00, stock INT NOT NULL DEFAULT 0, fecha_creacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP);-- Create movimientos tableCREATE TABLE movimientos ( id INT AUTO_INCREMENT PRIMARY KEY, producto_id INT NOT NULL, tipo ENUM('entrada', 'salida') NOT NULL, cantidad INT NOT NULL, fecha TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (producto_id) REFERENCES productos(id) ON DELETE CASCADE);-- Insert test userINSERT INTO usuarios (nombre, correo, contraseña, rol) VALUES ('Admin', '[email protected]', 'admin123', 'Admin');