@tomei/finance 0.1.4 → 0.1.5
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 +3 -4
- package/dist/account/account.js +5 -4
- package/dist/account/account.js.map +1 -1
- package/dist/payment/entities/payment-item.entity.js +1 -1
- package/dist/payment/entities/payment-item.entity.js.map +1 -1
- package/dist/payment/interfaces/payment-params.interface.d.ts +7 -0
- package/dist/payment/interfaces/payment-params.interface.js +3 -0
- package/dist/payment/interfaces/payment-params.interface.js.map +1 -0
- package/dist/payment/payment-item.repository.d.ts +1 -0
- package/dist/payment/payment-item.repository.js +4 -0
- package/dist/payment/payment-item.repository.js.map +1 -1
- package/dist/payment/payment.d.ts +3 -1
- package/dist/payment/payment.js +20 -3
- package/dist/payment/payment.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/finance-payment-item-migration.js +1 -1
- package/package.json +1 -1
- package/src/account/account.ts +20 -20
- package/src/payment/entities/payment-item.entity.ts +1 -1
- package/src/payment/interfaces/payment-params.interface.ts +8 -0
- package/src/payment/payment-item.repository.ts +5 -0
- package/src/payment/payment.ts +24 -12
|
@@ -6,7 +6,6 @@ module.exports = {
|
|
|
6
6
|
PaymentId: {
|
|
7
7
|
type: Sequelize.STRING(30),
|
|
8
8
|
allowNull: false,
|
|
9
|
-
primaryKey: true,
|
|
10
9
|
references: {
|
|
11
10
|
model: 'finance_Payment',
|
|
12
11
|
key: 'PaymentId',
|
|
@@ -16,6 +15,7 @@ module.exports = {
|
|
|
16
15
|
},
|
|
17
16
|
PayForObjectId: {
|
|
18
17
|
type: Sequelize.STRING(30),
|
|
18
|
+
primaryKey: true,
|
|
19
19
|
allowNull: false,
|
|
20
20
|
},
|
|
21
21
|
PayForObjectType: {
|
package/package.json
CHANGED
package/src/account/account.ts
CHANGED
|
@@ -21,17 +21,18 @@ export class Account {
|
|
|
21
21
|
RelatedObject: RelatedObject;
|
|
22
22
|
AccountType: string;
|
|
23
23
|
AccountSubType: string;
|
|
24
|
+
AccountingSystem: IAccountSystem;
|
|
24
25
|
|
|
25
26
|
isParamsInitialized: boolean;
|
|
26
|
-
accessToken: string;
|
|
27
|
-
refreshToken: string;
|
|
28
27
|
|
|
29
28
|
constructor(
|
|
30
29
|
accountRepository: IAccountRepository,
|
|
30
|
+
accountingSystem: IAccountSystem,
|
|
31
31
|
SysCode: string,
|
|
32
32
|
params?: ICreateAccountAttr,
|
|
33
33
|
) {
|
|
34
34
|
this.accountRepository = accountRepository;
|
|
35
|
+
this.AccountingSystem = accountingSystem;
|
|
35
36
|
this.AccSystemId = getConfig().systemConfig[SysCode].accountingSystem;
|
|
36
37
|
if (params) {
|
|
37
38
|
this.init(params);
|
|
@@ -77,7 +78,7 @@ export class Account {
|
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
async create(userId: string
|
|
81
|
+
async create(userId: string) {
|
|
81
82
|
try {
|
|
82
83
|
if (!this.Owner || !this.RelatedObject) {
|
|
83
84
|
throw new Error(
|
|
@@ -130,25 +131,24 @@ export class Account {
|
|
|
130
131
|
};
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
const accountId = await
|
|
134
|
-
|
|
135
|
-
const account = await this.accountRepository.create(
|
|
136
|
-
{
|
|
137
|
-
AccountNo: accountId,
|
|
138
|
-
SystemCode: this.AccSystemId,
|
|
139
|
-
Name: this.Owner.FullName,
|
|
140
|
-
OwnerId: this.OwnerId,
|
|
141
|
-
OwnerType: this.OwnerType,
|
|
142
|
-
RelatedObjectId: this.RelatedObjectId,
|
|
143
|
-
RelatedObjectType: this.RelatedObjectType,
|
|
144
|
-
CreatedAt: new Date(),
|
|
145
|
-
CreatedById: userId,
|
|
146
|
-
UpdatedAt: new Date(),
|
|
147
|
-
UpdatedById: userId,
|
|
148
|
-
},
|
|
149
|
-
dbOptions,
|
|
134
|
+
const accountId = await this.AccountingSystem.createAccount(
|
|
135
|
+
createAccountPayload,
|
|
150
136
|
);
|
|
151
137
|
|
|
138
|
+
const account = await this.accountRepository.create({
|
|
139
|
+
AccountNo: accountId,
|
|
140
|
+
SystemCode: this.AccSystemId,
|
|
141
|
+
Name: this.Owner.FullName,
|
|
142
|
+
OwnerId: this.OwnerId,
|
|
143
|
+
OwnerType: this.OwnerType,
|
|
144
|
+
RelatedObjectId: this.RelatedObjectId,
|
|
145
|
+
RelatedObjectType: this.RelatedObjectType,
|
|
146
|
+
CreatedAt: new Date(),
|
|
147
|
+
CreatedById: userId,
|
|
148
|
+
UpdatedAt: new Date(),
|
|
149
|
+
UpdatedById: userId,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
152
|
const payload = {
|
|
153
153
|
Action: 'Create',
|
|
154
154
|
Activity: 'Account Created',
|
|
@@ -12,13 +12,13 @@ import { PaymentModel } from './payment.entity';
|
|
|
12
12
|
export class PaymentItemModel extends Model {
|
|
13
13
|
@ForeignKey(() => PaymentModel)
|
|
14
14
|
@Column({
|
|
15
|
-
primaryKey: true,
|
|
16
15
|
allowNull: false,
|
|
17
16
|
type: DataType.STRING(30),
|
|
18
17
|
})
|
|
19
18
|
PaymentId: string;
|
|
20
19
|
|
|
21
20
|
@Column({
|
|
21
|
+
primaryKey: true,
|
|
22
22
|
allowNull: false,
|
|
23
23
|
type: DataType.STRING(30),
|
|
24
24
|
})
|
|
@@ -24,6 +24,11 @@ export class PaymentItemRepository
|
|
|
24
24
|
return this.paymentItemModel.create({ ...data }, options);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
bulkCreate(data: IPaymentItemAttr[], options?: any): any {
|
|
28
|
+
const payload: any = [...data];
|
|
29
|
+
return this.paymentItemModel.bulkCreate(payload, options);
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
findAll(options: any): Promise<PaymentItemModel[]> {
|
|
28
33
|
return this.paymentItemModel.findAll(options);
|
|
29
34
|
}
|
package/src/payment/payment.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { Sequelize } from 'sequelize-typescript';
|
|
|
9
9
|
import { IPaymentAttr } from './interfaces/payment-attr.interface';
|
|
10
10
|
import { PaymentModel } from './entities/payment.entity';
|
|
11
11
|
import axios from 'axios';
|
|
12
|
+
import { IPaymentParams } from './interfaces/payment-params.interface';
|
|
12
13
|
export class Payment extends ObjectBase {
|
|
13
14
|
Id: string;
|
|
14
15
|
Name: string;
|
|
@@ -51,6 +52,7 @@ export class Payment extends ObjectBase {
|
|
|
51
52
|
ReceivableAccount: Account,
|
|
52
53
|
DepositAccount: Account,
|
|
53
54
|
PaymentItems: PaymentItemBase[],
|
|
55
|
+
Params?: IPaymentParams,
|
|
54
56
|
sequelize?: Sequelize,
|
|
55
57
|
) {
|
|
56
58
|
super();
|
|
@@ -61,11 +63,21 @@ export class Payment extends ObjectBase {
|
|
|
61
63
|
this.ReceivableAccount = ReceivableAccount;
|
|
62
64
|
this.DepositAccount = DepositAccount;
|
|
63
65
|
this.PaymentItems = PaymentItems;
|
|
66
|
+
if (Params) {
|
|
67
|
+
this.init(Params);
|
|
68
|
+
}
|
|
64
69
|
if (sequelize) {
|
|
65
70
|
this.sequelize = sequelize;
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
|
|
74
|
+
init(Params: IPaymentParams): void {
|
|
75
|
+
if (Params.Currency) this.Currency = Params.Currency;
|
|
76
|
+
if (Params.Method) this.Method = Params.Method;
|
|
77
|
+
if (Params.MethodParty) this.MethodParty = Params.MethodParty;
|
|
78
|
+
if (Params.PaymentType) this.PaymentType = Params.PaymentType;
|
|
79
|
+
}
|
|
80
|
+
|
|
69
81
|
getAmount(): number {
|
|
70
82
|
if (!this.Amount) {
|
|
71
83
|
if (this.PaymentItems.length === 0) {
|
|
@@ -113,7 +125,6 @@ export class Payment extends ObjectBase {
|
|
|
113
125
|
if (!this.sequelize) {
|
|
114
126
|
throw new Error('sequelize instance used for transaction is required.');
|
|
115
127
|
}
|
|
116
|
-
|
|
117
128
|
if (!this.PaymentType) {
|
|
118
129
|
throw new Error('Payment Type is required.');
|
|
119
130
|
}
|
|
@@ -147,18 +158,19 @@ export class Payment extends ObjectBase {
|
|
|
147
158
|
const payment = await this.PaymentRepository.create(paymentAttribute, {
|
|
148
159
|
transaction,
|
|
149
160
|
});
|
|
150
|
-
|
|
161
|
+
const paymentItemsData = [];
|
|
151
162
|
this.PaymentItems.forEach(async (paymentItem) => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
paymentItemsData.push({
|
|
164
|
+
PaymentId: this.Id,
|
|
165
|
+
PayForObjectId: paymentItem.Id,
|
|
166
|
+
PayForObjectType: paymentItem.Type,
|
|
167
|
+
Amount: paymentItem.Amount,
|
|
168
|
+
Currency: paymentItem.Currency,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
await this.PaymentItemRepository.bulkCreate(paymentItemsData, {
|
|
173
|
+
transaction,
|
|
162
174
|
});
|
|
163
175
|
|
|
164
176
|
const payload = {
|