gemcap-be-common 1.5.21 → 1.5.23
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/new-summary.js +2 -1
- package/db/new-summary.ts +2 -1
- package/package.json +1 -1
- package/services/loan-payments.service.js +4 -4
- package/services/loan-payments.service.ts +4 -4
- package/services/loan-statement.service.js +1 -1
- package/services/loan-statement.service.ts +1 -1
- package/services/loan-transactions.service.js +3 -1
- package/services/loan-transactions.service.ts +3 -1
- package/services/nodemailer.service.js +2 -1
- package/services/nodemailer.service.ts +2 -1
- package/tsconfig.tsbuildinfo +1 -1
package/db/new-summary.js
CHANGED
|
@@ -28,6 +28,7 @@ const ProspectIndustry_model_1 = require("../models/ProspectIndustry.model");
|
|
|
28
28
|
const financial_spreading_service_1 = require("../services/financial-spreading.service");
|
|
29
29
|
const MonthEndData_Model_1 = require("../models/MonthEndData.Model");
|
|
30
30
|
const Yield_model_1 = require("../models/Yield.model");
|
|
31
|
+
const date_helper_1 = require("../helpers/date.helper");
|
|
31
32
|
const styles = {
|
|
32
33
|
blackOnWhiteWithTopBorder: {
|
|
33
34
|
fill: {
|
|
@@ -561,7 +562,7 @@ class NewSummaryExcel {
|
|
|
561
562
|
});
|
|
562
563
|
// TERM LOAN
|
|
563
564
|
const getTermLoanSection = async () => {
|
|
564
|
-
const termProduct = [...productsMap.values()].find((product) => product.borrowerId.toString() === borrowerId && product.type === loan_types_enum_1.ELoanTypes.TERM && product.
|
|
565
|
+
const termProduct = [...productsMap.values()].find((product) => product.borrowerId.toString() === borrowerId && product.type === loan_types_enum_1.ELoanTypes.TERM && (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, new Date()));
|
|
565
566
|
if (!termProduct || !availability) {
|
|
566
567
|
return [emptyRow];
|
|
567
568
|
}
|
package/db/new-summary.ts
CHANGED
|
@@ -44,6 +44,7 @@ import { SignsService } from '../services/signs.service';
|
|
|
44
44
|
import { MonthEndDataService } from '../services/month-end-data.service';
|
|
45
45
|
import { EMonthEndDataType } from '../models/MonthEndData.Model';
|
|
46
46
|
import { ETotalType, YIELD_TOTALS_MAP } from '../models/Yield.model';
|
|
47
|
+
import { isProductActive } from '../helpers/date.helper';
|
|
47
48
|
|
|
48
49
|
type DataSheet = {
|
|
49
50
|
[p: string]: IExcelJsCell[][]
|
|
@@ -661,7 +662,7 @@ export class NewSummaryExcel {
|
|
|
661
662
|
|
|
662
663
|
// TERM LOAN
|
|
663
664
|
const getTermLoanSection = async (): Promise<IExcelJsCell[][]> => {
|
|
664
|
-
const termProduct = [...productsMap.values()].find((product) => product.borrowerId.toString() === borrowerId && product.type === ELoanTypes.TERM && product.
|
|
665
|
+
const termProduct = [...productsMap.values()].find((product) => product.borrowerId.toString() === borrowerId && product.type === ELoanTypes.TERM && isProductActive(product.startDate, product.deactivationDate, new Date()));
|
|
665
666
|
if (!termProduct || !availability) {
|
|
666
667
|
return [emptyRow];
|
|
667
668
|
}
|
package/package.json
CHANGED
|
@@ -283,9 +283,9 @@ class LoanPaymentsService {
|
|
|
283
283
|
for (const [index, payment] of payments.entries()) {
|
|
284
284
|
try {
|
|
285
285
|
console.log(`updating payment (for ${product.name}) ${index + 1}/${payments.length}`, (0, dayjs_1.default)(payment.date).format('DD-MM-YYYY'), payment.amount);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
286
|
+
await LoanTransaction_model_1.LoanTransaction.deleteMany({
|
|
287
|
+
_id: { $in: payment.loanTransactions.map(t => t.transactionId) }
|
|
288
|
+
});
|
|
289
289
|
await LoanPayment_model_1.LoanPaymentModel.findByIdAndUpdate(payment._id, { paid: [], loanTransactions: [] });
|
|
290
290
|
await this.updateLoanPayment(payment, userId);
|
|
291
291
|
}
|
|
@@ -334,7 +334,7 @@ class LoanPaymentsService {
|
|
|
334
334
|
const data = await loanStatementService.getBorrowerComplianceData(combinedPayment.borrowerId, new Date());
|
|
335
335
|
let totalSumToCover = combinedPayment.payment;
|
|
336
336
|
const products = await this.loanChargesService.getLoanProducts(combinedPayment.borrowerId);
|
|
337
|
-
const revolverProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0,
|
|
337
|
+
const revolverProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, combinedPayment.date));
|
|
338
338
|
for (const p of combinedPayment.products) {
|
|
339
339
|
await this.loanProductsService.savePaymentOrder(p.productId, p.paymentOrder);
|
|
340
340
|
const desiredProductSum = data.productTotals[p.productId];
|
|
@@ -323,9 +323,9 @@ export class LoanPaymentsService {
|
|
|
323
323
|
for (const [index, payment] of payments.entries()) {
|
|
324
324
|
try {
|
|
325
325
|
console.log(`updating payment (for ${product.name}) ${index + 1}/${payments.length}`, dayjs(payment.date).format('DD-MM-YYYY'), payment.amount);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
326
|
+
await LoanTransaction.deleteMany({
|
|
327
|
+
_id: { $in: payment.loanTransactions.map(t => t.transactionId) }
|
|
328
|
+
});
|
|
329
329
|
await LoanPaymentModel.findByIdAndUpdate(payment._id, { paid: [], loanTransactions: [] });
|
|
330
330
|
await this.updateLoanPayment(payment as Partial<ILoanPaymentWithId>, userId);
|
|
331
331
|
} catch (e) {
|
|
@@ -375,7 +375,7 @@ export class LoanPaymentsService {
|
|
|
375
375
|
const data = await loanStatementService.getBorrowerComplianceData(combinedPayment.borrowerId, new Date());
|
|
376
376
|
let totalSumToCover = combinedPayment.payment;
|
|
377
377
|
const products = await this.loanChargesService.getLoanProducts(combinedPayment.borrowerId);
|
|
378
|
-
const revolverProduct = products.find((product) => product.type === ELoanTypes.REVOLVER &&
|
|
378
|
+
const revolverProduct = products.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.startDate, product.deactivationDate, combinedPayment.date));
|
|
379
379
|
|
|
380
380
|
for (const p of combinedPayment.products) {
|
|
381
381
|
await this.loanProductsService.savePaymentOrder(p.productId, p.paymentOrder);
|
|
@@ -166,7 +166,7 @@ class LoanStatementService {
|
|
|
166
166
|
}
|
|
167
167
|
async calculateStatement(productId, period, statementDate) {
|
|
168
168
|
if (!statementDate) {
|
|
169
|
-
statementDate =
|
|
169
|
+
statementDate = dayjs_1.default.utc().startOf('day').toDate();
|
|
170
170
|
}
|
|
171
171
|
const primeRate = await this.financialIndexesService.getFinancialIndexValue(financial_indexes_service_1.EFinancialIndex.PRIME_RATE, statementDate);
|
|
172
172
|
if (!primeRate) {
|
|
@@ -201,7 +201,7 @@ export class LoanStatementService {
|
|
|
201
201
|
|
|
202
202
|
async calculateStatement(productId: string, period: IStatementPeriod, statementDate?: Date) {
|
|
203
203
|
if (!statementDate) {
|
|
204
|
-
statementDate = dayjs
|
|
204
|
+
statementDate = dayjs.utc().startOf('day').toDate();
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
const primeRate = await this.financialIndexesService.getFinancialIndexValue(EFinancialIndex.PRIME_RATE, statementDate);
|
|
@@ -176,8 +176,10 @@ class LoanTransactionsService {
|
|
|
176
176
|
}));
|
|
177
177
|
}
|
|
178
178
|
async getDisbursementTransactions(productId, date) {
|
|
179
|
+
const startOfDay = dayjs_1.default.utc(date).startOf('day').toDate();
|
|
180
|
+
const endOfDay = dayjs_1.default.utc(date).endOf('day').toDate();
|
|
179
181
|
return LoanTransaction_model_1.LoanTransaction.countDocuments({
|
|
180
|
-
date:
|
|
182
|
+
date: { $gte: startOfDay, $lte: endOfDay },
|
|
181
183
|
productId: new mongoose_1.default.Types.ObjectId(productId),
|
|
182
184
|
transactionType: LoanTransaction_model_1.ELoanTransactionTypes.DISBURSEMENT,
|
|
183
185
|
bankId: { $ne: null },
|
|
@@ -218,9 +218,11 @@ export class LoanTransactionsService {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
async getDisbursementTransactions(productId: string, date: Date) {
|
|
221
|
+
const startOfDay = dayjs.utc(date).startOf('day').toDate();
|
|
222
|
+
const endOfDay = dayjs.utc(date).endOf('day').toDate();
|
|
221
223
|
return LoanTransaction.countDocuments(
|
|
222
224
|
{
|
|
223
|
-
date:
|
|
225
|
+
date: { $gte: startOfDay, $lte: endOfDay },
|
|
224
226
|
productId: new mongoose.Types.ObjectId(productId),
|
|
225
227
|
transactionType: ELoanTransactionTypes.DISBURSEMENT,
|
|
226
228
|
bankId: { $ne: null },
|
|
@@ -35,6 +35,7 @@ const loan_types_enum_1 = require("../enums/loan-types.enum");
|
|
|
35
35
|
const Organization_model_1 = require("../models/Organization.model");
|
|
36
36
|
const FinancialCompliance_model_1 = __importDefault(require("../models/FinancialCompliance.model"));
|
|
37
37
|
const OrganizationEmails_model_1 = require("../models/OrganizationEmails.model");
|
|
38
|
+
const date_helper_1 = require("../helpers/date.helper");
|
|
38
39
|
var ESenderType;
|
|
39
40
|
(function (ESenderType) {
|
|
40
41
|
ESenderType[ESenderType["REGULAR"] = 0] = "REGULAR";
|
|
@@ -406,7 +407,7 @@ class NodemailerService {
|
|
|
406
407
|
const borrower = await this.borrowerService.getBorrowerById(borrowerId);
|
|
407
408
|
const organization = await this.organizationsService.getOrganizationForBorrower(borrowerId);
|
|
408
409
|
const products = await this.loanChargesService.getLoanProducts(borrower._id.toString());
|
|
409
|
-
const borrowerHasRevolver = products.filter((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && product.
|
|
410
|
+
const borrowerHasRevolver = products.filter((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, new Date())).length > 0;
|
|
410
411
|
const textPath = path_1.default.resolve(__dirname, '../public/emails', organization.subfolder, borrowerHasRevolver ? 'interest-statement.html' : 'interest-statement-only-term.html');
|
|
411
412
|
const text = await fs.promises.readFile(textPath, 'utf8');
|
|
412
413
|
const signature = await this.getSignatureAsync(ESenderType.FINANCIAL, organization.subfolder);
|
|
@@ -21,6 +21,7 @@ import { LoanChargesService } from './loan-charges.service';
|
|
|
21
21
|
import { OrganizationEmailsService } from './organization-emails.service';
|
|
22
22
|
import { OrganizationsService } from './organizations.service';
|
|
23
23
|
import { SentryService } from './sentry.service';
|
|
24
|
+
import { isProductActive } from '../helpers/date.helper';
|
|
24
25
|
|
|
25
26
|
export enum ESenderType {
|
|
26
27
|
REGULAR,
|
|
@@ -472,7 +473,7 @@ export class NodemailerService {
|
|
|
472
473
|
const borrower = await this.borrowerService.getBorrowerById(borrowerId);
|
|
473
474
|
const organization = await this.organizationsService.getOrganizationForBorrower(borrowerId);
|
|
474
475
|
const products = await this.loanChargesService.getLoanProducts(borrower._id.toString());
|
|
475
|
-
const borrowerHasRevolver = products.filter((product) => product.type === ELoanTypes.REVOLVER && product.
|
|
476
|
+
const borrowerHasRevolver = products.filter((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.startDate, product.deactivationDate, new Date())).length > 0;
|
|
476
477
|
const textPath = path.resolve(__dirname, '../public/emails', organization.subfolder, borrowerHasRevolver ? 'interest-statement.html' : 'interest-statement-only-term.html');
|
|
477
478
|
const text = await fs.promises.readFile(textPath, 'utf8');
|
|
478
479
|
const signature = await this.getSignatureAsync(ESenderType.FINANCIAL, organization.subfolder);
|