payservedb 4.2.1 → 4.2.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.
Files changed (81) hide show
  1. package/.env +2 -2
  2. package/index.js +151 -151
  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/analog_water_meter.js +68 -68
  7. package/src/models/apilog.js +18 -18
  8. package/src/models/archivedapilog.js +18 -18
  9. package/src/models/archivedauditlog.js +83 -83
  10. package/src/models/asset.js +34 -34
  11. package/src/models/auditlog.js +83 -83
  12. package/src/models/bankdetails.js +40 -40
  13. package/src/models/budget.js +33 -33
  14. package/src/models/budgetCategory.js +19 -19
  15. package/src/models/cashpayment.js +185 -185
  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 -178
  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 +58 -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 +209 -209
  33. package/src/models/leaseagreement.js +156 -156
  34. package/src/models/leasetemplate.js +17 -17
  35. package/src/models/levy.js +72 -72
  36. package/src/models/levy_invoice_settings.js +26 -26
  37. package/src/models/levycontract.js +65 -65
  38. package/src/models/levytype.js +23 -23
  39. package/src/models/maintenance_service_vendor.js +38 -38
  40. package/src/models/maintenance_services.js +17 -17
  41. package/src/models/maintenancerequisition.js +31 -31
  42. package/src/models/message.js +38 -38
  43. package/src/models/module.js +21 -21
  44. package/src/models/notification.js +24 -24
  45. package/src/models/penalty.js +76 -76
  46. package/src/models/refresh_token.js +23 -23
  47. package/src/models/reminder.js +161 -161
  48. package/src/models/report.js +13 -13
  49. package/src/models/resident.js +121 -121
  50. package/src/models/service_charge_invoice_upload.js +42 -42
  51. package/src/models/service_charge_payments.js +27 -27
  52. package/src/models/servicerequest.js +55 -55
  53. package/src/models/settings.js +62 -62
  54. package/src/models/smart_meter_daily_consumption.js +44 -44
  55. package/src/models/smart_water_meter.js +85 -85
  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/user_account.js +80 -80
  65. package/src/models/valueaddedservices.js +36 -36
  66. package/src/models/vas_invoices_upload.js +50 -50
  67. package/src/models/vas_payments.js +24 -24
  68. package/src/models/vasinvoice.js +159 -159
  69. package/src/models/vasvendor.js +57 -57
  70. package/src/models/visitLog.js +86 -86
  71. package/src/models/visitor.js +63 -63
  72. package/src/models/waitlist.js +45 -45
  73. package/src/models/water_invoice.js +192 -192
  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 -84
  79. package/src/models/water_meter_size.js +15 -15
  80. package/src/models/water_meters_delivery.js +76 -76
  81. package/src/models/workorder.js +49 -49
@@ -1,210 +1,210 @@
1
- const mongoose = require("mongoose");
2
-
3
- const invoiceSchema = new mongoose.Schema(
4
- {
5
- invoiceNumber: {
6
- type: String,
7
- required: true,
8
- unique: true,
9
- },
10
- accountNumber: {
11
- type: String,
12
- required: true,
13
- unique: true,
14
- },
15
- client: {
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
- }
29
- },
30
- facility: {
31
- id: {
32
- type: mongoose.Schema.Types.ObjectId,
33
- ref: "Facility",
34
- required: true,
35
- },
36
- name: {
37
- type: String,
38
- required: true
39
- }
40
- },
41
- unit: {
42
- id: { type: mongoose.Schema.Types.ObjectId, ref: "Unit", required: true },
43
- name: { type: String, required: true },
44
- },
45
- currency: {
46
- id: {
47
- type: mongoose.Schema.Types.ObjectId,
48
- ref: "Currency",
49
- required: true
50
- },
51
- name: {
52
- type: String,
53
- required: true
54
- },
55
- code: {
56
- type: String,
57
- required: true,
58
- uppercase: true,
59
- minlength: 3,
60
- maxlength: 3
61
- }
62
- },
63
- items: [
64
- {
65
- description: { type: String, required: true },
66
- quantity: { type: Number, required: true, min: 1 },
67
- unitPrice: { type: Number, required: true, min: 0 },
68
- },
69
- ],
70
- subTotal: {
71
- type: Number,
72
- required: true,
73
- },
74
- tax: {
75
- type: Number,
76
- required: true,
77
- },
78
- totalAmount: {
79
- type: Number,
80
- required: true,
81
- },
82
- amountPaid: {
83
- type: Number,
84
- default: 0,
85
- min: 0,
86
- },
87
- overpay: {
88
- type: Number,
89
- default: 0,
90
- min: 0,
91
- },
92
- issueDate: {
93
- type: Date,
94
- required: true,
95
- },
96
- dueDate: {
97
- type: Date,
98
- required: true,
99
- },
100
- status: {
101
- type: String,
102
- required: true,
103
- enum: ["Unpaid", "Pending", "Paid", "Overdue", "Cancelled", "Partially Paid"],
104
- },
105
- penalty: {
106
- type: Number,
107
- default: 0,
108
- },
109
- whatFor: {
110
- invoiceType: { type: String, required: true },
111
- description: { type: String },
112
- },
113
- invoiceNote: {
114
- type: String,
115
- default: null,
116
- },
117
- // New field for balance brought forward
118
- balanceBroughtForward: {
119
- type: Number,
120
- default: 0,
121
- },
122
- lastReminderSent: Date,
123
- reminderHistory: [
124
- {
125
- sentAt: Date,
126
- reminderId: mongoose.Schema.Types.ObjectId,
127
- notificationTypes: [String],
128
- },
129
- ],
130
- reconciliationHistory: [{
131
- date: { type: Date, required: true },
132
- amount: { type: Number, required: true },
133
- type: {
134
- type: String,
135
- enum: ['payment', 'overpay-transfer', 'balance-deduction', 'overpay-received'],
136
- required: true
137
- },
138
- sourceInvoice: String,
139
- destinationInvoice: String,
140
- paymentReference: String,
141
- paymentCompletion: String,
142
- remainingBalance: Number,
143
- notes: String,
144
- exchangeRate: {
145
- type: Number,
146
- default: 1 // For cross-currency reconciliations
147
- },
148
- originalCurrency: {
149
- code: String, // Original currency code if different from invoice currency
150
- amount: Number // Amount in original currency
151
- }
152
- }],
153
- paymentDetails: {
154
- paymentStatus: { type: String, required: true },
155
- paymentMethod: { type: String },
156
- paymentDate: { type: Date },
157
- transactionId: { type: String },
158
- },
159
- },
160
- {
161
- timestamps: true,
162
- }
163
- );
164
-
165
- // Add indexes for frequently queried fields
166
- invoiceSchema.index({ accountNumber: 1 });
167
- invoiceSchema.index({ status: 1 });
168
- invoiceSchema.index({ 'client.clientId': 1, status: 1 });
169
- invoiceSchema.index({ 'reconciliationHistory.paymentReference': 1 });
170
- invoiceSchema.index({ issueDate: -1 });
171
- invoiceSchema.index({ 'currency.code': 1 }); // Add index for currency code
172
- invoiceSchema.index({ 'currency.id': 1 }); // Add index for currency ID
173
- invoiceSchema.index({ 'currency.code': 1, 'client.clientId': 1, status: 1 }); // Compound index for currency-based queries
174
-
175
- // Add virtual field for calculating balance
176
- invoiceSchema.virtual('calculatedBalance').get(function () {
177
- return this.totalAmount - (this.amountPaid || 0);
178
- });
179
-
180
- // Add method for currency conversion if needed
181
- invoiceSchema.methods.convertAmount = function (amount, fromCurrency, toCurrency, exchangeRate) {
182
- if (fromCurrency === toCurrency) {
183
- return amount;
184
- }
185
- return amount * exchangeRate;
186
- };
187
-
188
- // Add static method to find invoices by currency
189
- invoiceSchema.statics.findByCurrency = function (currencyCode) {
190
- return this.find({ 'currency.code': currencyCode.toUpperCase() });
191
- };
192
-
193
- // Add static method to calculate totals by currency
194
- invoiceSchema.statics.calculateTotalsByCurrency = function (query = {}) {
195
- return this.aggregate([
196
- { $match: query },
197
- {
198
- $group: {
199
- _id: '$currency.code',
200
- totalAmount: { $sum: '$totalAmount' },
201
- totalPaid: { $sum: '$amountPaid' },
202
- count: { $sum: 1 }
203
- }
204
- }
205
- ]);
206
- };
207
-
208
- const Invoice = mongoose.model('Invoice', invoiceSchema);
209
-
1
+ const mongoose = require("mongoose");
2
+
3
+ const invoiceSchema = new mongoose.Schema(
4
+ {
5
+ invoiceNumber: {
6
+ type: String,
7
+ required: true,
8
+ unique: true,
9
+ },
10
+ accountNumber: {
11
+ type: String,
12
+ required: true,
13
+ unique: true,
14
+ },
15
+ client: {
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
+ }
29
+ },
30
+ facility: {
31
+ id: {
32
+ type: mongoose.Schema.Types.ObjectId,
33
+ ref: "Facility",
34
+ required: true,
35
+ },
36
+ name: {
37
+ type: String,
38
+ required: true
39
+ }
40
+ },
41
+ unit: {
42
+ id: { type: mongoose.Schema.Types.ObjectId, ref: "Unit", required: true },
43
+ name: { type: String, required: true },
44
+ },
45
+ currency: {
46
+ id: {
47
+ type: mongoose.Schema.Types.ObjectId,
48
+ ref: "Currency",
49
+ required: true
50
+ },
51
+ name: {
52
+ type: String,
53
+ required: true
54
+ },
55
+ code: {
56
+ type: String,
57
+ required: true,
58
+ uppercase: true,
59
+ minlength: 3,
60
+ maxlength: 3
61
+ }
62
+ },
63
+ items: [
64
+ {
65
+ description: { type: String, required: true },
66
+ quantity: { type: Number, required: true, min: 1 },
67
+ unitPrice: { type: Number, required: true, min: 0 },
68
+ },
69
+ ],
70
+ subTotal: {
71
+ type: Number,
72
+ required: true,
73
+ },
74
+ tax: {
75
+ type: Number,
76
+ required: true,
77
+ },
78
+ totalAmount: {
79
+ type: Number,
80
+ required: true,
81
+ },
82
+ amountPaid: {
83
+ type: Number,
84
+ default: 0,
85
+ min: 0,
86
+ },
87
+ overpay: {
88
+ type: Number,
89
+ default: 0,
90
+ min: 0,
91
+ },
92
+ issueDate: {
93
+ type: Date,
94
+ required: true,
95
+ },
96
+ dueDate: {
97
+ type: Date,
98
+ required: true,
99
+ },
100
+ status: {
101
+ type: String,
102
+ required: true,
103
+ enum: ["Unpaid", "Pending", "Paid", "Overdue", "Cancelled", "Partially Paid"],
104
+ },
105
+ penalty: {
106
+ type: Number,
107
+ default: 0,
108
+ },
109
+ whatFor: {
110
+ invoiceType: { type: String, required: true },
111
+ description: { type: String },
112
+ },
113
+ invoiceNote: {
114
+ type: String,
115
+ default: null,
116
+ },
117
+ // New field for balance brought forward
118
+ balanceBroughtForward: {
119
+ type: Number,
120
+ default: 0,
121
+ },
122
+ lastReminderSent: Date,
123
+ reminderHistory: [
124
+ {
125
+ sentAt: Date,
126
+ reminderId: mongoose.Schema.Types.ObjectId,
127
+ notificationTypes: [String],
128
+ },
129
+ ],
130
+ reconciliationHistory: [{
131
+ date: { type: Date, required: true },
132
+ amount: { type: Number, required: true },
133
+ type: {
134
+ type: String,
135
+ enum: ['payment', 'overpay-transfer', 'balance-deduction', 'overpay-received'],
136
+ required: true
137
+ },
138
+ sourceInvoice: String,
139
+ destinationInvoice: String,
140
+ paymentReference: String,
141
+ paymentCompletion: String,
142
+ remainingBalance: Number,
143
+ notes: String,
144
+ exchangeRate: {
145
+ type: Number,
146
+ default: 1 // For cross-currency reconciliations
147
+ },
148
+ originalCurrency: {
149
+ code: String, // Original currency code if different from invoice currency
150
+ amount: Number // Amount in original currency
151
+ }
152
+ }],
153
+ paymentDetails: {
154
+ paymentStatus: { type: String, required: true },
155
+ paymentMethod: { type: String },
156
+ paymentDate: { type: Date },
157
+ transactionId: { type: String },
158
+ },
159
+ },
160
+ {
161
+ timestamps: true,
162
+ }
163
+ );
164
+
165
+ // Add indexes for frequently queried fields
166
+ invoiceSchema.index({ accountNumber: 1 });
167
+ invoiceSchema.index({ status: 1 });
168
+ invoiceSchema.index({ 'client.clientId': 1, status: 1 });
169
+ invoiceSchema.index({ 'reconciliationHistory.paymentReference': 1 });
170
+ invoiceSchema.index({ issueDate: -1 });
171
+ invoiceSchema.index({ 'currency.code': 1 }); // Add index for currency code
172
+ invoiceSchema.index({ 'currency.id': 1 }); // Add index for currency ID
173
+ invoiceSchema.index({ 'currency.code': 1, 'client.clientId': 1, status: 1 }); // Compound index for currency-based queries
174
+
175
+ // Add virtual field for calculating balance
176
+ invoiceSchema.virtual('calculatedBalance').get(function () {
177
+ return this.totalAmount - (this.amountPaid || 0);
178
+ });
179
+
180
+ // Add method for currency conversion if needed
181
+ invoiceSchema.methods.convertAmount = function (amount, fromCurrency, toCurrency, exchangeRate) {
182
+ if (fromCurrency === toCurrency) {
183
+ return amount;
184
+ }
185
+ return amount * exchangeRate;
186
+ };
187
+
188
+ // Add static method to find invoices by currency
189
+ invoiceSchema.statics.findByCurrency = function (currencyCode) {
190
+ return this.find({ 'currency.code': currencyCode.toUpperCase() });
191
+ };
192
+
193
+ // Add static method to calculate totals by currency
194
+ invoiceSchema.statics.calculateTotalsByCurrency = function (query = {}) {
195
+ return this.aggregate([
196
+ { $match: query },
197
+ {
198
+ $group: {
199
+ _id: '$currency.code',
200
+ totalAmount: { $sum: '$totalAmount' },
201
+ totalPaid: { $sum: '$amountPaid' },
202
+ count: { $sum: 1 }
203
+ }
204
+ }
205
+ ]);
206
+ };
207
+
208
+ const Invoice = mongoose.model('Invoice', invoiceSchema);
209
+
210
210
  module.exports = Invoice;