Overview
The sales system in TechCore manages customer transactions with two payment methods: CONTADO (cash/immediate payment) and CREDITO (credit/installment payment). Sales automatically update inventory and can include payment plans with interest calculations.Sales Entity
TheVenta entity represents a complete sales transaction.
Entity Fields
Unique sale order identifier (primary key)
Sequential order number for display purposes
Customer code (foreign key to
clientes table)Salesperson/user ID (foreign key to
users table)Sale date and time (defaults to current datetime)
Sum of all line items before tax
Tax amount (IVA - Value Added Tax)
Final sale total (Subtotal + IVA)
Payment type:
CONTADO (immediate payment) or CREDITO (installment payment)Number of months for credit sales (only applicable when TipoPago = ‘CREDITO’)
Interest rate percentage applied to credit sales (e.g., 5.00 for 5%)
Outstanding balance. Equals Total for new sales, decreases with payments
Indicates if the sale is voided/annulled (0 = valid, 1 = voided)
Active status of the sale record
Relationships
- VentasDetalles: Collection of line items for this sale
- PlanPagos: Collection of installment plans (for credit sales)
- AbonosVenta: Collection of payments made against this sale
- CodclienNavigation: Customer information
- CodvendNavigation: Salesperson/user information
Payment Types
CONTADO (Cash Sale)
Immediate payment transactions where the full amount is paid upfront. Characteristics:TipoPago= “CONTADO”Mesesis NULLTasaInteres= 0Saldoshould be 0 after initial payment- No payment plan is generated
CREDITO (Credit Sale)
Installment-based transactions with optional interest charges. Characteristics:TipoPago= “CREDITO”Mesesspecifies the number of monthly installmentsTasaInteresdefines the interest rate appliedSaldostarts at Total amount and decreases with each payment- Automatically generates a payment plan (
PlanPagos)
Sales Details
Each sale contains one or more line items stored in theVentasDetalle entity.
Line Item Fields
Auto-generated line item identifier
Sale order reference (foreign key to
ventas)Product code (foreign key to
productos)Quantity of product sold
Unit sale price for this product
Line total (Cantidad × Pventa)
Creating a Sale
Create the Sale Header
Create a new
Venta record with customer, salesperson, and payment details. Set TipoPago to either “CONTADO” or “CREDITO”.For credit sales, specify Meses (number of months) and TasaInteres (interest rate).Add Line Items
Create
VentasDetalle records for each product being sold. The system will automatically reduce inventory when line items are added (via the TR_DisminuirStock trigger).Stock is only reduced for non-voided sales (Nula = 0).Calculate Totals
Sum all line item subtotals to get the sale
Subtotal, calculate Iva (tax), and compute the final Total.Initial Saldo equals Total for credit sales, or 0 for cash sales after payment.Inventory Management
TheTR_DisminuirStock trigger automatically reduces product stock when sale details are inserted:
Voiding Sales
SetNula = 1 to void a sale. Voided sales:
- Are excluded from financial reports
- Do not affect inventory (trigger checks this flag)
- Remain in the database for audit purposes
- Are filtered out in views like
vw_CuotasVencidas
Database Schema
Related Documentation
- Payment Plans - Managing installment schedules
- Payments - Recording customer payments
- Purchases - Managing inventory purchases