payservedb 4.0.0 → 4.0.2
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 +1 -0
- package/package.json +1 -1
- package/src/models/analog_water_meter.js +12 -3
- package/src/models/water_invoice.js +178 -0
package/index.js
CHANGED
|
@@ -112,6 +112,7 @@ const models = {
|
|
|
112
112
|
AnalogMeter: require('./src/models/analog_water_meter'),
|
|
113
113
|
AnalogBilling: require('./src/models/analog_water_billing'),
|
|
114
114
|
MeterSize: require('./src/models/water_meter_size'),
|
|
115
|
+
WaterInvoice: require('./src/models/water_invoice'),
|
|
115
116
|
MeterProtocol: require('./src/models/water_meter_communication'),
|
|
116
117
|
MeterManufacturer: require('./src/models/water_meter_manufacturer'),
|
|
117
118
|
MeterIotCard: require('./src/models/water_meter_iot_cards'),
|
package/package.json
CHANGED
|
@@ -21,6 +21,10 @@ const analogMeterSchema = new mongoose.Schema({
|
|
|
21
21
|
min: 0,
|
|
22
22
|
default: 0
|
|
23
23
|
},
|
|
24
|
+
previousReading: {
|
|
25
|
+
type: Number,
|
|
26
|
+
min: 0,
|
|
27
|
+
},
|
|
24
28
|
currentReading: {
|
|
25
29
|
type: Number,
|
|
26
30
|
min: 0,
|
|
@@ -37,9 +41,14 @@ const analogMeterSchema = new mongoose.Schema({
|
|
|
37
41
|
default: Date.now
|
|
38
42
|
},
|
|
39
43
|
readingHistory: [{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
previousReading: Number,
|
|
45
|
+
currentReading: Number,
|
|
46
|
+
readingDate: {
|
|
47
|
+
type: Date,
|
|
48
|
+
default: Date.now
|
|
49
|
+
},
|
|
50
|
+
readBy: String,
|
|
51
|
+
consumption: Number
|
|
43
52
|
}]
|
|
44
53
|
}, {
|
|
45
54
|
timestamps: true
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const waterInvoiceSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
// Basic identifiers
|
|
6
|
+
invoiceNumber: {
|
|
7
|
+
type: String,
|
|
8
|
+
required: true,
|
|
9
|
+
unique: true
|
|
10
|
+
},
|
|
11
|
+
accountNumber: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true,
|
|
14
|
+
unique: true
|
|
15
|
+
},
|
|
16
|
+
facilityId: {
|
|
17
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
customerId: {
|
|
21
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// Dates
|
|
26
|
+
dateIssued: {
|
|
27
|
+
type: Date,
|
|
28
|
+
default: Date.now
|
|
29
|
+
},
|
|
30
|
+
dueDate: {
|
|
31
|
+
type: Date,
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
// Meter & Consumption Details
|
|
36
|
+
meterNumber: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true
|
|
39
|
+
},
|
|
40
|
+
meterReadings: {
|
|
41
|
+
previousReading: {
|
|
42
|
+
type: Number,
|
|
43
|
+
required: true
|
|
44
|
+
},
|
|
45
|
+
currentReading: {
|
|
46
|
+
type: Number,
|
|
47
|
+
required: true
|
|
48
|
+
},
|
|
49
|
+
usage: {
|
|
50
|
+
type: Number,
|
|
51
|
+
required: true,
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
consumptionPeriod: {
|
|
55
|
+
startDate: {
|
|
56
|
+
type: Date,
|
|
57
|
+
required: true
|
|
58
|
+
},
|
|
59
|
+
endDate: {
|
|
60
|
+
type: Date,
|
|
61
|
+
required: true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
// Charges
|
|
66
|
+
charges: {
|
|
67
|
+
waterCharge: {
|
|
68
|
+
type: Number,
|
|
69
|
+
required: true
|
|
70
|
+
},
|
|
71
|
+
sewerCharge: {
|
|
72
|
+
type: Number,
|
|
73
|
+
default: 0
|
|
74
|
+
},
|
|
75
|
+
tax: {
|
|
76
|
+
type: Number,
|
|
77
|
+
default: 0
|
|
78
|
+
},
|
|
79
|
+
otherFees: {
|
|
80
|
+
type: Number,
|
|
81
|
+
default: 0
|
|
82
|
+
},
|
|
83
|
+
totalMonthlyBill: {
|
|
84
|
+
type: Number,
|
|
85
|
+
required: true
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
amountPaid: {
|
|
89
|
+
type: Number,
|
|
90
|
+
default: 0
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
// Invoice Note & Status
|
|
94
|
+
invoiceNote: {
|
|
95
|
+
type: String,
|
|
96
|
+
default: 'Payment is due within 10 days'
|
|
97
|
+
},
|
|
98
|
+
status: {
|
|
99
|
+
type: String,
|
|
100
|
+
required: true,
|
|
101
|
+
enum: ['Pending', 'Paid', 'Partially Paid', 'Cancelled', 'Overdue', 'Unpaid'],
|
|
102
|
+
default: 'Pending'
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// Currency Info
|
|
106
|
+
currency: {
|
|
107
|
+
id: {
|
|
108
|
+
type: mongoose.Schema.Types.ObjectId
|
|
109
|
+
},
|
|
110
|
+
name: {
|
|
111
|
+
type: String,
|
|
112
|
+
default: 'Kenyan Shilling'
|
|
113
|
+
},
|
|
114
|
+
code: {
|
|
115
|
+
type: String,
|
|
116
|
+
default: 'KES'
|
|
117
|
+
},
|
|
118
|
+
symbol: {
|
|
119
|
+
type: String,
|
|
120
|
+
default: 'KSh'
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
// Payment & Reconciliation
|
|
125
|
+
reconciliationHistory: [
|
|
126
|
+
{
|
|
127
|
+
date: {
|
|
128
|
+
type: Date,
|
|
129
|
+
default: Date.now
|
|
130
|
+
},
|
|
131
|
+
amount: {
|
|
132
|
+
type: Number,
|
|
133
|
+
required: true
|
|
134
|
+
},
|
|
135
|
+
type: {
|
|
136
|
+
type: String,
|
|
137
|
+
default: 'Manual'
|
|
138
|
+
},
|
|
139
|
+
paymentReference: {
|
|
140
|
+
type: String
|
|
141
|
+
},
|
|
142
|
+
paymentCompletion: {
|
|
143
|
+
type: String,
|
|
144
|
+
default: 'Completed'
|
|
145
|
+
},
|
|
146
|
+
sourceInvoice: {
|
|
147
|
+
type: String
|
|
148
|
+
},
|
|
149
|
+
destinationInvoice: {
|
|
150
|
+
type: String
|
|
151
|
+
},
|
|
152
|
+
notes: {
|
|
153
|
+
type: String
|
|
154
|
+
},
|
|
155
|
+
remainingBalance: {
|
|
156
|
+
type: Number
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
timestamps: true
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
waterInvoiceSchema.pre('save', function (next) {
|
|
167
|
+
if (this.isModified('dueDate') || this.isNew) {
|
|
168
|
+
const today = new Date();
|
|
169
|
+
if (this.dueDate < today && this.status === 'Pending') {
|
|
170
|
+
this.status = 'Overdue';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
next();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const WaterInvoice = mongoose.model('WaterInvoice', waterInvoiceSchema);
|
|
177
|
+
|
|
178
|
+
module.exports = WaterInvoice;
|