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:
@@ -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);
|
||||
Reference in New Issue
Block a user