Overview
The supplier management system (proveedores) enables you to maintain a comprehensive database of vendors and suppliers. Track contact information, payment terms, and associate suppliers with inventory status parameters for better procurement management.Key Features
- Complete supplier profile management
- Contact information tracking (email, phone, web)
- Payment terms configuration
- Status parameter integration
- Product association tracking
- Advanced search across multiple fields
- NIF/tax ID validation
Data Structure
| Field | Type | Required | Description |
|---|---|---|---|
id | Integer | Auto | Unique identifier |
nif | String | No | Tax ID / business registration number |
nombre | String | Yes | Supplier name |
contacto | String | No | Primary contact person |
email | String | No | Email address (validated format) |
telefono | String | No | Phone number |
direccion | String | No | Street address |
ciudad | String | No | City/location |
web | String | No | Website URL |
terminos | Integer | No | Payment terms in days |
parametro_id | Integer | No | Status parameter reference (FK) |
fecha_creacion | DateTime | Auto | Creation timestamp |
fecha_actualizacion | DateTime | Auto | Last update timestamp |
User Workflows
Creating a Supplier
Enter required information
Fill in at minimum the Nombre field (required). All other fields are optional.
Add contact details
Provide optional information:
- NIF: Tax identification number
- Contacto: Contact person name
- Email: Validated email format (e.g.,
[email protected]) - Teléfono: Phone number
- Dirección: Street address
- Ciudad: City or region
Configure business details
- Web: Supplier website URL
- Términos: Payment terms in days (e.g., 30, 60, 90)
- Estado: Select status parameter if applicable
The only required field is Nombre. All other fields are optional, allowing flexible data entry as information becomes available.
Editing a Supplier
Locate supplier
Use the search bar to filter by name, NIF, email, or city. Or browse the supplier cards.
Deleting a Supplier
Confirm deletion
A browser confirmation dialog appears: “¿Seguro que deseas eliminar este proveedor?”
Click OK to proceed.
Searching Suppliers
The search feature filters across multiple fields:- Type supplier name, tax ID, email, or city
- Results update in real-time as you type
- Search is case-insensitive
- Clear search to show all suppliers
Status Parameters Integration
Suppliers can be assigned status parameters for classification:Loading Parameters
Source:proveedores.js:61-76
Parameter Display
Source:proveedores.js:131-141
Supplier cards display the status with parameter color:
The badge color comes from the associated parameter. Text color is calculated based on background luminance for optimal contrast.
Parameter Selection
The status dropdown is populated with all parameters:API Reference
Get All Suppliers
- Request
- Response
Create Supplier
- Request
- Success Response
- Error Response (Missing Name)
- Error Response (Invalid Email)
Update Supplier
- Request
- Success Response
Delete Supplier
- Request
- Success Response
Validation Rules
Nombre Validation
Nombre Validation
Required FieldBackend:
- Cannot be empty
- Validated on both frontend and backend
- Trimmed of leading/trailing whitespace
proveedores.js:224proveedores.php:44Email Validation
Email Validation
Optional but ValidatedIf email is provided, it must match the pattern: Examples:
\S+@\S+\.\S+Frontend: proveedores.js:225- ✅
[email protected] - ✅
[email protected] - ❌
invalid-email - ❌
missing@domain
Términos Validation
Términos Validation
Payment Terms Processing
- Stored as integer (days)
nullif not provided- Frontend parses to integer:
parseInt(provTerminos.value, 10) - Backend stores as SQL
NULLor integer value
proveedores.php:41,46Parameter ID Validation
Parameter ID Validation
Status Parameter Reference
- Optional field
- Must reference valid
parametros.idif provided nullif no status assigned- Joined with parameters table on GET for display
proveedores.php:17-22UI Components
Supplier Card
Each supplier is displayed as a card: Structure:- Header: Supplier name and status badge
- Body: All contact and business information
- Footer: Product count (currently shows 0)
- Actions: Edit and delete buttons (top-right corner)
proveedores.js:130-155
Status Badge Color Calculation
Source:proveedores.js:260-267
The badge uses smart text color based on background luminance:
Empty State
When no suppliers exist:Technical Implementation
Frontend (proveedores.js)
Key Functions:cargarParametrosEstado()- Loads status parameters (line 61)cargarProveedores()- Fetches all suppliers with JOIN data (line 79)crearProveedor(body)- POST new supplier (line 96)actualizarProveedor(id, body)- PUT update (line 101)eliminarProveedor(id)- DELETE with confirmation (line 106)filtrarProveedores()- Multi-field search (line 158)editarProveedor(id)- Populates edit form (line 182)
Backend (proveedores.php)
Database Table:proveedores
Key Operations:
- Line 16-27: GET with LEFT JOIN to parameters table
- Line 30-54: POST - Creates supplier with null handling
- Line 57-83: PUT - Updates supplier by ID
- Line 86-96: DELETE - Removes supplier (no cascade protection)
The backend does not validate foreign key integrity for
parametro_id. Ensure the parameter exists before assigning it to a supplier.Best Practices
Complete Profiles
Fill in as much supplier information as possible for better vendor management
Valid Emails
Use proper email format for automated communications and notifications
Payment Terms
Document payment terms to track cash flow and vendor agreements
Status Tracking
Use parameters to track supplier status (active, preferred, discontinued, etc.)
Search Optimization
Use consistent naming in ciudad field for location-based filtering
Regular Updates
Keep contact information current for effective communication
Common Error Messages
| Error Message | Cause | Solution |
|---|---|---|
| ”El nombre es obligatorio” | Empty nombre field | Enter supplier name |
| ”Correo inválido” | Email doesn’t match pattern | Use format: [email protected] |
| ”Error de conexión” | Network or server issue | Check connection and retry |
| ”Datos inválidos” | Invalid JSON payload | Check request format |
| ”ID inválido” | Missing or invalid ID on update/delete | Provide valid supplier ID |
Future Enhancements
Based on the code structure, potential improvements include:- Product Count: Implement actual COUNT query for
productos_count(currently hardcoded to 0) - Deletion Protection: Add cascade check to prevent deleting suppliers with products
- NIF Validation: Add format validation for tax ID numbers
- Duplicate Detection: Check for duplicate NIF or email before creation
- Contact History: Track communication history with suppliers
- Document Attachments: Link contracts and agreements to supplier records