payservedb 10.2.1 → 10.2.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/index.js CHANGED
@@ -276,6 +276,7 @@ const models = {
276
276
  QuickBooksAccountMapping: require("./src/models/quickbooks_account_mapping"),
277
277
  QuickBooksItemMapping: require("./src/models/quickbooks_item_mapping"),
278
278
  QuickBooksPaymentChannelMapping: require("./src/models/quickbooks_payment_channel_mapping"),
279
+ QuickBooksPostingRule: require("./src/models/quickbooks_posting_rule"),
279
280
  QuickBooksCustomerMapping: require("./src/models/quickbooks_customer_mapping"),
280
281
  QuickBooksVendorMapping: require("./src/models/quickbooks_vendor_mapping"),
281
282
  QuickBooksInvoiceMapping: require("./src/models/quickbooks_invoice_mapping"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "10.2.1",
3
+ "version": "10.2.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -13,6 +13,8 @@ const facilityAccountSnapshotSchema = new mongoose.Schema({
13
13
  waterAccounts: { type: Number, default: 0 },
14
14
  leaseAccounts: { type: Number, default: 0 },
15
15
  levyAccounts: { type: Number, default: 0 },
16
+ powerMeters: { type: Number, default: 0 },
17
+ waterMeters: { type: Number, default: 0 },
16
18
  source: { type: String, enum: ['cron', 'backfill'], required: true },
17
19
  snapshotAt: { type: Date, default: Date.now }
18
20
  }, {
@@ -14,8 +14,32 @@ const facilityPaymentDetailsSchema = new mongoose.Schema({
14
14
  enum: ["All", "Water", "Electricity", "Levy","Lease","Booking"],
15
15
  default: "All"
16
16
  },
17
+ provider: {
18
+ type: String,
19
+ trim: true,
20
+ uppercase: true,
21
+ default: "MPESA"
22
+ },
23
+ bankName: { type: String, trim: true },
24
+ billerReference: { type: String, trim: true },
17
25
  });
18
26
 
19
27
  const FacilityPaymentDetails = mongoose.model('FacilityPaymentDetails', facilityPaymentDetailsSchema);
20
28
 
29
+ FacilityPaymentDetails.isBankRow = function (details) {
30
+ const provider = String(details?.provider || "MPESA").toUpperCase();
31
+ return provider !== "MPESA";
32
+ };
33
+ FacilityPaymentDetails.buildPaymentInstructions = function (details, accountNumber) {
34
+ const account = String(accountNumber ?? "").trim();
35
+ const biller = String(details?.billerReference || "").trim();
36
+ const useBillerPrefix = FacilityPaymentDetails.isBankRow(details) && biller;
37
+
38
+ return {
39
+ payTo: "Mpesa",
40
+ paybill: details?.shortCode || "",
41
+ accountNo: useBillerPrefix ? `${biller}#${account}` : account,
42
+ };
43
+ };
44
+
21
45
  module.exports = FacilityPaymentDetails;
@@ -79,7 +79,7 @@ const powerMeterPowerChargeSchema = new mongoose.Schema({
79
79
  timestamps: true
80
80
  });
81
81
 
82
- powerMeterPowerChargeSchema.index({ facilityId: 1, yearMonth: 1 }, { unique: true });
82
+ powerMeterPowerChargeSchema.index({ facilityId: 1, yearMonth: 1, tariff: 1 }, { unique: true });
83
83
 
84
84
  const PowerMeterPowerCharge = mongoose.model('PowerMeterPowerCharge', powerMeterPowerChargeSchema);
85
85
 
@@ -1,8 +1,10 @@
1
- // Lease security deposit <-> QuickBooks invoice line.
1
+ // Lease security deposit <-> its own QuickBooks invoice ("<invoice>-DEP").
2
2
  // Lease deposits have no Deposit document (they are a "Security Deposit" line
3
- // on the tenant's first lease invoice), so this collection records each one
4
- // separately from levy deposits (quickbooks_deposit_mapping). The line posts
5
- // to the "security_deposit_lease" Item, which must be a Liability.
3
+ // on the tenant's lease invoice), so this collection records each one
4
+ // separately from levy deposits (quickbooks_deposit_mapping). The deposit
5
+ // invoice posts to the "security_deposit_lease" Item, which must be a Liability.
6
+ // qbInvoiceId is the DEPOSIT invoice; the rent invoice stays in
7
+ // quickbooks_invoice_mapping.
6
8
  const mongoose = require("mongoose");
7
9
 
8
10
  const quickBooksLeaseDepositMappingSchema = new mongoose.Schema(
@@ -14,6 +16,7 @@ const quickBooksLeaseDepositMappingSchema = new mongoose.Schema(
14
16
  invoiceNumber: { type: String, default: null },
15
17
  customerId: { type: mongoose.Schema.Types.ObjectId, ref: "Customer", default: null },
16
18
  depositAmount: { type: Number, default: 0 },
19
+ // The deposit invoice in QuickBooks (not the rent invoice).
17
20
  qbInvoiceId: { type: String, trim: true, default: null },
18
21
  // Item the deposit line was posted with (security_deposit_lease mapping).
19
22
  qbItemId: { type: String, trim: true, default: null },
@@ -0,0 +1,41 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ // One double-entry posting rule per (realm, event, set of categories).
4
+ //
5
+ // invoice_issued Dr = Accounts Receivable account Cr = income / liability account
6
+ // payment_received Dr = Bank / Other Current Asset Cr = Accounts Receivable account
7
+ //
8
+ // For invoices QuickBooks takes the debit as Invoice.ARAccountRef and the
9
+ // credit from the Item's income account, so qbItemId is the PayServe-managed
10
+ // Item created for the credit account.
11
+ const quickBooksPostingRuleSchema = new mongoose.Schema(
12
+ {
13
+ facilityId: { type: mongoose.Schema.Types.ObjectId, ref: "Facility", required: true, index: true },
14
+ qbConfigId: { type: mongoose.Schema.Types.ObjectId, ref: "QuickBooksConfig", required: true, index: true },
15
+ event: { type: String, enum: ["invoice_issued", "payment_received"], required: true },
16
+ categories: { type: [String], default: [] },
17
+ // payment_received only. Empty = every channel.
18
+ channels: { type: [String], default: [] },
19
+
20
+ debitQbAccountId: { type: String, required: true, trim: true },
21
+ debitQbAccountName: { type: String, trim: true, default: null },
22
+ debitQbAccountType: { type: String, trim: true, default: null },
23
+
24
+ creditQbAccountId: { type: String, required: true, trim: true },
25
+ creditQbAccountName: { type: String, trim: true, default: null },
26
+ creditQbAccountType: { type: String, trim: true, default: null },
27
+
28
+ // invoice_issued only: Item whose income account is creditQbAccountId.
29
+ qbItemId: { type: String, trim: true, default: null },
30
+ qbItemName: { type: String, trim: true, default: null },
31
+
32
+ note: { type: String, trim: true, default: null },
33
+ isActive: { type: Boolean, default: true },
34
+ updatedBy: { type: mongoose.Schema.Types.ObjectId, default: null },
35
+ },
36
+ { timestamps: true },
37
+ );
38
+
39
+ quickBooksPostingRuleSchema.index({ facilityId: 1, qbConfigId: 1, event: 1 });
40
+
41
+ module.exports = { schema: quickBooksPostingRuleSchema };