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.
src/utils/formatters.ts provides pure functions used across every module for consistent display of prices, dates, client names, sale states, and inventory values. None of these functions perform any I/O — they take plain values and return formatted strings or numbers, making them safe to call anywhere in the render tree without side effects.
formatPrecio
Intl.NumberFormat API with the es-CL locale. The formatter is configured with style: 'currency', currency: 'CLP', and maximumFractionDigits: 0, so decimal cents are never displayed. The result matches the currency notation used on Chilean receipts and price tags (e.g. $15.000).
The raw numeric price or amount to format. Must be a finite number. Negative values are formatted with a leading minus sign:
formatPrecio(-5000) → '-$5.000'.string — the value rendered as a CLP currency string.
formatFecha
incluirHora is false (the default) the output uses a DD/MM/YYYY pattern. When incluirHora is true the output includes hours and minutes as DD/MM/YYYY HH:mm. Any falsy, empty, or unparseable input returns the sentinel string 'Sin fecha registrada' instead of throwing.
An ISO 8601 date string such as
'2025-06-15' or '2025-06-15T10:30:00'. Passing an empty string or a string that cannot be parsed by new Date() causes the function to return 'Sin fecha registrada'.When
true, the formatted output appends the time component (HH:mm). Defaults to false.string — a locale-formatted date string, or 'Sin fecha registrada' for invalid inputs.
getNombreCliente
Number(c.id) === Number(clienteId) so that string/number type mismatches between the stored ID and the passed argument are handled gracefully. If no matching client is found the function returns 'Cliente no encontrado'.
This function is used throughout the Sales module to resolve a raw clienteId foreign-key value into a readable name without making additional network requests.
The ID of the client to look up. Can be a numeric string (e.g.
'42'); the function coerces it to a number for the comparison.The full array of client objects already loaded into component state. Each element is expected to have at least
id and nombre properties.string — cliente.nombre when a match is found, or 'Cliente no encontrado' otherwise.
getEstadoVenta
The raw state value as stored in the database. Recognised values are
'completada', 'pendiente', and 'cancelada' (lowercase). Any unrecognised value falls through to the default case and is rendered with neutral grey classes.{ label: string; color: string } — an object whose label is the Spanish display string and color is a space-separated pair of Tailwind background and text colour classes.
estado | label | color |
|---|---|---|
completada | Completada | bg-green-100 text-green-800 |
pendiente | Pendiente | bg-yellow-100 text-yellow-800 |
cancelada | Cancelada | bg-red-100 text-red-800 |
| (any other) | (as-is) | bg-gray-100 text-gray-800 |
calcularValorInventario
producto.precio * producto.stock for every element. This is a synchronous, pure computation used on the Reportes page to display the current inventory valuation without any additional network calls.
An array of product objects already loaded into memory. Each element must have
precio (unit price as a number) and stock (quantity on hand as a number). Elements where either field is undefined or NaN will contribute NaN to the total; ensure the input is clean before calling this function.number — the total inventory value. Returns 0 for an empty array.
There are two functions named
calcularValorInventario in this codebase with different signatures and execution models:src/utils/formatters.ts— the synchronous version documented here. It receives a pre-loadedproductosarray and returns a plainnumber. Use this when the products are already in component state (e.g. in the Reportes page).src/data/mockData.ts— anasyncversion that queries the Supabaseproductostable directly and returnsPromise<number>. Use this when you need a fresh inventory value from the database without loading the full products list into state first.
Promise — always check your import path.