payservedb 9.8.5 → 9.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/models/levy_deposits.js +32 -1
package/package.json
CHANGED
|
@@ -27,6 +27,25 @@ const DepositSchema = new Schema(
|
|
|
27
27
|
type: Number,
|
|
28
28
|
min: [0, 'Amount cannot be negative']
|
|
29
29
|
},
|
|
30
|
+
|
|
31
|
+
amountPaid: {
|
|
32
|
+
type: Number,
|
|
33
|
+
default: 0,
|
|
34
|
+
min: [0, 'Amount paid cannot be negative']
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
payments: [
|
|
38
|
+
{
|
|
39
|
+
amount: { type: Number, required: true },
|
|
40
|
+
appliedAmount: { type: Number, required: true },
|
|
41
|
+
overpaymentAmount: { type: Number, default: 0 },
|
|
42
|
+
datePaid: { type: Date, required: true },
|
|
43
|
+
paymentReference: { type: String, trim: true },
|
|
44
|
+
paymentMethod: { type: String, trim: true },
|
|
45
|
+
recordedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
|
46
|
+
recordedAt: { type: Date, default: Date.now }
|
|
47
|
+
}
|
|
48
|
+
],
|
|
30
49
|
datePaid: {
|
|
31
50
|
type: Date
|
|
32
51
|
},
|
|
@@ -47,7 +66,8 @@ const DepositSchema = new Schema(
|
|
|
47
66
|
}],
|
|
48
67
|
status: {
|
|
49
68
|
type: String,
|
|
50
|
-
|
|
69
|
+
|
|
70
|
+
enum: ['Pending', 'Partially Paid', 'Held', 'Refunded', 'Partially Refunded', 'Forfeited'],
|
|
51
71
|
default: 'Pending',
|
|
52
72
|
required: [true, 'Status is required']
|
|
53
73
|
},
|
|
@@ -92,6 +112,10 @@ DepositSchema.virtual('balanceRemaining').get(function () {
|
|
|
92
112
|
return this.amount - (this.refundedAmount || 0);
|
|
93
113
|
});
|
|
94
114
|
|
|
115
|
+
DepositSchema.virtual('amountDue').get(function () {
|
|
116
|
+
return Math.max(this.amount - (this.amountPaid || 0), 0);
|
|
117
|
+
});
|
|
118
|
+
|
|
95
119
|
DepositSchema.pre('save', function (next) {
|
|
96
120
|
if (
|
|
97
121
|
(this.status === 'Refunded' || this.status === 'Partially Refunded') &&
|
|
@@ -109,6 +133,13 @@ DepositSchema.pre('save', function (next) {
|
|
|
109
133
|
next();
|
|
110
134
|
});
|
|
111
135
|
|
|
136
|
+
DepositSchema.pre('save', function (next) {
|
|
137
|
+
if ((this.amountPaid || 0) > this.amount) {
|
|
138
|
+
return next(new Error('Amount paid cannot exceed deposit amount'));
|
|
139
|
+
}
|
|
140
|
+
next();
|
|
141
|
+
});
|
|
142
|
+
|
|
112
143
|
module.exports = {
|
|
113
144
|
schema: DepositSchema,
|
|
114
145
|
name: 'Deposit'
|