@tomei/finance 0.1.2 → 0.1.4
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/.eslintrc.js +7 -1
- package/.prettierrc +2 -1
- package/dist/account/account.d.ts +2 -0
- package/dist/account/account.js +26 -3
- package/dist/account/account.js.map +1 -1
- package/dist/account/entities/account.entity.d.ts +2 -0
- package/dist/account/entities/account.entity.js +5 -0
- package/dist/account/entities/account.entity.js.map +1 -1
- package/dist/customer/customer.d.ts +3 -2
- package/dist/customer/customer.js +10 -5
- package/dist/customer/customer.js.map +1 -1
- 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/enum/payment-method.enum.d.ts +3 -0
- package/dist/enum/payment-method.enum.js +8 -0
- package/dist/enum/payment-method.enum.js.map +1 -0
- package/dist/enum/payment-type.enum.d.ts +4 -0
- package/dist/enum/payment-type.enum.js +9 -0
- package/dist/enum/payment-type.enum.js.map +1 -0
- package/dist/interfaces/account-system.interface.d.ts +4 -0
- package/dist/payment/entities/payment-item.entity.d.ts +10 -0
- package/dist/payment/entities/payment-item.entity.js +62 -0
- package/dist/payment/entities/payment-item.entity.js.map +1 -0
- package/dist/payment/entities/payment.entity.d.ts +25 -0
- package/dist/payment/entities/payment.entity.js +152 -0
- package/dist/payment/entities/payment.entity.js.map +1 -0
- package/dist/payment/index.d.ts +10 -0
- package/dist/payment/index.js +18 -0
- package/dist/payment/index.js.map +1 -0
- package/dist/payment/interfaces/payment-attr.interface.d.ts +20 -0
- package/dist/payment/interfaces/payment-attr.interface.js +7 -0
- package/dist/payment/interfaces/payment-attr.interface.js.map +1 -0
- package/dist/payment/interfaces/payment-item-attr.interface.d.ts +7 -0
- package/dist/payment/interfaces/payment-item-attr.interface.js +7 -0
- package/dist/payment/interfaces/payment-item-attr.interface.js.map +1 -0
- package/dist/payment/interfaces/payment-item.repository.interface.d.ts +3 -0
- package/dist/payment/interfaces/payment-item.repository.interface.js +3 -0
- package/dist/payment/interfaces/payment-item.repository.interface.js.map +1 -0
- package/dist/payment/interfaces/payment.repository.interface.d.ts +3 -0
- package/dist/payment/interfaces/payment.repository.interface.js +3 -0
- package/dist/payment/interfaces/payment.repository.interface.js.map +1 -0
- package/dist/payment/payment-item.repository.d.ts +16 -0
- package/dist/payment/payment-item.repository.js +47 -0
- package/dist/payment/payment-item.repository.js.map +1 -0
- package/dist/payment/payment.d.ts +46 -0
- package/dist/payment/payment.js +122 -0
- package/dist/payment/payment.js.map +1 -0
- package/dist/payment/payment.repository.d.ts +16 -0
- package/dist/payment/payment.repository.js +47 -0
- package/dist/payment/payment.repository.js.map +1 -0
- package/dist/quickbook-client/client.d.ts +4 -0
- package/dist/quickbook-client/client.js +49 -2
- package/dist/quickbook-client/client.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/finance-account-migration.js +59 -59
- package/migrations/finance-payment-item-migration.js +39 -0
- package/migrations/finance-payment-migration.js +89 -0
- package/package.json +2 -2
- package/src/account/account.ts +26 -3
- package/src/account/entities/account.entity.ts +5 -0
- package/src/customer/customer.ts +152 -146
- package/src/enum/index.ts +3 -1
- package/src/enum/payment-method.enum.ts +3 -0
- package/src/enum/payment-type.enum.ts +4 -0
- package/src/interfaces/account-system.interface.ts +5 -0
- package/src/payment/entities/payment-item.entity.ts +47 -0
- package/src/payment/entities/payment.entity.ts +125 -0
- package/src/payment/index.ts +21 -0
- package/src/payment/interfaces/payment-attr.interface.ts +21 -0
- package/src/payment/interfaces/payment-item-attr.interface.ts +7 -0
- package/src/payment/interfaces/payment-item.repository.interface.ts +4 -0
- package/src/payment/interfaces/payment.repository.interface.ts +4 -0
- package/src/payment/payment-item.repository.ts +44 -0
- package/src/payment/payment.repository.ts +41 -0
- package/src/payment/payment.ts +187 -0
- package/src/quickbook-client/client.ts +54 -2
|
@@ -1,59 +1,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
|
-
SystemCode: {
|
|
12
|
-
type: Sequelize.STRING(10),
|
|
13
|
-
allowNull: false,
|
|
14
|
-
},
|
|
15
|
-
Name: {
|
|
16
|
-
type: Sequelize.STRING(200),
|
|
17
|
-
allowNull: true,
|
|
18
|
-
},
|
|
19
|
-
OwnerId: {
|
|
20
|
-
type: Sequelize.STRING(30),
|
|
21
|
-
allowNull: false,
|
|
22
|
-
},
|
|
23
|
-
OwnerType: {
|
|
24
|
-
type: Sequelize.STRING(200),
|
|
25
|
-
allowNull: false,
|
|
26
|
-
},
|
|
27
|
-
RelatedObjectId: {
|
|
28
|
-
type: Sequelize.STRING(30),
|
|
29
|
-
allowNull: false,
|
|
30
|
-
},
|
|
31
|
-
RelatedObjectType: {
|
|
32
|
-
type: Sequelize.STRING(200),
|
|
33
|
-
allowNull: false,
|
|
34
|
-
},
|
|
35
|
-
CreatedAt: {
|
|
36
|
-
allowNull: false,
|
|
37
|
-
defaultValue: new Date(),
|
|
38
|
-
type: Sequelize.DATE,
|
|
39
|
-
},
|
|
40
|
-
CreatedById: {
|
|
41
|
-
allowNull: false,
|
|
42
|
-
type: Sequelize.STRING,
|
|
43
|
-
},
|
|
44
|
-
UpdatedAt: {
|
|
45
|
-
allowNull: true,
|
|
46
|
-
defaultValue: new Date(),
|
|
47
|
-
type: Sequelize.DATE,
|
|
48
|
-
},
|
|
49
|
-
UpdatedById: {
|
|
50
|
-
allowNull: true,
|
|
51
|
-
type: Sequelize.STRING,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
async down(queryInterface) {
|
|
57
|
-
await queryInterface.dropTable('finance_Account');
|
|
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
|
+
SystemCode: {
|
|
12
|
+
type: Sequelize.STRING(10),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
},
|
|
15
|
+
Name: {
|
|
16
|
+
type: Sequelize.STRING(200),
|
|
17
|
+
allowNull: true,
|
|
18
|
+
},
|
|
19
|
+
OwnerId: {
|
|
20
|
+
type: Sequelize.STRING(30),
|
|
21
|
+
allowNull: false,
|
|
22
|
+
},
|
|
23
|
+
OwnerType: {
|
|
24
|
+
type: Sequelize.STRING(200),
|
|
25
|
+
allowNull: false,
|
|
26
|
+
},
|
|
27
|
+
RelatedObjectId: {
|
|
28
|
+
type: Sequelize.STRING(30),
|
|
29
|
+
allowNull: false,
|
|
30
|
+
},
|
|
31
|
+
RelatedObjectType: {
|
|
32
|
+
type: Sequelize.STRING(200),
|
|
33
|
+
allowNull: false,
|
|
34
|
+
},
|
|
35
|
+
CreatedAt: {
|
|
36
|
+
allowNull: false,
|
|
37
|
+
defaultValue: new Date(),
|
|
38
|
+
type: Sequelize.DATE,
|
|
39
|
+
},
|
|
40
|
+
CreatedById: {
|
|
41
|
+
allowNull: false,
|
|
42
|
+
type: Sequelize.STRING,
|
|
43
|
+
},
|
|
44
|
+
UpdatedAt: {
|
|
45
|
+
allowNull: true,
|
|
46
|
+
defaultValue: new Date(),
|
|
47
|
+
type: Sequelize.DATE,
|
|
48
|
+
},
|
|
49
|
+
UpdatedById: {
|
|
50
|
+
allowNull: true,
|
|
51
|
+
type: Sequelize.STRING,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async down(queryInterface) {
|
|
57
|
+
await queryInterface.dropTable('finance_Account');
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable('finance_PaymentItem', {
|
|
6
|
+
PaymentId: {
|
|
7
|
+
type: Sequelize.STRING(30),
|
|
8
|
+
allowNull: false,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
references: {
|
|
11
|
+
model: 'finance_Payment',
|
|
12
|
+
key: 'PaymentId',
|
|
13
|
+
},
|
|
14
|
+
onUpdate: 'CASCADE',
|
|
15
|
+
onDelete: 'CASCADE',
|
|
16
|
+
},
|
|
17
|
+
PayForObjectId: {
|
|
18
|
+
type: Sequelize.STRING(30),
|
|
19
|
+
allowNull: false,
|
|
20
|
+
},
|
|
21
|
+
PayForObjectType: {
|
|
22
|
+
type: Sequelize.STRING(200),
|
|
23
|
+
allowNull: false,
|
|
24
|
+
},
|
|
25
|
+
Currency: {
|
|
26
|
+
type: Sequelize.CHAR(3),
|
|
27
|
+
allowNull: false,
|
|
28
|
+
},
|
|
29
|
+
Amount: {
|
|
30
|
+
type: Sequelize.DECIMAL(10, 2),
|
|
31
|
+
allowNull: false,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
async down(queryInterface) {
|
|
37
|
+
await queryInterface.dropTable('finance_PaymentItem');
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable('finance_Payment', {
|
|
6
|
+
PaymentId: {
|
|
7
|
+
type: Sequelize.STRING(30),
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
allowNull: false,
|
|
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
|
+
PaymentType: {
|
|
22
|
+
type: Sequelize.ENUM(['Payment Received', 'Payout']),
|
|
23
|
+
defaultValue: 'Payment Received',
|
|
24
|
+
allowNull: false,
|
|
25
|
+
},
|
|
26
|
+
PaymentDate: {
|
|
27
|
+
type: Sequelize.DATE,
|
|
28
|
+
allowNull: false,
|
|
29
|
+
},
|
|
30
|
+
Currency: {
|
|
31
|
+
type: Sequelize.CHAR(3),
|
|
32
|
+
allowNull: false,
|
|
33
|
+
},
|
|
34
|
+
Amount: {
|
|
35
|
+
type: Sequelize.DECIMAL(10, 2),
|
|
36
|
+
allowNull: false,
|
|
37
|
+
},
|
|
38
|
+
Status: {
|
|
39
|
+
type: Sequelize.STRING(20),
|
|
40
|
+
allowNull: false,
|
|
41
|
+
},
|
|
42
|
+
Method: {
|
|
43
|
+
type: Sequelize.STRING,
|
|
44
|
+
allowNull: false,
|
|
45
|
+
},
|
|
46
|
+
MethodParty: {
|
|
47
|
+
type: Sequelize.STRING(255),
|
|
48
|
+
allowNull: false,
|
|
49
|
+
},
|
|
50
|
+
MethodAccountName: {
|
|
51
|
+
type: Sequelize.STRING(100),
|
|
52
|
+
allowNull: true,
|
|
53
|
+
},
|
|
54
|
+
MethodAccountNo: {
|
|
55
|
+
type: Sequelize.STRING(100),
|
|
56
|
+
allowNull: true,
|
|
57
|
+
},
|
|
58
|
+
TransactionId: {
|
|
59
|
+
type: Sequelize.STRING(100),
|
|
60
|
+
allowNull: true,
|
|
61
|
+
},
|
|
62
|
+
ApprovalId: {
|
|
63
|
+
type: Sequelize.STRING(100),
|
|
64
|
+
allowNull: true,
|
|
65
|
+
},
|
|
66
|
+
ReceivedBy: {
|
|
67
|
+
type: Sequelize.STRING(30),
|
|
68
|
+
allowNull: false,
|
|
69
|
+
},
|
|
70
|
+
UpdatedAt: {
|
|
71
|
+
allowNull: false,
|
|
72
|
+
defaultValue: new Date(),
|
|
73
|
+
type: Sequelize.DATE,
|
|
74
|
+
},
|
|
75
|
+
UpdatedBy: {
|
|
76
|
+
allowNull: false,
|
|
77
|
+
type: Sequelize.STRING,
|
|
78
|
+
},
|
|
79
|
+
Remarks: {
|
|
80
|
+
type: Sequelize.TEXT,
|
|
81
|
+
allowNull: true,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async down(queryInterface) {
|
|
87
|
+
await queryInterface.dropTable('finance_Payment');
|
|
88
|
+
},
|
|
89
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomei/finance",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "NestJS package for finance module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
]
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@tomei/general": "^0.0.
|
|
73
|
+
"@tomei/general": "^0.0.10"
|
|
74
74
|
}
|
|
75
75
|
}
|
package/src/account/account.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { IAccountSystem } from 'src/interfaces';
|
|
|
9
9
|
export class Account {
|
|
10
10
|
accountRepository: IAccountRepository;
|
|
11
11
|
|
|
12
|
+
private AccountNo: string;
|
|
12
13
|
private OwnerId: string;
|
|
13
14
|
private OwnerType: string;
|
|
14
15
|
private RelatedObjectId: string;
|
|
@@ -54,6 +55,28 @@ export class Account {
|
|
|
54
55
|
this.isParamsInitialized = true;
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
async getAccountNo() {
|
|
59
|
+
if (this.AccountNo) {
|
|
60
|
+
return this.AccountNo;
|
|
61
|
+
} else {
|
|
62
|
+
try {
|
|
63
|
+
const account = await this.accountRepository.findOne({
|
|
64
|
+
OwnerId: this.OwnerId,
|
|
65
|
+
AccSystemId: this.AccSystemId,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (account) {
|
|
69
|
+
this.AccountNo = account.AccountNo;
|
|
70
|
+
return this.AccountNo;
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error('Account need to be created first.');
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
57
80
|
async create(userId: string, client: IAccountSystem, dbOptions: any) {
|
|
58
81
|
try {
|
|
59
82
|
if (!this.Owner || !this.RelatedObject) {
|
|
@@ -107,13 +130,13 @@ export class Account {
|
|
|
107
130
|
};
|
|
108
131
|
}
|
|
109
132
|
|
|
110
|
-
const
|
|
133
|
+
const accountId = await client.createAccount(createAccountPayload);
|
|
111
134
|
|
|
112
135
|
const account = await this.accountRepository.create(
|
|
113
136
|
{
|
|
114
|
-
AccountNo:
|
|
137
|
+
AccountNo: accountId,
|
|
115
138
|
SystemCode: this.AccSystemId,
|
|
116
|
-
Name:
|
|
139
|
+
Name: this.Owner.FullName,
|
|
117
140
|
OwnerId: this.OwnerId,
|
|
118
141
|
OwnerType: this.OwnerType,
|
|
119
142
|
RelatedObjectId: this.RelatedObjectId,
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
Table,
|
|
7
7
|
DataType,
|
|
8
8
|
UpdatedAt,
|
|
9
|
+
HasMany,
|
|
9
10
|
} from 'sequelize-typescript';
|
|
11
|
+
import { PaymentModel } from '../../payment/entities/payment.entity';
|
|
10
12
|
|
|
11
13
|
@Table({ tableName: 'finance_Account', createdAt: false, updatedAt: false })
|
|
12
14
|
export class AccountModel extends Model {
|
|
@@ -99,4 +101,7 @@ export class AccountModel extends Model {
|
|
|
99
101
|
})
|
|
100
102
|
@Column({ allowNull: false, type: DataType.STRING(30) })
|
|
101
103
|
UpdatedById: string;
|
|
104
|
+
|
|
105
|
+
@HasMany(() => PaymentModel)
|
|
106
|
+
PaymentModel: PaymentModel[];
|
|
102
107
|
}
|
package/src/customer/customer.ts
CHANGED
|
@@ -1,146 +1,152 @@
|
|
|
1
|
-
import { AddressBase, PersonBase } from '@tomei/general';
|
|
2
|
-
import { IAccountSystem } from '../interfaces';
|
|
3
|
-
import { Address } from '../base/base.address';
|
|
4
|
-
import { FinanceCustomerRepository } from './finance-customer.repository';
|
|
5
|
-
import { ICustomerRepository } from './interfaces/customer.repository.interface';
|
|
6
|
-
import { getConfig } from '../config';
|
|
7
|
-
|
|
8
|
-
export class Customer extends PersonBase {
|
|
9
|
-
private CustomerId: string;
|
|
10
|
-
private AccSystemId: string;
|
|
11
|
-
|
|
12
|
-
FullName: string;
|
|
13
|
-
IDNo: string;
|
|
14
|
-
IDType: string;
|
|
15
|
-
Email: string;
|
|
16
|
-
ContactNo: string;
|
|
17
|
-
Address: AddressBase;
|
|
18
|
-
Id: string;
|
|
19
|
-
Name: string;
|
|
20
|
-
|
|
21
|
-
financeCustomerRepository: FinanceCustomerRepository;
|
|
22
|
-
customerRepository: ICustomerRepository<any>;
|
|
23
|
-
customerAddressRepository: any;
|
|
24
|
-
|
|
25
|
-
person: PersonBase;
|
|
26
|
-
systemCode: string;
|
|
27
|
-
constructor(
|
|
28
|
-
financeCustomerRepository: FinanceCustomerRepository,
|
|
29
|
-
customerRepository: ICustomerRepository<any>,
|
|
30
|
-
customerAddressRepository: any,
|
|
31
|
-
|
|
32
|
-
systemCode: string,
|
|
33
|
-
person?: PersonBase,
|
|
34
|
-
) {
|
|
35
|
-
super();
|
|
36
|
-
this.financeCustomerRepository = financeCustomerRepository;
|
|
37
|
-
this.customerRepository = customerRepository;
|
|
38
|
-
this.customerAddressRepository = customerAddressRepository;
|
|
39
|
-
this.
|
|
40
|
-
this.systemCode = systemCode;
|
|
41
|
-
if (person) {
|
|
42
|
-
this.person = person;
|
|
43
|
-
this.init(person);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
init(person: PersonBase) {
|
|
48
|
-
this.FullName = person.FullName;
|
|
49
|
-
this.IDNo = person.IDNo;
|
|
50
|
-
this.IDType = person.IDType;
|
|
51
|
-
this.Email = person.Email;
|
|
52
|
-
this.ContactNo = person.ContactNo;
|
|
53
|
-
this.Address = person.Address;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async getDetails(): Promise<any> {
|
|
57
|
-
if (
|
|
58
|
-
!this.FullName ||
|
|
59
|
-
!this.IDNo ||
|
|
60
|
-
!this.IDType ||
|
|
61
|
-
!this.Email ||
|
|
62
|
-
!this.ContactNo ||
|
|
63
|
-
!this.Address
|
|
64
|
-
) {
|
|
65
|
-
const customerData = await this.customerRepository.findOne({
|
|
66
|
-
where: { IdNo: this.IDNo },
|
|
67
|
-
});
|
|
68
|
-
if (!customerData) {
|
|
69
|
-
throw new Error('Customer must be created first.');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.FullName = customerData.FullName;
|
|
73
|
-
this.IDNo = customerData.IDNo;
|
|
74
|
-
this.IDType = customerData.IDType;
|
|
75
|
-
this.Email = customerData.Email;
|
|
76
|
-
this.ContactNo = customerData.ContactNo;
|
|
77
|
-
this.Id = customerData.CustomerId;
|
|
78
|
-
this.Name = customerData.PreferredName;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
FullName: this.FullName,
|
|
83
|
-
IDNo: this.IDNo,
|
|
84
|
-
IDType: this.IDType,
|
|
85
|
-
Email: this.Email,
|
|
86
|
-
ContactNo: this.ContactNo,
|
|
87
|
-
Address: this.Address,
|
|
88
|
-
Id: this.Id,
|
|
89
|
-
Name: this.Name,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async getDefaultAddress(): Promise<any> {
|
|
94
|
-
if (
|
|
95
|
-
!this.Address.Line1 ||
|
|
96
|
-
!this.Address.City ||
|
|
97
|
-
!this.Address.PostalCode ||
|
|
98
|
-
!this.Address.Country
|
|
99
|
-
) {
|
|
100
|
-
const addressData = await this.customerAddressRepository.findOne({
|
|
101
|
-
where: { CustomerId: this.Id, isDefaultYN: 'Y' },
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
if (!addressData) {
|
|
105
|
-
throw new Error('Address must be created first.');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this.Address = new Address(
|
|
109
|
-
addressData.Address,
|
|
110
|
-
addressData.City,
|
|
111
|
-
addressData.PostCode,
|
|
112
|
-
addressData.Country,
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
Line1: this.Address.Line1,
|
|
117
|
-
City: this.Address.City,
|
|
118
|
-
PostalCode: this.Address.PostalCode,
|
|
119
|
-
Country: this.Address.Country,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
1
|
+
import { AddressBase, PersonBase } from '@tomei/general';
|
|
2
|
+
import { IAccountSystem } from '../interfaces';
|
|
3
|
+
import { Address } from '../base/base.address';
|
|
4
|
+
import { FinanceCustomerRepository } from './finance-customer.repository';
|
|
5
|
+
import { ICustomerRepository } from './interfaces/customer.repository.interface';
|
|
6
|
+
import { getConfig } from '../config';
|
|
7
|
+
|
|
8
|
+
export class Customer extends PersonBase {
|
|
9
|
+
private CustomerId: string;
|
|
10
|
+
private AccSystemId: string;
|
|
11
|
+
|
|
12
|
+
FullName: string;
|
|
13
|
+
IDNo: string;
|
|
14
|
+
IDType: string;
|
|
15
|
+
public Email: string;
|
|
16
|
+
ContactNo: string;
|
|
17
|
+
Address: AddressBase;
|
|
18
|
+
Id: string;
|
|
19
|
+
Name: string;
|
|
20
|
+
|
|
21
|
+
financeCustomerRepository: FinanceCustomerRepository;
|
|
22
|
+
customerRepository: ICustomerRepository<any>;
|
|
23
|
+
customerAddressRepository: any;
|
|
24
|
+
accountingSystem: IAccountSystem;
|
|
25
|
+
person: PersonBase;
|
|
26
|
+
systemCode: string;
|
|
27
|
+
constructor(
|
|
28
|
+
financeCustomerRepository: FinanceCustomerRepository,
|
|
29
|
+
customerRepository: ICustomerRepository<any>,
|
|
30
|
+
customerAddressRepository: any,
|
|
31
|
+
accountingSystem: IAccountSystem,
|
|
32
|
+
systemCode: string,
|
|
33
|
+
person?: PersonBase,
|
|
34
|
+
) {
|
|
35
|
+
super();
|
|
36
|
+
this.financeCustomerRepository = financeCustomerRepository;
|
|
37
|
+
this.customerRepository = customerRepository;
|
|
38
|
+
this.customerAddressRepository = customerAddressRepository;
|
|
39
|
+
this.accountingSystem = accountingSystem;
|
|
40
|
+
this.systemCode = systemCode;
|
|
41
|
+
if (person) {
|
|
42
|
+
this.person = person;
|
|
43
|
+
this.init(person);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
init(person: PersonBase) {
|
|
48
|
+
this.FullName = person.FullName;
|
|
49
|
+
this.IDNo = person.IDNo;
|
|
50
|
+
this.IDType = person.IDType;
|
|
51
|
+
this.Email = person.Email;
|
|
52
|
+
this.ContactNo = person.ContactNo;
|
|
53
|
+
this.Address = person.Address;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async getDetails(): Promise<any> {
|
|
57
|
+
if (
|
|
58
|
+
!this.FullName ||
|
|
59
|
+
!this.IDNo ||
|
|
60
|
+
!this.IDType ||
|
|
61
|
+
!this.Email ||
|
|
62
|
+
!this.ContactNo ||
|
|
63
|
+
!this.Address
|
|
64
|
+
) {
|
|
65
|
+
const customerData = await this.customerRepository.findOne({
|
|
66
|
+
where: { IdNo: this.IDNo },
|
|
67
|
+
});
|
|
68
|
+
if (!customerData) {
|
|
69
|
+
throw new Error('Customer must be created first.');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.FullName = customerData.FullName;
|
|
73
|
+
this.IDNo = customerData.IDNo;
|
|
74
|
+
this.IDType = customerData.IDType;
|
|
75
|
+
this.Email = customerData.Email;
|
|
76
|
+
this.ContactNo = customerData.ContactNo;
|
|
77
|
+
this.Id = customerData.CustomerId;
|
|
78
|
+
this.Name = customerData.PreferredName;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
FullName: this.FullName,
|
|
83
|
+
IDNo: this.IDNo,
|
|
84
|
+
IDType: this.IDType,
|
|
85
|
+
Email: this.Email,
|
|
86
|
+
ContactNo: this.ContactNo,
|
|
87
|
+
Address: this.Address,
|
|
88
|
+
Id: this.Id,
|
|
89
|
+
Name: this.Name,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async getDefaultAddress(): Promise<any> {
|
|
94
|
+
if (
|
|
95
|
+
!this.Address.Line1 ||
|
|
96
|
+
!this.Address.City ||
|
|
97
|
+
!this.Address.PostalCode ||
|
|
98
|
+
!this.Address.Country
|
|
99
|
+
) {
|
|
100
|
+
const addressData = await this.customerAddressRepository.findOne({
|
|
101
|
+
where: { CustomerId: this.Id, isDefaultYN: 'Y' },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (!addressData) {
|
|
105
|
+
throw new Error('Address must be created first.');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.Address = new Address(
|
|
109
|
+
addressData.Address,
|
|
110
|
+
addressData.City,
|
|
111
|
+
addressData.PostCode,
|
|
112
|
+
addressData.Country,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
Line1: this.Address.Line1,
|
|
117
|
+
City: this.Address.City,
|
|
118
|
+
PostalCode: this.Address.PostalCode,
|
|
119
|
+
Country: this.Address.Country,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async getCustomerId(): Promise<any> {
|
|
124
|
+
if (!this.CustomerId) {
|
|
125
|
+
throw new Error('Finance Customer must be created first.');
|
|
126
|
+
}
|
|
127
|
+
return this.CustomerId;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async create() {
|
|
131
|
+
try {
|
|
132
|
+
await this.getDetails();
|
|
133
|
+
await this.getDefaultAddress();
|
|
134
|
+
|
|
135
|
+
this.CustomerId = await this.accountingSystem.createCustomer({
|
|
136
|
+
FullName: this.FullName,
|
|
137
|
+
Email: this.Email,
|
|
138
|
+
ContractNo: this.ContactNo,
|
|
139
|
+
Address: this.Address,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
this.AccSystemId =
|
|
143
|
+
getConfig().systemConfig[this.systemCode].accountingSystem;
|
|
144
|
+
return await this.financeCustomerRepository.create({
|
|
145
|
+
CustomerId: this.CustomerId,
|
|
146
|
+
AccSystemId: this.AccSystemId,
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
package/src/enum/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Customer } from '../customer';
|
|
2
|
+
import { Payment } from '../payment';
|
|
3
|
+
|
|
1
4
|
export interface IAccountSystem {
|
|
2
5
|
createAccount(payload: any): Promise<any>;
|
|
3
6
|
createInvoice(payload: any): Promise<any>;
|
|
@@ -5,4 +8,6 @@ export interface IAccountSystem {
|
|
|
5
8
|
createCreditNote(payload: any): Promise<any>;
|
|
6
9
|
postTransaction(payload: any): Promise<any>;
|
|
7
10
|
createCustomer(payload: any): Promise<any>;
|
|
11
|
+
makePayment(customer: Customer, paymentInfo: Payment): Promise<any>;
|
|
12
|
+
collectPayments(customer: Customer, paymentInfo: Payment): Promise<any>;
|
|
8
13
|
}
|