@churchsoln/dbms 1.0.64 → 1.0.65

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.
@@ -117,6 +117,11 @@ const INVOICE_STATUS = {
117
117
  // An asset account, but not cash: excluded wherever "posting asset" means a bank/cash account.
118
118
  const ACCOUNTS_RECEIVABLE_CODE = "1100";
119
119
 
120
+ const BANK_RECONCILIATION_STATUS = {
121
+ IN_PROGRESS: "InProgress",
122
+ COMPLETED: "Completed",
123
+ };
124
+
120
125
  const ACCOUNTING_ACCOUNT_TYPES = {
121
126
  ASSET: { name: "Asset", normalBalance: NORMAL_BALANCE.DEBIT },
122
127
  LIABILITY: { name: "Liability", normalBalance: NORMAL_BALANCE.CREDIT },
@@ -294,4 +299,5 @@ module.exports = {
294
299
  ACCOUNTS_PAYABLE_CODE,
295
300
  INVOICE_STATUS,
296
301
  ACCOUNTS_RECEIVABLE_CODE,
302
+ BANK_RECONCILIATION_STATUS,
297
303
  };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ module.exports = {
3
+ up: async (queryInterface, DataTypes) => {
4
+ await queryInterface
5
+ .createTable(
6
+ "BankReconciliation",
7
+ {
8
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
9
+ chartOfAccountId: { type: DataTypes.INTEGER, allowNull: false },
10
+ statementDate: { type: DataTypes.DATEONLY, allowNull: false },
11
+ statementEndingBalance: { type: DataTypes.DECIMAL(12, 2), allowNull: false },
12
+ beginningBalance: { type: DataTypes.DECIMAL(12, 2), allowNull: false },
13
+ clearedBalance: { type: DataTypes.DECIMAL(12, 2), allowNull: true },
14
+ difference: { type: DataTypes.DECIMAL(12, 2), allowNull: true },
15
+ status: { type: DataTypes.STRING, allowNull: false },
16
+ startedAt: { type: DataTypes.DATE, allowNull: false },
17
+ completedAt: { type: DataTypes.DATE, allowNull: true },
18
+ createdBy: { type: DataTypes.INTEGER, allowNull: true },
19
+ createdAt: {
20
+ type: DataTypes.DATE,
21
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
22
+ },
23
+ updatedAt: {
24
+ type: DataTypes.DATE,
25
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
26
+ },
27
+ },
28
+ { timestamps: false }
29
+ )
30
+ .then(() =>
31
+ queryInterface.addConstraint("BankReconciliation", {
32
+ fields: ["chartOfAccountId"],
33
+ type: "foreign key",
34
+ name: "BankReconciliation_ChartOfAccountId_Fkey",
35
+ references: {
36
+ table: "ChartOfAccounts",
37
+ field: "id",
38
+ },
39
+ onDelete: "restrict",
40
+ onUpdate: "cascade",
41
+ })
42
+ );
43
+ },
44
+ down: async (queryInterface) => {
45
+ await queryInterface.dropTable("BankReconciliation");
46
+ },
47
+ };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ module.exports = {
3
+ up: async (queryInterface, DataTypes) => {
4
+ await queryInterface
5
+ .addColumn("JournalEntryLine", "cleared", {
6
+ type: DataTypes.BOOLEAN,
7
+ allowNull: false,
8
+ defaultValue: false,
9
+ })
10
+ .then(() =>
11
+ queryInterface.addColumn("JournalEntryLine", "bankReconciliationId", {
12
+ type: DataTypes.INTEGER,
13
+ allowNull: true,
14
+ })
15
+ )
16
+ .then(() =>
17
+ queryInterface.addConstraint("JournalEntryLine", {
18
+ fields: ["bankReconciliationId"],
19
+ type: "foreign key",
20
+ name: "JournalEntryLine_BankReconciliationId_Fkey",
21
+ references: {
22
+ table: "BankReconciliation",
23
+ field: "id",
24
+ },
25
+ onDelete: "set null",
26
+ onUpdate: "cascade",
27
+ })
28
+ );
29
+ },
30
+ down: async (queryInterface) => {
31
+ await queryInterface.removeConstraint("JournalEntryLine", "JournalEntryLine_BankReconciliationId_Fkey");
32
+ await queryInterface.removeColumn("JournalEntryLine", "bankReconciliationId");
33
+ await queryInterface.removeColumn("JournalEntryLine", "cleared");
34
+ },
35
+ };
@@ -0,0 +1,48 @@
1
+ const { BANK_RECONCILIATION_STATUS } = require("../../constants");
2
+
3
+ module.exports = (sequelize, DataTypes) => {
4
+ const bankReconciliation = sequelize.define(
5
+ "BankReconciliation",
6
+ {
7
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
8
+ chartOfAccountId: { type: DataTypes.INTEGER, allowNull: false },
9
+ statementDate: { type: DataTypes.DATEONLY, allowNull: false },
10
+ statementEndingBalance: { type: DataTypes.DECIMAL(12, 2), allowNull: false },
11
+ beginningBalance: { type: DataTypes.DECIMAL(12, 2), allowNull: false },
12
+ clearedBalance: { type: DataTypes.DECIMAL(12, 2), allowNull: true },
13
+ difference: { type: DataTypes.DECIMAL(12, 2), allowNull: true },
14
+ status: { type: DataTypes.STRING, defaultValue: BANK_RECONCILIATION_STATUS.IN_PROGRESS },
15
+ startedAt: { type: DataTypes.DATE },
16
+ completedAt: { type: DataTypes.DATE, allowNull: true },
17
+ createdBy: { type: DataTypes.INTEGER, allowNull: true },
18
+ createdAt: { type: DataTypes.DATE },
19
+ updatedAt: { type: DataTypes.DATE },
20
+ },
21
+ { freezeTableName: true, timestamps: false }
22
+ );
23
+ bankReconciliation.associate = function (models) {
24
+ bankReconciliation.belongsTo(models.chartOfAccounts, {
25
+ foreignKey: "chartOfAccountId",
26
+ as: "chartOfAccount",
27
+ });
28
+ bankReconciliation.hasMany(models.journalEntryLine, {
29
+ foreignKey: "bankReconciliationId",
30
+ as: "clearedLines",
31
+ });
32
+ };
33
+ bankReconciliation.selectedFields = [
34
+ "id",
35
+ "chartOfAccountId",
36
+ "statementDate",
37
+ "statementEndingBalance",
38
+ "beginningBalance",
39
+ "clearedBalance",
40
+ "difference",
41
+ "status",
42
+ "startedAt",
43
+ "completedAt",
44
+ "createdBy",
45
+ "createdAt",
46
+ ];
47
+ return bankReconciliation;
48
+ };
@@ -8,6 +8,10 @@ module.exports = (sequelize, DataTypes) => {
8
8
  debit: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0 },
9
9
  credit: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0 },
10
10
  memo: { type: DataTypes.TEXT, allowNull: true },
11
+ // Bank reconciliation: cleared is toggled while a reconciliation is in progress;
12
+ // bankReconciliationId is stamped once that reconciliation is completed, locking the line in.
13
+ cleared: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false },
14
+ bankReconciliationId: { type: DataTypes.INTEGER, allowNull: true },
11
15
  createdAt: { type: DataTypes.DATE },
12
16
  updatedAt: { type: DataTypes.DATE },
13
17
  },
@@ -22,6 +26,10 @@ module.exports = (sequelize, DataTypes) => {
22
26
  foreignKey: "chartOfAccountId",
23
27
  as: "chartOfAccount",
24
28
  });
29
+ journalEntryLine.belongsTo(models.bankReconciliation, {
30
+ foreignKey: "bankReconciliationId",
31
+ as: "bankReconciliation",
32
+ });
25
33
  };
26
34
  journalEntryLine.selectedFields = [
27
35
  "id",
@@ -30,6 +38,8 @@ module.exports = (sequelize, DataTypes) => {
30
38
  "debit",
31
39
  "credit",
32
40
  "memo",
41
+ "cleared",
42
+ "bankReconciliationId",
33
43
  "createdAt",
34
44
  "updatedAt",
35
45
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchsoln/dbms",
3
- "version": "1.0.64",
3
+ "version": "1.0.65",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "prestart": "node db-setup.js",