@tomei/finance 0.2.5 → 0.2.7
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 +7 -3
- package/dist/account/account.js +6 -6
- package/dist/account/account.js.map +1 -1
- package/dist/account/entities/account.entity.d.ts +1 -1
- package/dist/account/entities/account.entity.js +1 -1
- package/dist/account/entities/account.entity.js.map +1 -1
- package/dist/customer/customer.d.ts +12 -12
- package/dist/customer/customer.js +29 -26
- package/dist/customer/customer.js.map +1 -1
- package/dist/customer/finance-customer.repository.d.ts +5 -3
- package/dist/customer/finance-customer.repository.js +9 -4
- package/dist/customer/finance-customer.repository.js.map +1 -1
- package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +3 -3
- package/dist/document/document.d.ts +8 -4
- package/dist/document/document.js +5 -1
- package/dist/document/document.js.map +1 -1
- package/dist/document/interfaces/document-attr.interface.d.ts +1 -1
- package/dist/finance-company/finance-company.d.ts +4 -1
- package/dist/finance-company/finance-company.js +41 -1
- package/dist/finance-company/finance-company.js.map +1 -1
- package/dist/journal-entry/entities/journal-entry.entity.d.ts +1 -1
- package/dist/journal-entry/entities/journal-entry.entity.js +1 -1
- package/dist/journal-entry/entities/journal-entry.entity.js.map +1 -1
- package/dist/journal-entry/journal-entry.d.ts +5 -1
- package/dist/journal-entry/journal-entry.js +1 -0
- package/dist/journal-entry/journal-entry.js.map +1 -1
- package/dist/payment/payment.d.ts +7 -1
- package/dist/payment/payment.js +1 -0
- package/dist/payment/payment.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/finance-account-migration.js +1 -1
- package/migrations/finance-journal-entry-migration.js +1 -1
- package/package.json +1 -1
- package/src/account/account.ts +12 -8
- package/src/account/entities/account.entity.ts +1 -1
- package/src/customer/customer.ts +49 -48
- package/src/customer/finance-customer.repository.ts +12 -4
- package/src/customer/interfaces/finance-customer.repository.interface.ts +4 -3
- package/src/document/document.ts +8 -4
- package/src/document/interfaces/document-attr.interface.ts +1 -1
- package/src/finance-company/finance-company.ts +68 -2
- package/src/journal-entry/entities/journal-entry.entity.ts +1 -1
- package/src/journal-entry/journal-entry.ts +6 -2
- package/src/payment/payment.ts +8 -1
package/package.json
CHANGED
package/src/account/account.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
|
2
2
|
import { AccountModel } from './entities/account.entity';
|
|
3
3
|
import { ObjectBase, PersonBase, RecordNotFoundError } from '@tomei/general';
|
|
4
4
|
import { IBaseRepository } from '@tomei/general/dist/interfaces/repository.base.interface';
|
|
5
|
-
|
|
5
|
+
import { IAccountSystemEntity } from 'src/interfaces/account-system-entity.interface';
|
|
6
|
+
export class Account implements IAccountSystemEntity {
|
|
6
7
|
accountRepository: IAccountRepository;
|
|
7
8
|
AccountNo: string;
|
|
8
9
|
Owner: PersonBase;
|
|
@@ -14,7 +15,7 @@ export class Account {
|
|
|
14
15
|
private RelatedObjectId: string;
|
|
15
16
|
private RelatedObjectType: string;
|
|
16
17
|
private ParentAccountNo: string;
|
|
17
|
-
|
|
18
|
+
AccSystemRefId: string;
|
|
18
19
|
|
|
19
20
|
SystemCode: string;
|
|
20
21
|
AccSystemCode: string;
|
|
@@ -22,6 +23,9 @@ export class Account {
|
|
|
22
23
|
Description: string;
|
|
23
24
|
AccountType: string;
|
|
24
25
|
AccountSubtype: string;
|
|
26
|
+
PostedToAccSystemYN: 'N';
|
|
27
|
+
PostedById: string;
|
|
28
|
+
PostedDateTime: Date;
|
|
25
29
|
|
|
26
30
|
CreatedAt: Date;
|
|
27
31
|
CreatedById: string;
|
|
@@ -41,7 +45,7 @@ export class Account {
|
|
|
41
45
|
this.ParentAccountNo = accountData.ParentAccountNo;
|
|
42
46
|
this.SystemCode = accountData.SystemCode;
|
|
43
47
|
this.AccSystemCode = accountData.AccSystemCode;
|
|
44
|
-
this.
|
|
48
|
+
this.AccSystemRefId = accountData.AccSystemRefId;
|
|
45
49
|
this.Name = accountData.Name;
|
|
46
50
|
this.Description = accountData.Description;
|
|
47
51
|
this.AccountType = accountData.AccountType;
|
|
@@ -83,7 +87,7 @@ export class Account {
|
|
|
83
87
|
if (!this.AccSystemCode) {
|
|
84
88
|
throw new Error('AccSystemCode is required.');
|
|
85
89
|
}
|
|
86
|
-
if (!this.
|
|
90
|
+
if (!this.AccSystemRefId) {
|
|
87
91
|
throw new Error('AccSystemAccountId is required.');
|
|
88
92
|
}
|
|
89
93
|
if (!this.AccountType) {
|
|
@@ -97,17 +101,17 @@ export class Account {
|
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
async save(
|
|
100
|
-
|
|
104
|
+
AccSystemRefId: string,
|
|
101
105
|
userId: string,
|
|
102
106
|
dbTransaction?: any,
|
|
103
107
|
): Promise<AccountModel> {
|
|
104
|
-
this.
|
|
108
|
+
this.AccSystemRefId = AccSystemRefId;
|
|
105
109
|
const data = await this.accountRepository.create(
|
|
106
110
|
{
|
|
107
111
|
AccountNo: this.AccountNo,
|
|
108
112
|
SystemCode: this.SystemCode,
|
|
109
113
|
AccSystemCode: this.AccSystemCode,
|
|
110
|
-
|
|
114
|
+
AccSystemRefId: this.AccSystemRefId,
|
|
111
115
|
Name: this.Name,
|
|
112
116
|
Description: this.Description,
|
|
113
117
|
AccountType: this.AccountType,
|
|
@@ -135,7 +139,7 @@ export class Account {
|
|
|
135
139
|
try {
|
|
136
140
|
const account = await this.accountRepository.findOne({
|
|
137
141
|
OwnerId: this.OwnerId,
|
|
138
|
-
|
|
142
|
+
AccSystemRefId: this.AccSystemRefId,
|
|
139
143
|
});
|
|
140
144
|
|
|
141
145
|
if (account) {
|
package/src/customer/customer.ts
CHANGED
|
@@ -1,36 +1,50 @@
|
|
|
1
|
-
import { AddressBase, PersonBase } from '@tomei/general';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import * as cuid from 'cuid';
|
|
1
|
+
import { AddressBase, PersonBase, RecordNotFoundError } from '@tomei/general';
|
|
2
|
+
import { FinanceCustomerModel } from './entities/customer.entity';
|
|
3
|
+
import { IFinanceCustomerRepository } from './interfaces/finance-customer.repository.interface';
|
|
5
4
|
|
|
6
5
|
export abstract class Customer extends PersonBase {
|
|
7
|
-
ObjectId: string; // Finance_Customer.CustomerId
|
|
8
|
-
ObjectName: string;
|
|
9
|
-
|
|
10
|
-
AccSystemCustomerId: string; //customer id return from accounting system
|
|
11
|
-
CustomerRefId: string | undefined; //CRM customer CustomerId
|
|
12
|
-
SystemCode: string;
|
|
13
|
-
AccSystemCode: string;
|
|
14
|
-
|
|
15
6
|
FullName: string;
|
|
16
7
|
IDNo: string;
|
|
17
8
|
IDType: string;
|
|
18
|
-
public Email: string;
|
|
19
9
|
ContactNo: string;
|
|
10
|
+
Email: string;
|
|
20
11
|
DefaultAddress: AddressBase;
|
|
21
12
|
|
|
22
|
-
|
|
13
|
+
financeCustomerRepository: IFinanceCustomerRepository;
|
|
14
|
+
|
|
15
|
+
CustomerId: string;
|
|
16
|
+
|
|
17
|
+
SystemCode: string;
|
|
18
|
+
AccSystemCode: string;
|
|
19
|
+
AccSystemCustomerId: string; //customer id return from accounting system
|
|
20
|
+
CustSystemCode: string;
|
|
21
|
+
CustSystemRefId: string;
|
|
23
22
|
|
|
24
23
|
constructor(
|
|
25
|
-
accountingSystem: IAccountSystem,
|
|
26
24
|
systemCode: string,
|
|
27
|
-
|
|
25
|
+
accSystemCode: string,
|
|
26
|
+
custSystemCode: string,
|
|
27
|
+
custSystemRefId: string,
|
|
28
28
|
) {
|
|
29
29
|
super();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const financeCustomerData = this.financeCustomerRepository.findOne({
|
|
31
|
+
where: {
|
|
32
|
+
SystemCode: systemCode,
|
|
33
|
+
AccSystemCode: accSystemCode,
|
|
34
|
+
AccSystemCustomerId: custSystemCode,
|
|
35
|
+
CustomerRefId: custSystemRefId,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
if (financeCustomerData) {
|
|
39
|
+
this.CustomerId = financeCustomerData.CustomerId;
|
|
40
|
+
this.AccSystemCode = accSystemCode;
|
|
41
|
+
this.AccSystemCustomerId = financeCustomerData.AccSystemCustomerId;
|
|
42
|
+
this.CustSystemCode = custSystemCode;
|
|
43
|
+
this.CustSystemRefId = custSystemRefId;
|
|
44
|
+
} else {
|
|
45
|
+
const notFoundError = new RecordNotFoundError('No Record Found');
|
|
46
|
+
throw notFoundError;
|
|
47
|
+
}
|
|
34
48
|
}
|
|
35
49
|
|
|
36
50
|
/*
|
|
@@ -63,33 +77,20 @@ export abstract class Customer extends PersonBase {
|
|
|
63
77
|
this.DefaultAddress = person.DefaultAddress;
|
|
64
78
|
}
|
|
65
79
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
async create() {
|
|
82
|
-
try {
|
|
83
|
-
this.AccSystemCustomerId = await this.accountingSystem.createCustomer({
|
|
84
|
-
FullName: this.FullName,
|
|
85
|
-
Email: this.Email,
|
|
86
|
-
ContractNo: this.ContactNo,
|
|
87
|
-
DefaultAddress: this.DefaultAddress,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
this.ObjectId = cuid();
|
|
91
|
-
} catch (error) {
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
80
|
+
async save(
|
|
81
|
+
customerId: string,
|
|
82
|
+
dbTransaction?: any,
|
|
83
|
+
): Promise<FinanceCustomerModel> {
|
|
84
|
+
const data = await this.financeCustomerRepository.create(
|
|
85
|
+
{
|
|
86
|
+
CustomerId: customerId,
|
|
87
|
+
SystemCode: this.SystemCode,
|
|
88
|
+
AccSystemCode: this.SystemCode,
|
|
89
|
+
AccSystemCustomerId: this.AccSystemCustomerId,
|
|
90
|
+
CustomerRefId: this.CustSystemRefId,
|
|
91
|
+
},
|
|
92
|
+
dbTransaction,
|
|
93
|
+
);
|
|
94
|
+
return data;
|
|
94
95
|
}
|
|
95
96
|
}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { InjectModel } from '@nestjs/sequelize';
|
|
2
|
+
import { BaseRepository } from '@tomei/general';
|
|
2
3
|
import { FinanceCustomerModel } from './entities/customer.entity';
|
|
3
4
|
import { IFinanceCustomerAttr } from './interfaces/finance-customer-attr.interface';
|
|
4
5
|
import { IFinanceCustomerRepository } from './interfaces/finance-customer.repository.interface';
|
|
5
6
|
|
|
6
7
|
export class FinanceCustomerRepository
|
|
7
|
-
|
|
8
|
+
extends BaseRepository<FinanceCustomerModel>
|
|
9
|
+
implements IFinanceCustomerRepository
|
|
8
10
|
{
|
|
9
11
|
constructor(
|
|
10
12
|
@InjectModel(FinanceCustomerModel)
|
|
11
|
-
private readonly
|
|
12
|
-
) {
|
|
13
|
+
private readonly financeCustomerModel: typeof FinanceCustomerModel,
|
|
14
|
+
) {
|
|
15
|
+
super(financeCustomerModel);
|
|
16
|
+
}
|
|
13
17
|
|
|
14
18
|
create(
|
|
15
19
|
data: IFinanceCustomerAttr | any,
|
|
16
20
|
options?: any,
|
|
17
21
|
): Promise<FinanceCustomerModel> | any {
|
|
18
|
-
return this.
|
|
22
|
+
return this.financeCustomerModel.create(data, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
findOne(options: any): Promise<FinanceCustomerModel> {
|
|
26
|
+
return this.financeCustomerModel.findOne(options);
|
|
19
27
|
}
|
|
20
28
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { IBaseRepository } from '@tomei/general';
|
|
2
|
+
import { FinanceCustomerModel } from '../entities/customer.entity';
|
|
3
|
+
|
|
4
|
+
export type IFinanceCustomerRepository = IBaseRepository<FinanceCustomerModel>;
|
package/src/document/document.ts
CHANGED
|
@@ -11,8 +11,9 @@ import {
|
|
|
11
11
|
import { DocumentStatus, DocType } from 'src/enum';
|
|
12
12
|
import { DocumentRepository } from './document.repository';
|
|
13
13
|
import { IDocumentAttr } from './interfaces/document-attr.interface';
|
|
14
|
+
import { IAccountSystemEntity } from 'src/interfaces/account-system-entity.interface';
|
|
14
15
|
|
|
15
|
-
export class Document extends ObjectBase {
|
|
16
|
+
export class Document extends ObjectBase implements IAccountSystemEntity {
|
|
16
17
|
ObjectId: string;
|
|
17
18
|
ObjectName: string;
|
|
18
19
|
|
|
@@ -23,15 +24,18 @@ export class Document extends ObjectBase {
|
|
|
23
24
|
Currency: string;
|
|
24
25
|
Amount: number;
|
|
25
26
|
Description: string;
|
|
26
|
-
Status: DocumentStatus;
|
|
27
27
|
IssuedById: string;
|
|
28
28
|
IssuedToId: string;
|
|
29
29
|
IssuedToType: string;
|
|
30
30
|
AccSystemCode: string;
|
|
31
|
-
|
|
31
|
+
PostedToAccSystemYN = 'N';
|
|
32
|
+
PostedById: string;
|
|
33
|
+
PostedDateTime: Date;
|
|
34
|
+
AccSystemRefId: string;
|
|
32
35
|
UseAccSystemDocYN: string;
|
|
33
36
|
private DocHTMLFilePath: string;
|
|
34
37
|
private DocPDFFilePath: string;
|
|
38
|
+
private Status: DocumentStatus;
|
|
35
39
|
|
|
36
40
|
documentRepository: DocumentRepository;
|
|
37
41
|
mediaRepository: IMediasRepository;
|
|
@@ -103,7 +107,7 @@ export class Document extends ObjectBase {
|
|
|
103
107
|
this.IssuedToId = params.IssuedToId;
|
|
104
108
|
this.IssuedToType = params.IssuedToType;
|
|
105
109
|
this.AccSystemCode = params.AccSystemCode;
|
|
106
|
-
this.
|
|
110
|
+
this.PostedToAccSystemYN = params.PostedToAccSystemYN;
|
|
107
111
|
this.UseAccSystemDocYN = params.UseAccSystemDocYN;
|
|
108
112
|
this.DocPDFFilePath = params.DocPDFFilePath;
|
|
109
113
|
this.DocHTMLFilePath = params.DocHTMLFilePath;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { CompanyBase, PersonBase } from '@tomei/general';
|
|
1
3
|
import { BadRequestException } from '@nestjs/common';
|
|
2
4
|
import { IAccountSystem } from 'src/interfaces';
|
|
3
5
|
import { JournalEntry, JournalEntryRepository } from 'src/journal-entry';
|
|
4
6
|
import { LedgerTransactionRepository } from 'src/ledger-transaction';
|
|
5
|
-
import axios from 'axios';
|
|
6
7
|
import { Account } from 'src/account';
|
|
7
|
-
import {
|
|
8
|
+
import { Customer, FinanceCustomerRepository } from 'src/customer';
|
|
8
9
|
|
|
9
10
|
export class FinanceCompany {
|
|
10
11
|
journalEntryRepository: JournalEntryRepository;
|
|
12
|
+
financeCustomerRepository: FinanceCustomerRepository;
|
|
11
13
|
ledgerTransactionRepository: LedgerTransactionRepository;
|
|
12
14
|
accountingSystem: IAccountSystem;
|
|
13
15
|
|
|
@@ -37,6 +39,70 @@ export class FinanceCompany {
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
async createCustomer(
|
|
43
|
+
dbTransaction: any,
|
|
44
|
+
custSystemCode: string,
|
|
45
|
+
custSystemRefId: string,
|
|
46
|
+
customer: Customer,
|
|
47
|
+
) {
|
|
48
|
+
try {
|
|
49
|
+
if (customer.CustSystemCode || customer.CustSystemRefId) {
|
|
50
|
+
throw new BadRequestException(
|
|
51
|
+
'CustSystemCode and CustomerRefId are required fields.',
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const financeCustomerData = await this.financeCustomerRepository.findOne({
|
|
56
|
+
where: {
|
|
57
|
+
SystemCode: this.SystemCode,
|
|
58
|
+
AccSystemCode: this.AccSystemCode,
|
|
59
|
+
AccSystemCustomerId: custSystemCode,
|
|
60
|
+
CustomerRefId: custSystemRefId,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (financeCustomerData) {
|
|
65
|
+
throw new BadRequestException('Customer already created previously.');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const customerData = await customer.getDetails();
|
|
69
|
+
|
|
70
|
+
if (!customerData.FullName) {
|
|
71
|
+
throw new BadRequestException(
|
|
72
|
+
'FullName is required to be retrieved from GetDetails().',
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Retrieve the type of accounting system, API Key, and API secret based on SysCode from the Config.ts
|
|
77
|
+
const customerId = await this.accountingSystem.createCustomer(
|
|
78
|
+
customerData,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const newCustomer = await customer.save(customerId, dbTransaction);
|
|
82
|
+
|
|
83
|
+
const payload = {
|
|
84
|
+
Action: 'Create',
|
|
85
|
+
Activity: 'Finance Customer Created',
|
|
86
|
+
Description: `Customer (ID: ${newCustomer.CustomerId}) has been created for ${this.AccSystemCode}`,
|
|
87
|
+
EntityType: 'finance_Customer',
|
|
88
|
+
EntityValueBefore: JSON.stringify({}),
|
|
89
|
+
EntityValueAfter: JSON.stringify(newCustomer),
|
|
90
|
+
PerformedById: 'test',
|
|
91
|
+
PerformedAt: new Date(),
|
|
92
|
+
EntityId: newCustomer.CustomerId,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
await axios.post(
|
|
96
|
+
`${process.env.COMMON_API_URL}/activity-histories`,
|
|
97
|
+
payload,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return customer;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
40
106
|
async postJournal(dbTransaction: any, journalEntry: JournalEntry) {
|
|
41
107
|
try {
|
|
42
108
|
if (
|
|
@@ -6,15 +6,19 @@ import { IJournalEntryAttr } from './interfaces/journal-entry-attr.interface';
|
|
|
6
6
|
import { TransactionTypeOptions } from 'src/enum';
|
|
7
7
|
import { Op } from 'sequelize';
|
|
8
8
|
import { JournalEntryModel } from './entities/journal-entry.entity';
|
|
9
|
+
import { IAccountSystemEntity } from 'src/interfaces/account-system-entity.interface';
|
|
9
10
|
|
|
10
|
-
export class JournalEntry {
|
|
11
|
+
export class JournalEntry implements IAccountSystemEntity {
|
|
11
12
|
JournalEntryId: string;
|
|
12
13
|
Date: Date;
|
|
13
14
|
Name: string;
|
|
14
15
|
Description: string;
|
|
15
16
|
PostedById: string;
|
|
16
|
-
PostedToAccSystemYN
|
|
17
|
+
PostedToAccSystemYN = 'N';
|
|
17
18
|
DatePosted?: string;
|
|
19
|
+
AccSystemCode: string;
|
|
20
|
+
AccSystemRefId: string;
|
|
21
|
+
PostedDateTime: Date;
|
|
18
22
|
|
|
19
23
|
journalEntryRepository: JournalEntryRepository;
|
|
20
24
|
ledgerTransactionRepository: LedgerTransactionRepository;
|
package/src/payment/payment.ts
CHANGED
|
@@ -10,7 +10,8 @@ import { IPaymentAttr } from './interfaces/payment-attr.interface';
|
|
|
10
10
|
import { PaymentModel } from './entities/payment.entity';
|
|
11
11
|
import axios from 'axios';
|
|
12
12
|
import { IPaymentParams } from './interfaces/payment-params.interface';
|
|
13
|
-
|
|
13
|
+
import { IAccountSystemEntity } from 'src/interfaces/account-system-entity.interface';
|
|
14
|
+
export class Payment extends ObjectBase implements IAccountSystemEntity {
|
|
14
15
|
ObjectId: string;
|
|
15
16
|
ObjectName: string;
|
|
16
17
|
|
|
@@ -44,6 +45,12 @@ export class Payment extends ObjectBase {
|
|
|
44
45
|
private PaymentItemRepository: IPaymentItemRepository;
|
|
45
46
|
private sequelize: Sequelize;
|
|
46
47
|
|
|
48
|
+
AccSystemCode: string;
|
|
49
|
+
PostedToAccSystemYN = 'N';
|
|
50
|
+
AccSystemRefId: string;
|
|
51
|
+
PostedById: string;
|
|
52
|
+
PostedDateTime: Date;
|
|
53
|
+
|
|
47
54
|
constructor(
|
|
48
55
|
AccountingSystem: IAccountSystem,
|
|
49
56
|
PaymentRepository: IPaymentRepository,
|