payservedb 3.8.1 → 3.8.3
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 +1 -1
- package/src/models/invoice.js +62 -1
- package/src/models/leaseagreement.js +20 -7
package/package.json
CHANGED
package/src/models/invoice.js
CHANGED
|
@@ -33,11 +33,33 @@ const invoiceSchema = new mongoose.Schema(
|
|
|
33
33
|
ref: "Facility",
|
|
34
34
|
required: true,
|
|
35
35
|
},
|
|
36
|
+
name: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true
|
|
39
|
+
}
|
|
36
40
|
},
|
|
37
41
|
unit: {
|
|
38
42
|
id: { type: mongoose.Schema.Types.ObjectId, ref: "Unit", required: true },
|
|
39
43
|
name: { type: String, required: true },
|
|
40
44
|
},
|
|
45
|
+
currency: {
|
|
46
|
+
id: {
|
|
47
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
48
|
+
ref: "Currency",
|
|
49
|
+
required: true
|
|
50
|
+
},
|
|
51
|
+
name: {
|
|
52
|
+
type: String,
|
|
53
|
+
required: true
|
|
54
|
+
},
|
|
55
|
+
code: {
|
|
56
|
+
type: String,
|
|
57
|
+
required: true,
|
|
58
|
+
uppercase: true,
|
|
59
|
+
minlength: 3,
|
|
60
|
+
maxlength: 3
|
|
61
|
+
}
|
|
62
|
+
},
|
|
41
63
|
items: [
|
|
42
64
|
{
|
|
43
65
|
description: { type: String, required: true },
|
|
@@ -113,7 +135,15 @@ const invoiceSchema = new mongoose.Schema(
|
|
|
113
135
|
paymentReference: String,
|
|
114
136
|
paymentCompletion: String,
|
|
115
137
|
remainingBalance: Number,
|
|
116
|
-
notes: String
|
|
138
|
+
notes: String,
|
|
139
|
+
exchangeRate: {
|
|
140
|
+
type: Number,
|
|
141
|
+
default: 1 // For cross-currency reconciliations
|
|
142
|
+
},
|
|
143
|
+
originalCurrency: {
|
|
144
|
+
code: String, // Original currency code if different from invoice currency
|
|
145
|
+
amount: Number // Amount in original currency
|
|
146
|
+
}
|
|
117
147
|
}],
|
|
118
148
|
paymentDetails: {
|
|
119
149
|
paymentStatus: { type: String, required: true },
|
|
@@ -133,12 +163,43 @@ invoiceSchema.index({ status: 1 });
|
|
|
133
163
|
invoiceSchema.index({ 'client.clientId': 1, status: 1 });
|
|
134
164
|
invoiceSchema.index({ 'reconciliationHistory.paymentReference': 1 });
|
|
135
165
|
invoiceSchema.index({ issueDate: -1 });
|
|
166
|
+
invoiceSchema.index({ 'currency.code': 1 }); // Add index for currency code
|
|
167
|
+
invoiceSchema.index({ 'currency.id': 1 }); // Add index for currency ID
|
|
168
|
+
invoiceSchema.index({ 'currency.code': 1, 'client.clientId': 1, status: 1 }); // Compound index for currency-based queries
|
|
136
169
|
|
|
137
170
|
// Add virtual field for calculating balance
|
|
138
171
|
invoiceSchema.virtual('calculatedBalance').get(function () {
|
|
139
172
|
return this.totalAmount - (this.amountPaid || 0);
|
|
140
173
|
});
|
|
141
174
|
|
|
175
|
+
// Add method for currency conversion if needed
|
|
176
|
+
invoiceSchema.methods.convertAmount = function (amount, fromCurrency, toCurrency, exchangeRate) {
|
|
177
|
+
if (fromCurrency === toCurrency) {
|
|
178
|
+
return amount;
|
|
179
|
+
}
|
|
180
|
+
return amount * exchangeRate;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// Add static method to find invoices by currency
|
|
184
|
+
invoiceSchema.statics.findByCurrency = function (currencyCode) {
|
|
185
|
+
return this.find({ 'currency.code': currencyCode.toUpperCase() });
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// Add static method to calculate totals by currency
|
|
189
|
+
invoiceSchema.statics.calculateTotalsByCurrency = function (query = {}) {
|
|
190
|
+
return this.aggregate([
|
|
191
|
+
{ $match: query },
|
|
192
|
+
{
|
|
193
|
+
$group: {
|
|
194
|
+
_id: '$currency.code',
|
|
195
|
+
totalAmount: { $sum: '$totalAmount' },
|
|
196
|
+
totalPaid: { $sum: '$amountPaid' },
|
|
197
|
+
count: { $sum: 1 }
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
]);
|
|
201
|
+
};
|
|
202
|
+
|
|
142
203
|
const Invoice = mongoose.model('Invoice', invoiceSchema);
|
|
143
204
|
|
|
144
205
|
module.exports = Invoice;
|
|
@@ -39,19 +39,19 @@ const leaseAgreementSchema = new mongoose.Schema({
|
|
|
39
39
|
type: {
|
|
40
40
|
type: String,
|
|
41
41
|
required: true,
|
|
42
|
-
enum: ['Bank Transfer', '
|
|
42
|
+
enum: ['Bank Transfer', 'Cash', 'Cheque']
|
|
43
43
|
},
|
|
44
44
|
details: {
|
|
45
|
+
// Bank Transfer details
|
|
45
46
|
bankName: String,
|
|
46
47
|
accountName: String,
|
|
47
48
|
accountNumber: String,
|
|
48
49
|
branch: String,
|
|
49
50
|
swiftCode: String,
|
|
50
|
-
|
|
51
|
-
provider: String,
|
|
52
|
-
mobileAccountName: String,
|
|
51
|
+
// Cheque details
|
|
53
52
|
bankToDraft: String,
|
|
54
53
|
chequeAccountNumber: String,
|
|
54
|
+
// Cash details
|
|
55
55
|
preferredCashLocation: String
|
|
56
56
|
},
|
|
57
57
|
isPrimary: { type: Boolean, default: false }
|
|
@@ -60,6 +60,15 @@ const leaseAgreementSchema = new mongoose.Schema({
|
|
|
60
60
|
penaltyId: {
|
|
61
61
|
type: mongoose.Schema.Types.ObjectId,
|
|
62
62
|
ref: 'Penalty'
|
|
63
|
+
},
|
|
64
|
+
mpesaEnabled: {
|
|
65
|
+
type: Boolean,
|
|
66
|
+
default: false
|
|
67
|
+
},
|
|
68
|
+
mpesaDetails: {
|
|
69
|
+
businessNumber: String, // Paybill or Till number
|
|
70
|
+
accountNumber: String, // Account number if using Paybill
|
|
71
|
+
phoneNumber: String // Phone number for receiving payments
|
|
63
72
|
}
|
|
64
73
|
},
|
|
65
74
|
billingCycle: {
|
|
@@ -114,15 +123,19 @@ const leaseAgreementSchema = new mongoose.Schema({
|
|
|
114
123
|
method: {
|
|
115
124
|
type: {
|
|
116
125
|
type: String,
|
|
117
|
-
enum: ['Bank Transfer', '
|
|
126
|
+
enum: ['Bank Transfer', 'Cash', 'Cheque', 'MPESA'],
|
|
118
127
|
required: true
|
|
119
128
|
},
|
|
120
129
|
details: {
|
|
130
|
+
// Bank Transfer payment details
|
|
121
131
|
bankName: String,
|
|
122
132
|
accountNumber: String,
|
|
123
133
|
transactionId: String,
|
|
124
|
-
|
|
125
|
-
chequeNumber: String
|
|
134
|
+
// Cheque payment details
|
|
135
|
+
chequeNumber: String,
|
|
136
|
+
// MPESA payment details
|
|
137
|
+
mpesaTransactionId: String,
|
|
138
|
+
mpesaPhoneNumber: String
|
|
126
139
|
}
|
|
127
140
|
},
|
|
128
141
|
amount: { type: Number, required: true },
|