@tomei/finance 0.1.1 → 0.1.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 +2 -1
- package/dist/account/account.js +1 -1
- package/dist/account/account.js.map +1 -1
- package/dist/base/base.address.d.ts +8 -0
- package/dist/base/base.address.js +15 -0
- package/dist/base/base.address.js.map +1 -0
- package/dist/base/base.object.d.ts +7 -0
- package/dist/base/base.object.js +14 -0
- package/dist/base/base.object.js.map +1 -0
- package/dist/base/base.owner.d.ts +23 -0
- package/dist/base/base.owner.js +34 -0
- package/dist/base/base.owner.js.map +1 -0
- package/dist/base/index.d.ts +4 -4
- package/dist/base/index.js +5 -3
- package/dist/base/index.js.map +1 -1
- package/dist/customer/customer.d.ts +27 -0
- package/dist/customer/customer.js +104 -0
- package/dist/customer/customer.js.map +1 -0
- package/dist/customer/customer.repository.d.ts +0 -0
- package/dist/customer/customer.repository.js +1 -0
- package/dist/customer/customer.repository.js.map +1 -0
- package/dist/customer/entities/customer.entity.d.ts +5 -0
- package/dist/customer/entities/customer.entity.js +41 -0
- package/dist/customer/entities/customer.entity.js.map +1 -0
- package/dist/customer/finance-customer.repository.d.ts +8 -0
- package/dist/customer/finance-customer.repository.js +31 -0
- package/dist/customer/finance-customer.repository.js.map +1 -0
- package/dist/customer/index.d.ts +7 -0
- package/dist/customer/index.js +10 -0
- package/dist/customer/index.js.map +1 -0
- package/dist/customer/interfaces/customer.repository.interface.d.ts +3 -0
- package/dist/customer/interfaces/customer.repository.interface.js +3 -0
- package/dist/customer/interfaces/customer.repository.interface.js.map +1 -0
- package/dist/customer/interfaces/finance-customer-attr.interface.d.ts +4 -0
- package/dist/customer/interfaces/finance-customer-attr.interface.js +3 -0
- package/dist/customer/interfaces/finance-customer-attr.interface.js.map +1 -0
- package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +3 -0
- package/dist/customer/interfaces/finance-customer.repository.interface.js +3 -0
- package/dist/customer/interfaces/finance-customer.repository.interface.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/account-system.interface.d.ts +8 -0
- package/dist/interfaces/account-system.interface.js +3 -0
- package/dist/interfaces/account-system.interface.js.map +1 -0
- package/dist/interfaces/customer.repository.interface.d.ts +3 -0
- package/dist/interfaces/customer.repository.interface.js +3 -0
- package/dist/interfaces/customer.repository.interface.js.map +1 -0
- package/dist/interfaces/finance-customer.repository.interface.d.ts +3 -0
- package/dist/interfaces/finance-customer.repository.interface.js +3 -0
- package/dist/interfaces/finance-customer.repository.interface.js.map +1 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/systemConfig.interface.d.ts +0 -0
- package/dist/interfaces/systemConfig.interface.js +1 -0
- package/dist/interfaces/systemConfig.interface.js.map +1 -0
- package/dist/quickbook-client/client.d.ts +4 -2
- package/dist/quickbook-client/client.js +33 -0
- package/dist/quickbook-client/client.js.map +1 -1
- package/dist/quickbook-client/index.d.ts +2 -1
- package/dist/quickbook-client/interfaces/quickbook-client-create-customer-options.interface.d.ts +7 -0
- package/dist/quickbook-client/interfaces/quickbook-client-create-customer-options.interface.js +3 -0
- package/dist/quickbook-client/interfaces/quickbook-client-create-customer-options.interface.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/finance-customer-migration.js +21 -0
- package/package.json +2 -2
- package/src/account/account.ts +3 -2
- package/src/base/base.address.ts +21 -0
- package/src/base/{object/base.object.ts → base.object.ts} +0 -0
- package/src/base/{owner/base.owner.ts → base.owner.ts} +4 -0
- package/src/base/index.ts +4 -5
- package/src/customer/customer.ts +146 -0
- package/src/customer/entities/customer.entity.ts +23 -0
- package/src/customer/finance-customer.repository.ts +20 -0
- package/src/customer/index.ts +15 -0
- package/src/customer/interfaces/customer.repository.interface.ts +3 -0
- package/src/customer/interfaces/finance-customer-attr.interface.ts +4 -0
- package/src/customer/interfaces/finance-customer.repository.interface.ts +3 -0
- package/src/index.ts +2 -0
- package/src/{base → interfaces}/account-system.interface.ts +1 -0
- package/src/interfaces/index.ts +3 -0
- package/src/quickbook-client/client.ts +38 -2
- package/src/quickbook-client/index.ts +2 -1
- package/src/quickbook-client/interfaces/quickbook-client-create-customer-options.interface.ts +8 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable('finance_Customer', {
|
|
6
|
+
CustomerId: {
|
|
7
|
+
type: Sequelize.STRING(30),
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
allowNull: false,
|
|
10
|
+
},
|
|
11
|
+
AccSystemId: {
|
|
12
|
+
type: Sequelize.STRING(30),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
async down(queryInterface) {
|
|
19
|
+
await queryInterface.dropTable('finance_Customer');
|
|
20
|
+
},
|
|
21
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomei/finance",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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.7"
|
|
74
74
|
}
|
|
75
75
|
}
|
package/src/account/account.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RelatedObject, Owner } from '../base';
|
|
2
2
|
import { ICreateAccountAttr } from './interfaces/account-attr.interface';
|
|
3
3
|
import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
4
4
|
import * as uniqid from 'uniqid';
|
|
5
5
|
import { AccountModel } from './entities/account.entity';
|
|
6
6
|
import axios from 'axios';
|
|
7
|
-
import { getConfig } from '
|
|
7
|
+
import { getConfig } from '../config';
|
|
8
|
+
import { IAccountSystem } from 'src/interfaces';
|
|
8
9
|
export class Account {
|
|
9
10
|
accountRepository: IAccountRepository;
|
|
10
11
|
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
File without changes
|
package/src/base/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export { IAccountSystem, RelatedObject, Owner };
|
|
1
|
+
import { RelatedObject } from './base.object';
|
|
2
|
+
import { Owner } from './base.owner';
|
|
3
|
+
import { Address } from './base.address';
|
|
4
|
+
export { RelatedObject, Owner, Address };
|
|
@@ -0,0 +1,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
|
+
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
|
+
client: IAccountSystem;
|
|
25
|
+
person: PersonBase;
|
|
26
|
+
systemCode: string;
|
|
27
|
+
constructor(
|
|
28
|
+
financeCustomerRepository: FinanceCustomerRepository,
|
|
29
|
+
customerRepository: ICustomerRepository<any>,
|
|
30
|
+
customerAddressRepository: any,
|
|
31
|
+
client: IAccountSystem,
|
|
32
|
+
systemCode: string,
|
|
33
|
+
person?: PersonBase,
|
|
34
|
+
) {
|
|
35
|
+
super();
|
|
36
|
+
this.financeCustomerRepository = financeCustomerRepository;
|
|
37
|
+
this.customerRepository = customerRepository;
|
|
38
|
+
this.customerAddressRepository = customerAddressRepository;
|
|
39
|
+
this.client = client;
|
|
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 create() {
|
|
124
|
+
try {
|
|
125
|
+
await this.getDetails();
|
|
126
|
+
await this.getDefaultAddress();
|
|
127
|
+
|
|
128
|
+
const customerData = await this.client.createCustomer({
|
|
129
|
+
FullName: this.FullName,
|
|
130
|
+
Email: this.Email,
|
|
131
|
+
ContractNo: this.ContactNo,
|
|
132
|
+
Address: this.Address,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
this.AccSystemId =
|
|
136
|
+
getConfig().systemConfig[this.systemCode].accountingSystem;
|
|
137
|
+
this.CustomerId = customerData.Id;
|
|
138
|
+
return await this.financeCustomerRepository.create({
|
|
139
|
+
CustomerId: customerData.Id,
|
|
140
|
+
AccSystemId: this.AccSystemId,
|
|
141
|
+
});
|
|
142
|
+
} catch (error) {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
import { Column, DataType, Model, Table } from 'sequelize-typescript';
|
|
3
|
+
|
|
4
|
+
@Table({ tableName: 'finance_Customer', createdAt: false, updatedAt: false })
|
|
5
|
+
export class FinanceCustomerModel extends Model {
|
|
6
|
+
@ApiProperty({ type: String, description: 'CustomerId' })
|
|
7
|
+
@Column({
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
allowNull: false,
|
|
10
|
+
type: DataType.STRING(30),
|
|
11
|
+
})
|
|
12
|
+
CustomerId: string;
|
|
13
|
+
|
|
14
|
+
@ApiProperty({
|
|
15
|
+
type: String,
|
|
16
|
+
description: 'Account System Id eg. "EZC", "CRM"',
|
|
17
|
+
})
|
|
18
|
+
@Column({
|
|
19
|
+
allowNull: false,
|
|
20
|
+
type: DataType.STRING(30),
|
|
21
|
+
})
|
|
22
|
+
AccSystemId: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { InjectModel } from '@nestjs/sequelize';
|
|
2
|
+
import { FinanceCustomerModel } from './entities/customer.entity';
|
|
3
|
+
import { IFinanceCustomerAttr } from './interfaces/finance-customer-attr.interface';
|
|
4
|
+
import { IFinanceCustomerRepository } from './interfaces/finance-customer.repository.interface';
|
|
5
|
+
|
|
6
|
+
export class FinanceCustomerRepository
|
|
7
|
+
implements IFinanceCustomerRepository<FinanceCustomerModel>
|
|
8
|
+
{
|
|
9
|
+
constructor(
|
|
10
|
+
@InjectModel(FinanceCustomerModel)
|
|
11
|
+
private readonly customerModel: typeof FinanceCustomerModel,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
create(
|
|
15
|
+
data: IFinanceCustomerAttr | any,
|
|
16
|
+
options?: any,
|
|
17
|
+
): Promise<FinanceCustomerModel> | any {
|
|
18
|
+
return this.customerModel.create(data, options);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IFinanceCustomerRepository } from './interfaces/finance-customer.repository.interface';
|
|
2
|
+
import { IFinanceCustomerAttr } from './interfaces/finance-customer-attr.interface';
|
|
3
|
+
import { FinanceCustomerModel } from './entities/customer.entity';
|
|
4
|
+
import { ICustomerRepository } from './interfaces/customer.repository.interface';
|
|
5
|
+
import { FinanceCustomerRepository } from './finance-customer.repository';
|
|
6
|
+
import { Customer } from './customer';
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
IFinanceCustomerRepository,
|
|
10
|
+
IFinanceCustomerAttr,
|
|
11
|
+
FinanceCustomerModel,
|
|
12
|
+
ICustomerRepository,
|
|
13
|
+
FinanceCustomerRepository,
|
|
14
|
+
Customer,
|
|
15
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as OAuthClient from 'intuit-oauth';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ClientScopes } from '../enum/quick-book-client-scopes.enum';
|
|
3
|
+
import { IAccountSystem } from '../interfaces';
|
|
4
4
|
import { IQuickBookAPICallOptions } from './interfaces/quickbook-client-call-options.interface';
|
|
5
5
|
import { IQuickBookCreateAccountOptions } from './interfaces/quickbook-client-create-account-options.interface';
|
|
6
|
+
import { IQuickBookCreateCustomerOptions } from './interfaces/quickbook-client-create-customer-options.interface';
|
|
6
7
|
import { IQuickBookClientOptions } from './interfaces/quickbook-client-options.interface';
|
|
7
8
|
|
|
8
9
|
export class QuickBookClient implements IAccountSystem {
|
|
@@ -36,6 +37,41 @@ export class QuickBookClient implements IAccountSystem {
|
|
|
36
37
|
throw error;
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
|
|
41
|
+
async createCustomer(payload: IQuickBookCreateCustomerOptions) {
|
|
42
|
+
try {
|
|
43
|
+
const requestBody = {
|
|
44
|
+
PrimaryEmailAddr: {
|
|
45
|
+
Address: payload.Email,
|
|
46
|
+
},
|
|
47
|
+
DisplayName: payload.FullName,
|
|
48
|
+
PrimaryPhone: {
|
|
49
|
+
FreeFormNumber: payload.ContractNo,
|
|
50
|
+
},
|
|
51
|
+
BillAddr: {
|
|
52
|
+
CountrySubDivisionCode: '',
|
|
53
|
+
City: payload.Address.City,
|
|
54
|
+
PostalCode: payload.Address.PostalCode,
|
|
55
|
+
Line1: payload.Address.Line1,
|
|
56
|
+
Country: payload.Address.Country,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const companyId = this.getCompanyId();
|
|
61
|
+
const response = await this.callApi({
|
|
62
|
+
endpoint: `/v3/company/${companyId}/customer?minorversion=65`,
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: {
|
|
65
|
+
'Content-Type': 'application/json',
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify(requestBody),
|
|
68
|
+
});
|
|
69
|
+
return response.json.Customer;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
39
75
|
async createInvoice() {
|
|
40
76
|
throw new Error('Method not implemented.');
|
|
41
77
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { QuickBookClient } from './client';
|
|
2
2
|
import { IQuickBookCreateAccountOptions } from './interfaces/quickbook-client-create-account-options.interface';
|
|
3
3
|
import { IQuickBookClientOptions } from './interfaces/quickbook-client-options.interface';
|
|
4
|
-
|
|
4
|
+
import { IQuickBookCreateCustomerOptions } from './interfaces/quickbook-client-create-customer-options.interface';
|
|
5
5
|
export {
|
|
6
6
|
QuickBookClient,
|
|
7
7
|
IQuickBookCreateAccountOptions,
|
|
8
8
|
IQuickBookClientOptions,
|
|
9
|
+
IQuickBookCreateCustomerOptions,
|
|
9
10
|
};
|