Overview
Themovimiento_stock table is the core transactional table for inventory management. It maintains a complete audit trail of all stock movements including receipts (entrada), sales/dispatches (salida), and inventory adjustments (ajuste). Each record creates an immutable history of quantity changes linked to specific products and employees.
Table Name: movimiento_stockEngine: InnoDB
Character Set: utf8mb4
Primary Key:
id_movimiento
Table Structure
Column Definitions
Primary key identifier for the stock movement. Auto-increments on insert.
Timestamp of when the movement occurred. Automatically set to current timestamp on insert.
Type of stock movement. Valid values:
"entrada"- Stock entry (receiving inventory)"salida"- Stock exit (sales, shipments)"ajuste"- Stock adjustment (corrections, damage, loss)
Quantity of units moved. Can be positive or negative:
- Positive: Adds to stock (entrada, or positive ajuste)
- Negative: Reduces stock (salida, or negative ajuste)
Foreign key reference to
prenda.id_prenda. Identifies which product was moved.Foreign key reference to
empleado.id_empleado. Records which employee performed the movement.CREATE TABLE Statement
Indexes
| Index Name | Type | Columns | Purpose |
|---|---|---|---|
PRIMARY | PRIMARY KEY | id_movimiento | Unique identifier |
fk_mov_prenda | INDEX | id_prenda | Foreign key lookup for products |
fk_mov_emp | INDEX | id_empleado | Foreign key lookup for employees |
idx_movimiento_fecha | INDEX | fecha | Temporal queries and date-range filtering |
Foreign Key Relationships
Parent Tables (Referenced)
prenda
Constraint:
Column:
Links movement to specific product
fk_mov_prendaColumn:
id_prenda → prenda.id_prendaLinks movement to specific product
empleado
Constraint:
Column:
Tracks employee who performed movement
fk_mov_empColumn:
id_empleado → empleado.id_empleadoTracks employee who performed movement
Sample Data
Movement Type Examples
Entrada (Stock Entry)
Example: ID 1 - 10 units of product 1 received by employee 2
Use Cases: Supplier deliveries, returns from customers, transfers from other locations
Effect: Increases
Use Cases: Supplier deliveries, returns from customers, transfers from other locations
Effect: Increases
prenda.stock_actualSalida (Stock Exit)
Example: ID 2 - 5 units of product 2 dispatched by employee 3
Use Cases: Customer sales, transfers to other locations, shipments
Effect: Decreases
Use Cases: Customer sales, transfers to other locations, shipments
Effect: Decreases
prenda.stock_actualAjuste (Stock Adjustment)
Example: ID 3 - Negative adjustment of 2 units on product 3 by manager (employee 1)
Use Cases: Inventory corrections, damaged goods, theft/loss, cycle count adjustments
Effect: Can increase or decrease
Use Cases: Inventory corrections, damaged goods, theft/loss, cycle count adjustments
Effect: Can increase or decrease
prenda.stock_actual (based on quantity sign)Movement Types
Entrada (Entry)
- Purpose: Record incoming inventory
- Quantity: Always positive
- Common Scenarios:
- Receiving supplier shipments
- Customer returns
- Inter-location transfers (receiving end)
- Employee Role: Typically staff (empleado)
Salida (Exit)
- Purpose: Record outgoing inventory
- Quantity: Positive value representing units leaving
- Common Scenarios:
- Customer purchases
- Inter-location transfers (sending end)
- Waste/disposal
- Employee Role: Mix of staff and managers
Ajuste (Adjustment)
- Purpose: Correct inventory discrepancies
- Quantity: Can be positive (increase) or negative (decrease)
- Common Scenarios:
- Physical inventory counts
- Damage or spoilage
- Theft or loss
- Data entry corrections
- Employee Role: Typically managers (gerente)
Common Queries
Recent Stock Movements
Movement Summary by Type
Product Movement History
Daily Movement Report
Employee Activity Report
Stock Movement Timeline for Product
Movements by Date Range and Type
Business Rules
Adjustment Authorization: Typically only managers (
puesto = 'gerente') should be authorized to create ajuste movements, as they represent inventory corrections.