@tomei/finance 0.1.10 → 0.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/finance",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,15 +34,15 @@
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.10",
37
+ "@tomei/general": "^0.0.11",
38
38
  "axios": "^1.1.3",
39
39
  "class-transformer": "^0.5.1",
40
40
  "class-validator": "^0.13.2",
41
+ "cuid": "^2.1.8",
41
42
  "dotenv": "^16.0.3",
42
43
  "intuit-oauth": "^4.0.0",
43
44
  "sequelize-typescript": "^2.1.3",
44
- "uniqid": "^5.4.0",
45
- "cuid": "^2.1.8"
45
+ "uniqid": "^5.4.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@nestjs/swagger": "^6.0.4",
@@ -1,4 +1,3 @@
1
- import { RelatedObject, Owner } from '../base';
2
1
  import { ICreateAccountAttr } from './interfaces/account-attr.interface';
3
2
  import { IAccountRepository } from './interfaces/account.repository.interface';
4
3
  import * as uniqid from 'uniqid';
@@ -6,6 +5,7 @@ import { AccountModel } from './entities/account.entity';
6
5
  import axios from 'axios';
7
6
  import { getConfig } from '../config';
8
7
  import { IAccountSystem } from 'src/interfaces';
8
+ import { ObjectBase, PersonBase } from '@tomei/general';
9
9
  export class Account {
10
10
  accountRepository: IAccountRepository;
11
11
 
@@ -17,8 +17,8 @@ export class Account {
17
17
  private AccSystemId: string;
18
18
 
19
19
  ParentAccountNo: string;
20
- Owner: Owner;
21
- RelatedObject: RelatedObject;
20
+ Owner: PersonBase;
21
+ RelatedObject: ObjectBase;
22
22
  AccountType: string;
23
23
  AccountSubType: string;
24
24
  AccountingSystem: IAccountSystem;
@@ -28,12 +28,12 @@ export class Account {
28
28
  constructor(
29
29
  accountRepository: IAccountRepository,
30
30
  accountingSystem: IAccountSystem,
31
- SysCode: string,
31
+ SystemCode: string,
32
32
  params?: ICreateAccountAttr,
33
33
  ) {
34
34
  this.accountRepository = accountRepository;
35
35
  this.AccountingSystem = accountingSystem;
36
- this.AccSystemId = getConfig().systemConfig[SysCode].accountingSystem;
36
+ this.AccSystemId = getConfig().systemConfig[SystemCode].accountingSystem;
37
37
  if (params) {
38
38
  this.init(params);
39
39
  }
@@ -41,12 +41,12 @@ export class Account {
41
41
 
42
42
  init(params: ICreateAccountAttr) {
43
43
  this.Owner = params.Owner;
44
- this.OwnerId = params.Owner.Id;
44
+ this.OwnerId = params.Owner.ObjectId;
45
45
  this.OwnerType = typeof params.Owner;
46
46
 
47
47
  if (params.RelatedObject) {
48
48
  this.RelatedObject = params.RelatedObject;
49
- this.RelatedObjectId = params.RelatedObject.Id;
49
+ this.RelatedObjectId = params.RelatedObject.ObjectId;
50
50
  this.RelatedObjectType = typeof params.RelatedObject;
51
51
  }
52
52
  if (params.AccountType) this.AccountType = params.AccountType;
@@ -63,7 +63,11 @@ export class Account {
63
63
  }
64
64
  }
65
65
 
66
- async getAccountNo() {
66
+ /**
67
+ * This method will return finance_Account.AccountNo
68
+ * @returns {Promise<string>} AccountNo
69
+ */
70
+ async getAccountNo(): Promise<string> {
67
71
  if (this.AccountNo) {
68
72
  return this.AccountNo;
69
73
  } else {
@@ -85,7 +89,11 @@ export class Account {
85
89
  }
86
90
  }
87
91
 
88
- async create(userId: string) {
92
+ /**
93
+ * This method will return finance_Account.AccountNo
94
+ * @returns {Promise<string>} AccountNo
95
+ */
96
+ async create() {
89
97
  try {
90
98
  if (!this.Owner || !this.RelatedObject) {
91
99
  throw new Error(
@@ -151,9 +159,9 @@ export class Account {
151
159
  RelatedObjectId: this.RelatedObjectId,
152
160
  RelatedObjectType: this.RelatedObjectType,
153
161
  CreatedAt: new Date(),
154
- CreatedById: userId,
162
+ CreatedById: 'System',
155
163
  UpdatedAt: new Date(),
156
- UpdatedById: userId,
164
+ UpdatedById: 'System',
157
165
  });
158
166
 
159
167
  const payload = {
@@ -1,4 +1,4 @@
1
- import { Owner, RelatedObject } from 'src/base';
1
+ import { ObjectBase, PersonBase } from '@tomei/general';
2
2
 
3
3
  export interface IAccountAttr {
4
4
  AccountNo: string;
@@ -15,8 +15,8 @@ export interface IAccountAttr {
15
15
  }
16
16
 
17
17
  export interface ICreateAccountAttr {
18
- Owner: Owner;
19
- RelatedObject?: RelatedObject;
18
+ Owner: PersonBase;
19
+ RelatedObject?: ObjectBase;
20
20
  AccountType?: string;
21
21
  AccountSubType?: string;
22
22
  ParentAccountNo?: string;
@@ -1,177 +1,93 @@
1
1
  import { AddressBase, PersonBase } from '@tomei/general';
2
2
  import { IAccountSystem } from '../interfaces';
3
- import { Address } from '../base/base.address';
4
3
  import { getConfig } from '../config';
5
- import { IBaseRepository } from '@tomei/general';
6
4
  import * as cuid from 'cuid';
7
- import axios from 'axios';
8
- import { FinanceCustomerModel } from './entities/customer.entity';
9
5
 
10
- export class Customer extends PersonBase {
11
- private CustomerId: string;
6
+ export abstract class Customer extends PersonBase {
7
+ ObjectId: string; // Finance_Customer.CustomerId
8
+ ObjectName: string;
12
9
 
13
- Id: string; // Finance_Customer.CustomerId
14
- AccSystemCustomerId: string; //customer id return from accounting system
15
- CustomerRefId: string | undefined; //CRM customer CustomerId
16
- SystemCode: string;
17
- AccSystemCode: string;
10
+ private AccSystemCustomerId: string; //customer id return from accounting system
11
+ private CustomerRefId: string | undefined; //CRM customer CustomerId
12
+ private SystemCode: string;
13
+ private AccSystemCode: string;
18
14
 
19
15
  FullName: string;
20
- Name: string;
21
16
  IDNo: string;
22
17
  IDType: string;
23
18
  public Email: string;
24
19
  ContactNo: string;
25
- Address: AddressBase;
20
+ DefaultAddress: AddressBase;
26
21
 
27
- financeCustomerRepository: IBaseRepository<any>;
28
- customerRepository: IBaseRepository<any>;
29
- customerAddressRepository: any;
30
22
  accountingSystem: IAccountSystem;
31
23
 
32
24
  constructor(
33
- financeCustomerRepository: IBaseRepository<any>,
34
- customerRepository: IBaseRepository<any>,
35
- customerAddressRepository: any,
36
25
  accountingSystem: IAccountSystem,
37
26
  systemCode: string,
38
27
  email: string,
39
28
  ) {
40
29
  super();
41
- this.financeCustomerRepository = financeCustomerRepository;
42
- this.customerRepository = customerRepository;
43
- this.customerAddressRepository = customerAddressRepository;
44
30
  this.accountingSystem = accountingSystem;
45
31
  this.SystemCode = systemCode;
46
32
  this.AccSystemCode = getConfig().systemConfig[systemCode].accountingSystem;
47
33
  this.Email = email;
48
34
  }
49
35
 
50
- init(person: PersonBase) {
51
- this.FullName = person.FullName;
52
- this.IDNo = person.IDNo;
53
- this.IDType = person.IDType;
54
- this.Email = person.Email;
55
- this.ContactNo = person.ContactNo;
56
- this.Address = person.Address;
57
- }
36
+ /*
37
+ * Get the billing address for a person.
38
+ **/
39
+ abstract getBilligAddress(): Promise<AddressBase>;
58
40
 
59
- async getDetails(): Promise<any> {
60
- if (
61
- !this.FullName ||
62
- !this.IDNo ||
63
- !this.IDType ||
64
- !this.Email ||
65
- !this.ContactNo ||
66
- !this.Address
67
- ) {
68
- const customerData = await this.customerRepository.findOne({
69
- where: { Email: this.Email },
70
- });
71
- if (!customerData) {
72
- throw new Error('Customer must be created first.');
73
- }
74
-
75
- this.FullName = customerData.FullName;
76
- this.IDNo = customerData.IDNo;
77
- this.IDType = customerData.IDType;
78
- this.ContactNo = customerData.ContactNo;
79
- this.CustomerRefId = customerData.Id;
80
- this.Name = customerData.PreferredName;
81
- }
82
-
83
- return {
84
- FullName: this.FullName,
85
- IDNo: this.IDNo,
86
- IDType: this.IDType,
87
- Email: this.Email,
88
- ContactNo: this.ContactNo,
89
- Address: this.Address,
90
- CustomerRefId: this.CustomerRefId,
91
- Name: this.Name,
92
- };
41
+ get objectId() {
42
+ return this.ObjectId;
93
43
  }
94
44
 
95
- async getDefaultAddress(): Promise<any> {
96
- if (!this.CustomerRefId) {
97
- await this.getDetails();
98
- }
45
+ set objectId(value) {
46
+ this.ObjectId = value;
47
+ }
99
48
 
100
- if (
101
- !this.Address.Line1 ||
102
- !this.Address.City ||
103
- !this.Address.PostalCode ||
104
- !this.Address.Country
105
- ) {
106
- const addressData = await this.customerAddressRepository.findOne({
107
- CustomerId: this.CustomerRefId,
108
- IsDefaultYN: 'Y',
109
- });
49
+ get objectName() {
50
+ return this.ObjectName;
51
+ }
110
52
 
111
- if (!addressData) {
112
- throw new Error('Address must be created first.');
113
- }
53
+ set objectName(value) {
54
+ this.ObjectName = value;
55
+ }
114
56
 
115
- this.Address = new Address(
116
- addressData.Address,
117
- addressData.City,
118
- addressData.PostCode,
119
- addressData.Country,
120
- );
121
- }
122
- return {
123
- Line1: this.Address.Line1,
124
- City: this.Address.City,
125
- PostalCode: this.Address.PostalCode,
126
- Country: this.Address.Country,
127
- };
57
+ init(person: PersonBase) {
58
+ this.FullName = person.FullName;
59
+ this.IDNo = person.IDNo;
60
+ this.IDType = person.IDType;
61
+ this.Email = person.Email;
62
+ this.ContactNo = person.ContactNo;
63
+ this.DefaultAddress = person.DefaultAddress;
128
64
  }
129
65
 
130
- async getCustomerId(): Promise<any> {
131
- if (!this.CustomerId) {
66
+ /**
67
+ *
68
+ * @returns {string} - Return Finance CustomerId
69
+ */
70
+ getCustomerId(): string {
71
+ if (!this.ObjectId) {
132
72
  throw new Error('Finance Customer must be created first.');
133
73
  }
134
- return this.CustomerId;
74
+ return this.ObjectId;
135
75
  }
136
76
 
77
+ /**
78
+ * Create customer in accounting system
79
+ *
80
+ */
137
81
  async create() {
138
82
  try {
139
- await this.getDetails();
140
- await this.getDefaultAddress();
141
-
142
83
  this.AccSystemCustomerId = await this.accountingSystem.createCustomer({
143
84
  FullName: this.FullName,
144
85
  Email: this.Email,
145
86
  ContractNo: this.ContactNo,
146
- Address: this.Address,
87
+ DefaultAddress: this.DefaultAddress,
147
88
  });
148
89
 
149
- this.Id = cuid();
150
-
151
- const customerData = await this.financeCustomerRepository.create({
152
- CustomerId: this.Id,
153
- SystemCode: this.SystemCode,
154
- AccSystemCode: this.AccSystemCode,
155
- AccSystemCustomerId: this.AccSystemCustomerId,
156
- CustomerRefId: this.CustomerRefId,
157
- });
158
-
159
- const payload = {
160
- Action: 'Create',
161
- Activity: 'Account Created',
162
- Description: `Customer (ID: ${this.Id}) has been created`,
163
- EntityType: typeof FinanceCustomerModel,
164
- EntityValueBefore: JSON.stringify({}),
165
- EntityValueAfter: JSON.stringify(customerData),
166
- PerformedById: this.SystemCode,
167
- PerformedAt: new Date(),
168
- EntityId: this.Id,
169
- };
170
-
171
- await axios.post(
172
- `${process.env.COMMON_API_URL}/activity-histories`,
173
- payload,
174
- );
90
+ this.ObjectId = cuid();
175
91
  } catch (error) {
176
92
  throw error;
177
93
  }
package/src/index.ts CHANGED
@@ -1,7 +1,5 @@
1
- export * from './base';
2
1
  export * from './account';
3
2
  export * from './customer';
4
- export * from './quickbook-client';
5
3
  export * from './enum';
6
4
  export * from './interfaces';
7
5
  export * from './payment';
@@ -11,8 +11,8 @@ import { PaymentModel } from './entities/payment.entity';
11
11
  import axios from 'axios';
12
12
  import { IPaymentParams } from './interfaces/payment-params.interface';
13
13
  export class Payment extends ObjectBase {
14
- Id: string;
15
- Name: string;
14
+ ObjectId: string;
15
+ ObjectName: string;
16
16
 
17
17
  private Amount: number;
18
18
  private Currency: string;
@@ -71,6 +71,13 @@ export class Payment extends ObjectBase {
71
71
  }
72
72
  }
73
73
 
74
+ get objectId(): string {
75
+ return this.ObjectId;
76
+ }
77
+ get objectName(): string {
78
+ return this.ObjectName;
79
+ }
80
+
74
81
  init(Params: IPaymentParams): void {
75
82
  if (Params.Currency) this.Currency = Params.Currency;
76
83
  if (Params.Method) this.Method = Params.Method;
@@ -138,11 +145,14 @@ export class Payment extends ObjectBase {
138
145
  this.ReceivableAccountNo = await this.ReceivableAccount.getAccountNo();
139
146
  this.DepositAccountNo = await this.DepositAccount.getAccountNo();
140
147
 
141
- this.Id = await this.AccountingSystem.makePayment(this.Customer, this);
148
+ this.ObjectId = await this.AccountingSystem.makePayment(
149
+ this.Customer,
150
+ this,
151
+ );
142
152
 
143
153
  this.Status = 'Successfull';
144
154
  const paymentAttribute: IPaymentAttr = {
145
- PaymentId: this.Id,
155
+ PaymentId: this.ObjectId,
146
156
  AccountNo: this.DepositAccountNo,
147
157
  PaymentType: this.PaymentType,
148
158
  PaymentDate: new Date(),
@@ -161,8 +171,8 @@ export class Payment extends ObjectBase {
161
171
  const paymentItemsData = [];
162
172
  this.PaymentItems.forEach(async (paymentItem) => {
163
173
  paymentItemsData.push({
164
- PaymentId: this.Id,
165
- PayForObjectId: paymentItem.Id,
174
+ PaymentId: this.ObjectId,
175
+ PayForObjectId: paymentItem.ObjectId,
166
176
  PayForObjectType: paymentItem.Type,
167
177
  Amount: paymentItem.Amount,
168
178
  Currency: paymentItem.Currency,
@@ -176,13 +186,13 @@ export class Payment extends ObjectBase {
176
186
  const payload = {
177
187
  Action: 'Create',
178
188
  Activity: 'Payment Created',
179
- Description: `Account (ID: ${this.Id}) has been created`,
189
+ Description: `Account (ID: ${this.ObjectId}) has been created`,
180
190
  EntityType: typeof PaymentModel,
181
191
  EntityValueBefore: JSON.stringify({}),
182
192
  EntityValueAfter: JSON.stringify(payment),
183
193
  PerformedById: payment.UpdatedBy,
184
194
  PerformedAt: payment.UpdatedAt,
185
- EntityId: this.Id,
195
+ EntityId: this.ObjectId,
186
196
  };
187
197
 
188
198
  await axios.post(
@@ -1,21 +0,0 @@
1
- import { AddressBase } from '@tomei/general';
2
-
3
- export class Address extends AddressBase {
4
- Line1: string;
5
- City: string;
6
- PostalCode: string;
7
- Country: string;
8
-
9
- constructor(
10
- line1: string,
11
- city: string,
12
- postalCode: string,
13
- country: string,
14
- ) {
15
- super();
16
- this.Line1 = line1;
17
- this.City = city;
18
- this.PostalCode = postalCode;
19
- this.Country = country;
20
- }
21
- }
@@ -1,14 +0,0 @@
1
- import { ObjectBase } from '@tomei/general';
2
-
3
- export class RelatedObject extends ObjectBase {
4
- Id: string;
5
- Name: string;
6
- Type: string;
7
-
8
- constructor(id: string, name: string) {
9
- super();
10
- this.Id = id;
11
- this.Name = name;
12
- this.Type = 'RelatedObject';
13
- }
14
- }
@@ -1,59 +0,0 @@
1
- import { PersonBase, AddressBase } from '@tomei/general';
2
-
3
- export class Owner extends PersonBase {
4
- FullName: string;
5
- IDNo: string;
6
- IDType: string;
7
- Email: string;
8
- ContactNo: string;
9
- Address: AddressBase;
10
- Id: string;
11
- Name: string;
12
-
13
- constructor(
14
- fullName: string,
15
- idNo: string,
16
- idType: string,
17
- email: string,
18
- contactNo: string,
19
- address: AddressBase,
20
- id: string,
21
- name: string,
22
- ) {
23
- super();
24
- this.FullName = fullName;
25
- this.IDNo = idNo;
26
- this.IDType = idType;
27
- this.Email = email;
28
- this.ContactNo = contactNo;
29
- this.Address = address;
30
- this.Id = id;
31
- this.Name = name;
32
- }
33
-
34
- getDetails(): {
35
- FullName: string;
36
- IDNo: string;
37
- IDType: string;
38
- Email: string;
39
- ContactNo: string;
40
- Address: AddressBase;
41
- Id: string;
42
- Name: string;
43
- } {
44
- return {
45
- FullName: this.FullName,
46
- IDNo: this.IDNo,
47
- IDType: this.IDType,
48
- Email: this.Email,
49
- ContactNo: this.ContactNo,
50
- Address: this.Address,
51
- Id: this.Id,
52
- Name: this.Name,
53
- };
54
- }
55
-
56
- getDefaultAddress() {
57
- return this.Address;
58
- }
59
- }
package/src/base/index.ts DELETED
@@ -1,4 +0,0 @@
1
- import { RelatedObject } from './base.object';
2
- import { Owner } from './base.owner';
3
- import { Address } from './base.address';
4
- export { RelatedObject, Owner, Address };