gemcap-be-common 1.3.184 → 1.3.186

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.3.184",
3
+ "version": "1.3.186",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -152,7 +152,7 @@ class LoanStatementService {
152
152
  await Promise.all(periods.map(async (period) => {
153
153
  const days = this.getDays(period);
154
154
  for (const day of days) {
155
- await this.calculateStatement(productId, period, new Date(day));
155
+ await this.calculateStatement(productId, period, dayjs_1.default.utc(day).toDate());
156
156
  }
157
157
  const statementDate = this.loanStatementStatusService.getStatementDateFromPeriod(period);
158
158
  await this.loanStatementStatusService.updateStatementStatus(productId, statementDate, true);
@@ -166,14 +166,14 @@ class LoanStatementService {
166
166
  }
167
167
  async calculateStatement(productId, period, statementDate) {
168
168
  if (!statementDate) {
169
- statementDate = (0, dayjs_1.default)(new Date()).startOf('day').toDate();
169
+ statementDate = (0, 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) {
173
173
  return;
174
174
  }
175
175
  await this.cleanProductStatement(productId, statementDate);
176
- const balance = await this.loanChargesService.getLoanProductBalance(productId, statementDate);
176
+ const balance = await this.loanChargesService.getLoanProductBalance(productId, dayjs_1.default.utc(statementDate).add(1, 'day').toDate());
177
177
  const loanStatementEffectsService = this.getLoanStatementEffectsService();
178
178
  await loanStatementEffectsService.saveMonthData(productId, statementDate);
179
179
  const charges = await this.loanChargesService.getLoanChargeForProduct(productId);
@@ -181,12 +181,10 @@ class LoanStatementService {
181
181
  const daysPerYear = 360;
182
182
  const dayInMonth = (0, dayjs_1.default)(period.end).diff(period.start, 'days') + 1;
183
183
  let orderIndex = 0;
184
- console.log({ statementDate, balance });
185
184
  for (const charge of charges) {
186
185
  if (charge.applyFrom.getTime() > statementDate.getTime()) {
187
186
  return;
188
187
  }
189
- console.log('applying');
190
188
  const statementDateFormat = (0, dayjs_1.default)(statementDate).format('YYYY-MM-DD');
191
189
  let calculateFee = false;
192
190
  switch (charge.frequency) {
@@ -230,7 +228,6 @@ class LoanStatementService {
230
228
  const getBalance = () => {
231
229
  return Math.max(0, useFloating ? balance.floatedBalance : balance.balance);
232
230
  };
233
- console.log({ calculateFee });
234
231
  if (calculateFee) {
235
232
  let fee = 0;
236
233
  let calculatedFee = 0;
@@ -242,7 +239,6 @@ class LoanStatementService {
242
239
  percentFee = Math.min(Math.max(percentFee, minPercent), maxPercent);
243
240
  }
244
241
  const dailyPercent = new decimal_js_1.default(percentFee).div(daysPerYear).toNumber();
245
- console.log(charge);
246
242
  switch (charge.calculationBasis) {
247
243
  case loan_types_enum_1.EChargeCalculationBasis.DAILY_BALANCE:
248
244
  if ((0, dayjs_1.default)(statementDate).isAfter((0, dayjs_1.default)(charge.applyFrom)) || (0, dayjs_1.default)(statementDate).isSame((0, dayjs_1.default)(charge.applyFrom))) {
@@ -290,9 +286,7 @@ class LoanStatementService {
290
286
  }
291
287
  return fee;
292
288
  };
293
- console.log({ fee });
294
289
  fee = checkMinAmount(fee);
295
- console.log({ fee });
296
290
  if (fee !== null && fee > 0) {
297
291
  const newStatement = {
298
292
  order: orderIndex,
@@ -338,7 +332,7 @@ class LoanStatementService {
338
332
  async getBalancesDaily(productId, period) {
339
333
  const days = this.getDays({ start: (0, dayjs_1.default)(period.start).utcOffset(0), end: (0, dayjs_1.default)(period.end).utcOffset(0) });
340
334
  return Promise.all(days.map(async (day) => {
341
- const balance = await this.loanChargesService.getLoanProductBalance(productId, new Date(day));
335
+ const balance = await this.loanChargesService.getLoanProductBalance(productId, dayjs_1.default.utc(day).toDate());
342
336
  return { day, ...balance };
343
337
  }));
344
338
  }
@@ -185,7 +185,7 @@ export class LoanStatementService {
185
185
  await Promise.all(periods.map(async (period) => {
186
186
  const days = this.getDays(period);
187
187
  for (const day of days) {
188
- await this.calculateStatement(productId, period, new Date(day));
188
+ await this.calculateStatement(productId, period, dayjs.utc(day).toDate());
189
189
  }
190
190
  const statementDate = this.loanStatementStatusService.getStatementDateFromPeriod(period);
191
191
  await this.loanStatementStatusService.updateStatementStatus(productId, statementDate, true);
@@ -201,14 +201,14 @@ export class LoanStatementService {
201
201
 
202
202
  async calculateStatement(productId: string, period: IStatementPeriod, statementDate?: Date) {
203
203
  if (!statementDate) {
204
- statementDate = dayjs(new Date()).startOf('day').toDate();
204
+ statementDate = dayjs().utc().startOf('day').toDate();
205
205
  }
206
206
  const primeRate = await this.financialIndexesService.getFinancialIndexValue(EFinancialIndex.PRIME_RATE, statementDate);
207
207
  if (!primeRate) {
208
208
  return;
209
209
  }
210
210
  await this.cleanProductStatement(productId, statementDate);
211
- const balance = await this.loanChargesService.getLoanProductBalance(productId, statementDate);
211
+ const balance = await this.loanChargesService.getLoanProductBalance(productId, dayjs.utc(statementDate).add(1, 'day').toDate());
212
212
 
213
213
  const loanStatementEffectsService = this.getLoanStatementEffectsService();
214
214
  await loanStatementEffectsService.saveMonthData(productId, statementDate);
@@ -219,12 +219,10 @@ export class LoanStatementService {
219
219
  const daysPerYear = 360;
220
220
  const dayInMonth = dayjs(period.end).diff(period.start, 'days') + 1;
221
221
  let orderIndex = 0;
222
- console.log({ statementDate, balance });
223
222
  for (const charge of charges) {
224
223
  if (charge.applyFrom.getTime() > statementDate.getTime()) {
225
224
  return;
226
225
  }
227
- console.log('applying');
228
226
  const statementDateFormat = dayjs(statementDate).format('YYYY-MM-DD');
229
227
  let calculateFee = false;
230
228
  switch (charge.frequency) {
@@ -271,8 +269,6 @@ export class LoanStatementService {
271
269
  return Math.max(0, useFloating ? balance.floatedBalance : balance.balance);
272
270
  };
273
271
 
274
- console.log({ calculateFee });
275
-
276
272
  if (calculateFee) {
277
273
  let fee = 0;
278
274
  let calculatedFee = 0;
@@ -284,7 +280,6 @@ export class LoanStatementService {
284
280
  percentFee = Math.min(Math.max(percentFee, minPercent), maxPercent);
285
281
  }
286
282
  const dailyPercent = new Decimal(percentFee).div(daysPerYear).toNumber();
287
- console.log(charge);
288
283
  switch (charge.calculationBasis) {
289
284
  case EChargeCalculationBasis.DAILY_BALANCE:
290
285
  if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom)) || dayjs(statementDate).isSame(dayjs(charge.applyFrom))) {
@@ -334,12 +329,8 @@ export class LoanStatementService {
334
329
  return fee;
335
330
  };
336
331
 
337
- console.log({ fee });
338
-
339
332
  fee = checkMinAmount(fee);
340
333
 
341
- console.log({ fee });
342
-
343
334
  if (fee !== null && fee > 0) {
344
335
  const newStatement: ILoanStatementTransaction = {
345
336
  order: orderIndex,
@@ -388,7 +379,7 @@ export class LoanStatementService {
388
379
  async getBalancesDaily(productId: string, period: { start: Date, end: Date }) {
389
380
  const days = this.getDays({ start: dayjs(period.start).utcOffset(0), end: dayjs(period.end).utcOffset(0) });
390
381
  return Promise.all(days.map(async (day) => {
391
- const balance = await this.loanChargesService.getLoanProductBalance(productId, new Date(day));
382
+ const balance = await this.loanChargesService.getLoanProductBalance(productId, dayjs.utc(day).toDate());
392
383
  return { day, ...balance };
393
384
  }));
394
385
  }
@@ -14,6 +14,7 @@ export declare class TermLoanService {
14
14
  private readonly getUploadsService;
15
15
  constructor(financialIndexesService: FinancialIndexesService, loanChargesService: LoanChargesService, getLoanStatementStatusService: () => LoanStatementStatusService, getLoanTransactionsService: () => LoanTransactionsService, getUploadsService: () => UploadsService);
16
16
  private createTermLoan;
17
+ private refreshChargeSettings;
17
18
  private createTermLoanSettings;
18
19
  private getCreateTermLoan;
19
20
  getTermLoan(productId: string, actual: boolean): Promise<ITermLoanView & {
@@ -61,6 +61,27 @@ class TermLoanService {
61
61
  };
62
62
  return TermLoan_model_1.TermLoanModel.findOneAndUpdate({ productId, actual }, newEmptyTerm, { upsert: true, new: true });
63
63
  }
64
+ async refreshChargeSettings(productId, actual) {
65
+ const product = await this.loanChargesService.getLoanProductById(productId);
66
+ const charges = await this.loanChargesService.getLoanChargeForProduct(productId);
67
+ if (charges.length === 0) {
68
+ return null;
69
+ }
70
+ const adminCharge = charges.find((charge) => charge.chargeType === loan_charge_type_enum_1.ELoanChargeType.ADMIN_FEE);
71
+ const interestCharge = charges.find((charge) => charge.chargeType === loan_charge_type_enum_1.ELoanChargeType.INTEREST_FEE);
72
+ if (!adminCharge || !interestCharge) {
73
+ return null;
74
+ }
75
+ const newEmptyTerm = {
76
+ productId: new mongoose_1.default.Types.ObjectId(String(product._id)),
77
+ initialBalance: product.commitment,
78
+ adminRate: adminCharge.percent,
79
+ interestRate: interestCharge.percent,
80
+ loanStartDate: product.startDate,
81
+ actual,
82
+ };
83
+ return TermLoan_model_1.TermLoanModel.findOneAndUpdate({ productId, actual }, newEmptyTerm, { upsert: true, new: true });
84
+ }
64
85
  async createTermLoanSettings(termLoanId) {
65
86
  return TermLoanSettings_model_1.TermLoanSettingsModel.findOneAndUpdate({ termLoanId }, { termLoanId, ...newEmptySettings }, {
66
87
  upsert: true,
@@ -82,6 +82,29 @@ export class TermLoanService {
82
82
  return TermLoanModel.findOneAndUpdate({ productId, actual }, newEmptyTerm, { upsert: true, new: true });
83
83
  }
84
84
 
85
+ private async refreshChargeSettings(productId: string, actual: boolean) {
86
+ const product = await this.loanChargesService.getLoanProductById(productId);
87
+ const charges = await this.loanChargesService.getLoanChargeForProduct(productId);
88
+ if (charges.length === 0) {
89
+ return null;
90
+ }
91
+ const adminCharge = charges.find((charge) => charge.chargeType === ELoanChargeType.ADMIN_FEE);
92
+ const interestCharge = charges.find((charge) => charge.chargeType === ELoanChargeType.INTEREST_FEE);
93
+ if (!adminCharge || !interestCharge) {
94
+ return null;
95
+ }
96
+
97
+ const newEmptyTerm: Partial<ITermLoan> = {
98
+ productId: new mongoose.Types.ObjectId(String(product._id)),
99
+ initialBalance: product.commitment,
100
+ adminRate: adminCharge.percent,
101
+ interestRate: interestCharge.percent,
102
+ loanStartDate: product.startDate,
103
+ actual,
104
+ };
105
+ return TermLoanModel.findOneAndUpdate({ productId, actual }, newEmptyTerm, { upsert: true, new: true });
106
+ }
107
+
85
108
  private async createTermLoanSettings(termLoanId: string) {
86
109
  return TermLoanSettingsModel.findOneAndUpdate({ termLoanId }, { termLoanId, ...newEmptySettings }, {
87
110
  upsert: true,