@tomei/finance 0.1.13 → 0.2.1
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/entities/account.entity.d.ts +3 -1
- package/dist/account/entities/account.entity.js +6 -1
- package/dist/account/entities/account.entity.js.map +1 -1
- package/dist/account/interfaces/account.repository.interface.d.ts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/enum/index.d.ts +2 -1
- package/dist/enum/index.js +3 -1
- package/dist/enum/index.js.map +1 -1
- package/dist/enum/transaction-type.enum.d.ts +4 -0
- package/dist/enum/transaction-type.enum.js +9 -0
- package/dist/enum/transaction-type.enum.js.map +1 -0
- package/dist/finance-company/finance-company.d.ts +10 -0
- package/dist/finance-company/finance-company.js +63 -0
- package/dist/finance-company/finance-company.js.map +1 -0
- package/dist/finance-company/index.d.ts +2 -0
- package/dist/finance-company/index.js +6 -0
- package/dist/finance-company/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/account-system.interface.d.ts +1 -0
- package/dist/journal-entry/entities/journal-entry.entity.d.ts +12 -0
- package/dist/journal-entry/entities/journal-entry.entity.js +98 -0
- package/dist/journal-entry/entities/journal-entry.entity.js.map +1 -0
- package/dist/journal-entry/index.d.ts +6 -0
- package/dist/journal-entry/index.js +10 -0
- package/dist/journal-entry/index.js.map +1 -0
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts +9 -0
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.js +3 -0
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.js.map +1 -0
- package/dist/journal-entry/interfaces/journal-entry.repository.interface.d.ts +10 -0
- package/dist/journal-entry/interfaces/journal-entry.repository.interface.js +3 -0
- package/dist/journal-entry/interfaces/journal-entry.repository.interface.js.map +1 -0
- package/dist/journal-entry/journal-entry.d.ts +32 -0
- package/dist/journal-entry/journal-entry.js +97 -0
- package/dist/journal-entry/journal-entry.js.map +1 -0
- package/dist/journal-entry/journal-entry.repository.d.ts +15 -0
- package/dist/journal-entry/journal-entry.repository.js +43 -0
- package/dist/journal-entry/journal-entry.repository.js.map +1 -0
- package/dist/ledger-transaction/entities/ledger-transaction.entity.d.ts +19 -0
- package/dist/ledger-transaction/entities/ledger-transaction.entity.js +157 -0
- package/dist/ledger-transaction/entities/ledger-transaction.entity.js.map +1 -0
- package/dist/ledger-transaction/index.d.ts +6 -0
- package/dist/ledger-transaction/index.js +10 -0
- package/dist/ledger-transaction/index.js.map +1 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +18 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js +3 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js.map +1 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts +5 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js +3 -0
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js.map +1 -0
- package/dist/ledger-transaction/ledger-transaction.d.ts +35 -0
- package/dist/ledger-transaction/ledger-transaction.js +71 -0
- package/dist/ledger-transaction/ledger-transaction.js.map +1 -0
- package/dist/ledger-transaction/ledger-transaction.repository.d.ts +10 -0
- package/dist/ledger-transaction/ledger-transaction.repository.js +37 -0
- package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -0
- package/dist/payment/interfaces/payment-item.repository.interface.d.ts +1 -1
- package/dist/payment/interfaces/payment.repository.interface.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/finance-journal-entry-migration.js +41 -0
- package/migrations/finance-ledger-transaction-migration.js +73 -0
- package/package.json +2 -2
- package/src/account/account.ts +189 -189
- package/src/account/entities/account.entity.ts +111 -107
- package/src/account/interfaces/account-attr.interface.ts +23 -23
- package/src/enum/index.ts +6 -5
- package/src/enum/transaction-type.enum.ts +4 -0
- package/src/finance-company/finance-company.ts +95 -0
- package/src/finance-company/index.ts +3 -0
- package/src/index.ts +9 -6
- package/src/interfaces/account-system.interface.ts +14 -13
- package/src/journal-entry/entities/journal-entry.entity.ts +74 -0
- package/src/journal-entry/index.ts +13 -0
- package/src/journal-entry/interfaces/journal-entry-attr.interface.ts +9 -0
- package/src/journal-entry/interfaces/journal-entry.repository.interface.ts +11 -0
- package/src/journal-entry/journal-entry.repository.ts +38 -0
- package/src/journal-entry/journal-entry.ts +136 -0
- package/src/ledger-transaction/entities/ledger-transaction.entity.ts +134 -0
- package/src/ledger-transaction/index.ts +13 -0
- package/src/ledger-transaction/interfaces/ledger-transaction-attr.interface.ts +20 -0
- package/src/ledger-transaction/interfaces/ledger-transaction.repository.interface.ts +7 -0
- package/src/ledger-transaction/ledger-transaction.repository.ts +28 -0
- package/src/ledger-transaction/ledger-transaction.ts +96 -0
- package/src/payment/payment.ts +209 -209
package/src/payment/payment.ts
CHANGED
|
@@ -1,209 +1,209 @@
|
|
|
1
|
-
import { ObjectBase, PaymentItemBase } from '@tomei/general';
|
|
2
|
-
import { PaymentMethod, PaymentType } from '../enum';
|
|
3
|
-
import { Account } from '../account';
|
|
4
|
-
import { Customer } from '../customer';
|
|
5
|
-
import { IAccountSystem } from '../interfaces';
|
|
6
|
-
import { IPaymentRepository } from './interfaces/payment.repository.interface';
|
|
7
|
-
import { IPaymentItemRepository } from './interfaces/payment-item.repository.interface';
|
|
8
|
-
import { Sequelize } from 'sequelize-typescript';
|
|
9
|
-
import { IPaymentAttr } from './interfaces/payment-attr.interface';
|
|
10
|
-
import { PaymentModel } from './entities/payment.entity';
|
|
11
|
-
import axios from 'axios';
|
|
12
|
-
import { IPaymentParams } from './interfaces/payment-params.interface';
|
|
13
|
-
export class Payment extends ObjectBase {
|
|
14
|
-
ObjectId: string;
|
|
15
|
-
ObjectName: string;
|
|
16
|
-
|
|
17
|
-
private Amount: number;
|
|
18
|
-
private Currency: string;
|
|
19
|
-
private Method: PaymentMethod;
|
|
20
|
-
private MethodParty: string;
|
|
21
|
-
private Status: string;
|
|
22
|
-
private PaymentType: PaymentType;
|
|
23
|
-
private PaymentDate: Date;
|
|
24
|
-
|
|
25
|
-
private AccountNo: string;
|
|
26
|
-
private SystemCode: string;
|
|
27
|
-
private OwnerId: string;
|
|
28
|
-
private OwnerType: string;
|
|
29
|
-
private RelatedObjectId: string;
|
|
30
|
-
private RelatedObjectType: string;
|
|
31
|
-
private CreatedAt: Date;
|
|
32
|
-
private CreatedById: string;
|
|
33
|
-
private UpdatedAt: Date;
|
|
34
|
-
private UpdatedById: string;
|
|
35
|
-
|
|
36
|
-
private Customer: Customer;
|
|
37
|
-
private ReceivableAccount: Account;
|
|
38
|
-
private DepositAccount: Account;
|
|
39
|
-
private ReceivableAccountNo: string;
|
|
40
|
-
private DepositAccountNo: string;
|
|
41
|
-
private PaymentItems: PaymentItemBase[];
|
|
42
|
-
private AccountingSystem: IAccountSystem;
|
|
43
|
-
private PaymentRepository: IPaymentRepository;
|
|
44
|
-
private PaymentItemRepository: IPaymentItemRepository;
|
|
45
|
-
private sequelize: Sequelize;
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
48
|
-
AccountingSystem: IAccountSystem,
|
|
49
|
-
PaymentRepository: IPaymentRepository,
|
|
50
|
-
PaymentItemRepository: IPaymentItemRepository,
|
|
51
|
-
Customer: Customer,
|
|
52
|
-
ReceivableAccount: Account,
|
|
53
|
-
DepositAccount: Account,
|
|
54
|
-
PaymentItems: PaymentItemBase[],
|
|
55
|
-
Params?: IPaymentParams,
|
|
56
|
-
sequelize?: Sequelize,
|
|
57
|
-
) {
|
|
58
|
-
super();
|
|
59
|
-
this.AccountingSystem = AccountingSystem;
|
|
60
|
-
this.PaymentRepository = PaymentRepository;
|
|
61
|
-
this.PaymentItemRepository = PaymentItemRepository;
|
|
62
|
-
this.Customer = Customer;
|
|
63
|
-
this.ReceivableAccount = ReceivableAccount;
|
|
64
|
-
this.DepositAccount = DepositAccount;
|
|
65
|
-
this.PaymentItems = PaymentItems;
|
|
66
|
-
if (Params) {
|
|
67
|
-
this.init(Params);
|
|
68
|
-
}
|
|
69
|
-
if (sequelize) {
|
|
70
|
-
this.sequelize = sequelize;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get objectId(): string {
|
|
75
|
-
return this.ObjectId;
|
|
76
|
-
}
|
|
77
|
-
get objectName(): string {
|
|
78
|
-
return this.ObjectName;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
init(Params: IPaymentParams): void {
|
|
82
|
-
if (Params.Currency) this.Currency = Params.Currency;
|
|
83
|
-
if (Params.Method) this.Method = Params.Method;
|
|
84
|
-
if (Params.MethodParty) this.MethodParty = Params.MethodParty;
|
|
85
|
-
if (Params.PaymentType) this.PaymentType = Params.PaymentType;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
getAmount(): number {
|
|
89
|
-
if (!this.Amount) {
|
|
90
|
-
if (this.PaymentItems.length === 0) {
|
|
91
|
-
throw new Error('Payment must have at least one payment item');
|
|
92
|
-
}
|
|
93
|
-
this.PaymentItems.forEach((paymentItem) => {
|
|
94
|
-
this.Amount += paymentItem.Amount;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return this.Amount;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
getCurrency(): string {
|
|
101
|
-
if (!this.Currency) {
|
|
102
|
-
throw new Error('Currency is missing.');
|
|
103
|
-
}
|
|
104
|
-
return this.Currency;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
setSequelize(sequelize: Sequelize): void {
|
|
108
|
-
this.sequelize = sequelize;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async getDepositAccountNo(): Promise<string> {
|
|
112
|
-
if (!this.DepositAccountNo) {
|
|
113
|
-
this.DepositAccountNo = await this.DepositAccount.getAccountNo();
|
|
114
|
-
}
|
|
115
|
-
return this.DepositAccountNo;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async getReceivableAccountNo(): Promise<string> {
|
|
119
|
-
if (!this.ReceivableAccountNo) {
|
|
120
|
-
this.ReceivableAccountNo = await this.ReceivableAccount.getAccountNo();
|
|
121
|
-
}
|
|
122
|
-
return this.ReceivableAccountNo;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getPaymentItems(): PaymentItemBase[] {
|
|
126
|
-
return this.PaymentItems;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async create() {
|
|
130
|
-
const transaction = await this.sequelize.transaction();
|
|
131
|
-
try {
|
|
132
|
-
if (!this.sequelize) {
|
|
133
|
-
throw new Error('sequelize instance used for transaction is required.');
|
|
134
|
-
}
|
|
135
|
-
if (!this.PaymentType) {
|
|
136
|
-
throw new Error('Payment Type is required.');
|
|
137
|
-
}
|
|
138
|
-
if (!this.Method) {
|
|
139
|
-
throw new Error('Method is required.');
|
|
140
|
-
}
|
|
141
|
-
if (this.PaymentItems.length === 0) {
|
|
142
|
-
throw new Error('Payment must have at least one payment item');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
this.ReceivableAccountNo = await this.ReceivableAccount.getAccountNo();
|
|
146
|
-
this.DepositAccountNo = await this.DepositAccount.getAccountNo();
|
|
147
|
-
|
|
148
|
-
this.ObjectId = await this.AccountingSystem.makePayment(
|
|
149
|
-
this.Customer,
|
|
150
|
-
this,
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
this.Status = 'Successfull';
|
|
154
|
-
const paymentAttribute: IPaymentAttr = {
|
|
155
|
-
PaymentId: this.ObjectId,
|
|
156
|
-
AccountNo: this.DepositAccountNo,
|
|
157
|
-
PaymentType: this.PaymentType,
|
|
158
|
-
PaymentDate: new Date(),
|
|
159
|
-
Currency: this.Currency,
|
|
160
|
-
Amount: this.Amount,
|
|
161
|
-
Status: this.Status,
|
|
162
|
-
Method: this.Method,
|
|
163
|
-
MethodParty: this.MethodParty,
|
|
164
|
-
ReceivedBy: this.ReceivableAccountNo,
|
|
165
|
-
UpdatedAt: new Date(),
|
|
166
|
-
UpdatedBy: 'System', //still ambigous
|
|
167
|
-
};
|
|
168
|
-
const payment = await this.PaymentRepository.create(paymentAttribute, {
|
|
169
|
-
transaction,
|
|
170
|
-
});
|
|
171
|
-
const paymentItemsData = [];
|
|
172
|
-
this.PaymentItems.forEach(async (paymentItem) => {
|
|
173
|
-
paymentItemsData.push({
|
|
174
|
-
PaymentId: this.ObjectId,
|
|
175
|
-
PayForObjectId: paymentItem.ObjectId,
|
|
176
|
-
PayForObjectType: paymentItem.Type,
|
|
177
|
-
Amount: paymentItem.Amount,
|
|
178
|
-
Currency: paymentItem.Currency,
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
await this.PaymentItemRepository.bulkCreate(paymentItemsData, {
|
|
183
|
-
transaction,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
const payload = {
|
|
187
|
-
Action: 'Create',
|
|
188
|
-
Activity: 'Payment Created',
|
|
189
|
-
Description: `Account (ID: ${this.ObjectId}) has been created`,
|
|
190
|
-
EntityType: typeof PaymentModel,
|
|
191
|
-
EntityValueBefore: JSON.stringify({}),
|
|
192
|
-
EntityValueAfter: JSON.stringify(payment),
|
|
193
|
-
PerformedById: payment.UpdatedBy,
|
|
194
|
-
PerformedAt: payment.UpdatedAt,
|
|
195
|
-
EntityId: this.ObjectId,
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
await axios.post(
|
|
199
|
-
`${process.env.COMMON_API_URL}/activity-histories`,
|
|
200
|
-
payload,
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
await transaction.commit();
|
|
204
|
-
} catch (error) {
|
|
205
|
-
await transaction.rollback();
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
1
|
+
import { ObjectBase, PaymentItemBase } from '@tomei/general';
|
|
2
|
+
import { PaymentMethod, PaymentType } from '../enum';
|
|
3
|
+
import { Account } from '../account';
|
|
4
|
+
import { Customer } from '../customer';
|
|
5
|
+
import { IAccountSystem } from '../interfaces';
|
|
6
|
+
import { IPaymentRepository } from './interfaces/payment.repository.interface';
|
|
7
|
+
import { IPaymentItemRepository } from './interfaces/payment-item.repository.interface';
|
|
8
|
+
import { Sequelize } from 'sequelize-typescript';
|
|
9
|
+
import { IPaymentAttr } from './interfaces/payment-attr.interface';
|
|
10
|
+
import { PaymentModel } from './entities/payment.entity';
|
|
11
|
+
import axios from 'axios';
|
|
12
|
+
import { IPaymentParams } from './interfaces/payment-params.interface';
|
|
13
|
+
export class Payment extends ObjectBase {
|
|
14
|
+
ObjectId: string;
|
|
15
|
+
ObjectName: string;
|
|
16
|
+
|
|
17
|
+
private Amount: number;
|
|
18
|
+
private Currency: string;
|
|
19
|
+
private Method: PaymentMethod;
|
|
20
|
+
private MethodParty: string;
|
|
21
|
+
private Status: string;
|
|
22
|
+
private PaymentType: PaymentType;
|
|
23
|
+
private PaymentDate: Date;
|
|
24
|
+
|
|
25
|
+
private AccountNo: string;
|
|
26
|
+
private SystemCode: string;
|
|
27
|
+
private OwnerId: string;
|
|
28
|
+
private OwnerType: string;
|
|
29
|
+
private RelatedObjectId: string;
|
|
30
|
+
private RelatedObjectType: string;
|
|
31
|
+
private CreatedAt: Date;
|
|
32
|
+
private CreatedById: string;
|
|
33
|
+
private UpdatedAt: Date;
|
|
34
|
+
private UpdatedById: string;
|
|
35
|
+
|
|
36
|
+
private Customer: Customer;
|
|
37
|
+
private ReceivableAccount: Account;
|
|
38
|
+
private DepositAccount: Account;
|
|
39
|
+
private ReceivableAccountNo: string;
|
|
40
|
+
private DepositAccountNo: string;
|
|
41
|
+
private PaymentItems: PaymentItemBase[];
|
|
42
|
+
private AccountingSystem: IAccountSystem;
|
|
43
|
+
private PaymentRepository: IPaymentRepository;
|
|
44
|
+
private PaymentItemRepository: IPaymentItemRepository;
|
|
45
|
+
private sequelize: Sequelize;
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
AccountingSystem: IAccountSystem,
|
|
49
|
+
PaymentRepository: IPaymentRepository,
|
|
50
|
+
PaymentItemRepository: IPaymentItemRepository,
|
|
51
|
+
Customer: Customer,
|
|
52
|
+
ReceivableAccount: Account,
|
|
53
|
+
DepositAccount: Account,
|
|
54
|
+
PaymentItems: PaymentItemBase[],
|
|
55
|
+
Params?: IPaymentParams,
|
|
56
|
+
sequelize?: Sequelize,
|
|
57
|
+
) {
|
|
58
|
+
super();
|
|
59
|
+
this.AccountingSystem = AccountingSystem;
|
|
60
|
+
this.PaymentRepository = PaymentRepository;
|
|
61
|
+
this.PaymentItemRepository = PaymentItemRepository;
|
|
62
|
+
this.Customer = Customer;
|
|
63
|
+
this.ReceivableAccount = ReceivableAccount;
|
|
64
|
+
this.DepositAccount = DepositAccount;
|
|
65
|
+
this.PaymentItems = PaymentItems;
|
|
66
|
+
if (Params) {
|
|
67
|
+
this.init(Params);
|
|
68
|
+
}
|
|
69
|
+
if (sequelize) {
|
|
70
|
+
this.sequelize = sequelize;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get objectId(): string {
|
|
75
|
+
return this.ObjectId;
|
|
76
|
+
}
|
|
77
|
+
get objectName(): string {
|
|
78
|
+
return this.ObjectName;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
init(Params: IPaymentParams): void {
|
|
82
|
+
if (Params.Currency) this.Currency = Params.Currency;
|
|
83
|
+
if (Params.Method) this.Method = Params.Method;
|
|
84
|
+
if (Params.MethodParty) this.MethodParty = Params.MethodParty;
|
|
85
|
+
if (Params.PaymentType) this.PaymentType = Params.PaymentType;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getAmount(): number {
|
|
89
|
+
if (!this.Amount) {
|
|
90
|
+
if (this.PaymentItems.length === 0) {
|
|
91
|
+
throw new Error('Payment must have at least one payment item');
|
|
92
|
+
}
|
|
93
|
+
this.PaymentItems.forEach((paymentItem) => {
|
|
94
|
+
this.Amount += paymentItem.Amount;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return this.Amount;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getCurrency(): string {
|
|
101
|
+
if (!this.Currency) {
|
|
102
|
+
throw new Error('Currency is missing.');
|
|
103
|
+
}
|
|
104
|
+
return this.Currency;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setSequelize(sequelize: Sequelize): void {
|
|
108
|
+
this.sequelize = sequelize;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async getDepositAccountNo(): Promise<string> {
|
|
112
|
+
if (!this.DepositAccountNo) {
|
|
113
|
+
this.DepositAccountNo = await this.DepositAccount.getAccountNo();
|
|
114
|
+
}
|
|
115
|
+
return this.DepositAccountNo;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async getReceivableAccountNo(): Promise<string> {
|
|
119
|
+
if (!this.ReceivableAccountNo) {
|
|
120
|
+
this.ReceivableAccountNo = await this.ReceivableAccount.getAccountNo();
|
|
121
|
+
}
|
|
122
|
+
return this.ReceivableAccountNo;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getPaymentItems(): PaymentItemBase[] {
|
|
126
|
+
return this.PaymentItems;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async create() {
|
|
130
|
+
const transaction = await this.sequelize.transaction();
|
|
131
|
+
try {
|
|
132
|
+
if (!this.sequelize) {
|
|
133
|
+
throw new Error('sequelize instance used for transaction is required.');
|
|
134
|
+
}
|
|
135
|
+
if (!this.PaymentType) {
|
|
136
|
+
throw new Error('Payment Type is required.');
|
|
137
|
+
}
|
|
138
|
+
if (!this.Method) {
|
|
139
|
+
throw new Error('Method is required.');
|
|
140
|
+
}
|
|
141
|
+
if (this.PaymentItems.length === 0) {
|
|
142
|
+
throw new Error('Payment must have at least one payment item');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.ReceivableAccountNo = await this.ReceivableAccount.getAccountNo();
|
|
146
|
+
this.DepositAccountNo = await this.DepositAccount.getAccountNo();
|
|
147
|
+
|
|
148
|
+
this.ObjectId = await this.AccountingSystem.makePayment(
|
|
149
|
+
this.Customer,
|
|
150
|
+
this,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
this.Status = 'Successfull';
|
|
154
|
+
const paymentAttribute: IPaymentAttr = {
|
|
155
|
+
PaymentId: this.ObjectId,
|
|
156
|
+
AccountNo: this.DepositAccountNo,
|
|
157
|
+
PaymentType: this.PaymentType,
|
|
158
|
+
PaymentDate: new Date(),
|
|
159
|
+
Currency: this.Currency,
|
|
160
|
+
Amount: this.Amount,
|
|
161
|
+
Status: this.Status,
|
|
162
|
+
Method: this.Method,
|
|
163
|
+
MethodParty: this.MethodParty,
|
|
164
|
+
ReceivedBy: this.ReceivableAccountNo,
|
|
165
|
+
UpdatedAt: new Date(),
|
|
166
|
+
UpdatedBy: 'System', //still ambigous
|
|
167
|
+
};
|
|
168
|
+
const payment = await this.PaymentRepository.create(paymentAttribute, {
|
|
169
|
+
transaction,
|
|
170
|
+
});
|
|
171
|
+
const paymentItemsData = [];
|
|
172
|
+
this.PaymentItems.forEach(async (paymentItem) => {
|
|
173
|
+
paymentItemsData.push({
|
|
174
|
+
PaymentId: this.ObjectId,
|
|
175
|
+
PayForObjectId: paymentItem.ObjectId,
|
|
176
|
+
PayForObjectType: paymentItem.Type,
|
|
177
|
+
Amount: paymentItem.Amount,
|
|
178
|
+
Currency: paymentItem.Currency,
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
await this.PaymentItemRepository.bulkCreate(paymentItemsData, {
|
|
183
|
+
transaction,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const payload = {
|
|
187
|
+
Action: 'Create',
|
|
188
|
+
Activity: 'Payment Created',
|
|
189
|
+
Description: `Account (ID: ${this.ObjectId}) has been created`,
|
|
190
|
+
EntityType: typeof PaymentModel,
|
|
191
|
+
EntityValueBefore: JSON.stringify({}),
|
|
192
|
+
EntityValueAfter: JSON.stringify(payment),
|
|
193
|
+
PerformedById: payment.UpdatedBy,
|
|
194
|
+
PerformedAt: payment.UpdatedAt,
|
|
195
|
+
EntityId: this.ObjectId,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
await axios.post(
|
|
199
|
+
`${process.env.COMMON_API_URL}/activity-histories`,
|
|
200
|
+
payload,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
await transaction.commit();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
await transaction.rollback();
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|