payservedb 8.9.2 → 8.9.4
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 +14 -0
- package/src/models/levy.js +0 -11
package/package.json
CHANGED
package/src/models/invoice.js
CHANGED
|
@@ -78,6 +78,13 @@ const invoiceSchema = new mongoose.Schema(
|
|
|
78
78
|
type: Number,
|
|
79
79
|
required: true,
|
|
80
80
|
},
|
|
81
|
+
taxes: [
|
|
82
|
+
{
|
|
83
|
+
name: { type: String, required: true }, // e.g. "VAT", "Withholding Tax"
|
|
84
|
+
percentage: { type: Number, required: true }, // e.g. 16
|
|
85
|
+
amount: { type: Number, required: true }, // e.g. 160.00 (subTotal * percentage / 100)
|
|
86
|
+
},
|
|
87
|
+
],
|
|
81
88
|
totalAmount: {
|
|
82
89
|
type: Number,
|
|
83
90
|
required: true,
|
|
@@ -462,6 +469,13 @@ invoiceSchema.statics.findFailedTaxSync = function (facilityId) {
|
|
|
462
469
|
|
|
463
470
|
// Pre-save middleware to ensure overpay and balanceBroughtForward stay in sync during transition
|
|
464
471
|
invoiceSchema.pre("save", function (next) {
|
|
472
|
+
|
|
473
|
+
if (this.taxes && this.taxes.length > 0) {
|
|
474
|
+
this.tax = Math.round(
|
|
475
|
+
this.taxes.reduce((sum, t) => sum + (t.amount || 0), 0) * 100
|
|
476
|
+
) / 100;
|
|
477
|
+
}
|
|
478
|
+
|
|
465
479
|
// If balanceBroughtForward is negative (credit), sync with overpay for backwards compatibility
|
|
466
480
|
if (this.balanceBroughtForward < 0) {
|
|
467
481
|
this.overpay = Math.abs(this.balanceBroughtForward);
|
package/src/models/levy.js
CHANGED
|
@@ -98,24 +98,20 @@ const levySchema = new mongoose.Schema(
|
|
|
98
98
|
debit: {
|
|
99
99
|
type: mongoose.Schema.Types.ObjectId,
|
|
100
100
|
ref: "GLAccount",
|
|
101
|
-
required: true,
|
|
102
101
|
},
|
|
103
102
|
credit: {
|
|
104
103
|
type: mongoose.Schema.Types.ObjectId,
|
|
105
104
|
ref: "GLAccount",
|
|
106
|
-
required: true,
|
|
107
105
|
}
|
|
108
106
|
},
|
|
109
107
|
payment: {
|
|
110
108
|
debit: {
|
|
111
109
|
type: mongoose.Schema.Types.ObjectId,
|
|
112
110
|
ref: "GLAccount",
|
|
113
|
-
required: true,
|
|
114
111
|
},
|
|
115
112
|
credit: {
|
|
116
113
|
type: mongoose.Schema.Types.ObjectId,
|
|
117
114
|
ref: "GLAccount",
|
|
118
|
-
required: true,
|
|
119
115
|
}
|
|
120
116
|
}
|
|
121
117
|
},
|
|
@@ -190,13 +186,6 @@ levySchema.pre('save', function (next) {
|
|
|
190
186
|
return next(error);
|
|
191
187
|
}
|
|
192
188
|
|
|
193
|
-
// Validate GL accounts
|
|
194
|
-
if (!this.glAccounts?.invoice?.debit || !this.glAccounts?.invoice?.credit ||
|
|
195
|
-
!this.glAccounts?.payment?.debit || !this.glAccounts?.payment?.credit) {
|
|
196
|
-
const error = new Error('All GL accounts (invoice and payment, debit and credit) are required');
|
|
197
|
-
return next(error);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
189
|
next();
|
|
201
190
|
});
|
|
202
191
|
|