@tomei/finance 0.3.0 → 0.3.2

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.
Files changed (178) hide show
  1. package/dist/account/account.d.ts +22 -27
  2. package/dist/account/account.js +89 -77
  3. package/dist/account/account.js.map +1 -1
  4. package/dist/account/account.repository.d.ts +3 -14
  5. package/dist/account/account.repository.js +4 -39
  6. package/dist/account/account.repository.js.map +1 -1
  7. package/dist/account/interfaces/account-attr.interface.d.ts +15 -7
  8. package/dist/account-system-entity/account-system-entity.d.ts +2 -2
  9. package/dist/account-system-entity/account-system-entity.js +1 -1
  10. package/dist/account-system-entity/post-history.repository.d.ts +2 -2
  11. package/dist/account-system-entity/post-history.repository.js +1 -1
  12. package/dist/customer/customer.d.ts +3 -3
  13. package/dist/customer/customer.js +1 -2
  14. package/dist/customer/customer.js.map +1 -1
  15. package/dist/customer/finance-customer.repository.d.ts +2 -2
  16. package/dist/customer/finance-customer.repository.js +1 -1
  17. package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +2 -2
  18. package/dist/document/document-item.d.ts +2 -1
  19. package/dist/document/document-item.js +2 -2
  20. package/dist/document/document-item.js.map +1 -1
  21. package/dist/document/document-item.repository.d.ts +3 -15
  22. package/dist/document/document-item.repository.js +4 -43
  23. package/dist/document/document-item.repository.js.map +1 -1
  24. package/dist/document/document.d.ts +20 -23
  25. package/dist/document/document.js +85 -54
  26. package/dist/document/document.js.map +1 -1
  27. package/dist/document/document.repository.d.ts +3 -14
  28. package/dist/document/document.repository.js +4 -39
  29. package/dist/document/document.repository.js.map +1 -1
  30. package/dist/document/interfaces/document-item.repository.interface.d.ts +2 -2
  31. package/dist/enum/index.d.ts +2 -1
  32. package/dist/enum/index.js +3 -1
  33. package/dist/enum/index.js.map +1 -1
  34. package/dist/enum/payment-status.enum.d.ts +4 -0
  35. package/dist/enum/payment-status.enum.js +9 -0
  36. package/dist/enum/payment-status.enum.js.map +1 -0
  37. package/dist/enum/transaction-type.enum.d.ts +2 -2
  38. package/dist/enum/transaction-type.enum.js +2 -2
  39. package/dist/enum/transaction-type.enum.js.map +1 -1
  40. package/dist/finance-company/finance-company.d.ts +15 -10
  41. package/dist/finance-company/finance-company.js +473 -30
  42. package/dist/finance-company/finance-company.js.map +1 -1
  43. package/dist/finance-company/finance-company.repository.d.ts +2 -2
  44. package/dist/finance-company/finance-company.repository.js +1 -1
  45. package/dist/index.d.ts +11 -8
  46. package/dist/index.js +14 -8
  47. package/dist/index.js.map +1 -1
  48. package/dist/interfaces/account-system.interface.d.ts +2 -2
  49. package/dist/journal-entry/journal-entry.d.ts +13 -17
  50. package/dist/journal-entry/journal-entry.js +83 -35
  51. package/dist/journal-entry/journal-entry.js.map +1 -1
  52. package/dist/journal-entry/journal-entry.repository.d.ts +3 -13
  53. package/dist/journal-entry/journal-entry.repository.js +5 -38
  54. package/dist/journal-entry/journal-entry.repository.js.map +1 -1
  55. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +0 -4
  56. package/dist/ledger-transaction/ledger-transaction.d.ts +6 -5
  57. package/dist/ledger-transaction/ledger-transaction.js +6 -9
  58. package/dist/ledger-transaction/ledger-transaction.js.map +1 -1
  59. package/dist/ledger-transaction/ledger-transaction.repository.d.ts +3 -8
  60. package/dist/ledger-transaction/ledger-transaction.repository.js +5 -32
  61. package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -1
  62. package/dist/models/account.entity.d.ts +7 -3
  63. package/dist/models/account.entity.js +69 -34
  64. package/dist/models/account.entity.js.map +1 -1
  65. package/dist/models/finance-company.entity.d.ts +0 -4
  66. package/dist/models/finance-company.entity.js +0 -20
  67. package/dist/models/finance-company.entity.js.map +1 -1
  68. package/dist/models/payment-item.entity.d.ts +1 -0
  69. package/dist/models/payment-item.entity.js +7 -0
  70. package/dist/models/payment-item.entity.js.map +1 -1
  71. package/dist/models/payment-method-type.entity.d.ts +13 -0
  72. package/dist/models/payment-method-type.entity.js +86 -0
  73. package/dist/models/payment-method-type.entity.js.map +1 -0
  74. package/dist/models/payment-method.entity.d.ts +7 -0
  75. package/dist/models/payment-method.entity.js +46 -0
  76. package/dist/models/payment-method.entity.js.map +1 -0
  77. package/dist/models/payment.entity.d.ts +15 -10
  78. package/dist/models/payment.entity.js +92 -34
  79. package/dist/models/payment.entity.js.map +1 -1
  80. package/dist/payment/interfaces/payment-attr.interface.d.ts +11 -8
  81. package/dist/payment/interfaces/payment-attr.interface.js.map +1 -1
  82. package/dist/payment/interfaces/payment-item-attr.interface.d.ts +1 -0
  83. package/dist/payment/interfaces/payment-item-attr.interface.js.map +1 -1
  84. package/dist/payment/payment-item.repository.d.ts +3 -15
  85. package/dist/payment/payment-item.repository.js +4 -43
  86. package/dist/payment/payment-item.repository.js.map +1 -1
  87. package/dist/payment/payment.d.ts +44 -48
  88. package/dist/payment/payment.js +122 -133
  89. package/dist/payment/payment.js.map +1 -1
  90. package/dist/payment/payment.repository.d.ts +3 -14
  91. package/dist/payment/payment.repository.js +4 -39
  92. package/dist/payment/payment.repository.js.map +1 -1
  93. package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts +8 -0
  94. package/dist/payment-item/interfaces/payment-item-attr.interface.js +7 -0
  95. package/dist/payment-item/interfaces/payment-item-attr.interface.js.map +1 -0
  96. package/{src/payment/interfaces/payment-item.repository.interface.ts → dist/payment-item/interfaces/payment-item.repository.interface.d.ts} +0 -1
  97. package/dist/payment-item/interfaces/payment-item.repository.interface.js +3 -0
  98. package/dist/payment-item/interfaces/payment-item.repository.interface.js.map +1 -0
  99. package/dist/payment-item/payment-item.d.ts +19 -0
  100. package/dist/payment-item/payment-item.js +42 -0
  101. package/dist/payment-item/payment-item.js.map +1 -0
  102. package/dist/payment-item/payment-item.repository.d.ts +5 -0
  103. package/dist/payment-item/payment-item.repository.js +12 -0
  104. package/dist/payment-item/payment-item.repository.js.map +1 -0
  105. package/dist/payment-method/interfaces/payment-method-attr.interface.d.ts +4 -0
  106. package/dist/payment-method/interfaces/payment-method-attr.interface.js +3 -0
  107. package/dist/payment-method/interfaces/payment-method-attr.interface.js.map +1 -0
  108. package/dist/payment-method/payment-method.d.ts +17 -0
  109. package/dist/payment-method/payment-method.js +83 -0
  110. package/dist/payment-method/payment-method.js.map +1 -0
  111. package/dist/payment-method/payment-method.repository.d.ts +5 -0
  112. package/dist/payment-method/payment-method.repository.js +12 -0
  113. package/dist/payment-method/payment-method.repository.js.map +1 -0
  114. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.d.ts +8 -0
  115. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.js +3 -0
  116. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.js.map +1 -0
  117. package/dist/payment-method-type/payment-method-type.d.ts +15 -0
  118. package/dist/payment-method-type/payment-method-type.js +55 -0
  119. package/dist/payment-method-type/payment-method-type.js.map +1 -0
  120. package/dist/payment-method-type/payment-method-type.repository.d.ts +5 -0
  121. package/dist/payment-method-type/payment-method-type.repository.js +12 -0
  122. package/dist/payment-method-type/payment-method-type.repository.js.map +1 -0
  123. package/dist/tsconfig.tsbuildinfo +1 -1
  124. package/migrations/finance-account-migration.js +30 -16
  125. package/migrations/finance-company-migration.js +0 -14
  126. package/migrations/finance-payment-item-migration.js +4 -0
  127. package/migrations/finance-payment-method-migration.js +21 -0
  128. package/migrations/finance-payment-method-type-migration.js +55 -0
  129. package/migrations/finance-payment-migration.js +42 -25
  130. package/package.json +4 -4
  131. package/src/account/account.repository.ts +5 -38
  132. package/src/account/account.ts +115 -98
  133. package/src/account/interfaces/account-attr.interface.ts +15 -7
  134. package/src/account-system-entity/account-system-entity.ts +4 -4
  135. package/src/account-system-entity/post-history.repository.ts +3 -3
  136. package/src/customer/customer.ts +3 -3
  137. package/src/customer/finance-customer.repository.ts +2 -2
  138. package/src/customer/interfaces/finance-customer.repository.interface.ts +2 -2
  139. package/src/document/document-item.repository.ts +5 -43
  140. package/src/document/document-item.ts +5 -1
  141. package/src/document/document.repository.ts +5 -35
  142. package/src/document/document.ts +127 -74
  143. package/src/document/interfaces/document-item.repository.interface.ts +2 -2
  144. package/src/enum/index.ts +2 -0
  145. package/src/enum/payment-status.enum.ts +4 -0
  146. package/src/enum/transaction-type.enum.ts +2 -2
  147. package/src/finance-company/finance-company.repository.ts +3 -3
  148. package/src/finance-company/finance-company.ts +685 -48
  149. package/src/index.ts +13 -7
  150. package/src/interfaces/account-system.interface.ts +2 -2
  151. package/src/journal-entry/journal-entry.repository.ts +5 -34
  152. package/src/journal-entry/journal-entry.ts +163 -63
  153. package/src/ledger-transaction/interfaces/ledger-transaction-attr.interface.ts +0 -5
  154. package/src/ledger-transaction/ledger-transaction.repository.ts +5 -24
  155. package/src/ledger-transaction/ledger-transaction.ts +8 -12
  156. package/src/models/account.entity.ts +67 -32
  157. package/src/models/finance-company.entity.ts +0 -16
  158. package/src/models/payment-item.entity.ts +6 -0
  159. package/src/models/payment-method-type.entity.ts +70 -0
  160. package/src/models/payment-method.entity.ts +28 -0
  161. package/src/models/payment.entity.ts +86 -31
  162. package/src/payment/interfaces/payment-attr.interface.ts +11 -8
  163. package/src/payment/payment.repository.ts +5 -35
  164. package/src/payment/payment.ts +183 -181
  165. package/src/{payment → payment-item}/interfaces/payment-item-attr.interface.ts +1 -0
  166. package/src/payment-item/payment-item.repository.ts +11 -0
  167. package/src/payment-item/payment-item.ts +54 -0
  168. package/src/payment-method/interfaces/payment-method-attr.interface.ts +4 -0
  169. package/src/payment-method/payment-method.repository.ts +11 -0
  170. package/src/payment-method/payment-method.ts +95 -0
  171. package/src/payment-method-type/interfaces/payment-method-type-attr.interface.ts +8 -0
  172. package/src/payment-method-type/payment-method-type.repository.ts +11 -0
  173. package/src/payment-method-type/payment-method-type.ts +58 -0
  174. package/src/account/interfaces/account.repository.interface.ts +0 -4
  175. package/src/document/interfaces/document.repository.interface.ts +0 -4
  176. package/src/journal-entry/interfaces/journal-entry.repository.interface.ts +0 -11
  177. package/src/payment/interfaces/payment.repository.interface.ts +0 -4
  178. package/src/payment/payment-item.repository.ts +0 -49
@@ -8,28 +8,26 @@ module.exports = {
8
8
  primaryKey: true,
9
9
  allowNull: false,
10
10
  },
11
- ParentAccountNo: {
11
+ CompanyId: {
12
12
  type: Sequelize.STRING(30),
13
- allowNull: true,
14
- },
15
- SystemCode: {
16
- type: Sequelize.STRING(10),
17
13
  allowNull: false,
14
+ references: {
15
+ model: 'finance_Company',
16
+ key: 'CompanyId',
17
+ },
18
+ onUpdate: 'CASCADE',
19
+ onDelete: 'CASCADE',
18
20
  },
19
- AccSystemCode: {
20
- type: Sequelize.STRING(10),
21
- allowNull: false,
22
- },
23
- AccSystemRefId: {
24
- type: Sequelize.STRING(10),
25
- allowNull: false,
21
+ ParentAccountNo: {
22
+ type: Sequelize.STRING(30),
23
+ allowNull: true,
26
24
  },
27
25
  Name: {
28
26
  type: Sequelize.STRING(200),
29
- allowNull: true,
27
+ allowNull: false,
30
28
  },
31
29
  Description: {
32
- type: Sequelize.TEXT,
30
+ type: Sequelize.STRING(2000),
33
31
  allowNull: true,
34
32
  },
35
33
  AccountType: {
@@ -62,8 +60,8 @@ module.exports = {
62
60
  type: Sequelize.DATE,
63
61
  },
64
62
  CreatedById: {
63
+ type: Sequelize.STRING(30),
65
64
  allowNull: false,
66
- type: Sequelize.STRING,
67
65
  },
68
66
  UpdatedAt: {
69
67
  allowNull: true,
@@ -71,8 +69,24 @@ module.exports = {
71
69
  type: Sequelize.DATE,
72
70
  },
73
71
  UpdatedById: {
72
+ type: Sequelize.STRING(30),
73
+ allowNull: true,
74
+ },
75
+ AccSystemRefId: {
76
+ type: Sequelize.STRING(30),
77
+ allowNull: false,
78
+ },
79
+ PostedToAccSystemYN: {
80
+ type: Sequelize.ENUM(['Y', 'N']),
81
+ allowNull: false,
82
+ },
83
+ PostedById: {
84
+ type: Sequelize.STRING(30),
85
+ allowNull: true,
86
+ },
87
+ PostedDateTime: {
88
+ type: Sequelize.DATE,
74
89
  allowNull: true,
75
- type: Sequelize.STRING,
76
90
  },
77
91
  });
78
92
  },
@@ -20,20 +20,6 @@ module.exports = {
20
20
  type: Sequelize.STRING(10),
21
21
  allowNull: false,
22
22
  },
23
- AccSystemRefId: {
24
- type: Sequelize.STRING(30),
25
- allowNull: false,
26
- },
27
- PostedToAccSystemYN: {
28
- type: Sequelize.ENUM(['Y', 'N']),
29
- allowNull: false,
30
- },
31
- PostedById: {
32
- type: Sequelize.STRING(30),
33
- },
34
- PostedDateTime: {
35
- type: Sequelize.DATE,
36
- },
37
23
  });
38
24
  },
39
25
 
@@ -30,6 +30,10 @@ module.exports = {
30
30
  type: Sequelize.DECIMAL(10, 2),
31
31
  allowNull: false,
32
32
  },
33
+ TaxCode: {
34
+ type: Sequelize.STRING(10),
35
+ allowNull: true,
36
+ },
33
37
  });
34
38
  },
35
39
 
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable('finance_PaymentMethod', {
6
+ MethodId: {
7
+ type: Sequelize.STRING(30),
8
+ primaryKey: true,
9
+ allowNull: false,
10
+ },
11
+ Name: {
12
+ type: Sequelize.STRING(100),
13
+ allowNull: false,
14
+ },
15
+ });
16
+ },
17
+
18
+ async down(queryInterface) {
19
+ await queryInterface.dropTable('finance_PaymentMethod');
20
+ },
21
+ };
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable('finance_PaymentMethodType', {
6
+ MethodId: {
7
+ type: Sequelize.STRING(30),
8
+ allowNull: false,
9
+ references: {
10
+ model: 'finance_PaymentMethod',
11
+ key: 'MethodId',
12
+ },
13
+ onUpdate: 'CASCADE',
14
+ onDelete: 'CASCADE',
15
+ },
16
+ MethodTypeId: {
17
+ type: Sequelize.STRING(30),
18
+ primaryKey: true,
19
+ allowNull: false,
20
+ },
21
+ Name: {
22
+ type: Sequelize.STRING(100),
23
+ allowNull: false,
24
+ },
25
+ AccountNo: {
26
+ type: Sequelize.STRING(30),
27
+ allowNull: false,
28
+ references: {
29
+ model: 'finance_Account',
30
+ key: 'AccountNo',
31
+ },
32
+ onUpdate: 'CASCADE',
33
+ onDelete: 'CASCADE',
34
+ },
35
+ ProcessingFeeRate: {
36
+ type: Sequelize.DECIMAL(10, 2),
37
+ allowNull: false,
38
+ },
39
+ ProcessingFeeAccountNo: {
40
+ type: Sequelize.STRING(30),
41
+ allowNull: false,
42
+ references: {
43
+ model: 'finance_Account',
44
+ key: 'AccountNo',
45
+ },
46
+ onUpdate: 'CASCADE',
47
+ onDelete: 'CASCADE',
48
+ },
49
+ });
50
+ },
51
+
52
+ async down(queryInterface) {
53
+ await queryInterface.dropTable('finance_PaymentMethodType');
54
+ },
55
+ };
@@ -8,16 +8,6 @@ module.exports = {
8
8
  primaryKey: true,
9
9
  allowNull: false,
10
10
  },
11
- AccountNo: {
12
- type: Sequelize.STRING(30),
13
- allowNull: false,
14
- references: {
15
- model: 'finance_Account',
16
- key: 'AccountNo',
17
- },
18
- onUpdate: 'CASCADE',
19
- onDelete: 'CASCADE',
20
- },
21
11
  PaymentType: {
22
12
  type: Sequelize.ENUM(['Payment Received', 'Payout']),
23
13
  defaultValue: 'Payment Received',
@@ -27,6 +17,26 @@ module.exports = {
27
17
  type: Sequelize.DATE,
28
18
  allowNull: false,
29
19
  },
20
+ CompanyId: {
21
+ type: Sequelize.STRING(30),
22
+ allowNull: false,
23
+ references: {
24
+ model: 'finance_Company',
25
+ key: 'CompanyId',
26
+ },
27
+ onUpdate: 'CASCADE',
28
+ onDelete: 'CASCADE',
29
+ },
30
+ MethodTypeId: {
31
+ type: Sequelize.STRING(30),
32
+ allowNull: false,
33
+ references: {
34
+ model: 'finance_PaymentMethodType',
35
+ key: 'MethodTypeId',
36
+ },
37
+ onUpdate: 'CASCADE',
38
+ onDelete: 'CASCADE',
39
+ },
30
40
  Currency: {
31
41
  type: Sequelize.CHAR(3),
32
42
  allowNull: false,
@@ -39,27 +49,19 @@ module.exports = {
39
49
  type: Sequelize.STRING(20),
40
50
  allowNull: false,
41
51
  },
42
- Method: {
43
- type: Sequelize.STRING,
44
- allowNull: false,
45
- },
46
- MethodParty: {
47
- type: Sequelize.STRING(255),
48
- allowNull: false,
49
- },
50
- MethodAccountName: {
52
+ TransactionId: {
51
53
  type: Sequelize.STRING(100),
52
54
  allowNull: true,
53
55
  },
54
- MethodAccountNo: {
56
+ TransactionApprovalCode: {
55
57
  type: Sequelize.STRING(100),
56
58
  allowNull: true,
57
59
  },
58
- TransactionId: {
60
+ TransactionAccountName: {
59
61
  type: Sequelize.STRING(100),
60
62
  allowNull: true,
61
63
  },
62
- ApprovalId: {
64
+ TransactionAccountNo: {
63
65
  type: Sequelize.STRING(100),
64
66
  allowNull: true,
65
67
  },
@@ -68,18 +70,33 @@ module.exports = {
68
70
  allowNull: false,
69
71
  },
70
72
  UpdatedAt: {
71
- allowNull: false,
72
- defaultValue: new Date(),
73
73
  type: Sequelize.DATE,
74
+ allowNull: false,
74
75
  },
75
76
  UpdatedBy: {
77
+ type: Sequelize.STRING(30),
76
78
  allowNull: false,
77
- type: Sequelize.STRING,
78
79
  },
79
80
  Remarks: {
80
81
  type: Sequelize.TEXT,
81
82
  allowNull: true,
82
83
  },
84
+ AccSystemRefId: {
85
+ type: Sequelize.STRING(30),
86
+ allowNull: true,
87
+ },
88
+ PostedToAccSystemYN: {
89
+ type: Sequelize.ENUM(['Y', 'N']),
90
+ allowNull: false,
91
+ },
92
+ PostedById: {
93
+ type: Sequelize.STRING(30),
94
+ allowNull: true,
95
+ },
96
+ PostedDateTime: {
97
+ type: Sequelize.DATE,
98
+ allowNull: true,
99
+ },
83
100
  });
84
101
  },
85
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/finance",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -35,7 +35,7 @@
35
35
  "@nestjs/platform-express": "^9.0.8",
36
36
  "@nestjs/sequelize": "^9.0.0",
37
37
  "@nestjs/swagger": "^6.1.4",
38
- "@tomei/general": "file:../General",
38
+ "@tomei/general": "^0.0.26",
39
39
  "@tomei/media": "^0.4.0",
40
40
  "axios": "^1.1.3",
41
41
  "class-transformer": "^0.5.1",
@@ -44,9 +44,9 @@
44
44
  "dotenv": "^16.0.3",
45
45
  "intuit-oauth": "^4.0.0",
46
46
  "mariadb": "^3.0.2",
47
+ "puppeteer": "^19.4.0",
47
48
  "sequelize-typescript": "^2.1.3",
48
- "uniqid": "^5.4.0",
49
- "puppeteer": "^19.4.0"
49
+ "uniqid": "^5.4.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/multer": "^1.4.7",
@@ -1,44 +1,11 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/sequelize';
3
- import { BaseRepository } from '@tomei/general';
4
- import {
5
- IAccountAttr,
6
- ICreateAccountAttr,
7
- } from './interfaces/account-attr.interface';
8
- import { IAccountRepository } from './interfaces/account.repository.interface';
1
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
9
2
  import AccountModel from '../models/account.entity';
10
3
 
11
- @Injectable()
12
4
  export class AccountRepository
13
- extends BaseRepository<AccountModel>
14
- implements IAccountRepository
5
+ extends RepositoryBase<AccountModel>
6
+ implements IRepositoryBase<AccountModel>
15
7
  {
16
- constructor(
17
- @InjectModel(AccountModel)
18
- private readonly accountModel: typeof AccountModel,
19
- ) {
20
- super(accountModel);
21
- }
22
-
23
- create(data: ICreateAccountAttr, options?: any): Promise<AccountModel> | any {
24
- return this.accountModel.create({ ...data }, options);
25
- }
26
-
27
- findAll(options: any): Promise<AccountModel[]> {
28
- return this.accountModel.findAll(options);
29
- }
30
-
31
- findAllWithPagination(
32
- options: any,
33
- ): Promise<{ count: number; rows: AccountModel[] }> {
34
- return this.accountModel.findAndCountAll(options);
35
- }
36
-
37
- findOne(options: any): Promise<AccountModel> {
38
- return this.accountModel.findOne(options);
39
- }
40
-
41
- update(data: IAccountAttr, options?: any): any {
42
- return this.accountModel.update({ ...data }, options);
8
+ constructor() {
9
+ super(AccountModel);
43
10
  }
44
11
  }
@@ -1,94 +1,139 @@
1
- import { IAccountRepository } from './interfaces/account.repository.interface';
2
- import { ObjectBase, LoginUserBase, RecordNotFoundError } from '@tomei/general';
3
- import { IBaseRepository } from '@tomei/general/dist/interfaces/repository.base.interface';
1
+ import { RecordNotFoundError } from '@tomei/general';
4
2
  import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
5
3
  import AccountModel from '../models/account.entity';
4
+ import { AccountRepository } from './account.repository';
6
5
 
7
- export class Account extends AccountSystemEntity {
8
- protected BaseRepository;
9
- ObjectId: string;
10
- ObjectName: string;
6
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
7
+ const { getConfig } = require('../config');
11
8
 
12
- accountRepository: IAccountRepository;
9
+ export default class Account extends AccountSystemEntity {
13
10
  AccountNo: string;
14
- Owner: LoginUserBase;
15
- RelatedObject: ObjectBase;
16
- TableName: string;
17
- private isNewRecord = true;
18
- private OwnerId: string;
19
- private OwnerType: string;
20
- private RelatedObjectId: string;
21
- private RelatedObjectType: string;
22
- private ParentAccountNo: string;
23
-
24
- SystemCode: string;
25
- AccSystemCode: string;
11
+ ParentAccountNo?: string;
26
12
  Name: string;
27
13
  Description: string;
28
14
  AccountType: string;
29
15
  AccountSubtype: string;
30
-
31
- CreatedAt: Date;
16
+ OwnerId: string;
17
+ OwnerType: string;
18
+ RelatedObjectId: string;
19
+ RelatedObjectType: string;
32
20
  CreatedById: string;
21
+ CreatedAt: Date;
22
+ UpdatedAt: Date;
23
+ UpdatedById: string;
33
24
 
34
- constructor(
35
- accountRepository?: IBaseRepository<AccountModel>,
36
- accountNo?: string,
37
- ) {
38
- super();
39
- if (accountRepository && accountNo) {
40
- this.accountRepository = accountRepository;
41
- this.AccountNo = accountNo;
42
- const accountData = this.accountRepository.findOne({
43
- where: { AccountNo: accountNo },
44
- });
45
- if (accountData) {
46
- this.isNewRecord = false;
47
- this.ParentAccountNo = accountData.ParentAccountNo;
48
- this.SystemCode = accountData.SystemCode;
49
- this.AccSystemCode = accountData.AccSystemCode;
50
- this.AccSystemRefId = accountData.AccSystemRefId;
51
- this.Name = accountData.Name;
52
- this.Description = accountData.Description;
53
- this.AccountType = accountData.AccountType;
54
- this.AccountSubtype = accountData.AccountSubtype;
55
- this.OwnerId = accountData.OwnerId;
56
- this.OwnerType = accountData.OwnerType;
57
- this.RelatedObjectId = accountData.RelatedObjectId;
58
- this.RelatedObjectType = accountData.RelatedObjectType;
59
- this.AccSystemCode = accountData.AccSystemCode;
60
- } else {
61
- const notFoundError = new RecordNotFoundError('No Record Found.');
62
- throw notFoundError;
63
- }
64
- } else if (accountRepository || accountNo) {
65
- throw new Error('AccountNo and AccountRepository both are required.');
66
- }
25
+ private static _RepositoryBase = new AccountRepository();
26
+
27
+ private _DbTransaction: any;
28
+ private _IsNewRecord = true;
29
+
30
+ private get IsNewRecord() {
31
+ return this._IsNewRecord;
67
32
  }
68
33
 
69
- public get name(): string {
70
- return this.Name;
34
+ private set IsNewRecord(record: boolean) {
35
+ this._IsNewRecord = record;
71
36
  }
72
37
 
73
- public get accountType(): string {
74
- return this.AccountType;
38
+ /* AccountSystemEntity Implementation */
39
+ get RepositoryBase() {
40
+ return Account._RepositoryBase;
75
41
  }
76
42
 
77
- public get accountSubType(): string {
78
- return this.AccountSubtype;
43
+ /* ObjectBase Implementation */
44
+ get ObjectId() {
45
+ return this.AccountNo;
79
46
  }
80
47
 
81
- public get parentAccountNo(): string {
82
- return this.ParentAccountNo;
48
+ get ObjectName() {
49
+ return this.Name;
83
50
  }
84
51
 
85
- validateAccountValue() {
86
- if (!this.SystemCode) {
87
- throw new Error('SystemCode is required.');
52
+ get TableName() {
53
+ return 'finance_Account';
54
+ }
55
+
56
+ constructor(dbTransaction?: any, accountNo?: string) {
57
+ super();
58
+ if (dbTransaction) {
59
+ this._DbTransaction = dbTransaction;
88
60
  }
89
- if (!this.AccSystemCode) {
90
- throw new Error('AccSystemCode is required.');
61
+ if (accountNo) {
62
+ this.RepositoryBase.findOne({
63
+ where: {
64
+ AccountNo: accountNo,
65
+ },
66
+ transaction: dbTransaction,
67
+ })
68
+ .then((accountData) => {
69
+ if (accountData) {
70
+ this.IsNewRecord = false;
71
+ this.CompanyId = accountData.CompanyId;
72
+ this.ParentAccountNo = accountData.ParentAccountNo;
73
+ this.Name = accountData.Name;
74
+ this.Description = accountData.Description;
75
+ this.AccountType = accountData.AccountType;
76
+ this.AccountSubtype = accountData.AccountSubType;
77
+ this.OwnerId = accountData.OwnerId;
78
+ this.OwnerType = accountData.OwnerType;
79
+ this.RelatedObjectId = accountData.RelatedObjectId;
80
+ this.RelatedObjectType = accountData.RelatedObjectType;
81
+ this.CreatedById = accountData.CreatedById;
82
+ this.CreatedAt = accountData.CreatedAt;
83
+ this.UpdatedById = accountData.UpdatedById;
84
+ this.UpdatedAt = accountData.UpdatedAt;
85
+ this.AccSystemRefId = accountData.AccSystemRefId;
86
+ this.PostedToAccSystemYN = accountData.PostedToAccSystemYN;
87
+ this.PostedById = accountData.PostedById;
88
+ this.PostedDateTime = accountData.PostedDateTime;
89
+ } else {
90
+ const notFoundError = new RecordNotFoundError('No Record Found.');
91
+ throw notFoundError;
92
+ }
93
+ })
94
+ .catch((err) => {
95
+ // tslint:disable-next-line:no-console
96
+ console.log('Account Class constructor err: ', err);
97
+ });
91
98
  }
99
+ }
100
+
101
+ /**
102
+ * Account static constructor
103
+ *
104
+ * Create the Customer Account Receivable (AR) and Customer Account Payable (AP) default accounts.
105
+ * The static constructor is to run once each time the program loads and check if the default accounts have been created.
106
+ * If it has not, it will create the accounts.
107
+ */
108
+ static async Account() {
109
+ const dbTransaction = null;
110
+ let DefaultAccountReceivable: Account = null;
111
+ let DefaultAccountPayable: Account = null;
112
+
113
+ // const config = getConfig();
114
+ // config.systemConfig['EZC']
115
+
116
+ try {
117
+ DefaultAccountReceivable = new Account(dbTransaction, 'EZC-AR');
118
+ } catch (err) {
119
+ DefaultAccountReceivable = new Account(dbTransaction);
120
+ DefaultAccountReceivable.AccountNo = null;
121
+ DefaultAccountReceivable.AccountType = 'Account Receivable';
122
+ DefaultAccountReceivable.OwnerId = 'System';
123
+ DefaultAccountReceivable.OwnerType = '';
124
+ }
125
+
126
+ try {
127
+ DefaultAccountPayable = new Account(dbTransaction, 'EZC-AP');
128
+ } catch (err) {
129
+ DefaultAccountPayable = new Account(dbTransaction);
130
+ DefaultAccountPayable.AccountNo = null;
131
+ DefaultAccountPayable.AccountType = 'Account Payable';
132
+ DefaultAccountPayable.OwnerId = 'System';
133
+ }
134
+ }
135
+
136
+ validateAccountValue() {
92
137
  if (!this.AccSystemRefId) {
93
138
  throw new Error('AccSystemAccountId is required.');
94
139
  }
@@ -97,7 +142,7 @@ export class Account extends AccountSystemEntity {
97
142
  }
98
143
  }
99
144
 
100
- isParentAccountExsits() {
145
+ isParentAccountExists() {
101
146
  if (this.ParentAccountNo) return true;
102
147
  return false;
103
148
  }
@@ -108,11 +153,9 @@ export class Account extends AccountSystemEntity {
108
153
  dbTransaction?: any,
109
154
  ): Promise<AccountModel> {
110
155
  this.AccSystemRefId = AccSystemRefId;
111
- const data = await this.accountRepository.create(
156
+ const data = await this.RepositoryBase.create(
112
157
  {
113
158
  AccountNo: this.AccountNo,
114
- SystemCode: this.SystemCode,
115
- AccSystemCode: this.AccSystemCode,
116
159
  AccSystemRefId: this.AccSystemRefId,
117
160
  Name: this.Name,
118
161
  Description: this.Description,
@@ -129,30 +172,4 @@ export class Account extends AccountSystemEntity {
129
172
  );
130
173
  return data;
131
174
  }
132
-
133
- /**
134
- * This method will return finance_Account.AccountNo
135
- * @returns {Promise<string>} AccountNo
136
- */
137
- async getAccountNo(): Promise<string> {
138
- if (this.AccountNo) {
139
- return this.AccountNo;
140
- } else {
141
- try {
142
- const account = await this.accountRepository.findOne({
143
- OwnerId: this.OwnerId,
144
- AccSystemRefId: this.AccSystemRefId,
145
- });
146
-
147
- if (account) {
148
- this.AccountNo = account.AccountNo;
149
- return this.AccountNo;
150
- } else {
151
- throw new Error('Account need to be created first.');
152
- }
153
- } catch (error) {
154
- throw error;
155
- }
156
- }
157
- }
158
175
  }
@@ -2,16 +2,24 @@ import { ObjectBase, LoginUserBase } from '@tomei/general';
2
2
 
3
3
  export interface IAccountAttr {
4
4
  AccountNo: string;
5
- SystemCode: string;
5
+ CompanyId: string;
6
+ ParentAccountNo?: string;
6
7
  Name: string;
7
- OwnerId: string;
8
- OwnerType: string;
9
- RelatedObjectId: string;
10
- RelatedObjectType: string;
8
+ Description?: string;
9
+ AccountType: string;
10
+ AccountSubType?: string;
11
+ OwnerId?: string;
12
+ OwnerType?: string;
13
+ RelatedObjectId?: string;
14
+ RelatedObjectType?: string;
11
15
  CreatedAt: Date;
12
16
  CreatedById: string;
13
- UpdatedAt: Date;
14
- UpdatedById: string;
17
+ UpdatedAt?: Date;
18
+ UpdatedById?: string;
19
+ AccSystemRefId: string;
20
+ PostedToAccSystemYN: string;
21
+ PostedById?: string;
22
+ PostedDateTime?: Date;
15
23
  }
16
24
 
17
25
  export interface ICreateAccountAttr {
@@ -1,4 +1,4 @@
1
- import { IBaseRepository, LoginUserBase, ObjectBase } from '@tomei/general';
1
+ import { IRepositoryBase, LoginUserBase, ObjectBase } from '@tomei/general';
2
2
  // import { FinanceCompany } from '../finance-company';
3
3
  import { PostHistoryRepository } from './post-history.repository';
4
4
  import cuid from 'cuid';
@@ -11,7 +11,7 @@ export abstract class AccountSystemEntity extends ObjectBase {
11
11
  private _AccSystemRefId = '';
12
12
  private _PostedById = '';
13
13
  private _PostedDateTime: Date;
14
- protected abstract BaseRepository: IBaseRepository<any>;
14
+ protected abstract RepositoryBase: IRepositoryBase<any>;
15
15
  private static PostHistoryRepository = new PostHistoryRepository();
16
16
 
17
17
  get CompanyId(): string {
@@ -73,8 +73,8 @@ export abstract class AccountSystemEntity extends ObjectBase {
73
73
  this._PostedDateTime = new Date();
74
74
 
75
75
  /*updating the posted fields to the table either using direct
76
- * SQL or BaseRepository*/
77
- const entity = await this.BaseRepository.findByPk(this.ObjectId);
76
+ * SQL or RepositoryBase*/
77
+ const entity = await this.RepositoryBase.findByPk(this.ObjectId);
78
78
  const updated = await entity.update(
79
79
  {
80
80
  PostedToAccSystemYN: this._PostedToAccSystemYN,