gemcap-be-common 1.3.182 → 1.3.184

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.182",
3
+ "version": "1.3.184",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -181,10 +181,12 @@ 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 });
184
185
  for (const charge of charges) {
185
186
  if (charge.applyFrom.getTime() > statementDate.getTime()) {
186
187
  return;
187
188
  }
189
+ console.log('applying');
188
190
  const statementDateFormat = (0, dayjs_1.default)(statementDate).format('YYYY-MM-DD');
189
191
  let calculateFee = false;
190
192
  switch (charge.frequency) {
@@ -228,6 +230,7 @@ class LoanStatementService {
228
230
  const getBalance = () => {
229
231
  return Math.max(0, useFloating ? balance.floatedBalance : balance.balance);
230
232
  };
233
+ console.log({ calculateFee });
231
234
  if (calculateFee) {
232
235
  let fee = 0;
233
236
  let calculatedFee = 0;
@@ -239,14 +242,15 @@ class LoanStatementService {
239
242
  percentFee = Math.min(Math.max(percentFee, minPercent), maxPercent);
240
243
  }
241
244
  const dailyPercent = new decimal_js_1.default(percentFee).div(daysPerYear).toNumber();
245
+ console.log(charge);
242
246
  switch (charge.calculationBasis) {
243
247
  case loan_types_enum_1.EChargeCalculationBasis.DAILY_BALANCE:
244
- if ((0, dayjs_1.default)(statementDate).isAfter((0, dayjs_1.default)(charge.applyFrom))) {
248
+ 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))) {
245
249
  fee = new decimal_js_1.default(getBalance()).mul(dailyPercent).toDP(2).toNumber();
246
250
  }
247
251
  break;
248
252
  case loan_types_enum_1.EChargeCalculationBasis.AVERAGE_MONTHLY_BALANCE:
249
- if ((0, dayjs_1.default)(statementDate).isAfter((0, dayjs_1.default)(charge.applyFrom))) {
253
+ 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))) {
250
254
  fee = new decimal_js_1.default(getBalance()).mul(percentFee).div(dayInMonth).toDP(2).toNumber();
251
255
  }
252
256
  if (!percentFee && charge.minimumAmount) {
@@ -254,7 +258,7 @@ class LoanStatementService {
254
258
  }
255
259
  break;
256
260
  case loan_types_enum_1.EChargeCalculationBasis.UNUSED_AMOUNT:
257
- if ((0, dayjs_1.default)(statementDate).isAfter((0, dayjs_1.default)(charge.applyFrom))) {
261
+ 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))) {
258
262
  calculatedFee = new decimal_js_1.default(product.commitment).sub(getBalance()).mul(charge.percent).div(daysPerYear).toDP(2).toNumber();
259
263
  fee = Math.max(calculatedFee, 0);
260
264
  }
@@ -263,12 +267,12 @@ class LoanStatementService {
263
267
  fee = new decimal_js_1.default(product.commitment).mul(charge.percent).toDP(2).toNumber();
264
268
  break;
265
269
  case loan_types_enum_1.EChargeCalculationBasis.DISBURSEMENT_AMOUNT:
266
- if ((0, dayjs_1.default)(statementDate).isAfter((0, dayjs_1.default)(charge.applyFrom))) {
270
+ 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))) {
267
271
  fee = await this.calculateDisbursementFee(product._id.toString(), charge, statementDate);
268
272
  }
269
273
  break;
270
274
  case loan_types_enum_1.EChargeCalculationBasis.FIXED:
271
- if ((0, dayjs_1.default)(statementDate).isAfter((0, dayjs_1.default)(charge.applyFrom))) {
275
+ 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))) {
272
276
  calculatedFee = new decimal_js_1.default(getBalance()).mul(dailyPercent).toDP(2).toNumber();
273
277
  fee = Math.max(calculatedFee, charge.minimumAmount);
274
278
  }
@@ -286,7 +290,9 @@ class LoanStatementService {
286
290
  }
287
291
  return fee;
288
292
  };
293
+ console.log({ fee });
289
294
  fee = checkMinAmount(fee);
295
+ console.log({ fee });
290
296
  if (fee !== null && fee > 0) {
291
297
  const newStatement = {
292
298
  order: orderIndex,
@@ -219,10 +219,12 @@ 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 });
222
223
  for (const charge of charges) {
223
224
  if (charge.applyFrom.getTime() > statementDate.getTime()) {
224
225
  return;
225
226
  }
227
+ console.log('applying');
226
228
  const statementDateFormat = dayjs(statementDate).format('YYYY-MM-DD');
227
229
  let calculateFee = false;
228
230
  switch (charge.frequency) {
@@ -269,6 +271,8 @@ export class LoanStatementService {
269
271
  return Math.max(0, useFloating ? balance.floatedBalance : balance.balance);
270
272
  };
271
273
 
274
+ console.log({ calculateFee });
275
+
272
276
  if (calculateFee) {
273
277
  let fee = 0;
274
278
  let calculatedFee = 0;
@@ -280,14 +284,15 @@ export class LoanStatementService {
280
284
  percentFee = Math.min(Math.max(percentFee, minPercent), maxPercent);
281
285
  }
282
286
  const dailyPercent = new Decimal(percentFee).div(daysPerYear).toNumber();
287
+ console.log(charge);
283
288
  switch (charge.calculationBasis) {
284
289
  case EChargeCalculationBasis.DAILY_BALANCE:
285
- if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom))) {
290
+ if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom)) || dayjs(statementDate).isSame(dayjs(charge.applyFrom))) {
286
291
  fee = new Decimal(getBalance()).mul(dailyPercent).toDP(2).toNumber();
287
292
  }
288
293
  break;
289
294
  case EChargeCalculationBasis.AVERAGE_MONTHLY_BALANCE:
290
- if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom))) {
295
+ if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom)) || dayjs(statementDate).isSame(dayjs(charge.applyFrom))) {
291
296
  fee = new Decimal(getBalance()).mul(percentFee).div(dayInMonth).toDP(2).toNumber();
292
297
  }
293
298
  if (!percentFee && charge.minimumAmount) {
@@ -295,7 +300,7 @@ export class LoanStatementService {
295
300
  }
296
301
  break;
297
302
  case EChargeCalculationBasis.UNUSED_AMOUNT:
298
- if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom))) {
303
+ if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom)) || dayjs(statementDate).isSame(dayjs(charge.applyFrom))) {
299
304
  calculatedFee = new Decimal(product.commitment).sub(getBalance()).mul(charge.percent).div(daysPerYear).toDP(2).toNumber();
300
305
  fee = Math.max(calculatedFee, 0);
301
306
  }
@@ -304,12 +309,12 @@ export class LoanStatementService {
304
309
  fee = new Decimal(product.commitment).mul(charge.percent).toDP(2).toNumber();
305
310
  break;
306
311
  case EChargeCalculationBasis.DISBURSEMENT_AMOUNT:
307
- if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom))) {
312
+ if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom)) || dayjs(statementDate).isSame(dayjs(charge.applyFrom))) {
308
313
  fee = await this.calculateDisbursementFee(product._id.toString(), charge, statementDate);
309
314
  }
310
315
  break;
311
316
  case EChargeCalculationBasis.FIXED:
312
- if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom))) {
317
+ if (dayjs(statementDate).isAfter(dayjs(charge.applyFrom)) || dayjs(statementDate).isSame(dayjs(charge.applyFrom))) {
313
318
  calculatedFee = new Decimal(getBalance()).mul(dailyPercent).toDP(2).toNumber();
314
319
  fee = Math.max(calculatedFee, charge.minimumAmount);
315
320
  }
@@ -329,8 +334,12 @@ export class LoanStatementService {
329
334
  return fee;
330
335
  };
331
336
 
337
+ console.log({ fee });
338
+
332
339
  fee = checkMinAmount(fee);
333
340
 
341
+ console.log({ fee });
342
+
334
343
  if (fee !== null && fee > 0) {
335
344
  const newStatement: ILoanStatementTransaction = {
336
345
  order: orderIndex,