gemcap-be-common 1.5.16 → 1.5.17

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.
@@ -26,4 +26,4 @@ export declare const getShiftedMonth: (month: ISelectedMonth, shift: number) =>
26
26
  year: number;
27
27
  month: number;
28
28
  };
29
- export declare const isProductActive: (deactivationDate: Date | null | undefined, checkDate: Date) => boolean;
29
+ export declare const isProductActive: (startDate: Date | null | undefined, deactivationDate: Date | null | undefined, checkDate: Date) => boolean;
@@ -97,14 +97,18 @@ const getShiftedMonth = (month, shift) => {
97
97
  return { year: nextMonth.year(), month: nextMonth.month() + 1 };
98
98
  };
99
99
  exports.getShiftedMonth = getShiftedMonth;
100
- const isProductActive = (deactivationDate, checkDate) => {
101
- // If no deactivation date → product is active
100
+ const isProductActive = (startDate, deactivationDate, checkDate) => {
101
+ const check = (0, dayjs_1.default)(checkDate);
102
+ // If startDate exists and is in the future → not active yet
103
+ if (startDate && (0, dayjs_1.default)(startDate).isAfter(check)) {
104
+ return false;
105
+ }
106
+ // If no deactivation date → active (and already started)
102
107
  if (!deactivationDate) {
103
108
  return true;
104
109
  }
105
110
  const deactivation = (0, dayjs_1.default)(deactivationDate);
106
- const check = (0, dayjs_1.default)(checkDate);
107
- // Active if deactivation is on or after the check date
108
- return !deactivation.isBefore(check);
111
+ // Active if checkDate is before deactivationDate
112
+ return check.isBefore(deactivation);
109
113
  };
110
114
  exports.isProductActive = isProductActive;
@@ -103,15 +103,25 @@ export const getShiftedMonth = (month: ISelectedMonth, shift: number) => {
103
103
  return { year: nextMonth.year(), month: nextMonth.month() + 1 };
104
104
  };
105
105
 
106
- export const isProductActive = (deactivationDate: Date | null | undefined, checkDate: Date) => {
107
- // If no deactivation date → product is active
106
+ export const isProductActive = (
107
+ startDate: Date | null | undefined,
108
+ deactivationDate: Date | null | undefined,
109
+ checkDate: Date
110
+ ) => {
111
+ const check = dayjs(checkDate);
112
+
113
+ // If startDate exists and is in the future → not active yet
114
+ if (startDate && dayjs(startDate).isAfter(check)) {
115
+ return false;
116
+ }
117
+
118
+ // If no deactivation date → active (and already started)
108
119
  if (!deactivationDate) {
109
120
  return true;
110
121
  }
111
122
 
112
123
  const deactivation = dayjs(deactivationDate);
113
- const check = dayjs(checkDate);
114
124
 
115
- // Active if deactivation is on or after the check date
116
- return !deactivation.isBefore(check);
125
+ // Active if checkDate is before deactivationDate
126
+ return check.isBefore(deactivation);
117
127
  };
@@ -206,9 +206,9 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
206
206
  insuredComponent: number;
207
207
  preliminaryEligibleBalance: number;
208
208
  uninsuredComponent: number;
209
- creditNotesNegative: number;
210
209
  insuredAvailability: number;
211
210
  uninsuredAvailability: number;
211
+ creditNotesNegative: number;
212
212
  ARAvailability: number;
213
213
  };
214
214
  userCalculatedId?: string;
@@ -218,15 +218,15 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
218
218
  limit?: number;
219
219
  customer?: string;
220
220
  }>;
221
- insuredCustomers: mongoose.Types.DocumentArray<{
221
+ permittedConcentration: mongoose.Types.DocumentArray<{
222
222
  limit?: number;
223
223
  customer?: string;
224
224
  }>;
225
- permittedConcentration: mongoose.Types.DocumentArray<{
225
+ permittedExtendedARDays: mongoose.Types.DocumentArray<{
226
226
  limit?: number;
227
227
  customer?: string;
228
228
  }>;
229
- permittedExtendedARDays: mongoose.Types.DocumentArray<{
229
+ insuredCustomers: mongoose.Types.DocumentArray<{
230
230
  limit?: number;
231
231
  customer?: string;
232
232
  }>;
@@ -266,9 +266,9 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
266
266
  insuredComponent: number;
267
267
  preliminaryEligibleBalance: number;
268
268
  uninsuredComponent: number;
269
- creditNotesNegative: number;
270
269
  insuredAvailability: number;
271
270
  uninsuredAvailability: number;
271
+ creditNotesNegative: number;
272
272
  ARAvailability: number;
273
273
  };
274
274
  userCalculatedId?: string;
@@ -278,15 +278,15 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
278
278
  limit?: number;
279
279
  customer?: string;
280
280
  }>;
281
- insuredCustomers: mongoose.Types.DocumentArray<{
281
+ permittedConcentration: mongoose.Types.DocumentArray<{
282
282
  limit?: number;
283
283
  customer?: string;
284
284
  }>;
285
- permittedConcentration: mongoose.Types.DocumentArray<{
285
+ permittedExtendedARDays: mongoose.Types.DocumentArray<{
286
286
  limit?: number;
287
287
  customer?: string;
288
288
  }>;
289
- permittedExtendedARDays: mongoose.Types.DocumentArray<{
289
+ insuredCustomers: mongoose.Types.DocumentArray<{
290
290
  limit?: number;
291
291
  customer?: string;
292
292
  }>;
@@ -326,9 +326,9 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
326
326
  insuredComponent: number;
327
327
  preliminaryEligibleBalance: number;
328
328
  uninsuredComponent: number;
329
- creditNotesNegative: number;
330
329
  insuredAvailability: number;
331
330
  uninsuredAvailability: number;
331
+ creditNotesNegative: number;
332
332
  ARAvailability: number;
333
333
  };
334
334
  userCalculatedId?: string;
@@ -338,15 +338,15 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
338
338
  limit?: number;
339
339
  customer?: string;
340
340
  }>;
341
- insuredCustomers: mongoose.Types.DocumentArray<{
341
+ permittedConcentration: mongoose.Types.DocumentArray<{
342
342
  limit?: number;
343
343
  customer?: string;
344
344
  }>;
345
- permittedConcentration: mongoose.Types.DocumentArray<{
345
+ permittedExtendedARDays: mongoose.Types.DocumentArray<{
346
346
  limit?: number;
347
347
  customer?: string;
348
348
  }>;
349
- permittedExtendedARDays: mongoose.Types.DocumentArray<{
349
+ insuredCustomers: mongoose.Types.DocumentArray<{
350
350
  limit?: number;
351
351
  customer?: string;
352
352
  }>;
@@ -32,9 +32,9 @@ export declare const allSchemas: {
32
32
  updatedAt: NativeDate;
33
33
  } & {
34
34
  order: number;
35
+ amount: number;
35
36
  bbcSheetId: import("mongoose").Types.ObjectId;
36
37
  apDate: Date;
37
- amount: number;
38
38
  __v?: number;
39
39
  poNumber?: string;
40
40
  customerName?: string;
@@ -46,9 +46,9 @@ export declare const allSchemas: {
46
46
  updatedAt: NativeDate;
47
47
  } & {
48
48
  order: number;
49
+ amount: number;
49
50
  bbcSheetId: import("mongoose").Types.ObjectId;
50
51
  apDate: Date;
51
- amount: number;
52
52
  __v?: number;
53
53
  poNumber?: string;
54
54
  customerName?: string;
@@ -60,9 +60,9 @@ export declare const allSchemas: {
60
60
  updatedAt: NativeDate;
61
61
  } & {
62
62
  order: number;
63
+ amount: number;
63
64
  bbcSheetId: import("mongoose").Types.ObjectId;
64
65
  apDate: Date;
65
- amount: number;
66
66
  __v?: number;
67
67
  poNumber?: string;
68
68
  customerName?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.5.16",
3
+ "version": "1.5.17",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -213,7 +213,7 @@ class BorrowerSummaryService {
213
213
  }
214
214
  async getChartData(borrowerId) {
215
215
  const products = await this.loanChargesService.getLoanProducts(borrowerId);
216
- const revolverProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.deactivationDate, new Date()));
216
+ const revolverProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, new Date()));
217
217
  const chartData = [];
218
218
  if (revolverProduct) {
219
219
  const lastSignedBBC = await (0, bbcDates_db_1.getLatestSignedBBCDateDoc)(borrowerId);
@@ -236,7 +236,7 @@ export class BorrowerSummaryService {
236
236
 
237
237
  private async getChartData(borrowerId: string) {
238
238
  const products = await this.loanChargesService.getLoanProducts(borrowerId);
239
- const revolverProduct = products.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.deactivationDate, new Date()));
239
+ const revolverProduct = products.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.startDate, product.deactivationDate, new Date()));
240
240
  const chartData = [];
241
241
  if (revolverProduct) {
242
242
  const lastSignedBBC = await getLatestSignedBBCDateDoc(borrowerId);
@@ -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
  }>;
@@ -46,9 +46,9 @@ export declare class BrokersService {
46
46
  getAllProductBrokers(): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & Required<{
47
47
  _id: import("mongoose").Types.ObjectId;
48
48
  }>)[]>;
49
- getBorrowerBrokers(borrowerId: string): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & Required<{
49
+ getBorrowerBrokers(borrowerId: string): Promise<BrokerView[] | (import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & Required<{
50
50
  _id: import("mongoose").Types.ObjectId;
51
- }>)[] | BrokerView[]>;
51
+ }>)[]>;
52
52
  getProductBrokers(productId: string): Promise<import("../models/ProductBroker.model").IProductBrokerDocWithBroker[]>;
53
53
  getTotalShares(borrowerId: string, brokers: IProductBrokerView[], replaceNames?: boolean): Promise<ProductTotal>;
54
54
  getTotals(borrowerId: string): Promise<BrokerTotalView[]>;
@@ -440,7 +440,7 @@ class LoanPaymentsService {
440
440
  if (borrowerIds.includes(borrower._id.toString())) {
441
441
  try {
442
442
  const borrowerProducts = await this.loanChargesService.getLoanProducts(borrower._id.toString());
443
- const revolverProduct = borrowerProducts.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.deactivationDate, selectedDate));
443
+ const revolverProduct = borrowerProducts.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, selectedDate));
444
444
  const loanStatementService = this.getLoanStatementService();
445
445
  const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString());
446
446
  if (dueAmounts.total === 0) {
@@ -491,7 +491,7 @@ export class LoanPaymentsService {
491
491
  if (borrowerIds.includes(borrower._id.toString())) {
492
492
  try {
493
493
  const borrowerProducts = await this.loanChargesService.getLoanProducts(borrower._id.toString());
494
- const revolverProduct = borrowerProducts.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.deactivationDate, selectedDate));
494
+ const revolverProduct = borrowerProducts.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.startDate, product.deactivationDate, selectedDate));
495
495
  const loanStatementService = this.getLoanStatementService();
496
496
  const dueAmounts = await loanStatementService.getBorrowerProductTotals(borrower._id.toString());
497
497
  if (dueAmounts.total === 0) {
@@ -677,7 +677,7 @@ class LoanTransactionsService {
677
677
  [loan_types_enum_1.ELoanTypes.REVOLVER]: 0,
678
678
  };
679
679
  await Promise.all(loanProducts
680
- .filter((product) => (0, date_helper_1.isProductActive)(product.deactivationDate, bbcDate.bbcDate))
680
+ .filter((product) => (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, bbcDate.bbcDate))
681
681
  .map(async (product) => {
682
682
  const lastTransaction = await this.getLastTransactionForDate(product._id.toString(), (0, dayjs_1.default)(bbcDate.bbcDate).utcOffset(0).endOf('day').toDate());
683
683
  if (lastTransaction) {
@@ -766,7 +766,7 @@ export class LoanTransactionsService {
766
766
  [ELoanTypes.REVOLVER]: 0,
767
767
  };
768
768
  await Promise.all(loanProducts
769
- .filter((product) => isProductActive(product.deactivationDate, bbcDate.bbcDate))
769
+ .filter((product) => isProductActive(product.startDate, product.deactivationDate, bbcDate.bbcDate))
770
770
  .map(async (product) => {
771
771
  const lastTransaction = await this.getLastTransactionForDate(product._id.toString(), dayjs(bbcDate.bbcDate).utcOffset(0).endOf('day').toDate());
772
772
  if (lastTransaction) {
@@ -434,7 +434,7 @@ class QuickbooksService {
434
434
  };
435
435
  if (settlementCode === 'null') {
436
436
  const products = await this.loanChargesService.getLoanProducts(borrower._id.toString());
437
- const revolverProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.deactivationDate, reportDate));
437
+ const revolverProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, reportDate));
438
438
  if (revolverProduct) {
439
439
  settlementCode = revolverProduct.code;
440
440
  }
@@ -506,7 +506,7 @@ export class QuickbooksService {
506
506
 
507
507
  if (settlementCode === 'null') {
508
508
  const products = await this.loanChargesService.getLoanProducts(borrower._id.toString());
509
- const revolverProduct = products.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.deactivationDate, reportDate));
509
+ const revolverProduct = products.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.startDate, product.deactivationDate, reportDate));
510
510
  if (revolverProduct) {
511
511
  settlementCode = revolverProduct.code;
512
512
  }
@@ -231,7 +231,7 @@ class ReportsService {
231
231
  if (!borrower) {
232
232
  return;
233
233
  }
234
- const revolverProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.deactivationDate, date));
234
+ const revolverProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.REVOLVER && (0, date_helper_1.isProductActive)(product.startDate, product.deactivationDate, date));
235
235
  const termProduct = products.find((product) => product.type === loan_types_enum_1.ELoanTypes.TERM);
236
236
  let revolverDataGroup = null;
237
237
  if (revolverProduct) {
@@ -314,7 +314,7 @@ export class ReportsService {
314
314
  if (!borrower) {
315
315
  return;
316
316
  }
317
- const revolverProduct = products.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.deactivationDate, date));
317
+ const revolverProduct = products.find((product) => product.type === ELoanTypes.REVOLVER && isProductActive(product.startDate, product.deactivationDate, date));
318
318
  const termProduct = products.find((product) => product.type === ELoanTypes.TERM);
319
319
 
320
320
  let revolverDataGroup: ISummaryReportDataGroup = null;