@churchsoln/dbms 1.0.57 → 1.0.58

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.
@@ -64,6 +64,17 @@ const NORMAL_BALANCE = {
64
64
  CREDIT: "Credit",
65
65
  };
66
66
 
67
+ const JOURNAL_ENTRY_SOURCE_TYPE = {
68
+ CONTRIBUTION: "Contribution",
69
+ MANUAL: "Manual",
70
+ BILL: "Bill",
71
+ INVOICE: "Invoice",
72
+ };
73
+
74
+ const JOURNAL_ENTRY_STATUS = {
75
+ POSTED: "posted",
76
+ };
77
+
67
78
  const ACCOUNTING_ACCOUNT_TYPES = {
68
79
  ASSET: { name: "Asset", normalBalance: NORMAL_BALANCE.DEBIT },
69
80
  LIABILITY: { name: "Liability", normalBalance: NORMAL_BALANCE.CREDIT },
@@ -231,4 +242,6 @@ module.exports = {
231
242
  NORMAL_BALANCE,
232
243
  ACCOUNTING_ACCOUNT_TYPES,
233
244
  CHART_OF_ACCOUNTS,
245
+ JOURNAL_ENTRY_SOURCE_TYPE,
246
+ JOURNAL_ENTRY_STATUS,
234
247
  };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ module.exports = {
3
+ up: async (queryInterface, DataTypes) => {
4
+ await queryInterface
5
+ .createTable(
6
+ "JournalEntry",
7
+ {
8
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
9
+ entryDate: { type: DataTypes.DATEONLY, allowNull: false },
10
+ sourceType: { type: DataTypes.STRING, allowNull: true },
11
+ contributionTransactionId: { type: DataTypes.INTEGER, allowNull: true },
12
+ description: { type: DataTypes.TEXT, allowNull: true },
13
+ status: { type: DataTypes.STRING, defaultValue: "posted" },
14
+ createdAt: {
15
+ type: DataTypes.DATE,
16
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
17
+ },
18
+ updatedAt: {
19
+ type: DataTypes.DATE,
20
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
21
+ },
22
+ },
23
+ { timestamps: false }
24
+ )
25
+ .then(() =>
26
+ queryInterface.addConstraint("JournalEntry", {
27
+ fields: ["contributionTransactionId"],
28
+ type: "foreign key",
29
+ name: "JournalEntry_ContributionTransactionId_Fkey",
30
+ references: {
31
+ table: "ContributionTransaction",
32
+ field: "id",
33
+ },
34
+ onDelete: "restrict",
35
+ onUpdate: "cascade",
36
+ })
37
+ );
38
+ },
39
+ down: async (queryInterface) => {
40
+ await queryInterface.dropTable("JournalEntry");
41
+ },
42
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ module.exports = {
3
+ up: async (queryInterface, DataTypes) => {
4
+ await queryInterface
5
+ .createTable(
6
+ "JournalEntryLine",
7
+ {
8
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
9
+ journalEntryId: { type: DataTypes.INTEGER, allowNull: false },
10
+ chartOfAccountId: { type: DataTypes.INTEGER, allowNull: false },
11
+ debit: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0 },
12
+ credit: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0 },
13
+ memo: { type: DataTypes.TEXT, allowNull: true },
14
+ createdAt: {
15
+ type: DataTypes.DATE,
16
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
17
+ },
18
+ updatedAt: {
19
+ type: DataTypes.DATE,
20
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
21
+ },
22
+ },
23
+ { timestamps: false }
24
+ )
25
+ .then(() =>
26
+ queryInterface.addConstraint("JournalEntryLine", {
27
+ fields: ["journalEntryId"],
28
+ type: "foreign key",
29
+ name: "JournalEntryLine_JournalEntryId_Fkey",
30
+ references: {
31
+ table: "JournalEntry",
32
+ field: "id",
33
+ },
34
+ onDelete: "cascade",
35
+ onUpdate: "cascade",
36
+ })
37
+ )
38
+ .then(() =>
39
+ queryInterface.addConstraint("JournalEntryLine", {
40
+ fields: ["chartOfAccountId"],
41
+ type: "foreign key",
42
+ name: "JournalEntryLine_ChartOfAccountId_Fkey",
43
+ references: {
44
+ table: "ChartOfAccounts",
45
+ field: "id",
46
+ },
47
+ onDelete: "restrict",
48
+ onUpdate: "cascade",
49
+ })
50
+ );
51
+ },
52
+ down: async (queryInterface) => {
53
+ await queryInterface.dropTable("JournalEntryLine");
54
+ },
55
+ };
@@ -31,6 +31,10 @@ module.exports = (sequelize, DataTypes) => {
31
31
  foreignKey: "chartOfAccountId",
32
32
  as: "accounts",
33
33
  });
34
+ chartOfAccounts.hasMany(models.journalEntryLine, {
35
+ foreignKey: "chartOfAccountId",
36
+ as: "journalEntryLines",
37
+ });
34
38
  };
35
39
  chartOfAccounts.selectedFields = [
36
40
  "id",
@@ -71,6 +71,10 @@ module.exports = (sequelize, DataTypes) => {
71
71
  foreignKey: "contributionTransactionId",
72
72
  as: "contributionTransactionLine",
73
73
  });
74
+ contributionTransaction.hasMany(models.journalEntry, {
75
+ foreignKey: "contributionTransactionId",
76
+ as: "journalEntries",
77
+ });
74
78
  }
75
79
  contributionTransaction.selectedFields = [
76
80
  "id",
@@ -0,0 +1,37 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const journalEntry = sequelize.define(
3
+ "JournalEntry",
4
+ {
5
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
6
+ entryDate: { type: DataTypes.DATEONLY, allowNull: false },
7
+ sourceType: { type: DataTypes.STRING, allowNull: true },
8
+ contributionTransactionId: { type: DataTypes.INTEGER, allowNull: true },
9
+ description: { type: DataTypes.TEXT, allowNull: true },
10
+ status: { type: DataTypes.STRING, defaultValue: "posted" },
11
+ createdAt: { type: DataTypes.DATE },
12
+ updatedAt: { type: DataTypes.DATE },
13
+ },
14
+ { freezeTableName: true, timestamps: false }
15
+ );
16
+ journalEntry.associate = function (models) {
17
+ journalEntry.belongsTo(models.contributionTransaction, {
18
+ foreignKey: "contributionTransactionId",
19
+ as: "contributionTransaction",
20
+ });
21
+ journalEntry.hasMany(models.journalEntryLine, {
22
+ foreignKey: "journalEntryId",
23
+ as: "journalEntryLines",
24
+ });
25
+ };
26
+ journalEntry.selectedFields = [
27
+ "id",
28
+ "entryDate",
29
+ "sourceType",
30
+ "contributionTransactionId",
31
+ "description",
32
+ "status",
33
+ "createdAt",
34
+ "updatedAt",
35
+ ];
36
+ return journalEntry;
37
+ };
@@ -0,0 +1,37 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const journalEntryLine = sequelize.define(
3
+ "JournalEntryLine",
4
+ {
5
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
6
+ journalEntryId: { type: DataTypes.INTEGER, allowNull: false },
7
+ chartOfAccountId: { type: DataTypes.INTEGER, allowNull: false },
8
+ debit: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0 },
9
+ credit: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0 },
10
+ memo: { type: DataTypes.TEXT, allowNull: true },
11
+ createdAt: { type: DataTypes.DATE },
12
+ updatedAt: { type: DataTypes.DATE },
13
+ },
14
+ { freezeTableName: true, timestamps: false }
15
+ );
16
+ journalEntryLine.associate = function (models) {
17
+ journalEntryLine.belongsTo(models.journalEntry, {
18
+ foreignKey: "journalEntryId",
19
+ as: "journalEntry",
20
+ });
21
+ journalEntryLine.belongsTo(models.chartOfAccounts, {
22
+ foreignKey: "chartOfAccountId",
23
+ as: "chartOfAccount",
24
+ });
25
+ };
26
+ journalEntryLine.selectedFields = [
27
+ "id",
28
+ "journalEntryId",
29
+ "chartOfAccountId",
30
+ "debit",
31
+ "credit",
32
+ "memo",
33
+ "createdAt",
34
+ "updatedAt",
35
+ ];
36
+ return journalEntryLine;
37
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchsoln/dbms",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "prestart": "node db-setup.js",