Skip to main content

Overview

The Sale (Venta) model represents a completed transaction in the Luis IT Repair POS system. It captures the full transaction details including items sold, payment methods, tax calculations, and loyalty point redemption/earning.

Firestore Collection

Collection Name: ventas

Core Fields

id
string
Sale document ID, automatically generated by Firestore.
fecha
timestamp
required
Transaction date and time.
clienteTelefono
string
Customer phone number if provided. Links to customer loyalty account.

Financial Details

subtotal
number
required
Sum of all items before discounts and tax.Calculation: Σ (producto.precioVenta * producto.cantidad)
descuentoManual
number
default:0
Manual discount amount applied by cashier.
descuentoPuntos
number
default:0
Discount from redeemed loyalty points. Typically 1 point = 1 peso.
aplicarIVA
boolean
required
Whether sales tax (IVA) was applied to this transaction.Note: Configurable per transaction based on POS settings.
ivaPorcentaje
number
Tax rate applied (e.g., 0.16 for 16% IVA).
iva
number
Calculated tax amount.Calculation: (subtotal - descuentoManual - descuentoPuntos) * ivaPorcentaje
total
number
required
Final transaction amount.Calculation: subtotal - descuentoManual - descuentoPuntos + iva

Payment Information

tipoPago
string
required
Primary payment method.Possible values:
  • efectivo - Cash
  • tarjeta - Credit/debit card
  • transferencia - Bank transfer
  • mixto - Multiple payment methods
pagoDetalle
object
Detailed breakdown of payment by method. Used for end-of-day reconciliation.

Loyalty Program

puntosGenerados
number
default:0
Loyalty points earned from this transaction.Calculation Logic:
  • Only products with generaPuntos: true contribute
  • Typically 1 point per peso spent
  • Points awarded to customer account after sale completion

Items Sold

productos
array
required
Array of items included in the transaction. Each item contains:

Example JSON

Simple Product Sale

{
  "id": "venta_abc123",
  "fecha": { "_seconds": 1678905678, "_nanoseconds": 890000000 },
  "clienteTelefono": "5551234567",
  "subtotal": 500,
  "descuentoManual": 0,
  "descuentoPuntos": 50,
  "aplicarIVA": true,
  "ivaPorcentaje": 0.16,
  "iva": 72,
  "total": 522,
  "tipoPago": "tarjeta",
  "pagoDetalle": {
    "efectivo": 0,
    "tarjeta": 522,
    "transferencia": 0,
    "referenciaTarjeta": "AUTH123456"
  },
  "puntosGenerados": 450,
  "productos": [
    {
      "id": "prod_xyz789",
      "nombre": "Cable USB-C 1m",
      "codigo": "7501234567890",
      "precioVenta": 50,
      "cantidad": 2,
      "generaPuntos": true,
      "esServicio": false
    },
    {
      "id": "prod_def456",
      "nombre": "Mouse inalámbrico",
      "codigo": "MS-WL-001",
      "precioVenta": 150,
      "cantidad": 1,
      "generaPuntos": true,
      "esServicio": false
    },
    {
      "id": "prod_ghi789",
      "nombre": "Limpieza de laptop",
      "codigo": "SRV-CLEAN",
      "precioVenta": 250,
      "cantidad": 1,
      "generaPuntos": true,
      "esServicio": false
    }
  ]
}

Service Delivery Sale

{
  "id": "venta_def456",
  "fecha": { "_seconds": 1678910000, "_nanoseconds": 0 },
  "clienteTelefono": "5559876543",
  "subtotal": 1800,
  "descuentoManual": 100,
  "descuentoPuntos": 0,
  "aplicarIVA": true,
  "ivaPorcentaje": 0.16,
  "iva": 272,
  "total": 1972,
  "tipoPago": "mixto",
  "pagoDetalle": {
    "efectivo": 1000,
    "tarjeta": 972,
    "transferencia": 0,
    "referenciaTarjeta": "AUTH789012"
  },
  "puntosGenerados": 0,
  "productos": [
    {
      "id": "servicio_abc789",
      "nombre": "Reparación laptop HP Pavilion 15",
      "codigo": "",
      "precioVenta": 1800,
      "cantidad": 1,
      "generaPuntos": false,
      "esServicio": true,
      "folioServicio": "HP/042",
      "servicioId": "servicio_abc789"
    }
  ]
}

Mixed Sale (Products + Service)

{
  "id": "venta_ghi789",
  "fecha": { "_seconds": 1678915000, "_nanoseconds": 0 },
  "clienteTelefono": null,
  "subtotal": 2300,
  "descuentoManual": 0,
  "descuentoPuntos": 0,
  "aplicarIVA": false,
  "ivaPorcentaje": 0,
  "iva": 0,
  "total": 2300,
  "tipoPago": "efectivo",
  "pagoDetalle": {
    "efectivo": 2300,
    "tarjeta": 0,
    "transferencia": 0,
    "referenciaTarjeta": null
  },
  "puntosGenerados": 0,
  "productos": [
    {
      "id": "servicio_xyz123",
      "nombre": "Cambio de pantalla iPhone 12",
      "codigo": "",
      "precioVenta": 1500,
      "cantidad": 1,
      "generaPuntos": false,
      "esServicio": true,
      "folioServicio": "AP/015",
      "servicioId": "servicio_xyz123"
    },
    {
      "id": "prod_case001",
      "nombre": "Funda iPhone 12",
      "codigo": "CASE-IP12-CLR",
      "precioVenta": 200,
      "cantidad": 4,
      "generaPuntos": true,
      "esServicio": false
    }
  ]
}
  • registrarVenta() - Create new sale record
  • descontarStock() - Update product inventory after sale
  • sumarPuntosCliente() - Award/redeem loyalty points
  • imprimirTicketVenta() - Generate receipt
See POS Firebase for detailed function documentation.

Transaction Flow

  1. Item Selection - Build cart with products/services
  2. Client Lookup - Optional phone number for loyalty
  3. Discount Application - Manual + points redemption
  4. Tax Calculation - Apply IVA if enabled
  5. Payment Processing - Record method(s) and amounts
  6. Inventory Update - Deduct stock for sold products
  7. Loyalty Update - Award/redeem points
  8. Service Update - Mark services as entregado and cobradoEnPOS
  9. Receipt Generation - Print transaction details

End-of-Day Reconciliation

Sales data is used in cash register close-out reports (cortes_caja):
import { cerrarCajaHoy } from './js/services/corte_caja_firestore';

// Close register and generate summary
const ventasHoy = await obtenerVentasPorFecha(fechaHoy);
const corte = await cerrarCajaHoy(ventasHoy, {
  efectivoContado: 5230,
  notasEmpleado: "Todo en orden"
});

// corte includes:
// - Total sales by payment method
// - Expected vs actual cash
// - Number of transactions
// - Discrepancy alerts
See Cash Register Operations for daily closing procedures.

Analytics & Reports

Sales records enable business intelligence queries:
  • Daily Revenue: Sum total grouped by date
  • Payment Mix: Aggregate pagoDetalle amounts
  • Top Products: Count/sum by product ID
  • Customer Frequency: Count sales by clienteTelefono
  • Tax Reporting: Sum iva for tax filings
  • Discount Analysis: Track descuentoManual and descuentoPuntos
Implement using Firestore queries or export to analytics tools.

Build docs developers (and LLMs) love