Skip to main content

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.

The Sales module (/ventas) is the transaction hub of FerreMarket. It provides a full-featured interface for creating new sales, browsing and filtering existing transactions, tracking daily and weekly revenue KPIs, generating per-sale PDF invoices via jsPDF, sending invoice emails, and bulk-exporting selected records. The page refreshes its data every time the browser tab regains focus so that figures stay current across multiple sessions.

Sales KPI Dashboard

Four metric cards appear above the transaction list, laid out in a 2 → 4 column responsive grid:
CardMetricExtra detail
Ventas HoyCLP total for the current calendar dayDay-over-day % change vs. yesterday with a green/red TrendingUp/TrendingDown icon
Esta SemanaCLP total for the rolling 7-day windowCount of individual transactions in that window
Promedio/VentaMean transaction value across all recordsLabelled “Últimas 30 ventas”
PendientesCount of sales with estado === 'pendiente'Labelled “Requieren atención”
All four values are recalculated via useMemo every time the ventas array or the refreshKey counter changes.

Statistics Charts

Below the KPI cards, two side-by-side distribution panels give a visual breakdown of the current transaction data. Both panels are rendered by the GraficosEstadisticas component and are recalculated via useMemo whenever the ventas array changes.

Estados de Ventas

Lists each estado value with a coloured dot, transaction count, and percentage share. Colours follow the same badge scheme used throughout the module: green for completada, yellow for pendiente, and red for cancelada.

Métodos de Pago

Lists each metodoPago value with transaction count and percentage share. Values are taken directly from the ventas array and shown with an orange dot, so any payment method actually stored in the database will appear here automatically.

Sale Fields

Each transaction is modelled by the Venta TypeScript interface from src/types/index.ts:
FieldTypeDescription
idstringUnique numeric identifier assigned by Supabase
fechastringISO 8601 timestamp in the America/Santiago timezone (set at creation)
clientestringNumeric client ID referencing the clientes table
productos{ id: string; cantidad: number; precioUnitario: number }[]Line items; each references a product ID from productos
totalnumberPre-calculated sale total in CLP (sum of cantidad × precioUnitario for all line items)
metodoPagostringOne of the four accepted payment methods
estadostringCurrent status of the transaction — values in practice are 'completada', 'pendiente', or 'cancelada' (constrained by VentaFormulario)

Creating a Sale

1

Open Nueva Venta

Click the orange Nueva Venta button in the top-right header. This opens VentaModal with all fields blank.
2

Select a client

Choose an active client from the dropdown. The list is populated from obtenerClientes() and only active clients are selectable.
3

Add line items

Search for and add products one by one. Set the quantity for each item; the unit price is pre-filled from the product’s precio field and is editable. Each line item also has a per-product Desc. % field (percentage discount on that line). The running total updates in real time. A stock-availability check is performed per line — if the requested quantity exceeds available stock, an inline error appears.
4

Set payment method, status, and taxes

Both metodoPago and estado are required fields. Select from the dropdowns. Optionally set a Descuento General (percentage discount applied to the cart subtotal after per-line discounts) and adjust the IVA percentage (defaults to 19%). The summary panel shows Subtotal → Descuento → IVA → Total Final.
5

Save the sale

On confirmation, agregarVenta(venta) performs four sequential Supabase writes:
  1. Inserts a row into ventas and retrieves the new ventaId.
  2. Inserts one row per line item into ventas_productos (with venta_id, producto_id, cantidad, precio_unitario).
  3. Decrements stock in the productos table for each line item.
  4. Updates ultimacompra on the client record to the current Santiago timestamp.

Payment Methods

The following payment methods are supported and stored verbatim in the metodo_pago column:
Stored valueDropdown label
EfectivoEfectivo
Tarjeta de créditoTarjeta de crédito
Tarjeta de débitoTarjeta de débito
TransferenciaTransferencia bancaria

Views

The transaction list supports three rendering modes, automatically adjusted on resize:
ModeTriggerLayout
GridDefault on ≥ 1024 px1 → 2 → 3 → 4 columns of VentaCard components
TableManual toggle on ≥ 1024 pxSortable table with columns: ID, Fecha, Cliente, Productos, Total, Método Pago, Estado, Acciones
ListaAutomatic on < 768 pxSingle-column card list
On mobile the view toggle is hidden and the list view is enforced automatically. Page size is also automatically reduced to 8 items on mobile, 9 on tablet, and 12 on desktop.

Filtering and Searching

The filter panel is always visible on desktop and toggles via a Filtros button on mobile:
FilterField filtered
Search boxcliente name (resolved via getNombreCliente)
Estadoestado — Completada / Pendiente / Cancelada
Método de pagometodoPago — the four payment options above
ClienteExact client ID match
Fecha desde / hastaCompares fecha.split('T')[0] against the date input values
Monto mínimo / máximoCompares total against the numeric bounds
Saving favourite filter sets: click the Guardar (bookmark) button to snapshot the current filter state with the date as its name. Saved sets appear as pill buttons below the filters and can be re-applied with a single click.

PDF Invoices

1

Single invoice

Click the PDF button on any sale card or the download icon in the table actions row. This calls generarFactura(venta), which uses jsPDF to build a formatted invoice document.
2

Bulk export

Select one or more sales using the checkboxes on the cards or in the table header. A blue action banner appears showing the count of selected sales and two export buttons — PDF (via FileText) and Excel (via FileSpreadsheet). Click either to call exportarSeleccion('pdf') or exportarSeleccion('excel').

Email

Click the Send icon (Send / Mail) on a sale card or in the table actions to call enviarFacturaPorEmail(venta). The function resolves the client’s email field from the clientes state array and dispatches the invoice.

Sale Status

Status values are displayed as coloured pill badges throughout the module:
EstadoBadge colourMeaning
completadaGreenTransaction fully processed and paid
pendienteYellowTransaction recorded but not yet finalised
canceladaRedTransaction voided; stock is not automatically restocked

Build docs developers (and LLMs) love