payservedb 3.7.2 → 3.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "3.7.2",
3
+ "version": "3.7.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,6 +1,5 @@
1
1
  const mongoose = require("mongoose");
2
2
 
3
- // Define the schema for Invoice
4
3
  const invoiceSchema = new mongoose.Schema(
5
4
  {
6
5
  invoiceNumber: {
@@ -14,9 +13,19 @@ const invoiceSchema = new mongoose.Schema(
14
13
  unique: true,
15
14
  },
16
15
  client: {
17
- type: mongoose.Schema.Types.ObjectId,
18
- ref: "Customer",
19
- required: true,
16
+ clientId: {
17
+ type: mongoose.Schema.Types.ObjectId,
18
+ ref: "Customer",
19
+ required: true,
20
+ },
21
+ firstName: {
22
+ type: String,
23
+ required: true
24
+ },
25
+ lastName: {
26
+ type: String,
27
+ required: true
28
+ }
20
29
  },
21
30
  facility: {
22
31
  id: {
@@ -48,6 +57,16 @@ const invoiceSchema = new mongoose.Schema(
48
57
  type: Number,
49
58
  required: true,
50
59
  },
60
+ amountPaid: {
61
+ type: Number,
62
+ default: 0,
63
+ min: 0,
64
+ },
65
+ overpay: {
66
+ type: Number,
67
+ default: 0,
68
+ min: 0,
69
+ },
51
70
  issueDate: {
52
71
  type: Date,
53
72
  required: true,
@@ -81,6 +100,21 @@ const invoiceSchema = new mongoose.Schema(
81
100
  notificationTypes: [String],
82
101
  },
83
102
  ],
103
+ reconciliationHistory: [{
104
+ date: { type: Date, required: true },
105
+ amount: { type: Number, required: true },
106
+ type: {
107
+ type: String,
108
+ enum: ['payment', 'overpay-transfer', 'balance-deduction', 'overpay-received'],
109
+ required: true
110
+ },
111
+ sourceInvoice: String,
112
+ destinationInvoice: String,
113
+ paymentReference: String,
114
+ paymentCompletion: String,
115
+ remainingBalance: Number,
116
+ notes: String
117
+ }],
84
118
  paymentDetails: {
85
119
  paymentStatus: { type: String, required: true },
86
120
  paymentMethod: { type: String },
@@ -93,6 +127,18 @@ const invoiceSchema = new mongoose.Schema(
93
127
  }
94
128
  );
95
129
 
96
- const Invoice = mongoose.model("Invoice", invoiceSchema);
130
+ // Add indexes for frequently queried fields
131
+ invoiceSchema.index({ accountNumber: 1 });
132
+ invoiceSchema.index({ status: 1 });
133
+ invoiceSchema.index({ 'client.clientId': 1, status: 1 });
134
+ invoiceSchema.index({ 'reconciliationHistory.paymentReference': 1 });
135
+ invoiceSchema.index({ issueDate: -1 });
136
+
137
+ // Add virtual field for calculating balance
138
+ invoiceSchema.virtual('calculatedBalance').get(function () {
139
+ return this.totalAmount - (this.amountPaid || 0);
140
+ });
141
+
142
+ const Invoice = mongoose.model('Invoice', invoiceSchema);
97
143
 
98
144
  module.exports = Invoice;