payservedb 7.0.8 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "7.0.8",
3
+ "version": "7.8.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -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
- // Biller Address Information (added from WaterMeterSettings)
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
 
@@ -4,7 +4,8 @@ const waterMeterSettingsSchema = new mongoose.Schema({
4
4
  facilityId: {
5
5
  type: mongoose.Schema.Types.ObjectId,
6
6
  ref: 'Facility',
7
- required: true
7
+ required: true,
8
+ unique: true
8
9
  },
9
10
  minAmount: {
10
11
  type: Number,
@@ -18,9 +19,11 @@ const waterMeterSettingsSchema = new mongoose.Schema({
18
19
  },
19
20
  lowThreshold: {
20
21
  type: Number,
22
+ default: 0
21
23
  },
22
24
  highThreshold: {
23
25
  type: Number,
26
+ default: 0
24
27
  },
25
28
  gracePeriod: {
26
29
  type: Number,
@@ -71,8 +74,9 @@ const waterMeterSettingsSchema = new mongoose.Schema({
71
74
  default: 0
72
75
  },
73
76
 
74
- // Updated notification structure
77
+ // Updated notification structure - separated concerns
75
78
  notifications: {
79
+ // Usage and billing notifications
76
80
  usageAlerts: {
77
81
  enabled: {
78
82
  type: Boolean,
@@ -96,22 +100,28 @@ const waterMeterSettingsSchema = new mongoose.Schema({
96
100
  type: Boolean,
97
101
  default: false
98
102
  }
103
+ },
104
+ // Payment reminder notifications
105
+ paymentReminders: {
106
+ enabled: {
107
+ type: Boolean,
108
+ default: false
109
+ },
110
+ daysBeforeDue: {
111
+ type: Number,
112
+ default: 3,
113
+ min: 1,
114
+ max: 30
115
+ },
116
+ frequency: {
117
+ type: String,
118
+ enum: ['daily', 'weekly', 'once'],
119
+ default: 'once'
120
+ }
99
121
  }
100
122
  },
101
- dailyNotifications: {
102
- type: Boolean,
103
- default: false
104
- },
105
- weeklyNotifications: {
106
- type: Boolean,
107
- default: false
108
- },
109
- allNotifications: {
110
- type: Boolean,
111
- default: false
112
- },
113
123
 
114
- // Add other charges section
124
+ // Other charges section
115
125
  otherCharges: {
116
126
  type: String,
117
127
  enum: ['yes', 'no'],
@@ -132,7 +142,7 @@ const waterMeterSettingsSchema = new mongoose.Schema({
132
142
  default: 0
133
143
  },
134
144
 
135
- // PAYMENTS
145
+ // Payment methods
136
146
  paymentMethods: {
137
147
  mobilePayment: {
138
148
  status: {
@@ -156,7 +166,7 @@ const waterMeterSettingsSchema = new mongoose.Schema({
156
166
  }
157
167
  },
158
168
 
159
- // Biller Address Information for Invoice Generation
169
+ // Biller address for invoices
160
170
  billerAddress: {
161
171
  name: {
162
172
  type: String,
@@ -193,6 +203,7 @@ const waterMeterSettingsSchema = new mongoose.Schema({
193
203
  }
194
204
  },
195
205
 
206
+ // GL accounts for accounting entries
196
207
  glAccounts: {
197
208
  invoice: {
198
209
  debit: {