gemcap-be-common 1.3.179 → 1.3.181
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 +1 -1
- package/services/bank-uploaded-transactions.service.js +14 -2
- package/services/bank-uploaded-transactions.service.ts +17 -2
- package/services/borrowers.service.d.ts +2 -2
- package/services/loan-payments.service.d.ts +1 -1
- package/services/loan-payments.service.js +5 -3
- package/services/loan-payments.service.ts +5 -3
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -82,6 +82,18 @@ class BankUploadedTransactionsService {
|
|
|
82
82
|
cashAllocationProducts.forEach((product) => {
|
|
83
83
|
cashAllocationProductsMap.set(product._id.toString(), product);
|
|
84
84
|
});
|
|
85
|
+
const findMatchingCashAllocationReference = (bankTransaction, searchInDetails) => {
|
|
86
|
+
return cashAllocationReferences.find((cashAllocationReference) => {
|
|
87
|
+
const referenceToSearch = cashAllocationReference.reference.toLowerCase();
|
|
88
|
+
const fieldsToSearch = [bankTransaction.reference];
|
|
89
|
+
if (searchInDetails) {
|
|
90
|
+
fieldsToSearch.push(bankTransaction.detail1, bankTransaction.detail2, bankTransaction.detail3);
|
|
91
|
+
}
|
|
92
|
+
return fieldsToSearch
|
|
93
|
+
.filter((field) => !!field)
|
|
94
|
+
.some((field) => field.toLowerCase().includes(referenceToSearch));
|
|
95
|
+
});
|
|
96
|
+
};
|
|
85
97
|
const transactionHasMatch = (bankTransaction) => {
|
|
86
98
|
if (bankTransaction.splitTransactions.length > 0) {
|
|
87
99
|
const totalSplit = bankTransaction.splitTransactions.reduce((acc, split) => new decimal_js_1.Decimal(split.amount).add(acc).toNumber(), 0);
|
|
@@ -89,14 +101,14 @@ class BankUploadedTransactionsService {
|
|
|
89
101
|
return true;
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
|
-
const foundCashAllocationReference =
|
|
104
|
+
const foundCashAllocationReference = findMatchingCashAllocationReference(bankTransaction, true);
|
|
93
105
|
if (!foundCashAllocationReference || !foundCashAllocationReference.cashAllocationProductId) {
|
|
94
106
|
return false;
|
|
95
107
|
}
|
|
96
108
|
return !!cashAllocationProductsMap.get(foundCashAllocationReference.cashAllocationProductId.toString());
|
|
97
109
|
};
|
|
98
110
|
const transactionCanSplit = (bankTransaction) => {
|
|
99
|
-
const foundCashAllocationReference =
|
|
111
|
+
const foundCashAllocationReference = findMatchingCashAllocationReference(bankTransaction, true);
|
|
100
112
|
if (!foundCashAllocationReference || !foundCashAllocationReference.cashAllocationProductId) {
|
|
101
113
|
return false;
|
|
102
114
|
}
|
|
@@ -103,6 +103,21 @@ export class BankUploadedTransactionsService {
|
|
|
103
103
|
cashAllocationProductsMap.set(product._id.toString(), product);
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
+
const findMatchingCashAllocationReference = (bankTransaction: IUploadedBankTransaction, searchInDetails: boolean) => {
|
|
107
|
+
return cashAllocationReferences.find((cashAllocationReference) => {
|
|
108
|
+
const referenceToSearch = cashAllocationReference.reference.toLowerCase();
|
|
109
|
+
|
|
110
|
+
const fieldsToSearch = [bankTransaction.reference];
|
|
111
|
+
if (searchInDetails) {
|
|
112
|
+
fieldsToSearch.push(bankTransaction.detail1, bankTransaction.detail2, bankTransaction.detail3);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return fieldsToSearch
|
|
116
|
+
.filter((field): field is string => !!field)
|
|
117
|
+
.some((field) => field.toLowerCase().includes(referenceToSearch));
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
106
121
|
const transactionHasMatch = (bankTransaction: IUploadedBankTransaction): boolean => {
|
|
107
122
|
if (bankTransaction.splitTransactions.length > 0) {
|
|
108
123
|
const totalSplit = bankTransaction.splitTransactions.reduce((acc, split) => new Decimal(split.amount).add(acc).toNumber(), 0);
|
|
@@ -110,7 +125,7 @@ export class BankUploadedTransactionsService {
|
|
|
110
125
|
return true;
|
|
111
126
|
}
|
|
112
127
|
}
|
|
113
|
-
const foundCashAllocationReference =
|
|
128
|
+
const foundCashAllocationReference = findMatchingCashAllocationReference(bankTransaction, true);
|
|
114
129
|
if (!foundCashAllocationReference || !foundCashAllocationReference.cashAllocationProductId) {
|
|
115
130
|
return false;
|
|
116
131
|
}
|
|
@@ -118,7 +133,7 @@ export class BankUploadedTransactionsService {
|
|
|
118
133
|
};
|
|
119
134
|
|
|
120
135
|
const transactionCanSplit = (bankTransaction: IUploadedBankTransaction): boolean => {
|
|
121
|
-
const foundCashAllocationReference =
|
|
136
|
+
const foundCashAllocationReference = findMatchingCashAllocationReference(bankTransaction, true);
|
|
122
137
|
if (!foundCashAllocationReference || !foundCashAllocationReference.cashAllocationProductId) {
|
|
123
138
|
return false;
|
|
124
139
|
}
|
|
@@ -83,10 +83,10 @@ export declare class BorrowerService {
|
|
|
83
83
|
getBorrowerCodesMap(): Promise<Map<string, string>>;
|
|
84
84
|
getBorrowerStatementDetails(borrowers: IBorrowerDocument[]): Promise<{
|
|
85
85
|
[x: number]: {
|
|
86
|
+
SELECTED_PERIOD?: boolean;
|
|
87
|
+
ENTIRE_LOAN?: boolean;
|
|
86
88
|
LAST_MONTH?: boolean;
|
|
87
89
|
CURRENT_MONTH?: boolean;
|
|
88
|
-
ENTIRE_LOAN?: boolean;
|
|
89
|
-
SELECTED_PERIOD?: boolean;
|
|
90
90
|
TERM_LOAN?: boolean;
|
|
91
91
|
};
|
|
92
92
|
}>;
|
|
@@ -421,7 +421,7 @@ class LoanPaymentsService {
|
|
|
421
421
|
}));
|
|
422
422
|
return { borrowers: borrowersData, isCalculated: !!isCalculated };
|
|
423
423
|
}
|
|
424
|
-
async payExpectedPayments(userId, borrowers) {
|
|
424
|
+
async payExpectedPayments(userId, borrowers, selectedDate) {
|
|
425
425
|
const arrayOfStringsSchema = joi_1.default.array().items(joi_1.default.string()).required();
|
|
426
426
|
const borrowerIds = Object.keys(borrowers);
|
|
427
427
|
const { error } = arrayOfStringsSchema.validate(borrowerIds, { abortEarly: false });
|
|
@@ -437,6 +437,8 @@ class LoanPaymentsService {
|
|
|
437
437
|
const paymentPromises = allowedBorrowers.map(async (borrower) => {
|
|
438
438
|
if (borrowerIds.includes(borrower._id.toString())) {
|
|
439
439
|
try {
|
|
440
|
+
const borrowerProducts = await this.loanChargesService.getLoanProducts(borrower._id.toString());
|
|
441
|
+
const revolverProduct = borrowerProducts.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER);
|
|
440
442
|
const loanStatementService = this.getLoanStatementService();
|
|
441
443
|
const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString());
|
|
442
444
|
if (dueAmounts.total === 0) {
|
|
@@ -449,7 +451,7 @@ class LoanPaymentsService {
|
|
|
449
451
|
return {
|
|
450
452
|
productId: productId,
|
|
451
453
|
payableSum: amount,
|
|
452
|
-
settlementCode: borrowers[borrower._id.toString()] ? product.code : product.settlementCode,
|
|
454
|
+
settlementCode: borrowers[borrower._id.toString()] ? (revolverProduct?.code ?? product.code) : product.settlementCode,
|
|
453
455
|
paymentOrder: null,
|
|
454
456
|
};
|
|
455
457
|
}
|
|
@@ -457,7 +459,7 @@ class LoanPaymentsService {
|
|
|
457
459
|
const combinedPayment = {
|
|
458
460
|
addToRevolver: borrowers[borrower._id.toString()],
|
|
459
461
|
borrowerId: borrower._id.toString(),
|
|
460
|
-
date:
|
|
462
|
+
date: selectedDate,
|
|
461
463
|
linkedProducts: [],
|
|
462
464
|
payment: dueAmounts.total,
|
|
463
465
|
products: products.filter((product) => !!product),
|
|
@@ -470,7 +470,7 @@ export class LoanPaymentsService {
|
|
|
470
470
|
return { borrowers: borrowersData, isCalculated: !!isCalculated };
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
-
async payExpectedPayments(userId: string, borrowers: { [borrowerId: string]: boolean }) {
|
|
473
|
+
async payExpectedPayments(userId: string, borrowers: { [borrowerId: string]: boolean }, selectedDate: Date) {
|
|
474
474
|
|
|
475
475
|
const arrayOfStringsSchema = Joi.array().items(Joi.string()).required();
|
|
476
476
|
const borrowerIds = Object.keys(borrowers);
|
|
@@ -488,6 +488,8 @@ export class LoanPaymentsService {
|
|
|
488
488
|
const paymentPromises = allowedBorrowers.map(async (borrower) => {
|
|
489
489
|
if (borrowerIds.includes(borrower._id.toString())) {
|
|
490
490
|
try {
|
|
491
|
+
const borrowerProducts = await this.loanChargesService.getLoanProducts(borrower._id.toString());
|
|
492
|
+
const revolverProduct = borrowerProducts.find((product) => product.type === ELoanTypes.REVOLVER);
|
|
491
493
|
const loanStatementService = this.getLoanStatementService();
|
|
492
494
|
const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString());
|
|
493
495
|
if (dueAmounts.total === 0) {
|
|
@@ -501,7 +503,7 @@ export class LoanPaymentsService {
|
|
|
501
503
|
return {
|
|
502
504
|
productId: productId,
|
|
503
505
|
payableSum: amount,
|
|
504
|
-
settlementCode: borrowers[borrower._id.toString()] ? product.code : product.settlementCode,
|
|
506
|
+
settlementCode: borrowers[borrower._id.toString()] ? (revolverProduct?.code ?? product.code) : product.settlementCode,
|
|
505
507
|
paymentOrder: null,
|
|
506
508
|
};
|
|
507
509
|
}
|
|
@@ -511,7 +513,7 @@ export class LoanPaymentsService {
|
|
|
511
513
|
const combinedPayment: ICombinedPayment = {
|
|
512
514
|
addToRevolver: borrowers[borrower._id.toString()],
|
|
513
515
|
borrowerId: borrower._id.toString(),
|
|
514
|
-
date:
|
|
516
|
+
date: selectedDate,
|
|
515
517
|
linkedProducts: [],
|
|
516
518
|
payment: dueAmounts.total,
|
|
517
519
|
products: products.filter((product) => !!product),
|