feat: store payment installments in a transactions collection

Move embedded payment rows into Transaction documents with due dates so remaining tuition can be tracked separately from paid amounts.
This commit is contained in:
2026-08-16 07:32:27 +03:30
parent b4ca5678bf
commit 06efcd5b90
7 changed files with 341 additions and 53 deletions
+48
View File
@@ -0,0 +1,48 @@
// /components/payments/transactionModel.js
'use strict';
const mongoose = require('mongoose');
const transactionSchema = new mongoose.Schema({
payment: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Payment',
required: true,
index: true
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
index: true
},
amount: {
type: Number,
required: true,
min: 0
},
method: {
type: String,
enum: ['online', 'card', 'cash']
},
receiptNumber: { type: String, trim: true },
notes: { type: String, trim: true, maxlength: 5000 },
recordedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
date: { type: Date },
dueDate: {
type: Date,
required: true,
index: true
},
status: {
type: String,
enum: ['pending', 'paid'],
default: 'pending',
index: true
}
}, {
timestamps: true
});
transactionSchema.index({ payment: 1, dueDate: 1 });
module.exports = mongoose.model('Transaction', transactionSchema);