The Customers module (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ProyectoFerretek/FerreMarket/llms.txt
Use this file to discover all available pages before exploring further.
/clientes) maintains the client base for FerreMarket. It supports two distinct client types — natural persons and legal entities — each with its own set of required fields and tax identification. The module surfaces purchase history (count, total CLP spent, and last purchase date) derived live from the ventas table, and provides grid and table views with rich search and filter capabilities.
In Chile, RUN (Rol Único Nacional) is the national identity number assigned to natural persons (individuals), while RUT (Rol Único Tributario) is the tax identification number used by legal entities and businesses. FerreMarket stores these as separate fields (
run for individuals, rut for companies) to ensure invoicing and legal compliance. Both numbers follow the same format (XX.XXX.XXX-X) but are issued and administered separately.Customer Types
FerreMarket supports twotipoCliente values, each with a distinct form and data shape:
Individual (tipoCliente: 'individual')
| Field | Description |
|---|---|
nombre | First name |
apellidos | Last name(s) |
email | Contact email address |
telefono | Contact phone number |
direccion | Physical address |
run | RUN — Chilean national identity number for natural persons |
nombre + ' ' + apellidos when loaded from Supabase and displayed as a single full name throughout the UI.
Business (tipoCliente: 'empresa')
| Field | Description |
|---|---|
razonSocial | Legal company name (stored as razonsocial in Supabase) |
nombreComercial | Trading name (stored as nombre in Supabase) |
rut | RUT — Chilean tax ID for legal entities |
giro | Business activity category (industry/sector code) |
email | Corporate contact email |
telefono | Corporate contact phone number |
direccion | Registered business address |
Building2 icon in place of the initial letter avatar, and by a purple Empresa badge.
Cliente Interface
The fullCliente TypeScript interface from src/types/index.ts:
| Field | Type | Description |
|---|---|---|
id | string (optional) | Numeric Supabase primary key |
tipoCliente | string | 'individual' or 'empresa' |
estado | 'activo' | 'inactivo' | Account status |
nombre | string (optional) | Full name (individual) or trading name (company) |
apellidos | string (optional) | Surname — individual clients only |
email | string (optional) | Email address |
telefono | string (optional) | Phone number |
direccion | string (optional) | Physical address |
run | string (optional) | Individual tax ID |
rut | string (optional) | Business tax ID |
giro | string (optional) | Business activity — companies only |
razonSocial | string (optional) | Legal company name — companies only |
nombreComercial | string (optional) | Trading name — companies only |
notas | string (optional) | Free-text internal notes |
compras | number (optional) | Total number of sales transactions for this client |
totalCompras | number (optional) | Cumulative CLP value of all purchases |
ultimaCompra | string (optional) | ISO 8601 timestamp of the most recent purchase |
fechaCreacion | string (optional) | ISO 8601 timestamp of when the record was created |
ultimaModificacion | string (optional) | ISO 8601 timestamp of the last edit |
Adding Customers
Open the modal
Click the orange Nuevo Cliente button in the top-right header.
ClienteModal opens with the type selector defaulting to Individual.Select client type
Toggle between Individual and Empresa. The form fields update immediately to match the selected type — individual fields (nombre, apellidos, RUN) swap for company fields (razonSocial, nombreComercial, RUT, giro).
Customer Status
Each client has anestado field with two possible values:
| Estado | Badge | Behaviour |
|---|---|---|
activo | Green pill | Client appears in the VentaModal client selector and is available for new sales |
inactivo | Red pill | Client is excluded from the new-sale client dropdown and cannot be assigned to new transactions |
'activo' automatically when a client is created via agregarCliente.
Purchase History
Purchase statistics are calculated live from theventas table during obtenerClientes() and are not stored as columns on the clientes table. Each time the Customers page loads, two async calls are made per client:
| Stat | Function | Supabase query |
|---|---|---|
compras | obtenerCantidadComprasClientePorId(id) | COUNT(*) from ventas WHERE cliente = id |
totalCompras | obtenerTotalComprasClientePorId(id) | SUM(total) from ventas WHERE cliente = id |
ultimaCompra is a column on the clientes table that is updated to the current Santiago timestamp every time a new sale is created for that client via agregarVenta.
The Customers page also surfaces a quick VIP indicator in the stats row: clients with 10 or more purchases are counted separately as “VIP (10+ compras)”, and clients with a ultimaCompra within the last 30 days are counted as “Activos (30 días)”.
Editing and Deleting
Editing: Click the Editar button on a customer card or the pencil icon in the table actions row.ClienteModal opens pre-populated with the client’s current values. On save, actualizarCliente() is called.
Deleting:
Click the delete icon
Click the red Trash icon on a card or in the table row. The client is stored in
clienteSeleccionado and ConfirmDialog opens.Confirm deletion
The dialog reads: “¿Estás seguro de que deseas eliminar al cliente ‘[nombre]’? Esta acción no se puede deshacer.”
nombre, email, telefono, and identificacion simultaneously. The identificacion check is present in the client filter expression in Clientes.tsx, though it is not a named field on the Cliente TypeScript interface — it will evaluate to undefined for all client objects and therefore never matches.