gemcap-be-common 1.5.19 → 1.5.21

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.5.19",
3
+ "version": "1.5.21",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -79,7 +79,7 @@ export declare class LoanPaymentsService {
79
79
  success: boolean;
80
80
  message: string;
81
81
  }>;
82
- getExpectedPayments(userId: string, forDate: Date): Promise<any[] | {
82
+ getExpectedPayments(userId: string): Promise<any[] | {
83
83
  borrowers: {
84
84
  borrowerId: string;
85
85
  borrowerTitle: string;
@@ -248,6 +248,7 @@ class LoanPaymentsService {
248
248
  }
249
249
  async recalculateProduct(productId, userId) {
250
250
  const loanCharges = await this.loanChargesService.getLoanChargeForProduct(productId);
251
+ const product = await this.loanChargesService.getLoanProductById(productId);
251
252
  const chargesIds = loanCharges.map((charge) => charge._id);
252
253
  await LoanStatementTransaction_model_1.LoanStatementTransactionModel.updateMany({ 'chargeId': { $in: chargesIds } }, { amountPaid: 0 });
253
254
  const firstStatements = await LoanStatementTransaction_model_1.LoanStatementTransactionModel.aggregate([
@@ -281,7 +282,7 @@ class LoanPaymentsService {
281
282
  ]);
282
283
  for (const [index, payment] of payments.entries()) {
283
284
  try {
284
- console.log(`updating payment ${index + 1}/${payments.length}`, (0, dayjs_1.default)(payment.date).format('DD-MM-YYYY'), payment.amount);
285
+ console.log(`updating payment (for ${product.name}) ${index + 1}/${payments.length}`, (0, dayjs_1.default)(payment.date).format('DD-MM-YYYY'), payment.amount);
285
286
  for (const loanTransaction of payment.loanTransactions) {
286
287
  await LoanTransaction_model_1.LoanTransaction.findByIdAndDelete(loanTransaction.transactionId);
287
288
  }
@@ -292,6 +293,9 @@ class LoanPaymentsService {
292
293
  console.error({ productId, payments });
293
294
  console.error(e);
294
295
  }
296
+ finally {
297
+ console.log(`finished updating payment (for ${product.name}) ${index + 1}/${payments.length}`);
298
+ }
295
299
  }
296
300
  }
297
301
  async getPaymentsForPeriod(productIds, startDate, endDate) {
@@ -400,7 +404,7 @@ class LoanPaymentsService {
400
404
  console.error(e);
401
405
  }
402
406
  }
403
- async getExpectedPayments(userId, forDate) {
407
+ async getExpectedPayments(userId) {
404
408
  const user = await this.usersService.getUserById(userId);
405
409
  if (!user) {
406
410
  return [];
@@ -411,7 +415,7 @@ class LoanPaymentsService {
411
415
  .filter((borrower) => borrower.active)
412
416
  .map(async (borrower) => {
413
417
  const loanStatementService = this.getLoanStatementService();
414
- const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString(), forDate);
418
+ const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString());
415
419
  return {
416
420
  borrowerId: borrower._id.toString(),
417
421
  borrowerTitle: borrower.name,
@@ -442,7 +446,7 @@ class LoanPaymentsService {
442
446
  const borrowerProducts = await this.loanChargesService.getLoanProducts(borrower._id.toString());
443
447
  const revolverProduct = borrowerProducts.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, selectedDate));
444
448
  const loanStatementService = this.getLoanStatementService();
445
- const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString(), selectedDate);
449
+ const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString());
446
450
  if (dueAmounts.total === 0) {
447
451
  console.log('no payment for this borrower');
448
452
  return;
@@ -285,6 +285,7 @@ export class LoanPaymentsService {
285
285
 
286
286
  async recalculateProduct(productId: string, userId: string) {
287
287
  const loanCharges = await this.loanChargesService.getLoanChargeForProduct(productId);
288
+ const product = await this.loanChargesService.getLoanProductById(productId);
288
289
  const chargesIds = loanCharges.map((charge) => charge._id);
289
290
  await LoanStatementTransactionModel.updateMany({ 'chargeId': { $in: chargesIds } }, { amountPaid: 0 });
290
291
 
@@ -321,7 +322,7 @@ export class LoanPaymentsService {
321
322
  ]);
322
323
  for (const [index, payment] of payments.entries()) {
323
324
  try {
324
- console.log(`updating payment ${index + 1}/${payments.length}`, dayjs(payment.date).format('DD-MM-YYYY'), payment.amount);
325
+ console.log(`updating payment (for ${product.name}) ${index + 1}/${payments.length}`, dayjs(payment.date).format('DD-MM-YYYY'), payment.amount);
325
326
  for (const loanTransaction of payment.loanTransactions) {
326
327
  await LoanTransaction.findByIdAndDelete(loanTransaction.transactionId);
327
328
  }
@@ -330,6 +331,8 @@ export class LoanPaymentsService {
330
331
  } catch (e) {
331
332
  console.error({ productId, payments });
332
333
  console.error(e);
334
+ } finally {
335
+ console.log(`finished updating payment (for ${product.name}) ${index + 1}/${payments.length}`);
333
336
  }
334
337
  }
335
338
  }
@@ -447,7 +450,7 @@ export class LoanPaymentsService {
447
450
  }
448
451
  }
449
452
 
450
- async getExpectedPayments(userId: string, forDate: Date) {
453
+ async getExpectedPayments(userId: string) {
451
454
  const user = await this.usersService.getUserById(userId);
452
455
  if (!user) {
453
456
  return [];
@@ -458,7 +461,7 @@ export class LoanPaymentsService {
458
461
  .filter((borrower) => borrower.active)
459
462
  .map(async (borrower) => {
460
463
  const loanStatementService = this.getLoanStatementService();
461
- const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString(), forDate);
464
+ const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString());
462
465
  return {
463
466
  borrowerId: borrower._id.toString(),
464
467
  borrowerTitle: borrower.name,
@@ -493,7 +496,7 @@ export class LoanPaymentsService {
493
496
  const borrowerProducts = await this.loanChargesService.getLoanProducts(borrower._id.toString());
494
497
  const revolverProduct = borrowerProducts.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.startDate, product.deactivationDate, selectedDate));
495
498
  const loanStatementService = this.getLoanStatementService();
496
- const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString(), selectedDate);
499
+ const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString());
497
500
  if (dueAmounts.total === 0) {
498
501
  console.log('no payment for this borrower');
499
502
  return;
@@ -173,7 +173,7 @@ export declare class LoanStatementService {
173
173
  }>;
174
174
  private getOutstandingStatements;
175
175
  getOutstandingStatementsExcel(borrowerIds: string[], selectedDate: Date, fullMonth: boolean): Promise<any>;
176
- getBorrowerProductTotals(borrowerId: string, forDate: Date): Promise<{
176
+ getBorrowerProductTotals(borrowerId: string): Promise<{
177
177
  productTotals: {
178
178
  [productId: string]: number;
179
179
  };
@@ -723,7 +723,7 @@ class LoanStatementService {
723
723
  return (0, loan_statement_db_1.getStatementBorrowersTransactions)(start, end, selectedPeriod, selectedBorrowerIds, ledgerType);
724
724
  }
725
725
  async getBorrowerComplianceData(borrowerId, date) {
726
- const end = (0, dayjs_1.default)(date).utcOffset(0).subtract(1, 'month').endOf('month');
726
+ const end = dayjs_1.default.utc(date).subtract(1, 'month').endOf('month');
727
727
  const start = end.startOf('month');
728
728
  const products = await this.loanChargesService.getLoanProducts(borrowerId);
729
729
  const data = {
@@ -889,8 +889,8 @@ class LoanStatementService {
889
889
  });
890
890
  return await this.uploadsService.convertDataToFile([{ data: [...header, ...onlyData] }]);
891
891
  }
892
- async getBorrowerProductTotals(borrowerId, forDate) {
893
- return await this.getBorrowerComplianceData(borrowerId, forDate);
892
+ async getBorrowerProductTotals(borrowerId) {
893
+ return await this.getBorrowerComplianceData(borrowerId, new Date());
894
894
  }
895
895
  async getProductsTotals(productIds) {
896
896
  const totals = {};
@@ -817,7 +817,7 @@ export class LoanStatementService {
817
817
  }
818
818
 
819
819
  async getBorrowerComplianceData(borrowerId: string, date: Date) {
820
- const end = dayjs(date).utcOffset(0).subtract(1, 'month').endOf('month');
820
+ const end = dayjs.utc(date).subtract(1, 'month').endOf('month');
821
821
  const start = end.startOf('month');
822
822
  const products = await this.loanChargesService.getLoanProducts(borrowerId);
823
823
  const data = {
@@ -992,8 +992,8 @@ export class LoanStatementService {
992
992
  return await this.uploadsService.convertDataToFile([{ data: [...header, ...onlyData] }]);
993
993
  }
994
994
 
995
- async getBorrowerProductTotals(borrowerId: string, forDate: Date) {
996
- return await this.getBorrowerComplianceData(borrowerId, forDate);
995
+ async getBorrowerProductTotals(borrowerId: string) {
996
+ return await this.getBorrowerComplianceData(borrowerId, new Date());
997
997
  }
998
998
 
999
999
  async getProductsTotals(productIds: string[]) {