payservedb 10.1.5 → 10.1.6
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 +18 -0
- package/package.json +1 -1
- package/src/models/damr.BulkMeter.js +27 -0
- package/src/models/damr.BulkReading.js +31 -0
- package/src/models/damr.Credit.js +38 -0
- package/src/models/damr.DAMRCounter.js +10 -0
- package/src/models/damr.FacilitySettings.js +22 -0
- package/src/models/damr.Flag.js +59 -0
- package/src/models/damr.Location.js +20 -0
- package/src/models/damr.Meter.js +56 -0
- package/src/models/damr.MeterBinding.js +29 -0
- package/src/models/damr.MeterInvoice.js +144 -0
- package/src/models/damr.MpesaTransaction.js +24 -0
- package/src/models/damr.OccupancyHistory.js +33 -0
- package/src/models/damr.PaymentAccount.js +30 -0
- package/src/models/damr.Reading.js +51 -0
- package/src/models/damr.StkPushRequest.js +46 -0
- package/src/models/damr.TariffPlan.js +74 -0
- package/src/models/damr.VerificationCode.js +43 -0
package/index.js
CHANGED
|
@@ -302,6 +302,24 @@ const models = {
|
|
|
302
302
|
RecipientGroupMember: require("./src/models/recipient_group_member"),
|
|
303
303
|
InvoiceWithholdingTax: require("./src/models/InvoiceWithholdingTax"),
|
|
304
304
|
InvoiceCreditAdjustment: require("./src/models/invoiceCreditAdjustment"),
|
|
305
|
+
//DAMR
|
|
306
|
+
BulkMeter: require("./src/models/damr.Bulkmeter"),
|
|
307
|
+
BulkReading: require("./src/models/damr.BulkReading"),
|
|
308
|
+
Credit: require("./src/models/damr.Credit"),
|
|
309
|
+
DAMRCounter: require("./src/models/damr.DAMRCounter"),
|
|
310
|
+
FacilitySettings: require("./src/models/damr.FacilitySettings"),
|
|
311
|
+
Flag: require("./src/models/damr.Flag"),
|
|
312
|
+
Location: require("./src/models/damr.Location"),
|
|
313
|
+
Meter: require("./src/models/damr.Meter"),
|
|
314
|
+
MeterBinding: require("./src/models/damr.MeterBinding"),
|
|
315
|
+
MeterInvoice: require("./src/models/damr.MeterInvoice"),
|
|
316
|
+
MpesaTransaction: require("./src/models/damr.MpesaTransaction"),
|
|
317
|
+
OccupancyHistory: require("./src/models/damr.OccupancyHistory"),
|
|
318
|
+
PaymentAccount: require("./src/models/damr.PaymentAccount"),
|
|
319
|
+
Reading: require("./src/models/damr.Reading"),
|
|
320
|
+
StkPushRequest: require("./src/models/damr.StkPushRequest"),
|
|
321
|
+
TariffPlan: require("./src/models/damr.TariffPlan"),
|
|
322
|
+
VerificationCode: require("./src/models/damr.VerificationCode"),
|
|
305
323
|
};
|
|
306
324
|
|
|
307
325
|
// Function to get models dynamically from a specific database connection
|
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const bulkMeterSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
facilityId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "Facility",
|
|
8
|
+
required: true,
|
|
9
|
+
unique: true,
|
|
10
|
+
},
|
|
11
|
+
serialNumber: { type: String, trim: true, default: null },
|
|
12
|
+
installationDate: { type: Date, default: Date.now },
|
|
13
|
+
initialReading: { type: Number, default: 0 },
|
|
14
|
+
lastReadingValue: { type: Number, default: null },
|
|
15
|
+
lastReadingDate: { type: Date, default: null },
|
|
16
|
+
createdBy: {
|
|
17
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
18
|
+
ref: "User",
|
|
19
|
+
default: null,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{ timestamps: true },
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const BulkMeter = mongoose.model('damr.BulkMeter', bulkMeterSchema);
|
|
26
|
+
|
|
27
|
+
module.exports = BulkMeter;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const bulkReadingSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
bulkMeterId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "damr.BulkMeter",
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
facilityId: {
|
|
11
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
12
|
+
ref: "Facility",
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
readingDate: { type: Date, default: Date.now },
|
|
16
|
+
value: { type: Number, required: true },
|
|
17
|
+
previousValue: { type: Number, default: null },
|
|
18
|
+
consumption: { type: Number, default: null },
|
|
19
|
+
submittedBy: {
|
|
20
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
21
|
+
ref: "User",
|
|
22
|
+
default: null,
|
|
23
|
+
},
|
|
24
|
+
notes: { type: String, default: null },
|
|
25
|
+
},
|
|
26
|
+
{ timestamps: true },
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const BulkReading = mongoose.model('damr.BulkReading', bulkReadingSchema);
|
|
30
|
+
|
|
31
|
+
module.exports = BulkReading;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const creditSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
residentId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "Resident",
|
|
8
|
+
required: true,
|
|
9
|
+
index: true,
|
|
10
|
+
},
|
|
11
|
+
facilityId: {
|
|
12
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
+
ref: "Facility",
|
|
14
|
+
default: null,
|
|
15
|
+
},
|
|
16
|
+
amount: { type: Number, required: true, min: 0 },
|
|
17
|
+
remainingAmount: { type: Number, required: true, min: 0 },
|
|
18
|
+
reason: { type: String, trim: true, default: null },
|
|
19
|
+
status: {
|
|
20
|
+
type: String,
|
|
21
|
+
enum: ["open", "applied", "void"],
|
|
22
|
+
default: "open",
|
|
23
|
+
},
|
|
24
|
+
appliedToInvoiceIds: [
|
|
25
|
+
{ type: mongoose.Schema.Types.ObjectId, ref: "damr.MeterInvoice" },
|
|
26
|
+
],
|
|
27
|
+
issuedBy: {
|
|
28
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
29
|
+
ref: "User",
|
|
30
|
+
default: null,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{ timestamps: true },
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const Credit = mongoose.model('damr.Credit', creditSchema);
|
|
37
|
+
|
|
38
|
+
module.exports = Credit;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const counterSchema = new mongoose.Schema({
|
|
4
|
+
key: { type: String, required: true, unique: true },
|
|
5
|
+
seq: { type: Number, default: 0 },
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const DAMRCounter = mongoose.model('damr.DAMRCounter', counterSchema);
|
|
9
|
+
|
|
10
|
+
module.exports = DAMRCounter;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const facilitySettingsSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
facilityId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "Facility",
|
|
8
|
+
required: true,
|
|
9
|
+
unique: true,
|
|
10
|
+
},
|
|
11
|
+
mpesaShortCode: { type: String, trim: true, default: null },
|
|
12
|
+
mpesaConsumerKey: { type: String, trim: true, default: null },
|
|
13
|
+
mpesaConsumerSecret: { type: String, trim: true, default: null },
|
|
14
|
+
mpesaPasskey: { type: String, trim: true, default: null },
|
|
15
|
+
mpesaC2bRegistered: { type: Boolean, default: false },
|
|
16
|
+
},
|
|
17
|
+
{ timestamps: true },
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const FacilitySettings = mongoose.model('damr.FacilitySettings', facilitySettingsSchema);
|
|
21
|
+
|
|
22
|
+
module.exports = FacilitySettings;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const flagSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
meterId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "damr.Meter",
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
readingId: {
|
|
11
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
12
|
+
ref: "damr.Reading",
|
|
13
|
+
default: null,
|
|
14
|
+
},
|
|
15
|
+
facilityId: {
|
|
16
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
17
|
+
ref: "Facility",
|
|
18
|
+
default: null,
|
|
19
|
+
},
|
|
20
|
+
type: {
|
|
21
|
+
type: String,
|
|
22
|
+
enum: [
|
|
23
|
+
"high_consumption",
|
|
24
|
+
"ocr_mismatch",
|
|
25
|
+
"missing_reading",
|
|
26
|
+
"manual_review",
|
|
27
|
+
"duplicate_submission",
|
|
28
|
+
"serial_mismatch",
|
|
29
|
+
"serial_unverified",
|
|
30
|
+
"SPIKE",
|
|
31
|
+
"DROP",
|
|
32
|
+
"ZERO_FLOW",
|
|
33
|
+
"OVERNIGHT_LEAK",
|
|
34
|
+
"ERRATIC",
|
|
35
|
+
"CRITICAL",
|
|
36
|
+
],
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
status: { type: String, enum: ["open", "resolved"], default: "open" },
|
|
40
|
+
description: { type: String },
|
|
41
|
+
notes: { type: String, default: null },
|
|
42
|
+
resolvedBy: {
|
|
43
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
44
|
+
ref: "User",
|
|
45
|
+
default: null,
|
|
46
|
+
},
|
|
47
|
+
resolvedAt: { type: Date, default: null },
|
|
48
|
+
staffId: {
|
|
49
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
50
|
+
ref: "User",
|
|
51
|
+
default: null,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{ timestamps: true },
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const Flag = mongoose.model('damr.Flag', flagSchema);
|
|
58
|
+
|
|
59
|
+
module.exports = Flag;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const locationSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
name: { type: String, required: true, trim: true },
|
|
6
|
+
county: { type: String, trim: true },
|
|
7
|
+
town: { type: String, trim: true },
|
|
8
|
+
address: { type: String, trim: true },
|
|
9
|
+
createdBy: {
|
|
10
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
11
|
+
ref: "User",
|
|
12
|
+
default: null,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{ timestamps: true },
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const Location = mongoose.model('damr.Location', locationSchema);
|
|
19
|
+
|
|
20
|
+
module.exports = Location;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const meterSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
serialNumber: { type: String, required: true, unique: true, trim: true },
|
|
6
|
+
manufacturer: { type: String, trim: true },
|
|
7
|
+
model: { type: String, trim: true },
|
|
8
|
+
meterType: {
|
|
9
|
+
type: String,
|
|
10
|
+
enum: ["analogue", "digital"],
|
|
11
|
+
default: "analogue",
|
|
12
|
+
},
|
|
13
|
+
installationDate: { type: Date, default: Date.now },
|
|
14
|
+
initialReading: { type: Number, default: 0 },
|
|
15
|
+
condition: {
|
|
16
|
+
type: String,
|
|
17
|
+
enum: ["new", "used", "replaced"],
|
|
18
|
+
default: "new",
|
|
19
|
+
},
|
|
20
|
+
status: {
|
|
21
|
+
type: String,
|
|
22
|
+
enum: ["UNASSIGNED", "ASSIGNED", "FAULTY"],
|
|
23
|
+
default: "UNASSIGNED",
|
|
24
|
+
},
|
|
25
|
+
unitId: {
|
|
26
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
27
|
+
ref: "Unit",
|
|
28
|
+
default: null,
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
division: { type: String, default: null, trim: true },
|
|
32
|
+
facilityId: {
|
|
33
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
34
|
+
ref: "Facility",
|
|
35
|
+
default: null,
|
|
36
|
+
},
|
|
37
|
+
currentResident: {
|
|
38
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
39
|
+
ref: "Resident",
|
|
40
|
+
default: null,
|
|
41
|
+
},
|
|
42
|
+
lastReadingValue: { type: Number, default: null },
|
|
43
|
+
lastReadingDate: { type: Date, default: null },
|
|
44
|
+
lastReadingBy: {
|
|
45
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
46
|
+
ref: "User",
|
|
47
|
+
default: null,
|
|
48
|
+
},
|
|
49
|
+
openFlagCount: { type: Number, default: 0 },
|
|
50
|
+
},
|
|
51
|
+
{ timestamps: true },
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const Meter = mongoose.model('damr.Meter', meterSchema);
|
|
55
|
+
|
|
56
|
+
module.exports = Meter;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const meterBindingSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
meterId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "damr.Meter",
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
residentId: {
|
|
11
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
12
|
+
ref: "Resident",
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
unitId: {
|
|
16
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
17
|
+
ref: "Unit",
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
bindDate: { type: Date, default: Date.now },
|
|
21
|
+
unbindDate: { type: Date, default: null },
|
|
22
|
+
active: { type: Boolean, default: true },
|
|
23
|
+
},
|
|
24
|
+
{ timestamps: true },
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const MeterBinding = mongoose.model('damr.MeterBinding', meterBindingSchema);
|
|
28
|
+
|
|
29
|
+
module.exports = MeterBinding;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const invoiceSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
meterId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "damr.Meter",
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
readingId: {
|
|
11
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
12
|
+
ref: "damr.Reading",
|
|
13
|
+
default: null,
|
|
14
|
+
},
|
|
15
|
+
residentId: {
|
|
16
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
17
|
+
ref: "Resident",
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
unitId: {
|
|
21
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
22
|
+
ref: "Unit",
|
|
23
|
+
default: null,
|
|
24
|
+
},
|
|
25
|
+
facilityId: {
|
|
26
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
27
|
+
ref: "Facility",
|
|
28
|
+
default: null,
|
|
29
|
+
},
|
|
30
|
+
periodStart: { type: Date, required: true },
|
|
31
|
+
periodEnd: { type: Date, required: true },
|
|
32
|
+
consumption: { type: Number, required: true },
|
|
33
|
+
ratePerUnit: { type: Number, required: true },
|
|
34
|
+
totalAmount: { type: Number, required: true },
|
|
35
|
+
amountPaid: { type: Number, default: 0 },
|
|
36
|
+
balance: { type: Number, default: null },
|
|
37
|
+
status: {
|
|
38
|
+
type: String,
|
|
39
|
+
enum: ["Unpaid", "Paid", "Partial", "Void", "Overdue", "Held"],
|
|
40
|
+
default: "Unpaid",
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
invoiceNumber: { type: String, unique: true, sparse: true, index: true },
|
|
44
|
+
|
|
45
|
+
viewStatus: {
|
|
46
|
+
isOpened: { type: Boolean, default: false },
|
|
47
|
+
openedAt: { type: Date, default: null },
|
|
48
|
+
},
|
|
49
|
+
reconciliationHistory: {
|
|
50
|
+
type: [
|
|
51
|
+
{
|
|
52
|
+
_id: false,
|
|
53
|
+
date: { type: Date, default: Date.now },
|
|
54
|
+
amount: { type: Number, required: true },
|
|
55
|
+
type: { type: String, default: "payment" },
|
|
56
|
+
reference: { type: String, default: null },
|
|
57
|
+
status: { type: String, default: "Completed" },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
default: [],
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
heldReason: { type: String, default: null },
|
|
64
|
+
mpesaCode: { type: String, default: null },
|
|
65
|
+
appliedReceipts: { type: [String], default: [] },
|
|
66
|
+
paidAt: { type: Date, default: null },
|
|
67
|
+
generatedBy: {
|
|
68
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
69
|
+
ref: "User",
|
|
70
|
+
default: null,
|
|
71
|
+
},
|
|
72
|
+
dueDate: { type: Date, default: null },
|
|
73
|
+
tariffPlanId: {
|
|
74
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
75
|
+
ref: "damr.TariffPlan",
|
|
76
|
+
default: null,
|
|
77
|
+
},
|
|
78
|
+
paymentMethod: { type: String, enum: ["mpesa", "bank"], default: "mpesa" },
|
|
79
|
+
paybillShortCode: { type: String, default: null },
|
|
80
|
+
bankDetails: {
|
|
81
|
+
bankName: { type: String, default: null },
|
|
82
|
+
bankAccountName: { type: String, default: null },
|
|
83
|
+
bankAccountNumber: { type: String, default: null },
|
|
84
|
+
bankBranchName: { type: String, default: null },
|
|
85
|
+
bankBranchCode: { type: String, default: null },
|
|
86
|
+
bankSwiftCode: { type: String, default: null },
|
|
87
|
+
_id: false,
|
|
88
|
+
},
|
|
89
|
+
breakdown: {
|
|
90
|
+
bands: [
|
|
91
|
+
{
|
|
92
|
+
_id: false,
|
|
93
|
+
from: Number,
|
|
94
|
+
to: { type: Number, default: null },
|
|
95
|
+
units: Number,
|
|
96
|
+
rate: Number,
|
|
97
|
+
amount: Number,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
waterCharge: { type: Number, default: 0 },
|
|
101
|
+
sewerageCharge: { type: Number, default: 0 },
|
|
102
|
+
techFee: { type: Number, default: 0 },
|
|
103
|
+
minimumChargeApplied: { type: Boolean, default: false },
|
|
104
|
+
arrears: { type: Number, default: 0 },
|
|
105
|
+
creditsApplied: { type: Number, default: 0 },
|
|
106
|
+
penalty: { type: Number, default: 0 },
|
|
107
|
+
|
|
108
|
+
taxRate: { type: Number, default: 0 },
|
|
109
|
+
tax: { type: Number, default: 0 },
|
|
110
|
+
},
|
|
111
|
+
penaltyApplied: { type: Boolean, default: false },
|
|
112
|
+
remindersSent: {
|
|
113
|
+
upcoming: { type: Boolean, default: false },
|
|
114
|
+
dueToday: { type: Boolean, default: false },
|
|
115
|
+
},
|
|
116
|
+
publicToken: { type: String, unique: true, sparse: true },
|
|
117
|
+
publicTokenExpiresAt: { type: Date, default: null },
|
|
118
|
+
notes: { type: String, default: null },
|
|
119
|
+
editHistory: {
|
|
120
|
+
type: [
|
|
121
|
+
{
|
|
122
|
+
_id: false,
|
|
123
|
+
editedBy: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
|
|
124
|
+
editedAt: { type: Date, default: Date.now },
|
|
125
|
+
changes: [
|
|
126
|
+
{
|
|
127
|
+
_id: false,
|
|
128
|
+
field: String,
|
|
129
|
+
before: mongoose.Schema.Types.Mixed,
|
|
130
|
+
after: mongoose.Schema.Types.Mixed,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
reason: { type: String, default: null },
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
default: [],
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
{ timestamps: true },
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const MeterInvoice = mongoose.model('damr.MeterInvoice', invoiceSchema);
|
|
143
|
+
|
|
144
|
+
module.exports = MeterInvoice;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const mpesaTransactionSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
transId: { type: String, required: true, unique: true, trim: true },
|
|
6
|
+
accountNumber: { type: String, required: true, trim: true, index: true },
|
|
7
|
+
amount: { type: Number, required: true },
|
|
8
|
+
msisdn: { type: String, default: null },
|
|
9
|
+
transTime: { type: String, default: null },
|
|
10
|
+
shortCode: { type: String, default: null },
|
|
11
|
+
source: {
|
|
12
|
+
type: String,
|
|
13
|
+
enum: ["mpesa-c2b", "cash"],
|
|
14
|
+
default: "mpesa-c2b",
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
rawPayload: { type: Object, default: null },
|
|
18
|
+
},
|
|
19
|
+
{ timestamps: true },
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const MpesaTransaction = mongoose.model('damr.MpesaTransaction', mpesaTransactionSchema);
|
|
23
|
+
|
|
24
|
+
module.exports = MpesaTransaction;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const occupancyHistorySchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
unitId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "Unit",
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
residentId: {
|
|
11
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
12
|
+
ref: "Resident",
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
moveInDate: { type: Date, default: Date.now },
|
|
16
|
+
moveOutDate: { type: Date, default: null },
|
|
17
|
+
moveOutReason: {
|
|
18
|
+
type: String,
|
|
19
|
+
enum: ["transfer", "eviction", "lease_end", "other"],
|
|
20
|
+
default: null,
|
|
21
|
+
},
|
|
22
|
+
recordedBy: {
|
|
23
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
24
|
+
ref: "User",
|
|
25
|
+
default: null,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{ timestamps: true },
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const OccupancyHistory = mongoose.model('damr.OccupancyHistory', occupancyHistorySchema);
|
|
32
|
+
|
|
33
|
+
module.exports = OccupancyHistory;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const paymentAccountSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
residentId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "Resident",
|
|
8
|
+
required: true,
|
|
9
|
+
index: true,
|
|
10
|
+
},
|
|
11
|
+
facilityId: {
|
|
12
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
+
ref: "Facility",
|
|
14
|
+
required: true,
|
|
15
|
+
index: true,
|
|
16
|
+
},
|
|
17
|
+
unitId: {
|
|
18
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
19
|
+
ref: "Unit",
|
|
20
|
+
default: null,
|
|
21
|
+
},
|
|
22
|
+
accountNumber: { type: String, required: true, unique: true, trim: true },
|
|
23
|
+
appliedReceipts: { type: [String], default: [] },
|
|
24
|
+
},
|
|
25
|
+
{ timestamps: true },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const PaymentAccount = mongoose.model('damr.PaymentAccount', paymentAccountSchema);
|
|
29
|
+
|
|
30
|
+
module.exports = PaymentAccount;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const readingSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
meterId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "damr.Meter",
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
unitId: {
|
|
11
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
12
|
+
ref: "Unit",
|
|
13
|
+
default: null,
|
|
14
|
+
},
|
|
15
|
+
facilityId: {
|
|
16
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
17
|
+
ref: "Facility",
|
|
18
|
+
default: null,
|
|
19
|
+
},
|
|
20
|
+
readingDate: { type: Date, default: Date.now },
|
|
21
|
+
value: { type: Number, required: true },
|
|
22
|
+
previousValue: { type: Number, default: null },
|
|
23
|
+
consumption: { type: Number, default: null },
|
|
24
|
+
method: { type: String, enum: ["ocr", "manual"], default: "manual" },
|
|
25
|
+
imageUrl: { type: String, default: null },
|
|
26
|
+
ocrRawValue: { type: String, default: null },
|
|
27
|
+
ocrConfidence: { type: Number, default: null },
|
|
28
|
+
|
|
29
|
+
status: {
|
|
30
|
+
type: String,
|
|
31
|
+
enum: ["confirmed", "rejected"],
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
submittedBy: {
|
|
35
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
36
|
+
ref: "User",
|
|
37
|
+
default: null,
|
|
38
|
+
},
|
|
39
|
+
confirmedBy: {
|
|
40
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
41
|
+
ref: "User",
|
|
42
|
+
default: null,
|
|
43
|
+
},
|
|
44
|
+
notes: { type: String, default: null },
|
|
45
|
+
},
|
|
46
|
+
{ timestamps: true },
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const Reading = mongoose.model('damr.Reading', readingSchema);
|
|
50
|
+
|
|
51
|
+
module.exports = Reading;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const stkPushRequestSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
invoiceId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "damr.MeterInvoice",
|
|
8
|
+
required: true,
|
|
9
|
+
index: true,
|
|
10
|
+
},
|
|
11
|
+
residentId: {
|
|
12
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
+
ref: "Resident",
|
|
14
|
+
default: null,
|
|
15
|
+
},
|
|
16
|
+
facilityId: {
|
|
17
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
18
|
+
ref: "Facility",
|
|
19
|
+
default: null,
|
|
20
|
+
},
|
|
21
|
+
phone: { type: String, required: true },
|
|
22
|
+
amount: { type: Number, required: true },
|
|
23
|
+
accountReference: { type: String, default: null },
|
|
24
|
+
merchantRequestId: { type: String, default: null },
|
|
25
|
+
checkoutRequestId: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
unique: true,
|
|
29
|
+
index: true,
|
|
30
|
+
},
|
|
31
|
+
status: {
|
|
32
|
+
type: String,
|
|
33
|
+
enum: ["pending", "success", "failed", "cancelled"],
|
|
34
|
+
default: "pending",
|
|
35
|
+
},
|
|
36
|
+
resultCode: { type: Number, default: null },
|
|
37
|
+
resultDesc: { type: String, default: null },
|
|
38
|
+
mpesaReceiptNumber: { type: String, default: null },
|
|
39
|
+
transactionDate: { type: String, default: null },
|
|
40
|
+
},
|
|
41
|
+
{ timestamps: true },
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const StkPushRequest = mongoose.model('damr.StkPushRequest', stkPushRequestSchema);
|
|
45
|
+
|
|
46
|
+
module.exports = StkPushRequest;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const tariffBandSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
|
|
6
|
+
upTo: { type: Number, default: null },
|
|
7
|
+
rate: { type: Number, required: true, min: 0 },
|
|
8
|
+
},
|
|
9
|
+
{ _id: false },
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const tariffPlanSchema = new mongoose.Schema(
|
|
13
|
+
{
|
|
14
|
+
name: { type: String, required: true, trim: true },
|
|
15
|
+
facilityId: {
|
|
16
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
17
|
+
ref: "Facility",
|
|
18
|
+
required: true,
|
|
19
|
+
index: true,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
division: { type: String, default: null, trim: true, index: true },
|
|
23
|
+
|
|
24
|
+
unitType: { type: String, default: null, trim: true, index: true },
|
|
25
|
+
|
|
26
|
+
bands: {
|
|
27
|
+
type: [tariffBandSchema],
|
|
28
|
+
required: true,
|
|
29
|
+
validate: {
|
|
30
|
+
validator: (v) => Array.isArray(v) && v.length > 0,
|
|
31
|
+
message: "A tariff plan needs at least one band",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
minimumCharge: { type: Number, default: 0, min: 0 },
|
|
35
|
+
sewerageRate: { type: Number, default: 0.75, min: 0 },
|
|
36
|
+
techFee: { type: Number, default: 150, min: 0 },
|
|
37
|
+
penaltyEnabled: { type: Boolean, default: false },
|
|
38
|
+
penaltyType: {
|
|
39
|
+
type: String,
|
|
40
|
+
enum: ["percentage", "flat"],
|
|
41
|
+
default: "percentage",
|
|
42
|
+
},
|
|
43
|
+
penaltyValue: { type: Number, default: 0, min: 0 },
|
|
44
|
+
dueDateOffsetDays: { type: Number, default: 15, min: 0 },
|
|
45
|
+
reminderDaysBefore: { type: Number, default: 3, min: 0 },
|
|
46
|
+
|
|
47
|
+
taxRate: { type: Number, default: 0, min: 0, max: 100 },
|
|
48
|
+
|
|
49
|
+
paymentMethod: {
|
|
50
|
+
type: String,
|
|
51
|
+
enum: ["mpesa", "bank"],
|
|
52
|
+
default: "mpesa",
|
|
53
|
+
},
|
|
54
|
+
paybillShortCode: { type: String, trim: true, default: null },
|
|
55
|
+
bankName: { type: String, trim: true, default: null },
|
|
56
|
+
bankAccountName: { type: String, trim: true, default: null },
|
|
57
|
+
bankAccountNumber: { type: String, trim: true, default: null },
|
|
58
|
+
bankBranchName: { type: String, trim: true, default: null },
|
|
59
|
+
bankBranchCode: { type: String, trim: true, default: null },
|
|
60
|
+
bankSwiftCode: { type: String, trim: true, default: null },
|
|
61
|
+
|
|
62
|
+
active: { type: Boolean, default: true },
|
|
63
|
+
createdBy: {
|
|
64
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
65
|
+
ref: "User",
|
|
66
|
+
default: null,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{ timestamps: true },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const TariffPlan = mongoose.model('damr.TariffPlan', tariffPlanSchema);
|
|
73
|
+
|
|
74
|
+
module.exports = TariffPlan;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const verificationCodeSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
userId: {
|
|
6
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
7
|
+
ref: "User",
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
identifier: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true,
|
|
13
|
+
trim: true,
|
|
14
|
+
},
|
|
15
|
+
channel: {
|
|
16
|
+
type: String,
|
|
17
|
+
enum: ["email", "phone"],
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
code: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
attempts: {
|
|
25
|
+
type: Number,
|
|
26
|
+
default: 0,
|
|
27
|
+
},
|
|
28
|
+
consumedAt: {
|
|
29
|
+
type: Date,
|
|
30
|
+
default: null,
|
|
31
|
+
},
|
|
32
|
+
expiresAt: {
|
|
33
|
+
type: Date,
|
|
34
|
+
required: true,
|
|
35
|
+
index: { expires: 0 },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{ timestamps: true },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const VerificationCode = mongoose.model('damr.VerificationCode', verificationCodeSchema);
|
|
42
|
+
|
|
43
|
+
module.exports = VerificationCode;
|