Overview
The payment tables manage credit sales and installment payments in TechCore Mini ERP. TheplanPagos table defines the payment schedule for credit sales, while the abonosVentas table records actual payments made against those installments.
PlanPagos Table
TheplanPagos table stores the payment schedule for credit sales, breaking down the total amount into individual installments.
SQL Schema
Columns
Primary key with auto-increment. Uniquely identifies each installment in the payment plan.
Foreign key to
ventas table. Links the installment to its parent sale. Required field. CASCADE DELETE ensures payment plans are removed when the sale is deleted.Installment/payment number (1, 2, 3, etc.). Identifies the sequence of the payment within the payment plan. Required field.
Due date for this installment. Required field. Used for calculating overdue payments and late fees.
Installment amount. Required field. This is the payment amount due on the fechaVencimiento.
Payment status flag. Defaults to 0 (unpaid). Set to 1 when payment is received. Automatically updated by TR_ActualizarSaldo trigger.
Constraints
- Primary Key:
id - Foreign Key:
nordenreferencesventas(norden)ON DELETE CASCADE
Indexes
- IDX_planPagos_norden: Queries for all installments of a specific sale
- IDX_planPagos_fechaVencimiento: Date-based queries for upcoming or overdue payments
- IDX_planPagos_pagada: Filtered index for unpaid installments (optimized WHERE pagada = 0)
C# Model
Relationships
- Many-to-One with ventas: Multiple installments belong to one sale (CASCADE DELETE)
AbonosVentas Table
TheabonosVentas table records actual payments received from customers for credit sales.
SQL Schema
Columns
Primary key with auto-increment. Uniquely identifies each payment transaction.
Foreign key to
ventas table. Links the payment to its parent sale. Required field. CASCADE DELETE ensures payments are removed when the sale is deleted.Payment date/time. Defaults to current date/time (GETDATE()). Records when the payment was received.
Payment amount. Required field. The actual amount received from the customer.
The installment number this payment applies to. Required field. Links to planPagos.numeroCuota.
Constraints
- Primary Key:
id - Foreign Key:
nordenreferencesventas(norden)ON DELETE CASCADE
Indexes
- IDX_abonosVentas_norden: Payment history queries for specific sales
- IDX_abonosVentas_fecha: Date-based payment reports and cash flow analysis
C# Model
Relationships
- Many-to-One with ventas: Multiple payments can be made for one sale (CASCADE DELETE)
Entity Relationships
Automatic Payment Processing
When a payment is received, the system automatically updates the sale balance and marks installments as paid:TR_ActualizarSaldo Trigger
- Decreases
ventas.saldoby the payment amount - Sets
planPagos.pagada = 1for the corresponding installment
Payment Tracking Views
The system includes built-in views for payment management:vw_CuotasVencidas
Tracks overdue installments with calculated late fees:- Shows only unpaid installments past due date
- Calculates days overdue
- Applies 2% daily late fee (mora)
- Excludes voided sales
vw_CuotasPorVencer
Tracks upcoming installments:- Shows unpaid installments not yet due
- Useful for payment reminders
- Excludes voided sales
vw_EstadoCuenta
Provides account status for credit customers:- Shows credit sales only
- Displays total, remaining balance, and total paid
- Groups payments by sale
- Excludes voided sales
Payment Workflow
Creating a Credit Sale
-
Create
ventasrecord with:tipoPago = 'CREDITO'meses= number of installmentstasaInteres= interest ratesaldo= total amount (initially)
-
Generate
planPagosrecords:- One record per installment
- Calculate
fechaVencimientofor each installment - Calculate
montoCuotaincluding interest - All installments start with
pagada = 0
Recording a Payment
-
Insert
abonosVentasrecord:- Set
nordento the sale - Set
numeroCuotato the installment being paid - Set
montoto the payment amount fechadefaults to current time
- Set
-
Trigger automatically:
- Updates
ventas.saldo - Sets
planPagos.pagada = 1
- Updates
Querying Payment Status
Usage Notes
- Payment plans are automatically deleted when the parent sale is deleted (CASCADE)
- The
pagadafiltered index optimizes queries for pending payments - Late fees (mora) are calculated at 2% per day in vw_CuotasVencidas
- All monetary amounts use DECIMAL(18,2) for precision
- The trigger ensures data consistency between sales balance and payment records
- Voided sales (nula = 1) are excluded from all payment tracking views
- Multiple payments can be made against a single sale for different installments
- The
numeroCuotafield links payments to specific installments in the payment plan