@tomei/finance 0.1.13 → 0.2.1
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/dist/account/entities/account.entity.d.ts +3 -1
- package/dist/account/entities/account.entity.js +6 -1
- package/dist/account/entities/account.entity.js.map +1 -1
- package/dist/account/interfaces/account.repository.interface.d.ts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/enum/index.d.ts +2 -1
- package/dist/enum/index.js +3 -1
- package/dist/enum/index.js.map +1 -1
- package/dist/enum/transaction-type.enum.d.ts +4 -0
- package/dist/enum/transaction-type.enum.js +9 -0
- package/dist/enum/transaction-type.enum.js.map +1 -0
- package/dist/finance-company/finance-company.d.ts +10 -0
- package/dist/finance-company/finance-company.js +63 -0
- package/dist/finance-company/finance-company.js.map +1 -0
- package/dist/finance-company/index.d.ts +2 -0
- package/dist/finance-company/index.js +6 -0
- package/dist/finance-company/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/account-system.interface.d.ts +1 -0
- package/dist/journal-entry/entities/journal-entry.entity.d.ts +12 -0
- package/dist/journal-entry/entities/journal-entry.entity.js +98 -0
- package/dist/journal-entry/entities/journal-entry.entity.js.map +1 -0
- package/dist/journal-entry/index.d.ts +6 -0
- package/dist/journal-entry/index.js +10 -0
- package/dist/journal-entry/index.js.map +1 -0
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts +9 -0
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.js +3 -0
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.js.map +1 -0
- package/dist/journal-entry/interfaces/journal-entry.repository.interface.d.ts +10 -0
- package/dist/journal-entry/interfaces/journal-entry.repository.interface.js +3 -0
- package/dist/journal-entry/interfaces/journal-entry.repository.interface.js.map +1 -0
- package/dist/journal-entry/journal-entry.d.ts +32 -0
- package/dist/journal-entry/journal-entry.js +97 -0
- package/dist/journal-entry/journal-entry.js.map +1 -0
- package/dist/journal-entry/journal-entry.repository.d.ts +15 -0
- package/dist/journal-entry/journal-entry.repository.js +43 -0
- package/dist/journal-entry/journal-entry.repository.js.map +1 -0
- package/dist/ledger-transaction/entities/ledger-transaction.entity.d.ts +19 -0
- package/dist/ledger-transaction/entities/ledger-transaction.entity.js +157 -0
- package/dist/ledger-transaction/entities/ledger-transaction.entity.js.map +1 -0
- package/dist/ledger-transaction/index.d.ts +6 -0
- package/dist/ledger-transaction/index.js +10 -0
- package/dist/ledger-transaction/index.js.map +1 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +18 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js +3 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js.map +1 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts +5 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js +3 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js.map +1 -0
- package/dist/ledger-transaction/ledger-transaction.d.ts +35 -0
- package/dist/ledger-transaction/ledger-transaction.js +71 -0
- package/dist/ledger-transaction/ledger-transaction.js.map +1 -0
- package/dist/ledger-transaction/ledger-transaction.repository.d.ts +10 -0
- package/dist/ledger-transaction/ledger-transaction.repository.js +37 -0
- package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -0
- package/dist/payment/interfaces/payment-item.repository.interface.d.ts +1 -1
- package/dist/payment/interfaces/payment.repository.interface.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/finance-journal-entry-migration.js +41 -0
- package/migrations/finance-ledger-transaction-migration.js +73 -0
- package/package.json +2 -2
- package/src/account/account.ts +189 -189
- package/src/account/entities/account.entity.ts +111 -107
- package/src/account/interfaces/account-attr.interface.ts +23 -23
- package/src/enum/index.ts +6 -5
- package/src/enum/transaction-type.enum.ts +4 -0
- package/src/finance-company/finance-company.ts +95 -0
- package/src/finance-company/index.ts +3 -0
- package/src/index.ts +9 -6
- package/src/interfaces/account-system.interface.ts +14 -13
- package/src/journal-entry/entities/journal-entry.entity.ts +74 -0
- package/src/journal-entry/index.ts +13 -0
- package/src/journal-entry/interfaces/journal-entry-attr.interface.ts +9 -0
- package/src/journal-entry/interfaces/journal-entry.repository.interface.ts +11 -0
- package/src/journal-entry/journal-entry.repository.ts +38 -0
- package/src/journal-entry/journal-entry.ts +136 -0
- package/src/ledger-transaction/entities/ledger-transaction.entity.ts +134 -0
- package/src/ledger-transaction/index.ts +13 -0
- package/src/ledger-transaction/interfaces/ledger-transaction-attr.interface.ts +20 -0
- package/src/ledger-transaction/interfaces/ledger-transaction.repository.interface.ts +7 -0
- package/src/ledger-transaction/ledger-transaction.repository.ts +28 -0
- package/src/ledger-transaction/ledger-transaction.ts +96 -0
- package/src/payment/payment.ts +209 -209
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable('finance_JournalEntry', {
|
|
6
|
+
JournalEntryId: {
|
|
7
|
+
type: Sequelize.STRING(30),
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
allowNull: false,
|
|
10
|
+
},
|
|
11
|
+
Date: {
|
|
12
|
+
type: Sequelize.DATE,
|
|
13
|
+
allowNull: true,
|
|
14
|
+
},
|
|
15
|
+
Name: {
|
|
16
|
+
type: Sequelize.STRING(200),
|
|
17
|
+
allowNull: false,
|
|
18
|
+
},
|
|
19
|
+
Description: {
|
|
20
|
+
type: Sequelize.STRING(1000),
|
|
21
|
+
allowNull: true,
|
|
22
|
+
},
|
|
23
|
+
PostedById: {
|
|
24
|
+
type: Sequelize.STRING(30),
|
|
25
|
+
allowNull: false,
|
|
26
|
+
},
|
|
27
|
+
PostedToAccSystemYN: {
|
|
28
|
+
type: Sequelize.CHAR(1),
|
|
29
|
+
allowNull: false,
|
|
30
|
+
},
|
|
31
|
+
DatePostedToAccSystem: {
|
|
32
|
+
type: Sequelize.DATE,
|
|
33
|
+
allowNull: true,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
async down(queryInterface) {
|
|
39
|
+
await queryInterface.dropTable('finance_JournalEntry');
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable('finance_LedgerTransaction', {
|
|
6
|
+
TransactionId: {
|
|
7
|
+
type: Sequelize.STRING(30),
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
allowNull: false,
|
|
10
|
+
},
|
|
11
|
+
TransactionType: {
|
|
12
|
+
type: Sequelize.STRING(20),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
},
|
|
15
|
+
JournalEntryId: {
|
|
16
|
+
type: Sequelize.STRING(30),
|
|
17
|
+
allowNull: false,
|
|
18
|
+
references: {
|
|
19
|
+
model: 'finance_JournalEntry',
|
|
20
|
+
key: 'JournalEntryId',
|
|
21
|
+
},
|
|
22
|
+
onUpdate: 'CASCADE',
|
|
23
|
+
onDelete: 'CASCADE',
|
|
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
|
+
Date: {
|
|
36
|
+
type: Sequelize.DATE,
|
|
37
|
+
allowNull: false,
|
|
38
|
+
},
|
|
39
|
+
Name: {
|
|
40
|
+
type: Sequelize.STRING(200),
|
|
41
|
+
allowNull: false,
|
|
42
|
+
},
|
|
43
|
+
Description: {
|
|
44
|
+
type: Sequelize.STRING(1000),
|
|
45
|
+
allowNull: true,
|
|
46
|
+
},
|
|
47
|
+
Currency: {
|
|
48
|
+
type: Sequelize.CHAR(3),
|
|
49
|
+
allowNull: false,
|
|
50
|
+
},
|
|
51
|
+
DebitAmount: {
|
|
52
|
+
type: Sequelize.DECIMAL(10, 2),
|
|
53
|
+
allowNull: true,
|
|
54
|
+
},
|
|
55
|
+
CreditAmount: {
|
|
56
|
+
type: Sequelize.DECIMAL(10, 2),
|
|
57
|
+
allowNull: true,
|
|
58
|
+
},
|
|
59
|
+
RelatedObjectId: {
|
|
60
|
+
type: Sequelize.STRING(30),
|
|
61
|
+
allowNull: false,
|
|
62
|
+
},
|
|
63
|
+
RelatedObjectType: {
|
|
64
|
+
type: Sequelize.STRING(200),
|
|
65
|
+
allowNull: false,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
async down(queryInterface) {
|
|
71
|
+
await queryInterface.dropTable('finance_LedgerTransaction');
|
|
72
|
+
},
|
|
73
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomei/finance",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "NestJS package for finance module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@nestjs/core": "^9.0.8",
|
|
35
35
|
"@nestjs/platform-express": "^9.0.8",
|
|
36
36
|
"@nestjs/sequelize": "^9.0.0",
|
|
37
|
-
"@tomei/general": "^0.0.
|
|
37
|
+
"@tomei/general": "^0.0.13",
|
|
38
38
|
"axios": "^1.1.3",
|
|
39
39
|
"class-transformer": "^0.5.1",
|
|
40
40
|
"class-validator": "^0.13.2",
|
package/src/account/account.ts
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
import { ICreateAccountAttr } from './interfaces/account-attr.interface';
|
|
2
|
-
import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
3
|
-
import * as uniqid from 'uniqid';
|
|
4
|
-
import { AccountModel } from './entities/account.entity';
|
|
5
|
-
import axios from 'axios';
|
|
6
|
-
import { getConfig } from '../config';
|
|
7
|
-
import { IAccountSystem } from 'src/interfaces';
|
|
8
|
-
import { ObjectBase, PersonBase } from '@tomei/general';
|
|
9
|
-
export class Account {
|
|
10
|
-
accountRepository: IAccountRepository;
|
|
11
|
-
|
|
12
|
-
private AccountNo: string;
|
|
13
|
-
private OwnerId: string;
|
|
14
|
-
private OwnerType: string;
|
|
15
|
-
private RelatedObjectId: string;
|
|
16
|
-
private RelatedObjectType: string;
|
|
17
|
-
private AccSystemId: string;
|
|
18
|
-
|
|
19
|
-
ParentAccountNo: string;
|
|
20
|
-
Owner: PersonBase;
|
|
21
|
-
RelatedObject: ObjectBase;
|
|
22
|
-
AccountType: string;
|
|
23
|
-
AccountSubType: string;
|
|
24
|
-
AccountingSystem: IAccountSystem;
|
|
25
|
-
|
|
26
|
-
isParamsInitialized: boolean;
|
|
27
|
-
|
|
28
|
-
constructor(
|
|
29
|
-
accountRepository: IAccountRepository,
|
|
30
|
-
accountingSystem: IAccountSystem,
|
|
31
|
-
SystemCode: string,
|
|
32
|
-
params?: ICreateAccountAttr,
|
|
33
|
-
) {
|
|
34
|
-
this.accountRepository = accountRepository;
|
|
35
|
-
this.AccountingSystem = accountingSystem;
|
|
36
|
-
this.AccSystemId = getConfig().systemConfig[SystemCode].accountingSystem;
|
|
37
|
-
if (params) {
|
|
38
|
-
this.init(params);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
init(params: ICreateAccountAttr) {
|
|
43
|
-
this.Owner = params.Owner;
|
|
44
|
-
this.OwnerId = params.Owner.ObjectId;
|
|
45
|
-
this.OwnerType = typeof params.Owner;
|
|
46
|
-
|
|
47
|
-
if (params.RelatedObject) {
|
|
48
|
-
this.RelatedObject = params.RelatedObject;
|
|
49
|
-
this.RelatedObjectId = params.RelatedObject.ObjectId;
|
|
50
|
-
this.RelatedObjectType = typeof params.RelatedObject;
|
|
51
|
-
}
|
|
52
|
-
if (params.AccountType) this.AccountType = params.AccountType;
|
|
53
|
-
if (params.AccountSubType) this.AccountSubType = params.AccountSubType;
|
|
54
|
-
if (params.ParentAccountNo) this.ParentAccountNo = params.ParentAccountNo;
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
this.Owner &&
|
|
58
|
-
this.RelatedObject &&
|
|
59
|
-
this.AccountType &&
|
|
60
|
-
this.AccountSubType
|
|
61
|
-
) {
|
|
62
|
-
this.isParamsInitialized = true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* This method will return finance_Account.AccountNo
|
|
68
|
-
* @returns {Promise<string>} AccountNo
|
|
69
|
-
*/
|
|
70
|
-
async getAccountNo(): Promise<string> {
|
|
71
|
-
if (this.AccountNo) {
|
|
72
|
-
return this.AccountNo;
|
|
73
|
-
} else {
|
|
74
|
-
try {
|
|
75
|
-
const account = await this.accountRepository.findOne({
|
|
76
|
-
OwnerId: this.OwnerId,
|
|
77
|
-
AccSystemId: this.AccSystemId,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
if (account) {
|
|
81
|
-
this.AccountNo = account.AccountNo;
|
|
82
|
-
return this.AccountNo;
|
|
83
|
-
} else {
|
|
84
|
-
throw new Error('Account need to be created first.');
|
|
85
|
-
}
|
|
86
|
-
} catch (error) {
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* This method will return finance_Account.AccountNo
|
|
94
|
-
* @returns {Promise<string>} AccountNo
|
|
95
|
-
*/
|
|
96
|
-
async create() {
|
|
97
|
-
try {
|
|
98
|
-
if (!this.Owner || !this.RelatedObject) {
|
|
99
|
-
throw new Error(
|
|
100
|
-
'Owner must be set before creating an account." or "RelatedObject must be set before creating an account.',
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!this.isParamsInitialized) {
|
|
105
|
-
throw new Error(
|
|
106
|
-
'Account parameters must be initialized before creating an account.',
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const ownerData = this.Owner.getDetails();
|
|
111
|
-
if (!ownerData) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
'Please save owner information in the database before creating an account',
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let isFull = true;
|
|
118
|
-
for (const key in ownerData) {
|
|
119
|
-
if (ownerData.hasOwnProperty(key)) {
|
|
120
|
-
if (!ownerData[key]) {
|
|
121
|
-
isFull = false;
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!isFull) {
|
|
128
|
-
throw new Error(
|
|
129
|
-
'Please save owner information in the database before creating an account',
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
let createAccountPayload: any = {
|
|
134
|
-
Name: this.Owner.FullName,
|
|
135
|
-
AcctNum: uniqid(),
|
|
136
|
-
AccountType: this.AccountType,
|
|
137
|
-
AccountSubType: this.AccountSubType,
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
if (this.ParentAccountNo) {
|
|
141
|
-
createAccountPayload = {
|
|
142
|
-
...createAccountPayload,
|
|
143
|
-
CurrencyRef: 'MYR',
|
|
144
|
-
ParentRef: this.ParentAccountNo,
|
|
145
|
-
SubAccount: true,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const accountId = await this.AccountingSystem.createAccount(
|
|
150
|
-
createAccountPayload,
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
const account = await this.accountRepository.create({
|
|
154
|
-
AccountNo: accountId,
|
|
155
|
-
SystemCode: this.AccSystemId,
|
|
156
|
-
Name: this.Owner.FullName,
|
|
157
|
-
OwnerId: this.OwnerId,
|
|
158
|
-
OwnerType: this.OwnerType,
|
|
159
|
-
RelatedObjectId: this.RelatedObjectId,
|
|
160
|
-
RelatedObjectType: this.RelatedObjectType,
|
|
161
|
-
CreatedAt: new Date(),
|
|
162
|
-
CreatedById: 'System',
|
|
163
|
-
UpdatedAt: new Date(),
|
|
164
|
-
UpdatedById: 'System',
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
const payload = {
|
|
168
|
-
Action: 'Create',
|
|
169
|
-
Activity: 'Account Created',
|
|
170
|
-
Description: `Account (ID: ${account.AccountNo}) has been created`,
|
|
171
|
-
EntityType: typeof AccountModel,
|
|
172
|
-
EntityValueBefore: JSON.stringify({}),
|
|
173
|
-
EntityValueAfter: JSON.stringify(account),
|
|
174
|
-
PerformedById: account.CreatedById,
|
|
175
|
-
PerformedAt: new Date(),
|
|
176
|
-
EntityId: account.AccountNo,
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
await axios.post(
|
|
180
|
-
`${process.env.COMMON_API_URL}/activity-histories`,
|
|
181
|
-
payload,
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
return account;
|
|
185
|
-
} catch (error) {
|
|
186
|
-
throw error;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
1
|
+
import { ICreateAccountAttr } from './interfaces/account-attr.interface';
|
|
2
|
+
import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
3
|
+
import * as uniqid from 'uniqid';
|
|
4
|
+
import { AccountModel } from './entities/account.entity';
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import { getConfig } from '../config';
|
|
7
|
+
import { IAccountSystem } from 'src/interfaces';
|
|
8
|
+
import { ObjectBase, PersonBase } from '@tomei/general';
|
|
9
|
+
export class Account {
|
|
10
|
+
accountRepository: IAccountRepository;
|
|
11
|
+
|
|
12
|
+
private AccountNo: string;
|
|
13
|
+
private OwnerId: string;
|
|
14
|
+
private OwnerType: string;
|
|
15
|
+
private RelatedObjectId: string;
|
|
16
|
+
private RelatedObjectType: string;
|
|
17
|
+
private AccSystemId: string;
|
|
18
|
+
|
|
19
|
+
ParentAccountNo: string;
|
|
20
|
+
Owner: PersonBase;
|
|
21
|
+
RelatedObject: ObjectBase;
|
|
22
|
+
AccountType: string;
|
|
23
|
+
AccountSubType: string;
|
|
24
|
+
AccountingSystem: IAccountSystem;
|
|
25
|
+
|
|
26
|
+
isParamsInitialized: boolean;
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
accountRepository: IAccountRepository,
|
|
30
|
+
accountingSystem: IAccountSystem,
|
|
31
|
+
SystemCode: string,
|
|
32
|
+
params?: ICreateAccountAttr,
|
|
33
|
+
) {
|
|
34
|
+
this.accountRepository = accountRepository;
|
|
35
|
+
this.AccountingSystem = accountingSystem;
|
|
36
|
+
this.AccSystemId = getConfig().systemConfig[SystemCode].accountingSystem;
|
|
37
|
+
if (params) {
|
|
38
|
+
this.init(params);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
init(params: ICreateAccountAttr) {
|
|
43
|
+
this.Owner = params.Owner;
|
|
44
|
+
this.OwnerId = params.Owner.ObjectId;
|
|
45
|
+
this.OwnerType = typeof params.Owner;
|
|
46
|
+
|
|
47
|
+
if (params.RelatedObject) {
|
|
48
|
+
this.RelatedObject = params.RelatedObject;
|
|
49
|
+
this.RelatedObjectId = params.RelatedObject.ObjectId;
|
|
50
|
+
this.RelatedObjectType = typeof params.RelatedObject;
|
|
51
|
+
}
|
|
52
|
+
if (params.AccountType) this.AccountType = params.AccountType;
|
|
53
|
+
if (params.AccountSubType) this.AccountSubType = params.AccountSubType;
|
|
54
|
+
if (params.ParentAccountNo) this.ParentAccountNo = params.ParentAccountNo;
|
|
55
|
+
|
|
56
|
+
if (
|
|
57
|
+
this.Owner &&
|
|
58
|
+
this.RelatedObject &&
|
|
59
|
+
this.AccountType &&
|
|
60
|
+
this.AccountSubType
|
|
61
|
+
) {
|
|
62
|
+
this.isParamsInitialized = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This method will return finance_Account.AccountNo
|
|
68
|
+
* @returns {Promise<string>} AccountNo
|
|
69
|
+
*/
|
|
70
|
+
async getAccountNo(): Promise<string> {
|
|
71
|
+
if (this.AccountNo) {
|
|
72
|
+
return this.AccountNo;
|
|
73
|
+
} else {
|
|
74
|
+
try {
|
|
75
|
+
const account = await this.accountRepository.findOne({
|
|
76
|
+
OwnerId: this.OwnerId,
|
|
77
|
+
AccSystemId: this.AccSystemId,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (account) {
|
|
81
|
+
this.AccountNo = account.AccountNo;
|
|
82
|
+
return this.AccountNo;
|
|
83
|
+
} else {
|
|
84
|
+
throw new Error('Account need to be created first.');
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* This method will return finance_Account.AccountNo
|
|
94
|
+
* @returns {Promise<string>} AccountNo
|
|
95
|
+
*/
|
|
96
|
+
async create() {
|
|
97
|
+
try {
|
|
98
|
+
if (!this.Owner || !this.RelatedObject) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
'Owner must be set before creating an account." or "RelatedObject must be set before creating an account.',
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!this.isParamsInitialized) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
'Account parameters must be initialized before creating an account.',
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const ownerData = this.Owner.getDetails();
|
|
111
|
+
if (!ownerData) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
'Please save owner information in the database before creating an account',
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let isFull = true;
|
|
118
|
+
for (const key in ownerData) {
|
|
119
|
+
if (ownerData.hasOwnProperty(key)) {
|
|
120
|
+
if (!ownerData[key]) {
|
|
121
|
+
isFull = false;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!isFull) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
'Please save owner information in the database before creating an account',
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let createAccountPayload: any = {
|
|
134
|
+
Name: this.Owner.FullName,
|
|
135
|
+
AcctNum: uniqid(),
|
|
136
|
+
AccountType: this.AccountType,
|
|
137
|
+
AccountSubType: this.AccountSubType,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
if (this.ParentAccountNo) {
|
|
141
|
+
createAccountPayload = {
|
|
142
|
+
...createAccountPayload,
|
|
143
|
+
CurrencyRef: 'MYR',
|
|
144
|
+
ParentRef: this.ParentAccountNo,
|
|
145
|
+
SubAccount: true,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const accountId = await this.AccountingSystem.createAccount(
|
|
150
|
+
createAccountPayload,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const account = await this.accountRepository.create({
|
|
154
|
+
AccountNo: accountId,
|
|
155
|
+
SystemCode: this.AccSystemId,
|
|
156
|
+
Name: this.Owner.FullName,
|
|
157
|
+
OwnerId: this.OwnerId,
|
|
158
|
+
OwnerType: this.OwnerType,
|
|
159
|
+
RelatedObjectId: this.RelatedObjectId,
|
|
160
|
+
RelatedObjectType: this.RelatedObjectType,
|
|
161
|
+
CreatedAt: new Date(),
|
|
162
|
+
CreatedById: 'System',
|
|
163
|
+
UpdatedAt: new Date(),
|
|
164
|
+
UpdatedById: 'System',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const payload = {
|
|
168
|
+
Action: 'Create',
|
|
169
|
+
Activity: 'Account Created',
|
|
170
|
+
Description: `Account (ID: ${account.AccountNo}) has been created`,
|
|
171
|
+
EntityType: typeof AccountModel,
|
|
172
|
+
EntityValueBefore: JSON.stringify({}),
|
|
173
|
+
EntityValueAfter: JSON.stringify(account),
|
|
174
|
+
PerformedById: account.CreatedById,
|
|
175
|
+
PerformedAt: new Date(),
|
|
176
|
+
EntityId: account.AccountNo,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
await axios.post(
|
|
180
|
+
`${process.env.COMMON_API_URL}/activity-histories`,
|
|
181
|
+
payload,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
return account;
|
|
185
|
+
} catch (error) {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|