payservedb 7.0.9 → 7.8.0
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
CHANGED
|
@@ -37,7 +37,7 @@ const waterInvoiceSchema = new mongoose.Schema(
|
|
|
37
37
|
default: 0
|
|
38
38
|
},
|
|
39
39
|
|
|
40
|
-
// PAYMENTS
|
|
40
|
+
// PAYMENTS - Updated structure
|
|
41
41
|
paymentMethods: {
|
|
42
42
|
mobilePayment: {
|
|
43
43
|
status: {
|
|
@@ -58,10 +58,23 @@ const waterInvoiceSchema = new mongoose.Schema(
|
|
|
58
58
|
type: mongoose.Schema.Types.ObjectId,
|
|
59
59
|
ref: 'BankDetails'
|
|
60
60
|
}
|
|
61
|
+
},
|
|
62
|
+
cashPayment: {
|
|
63
|
+
status: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: false
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
68
|
},
|
|
63
69
|
|
|
64
|
-
//
|
|
70
|
+
// Add a separate field for the primary payment method used
|
|
71
|
+
primaryPaymentMethod: {
|
|
72
|
+
type: String,
|
|
73
|
+
enum: ['mobile', 'bank', 'cash', 'mixed'],
|
|
74
|
+
default: null
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
// Biller Address Information
|
|
65
78
|
billerAddress: {
|
|
66
79
|
name: {
|
|
67
80
|
type: String,
|
|
@@ -291,13 +304,49 @@ const waterInvoiceSchema = new mongoose.Schema(
|
|
|
291
304
|
}
|
|
292
305
|
);
|
|
293
306
|
|
|
307
|
+
// Pre-save middleware to update payment method status and primary payment method
|
|
294
308
|
waterInvoiceSchema.pre('save', function (next) {
|
|
309
|
+
// Handle due date and status
|
|
295
310
|
if (this.isModified('dueDate') || this.isNew) {
|
|
296
311
|
const today = new Date();
|
|
297
312
|
if (this.dueDate < today && this.status === 'Pending') {
|
|
298
313
|
this.status = 'Overdue';
|
|
299
314
|
}
|
|
300
315
|
}
|
|
316
|
+
|
|
317
|
+
// Update payment method status based on reconciliation history
|
|
318
|
+
if (this.isModified('reconciliationHistory') || this.isNew) {
|
|
319
|
+
if (this.reconciliationHistory && this.reconciliationHistory.length > 0) {
|
|
320
|
+
const latestPayment = this.reconciliationHistory[this.reconciliationHistory.length - 1];
|
|
321
|
+
const paymentType = latestPayment.type?.toLowerCase();
|
|
322
|
+
|
|
323
|
+
// Initialize paymentMethods if not exists
|
|
324
|
+
if (!this.paymentMethods) {
|
|
325
|
+
this.paymentMethods = {
|
|
326
|
+
mobilePayment: { status: false },
|
|
327
|
+
bankPayment: { status: false },
|
|
328
|
+
cashPayment: { status: false }
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Update payment method status based on payment type
|
|
333
|
+
if (paymentType && (paymentType.includes('mobile') || paymentType.includes('mpesa') || paymentType.includes('m-pesa'))) {
|
|
334
|
+
this.paymentMethods.mobilePayment.status = true;
|
|
335
|
+
this.primaryPaymentMethod = 'mobile';
|
|
336
|
+
} else if (paymentType && paymentType.includes('bank')) {
|
|
337
|
+
this.paymentMethods.bankPayment.status = true;
|
|
338
|
+
this.primaryPaymentMethod = 'bank';
|
|
339
|
+
} else if (paymentType && paymentType.includes('cash')) {
|
|
340
|
+
this.paymentMethods.cashPayment.status = true;
|
|
341
|
+
this.primaryPaymentMethod = 'cash';
|
|
342
|
+
} else {
|
|
343
|
+
// Default to cash for manual or unspecified payments
|
|
344
|
+
this.paymentMethods.cashPayment.status = true;
|
|
345
|
+
this.primaryPaymentMethod = 'cash';
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
301
350
|
next();
|
|
302
351
|
});
|
|
303
352
|
|
|
@@ -101,7 +101,7 @@ const waterMeterSettingsSchema = new mongoose.Schema({
|
|
|
101
101
|
default: false
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
|
-
// Payment reminder notifications
|
|
104
|
+
// Payment reminder notifications
|
|
105
105
|
paymentReminders: {
|
|
106
106
|
enabled: {
|
|
107
107
|
type: Boolean,
|