feat: add messaging toggles, password reset SMS, and payment discounts
Allow SuperAdmin to disable SMS, email, and bot from dashboard settings on top of env flags. Add admin password reset with credentials SMS, plus payment discounts, notes, and payable amount handling.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const { getPayableAmount, normalizeDiscount } = require('../../utils/paymentAmount');
|
||||
|
||||
const transactionSchema = new mongoose.Schema({
|
||||
amount: { type: Number, required: true },
|
||||
method: {
|
||||
@@ -11,6 +13,7 @@ const transactionSchema = new mongoose.Schema({
|
||||
default: 'card'
|
||||
},
|
||||
receiptNumber: { type: String, trim: true },
|
||||
notes: { type: String, trim: true, maxlength: 5000 },
|
||||
recordedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
||||
date: { type: Date, default: Date.now }
|
||||
}, { _id: true });
|
||||
@@ -35,6 +38,11 @@ const paymentSchema = new mongoose.Schema({
|
||||
required: true,
|
||||
min: 0
|
||||
},
|
||||
discount: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
min: 0
|
||||
},
|
||||
paidAmount: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
@@ -49,14 +57,16 @@ const paymentSchema = new mongoose.Schema({
|
||||
default: 'pending'
|
||||
},
|
||||
transactions: [transactionSchema],
|
||||
notes: { type: String, trim: true }
|
||||
notes: { type: String, trim: true, maxlength: 5000 }
|
||||
}, {
|
||||
timestamps: true
|
||||
});
|
||||
|
||||
// Auto-update status based on paid amount
|
||||
// Auto-update status based on paid amount vs payable (amount - discount)
|
||||
paymentSchema.pre('save', function (next) {
|
||||
if (this.paidAmount >= this.amount) {
|
||||
this.discount = normalizeDiscount(this.discount, this.amount);
|
||||
const payable = getPayableAmount(this);
|
||||
if (this.paidAmount >= payable) {
|
||||
this.status = 'paid';
|
||||
} else if (this.paidAmount > 0) {
|
||||
this.status = 'partial';
|
||||
|
||||
Reference in New Issue
Block a user