payservedb 10.0.7 → 10.0.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/package.json
CHANGED
|
@@ -132,17 +132,17 @@ const powerMeterSchema = new mongoose.Schema({
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
powerMeterSchema.virtual('displayName').get(function () {
|
|
135
|
-
return this.
|
|
136
|
-
? this.unitName
|
|
137
|
-
: this.description;
|
|
135
|
+
return this.unitName || this.description;
|
|
138
136
|
});
|
|
139
137
|
powerMeterSchema.pre('save', function (next) {
|
|
140
138
|
if (this.meterCategory === 'unit') {
|
|
141
139
|
if (!this.unitId || !this.unitName) {
|
|
142
140
|
return next(new Error('Unit meters require both unitId and unitName.'));
|
|
143
141
|
}
|
|
142
|
+
} else if (this.meterCategory === 'commercial' && this.unitId && this.unitName) {
|
|
143
|
+
// commercial unit meter: tied to a unit, no description needed
|
|
144
144
|
} else {
|
|
145
|
-
// common_area or
|
|
145
|
+
// common_area, bulk or non-unit commercial
|
|
146
146
|
if (!this.description) {
|
|
147
147
|
return next(new Error(`${this.meterCategory} meters require a description.`));
|
|
148
148
|
}
|
|
@@ -27,6 +27,21 @@ const powerInvoiceSchema = new mongoose.Schema(
|
|
|
27
27
|
required: true,
|
|
28
28
|
// Format: "YYYY-MM" e.g. "2025-03"
|
|
29
29
|
},
|
|
30
|
+
// ── Multi-month "period" invoices (yearMonth = "YYYY-MM-DD_to_YYYY-MM-DD") ──
|
|
31
|
+
periodStart: { type: String, default: null }, // 'YYYY-MM-DD'
|
|
32
|
+
periodEnd: { type: String, default: null }, // 'YYYY-MM-DD'
|
|
33
|
+
isPeriodInvoice: { type: Boolean, default: false },
|
|
34
|
+
// One entry per month actually billed on a period invoice, so reports can
|
|
35
|
+
// attribute usage/cost to each month without recalculating.
|
|
36
|
+
monthlyBreakdown: [
|
|
37
|
+
{
|
|
38
|
+
_id: false,
|
|
39
|
+
yearMonth: { type: String, required: true }, // "YYYY-MM"
|
|
40
|
+
units: { type: Number, default: 0 },
|
|
41
|
+
tariff: { type: String },
|
|
42
|
+
totalCharge: { type: Number, default: 0 },
|
|
43
|
+
},
|
|
44
|
+
],
|
|
30
45
|
facilityId: {
|
|
31
46
|
type: mongoose.Schema.Types.ObjectId,
|
|
32
47
|
required: true,
|