payservedb 9.8.4 → 9.8.5

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": "9.8.4",
3
+ "version": "9.8.5",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -390,6 +390,58 @@ const invoiceSchema = new mongoose.Schema(
390
390
 
391
391
  }
392
392
  },
393
+ // Zoho Books sync tracking
394
+ zohoSync: {
395
+ synced: {
396
+ type: Boolean,
397
+ default: false,
398
+ },
399
+ status: {
400
+ type: String,
401
+ enum: ["pending", "synced", "failed", "not-applicable"],
402
+ default: "not-applicable",
403
+ },
404
+ zohoInvoiceId: {
405
+ type: String,
406
+ default: null,
407
+ },
408
+ zohoInvoiceNumber: {
409
+ type: String,
410
+ default: null,
411
+ },
412
+ zohoCustomerId: {
413
+ type: String,
414
+ default: null,
415
+ },
416
+ zohoCustomerName: {
417
+ type: String,
418
+ default: null,
419
+ },
420
+ paymentId: {
421
+ type: String,
422
+ default: null,
423
+ },
424
+ paymentReference: {
425
+ type: String,
426
+ default: null,
427
+ },
428
+ syncedAt: {
429
+ type: Date,
430
+ default: null,
431
+ },
432
+ lastAttemptAt: {
433
+ type: Date,
434
+ default: null,
435
+ },
436
+ errorMessage: {
437
+ type: String,
438
+ default: null,
439
+ },
440
+ attempts: {
441
+ type: Number,
442
+ default: 0,
443
+ },
444
+ },
393
445
  // New fields for double entry accounts
394
446
  invoiceDoubleEntryAccount: {
395
447
  type: mongoose.Schema.Types.ObjectId,
@@ -441,6 +493,9 @@ invoiceSchema.index({ "notificationsSent.email": 1 }); // For finding email sent
441
493
  // eTims tax sync indexes
442
494
  invoiceSchema.index({ "txsync.status": 1 }); // For finding invoices by sync status
443
495
  invoiceSchema.index({ "txsync.etimsInvoiceNo": 1 }); // For looking up by eTims invoice number
496
+ // Zoho Books sync indexes
497
+ invoiceSchema.index({ "zohoSync.status": 1 }); // For finding invoices by Zoho sync status
498
+ invoiceSchema.index({ "zohoSync.zohoInvoiceId": 1 }); // For looking up by Zoho invoice ID
444
499
 
445
500
  // Add virtual field for calculating balance
446
501
  invoiceSchema.virtual("calculatedBalance").get(function () {
@@ -568,6 +623,22 @@ invoiceSchema.statics.findFailedTaxSync = function (facilityId) {
568
623
  });
569
624
  };
570
625
 
626
+ // Find invoices pending Zoho sync
627
+ invoiceSchema.statics.findPendingZohoSync = function (facilityId) {
628
+ return this.find({
629
+ "facility.id": facilityId,
630
+ "zohoSync.status": "pending",
631
+ });
632
+ };
633
+
634
+ // Find invoices with failed Zoho sync
635
+ invoiceSchema.statics.findFailedZohoSync = function (facilityId) {
636
+ return this.find({
637
+ "facility.id": facilityId,
638
+ "zohoSync.status": "failed",
639
+ });
640
+ };
641
+
571
642
  // Pre-save middleware to ensure overpay and balanceBroughtForward stay in sync during transition
572
643
  invoiceSchema.pre("save", function (next) {
573
644