gemcap-be-common 1.5.57 → 1.5.58

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/reports.db.js CHANGED
@@ -207,7 +207,7 @@ const getLedgerData = async (params, options = defaultReportLedgerOptions) => {
207
207
  };
208
208
  }))
209
209
  : statementTransactions.slice();
210
- const isParticipant = group.product.isParticipant;
210
+ const isParticipant = group.product.masterLoanProductId !== undefined;
211
211
  const groupedMappedStatementTransactions = await Promise.all(statementTransactionsWithBalance.map(async (statement) => {
212
212
  const transactions = [];
213
213
  if (statement.amountPaid > 0) {
package/db/reports.db.ts CHANGED
@@ -285,7 +285,7 @@ const getLedgerData = async (params: ReportLedgerParams, options = defaultReport
285
285
  }))
286
286
  : statementTransactions.slice();
287
287
 
288
- const isParticipant = group.product.isParticipant;
288
+ const isParticipant = group.product.masterLoanProductId !== undefined;
289
289
  const groupedMappedStatementTransactions = await Promise.all(statementTransactionsWithBalance.map(async (statement) => {
290
290
 
291
291
  const transactions = [];
@@ -30,7 +30,7 @@ export interface ILoanProduct {
30
30
  order: number;
31
31
  active: boolean;
32
32
  code: string;
33
- masterCode: string;
33
+ masterCode?: string;
34
34
  name: string;
35
35
  type: ELoanTypes;
36
36
  startDate: Date;
@@ -39,7 +39,8 @@ export interface ILoanProduct {
39
39
  commitment: number;
40
40
  isBalanceActual: boolean;
41
41
  isFloatedBalanceActual: boolean;
42
- isParticipant: boolean;
42
+ isParticipant?: boolean;
43
+ masterLoanProductId?: mongoose.Types.ObjectId;
43
44
  minPercent: number;
44
45
  maxPercent: number;
45
46
  prepaymentDate?: Date;
@@ -81,80 +82,83 @@ export declare const LoanProductSchema: mongoose.Schema<any, mongoose.Model<any,
81
82
  createdAt: NativeDate;
82
83
  updatedAt: NativeDate;
83
84
  } & {
85
+ borrowerId: mongoose.Types.ObjectId;
86
+ order: number;
87
+ active: boolean;
84
88
  code: string;
85
89
  name: string;
86
- active: boolean;
87
90
  type: string;
88
- order: number;
89
- borrowerId: mongoose.Types.ObjectId;
90
91
  startDate: Date;
91
92
  maturityDate: Date;
92
93
  commitment: number;
93
94
  isBalanceActual: boolean;
94
95
  isFloatedBalanceActual: boolean;
95
- isParticipant: boolean;
96
96
  isDefaultPaymentOrder: boolean;
97
- __v?: number;
98
- settlementCode?: string;
99
97
  masterCode?: string;
100
98
  payoffDate?: Date;
99
+ isParticipant?: boolean;
100
+ masterLoanProductId?: mongoose.Types.ObjectId;
101
101
  minPercent?: number;
102
102
  maxPercent?: number;
103
103
  prepaymentDate?: Date;
104
104
  prepaymentTerms?: string;
105
+ settlementCode?: string;
105
106
  deactivationDate?: Date;
107
+ __v?: number;
106
108
  }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
107
109
  createdAt: NativeDate;
108
110
  updatedAt: NativeDate;
109
111
  } & {
112
+ borrowerId: mongoose.Types.ObjectId;
113
+ order: number;
114
+ active: boolean;
110
115
  code: string;
111
116
  name: string;
112
- active: boolean;
113
117
  type: string;
114
- order: number;
115
- borrowerId: mongoose.Types.ObjectId;
116
118
  startDate: Date;
117
119
  maturityDate: Date;
118
120
  commitment: number;
119
121
  isBalanceActual: boolean;
120
122
  isFloatedBalanceActual: boolean;
121
- isParticipant: boolean;
122
123
  isDefaultPaymentOrder: boolean;
123
- __v?: number;
124
- settlementCode?: string;
125
124
  masterCode?: string;
126
125
  payoffDate?: Date;
126
+ isParticipant?: boolean;
127
+ masterLoanProductId?: mongoose.Types.ObjectId;
127
128
  minPercent?: number;
128
129
  maxPercent?: number;
129
130
  prepaymentDate?: Date;
130
131
  prepaymentTerms?: string;
132
+ settlementCode?: string;
131
133
  deactivationDate?: Date;
134
+ __v?: number;
132
135
  }>> & mongoose.FlatRecord<{
133
136
  createdAt: NativeDate;
134
137
  updatedAt: NativeDate;
135
138
  } & {
139
+ borrowerId: mongoose.Types.ObjectId;
140
+ order: number;
141
+ active: boolean;
136
142
  code: string;
137
143
  name: string;
138
- active: boolean;
139
144
  type: string;
140
- order: number;
141
- borrowerId: mongoose.Types.ObjectId;
142
145
  startDate: Date;
143
146
  maturityDate: Date;
144
147
  commitment: number;
145
148
  isBalanceActual: boolean;
146
149
  isFloatedBalanceActual: boolean;
147
- isParticipant: boolean;
148
150
  isDefaultPaymentOrder: boolean;
149
- __v?: number;
150
- settlementCode?: string;
151
151
  masterCode?: string;
152
152
  payoffDate?: Date;
153
+ isParticipant?: boolean;
154
+ masterLoanProductId?: mongoose.Types.ObjectId;
153
155
  minPercent?: number;
154
156
  maxPercent?: number;
155
157
  prepaymentDate?: Date;
156
158
  prepaymentTerms?: string;
159
+ settlementCode?: string;
157
160
  deactivationDate?: Date;
161
+ __v?: number;
158
162
  }> & {
159
163
  _id: mongoose.Types.ObjectId;
160
164
  }>;
@@ -27,7 +27,7 @@ exports.LoanProductSchema = new mongoose_1.default.Schema({
27
27
  },
28
28
  masterCode: {
29
29
  type: String,
30
- trim: true,
30
+ trim: false,
31
31
  },
32
32
  name: {
33
33
  type: String,
@@ -66,7 +66,12 @@ exports.LoanProductSchema = new mongoose_1.default.Schema({
66
66
  },
67
67
  isParticipant: {
68
68
  type: Boolean,
69
- required: true,
69
+ required: false,
70
+ },
71
+ masterLoanProductId: {
72
+ type: mongoose_1.default.Schema.Types.ObjectId,
73
+ ref: _models_1.MODEL_NAMES.loanProducts,
74
+ required: false,
70
75
  },
71
76
  minPercent: {
72
77
  type: Number,
@@ -9,7 +9,7 @@ export interface ILoanProduct {
9
9
  order: number;
10
10
  active: boolean;
11
11
  code: string;
12
- masterCode: string;
12
+ masterCode?: string;
13
13
  name: string;
14
14
  type: ELoanTypes;
15
15
  startDate: Date;
@@ -18,7 +18,8 @@ export interface ILoanProduct {
18
18
  commitment: number;
19
19
  isBalanceActual: boolean;
20
20
  isFloatedBalanceActual: boolean;
21
- isParticipant: boolean;
21
+ isParticipant?: boolean;
22
+ masterLoanProductId?: mongoose.Types.ObjectId;
22
23
  minPercent: number;
23
24
  maxPercent: number;
24
25
  prepaymentDate?: Date;
@@ -85,7 +86,7 @@ export const LoanProductSchema = new mongoose.Schema(
85
86
  },
86
87
  masterCode: {
87
88
  type: String,
88
- trim: true,
89
+ trim: false,
89
90
  },
90
91
  name: {
91
92
  type: String,
@@ -124,7 +125,12 @@ export const LoanProductSchema = new mongoose.Schema(
124
125
  },
125
126
  isParticipant: {
126
127
  type: Boolean,
127
- required: true,
128
+ required: false,
129
+ },
130
+ masterLoanProductId: {
131
+ type: mongoose.Schema.Types.ObjectId,
132
+ ref: MODEL_NAMES.loanProducts,
133
+ required: false,
128
134
  },
129
135
  minPercent: {
130
136
  type: Number,
@@ -31,8 +31,8 @@ export declare const allSchemas: {
31
31
  createdAt: NativeDate;
32
32
  updatedAt: NativeDate;
33
33
  } & {
34
- bbcSheetId: import("mongoose").Types.ObjectId;
35
34
  order: number;
35
+ bbcSheetId: import("mongoose").Types.ObjectId;
36
36
  apDate: Date;
37
37
  amount: number;
38
38
  __v?: number;
@@ -45,8 +45,8 @@ export declare const allSchemas: {
45
45
  createdAt: NativeDate;
46
46
  updatedAt: NativeDate;
47
47
  } & {
48
- bbcSheetId: import("mongoose").Types.ObjectId;
49
48
  order: number;
49
+ bbcSheetId: import("mongoose").Types.ObjectId;
50
50
  apDate: Date;
51
51
  amount: number;
52
52
  __v?: number;
@@ -59,8 +59,8 @@ export declare const allSchemas: {
59
59
  createdAt: NativeDate;
60
60
  updatedAt: NativeDate;
61
61
  } & {
62
- bbcSheetId: import("mongoose").Types.ObjectId;
63
62
  order: number;
63
+ bbcSheetId: import("mongoose").Types.ObjectId;
64
64
  apDate: Date;
65
65
  amount: number;
66
66
  __v?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.5.57",
3
+ "version": "1.5.58",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -84,10 +84,10 @@ export declare class BorrowerService {
84
84
  getBorrowerCodesMap(): Promise<Map<string, string>>;
85
85
  getBorrowerStatementDetails(borrowers: IBorrowerDoc[]): Promise<{
86
86
  [x: string]: {
87
+ SELECTED_PERIOD?: boolean;
88
+ ENTIRE_LOAN?: boolean;
87
89
  LAST_MONTH?: boolean;
88
90
  CURRENT_MONTH?: boolean;
89
- ENTIRE_LOAN?: boolean;
90
- SELECTED_PERIOD?: boolean;
91
91
  TERM_LOAN?: boolean;
92
92
  };
93
93
  }>;
@@ -81,11 +81,15 @@ class LoanChargesService {
81
81
  return (0, loan_products_db_1.getLoanProductBalance)(productId, forDate);
82
82
  }
83
83
  async getParticipationBalance(code, end) {
84
- const masterProduct = await LoanProducts_model_1.LoanProduct.findOne({ masterCode: code }).lean();
84
+ const masterProduct = await LoanProducts_model_1.LoanProduct.findOne({ code }).lean();
85
85
  if (!masterProduct) {
86
86
  return 0;
87
87
  }
88
- const { balance } = await this.getLoanProductBalance(masterProduct._id.toString(), end);
88
+ const participationProduct = await LoanProducts_model_1.LoanProduct.findOne({ masterLoanProductId: masterProduct._id }).lean();
89
+ if (!participationProduct) {
90
+ return 0;
91
+ }
92
+ const { balance } = await this.getLoanProductBalance(participationProduct._id.toString(), end);
89
93
  return balance;
90
94
  }
91
95
  ;
@@ -108,11 +108,15 @@ export class LoanChargesService {
108
108
  }
109
109
 
110
110
  async getParticipationBalance(code: string, end: Date){
111
- const masterProduct = await LoanProduct.findOne({ masterCode: code }).lean();
111
+ const masterProduct = await LoanProduct.findOne({ code }).lean();
112
112
  if (!masterProduct) {
113
113
  return 0;
114
114
  }
115
- const { balance } = await this.getLoanProductBalance(masterProduct._id.toString(), end);
115
+ const participationProduct = await LoanProduct.findOne({ masterLoanProductId: masterProduct._id }).lean();
116
+ if (!participationProduct) {
117
+ return 0;
118
+ }
119
+ const { balance } = await this.getLoanProductBalance(participationProduct._id.toString(), end);
116
120
  return balance;
117
121
  };
118
122
 
@@ -22,8 +22,10 @@ class LoanProductsService {
22
22
  this.borrowersDB = borrowersDB;
23
23
  }
24
24
  async getLinkedLoanProducts(codes) {
25
+ const masterProducts = await LoanProducts_model_1.LoanProduct.find({ code: { $in: codes } });
26
+ const masterProductIds = masterProducts.map((product) => product._id);
25
27
  const loanProducts = await LoanProducts_model_1.LoanProduct
26
- .find({ isParticipant: true, masterCode: { $in: codes } })
28
+ .find({ masterLoanProductId: { $in: masterProductIds } })
27
29
  .sort({ code: 1 })
28
30
  .lean();
29
31
  return loanProducts.reduce((acc, loanProduct) => ({ ...acc, [loanProduct.code]: loanProduct._id.toString() }), {});
@@ -26,8 +26,10 @@ export class LoanProductsService {
26
26
  }
27
27
 
28
28
  async getLinkedLoanProducts(codes: string[]): Promise<{ [code: string]: string }> {
29
+ const masterProducts = await LoanProduct.find({ code: { $in: codes } });
30
+ const masterProductIds = masterProducts.map((product) => product._id);
29
31
  const loanProducts = await LoanProduct
30
- .find({ isParticipant: true, masterCode: { $in: codes } })
32
+ .find({ masterLoanProductId: { $in: masterProductIds } })
31
33
  .sort({ code: 1 })
32
34
  .lean();
33
35
  return loanProducts.reduce((acc, loanProduct) => ({ ...acc, [loanProduct.code]: loanProduct._id.toString() }), {});
@@ -357,7 +357,7 @@ class QuickbooksService {
357
357
  if (totalAmountValue === 0) {
358
358
  return;
359
359
  }
360
- let totalAmount = product.isParticipant ? -totalAmountValue : totalAmountValue;
360
+ let totalAmount = product.masterLoanProductId !== undefined ? -totalAmountValue : totalAmountValue;
361
361
  totalAmount = isAccrual ? totalAmount : -totalAmount;
362
362
  const quickbooksAccountBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: charge.code, ...companyFilter }).lean();
363
363
  const quickbooksAccountPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: PLCode, ...companyFilter }).lean();
@@ -374,7 +374,7 @@ class QuickbooksService {
374
374
  ...trTemplate,
375
375
  productId,
376
376
  class: borrower.code,
377
- memo: `${borrower.code} ${product.isParticipant ? 'PARTICIPANT' : ''} ${reports_db_1.EChargeType[charge.chargeType].toUpperCase()} ${product.type.toUpperCase()} - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
377
+ memo: `${borrower.code} ${product.masterLoanProductId !== undefined ? 'PARTICIPANT' : ''} ${reports_db_1.EChargeType[charge.chargeType].toUpperCase()} ${product.type.toUpperCase()} - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
378
378
  };
379
379
  tr.account = quickbooksAccountBS.fullName;
380
380
  tr.amount = totalAmount;
@@ -429,8 +429,8 @@ class QuickbooksService {
429
429
  ...trTemplate,
430
430
  productId,
431
431
  class: borrower.code,
432
- amount: product.isParticipant ? +amount : -+amount,
433
- memo: `${borrower.code} ${product.isParticipant ? 'PARTICIPANT' : ''} PRINCIPAL PAID TERM - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
432
+ amount: product.masterLoanProductId !== undefined ? +amount : -+amount,
433
+ memo: `${borrower.code} ${product.masterLoanProductId !== undefined ? 'PARTICIPANT' : ''} PRINCIPAL PAID TERM - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
434
434
  };
435
435
  if (settlementCode === 'null') {
436
436
  const products = await this.loanChargesService.getLoanProducts(borrower._id.toString());
@@ -416,7 +416,7 @@ export class QuickbooksService {
416
416
  if (totalAmountValue === 0) {
417
417
  return;
418
418
  }
419
- let totalAmount = product.isParticipant ? -totalAmountValue : totalAmountValue;
419
+ let totalAmount = product.masterLoanProductId !== undefined ? -totalAmountValue : totalAmountValue;
420
420
  totalAmount = isAccrual ? totalAmount : -totalAmount;
421
421
  const quickbooksAccountBS = await QuickbooksAccount.findOne({ accountCode: charge.code, ...companyFilter }).lean();
422
422
  const quickbooksAccountPL = await QuickbooksAccount.findOne({ accountCode: PLCode, ...companyFilter }).lean();
@@ -433,7 +433,7 @@ export class QuickbooksService {
433
433
  ...trTemplate,
434
434
  productId,
435
435
  class: borrower.code,
436
- memo: `${borrower.code} ${product.isParticipant ? 'PARTICIPANT' : ''} ${EChargeType[charge.chargeType].toUpperCase()} ${product.type.toUpperCase()} - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
436
+ memo: `${borrower.code} ${product.masterLoanProductId !== undefined ? 'PARTICIPANT' : ''} ${EChargeType[charge.chargeType].toUpperCase()} ${product.type.toUpperCase()} - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
437
437
  };
438
438
 
439
439
  tr.account = quickbooksAccountBS.fullName;
@@ -500,8 +500,8 @@ export class QuickbooksService {
500
500
  ...trTemplate,
501
501
  productId,
502
502
  class: borrower.code,
503
- amount: product.isParticipant ? +amount : -+amount,
504
- memo: `${borrower.code} ${product.isParticipant ? 'PARTICIPANT' : ''} PRINCIPAL PAID TERM - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
503
+ amount: product.masterLoanProductId !== undefined ? +amount : -+amount,
504
+ memo: `${borrower.code} ${product.masterLoanProductId !== undefined ? 'PARTICIPANT' : ''} PRINCIPAL PAID TERM - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
505
505
  };
506
506
 
507
507
  if (settlementCode === 'null') {
@@ -76,7 +76,7 @@ class InvestorSummaryService {
76
76
  await Promise.all(borrowerIds.map(async (borrowerId) => {
77
77
  const borrower = await Borrower_model_1.BorrowerModel.findById(borrowerId).lean();
78
78
  const borrowerProducts = await this.loanChargesService.getLoanProducts(borrowerId);
79
- await Promise.all(borrowerProducts.filter((product) => !product.isParticipant).map(async (product) => {
79
+ await Promise.all(borrowerProducts.filter((product) => product.masterLoanProductId === undefined).map(async (product) => {
80
80
  const productId = product._id.toString();
81
81
  const isRevolver = product.type === loan_types_enum_1.ELoanTypes.REVOLVER;
82
82
  const { balance: balanceEnd } = await this.loanChargesService.getLoanProductBalance(productId, end);
@@ -100,7 +100,7 @@ export class InvestorSummaryService {
100
100
  await Promise.all(borrowerIds.map(async (borrowerId) => {
101
101
  const borrower = await BorrowerModel.findById(borrowerId).lean();
102
102
  const borrowerProducts = await this.loanChargesService.getLoanProducts(borrowerId);
103
- await Promise.all(borrowerProducts.filter((product) => !product.isParticipant).map(async (product) => {
103
+ await Promise.all(borrowerProducts.filter((product) => product.masterLoanProductId === undefined).map(async (product) => {
104
104
  const productId = product._id.toString();
105
105
  const isRevolver = product.type === ELoanTypes.REVOLVER;
106
106
  const { balance: balanceEnd } = await this.loanChargesService.getLoanProductBalance(productId, end);
@@ -323,7 +323,7 @@ class ReportsService {
323
323
  const hasTermProduct = products.some((product) => product.type === loan_types_enum_1.ELoanTypes.TERM);
324
324
  const manyTermProduct = products.filter((product) => product.type === loan_types_enum_1.ELoanTypes.TERM).length > 1;
325
325
  return await Promise.all(products.map(async (product) => {
326
- if (product.isParticipant) {
326
+ if (product.masterLoanProductId !== undefined) {
327
327
  return null;
328
328
  }
329
329
  if ((0, dayjs_1.default)(product.deactivationDate).isBefore((0, dayjs_1.default)(date))) {
@@ -426,7 +426,7 @@ export class ReportsService {
426
426
  const manyTermProduct = products.filter((product) => product.type === ELoanTypes.TERM).length > 1;
427
427
 
428
428
  return await Promise.all(products.map(async (product) => {
429
- if (product.isParticipant) {
429
+ if (product.masterLoanProductId !== undefined) {
430
430
  return null as IBankReportData;
431
431
  }
432
432
  if (dayjs(product.deactivationDate).isBefore(dayjs(date))) {