gemcap-be-common 1.4.115 → 1.4.117
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
|
@@ -777,6 +777,9 @@ class LoanStatementService {
|
|
|
777
777
|
const borrower = await Borrower_model_1.BorrowerModel.findById(borrowerId).lean();
|
|
778
778
|
const products = await this.loanChargesService.getLoanProducts(borrowerId);
|
|
779
779
|
return await Promise.all(products.map(async (product) => {
|
|
780
|
+
if ((0, dayjs_1.default)(product.deactivationDate).isBefore((0, dayjs_1.default)(selectedDate))) {
|
|
781
|
+
return null;
|
|
782
|
+
}
|
|
780
783
|
const relevantStatementEndMonth = fullMonth
|
|
781
784
|
? (0, dayjs_1.default)(selectedDate).utcOffset(0).startOf('month').subtract(1, 'seconds')
|
|
782
785
|
: (0, dayjs_1.default)(selectedDate).utcOffset(0).endOf('month');
|
|
@@ -822,20 +825,22 @@ class LoanStatementService {
|
|
|
822
825
|
}, fees);
|
|
823
826
|
let principal = 0;
|
|
824
827
|
let principalExpectedDate = null;
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
if (calculatedTermLoan
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
828
|
+
if (product.type === loan_types_enum_1.ELoanTypes.TERM) {
|
|
829
|
+
const termLoan = await TermLoan_model_1.TermLoanModel.findOne({ productId: product._id.toString(), actual: true });
|
|
830
|
+
if (termLoan) {
|
|
831
|
+
const calculatedTermLoan = await TermLoanCalculated_model_1.TermLoanCalculatedModel.findOne({
|
|
832
|
+
termLoanId: termLoan._id.toString(),
|
|
833
|
+
relevantStatement: relevantStatementEndMonth.format('YYYY-MM-DD'),
|
|
834
|
+
});
|
|
835
|
+
if (calculatedTermLoan) {
|
|
836
|
+
if (calculatedTermLoan.payments && calculatedTermLoan.payments.length > 0) {
|
|
837
|
+
const totalPayment = calculatedTermLoan.payments.reduce((acc, p) => new decimal_js_1.default(acc ?? 0).add(p.amount ?? 0).toNumber(), 0);
|
|
838
|
+
principal = new decimal_js_1.default(calculatedTermLoan.monthlyPrincipal).sub(totalPayment).toDP(2).toNumber();
|
|
839
|
+
}
|
|
840
|
+
else {
|
|
841
|
+
principal = calculatedTermLoan.monthlyPrincipal;
|
|
842
|
+
principalExpectedDate = calculatedTermLoan.paymentDueDate;
|
|
843
|
+
}
|
|
839
844
|
}
|
|
840
845
|
}
|
|
841
846
|
}
|
|
@@ -871,6 +871,9 @@ export class LoanStatementService {
|
|
|
871
871
|
const borrower = await BorrowerModel.findById(borrowerId).lean();
|
|
872
872
|
const products = await this.loanChargesService.getLoanProducts(borrowerId);
|
|
873
873
|
return await Promise.all(products.map(async (product) => {
|
|
874
|
+
if (dayjs(product.deactivationDate).isBefore(dayjs(selectedDate))) {
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
874
877
|
const relevantStatementEndMonth = fullMonth
|
|
875
878
|
? dayjs(selectedDate).utcOffset(0).startOf('month').subtract(1, 'seconds')
|
|
876
879
|
: dayjs(selectedDate).utcOffset(0).endOf('month');
|
|
@@ -920,19 +923,21 @@ export class LoanStatementService {
|
|
|
920
923
|
|
|
921
924
|
let principal = 0;
|
|
922
925
|
let principalExpectedDate = null;
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
if (calculatedTermLoan
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
926
|
+
if (product.type === ELoanTypes.TERM) {
|
|
927
|
+
const termLoan = await TermLoanModel.findOne({ productId: product._id.toString(), actual: true });
|
|
928
|
+
if (termLoan) {
|
|
929
|
+
const calculatedTermLoan = await TermLoanCalculatedModel.findOne({
|
|
930
|
+
termLoanId: termLoan._id.toString(),
|
|
931
|
+
relevantStatement: relevantStatementEndMonth.format('YYYY-MM-DD'),
|
|
932
|
+
});
|
|
933
|
+
if (calculatedTermLoan) {
|
|
934
|
+
if (calculatedTermLoan.payments && calculatedTermLoan.payments.length > 0) {
|
|
935
|
+
const totalPayment = calculatedTermLoan.payments.reduce((acc, p) => new Decimal(acc ?? 0).add(p.amount ?? 0).toNumber(), 0);
|
|
936
|
+
principal = new Decimal(calculatedTermLoan.monthlyPrincipal).sub(totalPayment).toDP(2).toNumber();
|
|
937
|
+
} else {
|
|
938
|
+
principal = calculatedTermLoan.monthlyPrincipal;
|
|
939
|
+
principalExpectedDate = calculatedTermLoan.paymentDueDate;
|
|
940
|
+
}
|
|
936
941
|
}
|
|
937
942
|
}
|
|
938
943
|
}
|
|
@@ -325,6 +325,9 @@ class ReportsService {
|
|
|
325
325
|
if (product.isParticipant) {
|
|
326
326
|
return null;
|
|
327
327
|
}
|
|
328
|
+
if ((0, dayjs_1.default)(product.deactivationDate).isBefore((0, dayjs_1.default)(date))) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
328
331
|
const isRevolver = product.type === loan_types_enum_1.ELoanTypes.REVOLVER;
|
|
329
332
|
const productMainData = {
|
|
330
333
|
borrowerId,
|
|
@@ -428,6 +428,9 @@ export class ReportsService {
|
|
|
428
428
|
if (product.isParticipant) {
|
|
429
429
|
return null as IBankReportData;
|
|
430
430
|
}
|
|
431
|
+
if (dayjs(product.deactivationDate).isBefore(dayjs(date))) {
|
|
432
|
+
return null as IBankReportData;
|
|
433
|
+
}
|
|
431
434
|
const isRevolver = product.type === ELoanTypes.REVOLVER;
|
|
432
435
|
const productMainData: Partial<IBankReportData> = {
|
|
433
436
|
borrowerId,
|