payservedb 5.7.0 → 5.7.2
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 +1 -1
- package/src/models/assetsAssignment.js +74 -0
- package/src/models/levy.js +92 -38
- package/src/models/tickets.js +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const assetAssignmentSchema = new mongoose.Schema({
|
|
4
|
+
assetId: {
|
|
5
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
6
|
+
ref: 'Asset',
|
|
7
|
+
required: true,
|
|
8
|
+
},
|
|
9
|
+
serviceVendorId: {
|
|
10
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
11
|
+
ref: 'ServiceVendor',
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
facilityId: {
|
|
15
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
16
|
+
ref: 'Facility',
|
|
17
|
+
required: true,
|
|
18
|
+
},
|
|
19
|
+
assignedDate: {
|
|
20
|
+
type: Date,
|
|
21
|
+
default: Date.now,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
unassignedDate: {
|
|
25
|
+
type: Date,
|
|
26
|
+
},
|
|
27
|
+
status: {
|
|
28
|
+
type: String,
|
|
29
|
+
enum: ['Active', 'Inactive', 'Completed'],
|
|
30
|
+
default: 'Active',
|
|
31
|
+
},
|
|
32
|
+
notes: {
|
|
33
|
+
type: String,
|
|
34
|
+
},
|
|
35
|
+
priority: {
|
|
36
|
+
type: String,
|
|
37
|
+
enum: ['Low', 'Medium', 'High', 'Critical'],
|
|
38
|
+
default: 'Medium',
|
|
39
|
+
},
|
|
40
|
+
serviceType: {
|
|
41
|
+
type: String,
|
|
42
|
+
enum: ['Maintenance', 'Repair', 'Installation', 'Inspection', 'Other'],
|
|
43
|
+
},
|
|
44
|
+
estimatedCompletionDate: {
|
|
45
|
+
type: Date,
|
|
46
|
+
},
|
|
47
|
+
actualCompletionDate: {
|
|
48
|
+
type: Date,
|
|
49
|
+
},
|
|
50
|
+
cost: {
|
|
51
|
+
type: Number,
|
|
52
|
+
min: 0,
|
|
53
|
+
},
|
|
54
|
+
}, {
|
|
55
|
+
timestamps: true,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Compound index to ensure unique active assignments per asset-vendor pair
|
|
59
|
+
assetAssignmentSchema.index(
|
|
60
|
+
{ assetId: 1, serviceVendorId: 1, status: 1 },
|
|
61
|
+
{
|
|
62
|
+
unique: true,
|
|
63
|
+
partialFilterExpression: { status: 'Active' }
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Index for efficient querying by facility
|
|
68
|
+
assetAssignmentSchema.index({ facilityId: 1 });
|
|
69
|
+
|
|
70
|
+
// Index for date-based queries
|
|
71
|
+
assetAssignmentSchema.index({ assignedDate: 1 });
|
|
72
|
+
assetAssignmentSchema.index({ estimatedCompletionDate: 1 });
|
|
73
|
+
|
|
74
|
+
module.exports = mongoose.model('AssetAssignment', assetAssignmentSchema);
|
package/src/models/levy.js
CHANGED
|
@@ -37,18 +37,16 @@ const levySchema = new mongoose.Schema(
|
|
|
37
37
|
type: String,
|
|
38
38
|
required: true,
|
|
39
39
|
},
|
|
40
|
-
// New billing type field
|
|
41
40
|
billingType: {
|
|
42
41
|
type: String,
|
|
43
42
|
enum: ['Prepaid', 'Postpaid'],
|
|
44
43
|
required: true,
|
|
45
44
|
default: 'Postpaid'
|
|
46
45
|
},
|
|
47
|
-
// Fields from levy contract
|
|
48
46
|
currency: {
|
|
49
47
|
type: mongoose.Schema.Types.ObjectId,
|
|
50
48
|
ref: "Currency",
|
|
51
|
-
required:
|
|
49
|
+
required: true,
|
|
52
50
|
},
|
|
53
51
|
mobilePayment: {
|
|
54
52
|
type: Boolean,
|
|
@@ -57,71 +55,56 @@ const levySchema = new mongoose.Schema(
|
|
|
57
55
|
},
|
|
58
56
|
paymentMethodId: {
|
|
59
57
|
type: mongoose.Schema.Types.ObjectId,
|
|
58
|
+
ref: "FacilityPaymentDetails",
|
|
60
59
|
required: false,
|
|
61
60
|
},
|
|
62
|
-
// New bank payment field
|
|
63
61
|
bankPayment: {
|
|
64
62
|
type: Boolean,
|
|
65
63
|
default: false,
|
|
66
64
|
required: false,
|
|
67
65
|
},
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
trim: true,
|
|
74
|
-
},
|
|
75
|
-
accountName: {
|
|
76
|
-
type: String,
|
|
77
|
-
required: false,
|
|
78
|
-
trim: true,
|
|
79
|
-
},
|
|
80
|
-
accountNumber: {
|
|
81
|
-
type: String,
|
|
82
|
-
required: false,
|
|
83
|
-
trim: true,
|
|
84
|
-
},
|
|
85
|
-
branch: {
|
|
86
|
-
type: String,
|
|
87
|
-
required: false,
|
|
88
|
-
trim: true,
|
|
89
|
-
},
|
|
90
|
-
swiftCode: {
|
|
91
|
-
type: String,
|
|
92
|
-
required: false,
|
|
93
|
-
trim: true,
|
|
94
|
-
}
|
|
66
|
+
// Reference to BankDetails document
|
|
67
|
+
bankAccountId: {
|
|
68
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
69
|
+
ref: "BankDetails",
|
|
70
|
+
required: false,
|
|
95
71
|
},
|
|
96
|
-
//
|
|
72
|
+
// Reference to BillerAddress document
|
|
73
|
+
billerAddressId: {
|
|
74
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
75
|
+
ref: "BillerAddress",
|
|
76
|
+
required: true,
|
|
77
|
+
},
|
|
78
|
+
// GL Account Configuration
|
|
97
79
|
glAccounts: {
|
|
98
80
|
invoice: {
|
|
99
81
|
debit: {
|
|
100
82
|
type: mongoose.Schema.Types.ObjectId,
|
|
101
83
|
ref: "GLAccount",
|
|
102
|
-
required:
|
|
84
|
+
required: true,
|
|
103
85
|
},
|
|
104
86
|
credit: {
|
|
105
87
|
type: mongoose.Schema.Types.ObjectId,
|
|
106
88
|
ref: "GLAccount",
|
|
107
|
-
required:
|
|
89
|
+
required: true,
|
|
108
90
|
}
|
|
109
91
|
},
|
|
110
92
|
payment: {
|
|
111
93
|
debit: {
|
|
112
94
|
type: mongoose.Schema.Types.ObjectId,
|
|
113
95
|
ref: "GLAccount",
|
|
114
|
-
required:
|
|
96
|
+
required: true,
|
|
115
97
|
},
|
|
116
98
|
credit: {
|
|
117
99
|
type: mongoose.Schema.Types.ObjectId,
|
|
118
100
|
ref: "GLAccount",
|
|
119
|
-
required:
|
|
101
|
+
required: true,
|
|
120
102
|
}
|
|
121
103
|
}
|
|
122
104
|
},
|
|
123
105
|
disabled: {
|
|
124
106
|
type: Boolean,
|
|
107
|
+
default: false,
|
|
125
108
|
required: false,
|
|
126
109
|
},
|
|
127
110
|
facilityId: {
|
|
@@ -129,13 +112,13 @@ const levySchema = new mongoose.Schema(
|
|
|
129
112
|
ref: "Facility",
|
|
130
113
|
required: true,
|
|
131
114
|
},
|
|
132
|
-
//
|
|
115
|
+
// Reminder reference
|
|
133
116
|
reminderId: {
|
|
134
117
|
type: mongoose.Schema.Types.ObjectId,
|
|
135
118
|
ref: 'Reminder',
|
|
136
119
|
required: false
|
|
137
120
|
},
|
|
138
|
-
//
|
|
121
|
+
// Penalty reference
|
|
139
122
|
penaltyId: {
|
|
140
123
|
type: mongoose.Schema.Types.ObjectId,
|
|
141
124
|
ref: 'Penalty',
|
|
@@ -147,6 +130,77 @@ const levySchema = new mongoose.Schema(
|
|
|
147
130
|
}
|
|
148
131
|
);
|
|
149
132
|
|
|
133
|
+
// Add virtuals for populated references
|
|
134
|
+
levySchema.virtual('bankAccount', {
|
|
135
|
+
ref: 'BankDetails',
|
|
136
|
+
localField: 'bankAccountId',
|
|
137
|
+
foreignField: '_id',
|
|
138
|
+
justOne: true
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
levySchema.virtual('billerAddress', {
|
|
142
|
+
ref: 'BillerAddress',
|
|
143
|
+
localField: 'billerAddressId',
|
|
144
|
+
foreignField: '_id',
|
|
145
|
+
justOne: true
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
levySchema.virtual('reminder', {
|
|
149
|
+
ref: 'Reminder',
|
|
150
|
+
localField: 'reminderId',
|
|
151
|
+
foreignField: '_id',
|
|
152
|
+
justOne: true
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
levySchema.virtual('penalty', {
|
|
156
|
+
ref: 'Penalty',
|
|
157
|
+
localField: 'penaltyId',
|
|
158
|
+
foreignField: '_id',
|
|
159
|
+
justOne: true
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Pre-save validation middleware
|
|
163
|
+
levySchema.pre('save', function (next) {
|
|
164
|
+
// Validate bank payment requirements
|
|
165
|
+
if (this.bankPayment && !this.bankAccountId) {
|
|
166
|
+
const error = new Error('Bank account is required when bank payment is enabled');
|
|
167
|
+
return next(error);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Validate mobile payment requirements
|
|
171
|
+
if (this.mobilePayment && !this.paymentMethodId) {
|
|
172
|
+
const error = new Error('Payment method is required when mobile payment is enabled');
|
|
173
|
+
return next(error);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Validate GL accounts
|
|
177
|
+
if (!this.glAccounts?.invoice?.debit || !this.glAccounts?.invoice?.credit ||
|
|
178
|
+
!this.glAccounts?.payment?.debit || !this.glAccounts?.payment?.credit) {
|
|
179
|
+
const error = new Error('All GL accounts (invoice and payment, debit and credit) are required');
|
|
180
|
+
return next(error);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
next();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Add indexes for better performance
|
|
187
|
+
levySchema.index({ facilityId: 1 });
|
|
188
|
+
levySchema.index({ levyType: 1 });
|
|
189
|
+
levySchema.index({ disabled: 1 });
|
|
190
|
+
levySchema.index({ bankAccountId: 1 });
|
|
191
|
+
levySchema.index({ billerAddressId: 1 });
|
|
192
|
+
levySchema.index({ reminderId: 1 });
|
|
193
|
+
levySchema.index({ penaltyId: 1 });
|
|
194
|
+
levySchema.index({ createdAt: -1 });
|
|
195
|
+
|
|
196
|
+
// Compound indexes
|
|
197
|
+
levySchema.index({ facilityId: 1, disabled: 1 });
|
|
198
|
+
levySchema.index({ facilityId: 1, levyType: 1 });
|
|
199
|
+
|
|
200
|
+
// Ensure virtual fields are serialized
|
|
201
|
+
levySchema.set('toJSON', { virtuals: true });
|
|
202
|
+
levySchema.set('toObject', { virtuals: true });
|
|
203
|
+
|
|
150
204
|
// Compile the model from the schema
|
|
151
205
|
const Levy = mongoose.model("Levy", levySchema);
|
|
152
206
|
|
package/src/models/tickets.js
CHANGED
|
@@ -37,7 +37,7 @@ const ticketSchema = new mongoose.Schema({
|
|
|
37
37
|
},
|
|
38
38
|
status: {
|
|
39
39
|
type: String,
|
|
40
|
-
enum: ['open', '
|
|
40
|
+
enum: ['open', 'under review', 'ongoing', 'resolved', 'cancelled', 'closed'],
|
|
41
41
|
required: true,
|
|
42
42
|
default: 'open',
|
|
43
43
|
},
|