payservedb 7.0.9 → 7.8.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "7.0.9",
3
+ "version": "7.8.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -37,7 +37,6 @@ const waterInvoiceSchema = new mongoose.Schema(
37
37
  default: 0
38
38
  },
39
39
 
40
- // PAYMENTS
41
40
  paymentMethods: {
42
41
  mobilePayment: {
43
42
  status: {
@@ -58,10 +57,21 @@ const waterInvoiceSchema = new mongoose.Schema(
58
57
  type: mongoose.Schema.Types.ObjectId,
59
58
  ref: 'BankDetails'
60
59
  }
60
+ },
61
+ cashPayment: {
62
+ status: {
63
+ type: Boolean,
64
+ default: false
65
+ }
61
66
  }
62
67
  },
68
+ paymentMethod: {
69
+ type: String,
70
+ enum: ['mobile', 'bank', 'cash', 'mixed'],
71
+ default: null
72
+ },
63
73
 
64
- // Biller Address Information (added from WaterMeterSettings)
74
+ // Biller Address Information
65
75
  billerAddress: {
66
76
  name: {
67
77
  type: String,
@@ -291,13 +301,49 @@ const waterInvoiceSchema = new mongoose.Schema(
291
301
  }
292
302
  );
293
303
 
304
+ // Pre-save middleware to update payment method status and primary payment method
294
305
  waterInvoiceSchema.pre('save', function (next) {
306
+ // Handle due date and status
295
307
  if (this.isModified('dueDate') || this.isNew) {
296
308
  const today = new Date();
297
309
  if (this.dueDate < today && this.status === 'Pending') {
298
310
  this.status = 'Overdue';
299
311
  }
300
312
  }
313
+
314
+ // Update payment method status based on reconciliation history
315
+ if (this.isModified('reconciliationHistory') || this.isNew) {
316
+ if (this.reconciliationHistory && this.reconciliationHistory.length > 0) {
317
+ const latestPayment = this.reconciliationHistory[this.reconciliationHistory.length - 1];
318
+ const paymentType = latestPayment.type?.toLowerCase();
319
+
320
+ // Initialize paymentMethods if not exists
321
+ if (!this.paymentMethods) {
322
+ this.paymentMethods = {
323
+ mobilePayment: { status: false },
324
+ bankPayment: { status: false },
325
+ cashPayment: { status: false }
326
+ };
327
+ }
328
+
329
+ // Update payment method status based on payment type
330
+ if (paymentType && (paymentType.includes('mobile') || paymentType.includes('mpesa') || paymentType.includes('m-pesa'))) {
331
+ this.paymentMethods.mobilePayment.status = true;
332
+ this.primaryPaymentMethod = 'mobile';
333
+ } else if (paymentType && paymentType.includes('bank')) {
334
+ this.paymentMethods.bankPayment.status = true;
335
+ this.primaryPaymentMethod = 'bank';
336
+ } else if (paymentType && paymentType.includes('cash')) {
337
+ this.paymentMethods.cashPayment.status = true;
338
+ this.primaryPaymentMethod = 'cash';
339
+ } else {
340
+ // Default to cash for manual or unspecified payments
341
+ this.paymentMethods.cashPayment.status = true;
342
+ this.primaryPaymentMethod = 'cash';
343
+ }
344
+ }
345
+ }
346
+
301
347
  next();
302
348
  });
303
349
 
@@ -101,7 +101,7 @@ const waterMeterSettingsSchema = new mongoose.Schema({
101
101
  default: false
102
102
  }
103
103
  },
104
- // Payment reminder notifications (separate from usage notifications)
104
+ // Payment reminder notifications
105
105
  paymentReminders: {
106
106
  enabled: {
107
107
  type: Boolean,
@@ -15,7 +15,6 @@ const waterMeterSchema = new mongoose.Schema({
15
15
  },
16
16
  serialNumber: {
17
17
  type: String,
18
- required: true,
19
18
  unique: true,
20
19
  trim: true,
21
20
  index: true