gemcap-be-common 1.3.180 → 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
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
|
}
|