payservedb 5.5.8 → 5.6.0
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/facility.js +2 -1
- package/src/models/propertyManagerRevenue.js +101 -0
- package/src/models/units.js +23 -5
- package/src/models/water_invoice.js +1 -0
package/index.js
CHANGED
|
@@ -170,7 +170,8 @@ const models = {
|
|
|
170
170
|
GLEntry: require('./src/models/gl_entries'),
|
|
171
171
|
GLAccountDoubleEntries: require('./src/models/gl_account_double_entries'),
|
|
172
172
|
PendingCredential: require('./src/models/pendingCredentials'),
|
|
173
|
-
UnitManagementTemplate: require('./src/models/unitManagementTemplate')
|
|
173
|
+
UnitManagementTemplate: require('./src/models/unitManagementTemplate'),
|
|
174
|
+
PropertyManagerRevenue: require('./src/models/propertyManagerRevenue')
|
|
174
175
|
};
|
|
175
176
|
|
|
176
177
|
// Function to get models dynamically from a specific database connection
|
package/package.json
CHANGED
package/src/models/facility.js
CHANGED
|
@@ -23,6 +23,7 @@ const facilitySchema = new mongoose.Schema({
|
|
|
23
23
|
visitor: { type: Boolean, },
|
|
24
24
|
levy: { type: Boolean, },
|
|
25
25
|
maintenance: { type: Boolean, },
|
|
26
|
+
propertyManagement: { type: Boolean, },
|
|
26
27
|
lease: { type: Boolean, },
|
|
27
28
|
vas: { type: Boolean, },
|
|
28
29
|
tickets: { type: Boolean, },
|
|
@@ -58,4 +59,4 @@ facilitySchema.index({ dbName: 1 });
|
|
|
58
59
|
// Compile the model from the schema
|
|
59
60
|
const Facility = mongoose.model('Facility', facilitySchema);
|
|
60
61
|
|
|
61
|
-
module.exports = Facility;
|
|
62
|
+
module.exports = Facility;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const propertyManagerRevenue = new mongoose.Schema({
|
|
4
|
+
facility: {
|
|
5
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
6
|
+
ref: 'Facility',
|
|
7
|
+
required: true,
|
|
8
|
+
index: true
|
|
9
|
+
},
|
|
10
|
+
calculationDate: {
|
|
11
|
+
type: Date,
|
|
12
|
+
required: true,
|
|
13
|
+
index: true
|
|
14
|
+
},
|
|
15
|
+
dateRange: {
|
|
16
|
+
startDate: Date,
|
|
17
|
+
endDate: Date
|
|
18
|
+
},
|
|
19
|
+
totalRevenue: {
|
|
20
|
+
type: Number,
|
|
21
|
+
required: true,
|
|
22
|
+
default: 0
|
|
23
|
+
},
|
|
24
|
+
totalOwnerAmount: {
|
|
25
|
+
type: Number,
|
|
26
|
+
required: true,
|
|
27
|
+
default: 0
|
|
28
|
+
},
|
|
29
|
+
totalPaidAmount: {
|
|
30
|
+
type: Number,
|
|
31
|
+
required: true,
|
|
32
|
+
default: 0
|
|
33
|
+
},
|
|
34
|
+
unitsProcessed: {
|
|
35
|
+
type: Number,
|
|
36
|
+
default: 0
|
|
37
|
+
},
|
|
38
|
+
invoicesProcessed: {
|
|
39
|
+
type: Number,
|
|
40
|
+
default: 0
|
|
41
|
+
},
|
|
42
|
+
unitBreakdown: [{
|
|
43
|
+
unit: {
|
|
44
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
45
|
+
ref: 'Unit',
|
|
46
|
+
required: true
|
|
47
|
+
},
|
|
48
|
+
unitName: String, // Denormalized for easier access
|
|
49
|
+
propertyManagementFee: Number,
|
|
50
|
+
totalPaid: Number,
|
|
51
|
+
managerRevenue: Number,
|
|
52
|
+
ownerAmount: Number,
|
|
53
|
+
invoiceCount: Number,
|
|
54
|
+
invoices: [{
|
|
55
|
+
invoice: {
|
|
56
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
57
|
+
ref: 'Invoice',
|
|
58
|
+
required: true
|
|
59
|
+
},
|
|
60
|
+
invoiceNumber: String, // Denormalized for easier access
|
|
61
|
+
invoiceType: String,
|
|
62
|
+
totalAmount: Number,
|
|
63
|
+
paidAmount: Number,
|
|
64
|
+
managerCommission: Number,
|
|
65
|
+
ownerAmount: Number,
|
|
66
|
+
paymentDate: Date,
|
|
67
|
+
managementFeePercent: Number
|
|
68
|
+
}]
|
|
69
|
+
}],
|
|
70
|
+
summary: {
|
|
71
|
+
totalUnits: Number,
|
|
72
|
+
totalInvoicesProcessed: Number,
|
|
73
|
+
includesHistoricalRevenue: Boolean,
|
|
74
|
+
calculationNote: String
|
|
75
|
+
},
|
|
76
|
+
status: {
|
|
77
|
+
type: String,
|
|
78
|
+
enum: ['calculated', 'paid', 'partially_paid', 'cancelled'],
|
|
79
|
+
default: 'calculated'
|
|
80
|
+
},
|
|
81
|
+
notes: String,
|
|
82
|
+
createdBy: {
|
|
83
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
84
|
+
ref: 'User' // Reference to User who created this record
|
|
85
|
+
},
|
|
86
|
+
createdAt: {
|
|
87
|
+
type: Date,
|
|
88
|
+
default: Date.now,
|
|
89
|
+
index: true
|
|
90
|
+
},
|
|
91
|
+
updatedAt: {
|
|
92
|
+
type: Date,
|
|
93
|
+
default: Date.now
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
timestamps: true
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const PropertyManagerRevenue = mongoose.model('PropertyManagerRevenue', propertyManagerRevenue);
|
|
100
|
+
|
|
101
|
+
module.exports = PropertyManagerRevenue;
|
package/src/models/units.js
CHANGED
|
@@ -42,16 +42,27 @@ const unitSchema = new mongoose.Schema({
|
|
|
42
42
|
type: mongoose.Schema.Types.ObjectId,
|
|
43
43
|
ref: 'Facility',
|
|
44
44
|
},
|
|
45
|
-
|
|
46
45
|
homeOwnerId: {
|
|
47
46
|
type: mongoose.Schema.Types.ObjectId,
|
|
48
47
|
ref: 'Customer',
|
|
49
48
|
},
|
|
49
|
+
isManagedByPropertyManager: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: false
|
|
52
|
+
},
|
|
53
|
+
propertyManagementFee: {
|
|
54
|
+
type: Number,
|
|
55
|
+
required: function () {
|
|
56
|
+
return this.isManagedByPropertyManager === true;
|
|
57
|
+
},
|
|
58
|
+
min: [0, "Property management fee must be at least 0"],
|
|
59
|
+
max: [100, "Property management fee cannot exceed 100%"]
|
|
60
|
+
},
|
|
50
61
|
occupants: [
|
|
51
62
|
{
|
|
52
63
|
customerId: { type: mongoose.Schema.Types.ObjectId, ref: 'Customer' },
|
|
53
64
|
customerType: { type: String, enum: ['home owner', 'tenant'] },
|
|
54
|
-
residentType: { type: String, enum: [
|
|
65
|
+
residentType: { type: String, enum: ['resident'] },
|
|
55
66
|
moveInDate: { type: Date },
|
|
56
67
|
moveOutDate: { type: Date, default: null }
|
|
57
68
|
}
|
|
@@ -80,16 +91,23 @@ const unitSchema = new mongoose.Schema({
|
|
|
80
91
|
type: mongoose.Schema.Types.ObjectId,
|
|
81
92
|
ref: 'Customer',
|
|
82
93
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
94
|
}, {
|
|
86
95
|
timestamps: true // Automatically add createdAt and updatedAt fields
|
|
87
96
|
});
|
|
88
97
|
|
|
98
|
+
// Add pre-save middleware to handle propertyManagementFee
|
|
99
|
+
unitSchema.pre('save', function (next) {
|
|
100
|
+
// Clear propertyManagementFee if not managed by property manager
|
|
101
|
+
if (!this.isManagedByPropertyManager) {
|
|
102
|
+
this.propertyManagementFee = null;
|
|
103
|
+
}
|
|
104
|
+
next();
|
|
105
|
+
});
|
|
106
|
+
|
|
89
107
|
// Indexes for improved performance
|
|
90
108
|
unitSchema.index({ name: 1 });
|
|
91
109
|
|
|
92
110
|
// Compile the model from the schema
|
|
93
111
|
const Unit = mongoose.model('Unit', unitSchema);
|
|
94
112
|
|
|
95
|
-
module.exports = Unit;
|
|
113
|
+
module.exports = Unit;
|