payservedb 3.7.1 → 3.7.3
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/index.js +2 -1
- package/package.json +1 -1
- package/src/models/invoice.js +51 -5
- package/src/models/user_account.js +60 -0
package/index.js
CHANGED
|
@@ -121,7 +121,8 @@ const models = {
|
|
|
121
121
|
InvoiceSettings: require('./src/models/levy_invoice_settings'),
|
|
122
122
|
Account: require('./src/models/account'),
|
|
123
123
|
FacilityPaymentDetails: require('./src/models/facility_payment_details'),
|
|
124
|
-
DefaultPaymentDetails: require('./src/models/default_payment_details')
|
|
124
|
+
DefaultPaymentDetails: require('./src/models/default_payment_details'),
|
|
125
|
+
UserAccount: require('./src/models/user_account')
|
|
125
126
|
|
|
126
127
|
|
|
127
128
|
};
|
package/package.json
CHANGED
package/src/models/invoice.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const mongoose = require("mongoose");
|
|
2
2
|
|
|
3
|
-
// Define the schema for Invoice
|
|
4
3
|
const invoiceSchema = new mongoose.Schema(
|
|
5
4
|
{
|
|
6
5
|
invoiceNumber: {
|
|
@@ -14,9 +13,19 @@ const invoiceSchema = new mongoose.Schema(
|
|
|
14
13
|
unique: true,
|
|
15
14
|
},
|
|
16
15
|
client: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
clientId: {
|
|
17
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
18
|
+
ref: "Customer",
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
firstName: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
lastName: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true
|
|
28
|
+
}
|
|
20
29
|
},
|
|
21
30
|
facility: {
|
|
22
31
|
id: {
|
|
@@ -48,6 +57,16 @@ const invoiceSchema = new mongoose.Schema(
|
|
|
48
57
|
type: Number,
|
|
49
58
|
required: true,
|
|
50
59
|
},
|
|
60
|
+
amountPaid: {
|
|
61
|
+
type: Number,
|
|
62
|
+
default: 0,
|
|
63
|
+
min: 0,
|
|
64
|
+
},
|
|
65
|
+
overpay: {
|
|
66
|
+
type: Number,
|
|
67
|
+
default: 0,
|
|
68
|
+
min: 0,
|
|
69
|
+
},
|
|
51
70
|
issueDate: {
|
|
52
71
|
type: Date,
|
|
53
72
|
required: true,
|
|
@@ -81,6 +100,21 @@ const invoiceSchema = new mongoose.Schema(
|
|
|
81
100
|
notificationTypes: [String],
|
|
82
101
|
},
|
|
83
102
|
],
|
|
103
|
+
reconciliationHistory: [{
|
|
104
|
+
date: { type: Date, required: true },
|
|
105
|
+
amount: { type: Number, required: true },
|
|
106
|
+
type: {
|
|
107
|
+
type: String,
|
|
108
|
+
enum: ['payment', 'overpay-transfer', 'balance-deduction', 'overpay-received'],
|
|
109
|
+
required: true
|
|
110
|
+
},
|
|
111
|
+
sourceInvoice: String,
|
|
112
|
+
destinationInvoice: String,
|
|
113
|
+
paymentReference: String,
|
|
114
|
+
paymentCompletion: String,
|
|
115
|
+
remainingBalance: Number,
|
|
116
|
+
notes: String
|
|
117
|
+
}],
|
|
84
118
|
paymentDetails: {
|
|
85
119
|
paymentStatus: { type: String, required: true },
|
|
86
120
|
paymentMethod: { type: String },
|
|
@@ -93,6 +127,18 @@ const invoiceSchema = new mongoose.Schema(
|
|
|
93
127
|
}
|
|
94
128
|
);
|
|
95
129
|
|
|
96
|
-
|
|
130
|
+
// Add indexes for frequently queried fields
|
|
131
|
+
invoiceSchema.index({ accountNumber: 1 });
|
|
132
|
+
invoiceSchema.index({ status: 1 });
|
|
133
|
+
invoiceSchema.index({ 'client.clientId': 1, status: 1 });
|
|
134
|
+
invoiceSchema.index({ 'reconciliationHistory.paymentReference': 1 });
|
|
135
|
+
invoiceSchema.index({ issueDate: -1 });
|
|
136
|
+
|
|
137
|
+
// Add virtual field for calculating balance
|
|
138
|
+
invoiceSchema.virtual('calculatedBalance').get(function () {
|
|
139
|
+
return this.totalAmount - (this.amountPaid || 0);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const Invoice = mongoose.model('Invoice', invoiceSchema);
|
|
97
143
|
|
|
98
144
|
module.exports = Invoice;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const userAccountSchema = new mongoose.Schema({
|
|
4
|
+
account_no: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: true,
|
|
7
|
+
unique: true,
|
|
8
|
+
trim: true
|
|
9
|
+
},
|
|
10
|
+
customerId: {
|
|
11
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
12
|
+
ref: 'Customer',
|
|
13
|
+
},
|
|
14
|
+
customerName: {
|
|
15
|
+
type: String,
|
|
16
|
+
required: true,
|
|
17
|
+
trim: true
|
|
18
|
+
},
|
|
19
|
+
phoneNumber: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: true,
|
|
22
|
+
trim: true
|
|
23
|
+
},
|
|
24
|
+
payment_type: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: true,
|
|
27
|
+
enum: ['Postpaid', 'Prepaid']
|
|
28
|
+
},
|
|
29
|
+
previousReading: {
|
|
30
|
+
type: Number,
|
|
31
|
+
required: true,
|
|
32
|
+
default: 0
|
|
33
|
+
},
|
|
34
|
+
currentReading: {
|
|
35
|
+
type: Number,
|
|
36
|
+
required: true
|
|
37
|
+
},
|
|
38
|
+
status: {
|
|
39
|
+
type: String,
|
|
40
|
+
required: true,
|
|
41
|
+
enum: ['Active', 'Inactive'],
|
|
42
|
+
default: 'Active'
|
|
43
|
+
},
|
|
44
|
+
created_on: {
|
|
45
|
+
type: Date,
|
|
46
|
+
required: true,
|
|
47
|
+
default: Date.now
|
|
48
|
+
},
|
|
49
|
+
meter_id: {
|
|
50
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
51
|
+
ref: 'Meter',
|
|
52
|
+
required: true
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
timestamps: true
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const UserAccount = mongoose.model('UserAccount', userAccountSchema);
|
|
59
|
+
|
|
60
|
+
module.exports = UserAccount;
|