payservedb 5.0.3 → 5.0.5

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 (103) hide show
  1. package/.env +2 -2
  2. package/index.js +172 -172
  3. package/package.json +17 -17
  4. package/src/models/account.js +35 -35
  5. package/src/models/analog_water_billing.js +58 -58
  6. package/src/models/apilog.js +18 -18
  7. package/src/models/approvalsWorkflows.js +49 -49
  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/bookinganalytics.js +63 -63
  14. package/src/models/bookingconfig.js +45 -45
  15. package/src/models/bookingproperty.js +112 -112
  16. package/src/models/bookingreservation.js +192 -192
  17. package/src/models/bookingrevenuerecord.js +84 -84
  18. package/src/models/budget.js +33 -33
  19. package/src/models/budgetCategory.js +19 -19
  20. package/src/models/campaigns.js +72 -72
  21. package/src/models/cashpayment.js +262 -262
  22. package/src/models/combinedUnits.js +62 -62
  23. package/src/models/common_area_electricity.js +38 -38
  24. package/src/models/common_area_generator.js +38 -38
  25. package/src/models/common_area_utility_alert.js +37 -37
  26. package/src/models/common_area_water.js +39 -39
  27. package/src/models/company.js +53 -53
  28. package/src/models/country_tax.js +42 -42
  29. package/src/models/currency_settings.js +39 -39
  30. package/src/models/customer.js +200 -200
  31. package/src/models/default_payment_details.js +17 -17
  32. package/src/models/dutyroster.js +129 -129
  33. package/src/models/email.js +24 -24
  34. package/src/models/entry_exit.js +53 -53
  35. package/src/models/expense.js +55 -55
  36. package/src/models/facility.js +61 -61
  37. package/src/models/facility_payment_details.js +20 -20
  38. package/src/models/facilityasset.js +25 -25
  39. package/src/models/faq.js +18 -18
  40. package/src/models/gl_account_double_entries.js +25 -25
  41. package/src/models/gl_accounts.js +56 -56
  42. package/src/models/gl_entries.js +52 -45
  43. package/src/models/guard.js +47 -47
  44. package/src/models/handover.js +241 -241
  45. package/src/models/invoice.js +291 -291
  46. package/src/models/item_inspection.js +67 -67
  47. package/src/models/leaseagreement.js +169 -168
  48. package/src/models/leasetemplate.js +17 -17
  49. package/src/models/levy.js +84 -84
  50. package/src/models/levy_invoice_settings.js +26 -26
  51. package/src/models/levycontract.js +77 -77
  52. package/src/models/levytype.js +23 -23
  53. package/src/models/maintenance_service_vendor.js +38 -38
  54. package/src/models/maintenance_services.js +17 -17
  55. package/src/models/maintenancerequisition.js +31 -31
  56. package/src/models/message.js +38 -38
  57. package/src/models/module.js +21 -21
  58. package/src/models/notification.js +24 -24
  59. package/src/models/penalty.js +76 -76
  60. package/src/models/purchase_order.js +190 -190
  61. package/src/models/purchase_request.js +65 -65
  62. package/src/models/refresh_token.js +23 -23
  63. package/src/models/reminder.js +161 -161
  64. package/src/models/report.js +13 -13
  65. package/src/models/resident.js +121 -121
  66. package/src/models/rfq_details.js +87 -87
  67. package/src/models/rfq_response.js +109 -109
  68. package/src/models/service_charge_invoice_upload.js +42 -42
  69. package/src/models/service_charge_payments.js +27 -27
  70. package/src/models/servicerequest.js +55 -55
  71. package/src/models/settings.js +62 -62
  72. package/src/models/smart_meter_daily_consumption.js +44 -44
  73. package/src/models/sms_africastalking.js +20 -20
  74. package/src/models/sms_meliora.js +16 -16
  75. package/src/models/staff.js +36 -36
  76. package/src/models/stocksandspare.js +34 -34
  77. package/src/models/suppliers.js +68 -68
  78. package/src/models/tickets.js +109 -109
  79. package/src/models/unitasset.js +25 -25
  80. package/src/models/units.js +86 -86
  81. package/src/models/user.js +187 -187
  82. package/src/models/valueaddedservices.js +36 -36
  83. package/src/models/vas_invoices_upload.js +50 -50
  84. package/src/models/vas_payments.js +24 -24
  85. package/src/models/vasinvoice.js +159 -159
  86. package/src/models/vasvendor.js +57 -57
  87. package/src/models/visitLog.js +86 -86
  88. package/src/models/visitor.js +63 -63
  89. package/src/models/waitlist.js +45 -45
  90. package/src/models/water_invoice.js +192 -192
  91. package/src/models/water_meter_account.js +74 -74
  92. package/src/models/water_meter_communication.js +17 -17
  93. package/src/models/water_meter_concentrator.js +59 -59
  94. package/src/models/water_meter_daily_history.js +31 -31
  95. package/src/models/water_meter_iot_cards.js +34 -34
  96. package/src/models/water_meter_manufacturer.js +35 -35
  97. package/src/models/water_meter_monthly_history.js +37 -37
  98. package/src/models/water_meter_settings.js +88 -88
  99. package/src/models/water_meter_single_day_history.js +31 -31
  100. package/src/models/water_meter_size.js +15 -15
  101. package/src/models/water_meters.js +106 -106
  102. package/src/models/water_meters_delivery.js +76 -76
  103. package/src/models/workorder.js +49 -49
@@ -1,242 +1,242 @@
1
- const mongoose = require('mongoose');
2
-
3
- const handoverItemSchema = new mongoose.Schema({
4
- name: {
5
- type: String,
6
- required: true,
7
- trim: true
8
- },
9
- category: {
10
- type: String,
11
- required: true,
12
- trim: true,
13
- enum: ['Furniture', 'Appliance', 'Electronics', 'Fixture', 'Utility', 'Other']
14
- },
15
- description: {
16
- type: String,
17
- trim: true
18
- },
19
- condition: {
20
- type: String,
21
- required: true,
22
- enum: ['Excellent', 'Good', 'Fair', 'Poor', 'Damaged', 'Non-functional']
23
- },
24
- quantity: {
25
- type: Number,
26
- required: true,
27
- default: 1,
28
- min: [1, 'Quantity must be at least 1']
29
- },
30
- serialNumber: {
31
- type: String,
32
- trim: true
33
- },
34
- images: [{
35
- type: String, // URLs to stored images
36
- trim: true
37
- }],
38
- notes: {
39
- type: String,
40
- trim: true
41
- }
42
- }, { _id: true });
43
-
44
- // Define the main Handover schema
45
- const handoverSchema = new mongoose.Schema({
46
- // References
47
- facilityId: {
48
- type: mongoose.Schema.Types.ObjectId,
49
- ref: 'Facility',
50
- required: true
51
- },
52
- unitId: {
53
- type: mongoose.Schema.Types.ObjectId,
54
- ref: 'Unit',
55
- required: true
56
- },
57
- // IMPORTANT: For Customer, we don't specify 'ref' since it's in a different database
58
- // This avoids the cross-database population errors
59
- customerId: {
60
- type: mongoose.Schema.Types.ObjectId,
61
- required: true
62
- },
63
-
64
- // Handover details
65
- handoverType: {
66
- type: String,
67
- required: true,
68
- enum: ['MoveIn', 'MoveOut'],
69
- trim: true
70
- },
71
- handoverDate: {
72
- type: Date,
73
- required: true,
74
- default: Date.now
75
- },
76
- status: {
77
- type: String,
78
- required: true,
79
- enum: ['Draft', 'Completed', 'Disputed', 'Resolved'],
80
- default: 'Draft'
81
- },
82
-
83
- // If this is a move-out handover, reference the original move-in handover
84
- relatedHandoverId: {
85
- type: mongoose.Schema.Types.ObjectId,
86
- ref: 'Handover',
87
- default: null // Only populated for move-out handovers
88
- },
89
-
90
- // Items included in the handover
91
- items: [handoverItemSchema],
92
-
93
- // Additional information
94
- meterReadings: {
95
- electricity: {
96
- reading: Number,
97
- imageUrl: String
98
- },
99
- water: {
100
- reading: Number,
101
- imageUrl: String
102
- },
103
- gas: {
104
- reading: Number,
105
- imageUrl: String
106
- }
107
- },
108
-
109
- // Key handover confirmation
110
- keysHandedOver: {
111
- type: Number,
112
- default: 0,
113
- min: 0
114
- },
115
-
116
- // Security deposit info (for move-out)
117
- securityDeposit: {
118
- amount: {
119
- type: Number,
120
- default: 0
121
- },
122
- deductions: [{
123
- reason: {
124
- type: String,
125
- trim: true
126
- },
127
- amount: {
128
- type: Number,
129
- min: 0
130
- },
131
- description: String
132
- }],
133
- refundAmount: {
134
- type: Number,
135
- default: 0
136
- }
137
- },
138
-
139
- // Signature and agreement info
140
- signatures: {
141
- propertyManager: {
142
- signature: String, // URL to stored signature image or digital signature data
143
- date: Date
144
- },
145
- customer: {
146
- signature: String, // URL to stored signature image or digital signature data
147
- date: Date,
148
- agreement: {
149
- type: Boolean,
150
- default: false
151
- }
152
- }
153
- },
154
-
155
- // General notes
156
- notes: {
157
- type: String,
158
- trim: true
159
- },
160
-
161
- // Any attached documents
162
- attachments: [{
163
- name: String,
164
- fileUrl: String,
165
- uploadDate: {
166
- type: Date,
167
- default: Date.now
168
- }
169
- }]
170
- }, {
171
- timestamps: true,
172
- toJSON: { virtuals: true }, // Enable virtuals when converting to JSON
173
- toObject: { virtuals: true } // Enable virtuals when converting to object
174
- });
175
-
176
- // Add indexes for common queries
177
- handoverSchema.index({ facilityId: 1, unitId: 1, handoverType: 1 });
178
- handoverSchema.index({ customerId: 1, handoverType: 1 });
179
- handoverSchema.index({ handoverDate: -1 });
180
-
181
- // Virtual for calculating total deductions
182
- handoverSchema.virtual('totalDeductions').get(function() {
183
- if (!this.securityDeposit.deductions || this.securityDeposit.deductions.length === 0) {
184
- return 0;
185
- }
186
- return this.securityDeposit.deductions.reduce((total, deduction) => total + (deduction.amount || 0), 0);
187
- });
188
-
189
- // Add method to compare move-in and move-out states
190
- handoverSchema.methods.compareWithMoveIn = async function() {
191
- if (this.handoverType !== 'MoveOut' || !this.relatedHandoverId) {
192
- throw new Error('This method can only be called on a move-out handover with a related move-in handover');
193
- }
194
-
195
- // Find the related move-in handover
196
- const MoveInHandover = mongoose.model('Handover');
197
- const moveInHandover = await MoveInHandover.findById(this.relatedHandoverId);
198
-
199
- if (!moveInHandover) {
200
- throw new Error('Related move-in handover not found');
201
- }
202
-
203
- // Compare items and return differences
204
- const differences = {
205
- missing: [],
206
- damaged: [],
207
- changed: []
208
- };
209
-
210
- // Check for missing or damaged items
211
- moveInHandover.items.forEach(moveInItem => {
212
- const moveOutItem = this.items.find(item =>
213
- item.name === moveInItem.name &&
214
- item.category === moveInItem.category
215
- );
216
-
217
- if (!moveOutItem) {
218
- differences.missing.push(moveInItem);
219
- } else if (moveOutItem.condition !== moveInItem.condition) {
220
- if (['Poor', 'Damaged', 'Non-functional'].includes(moveOutItem.condition)) {
221
- differences.damaged.push({
222
- item: moveOutItem,
223
- originalCondition: moveInItem.condition,
224
- currentCondition: moveOutItem.condition
225
- });
226
- } else {
227
- differences.changed.push({
228
- item: moveOutItem,
229
- originalCondition: moveInItem.condition,
230
- currentCondition: moveOutItem.condition
231
- });
232
- }
233
- }
234
- });
235
-
236
- return differences;
237
- };
238
-
239
- // Create and export the model with the standard pattern
240
- const Handover = mongoose.model('Handover', handoverSchema);
241
-
1
+ const mongoose = require('mongoose');
2
+
3
+ const handoverItemSchema = new mongoose.Schema({
4
+ name: {
5
+ type: String,
6
+ required: true,
7
+ trim: true
8
+ },
9
+ category: {
10
+ type: String,
11
+ required: true,
12
+ trim: true,
13
+ enum: ['Furniture', 'Appliance', 'Electronics', 'Fixture', 'Utility', 'Other']
14
+ },
15
+ description: {
16
+ type: String,
17
+ trim: true
18
+ },
19
+ condition: {
20
+ type: String,
21
+ required: true,
22
+ enum: ['Excellent', 'Good', 'Fair', 'Poor', 'Damaged', 'Non-functional']
23
+ },
24
+ quantity: {
25
+ type: Number,
26
+ required: true,
27
+ default: 1,
28
+ min: [1, 'Quantity must be at least 1']
29
+ },
30
+ serialNumber: {
31
+ type: String,
32
+ trim: true
33
+ },
34
+ images: [{
35
+ type: String, // URLs to stored images
36
+ trim: true
37
+ }],
38
+ notes: {
39
+ type: String,
40
+ trim: true
41
+ }
42
+ }, { _id: true });
43
+
44
+ // Define the main Handover schema
45
+ const handoverSchema = new mongoose.Schema({
46
+ // References
47
+ facilityId: {
48
+ type: mongoose.Schema.Types.ObjectId,
49
+ ref: 'Facility',
50
+ required: true
51
+ },
52
+ unitId: {
53
+ type: mongoose.Schema.Types.ObjectId,
54
+ ref: 'Unit',
55
+ required: true
56
+ },
57
+ // IMPORTANT: For Customer, we don't specify 'ref' since it's in a different database
58
+ // This avoids the cross-database population errors
59
+ customerId: {
60
+ type: mongoose.Schema.Types.ObjectId,
61
+ required: true
62
+ },
63
+
64
+ // Handover details
65
+ handoverType: {
66
+ type: String,
67
+ required: true,
68
+ enum: ['MoveIn', 'MoveOut'],
69
+ trim: true
70
+ },
71
+ handoverDate: {
72
+ type: Date,
73
+ required: true,
74
+ default: Date.now
75
+ },
76
+ status: {
77
+ type: String,
78
+ required: true,
79
+ enum: ['Draft', 'Completed', 'Disputed', 'Resolved'],
80
+ default: 'Draft'
81
+ },
82
+
83
+ // If this is a move-out handover, reference the original move-in handover
84
+ relatedHandoverId: {
85
+ type: mongoose.Schema.Types.ObjectId,
86
+ ref: 'Handover',
87
+ default: null // Only populated for move-out handovers
88
+ },
89
+
90
+ // Items included in the handover
91
+ items: [handoverItemSchema],
92
+
93
+ // Additional information
94
+ meterReadings: {
95
+ electricity: {
96
+ reading: Number,
97
+ imageUrl: String
98
+ },
99
+ water: {
100
+ reading: Number,
101
+ imageUrl: String
102
+ },
103
+ gas: {
104
+ reading: Number,
105
+ imageUrl: String
106
+ }
107
+ },
108
+
109
+ // Key handover confirmation
110
+ keysHandedOver: {
111
+ type: Number,
112
+ default: 0,
113
+ min: 0
114
+ },
115
+
116
+ // Security deposit info (for move-out)
117
+ securityDeposit: {
118
+ amount: {
119
+ type: Number,
120
+ default: 0
121
+ },
122
+ deductions: [{
123
+ reason: {
124
+ type: String,
125
+ trim: true
126
+ },
127
+ amount: {
128
+ type: Number,
129
+ min: 0
130
+ },
131
+ description: String
132
+ }],
133
+ refundAmount: {
134
+ type: Number,
135
+ default: 0
136
+ }
137
+ },
138
+
139
+ // Signature and agreement info
140
+ signatures: {
141
+ propertyManager: {
142
+ signature: String, // URL to stored signature image or digital signature data
143
+ date: Date
144
+ },
145
+ customer: {
146
+ signature: String, // URL to stored signature image or digital signature data
147
+ date: Date,
148
+ agreement: {
149
+ type: Boolean,
150
+ default: false
151
+ }
152
+ }
153
+ },
154
+
155
+ // General notes
156
+ notes: {
157
+ type: String,
158
+ trim: true
159
+ },
160
+
161
+ // Any attached documents
162
+ attachments: [{
163
+ name: String,
164
+ fileUrl: String,
165
+ uploadDate: {
166
+ type: Date,
167
+ default: Date.now
168
+ }
169
+ }]
170
+ }, {
171
+ timestamps: true,
172
+ toJSON: { virtuals: true }, // Enable virtuals when converting to JSON
173
+ toObject: { virtuals: true } // Enable virtuals when converting to object
174
+ });
175
+
176
+ // Add indexes for common queries
177
+ handoverSchema.index({ facilityId: 1, unitId: 1, handoverType: 1 });
178
+ handoverSchema.index({ customerId: 1, handoverType: 1 });
179
+ handoverSchema.index({ handoverDate: -1 });
180
+
181
+ // Virtual for calculating total deductions
182
+ handoverSchema.virtual('totalDeductions').get(function() {
183
+ if (!this.securityDeposit.deductions || this.securityDeposit.deductions.length === 0) {
184
+ return 0;
185
+ }
186
+ return this.securityDeposit.deductions.reduce((total, deduction) => total + (deduction.amount || 0), 0);
187
+ });
188
+
189
+ // Add method to compare move-in and move-out states
190
+ handoverSchema.methods.compareWithMoveIn = async function() {
191
+ if (this.handoverType !== 'MoveOut' || !this.relatedHandoverId) {
192
+ throw new Error('This method can only be called on a move-out handover with a related move-in handover');
193
+ }
194
+
195
+ // Find the related move-in handover
196
+ const MoveInHandover = mongoose.model('Handover');
197
+ const moveInHandover = await MoveInHandover.findById(this.relatedHandoverId);
198
+
199
+ if (!moveInHandover) {
200
+ throw new Error('Related move-in handover not found');
201
+ }
202
+
203
+ // Compare items and return differences
204
+ const differences = {
205
+ missing: [],
206
+ damaged: [],
207
+ changed: []
208
+ };
209
+
210
+ // Check for missing or damaged items
211
+ moveInHandover.items.forEach(moveInItem => {
212
+ const moveOutItem = this.items.find(item =>
213
+ item.name === moveInItem.name &&
214
+ item.category === moveInItem.category
215
+ );
216
+
217
+ if (!moveOutItem) {
218
+ differences.missing.push(moveInItem);
219
+ } else if (moveOutItem.condition !== moveInItem.condition) {
220
+ if (['Poor', 'Damaged', 'Non-functional'].includes(moveOutItem.condition)) {
221
+ differences.damaged.push({
222
+ item: moveOutItem,
223
+ originalCondition: moveInItem.condition,
224
+ currentCondition: moveOutItem.condition
225
+ });
226
+ } else {
227
+ differences.changed.push({
228
+ item: moveOutItem,
229
+ originalCondition: moveInItem.condition,
230
+ currentCondition: moveOutItem.condition
231
+ });
232
+ }
233
+ }
234
+ });
235
+
236
+ return differences;
237
+ };
238
+
239
+ // Create and export the model with the standard pattern
240
+ const Handover = mongoose.model('Handover', handoverSchema);
241
+
242
242
  module.exports = Handover;