@tomei/finance 0.2.1 → 0.2.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.
- package/dist/account/account.d.ts +22 -14
- package/dist/account/account.js +75 -94
- package/dist/account/account.js.map +1 -1
- package/dist/account/entities/account.entity.d.ts +8 -0
- package/dist/account/entities/account.entity.js +72 -5
- package/dist/account/entities/account.entity.js.map +1 -1
- package/dist/document/document-item.repository.d.ts +17 -0
- package/dist/document/document-item.repository.js +51 -0
- package/dist/document/document-item.repository.js.map +1 -0
- package/dist/document/document.repository.d.ts +16 -0
- package/dist/document/document.repository.js +47 -0
- package/dist/document/document.repository.js.map +1 -0
- package/dist/document/entities/document-item.entity.d.ts +24 -0
- package/dist/document/entities/document-item.entity.js +153 -0
- package/dist/document/entities/document-item.entity.js.map +1 -0
- package/dist/document/entities/document.entity.d.ts +22 -0
- package/dist/document/entities/document.entity.js +139 -0
- package/dist/document/entities/document.entity.js.map +1 -0
- package/dist/document/index.d.ts +9 -0
- package/dist/document/index.js +16 -0
- package/dist/document/index.js.map +1 -0
- package/dist/document/interfaces/document-attr.interface.d.ts +19 -0
- package/dist/document/interfaces/document-attr.interface.js +7 -0
- package/dist/document/interfaces/document-attr.interface.js.map +1 -0
- package/dist/document/interfaces/document-item-attr.interface.d.ts +19 -0
- package/dist/document/interfaces/document-item-attr.interface.js +7 -0
- package/dist/document/interfaces/document-item-attr.interface.js.map +1 -0
- package/dist/document/interfaces/document-item.repository.interface.d.ts +3 -0
- package/dist/document/interfaces/document-item.repository.interface.js +3 -0
- package/dist/document/interfaces/document-item.repository.interface.js.map +1 -0
- package/dist/document/interfaces/document.repository.interface.d.ts +3 -0
- package/dist/document/interfaces/document.repository.interface.js +3 -0
- package/dist/document/interfaces/document.repository.interface.js.map +1 -0
- package/dist/enum/document-status.enum.d.ts +4 -0
- package/dist/enum/document-status.enum.js +9 -0
- package/dist/enum/document-status.enum.js.map +1 -0
- package/dist/enum/document-type.enum.d.ts +7 -0
- package/dist/enum/document-type.enum.js +12 -0
- package/dist/enum/document-type.enum.js.map +1 -0
- package/dist/enum/index.d.ts +3 -1
- package/dist/enum/index.js +5 -1
- package/dist/enum/index.js.map +1 -1
- package/dist/finance-company/finance-company.d.ts +2 -0
- package/dist/finance-company/finance-company.js +32 -0
- package/dist/finance-company/finance-company.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/finance-account-migration.js +83 -59
- package/migrations/finance-document-item-migration.js +99 -0
- package/migrations/finance-document-migration.js +77 -0
- package/package.json +2 -2
- package/src/account/account.ts +98 -143
- package/src/account/entities/account.entity.ts +66 -6
- package/src/document/document-item.repository.ts +49 -0
- package/src/document/document.repository.ts +41 -0
- package/src/document/entities/document-item.entity.ts +125 -0
- package/src/document/entities/document.entity.ts +106 -0
- package/src/document/index.ts +19 -0
- package/src/document/interfaces/document-attr.interface.ts +20 -0
- package/src/document/interfaces/document-item-attr.interface.ts +19 -0
- package/src/document/interfaces/document-item.repository.interface.ts +4 -0
- package/src/document/interfaces/document.repository.interface.ts +4 -0
- package/src/enum/document-status.enum.ts +4 -0
- package/src/enum/document-type.enum.ts +7 -0
- package/src/enum/index.ts +10 -1
- package/src/finance-company/finance-company.ts +54 -0
|
@@ -1,59 +1,83 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
async up(queryInterface, Sequelize) {
|
|
5
|
-
await queryInterface.createTable('finance_Account', {
|
|
6
|
-
AccountNo: {
|
|
7
|
-
type: Sequelize.STRING(30),
|
|
8
|
-
primaryKey: true,
|
|
9
|
-
allowNull: false,
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
type: Sequelize.STRING(
|
|
13
|
-
allowNull:
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
type: Sequelize.STRING(
|
|
17
|
-
allowNull:
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
type: Sequelize.STRING(
|
|
21
|
-
allowNull: false,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
type: Sequelize.STRING(
|
|
25
|
-
allowNull: false,
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
type: Sequelize.STRING(
|
|
29
|
-
allowNull:
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
type: Sequelize.
|
|
33
|
-
allowNull:
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
allowNull:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
allowNull: true,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable('finance_Account', {
|
|
6
|
+
AccountNo: {
|
|
7
|
+
type: Sequelize.STRING(30),
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
allowNull: false,
|
|
10
|
+
},
|
|
11
|
+
ParentAccountNo: {
|
|
12
|
+
type: Sequelize.STRING(30),
|
|
13
|
+
allowNull: true,
|
|
14
|
+
},
|
|
15
|
+
SystemCode: {
|
|
16
|
+
type: Sequelize.STRING(10),
|
|
17
|
+
allowNull: false,
|
|
18
|
+
},
|
|
19
|
+
AccSystemCode: {
|
|
20
|
+
type: Sequelize.STRING(10),
|
|
21
|
+
allowNull: false,
|
|
22
|
+
},
|
|
23
|
+
AccSystemAccountId: {
|
|
24
|
+
type: Sequelize.STRING(10),
|
|
25
|
+
allowNull: false,
|
|
26
|
+
},
|
|
27
|
+
Name: {
|
|
28
|
+
type: Sequelize.STRING(200),
|
|
29
|
+
allowNull: true,
|
|
30
|
+
},
|
|
31
|
+
Description: {
|
|
32
|
+
type: Sequelize.TEXT,
|
|
33
|
+
allowNull: true,
|
|
34
|
+
},
|
|
35
|
+
AccountType: {
|
|
36
|
+
type: Sequelize.STRING(100),
|
|
37
|
+
allowNull: false,
|
|
38
|
+
},
|
|
39
|
+
AccountSubtype: {
|
|
40
|
+
type: Sequelize.STRING(100),
|
|
41
|
+
allowNull: true,
|
|
42
|
+
},
|
|
43
|
+
OwnerId: {
|
|
44
|
+
type: Sequelize.STRING(30),
|
|
45
|
+
allowNull: true,
|
|
46
|
+
},
|
|
47
|
+
OwnerType: {
|
|
48
|
+
type: Sequelize.STRING(200),
|
|
49
|
+
allowNull: true,
|
|
50
|
+
},
|
|
51
|
+
RelatedObjectId: {
|
|
52
|
+
type: Sequelize.STRING(30),
|
|
53
|
+
allowNull: true,
|
|
54
|
+
},
|
|
55
|
+
RelatedObjectType: {
|
|
56
|
+
type: Sequelize.STRING(200),
|
|
57
|
+
allowNull: true,
|
|
58
|
+
},
|
|
59
|
+
CreatedAt: {
|
|
60
|
+
allowNull: false,
|
|
61
|
+
defaultValue: new Date(),
|
|
62
|
+
type: Sequelize.DATE,
|
|
63
|
+
},
|
|
64
|
+
CreatedById: {
|
|
65
|
+
allowNull: false,
|
|
66
|
+
type: Sequelize.STRING,
|
|
67
|
+
},
|
|
68
|
+
UpdatedAt: {
|
|
69
|
+
allowNull: true,
|
|
70
|
+
defaultValue: new Date(),
|
|
71
|
+
type: Sequelize.DATE,
|
|
72
|
+
},
|
|
73
|
+
UpdatedById: {
|
|
74
|
+
allowNull: true,
|
|
75
|
+
type: Sequelize.STRING,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
async down(queryInterface) {
|
|
81
|
+
await queryInterface.dropTable('finance_Account');
|
|
82
|
+
},
|
|
83
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable('finance_DocumentItem', {
|
|
6
|
+
DocumentItemId: {
|
|
7
|
+
type: Sequelize.STRING(30),
|
|
8
|
+
allowNull: false,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
},
|
|
11
|
+
DocNo:{
|
|
12
|
+
type: Sequelize.STRING(30),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
references: {
|
|
15
|
+
model: 'finance_Document',
|
|
16
|
+
key: 'DocNo',
|
|
17
|
+
},
|
|
18
|
+
onUpdate: 'CASCADE',
|
|
19
|
+
onDelete: 'CASCADE',
|
|
20
|
+
},
|
|
21
|
+
Name:{
|
|
22
|
+
type: Sequelize.STRING(200),
|
|
23
|
+
allowNull: false,
|
|
24
|
+
},
|
|
25
|
+
NameBM:{
|
|
26
|
+
type: Sequelize.STRING(200),
|
|
27
|
+
allowNull: false,
|
|
28
|
+
},
|
|
29
|
+
Description: {
|
|
30
|
+
type: Sequelize.STRING(1000),
|
|
31
|
+
allowNull: true,
|
|
32
|
+
},
|
|
33
|
+
ItemId: {
|
|
34
|
+
type: Sequelize.STRING(30),
|
|
35
|
+
allowNull: true,
|
|
36
|
+
},
|
|
37
|
+
ItemType: {
|
|
38
|
+
type: Sequelize.STRING(200),
|
|
39
|
+
allowNull: true,
|
|
40
|
+
},
|
|
41
|
+
ItemSKU: {
|
|
42
|
+
type: Sequelize.STRING(30),
|
|
43
|
+
allowNull: true,
|
|
44
|
+
},
|
|
45
|
+
ItemSerialNo: {
|
|
46
|
+
type: Sequelize.STRING(30),
|
|
47
|
+
allowNull: true,
|
|
48
|
+
},
|
|
49
|
+
Currency: {
|
|
50
|
+
type: Sequelize.CHAR(3),
|
|
51
|
+
allowNull: false,
|
|
52
|
+
},
|
|
53
|
+
UnitPrice: {
|
|
54
|
+
type: Sequelize.DECIMAL(10, 2),
|
|
55
|
+
allowNull: true,
|
|
56
|
+
},
|
|
57
|
+
Quantity: {
|
|
58
|
+
type: Sequelize.DECIMAL(10, 2),
|
|
59
|
+
allowNull: false,
|
|
60
|
+
},
|
|
61
|
+
QuantityUOM: {
|
|
62
|
+
type: Sequelize.STRING(20),
|
|
63
|
+
allowNull: true,
|
|
64
|
+
},
|
|
65
|
+
Amount: {
|
|
66
|
+
type: Sequelize.DECIMAL(10, 2),
|
|
67
|
+
allowNull: false,
|
|
68
|
+
},
|
|
69
|
+
TaxCode: {
|
|
70
|
+
type: Sequelize.STRING(30),
|
|
71
|
+
allowNull: true,
|
|
72
|
+
},
|
|
73
|
+
DtAccountNo:{
|
|
74
|
+
type: Sequelize.STRING(30),
|
|
75
|
+
allowNull: false,
|
|
76
|
+
references: {
|
|
77
|
+
model: 'finance_Account',
|
|
78
|
+
key: 'AccountNo',
|
|
79
|
+
},
|
|
80
|
+
onUpdate: 'CASCADE',
|
|
81
|
+
onDelete: 'CASCADE',
|
|
82
|
+
},
|
|
83
|
+
CtAccountNo:{
|
|
84
|
+
type: Sequelize.STRING(30),
|
|
85
|
+
allowNull: false,
|
|
86
|
+
references: {
|
|
87
|
+
model: 'finance_Account',
|
|
88
|
+
key: 'AccountNo',
|
|
89
|
+
},
|
|
90
|
+
onUpdate: 'CASCADE',
|
|
91
|
+
onDelete: 'CASCADE',
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
async down(queryInterface) {
|
|
97
|
+
await queryInterface.dropTable('finance_DocumentItem');
|
|
98
|
+
},
|
|
99
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable('finance_Document', {
|
|
6
|
+
DocNo: {
|
|
7
|
+
type: Sequelize.STRING(30),
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
allowNull: false,
|
|
10
|
+
},
|
|
11
|
+
DocType: {
|
|
12
|
+
type: Sequelize.ENUM(['Invoice', 'Debit Note', 'Credit Note', 'Quotation', 'Receipt']),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
},
|
|
15
|
+
DocDate: {
|
|
16
|
+
type: Sequelize.DATE,
|
|
17
|
+
allowNull: false,
|
|
18
|
+
},
|
|
19
|
+
SystemCode: {
|
|
20
|
+
type: Sequelize.STRING(10),
|
|
21
|
+
allowNull: false,
|
|
22
|
+
},
|
|
23
|
+
Currency: {
|
|
24
|
+
type: Sequelize.CHAR(3),
|
|
25
|
+
allowNull: false,
|
|
26
|
+
},
|
|
27
|
+
Amount: {
|
|
28
|
+
type: Sequelize.DECIMAL(10, 2),
|
|
29
|
+
allowNull: false,
|
|
30
|
+
},
|
|
31
|
+
Description: {
|
|
32
|
+
type: Sequelize.STRING(1000),
|
|
33
|
+
allowNull: false,
|
|
34
|
+
},
|
|
35
|
+
Status: {
|
|
36
|
+
type: Sequelize.STRING(20),
|
|
37
|
+
allowNull: false,
|
|
38
|
+
},
|
|
39
|
+
IssuedById: {
|
|
40
|
+
type: Sequelize.STRING(30),
|
|
41
|
+
allowNull: false,
|
|
42
|
+
},
|
|
43
|
+
IssuedToId: {
|
|
44
|
+
type: Sequelize.STRING(30),
|
|
45
|
+
allowNull: false,
|
|
46
|
+
},
|
|
47
|
+
IssuedToType: {
|
|
48
|
+
type: Sequelize.STRING(200),
|
|
49
|
+
allowNull: false,
|
|
50
|
+
},
|
|
51
|
+
AccSystemCode: {
|
|
52
|
+
type: Sequelize.STRING(10),
|
|
53
|
+
allowNull: false,
|
|
54
|
+
},
|
|
55
|
+
PostedToAccYN: {
|
|
56
|
+
type: Sequelize.CHAR(1),
|
|
57
|
+
allowNull: false,
|
|
58
|
+
},
|
|
59
|
+
UseAccSystemDocYN: {
|
|
60
|
+
type: Sequelize.CHAR(1),
|
|
61
|
+
allowNull: false,
|
|
62
|
+
},
|
|
63
|
+
DocPDFFilePath: {
|
|
64
|
+
type: Sequelize.STRING(500),
|
|
65
|
+
allowNull: false,
|
|
66
|
+
},
|
|
67
|
+
DocHTMLFilePath: {
|
|
68
|
+
type: Sequelize.STRING(500),
|
|
69
|
+
allowNull: false,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
async down(queryInterface) {
|
|
75
|
+
await queryInterface.dropTable('finance_Document');
|
|
76
|
+
},
|
|
77
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomei/finance",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
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.14",
|
|
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,66 +1,119 @@
|
|
|
1
|
-
import { ICreateAccountAttr } from './interfaces/account-attr.interface';
|
|
2
1
|
import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
3
|
-
import * as uniqid from 'uniqid';
|
|
4
2
|
import { AccountModel } from './entities/account.entity';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { IAccountSystem } from 'src/interfaces';
|
|
8
|
-
import { ObjectBase, PersonBase } from '@tomei/general';
|
|
3
|
+
import { ObjectBase, PersonBase, RecordNotFoundError } from '@tomei/general';
|
|
4
|
+
import { IBaseRepository } from '@tomei/general/dist/interfaces/repository.base.interface';
|
|
9
5
|
export class Account {
|
|
10
6
|
accountRepository: IAccountRepository;
|
|
7
|
+
AccountNo: string;
|
|
8
|
+
Owner: PersonBase;
|
|
9
|
+
RelatedObject: ObjectBase;
|
|
11
10
|
|
|
12
|
-
private
|
|
11
|
+
private isNewRecord = true;
|
|
13
12
|
private OwnerId: string;
|
|
14
13
|
private OwnerType: string;
|
|
15
14
|
private RelatedObjectId: string;
|
|
16
15
|
private RelatedObjectType: string;
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
isParamsInitialized: boolean;
|
|
16
|
+
private ParentAccountNo: string;
|
|
17
|
+
private SystemCode: string;
|
|
18
|
+
private AccSystemAccountId: string;
|
|
19
|
+
private AccSystemCode: string;
|
|
20
|
+
private Name: string;
|
|
21
|
+
private Description: string;
|
|
22
|
+
private AccountType: string;
|
|
23
|
+
private AccountSubtype: string;
|
|
27
24
|
|
|
28
25
|
constructor(
|
|
29
|
-
accountRepository:
|
|
30
|
-
|
|
31
|
-
SystemCode: string,
|
|
32
|
-
params?: ICreateAccountAttr,
|
|
26
|
+
accountRepository: IBaseRepository<AccountModel>,
|
|
27
|
+
accountNo: string,
|
|
33
28
|
) {
|
|
34
29
|
this.accountRepository = accountRepository;
|
|
35
|
-
this.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
this.AccountNo = accountNo;
|
|
31
|
+
const accountData = this.accountRepository.findOne({
|
|
32
|
+
where: { AccountNo: accountNo },
|
|
33
|
+
});
|
|
34
|
+
if (accountData) {
|
|
35
|
+
this.isNewRecord = false;
|
|
36
|
+
this.ParentAccountNo = accountData.ParentAccountNo;
|
|
37
|
+
this.SystemCode = accountData.SystemCode;
|
|
38
|
+
this.AccSystemCode = accountData.AccSystemCode;
|
|
39
|
+
this.AccSystemAccountId = accountData.AccSystemAccountId;
|
|
40
|
+
this.Name = accountData.Name;
|
|
41
|
+
this.Description = accountData.Description;
|
|
42
|
+
this.AccountType = accountData.AccountType;
|
|
43
|
+
this.AccountSubtype = accountData.AccountSubtype;
|
|
44
|
+
this.OwnerId = accountData.OwnerId;
|
|
45
|
+
this.OwnerType = accountData.OwnerType;
|
|
46
|
+
this.RelatedObjectId = accountData.RelatedObjectId;
|
|
47
|
+
this.RelatedObjectType = accountData.RelatedObjectType;
|
|
48
|
+
this.AccSystemCode = accountData.AccSystemCode;
|
|
49
|
+
} else {
|
|
50
|
+
const notFoundError = new RecordNotFoundError('No Record Found.');
|
|
51
|
+
throw notFoundError;
|
|
39
52
|
}
|
|
40
53
|
}
|
|
41
54
|
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
|
|
45
|
-
this.OwnerType = typeof params.Owner;
|
|
55
|
+
public get name(): string {
|
|
56
|
+
return this.Name;
|
|
57
|
+
}
|
|
46
58
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (params.ParentAccountNo) this.ParentAccountNo = params.ParentAccountNo;
|
|
59
|
+
public get accountType(): string {
|
|
60
|
+
return this.AccountType;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public get accountSubType(): string {
|
|
64
|
+
return this.AccountSubtype;
|
|
65
|
+
}
|
|
55
66
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
) {
|
|
62
|
-
|
|
67
|
+
public get parentAccountNo(): string {
|
|
68
|
+
return this.ParentAccountNo;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
validateAccountValue() {
|
|
72
|
+
if (!this.SystemCode) {
|
|
73
|
+
throw new Error('SystemCode is required.');
|
|
74
|
+
}
|
|
75
|
+
if (!this.AccSystemCode) {
|
|
76
|
+
throw new Error('AccSystemCode is required.');
|
|
63
77
|
}
|
|
78
|
+
if (!this.AccSystemAccountId) {
|
|
79
|
+
throw new Error('AccSystemAccountId is required.');
|
|
80
|
+
}
|
|
81
|
+
if (!this.AccountType) {
|
|
82
|
+
throw new Error('AccountType is required.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
isParentAccountExsits() {
|
|
87
|
+
if (this.ParentAccountNo) return true;
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async save(
|
|
92
|
+
accSystemAccountId: string,
|
|
93
|
+
userId: string,
|
|
94
|
+
dbTransaction?: any,
|
|
95
|
+
): Promise<AccountModel> {
|
|
96
|
+
this.AccSystemAccountId = accSystemAccountId;
|
|
97
|
+
const data = await this.accountRepository.create(
|
|
98
|
+
{
|
|
99
|
+
AccountNo: this.AccountNo,
|
|
100
|
+
SystemCode: this.SystemCode,
|
|
101
|
+
AccSystemCode: this.AccSystemCode,
|
|
102
|
+
AccSystemAccountId: this.AccSystemAccountId,
|
|
103
|
+
Name: this.Name,
|
|
104
|
+
Description: this.Description,
|
|
105
|
+
AccountType: this.AccountType,
|
|
106
|
+
AccountSubtype: this.AccountSubtype,
|
|
107
|
+
OwnerId: this.OwnerId,
|
|
108
|
+
OwnerType: this.OwnerType,
|
|
109
|
+
RelatedObjectId: this.RelatedObjectId,
|
|
110
|
+
RelatedObjectType: this.RelatedObjectType,
|
|
111
|
+
CreatedAt: new Date(),
|
|
112
|
+
CreatedById: userId,
|
|
113
|
+
},
|
|
114
|
+
dbTransaction,
|
|
115
|
+
);
|
|
116
|
+
return data;
|
|
64
117
|
}
|
|
65
118
|
|
|
66
119
|
/**
|
|
@@ -74,7 +127,7 @@ export class Account {
|
|
|
74
127
|
try {
|
|
75
128
|
const account = await this.accountRepository.findOne({
|
|
76
129
|
OwnerId: this.OwnerId,
|
|
77
|
-
|
|
130
|
+
AccSystemAccountId: this.AccSystemAccountId,
|
|
78
131
|
});
|
|
79
132
|
|
|
80
133
|
if (account) {
|
|
@@ -88,102 +141,4 @@ export class Account {
|
|
|
88
141
|
}
|
|
89
142
|
}
|
|
90
143
|
}
|
|
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
144
|
}
|