Overview
The Amortization API manages payment schedules for down payments. When a sale is created with installment payments, the system automatically generates an amortization plan with individual cuotas (installments).Model Structure
PlanAmortizacionVenta Model
Table:planes_amortizacion_ventaPrimary Key:
id_plan (auto-increment)
Attributes
Primary key, auto-increment
Foreign key to
ventas table. The sale this plan belongs to.Plan type. Common values:
'cuota_inicial': Down payment plan'credito': Credit/loan plan (future use)
Annual interest rate percentage. Currently 0 for down payments.
Total term in months
Plan start date (typically sale date)
Plan notes or description
Record creation timestamp
Last update timestamp
Relationships
The sale this plan belongs to
Collection of
PlanAmortizacionCuota records (individual installments)PlanAmortizacionCuota Model
Table:planes_amortizacion_cuotaPrimary Key:
id_cuota (auto-increment)
Attributes
Primary key, auto-increment
Foreign key to
planes_amortizacion_venta tableInstallment number (1, 2, 3, …)
Due date for this installment
Total installment amount
Interest portion (currently 0 for down payments)
Principal portion (equals valor_cuota for down payments)
Remaining balance after this payment
Payment status:
'Pendiente': Unpaid'Pagada': Fully paid'Parcial': Partially paid'Vencida': Overdue
Record creation timestamp
Last update timestamp
Relationships
The parent payment plan
Collection of
Pago records applied to this cuotaGet Payment Plan for Sale
Path Parameters
Sale ID
Response
Generate Payment Plan (Internal)
Payment plans are automatically generated when creating or converting a sale. This section documents the internal logic.
Plan Generation Algorithm
Example Calculation
Input:- Total down payment: $67,500,000
- Term: 18 months
- Frequency: 1 month (monthly payments)
- Number of payments: 18
- Base payment: $3,750,000
- Last payment: $3,750,000 (includes any remainder)
| Cuota | Due Date | Amount | Saldo | Status |
|---|---|---|---|---|
| 1 | 2024-01-15 | 3,750,000 | 63,750,000 | Pendiente |
| 2 | 2024-02-15 | 3,750,000 | 60,000,000 | Pendiente |
| 3 | 2024-03-15 | 3,750,000 | 56,250,000 | Pendiente |
| … | … | … | … | … |
| 18 | 2024-06-15 | 3,750,000 | 0 | Pendiente |
Regenerate Payment Plan
Path Parameters
Sale ID
Use Cases
- Sale terms were updated (different amount, term, or frequency)
- Conversion from separation to sale
- Correction of calculation errors
List Amortization Plans
Query Parameters
Filter by project
Filter by client document
Filter by plan type (e.g., ‘cuota_inicial’)
Get Sales by Client for Plan Generation
Query Parameters
Project ID
Client document
Export Payment Plan to PDF
Request Body
Sale ID to export payment plan for
Response
Returns PDF file with payment schedule table including:- Client and property information
- Payment plan details (term, frequency)
- Cuota table with due dates, amounts, and balances
Update Cuota Status
Path Parameters
Cuota ID
Request Body
New status:
'Pendiente', 'Pagada', 'Parcial', or 'Vencida'Business Logic
Automatic Plan Generation
Payment plans are automatically generated when:- Creating a Sale with
tipo_operacion = 'venta' - Converting a Separation to sale
- Updating a Sale that changes payment terms
Payment Frequency
Thefrecuencia_cuota_inicial_meses field controls payment intervals:
- 1: Monthly payments
- 2: Bimonthly (every 2 months)
- 3: Quarterly (every 3 months)
- 6: Semi-annual (every 6 months)
Interest-Free Down Payments
Current implementation:valor_interes_anual = 0(no interest charged)valor_interes = 0per cuotavalor_capital = valor_cuota(full payment to principal)
The model structure supports future interest calculations if business requirements change.
Cuota Status Management
Cuota status is typically updated when payments are recorded:Overdue Detection
Implement a scheduled task to mark overdue cuotas:Reporting Queries
Payment Schedule Summary
Client Payment Schedule
Project Payment Schedule
Related Endpoints
- Sales API - Create sales that generate plans
- Payments API - Record payments against cuotas
- Clients API - Client information