payservedb 3.9.8 → 3.9.9

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": "3.9.8",
3
+ "version": "3.9.9",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -7,6 +7,11 @@ const vasInvoiceSchema = new mongoose.Schema({
7
7
  required: true,
8
8
  unique: true,
9
9
  },
10
+ accountNumber: {
11
+ type: String,
12
+ required: true,
13
+ unique: true
14
+ },
10
15
  facilityId: {
11
16
  type: mongoose.Schema.Types.ObjectId,
12
17
  required: true
@@ -25,31 +30,131 @@ const vasInvoiceSchema = new mongoose.Schema({
25
30
  },
26
31
  invoiceNote: {
27
32
  type: String,
28
- default: null,
33
+ default: "Payment is due within 30 days",
29
34
  },
30
35
  status: {
31
36
  type: String,
32
37
  required: true,
33
- enum: ['Pending', 'Paid', 'Cancelled', 'Overdue'],
38
+ enum: ['Pending', 'Paid', 'Partially Paid', 'Cancelled', 'Overdue', 'Unpaid'],
39
+ default: 'Pending'
34
40
  },
35
41
  unit: {
36
42
  type: String,
37
43
  required: true
38
44
  },
45
+ serviceName: {
46
+ type: String,
47
+ default: 'Service Fee'
48
+ },
49
+ amountPaid: {
50
+ type: Number,
51
+ default: 0
52
+ },
39
53
  subTotal: {
40
54
  type: Number,
41
55
  required: true,
42
56
  },
43
57
  tax: {
44
58
  type: Number,
59
+ default: 0
45
60
  },
46
61
  amount: {
47
- type: Number
62
+ type: Number,
63
+ required: true
64
+ },
65
+ currency: {
66
+ id: {
67
+ type: mongoose.Schema.Types.ObjectId
68
+ },
69
+ name: {
70
+ type: String,
71
+ default: 'Kenyan Shilling'
72
+ },
73
+ code: {
74
+ type: String,
75
+ default: 'KES'
76
+ },
77
+ symbol: {
78
+ type: String,
79
+ default: 'KSh'
80
+ }
81
+ },
82
+ items: [{
83
+ description: {
84
+ type: String,
85
+ required: true
86
+ },
87
+ quantity: {
88
+ type: Number,
89
+ default: 1
90
+ },
91
+ unitPrice: {
92
+ type: Number,
93
+ required: true
94
+ }
95
+ }],
96
+ reconciliationHistory: [{
97
+ date: {
98
+ type: Date,
99
+ default: Date.now
100
+ },
101
+ amount: {
102
+ type: Number,
103
+ required: true
104
+ },
105
+ type: {
106
+ type: String,
107
+ default: 'Manual'
108
+ },
109
+ paymentReference: String,
110
+ paymentCompletion: {
111
+ type: String,
112
+ default: 'Completed'
113
+ },
114
+ sourceInvoice: String,
115
+ destinationInvoice: String,
116
+ notes: String,
117
+ remainingBalance: Number
118
+ }],
119
+ customerInfo: {
120
+ fullName: {
121
+ type: String,
122
+ default: 'Customer'
123
+ }
124
+ },
125
+ paymentDetails: {
126
+ paymentStatus: {
127
+ type: String,
128
+ enum: ['Pending', 'Completed', 'Failed', 'Partial'],
129
+ default: 'Pending'
130
+ },
131
+ paymentMethod: String,
132
+ paymentDate: Date,
133
+ transactionId: String,
134
+ mobilePayment: {
135
+ type: Boolean,
136
+ default: false
137
+ }
138
+ },
139
+ overpay: {
140
+ type: Number,
141
+ default: 0
48
142
  }
49
143
  }, {
50
144
  timestamps: true
51
145
  });
52
146
 
147
+ // Add pre-save middleware to check if invoice is overdue
148
+ vasInvoiceSchema.pre('save', function (next) {
149
+ if (this.isModified('dueDate') || this.isNew) {
150
+ const today = new Date();
151
+ if (this.dueDate < today && this.status === 'Pending') {
152
+ this.status = 'Overdue';
153
+ }
154
+ }
155
+ next();
156
+ });
157
+
53
158
  const VasInvoice = mongoose.model('VasInvoice', vasInvoiceSchema);
54
159
 
55
- module.exports = VasInvoice;
160
+ module.exports = VasInvoice;