payservedb 4.4.6 → 4.4.8

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.
Files changed (82) hide show
  1. package/.env +2 -2
  2. package/index.js +152 -152
  3. package/package.json +17 -17
  4. package/src/models/account.js +36 -36
  5. package/src/models/analog_water_billing.js +58 -58
  6. package/src/models/apilog.js +18 -18
  7. package/src/models/archivedapilog.js +18 -18
  8. package/src/models/archivedauditlog.js +83 -83
  9. package/src/models/asset.js +34 -34
  10. package/src/models/auditlog.js +83 -83
  11. package/src/models/bankdetails.js +40 -40
  12. package/src/models/budget.js +33 -33
  13. package/src/models/budgetCategory.js +19 -19
  14. package/src/models/campaigns.js +72 -77
  15. package/src/models/cashpayment.js +263 -186
  16. package/src/models/combinedUnits.js +62 -62
  17. package/src/models/company.js +53 -53
  18. package/src/models/country_tax.js +42 -42
  19. package/src/models/currency_settings.js +39 -39
  20. package/src/models/customer.js +178 -181
  21. package/src/models/default_payment_details.js +17 -17
  22. package/src/models/dutyroster.js +39 -39
  23. package/src/models/email.js +24 -24
  24. package/src/models/entry_exit.js +53 -53
  25. package/src/models/expense.js +55 -55
  26. package/src/models/facility.js +59 -58
  27. package/src/models/facility_payment_details.js +20 -20
  28. package/src/models/facilityasset.js +25 -25
  29. package/src/models/faq.js +18 -18
  30. package/src/models/guard.js +47 -47
  31. package/src/models/handover.js +241 -241
  32. package/src/models/invoice.js +252 -252
  33. package/src/models/item_inspection.js +67 -67
  34. package/src/models/leaseagreement.js +156 -167
  35. package/src/models/leasetemplate.js +17 -17
  36. package/src/models/levy.js +72 -72
  37. package/src/models/levy_invoice_settings.js +26 -26
  38. package/src/models/levycontract.js +65 -65
  39. package/src/models/levytype.js +23 -23
  40. package/src/models/maintenance_service_vendor.js +38 -38
  41. package/src/models/maintenance_services.js +17 -17
  42. package/src/models/maintenancerequisition.js +31 -31
  43. package/src/models/message.js +38 -38
  44. package/src/models/module.js +21 -21
  45. package/src/models/notification.js +24 -24
  46. package/src/models/penalty.js +76 -76
  47. package/src/models/refresh_token.js +23 -23
  48. package/src/models/reminder.js +161 -161
  49. package/src/models/report.js +13 -13
  50. package/src/models/resident.js +121 -121
  51. package/src/models/service_charge_invoice_upload.js +42 -42
  52. package/src/models/service_charge_payments.js +27 -27
  53. package/src/models/servicerequest.js +55 -55
  54. package/src/models/settings.js +62 -62
  55. package/src/models/smart_meter_daily_consumption.js +44 -44
  56. package/src/models/sms_africastalking.js +20 -20
  57. package/src/models/sms_meliora.js +16 -16
  58. package/src/models/staff.js +36 -36
  59. package/src/models/stocksandspare.js +34 -34
  60. package/src/models/tickets.js +109 -109
  61. package/src/models/unitasset.js +25 -25
  62. package/src/models/units.js +70 -70
  63. package/src/models/user.js +94 -94
  64. package/src/models/valueaddedservices.js +36 -36
  65. package/src/models/vas_invoices_upload.js +50 -50
  66. package/src/models/vas_payments.js +24 -24
  67. package/src/models/vasinvoice.js +159 -159
  68. package/src/models/vasvendor.js +57 -57
  69. package/src/models/visitLog.js +86 -86
  70. package/src/models/visitor.js +63 -63
  71. package/src/models/waitlist.js +45 -45
  72. package/src/models/water_invoice.js +192 -192
  73. package/src/models/water_meter_account.js +74 -73
  74. package/src/models/water_meter_communication.js +17 -17
  75. package/src/models/water_meter_concentrator.js +59 -59
  76. package/src/models/water_meter_iot_cards.js +34 -34
  77. package/src/models/water_meter_manufacturer.js +35 -35
  78. package/src/models/water_meter_settings.js +88 -101
  79. package/src/models/water_meter_size.js +15 -15
  80. package/src/models/water_meters.js +110 -110
  81. package/src/models/water_meters_delivery.js +76 -76
  82. package/src/models/workorder.js +49 -49
@@ -1,78 +1,73 @@
1
- const mongoose = require('mongoose');
2
-
3
- const CampaignSchema = new mongoose.Schema({
4
- facilityId: {
5
- type: mongoose.Schema.Types.ObjectId,
6
- ref: 'Facility',
7
- required: true,
8
- },
9
- name: {
10
- type: String,
11
- required: true,
12
- trim: true,
13
- maxlength: 100
14
- },
15
- objective: {
16
- type: String,
17
- enum: ['Brand Awareness', 'Lead Generation', 'Sales', 'Engagement'],
18
- required: true
19
- },
20
- startDate: {
21
- type: Date,
22
- required: true
23
- },
24
- endDate: {
25
- type: Date,
26
- required: true,
27
- validate: {
28
- validator: function (value) {
29
- return this.startDate <= value;
30
- },
31
- message: 'End date must be after or equal to start date'
32
- }
33
- },
34
- targetAudience: {
35
- type: String,
36
- required: true,
37
- trim: true,
38
- maxlength: 200
39
- },
40
- channels: {
41
- type: [String],
42
- enum: ['Email', 'Social Media', 'SMS', 'Ads'],
43
- required: true
44
- },
45
- status: {
46
- type: String,
47
- enum: ['Draft', 'Ongoing', 'Completed'],
48
- default: 'Draft'
49
- },
50
- description: {
51
- type: String,
52
- trim: true,
53
- maxlength: 500
54
- },
55
- message: {
56
- type: String,
57
- trim: true
58
- },
59
- createdAt: {
60
- type: Date,
61
- default: Date.now
62
- },
63
- updatedAt: {
64
- type: Date,
65
- default: Date.now
66
- }
67
- }, {
68
- timestamps: true
69
- });
70
-
71
- // Ensure at least one channel is selected
72
- CampaignSchema.path('channels').validate(function (value) {
73
- return value.length > 0;
74
- }, 'At least one channel must be selected');
75
-
76
- const Campaign = mongoose.model('Campaign', CampaignSchema);
77
-
1
+ const mongoose = require('mongoose');
2
+
3
+ const CampaignSchema = new mongoose.Schema({
4
+ facilityId: {
5
+ type: mongoose.Schema.Types.ObjectId,
6
+ ref: 'Facility',
7
+ required: true,
8
+ },
9
+ name: {
10
+ type: String,
11
+ required: true,
12
+ trim: true,
13
+ maxlength: 100
14
+ },
15
+ objective: {
16
+ type: String,
17
+ enum: ['Brand Awareness', 'Lead Generation', 'Sales', 'Engagement'],
18
+ required: true
19
+ },
20
+ startDate: {
21
+ type: Date,
22
+ required: true
23
+ },
24
+ endDate: {
25
+ type: Date,
26
+ required: true,
27
+ validate: {
28
+ validator: function (value) {
29
+ return this.startDate <= value;
30
+ },
31
+ message: 'End date must be after or equal to start date'
32
+ }
33
+ },
34
+ targetAudience: {
35
+ type: String,
36
+ required: true,
37
+ trim: true,
38
+ maxlength: 200
39
+ },
40
+ channels: [{
41
+ type: String,
42
+ enum: ['Email', 'Social Media', 'SMS', 'Ads'],
43
+ required: true
44
+ }],
45
+ status: {
46
+ type: String,
47
+ enum: ['Draft', 'Ongoing', 'Completed'],
48
+ default: 'Draft'
49
+ }, description: {
50
+ type: String,
51
+ trim: true,
52
+ maxlength: 500
53
+ },
54
+ createdAt: {
55
+ type: Date,
56
+ default: Date.now
57
+ },
58
+ updatedAt: {
59
+ type: Date,
60
+ default: Date.now
61
+ }
62
+ }, {
63
+ timestamps: true
64
+ });
65
+
66
+ // Ensure at least one channel is selected
67
+ CampaignSchema.path('channels').validate(function (value) {
68
+ return value.length > 0;
69
+ }, 'At least one channel must be selected');
70
+
71
+ const Campaign = mongoose.model('Campaign', CampaignSchema);
72
+
78
73
  module.exports =Campaign;
@@ -1,186 +1,263 @@
1
- // File: models/CashPayment.js
2
- const mongoose = require('mongoose');
3
-
4
- // Define the schema for Cash Payments
5
- const cashPaymentSchema = new mongoose.Schema({
6
- // Payment reference details
7
- paymentReference: {
8
- type: String,
9
- required: true,
10
- unique: true,
11
- trim: true
12
- },
13
- facilityId: {
14
- type: mongoose.Schema.Types.ObjectId,
15
- ref: 'Facility',
16
- required: true
17
- },
18
- // Invoice details
19
- invoice: {
20
- invoiceId: {
21
- type: mongoose.Schema.Types.ObjectId,
22
- ref: 'Invoice',
23
- required: true
24
- },
25
- invoiceNumber: {
26
- type: String,
27
- required: true,
28
- trim: true
29
- },
30
- accountNumber: {
31
- type: String,
32
- required: true,
33
- trim: true
34
- },
35
- totalAmount: {
36
- type: Number,
37
- required: true,
38
- min: 0
39
- }
40
- },
41
- // Client details
42
- client: {
43
- clientId: {
44
- type: mongoose.Schema.Types.ObjectId,
45
- ref: 'Customer',
46
- required: true
47
- },
48
- firstName: {
49
- type: String,
50
- required: true
51
- },
52
- lastName: {
53
- type: String,
54
- required: true
55
- }
56
- },
57
- // Payment details
58
- paymentAmount: {
59
- type: Number,
60
- required: true,
61
- min: 0
62
- },
63
- currency: {
64
- id: {
65
- type: mongoose.Schema.Types.ObjectId,
66
- ref: 'Currency',
67
- required: true
68
- },
69
- name: {
70
- type: String,
71
- required: true
72
- },
73
- code: {
74
- type: String,
75
- required: true,
76
- uppercase: true,
77
- minlength: 3,
78
- maxlength: 3
79
- }
80
- },
81
- paymentDate: {
82
- type: Date,
83
- required: true,
84
- default: Date.now
85
- },
86
- receivedBy: {
87
- type: mongoose.Schema.Types.ObjectId,
88
- ref: 'User',
89
- required: true
90
- },
91
- receiptNumber: {
92
- type: String,
93
- required: true,
94
- unique: true
95
- },
96
- paymentMethod: {
97
- type: String,
98
- enum: ['Cash', 'Check', 'Bank Transfer'],
99
- default: 'Cash'
100
- },
101
- paymentDetails: {
102
- checkNumber: String,
103
- bankName: String,
104
- transferReference: String,
105
- notes: String
106
- },
107
- // Reconciliation status
108
- reconciliationStatus: {
109
- type: String,
110
- enum: ['Pending', 'Matched', 'Partial', 'Overpaid', 'Voided'],
111
- default: 'Pending'
112
- },
113
- // Approval details
114
- approvalStatus: {
115
- type: String,
116
- enum: ['Pending', 'Approved', 'Rejected'],
117
- default: 'Pending'
118
- },
119
- approvedBy: {
120
- userId: {
121
- type: mongoose.Schema.Types.ObjectId,
122
- ref: 'User'
123
- },
124
- name: String,
125
- approvalDate: Date,
126
- comments: String
127
- },
128
- // Reconciliation details
129
- reconciliationDetails: {
130
- appliedAmount: {
131
- type: Number,
132
- default: 0
133
- },
134
- overpayAmount: {
135
- type: Number,
136
- default: 0
137
- },
138
- reconciliationDate: Date,
139
- reconciledBy: {
140
- type: mongoose.Schema.Types.ObjectId,
141
- ref: 'User'
142
- }
143
- },
144
- // Exchange rate (for payments in different currencies)
145
- exchangeRate: {
146
- rate: {
147
- type: Number,
148
- default: 1
149
- },
150
- originalCurrency: {
151
- code: String,
152
- amount: Number
153
- }
154
- },
155
- // Additional fields
156
- isVoided: {
157
- type: Boolean,
158
- default: false
159
- },
160
- voidReason: {
161
- type: String
162
- },
163
- voidedBy: {
164
- type: mongoose.Schema.Types.ObjectId,
165
- ref: 'User'
166
- },
167
- voidDate: Date,
168
- attachments: [{
169
- fileName: String,
170
- fileUrl: String,
171
- uploadDate: {
172
- type: Date,
173
- default: Date.now
174
- },
175
- uploadedBy: {
176
- type: mongoose.Schema.Types.ObjectId,
177
- ref: 'User'
178
- }
179
- }]
180
- }, {
181
- timestamps: true
182
- });
183
-
184
- const CashPayment = mongoose.model('CashPayment', cashPaymentSchema);
185
-
186
- module.exports = CashPayment;
1
+ const mongoose = require('mongoose');
2
+
3
+ const cashPaymentSchema = new mongoose.Schema(
4
+ {
5
+ paymentReference: {
6
+ type: String,
7
+ required: true,
8
+ unique: true,
9
+ trim: true
10
+ },
11
+ receiptNumber: {
12
+ type: String,
13
+ required: true,
14
+ unique: true,
15
+ trim: true
16
+ },
17
+ invoice: {
18
+ invoiceId: {
19
+ type: mongoose.Schema.Types.ObjectId,
20
+ ref: "Invoice",
21
+ required: true
22
+ },
23
+ invoiceNumber: {
24
+ type: String,
25
+ required: true,
26
+ trim: true
27
+ },
28
+ accountNumber: {
29
+ type: String,
30
+ trim: true
31
+ }
32
+ },
33
+ client: {
34
+ clientId: {
35
+ type: mongoose.Schema.Types.ObjectId,
36
+ ref: "Customer",
37
+ required: true
38
+ },
39
+ firstName: {
40
+ type: String,
41
+ required: true,
42
+ trim: true
43
+ },
44
+ lastName: {
45
+ type: String,
46
+ required: true,
47
+ trim: true
48
+ }
49
+ },
50
+ facility: {
51
+ id: {
52
+ type: mongoose.Schema.Types.ObjectId,
53
+ ref: "Facility",
54
+ required: true
55
+ },
56
+ name: {
57
+ type: String,
58
+ required: true,
59
+ trim: true
60
+ }
61
+ },
62
+ currency: {
63
+ id: {
64
+ type: mongoose.Schema.Types.ObjectId,
65
+ ref: "Currency",
66
+ required: true
67
+ },
68
+ name: {
69
+ type: String,
70
+ required: true,
71
+ trim: true
72
+ },
73
+ code: {
74
+ type: String,
75
+ required: true,
76
+ uppercase: true,
77
+ minlength: 3,
78
+ maxlength: 3
79
+ }
80
+ },
81
+ paymentAmount: {
82
+ type: Number,
83
+ required: true,
84
+ min: 0
85
+ },
86
+ paymentDate: {
87
+ type: Date,
88
+ required: true,
89
+ default: Date.now
90
+ },
91
+ paymentMethod: {
92
+ type: String,
93
+ enum: ['cash', 'bank-transfer', 'cheque'],
94
+ default: 'cash'
95
+ },
96
+ exchangeRate: {
97
+ rate: {
98
+ type: Number,
99
+ default: 1
100
+ },
101
+ sourceCurrency: {
102
+ type: String,
103
+ uppercase: true,
104
+ minlength: 3,
105
+ maxlength: 3
106
+ },
107
+ targetCurrency: {
108
+ type: String,
109
+ uppercase: true,
110
+ minlength: 3,
111
+ maxlength: 3
112
+ },
113
+ conversionDate: Date
114
+ },
115
+ approvalStatus: {
116
+ type: String,
117
+ enum: ['Pending', 'Approved', 'Rejected'],
118
+ default: 'Pending'
119
+ },
120
+ approvedBy: {
121
+ userId: mongoose.Schema.Types.ObjectId,
122
+ name: String,
123
+ approvalDate: Date,
124
+ comments: String
125
+ },
126
+ rejectedBy: {
127
+ userId: mongoose.Schema.Types.ObjectId,
128
+ name: String,
129
+ rejectionDate: Date,
130
+ reason: String
131
+ },
132
+ isVoided: {
133
+ type: Boolean,
134
+ default: false
135
+ },
136
+ voidedBy: {
137
+ userId: mongoose.Schema.Types.ObjectId,
138
+ name: String,
139
+ voidDate: Date,
140
+ reason: String
141
+ },
142
+ reconciliationStatus: {
143
+ type: String,
144
+ enum: ['Pending', 'Matched', 'Partial', 'Overpaid', 'Error'],
145
+ default: 'Pending'
146
+ },
147
+ reconciliationDetails: {
148
+ appliedAmount: Number,
149
+ overpayAmount: {
150
+ type: Number,
151
+ default: 0
152
+ },
153
+ reconciliationDate: Date,
154
+ reconciledBy: mongoose.Schema.Types.ObjectId,
155
+ paymentMethod: String, // To store the payment method used during reconciliation
156
+ notes: String
157
+ },
158
+ paymentNotes: String,
159
+ attachments: [
160
+ {
161
+ fileId: mongoose.Schema.Types.ObjectId,
162
+ fileName: String,
163
+ fileType: String,
164
+ uploadDate: Date,
165
+ uploadedBy: mongoose.Schema.Types.ObjectId
166
+ }
167
+ ],
168
+ metadata: {
169
+ createdBy: {
170
+ type: mongoose.Schema.Types.ObjectId,
171
+ required: true
172
+ },
173
+ source: {
174
+ type: String,
175
+ enum: ['manual', 'api', 'import', 'mobile'],
176
+ default: 'manual'
177
+ },
178
+ deviceInfo: {
179
+ deviceId: String,
180
+ deviceType: String,
181
+ ipAddress: String
182
+ }
183
+ }
184
+ },
185
+ {
186
+ timestamps: true
187
+ }
188
+ );
189
+
190
+ // Add indexes for frequently queried fields
191
+ cashPaymentSchema.index({ 'paymentReference': 1 });
192
+ cashPaymentSchema.index({ 'receiptNumber': 1 });
193
+ cashPaymentSchema.index({ 'approvalStatus': 1 });
194
+ cashPaymentSchema.index({ 'isVoided': 1 });
195
+ cashPaymentSchema.index({ 'client.clientId': 1 });
196
+ cashPaymentSchema.index({ 'invoice.invoiceId': 1 });
197
+ cashPaymentSchema.index({ 'facility.id': 1 });
198
+ cashPaymentSchema.index({ 'reconciliationStatus': 1 });
199
+ cashPaymentSchema.index({ 'paymentDate': -1 });
200
+ cashPaymentSchema.index({ 'currency.code': 1 });
201
+ cashPaymentSchema.index({ 'paymentMethod': 1 });
202
+ cashPaymentSchema.index({ 'paymentDate': -1, 'approvalStatus': 1 });
203
+ cashPaymentSchema.index({ 'client.clientId': 1, 'approvalStatus': 1 });
204
+
205
+ // Add virtual properties
206
+ cashPaymentSchema.virtual('clientFullName').get(function () {
207
+ return `${this.client.firstName} ${this.client.lastName}`;
208
+ });
209
+
210
+ // Add instance methods
211
+ cashPaymentSchema.methods.convertCurrency = function (targetCurrencyCode, exchangeRate) {
212
+ if (this.currency.code === targetCurrencyCode) {
213
+ return this.paymentAmount;
214
+ }
215
+ return this.paymentAmount * exchangeRate;
216
+ };
217
+
218
+ // Static methods
219
+ cashPaymentSchema.statics.findByClientId = function (clientId) {
220
+ return this.find({ 'client.clientId': clientId }).sort({ paymentDate: -1 });
221
+ };
222
+
223
+ cashPaymentSchema.statics.findByInvoiceId = function (invoiceId) {
224
+ return this.find({ 'invoice.invoiceId': invoiceId }).sort({ paymentDate: -1 });
225
+ };
226
+
227
+ cashPaymentSchema.statics.findPendingPayments = function (facilityId) {
228
+ return this.find({
229
+ 'facility.id': facilityId,
230
+ 'approvalStatus': 'Pending',
231
+ 'isVoided': false
232
+ }).sort({ paymentDate: -1 });
233
+ };
234
+
235
+ cashPaymentSchema.statics.findOverpaidPayments = function (facilityId) {
236
+ return this.find({
237
+ 'facility.id': facilityId,
238
+ 'approvalStatus': 'Approved',
239
+ 'reconciliationStatus': 'Overpaid',
240
+ 'isVoided': false
241
+ }).sort({ paymentDate: -1 });
242
+ };
243
+
244
+ // Pre-save middleware
245
+ cashPaymentSchema.pre('save', function (next) {
246
+ // If the payment is approved, ensure the reconciliation status is set
247
+ if (this.isModified('approvalStatus') && this.approvalStatus === 'Approved' && this.reconciliationStatus === 'Pending') {
248
+ this.reconciliationStatus = 'Matched'; // Default status when approved
249
+ }
250
+
251
+ // If the payment is voided, clear certain fields
252
+ if (this.isModified('isVoided') && this.isVoided) {
253
+ this.approvalStatus = 'Pending';
254
+ this.reconciliationStatus = 'Pending';
255
+ }
256
+
257
+ next();
258
+ });
259
+
260
+ // Create model (only if not already defined by getModel utility)
261
+ const CashPayment = mongoose.models.CashPayment || mongoose.model('CashPayment', cashPaymentSchema);
262
+
263
+ module.exports = CashPayment;