gemcap-be-common 1.2.63 → 1.2.65
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/db/loan-statement.db.d.ts +13 -1
- package/db/loan-statement.db.js +24 -28
- package/db/loan-statement.db.ts +28 -34
- package/db/reports.db.d.ts +44 -4
- package/db/reports.db.js +234 -186
- package/db/reports.db.ts +279 -201
- package/enums/microservice-task.enum.d.ts +2 -1
- package/enums/microservice-task.enum.js +1 -0
- package/enums/microservice-task.enum.ts +1 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import { IStatementPeriod } from '../models/LoanStatementTransaction.model';
|
|
2
3
|
export declare enum ELedgerReportType {
|
|
3
4
|
SHORT = 0,
|
|
@@ -36,7 +37,18 @@ export declare const ledgerHeadersMap: {
|
|
|
36
37
|
export declare const getTotalTransactionAmountForCharge: (chargeId: string, start: Date, end: Date) => Promise<any>;
|
|
37
38
|
export declare const getTotalForDate: (productId: string, date: Date) => Promise<number>;
|
|
38
39
|
export declare const getStatementBorrowersTransactions: (start: string, end: string, selectedPeriod: string, selectedBorrowerIds: string[], ledgerType: ELedgerReportType) => Promise<{
|
|
39
|
-
transactions:
|
|
40
|
+
transactions: ({
|
|
41
|
+
borrowerCode: string;
|
|
42
|
+
type: string;
|
|
43
|
+
chargeCode: string;
|
|
44
|
+
PLCode: string;
|
|
45
|
+
productCode: string;
|
|
46
|
+
productName: string;
|
|
47
|
+
info: string;
|
|
48
|
+
title: string;
|
|
49
|
+
amount: string;
|
|
50
|
+
statementAmount: string;
|
|
51
|
+
} | _.Omit<import("./reports.db").ILedgerReportRow, "balance" | "floatedBalance">)[];
|
|
40
52
|
}[]>;
|
|
41
53
|
export declare const getBorrowerWithPeriods: (borrowerId: string, period: {
|
|
42
54
|
selectedPeriod: string;
|
package/db/loan-statement.db.js
CHANGED
|
@@ -105,39 +105,35 @@ const getStatementBorrowersTransactions = async (start, end, selectedPeriod, sel
|
|
|
105
105
|
if (!selectedBorrowerIds) {
|
|
106
106
|
return [{ transactions: [header] }];
|
|
107
107
|
}
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
const periodFull = selectedPeriod === 'ENTIRE_LOAN'
|
|
109
|
+
? [{
|
|
110
|
+
period: {
|
|
111
|
+
selectedPeriod: selectedPeriod,
|
|
112
|
+
start: (0, dayjs_1.default)(start).utc().toDate().toISOString(),
|
|
113
|
+
end: (0, dayjs_1.default)(end).utc().toDate().toISOString(),
|
|
114
|
+
},
|
|
115
|
+
}]
|
|
116
|
+
: await (0, exports.getBorrowerWithPeriods)(selectedBorrowerIds[0], {
|
|
112
117
|
selectedStart: new Date(start),
|
|
113
118
|
selectedEnd: new Date(end),
|
|
114
119
|
selectedPeriod,
|
|
115
120
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
productStart: periodDesc.period.start,
|
|
121
|
-
productEnd: periodDesc.period.end,
|
|
122
|
-
productId: product._id.toString(),
|
|
123
|
-
})),
|
|
124
|
-
];
|
|
125
|
-
}, []);
|
|
126
|
-
await Promise.all(someMappedResults.map(async (productDesc) => {
|
|
127
|
-
const borrowerTransactions = await (0, reports_db_1.getLedger)(productDesc.productId, new Date(productDesc.productStart), new Date(productDesc.productEnd), ledgerType, true);
|
|
128
|
-
Object.values(borrowerTransactions).forEach((transactions) => {
|
|
129
|
-
const [_header, ...onlyData] = transactions;
|
|
130
|
-
const mappedData = lodash_1.default.map(onlyData, (obj) => lodash_1.default.omit(obj, ['balance', 'floatedBalance']));
|
|
131
|
-
allTransactions[borrowerId] = mappedData;
|
|
132
|
-
});
|
|
133
|
-
}));
|
|
121
|
+
const allProductIds = [];
|
|
122
|
+
await Promise.all(selectedBorrowerIds.map(async (borrowerId) => {
|
|
123
|
+
const borrowerProducts = await (0, loan_products_db_1.getLoanProducts)(borrowerId);
|
|
124
|
+
allProductIds.push(borrowerProducts.map((product) => product._id.toString()));
|
|
134
125
|
}));
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
126
|
+
const products = await LoanProducts_model_1.LoanProduct.find({ borrowerId: { $in: selectedBorrowerIds.map((id) => new mongoose_1.default.Types.ObjectId(id)) } }).lean();
|
|
127
|
+
const productIds = products.map((product) => product._id.toString());
|
|
128
|
+
const ledgerData = await (0, reports_db_1.getLedger)({
|
|
129
|
+
productIds,
|
|
130
|
+
startDate: new Date((0, dayjs_1.default)(periodFull[0].period.start).utc().toDate().toISOString()),
|
|
131
|
+
endDate: new Date((0, dayjs_1.default)(periodFull[0].period.end).utc().toDate().toISOString()),
|
|
132
|
+
reportType: ledgerType,
|
|
133
|
+
}, { showBalances: false, showFloatedBalance: false });
|
|
134
|
+
const transactions = Object.values(ledgerData).reduce((acc, ledgerTransaction) => [...acc, ...ledgerTransaction], []);
|
|
135
|
+
const transactionsWithoutBalance = lodash_1.default.map(transactions, (obj) => lodash_1.default.omit(obj, ['balance', 'floatedBalance']));
|
|
136
|
+
return [{ transactions: [header, ...transactionsWithoutBalance] }];
|
|
141
137
|
};
|
|
142
138
|
exports.getStatementBorrowersTransactions = getStatementBorrowersTransactions;
|
|
143
139
|
const getBorrowerWithPeriods = async (borrowerId, period, splitPeriods = false) => {
|
package/db/loan-statement.db.ts
CHANGED
|
@@ -103,45 +103,39 @@ export const getStatementBorrowersTransactions = async (start: string, end: stri
|
|
|
103
103
|
if (!selectedBorrowerIds) {
|
|
104
104
|
return [{ transactions: [header] }];
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
|
|
107
|
+
const periodFull = selectedPeriod === 'ENTIRE_LOAN'
|
|
108
|
+
? [{
|
|
109
|
+
period: {
|
|
110
|
+
selectedPeriod: selectedPeriod,
|
|
111
|
+
start: dayjs(start).utc().toDate().toISOString(),
|
|
112
|
+
end: dayjs(end).utc().toDate().toISOString(),
|
|
113
|
+
},
|
|
114
|
+
}]
|
|
115
|
+
: await getBorrowerWithPeriods(selectedBorrowerIds[0], {
|
|
110
116
|
selectedStart: new Date(start),
|
|
111
117
|
selectedEnd: new Date(end),
|
|
112
118
|
selectedPeriod,
|
|
113
119
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
productEnd: periodDesc.period.end,
|
|
120
|
-
productId: product._id.toString(),
|
|
121
|
-
})),
|
|
122
|
-
];
|
|
123
|
-
}, []);
|
|
124
|
-
await Promise.all(someMappedResults.map(async (productDesc) => {
|
|
125
|
-
const borrowerTransactions = await getLedger(
|
|
126
|
-
productDesc.productId,
|
|
127
|
-
new Date(productDesc.productStart),
|
|
128
|
-
new Date(productDesc.productEnd),
|
|
129
|
-
ledgerType,
|
|
130
|
-
true,
|
|
131
|
-
);
|
|
132
|
-
Object.values(borrowerTransactions).forEach((transactions) => {
|
|
133
|
-
const [_header, ...onlyData] = transactions;
|
|
134
|
-
const mappedData = _.map(onlyData, (obj) => _.omit(obj, ['balance', 'floatedBalance']));
|
|
135
|
-
allTransactions[borrowerId] = mappedData;
|
|
136
|
-
});
|
|
137
|
-
}));
|
|
120
|
+
|
|
121
|
+
const allProductIds = [];
|
|
122
|
+
await Promise.all(selectedBorrowerIds.map(async (borrowerId) => {
|
|
123
|
+
const borrowerProducts = await getLoanProducts(borrowerId);
|
|
124
|
+
allProductIds.push(borrowerProducts.map((product) => product._id.toString()));
|
|
138
125
|
}));
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
|
|
127
|
+
const products = await LoanProduct.find({ borrowerId: { $in: selectedBorrowerIds.map((id) => new mongoose.Types.ObjectId(id)) } }).lean();
|
|
128
|
+
const productIds = products.map((product) => product._id.toString());
|
|
129
|
+
const ledgerData = await getLedger({
|
|
130
|
+
productIds,
|
|
131
|
+
startDate: new Date(dayjs(periodFull[0].period.start).utc().toDate().toISOString()),
|
|
132
|
+
endDate: new Date(dayjs(periodFull[0].period.end).utc().toDate().toISOString()),
|
|
133
|
+
reportType: ledgerType,
|
|
134
|
+
}, { showBalances: false, showFloatedBalance: false },
|
|
135
|
+
);
|
|
136
|
+
const transactions = Object.values(ledgerData).reduce((acc, ledgerTransaction) => [...acc, ...ledgerTransaction], []);
|
|
137
|
+
const transactionsWithoutBalance = _.map(transactions, (obj) => _.omit(obj, ['balance', 'floatedBalance']));
|
|
138
|
+
return [{ transactions: [header, ...transactionsWithoutBalance] }];
|
|
145
139
|
};
|
|
146
140
|
|
|
147
141
|
export const getBorrowerWithPeriods = async (borrowerId: string, period: {
|
package/db/reports.db.d.ts
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
+
/// <reference types="mongoose/types/callback" />
|
|
3
|
+
/// <reference types="mongoose/types/collection" />
|
|
4
|
+
/// <reference types="mongoose/types/connection" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor" />
|
|
6
|
+
/// <reference types="mongoose/types/document" />
|
|
7
|
+
/// <reference types="mongoose/types/error" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes" />
|
|
12
|
+
/// <reference types="mongoose/types/models" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
+
/// <reference types="mongoose/types/populate" />
|
|
16
|
+
/// <reference types="mongoose/types/query" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
+
/// <reference types="mongoose/types/session" />
|
|
20
|
+
/// <reference types="mongoose/types/types" />
|
|
21
|
+
/// <reference types="mongoose/types/utility" />
|
|
22
|
+
/// <reference types="mongoose/types/validation" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
+
import { ILoanProductDoc } from '../models/LoanProducts.model';
|
|
1
26
|
import { ELedgerReportType } from './loan-statement.db';
|
|
27
|
+
import mongoose from 'mongoose';
|
|
28
|
+
import { ILoanTransactionDoc } from '../models/LoanTransaction.model';
|
|
2
29
|
export declare enum EChargeType {
|
|
3
30
|
INTEREST_FEE = "INTEREST",
|
|
4
31
|
ADMIN_FEE = "ADMIN FEE",
|
|
@@ -49,8 +76,21 @@ export interface ILedgerDataRow {
|
|
|
49
76
|
paymentDate: Date;
|
|
50
77
|
isBrokerFee?: boolean;
|
|
51
78
|
}
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
export type LedgerTransactions = {
|
|
80
|
+
transactions: ILoanTransactionDoc[];
|
|
81
|
+
product: ILoanProductDoc;
|
|
82
|
+
productId: mongoose.Types.ObjectId;
|
|
83
|
+
};
|
|
84
|
+
export type ReportLedgerParams = {
|
|
85
|
+
productIds: string[];
|
|
86
|
+
startDate: Date;
|
|
87
|
+
endDate: Date;
|
|
88
|
+
reportType: ELedgerReportType;
|
|
89
|
+
};
|
|
90
|
+
export type ReportLedgerOptions = {
|
|
91
|
+
showFloatedBalance: boolean;
|
|
92
|
+
showBalances: boolean;
|
|
93
|
+
};
|
|
94
|
+
export declare const getLedger: (params: ReportLedgerParams, options?: ReportLedgerOptions) => Promise<{
|
|
95
|
+
[productId: string]: ILedgerReportRow[];
|
|
56
96
|
}>;
|