payservedb 9.4.7 → 9.4.9

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 CHANGED
@@ -93,7 +93,6 @@ const models = {
93
93
  Settings: require("./src/models/settings"),
94
94
  Levy: require("./src/models/levy"),
95
95
  LevyType: require("./src/models/levytype"),
96
- ContractPaymentReceipt: require("./src/models/levy_payment_receipt"),
97
96
  LevyContract: require("./src/models/levycontract"),
98
97
  DepositSchema: require("./src/models/levy_deposits"),
99
98
  Invoice: require("./src/models/invoice"),
@@ -181,6 +180,7 @@ const models = {
181
180
  BookingConfig: require("./src/models/bookingconfig"),
182
181
  BookingAnalytics: require("./src/models/bookinganalytics"),
183
182
  BookingInvoice: require("./src/models/booking_invoice"),
183
+ CancellationPolicy: require("./src/models/cancellation_policy"),
184
184
  BankDetails: require("./src/models/bankdetails"),
185
185
  RevenueRecord: require("./src/models/bookingrevenuerecord"),
186
186
  GLAccount: require("./src/models/gl_accounts"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "9.4.7",
3
+ "version": "9.4.9",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -11,9 +11,16 @@ const accountSchema = new mongoose.Schema({
11
11
  type: mongoose.Schema.Types.ObjectId,
12
12
  default: null,
13
13
  },
14
+ // NOT unique: 'lease' and 'listing-fee' accounts intentionally share
15
+ // contractId: null across many documents (identified instead by
16
+ // customerId+facilityId+unitId), so a unique index here would let only
17
+ // one such account ever be created. Uniqueness for contract-scoped
18
+ // types (levy, property-management, booking) is enforced by the
19
+ // findOne-before-create check in getOrCreateAccountNumber, not a DB
20
+ // constraint.
14
21
  contractId: {
15
22
  type: mongoose.Schema.Types.ObjectId,
16
- unique: true,
23
+ index: true,
17
24
  default: null,
18
25
  },
19
26
  customerId: {
@@ -22,10 +22,32 @@ const bookingInvoiceSchema = new mongoose.Schema({
22
22
  unique: true,
23
23
  sparse: true // Allow null/undefined values while maintaining uniqueness for non-null values
24
24
  },
25
+ // Reservation-billed invoices (the default/original use of this model)
26
+ // always set bookingReservationId. Recurring landlord listing-fee
27
+ // invoices (invoiceType: 'ListingFee') are not tied to a reservation,
28
+ // so this is intentionally not required at the schema level.
25
29
  bookingReservationId: {
26
30
  type: mongoose.Schema.Types.ObjectId,
27
- ref: 'BookingReservation',
28
- required: true
31
+ ref: 'BookingReservation'
32
+ },
33
+ // Distinguishes a guest-facing reservation invoice from a recurring
34
+ // landlord listing-fee invoice billed for hosting a unit on the
35
+ // booking platform (Managed by Landlord units).
36
+ invoiceType: {
37
+ type: String,
38
+ enum: ['Reservation', 'ListingFee'],
39
+ default: 'Reservation'
40
+ },
41
+ // Landlord being billed - only set for invoiceType: 'ListingFee'
42
+ landlordId: {
43
+ type: mongoose.Schema.Types.ObjectId,
44
+ ref: 'Customer'
45
+ },
46
+ // "YYYY-MM" of the billing period - only set for invoiceType: 'ListingFee',
47
+ // used to prevent generating more than one listing-fee invoice per unit
48
+ // per month
49
+ billingYearMonth: {
50
+ type: String
29
51
  },
30
52
  unitId: {
31
53
  type: mongoose.Schema.Types.ObjectId,
@@ -34,6 +34,28 @@ const bookingConfigSchema = new mongoose.Schema({
34
34
  defaultCommission: {
35
35
  type: Number,
36
36
  default: 10
37
+ },
38
+ // Business-day cutoff, "HH:mm" 24h format. A checkout/checkin
39
+ // timestamp before this time counts as belonging to the previous
40
+ // calendar day (see src/utils/resolveBusinessDay.js).
41
+ dayEndTime: {
42
+ type: String,
43
+ default: '00:00',
44
+ validate: {
45
+ validator: (value) => /^([01]\d|2[0-3]):([0-5]\d)$/.test(value),
46
+ message: 'dayEndTime must be in HH:mm 24-hour format'
47
+ }
48
+ },
49
+ // Recurring fee (per Phase 3b) charged to landlords whose unit is
50
+ // listed via the facility's booking platform (managedByLandlord=true).
51
+ listingFeeAmount: {
52
+ type: Number,
53
+ default: 0,
54
+ min: 0
55
+ },
56
+ listingFeeCurrencyId: {
57
+ type: mongoose.Schema.Types.ObjectId,
58
+ ref: 'Currency'
37
59
  }
38
60
  }
39
61
  }, {
@@ -88,6 +88,15 @@ const bookingPropertySchema = new mongoose.Schema({
88
88
  enum: ['Flexible', 'Moderate', 'Strict'],
89
89
  default: 'Moderate'
90
90
  },
91
+ // Reference to a reusable, named CancellationPolicy - the current,
92
+ // actively-used way to assign a policy to a unit. One policy can be
93
+ // assigned to many units. Supersedes the string-based
94
+ // cancellationPolicy/cancellationPolicyDetails fields above, which are
95
+ // kept for backward compatibility with older records.
96
+ cancellationPolicyId: {
97
+ type: mongoose.Schema.Types.ObjectId,
98
+ ref: 'CancellationPolicy'
99
+ },
91
100
  // Detailed cancellation policy information for display and API
92
101
  cancellationPolicyDetails: {
93
102
  description: {
@@ -176,4 +185,3 @@ const bookingPropertySchema = new mongoose.Schema({
176
185
  const BookingProperty = mongoose.model('BookingProperty', bookingPropertySchema);
177
186
 
178
187
  module.exports = BookingProperty;
179
-
@@ -5,6 +5,10 @@ const bookingReservationSchema = new mongoose.Schema({
5
5
  checkOutActual: {
6
6
  type: Date
7
7
  },
8
+ // When the guest was actually checked in (set by the Check In action)
9
+ checkedInAt: {
10
+ type: Date
11
+ },
8
12
  // Field for checkout notes
9
13
  checkoutNotes: {
10
14
  type: String,
@@ -167,15 +171,24 @@ const bookingReservationSchema = new mongoose.Schema({
167
171
  specialRequests: {
168
172
  type: String
169
173
  },
174
+ // This enum is a superset shared across companies on this multitenant
175
+ // platform (payservedb has no per-company branch) - each company's own
176
+ // controller code decides how 'booked'/'reserved' are actually used, so
177
+ // do not change the default here without checking every consumer.
178
+ // Swan: booked = created, zero payment. reserved = has payment (partial
179
+ // or full), not yet checked in. checked-in = guest on premises.
180
+ // checked-out = guest left but balance outstanding (e.g. damage
181
+ // charges). completed = balance cleared. cancelled = terminal, reachable
182
+ // from booked/reserved.
170
183
  status: {
171
184
  type: String,
172
- enum: ['reserved', 'booked', 'canceled', 'completed'],
185
+ enum: ['reserved', 'booked', 'canceled', 'cancelled', 'checked-in', 'checked-out', 'completed'],
173
186
  default: 'reserved'
174
187
  },
175
188
  statusHistory: [{
176
189
  status: {
177
190
  type: String,
178
- enum: ['reserved', 'booked', 'canceled', 'completed'],
191
+ enum: ['reserved', 'booked', 'canceled', 'cancelled', 'checked-in', 'checked-out', 'completed'],
179
192
  required: true
180
193
  },
181
194
  timestamp: {
@@ -218,7 +231,17 @@ const bookingReservationSchema = new mongoose.Schema({
218
231
  refundRequestedAt: Date,
219
232
  refundApprovedAt: Date,
220
233
  refundRejectedAt: Date,
221
- refundRejectionReason: String
234
+ refundRejectionReason: String,
235
+ // Records which named CancellationPolicy (if any) determined
236
+ // refundAmount, for display/audit purposes
237
+ appliedPolicy: {
238
+ policyId: {
239
+ type: mongoose.Schema.Types.ObjectId,
240
+ ref: 'CancellationPolicy'
241
+ },
242
+ policyName: String,
243
+ refundPercentage: Number
244
+ }
222
245
  },
223
246
  createdBy: {
224
247
  type: mongoose.Schema.Types.ObjectId,
@@ -236,4 +259,3 @@ const bookingReservationSchema = new mongoose.Schema({
236
259
  const BookingReservation = mongoose.model('BookingReservation', bookingReservationSchema);
237
260
 
238
261
  module.exports = BookingReservation;
239
-
@@ -0,0 +1,57 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // A reusable, named cancellation policy. One policy can be assigned to many
4
+ // BookingProperty units (BookingProperty.cancellationPolicyId).
5
+ const cancellationPolicySchema = new mongoose.Schema({
6
+ facilityId: {
7
+ type: mongoose.Schema.Types.ObjectId,
8
+ ref: 'Facility',
9
+ required: true
10
+ },
11
+ name: {
12
+ type: String,
13
+ required: true,
14
+ trim: true
15
+ },
16
+ description: {
17
+ type: String,
18
+ default: ''
19
+ },
20
+ // If true, no refund is ever given under this policy regardless of
21
+ // refundRules
22
+ isNonRefundable: {
23
+ type: Boolean,
24
+ default: false
25
+ },
26
+ // Tiered refund rules: a guest cancelling at least `daysBeforeCheckIn`
27
+ // days before check-in receives `refundPercentage` of what they paid.
28
+ // The rule with the highest daysBeforeCheckIn that the guest still
29
+ // qualifies for applies.
30
+ refundRules: [{
31
+ daysBeforeCheckIn: {
32
+ type: Number,
33
+ required: true,
34
+ min: 0
35
+ },
36
+ refundPercentage: {
37
+ type: Number,
38
+ required: true,
39
+ min: 0,
40
+ max: 100
41
+ },
42
+ description: {
43
+ type: String,
44
+ default: ''
45
+ }
46
+ }],
47
+ createdBy: {
48
+ type: mongoose.Schema.Types.ObjectId,
49
+ ref: 'User'
50
+ }
51
+ }, {
52
+ timestamps: true
53
+ });
54
+
55
+ const CancellationPolicy = mongoose.model('CancellationPolicy', cancellationPolicySchema);
56
+
57
+ module.exports = CancellationPolicy;
@@ -45,6 +45,15 @@ const invoiceSchema = new mongoose.Schema(
45
45
  id: { type: mongoose.Schema.Types.ObjectId, ref: "Unit", required: true },
46
46
  name: { type: String, required: true },
47
47
  },
48
+ // Per-unit fee breakdown for a single invoice covering multiple units
49
+ // (e.g. a Property-Management contract billing several units at
50
+ // different rates). Only set when the invoice spans more than one
51
+ // unit - `unit` above still identifies the contract's primary unit for
52
+ // backward compatibility with code that expects a single unit.
53
+ unitBreakdown: [{
54
+ unitId: { type: mongoose.Schema.Types.ObjectId, ref: "Unit" },
55
+ amount: Number
56
+ }],
48
57
  currency: {
49
58
  id: {
50
59
  type: mongoose.Schema.Types.ObjectId,
@@ -558,4 +567,4 @@ invoiceSchema.pre("save", function (next) {
558
567
 
559
568
  const Invoice = mongoose.model("Invoice", invoiceSchema);
560
569
 
561
- module.exports = Invoice;
570
+ module.exports = Invoice;
@@ -53,6 +53,8 @@ const levySchema = new mongoose.Schema(
53
53
 
54
54
  itemName: String,
55
55
 
56
+ itemClassCode: String,
57
+
56
58
  taxTypeCode: String,
57
59
 
58
60
  synced: Boolean,
@@ -118,6 +118,48 @@ const PropertyManagerContractSchema = new Schema(
118
118
  }
119
119
  }
120
120
  },
121
+ // Currency for fixed-amount managementFee/leaseFee values above.
122
+ // Only meaningful when the fee type is 'amount' (percentage fees are
123
+ // currency-agnostic).
124
+ currencyId: {
125
+ type: mongoose.Schema.Types.ObjectId,
126
+ ref: 'Currency'
127
+ },
128
+ // Per-unit fee overrides. Each unit in `units` may have a different
129
+ // management/lease fee here; a unit with no entry here falls back to
130
+ // the contract-level managementFee/leaseFee/currencyId above. This is
131
+ // what lets one contract cover multiple units at different rates.
132
+ unitFees: [{
133
+ unitId: {
134
+ type: mongoose.Schema.Types.ObjectId,
135
+ ref: 'Unit',
136
+ required: true
137
+ },
138
+ managementFee: {
139
+ type: {
140
+ type: String,
141
+ enum: ['percentage', 'amount']
142
+ },
143
+ value: {
144
+ type: Number,
145
+ min: [0, 'Management fee value cannot be negative']
146
+ }
147
+ },
148
+ leaseFee: {
149
+ type: {
150
+ type: String,
151
+ enum: ['percentage', 'amount']
152
+ },
153
+ value: {
154
+ type: Number,
155
+ min: [0, 'Lease commission value cannot be negative']
156
+ }
157
+ },
158
+ currencyId: {
159
+ type: mongoose.Schema.Types.ObjectId,
160
+ ref: 'Currency'
161
+ }
162
+ }],
121
163
  // GL Account configurations - updated to match sample data structure
122
164
  invoiceDoubleEntryAccount: {
123
165
  type: mongoose.Schema.Types.ObjectId,
@@ -152,7 +194,10 @@ const PropertyManagerContractSchema = new Schema(
152
194
  status: {
153
195
  type: String,
154
196
  enum: ['Active', 'Inactive', 'Completed', 'Suspended', 'Terminated'],
155
- default: 'Inactive',
197
+ // Contracts default Active on creation - billing eligibility is
198
+ // driven by lease existence, not contract status. Status is now
199
+ // a purely manual lifecycle field the property manager controls.
200
+ default: 'Active',
156
201
  required: [true, 'Status is required']
157
202
  },
158
203
  createdBy: {
@@ -219,26 +264,13 @@ PropertyManagerContractSchema.pre('save', function (next) {
219
264
  return;
220
265
  }
221
266
 
222
- // Validate required fields for Active status
223
- if (this.status === 'Active') {
224
- if (!this.startDate) {
225
- next(new Error('Start date is required for Active contracts'));
226
- return;
227
- }
228
- if (!this.endDate) {
229
- next(new Error('End date is required for Active contracts'));
230
- return;
231
- }
232
- if (!this.paymentDueDate) {
233
- next(new Error('Payment due date is required for Active contracts'));
234
- return;
235
- }
236
- if (!this.frequency) {
237
- next(new Error('Payment frequency is required for Active contracts'));
238
- return;
239
- }
240
- }
241
-
267
+ // Note: startDate/endDate/paymentDueDate/frequency are no longer
268
+ // required for Active status - contracts are always Active regardless
269
+ // of whether a lease has populated those fields yet. They remain
270
+ // required only for billing (see invoice_service's eligibility checks,
271
+ // which additionally require an active lease before generating an
272
+ // invoice).
273
+
242
274
  next();
243
275
  });
244
276
 
@@ -32,6 +32,14 @@ const propertyManagerRevenueEntrySchema = new mongoose.Schema({
32
32
  required: true
33
33
  },
34
34
  unitName: String,
35
+ // Informational per-unit split when this entry's source invoice covered
36
+ // multiple units (e.g. a multi-unit management-fee invoice) - `unit`/
37
+ // `unitName` above remain the primary unit for backward compatibility.
38
+ unitBreakdown: [{
39
+ unitId: { type: mongoose.Schema.Types.ObjectId, ref: 'Unit' },
40
+ unitName: String,
41
+ amount: Number
42
+ }],
35
43
  source: {
36
44
  type: String,
37
45
  enum: ['booking_commission', 'lease_fee', 'management_fee'],