gemcap-be-common 1.4.201 → 1.4.204

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.
@@ -28,7 +28,8 @@ import { IBankDoc } from './Banks.model';
28
28
  export declare enum ELoanTransactionTypes {
29
29
  COLLECTION = "COLLECTION",
30
30
  DISBURSEMENT = "DISBURSEMENT",
31
- ADJUSTMENT = "ADJUSTMENT"
31
+ ADJUSTMENT = "ADJUSTMENT",
32
+ CHARGE = "CHARGE"
32
33
  }
33
34
  export declare const LOAN_TRANSACTION_DOWNLOAD_FIELDS: string[];
34
35
  export declare const LOAN_TRANSACTION_FIELDS: string[];
@@ -47,6 +48,7 @@ export interface ILoanTransaction {
47
48
  date: Date;
48
49
  effectiveDate: Date;
49
50
  productId: mongoose.Types.ObjectId;
51
+ chargeId?: mongoose.Types.ObjectId;
50
52
  amount: number;
51
53
  description: string;
52
54
  reference: string;
@@ -79,11 +81,12 @@ export interface ILoanTransactionLean extends ILoanTransaction {
79
81
  createdAt: Date;
80
82
  updatedAt: Date;
81
83
  }
82
- export interface ILoanTransactionPlain extends Omit<ILoanTransaction, 'productId' | 'bankId' | 'loanPaymentId'> {
84
+ export interface ILoanTransactionPlain extends Omit<ILoanTransaction, 'productId' | 'bankId' | 'loanPaymentId' | 'chargeId'> {
83
85
  _id: string;
84
86
  productId: string;
85
87
  bankId: string;
86
88
  loanPaymentId: string;
89
+ chargeId: string;
87
90
  }
88
91
  export type TLoanTransactionModel = mongoose.Model<ILoanTransaction>;
89
92
  export interface ILoanTransactionModel extends mongoose.Model<ILoanTransaction> {
@@ -14,6 +14,7 @@ var ELoanTransactionTypes;
14
14
  ELoanTransactionTypes["COLLECTION"] = "COLLECTION";
15
15
  ELoanTransactionTypes["DISBURSEMENT"] = "DISBURSEMENT";
16
16
  ELoanTransactionTypes["ADJUSTMENT"] = "ADJUSTMENT";
17
+ ELoanTransactionTypes["CHARGE"] = "CHARGE";
17
18
  })(ELoanTransactionTypes || (exports.ELoanTransactionTypes = ELoanTransactionTypes = {}));
18
19
  exports.LOAN_TRANSACTION_DOWNLOAD_FIELDS = [
19
20
  'date',
@@ -28,6 +29,7 @@ exports.LOAN_TRANSACTION_FIELDS = [
28
29
  'date',
29
30
  'effectiveDate',
30
31
  'productId',
32
+ 'chargeId',
31
33
  'amount',
32
34
  'description',
33
35
  'reference',
@@ -62,6 +64,11 @@ exports.LoanTransactionSchema = new mongoose_1.default.Schema({
62
64
  ref: _models_1.MODEL_NAMES.loanProducts,
63
65
  required: true,
64
66
  },
67
+ chargeId: {
68
+ type: mongoose_1.default.Schema.Types.ObjectId,
69
+ ref: _models_1.MODEL_NAMES.loanCharges,
70
+ required: false,
71
+ },
65
72
  amount: {
66
73
  type: Number,
67
74
  required: true,
@@ -10,7 +10,8 @@ import { createLog, getLogChanges } from '../db/user-logs.db';
10
10
  export enum ELoanTransactionTypes {
11
11
  COLLECTION = 'COLLECTION',
12
12
  DISBURSEMENT = 'DISBURSEMENT',
13
- ADJUSTMENT = 'ADJUSTMENT'
13
+ ADJUSTMENT = 'ADJUSTMENT',
14
+ CHARGE = 'CHARGE',
14
15
  }
15
16
 
16
17
  export const LOAN_TRANSACTION_DOWNLOAD_FIELDS = [
@@ -27,6 +28,7 @@ export const LOAN_TRANSACTION_FIELDS = [
27
28
  'date',
28
29
  'effectiveDate',
29
30
  'productId',
31
+ 'chargeId',
30
32
  'amount',
31
33
  'description',
32
34
  'reference',
@@ -55,6 +57,7 @@ export interface ILoanTransaction {
55
57
  date: Date;
56
58
  effectiveDate: Date,
57
59
  productId: mongoose.Types.ObjectId;
60
+ chargeId?: mongoose.Types.ObjectId;
58
61
  amount: number;
59
62
  description: string;
60
63
  reference: string;
@@ -92,11 +95,12 @@ export interface ILoanTransactionLean extends ILoanTransaction {
92
95
  updatedAt: Date;
93
96
  }
94
97
 
95
- export interface ILoanTransactionPlain extends Omit<ILoanTransaction, 'productId' | 'bankId' | 'loanPaymentId'> {
98
+ export interface ILoanTransactionPlain extends Omit<ILoanTransaction, 'productId' | 'bankId' | 'loanPaymentId' | 'chargeId'> {
96
99
  _id: string;
97
100
  productId: string;
98
101
  bankId: string;
99
102
  loanPaymentId: string;
103
+ chargeId: string;
100
104
  }
101
105
 
102
106
  export type TLoanTransactionModel = mongoose.Model<ILoanTransaction>;
@@ -138,6 +142,11 @@ export const LoanTransactionSchema = new mongoose.Schema<ILoanTransactionDoc, IL
138
142
  ref: MODEL_NAMES.loanProducts,
139
143
  required: true,
140
144
  },
145
+ chargeId: {
146
+ type: mongoose.Schema.Types.ObjectId,
147
+ ref: MODEL_NAMES.loanCharges,
148
+ required: false,
149
+ },
141
150
  amount: {
142
151
  type: Number,
143
152
  required: true,
@@ -31,10 +31,10 @@ export declare const allSchemas: {
31
31
  createdAt: NativeDate;
32
32
  updatedAt: NativeDate;
33
33
  } & {
34
+ amount: number;
34
35
  order: 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;
@@ -45,10 +45,10 @@ export declare const allSchemas: {
45
45
  createdAt: NativeDate;
46
46
  updatedAt: NativeDate;
47
47
  } & {
48
+ amount: number;
48
49
  order: 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;
@@ -59,10 +59,10 @@ export declare const allSchemas: {
59
59
  createdAt: NativeDate;
60
60
  updatedAt: NativeDate;
61
61
  } & {
62
+ amount: number;
62
63
  order: 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.4.201",
3
+ "version": "1.4.204",
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
- LAST_MONTH?: boolean;
88
- CURRENT_MONTH?: boolean;
89
87
  ENTIRE_LOAN?: boolean;
90
88
  SELECTED_PERIOD?: boolean;
89
+ CURRENT_MONTH?: boolean;
90
+ LAST_MONTH?: 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> & {
47
47
  _id: import("mongoose").Types.ObjectId;
48
48
  })[]>;
49
- getBorrowerBrokers(borrowerId: string): Promise<BrokerView[] | (import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
49
+ getBorrowerBrokers(borrowerId: string): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
50
50
  _id: import("mongoose").Types.ObjectId;
51
- })[]>;
51
+ })[] | BrokerView[]>;
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[]>;
@@ -452,17 +452,15 @@ class LoanTransactionsService {
452
452
  for (const transaction of recalculatedTransactions) {
453
453
  const totalPostponed = await (0, loan_products_db_1.getPostponedTransactions)(transaction.date, transaction.productId.toString(), true);
454
454
  switch (transaction.transactionType) {
455
- case LoanTransaction_model_1.ELoanTransactionTypes.COLLECTION:
455
+ case LoanTransaction_model_1.ELoanTransactionTypes.COLLECTION: {
456
456
  await this.postponedTransactionsService.cleanRecalculated(transaction._id.toString());
457
457
  await this.postponedTransactionsService.createPostponedTransaction(transaction);
458
458
  currentFloatedBalance = new decimal_js_1.default(currentFloatedBalance).add(totalPostponed).toNumber();
459
459
  break;
460
- case LoanTransaction_model_1.ELoanTransactionTypes.DISBURSEMENT:
461
- currentFloatedBalance = new decimal_js_1.default(currentFloatedBalance).add(transaction.amount).add(totalPostponed).toNumber();
462
- break;
463
- case LoanTransaction_model_1.ELoanTransactionTypes.ADJUSTMENT:
460
+ }
461
+ default: {
464
462
  currentFloatedBalance = new decimal_js_1.default(currentFloatedBalance).add(transaction.amount).add(totalPostponed).toNumber();
465
- break;
463
+ }
466
464
  }
467
465
  await LoanTransaction_model_1.LoanTransaction.findByIdAndUpdate(transaction._id, { floatedBalance: currentFloatedBalance });
468
466
  }
@@ -527,15 +525,15 @@ class LoanTransactionsService {
527
525
  // floatedBalance recalculation
528
526
  const totalPostponed = await (0, loan_products_db_1.getPostponedTransactions)(tr.date, tr.productId.toString(), true);
529
527
  switch (tr.transactionType) {
530
- case LoanTransaction_model_1.ELoanTransactionTypes.COLLECTION:
528
+ case LoanTransaction_model_1.ELoanTransactionTypes.COLLECTION: {
531
529
  await this.postponedTransactionsService.cleanRecalculated(tr._id.toString());
532
530
  await this.postponedTransactionsService.createPostponedTransaction(tr);
533
531
  floatedBalance = new decimal_js_1.default(floatedBalance).add(totalPostponed).toNumber();
534
532
  break;
535
- case LoanTransaction_model_1.ELoanTransactionTypes.DISBURSEMENT:
536
- case LoanTransaction_model_1.ELoanTransactionTypes.ADJUSTMENT:
533
+ }
534
+ default: {
537
535
  floatedBalance = new decimal_js_1.default(floatedBalance).add(tr.amount).add(totalPostponed).toNumber();
538
- break;
536
+ }
539
537
  }
540
538
  await LoanTransaction_model_1.LoanTransaction.updateOne({ _id: tr._id }, { balance, floatedBalance });
541
539
  }
@@ -515,17 +515,15 @@ export class LoanTransactionsService {
515
515
  for (const transaction of recalculatedTransactions) {
516
516
  const totalPostponed = await getPostponedTransactions(transaction.date, transaction.productId.toString(), true);
517
517
  switch (transaction.transactionType) {
518
- case ELoanTransactionTypes.COLLECTION:
518
+ case ELoanTransactionTypes.COLLECTION: {
519
519
  await this.postponedTransactionsService.cleanRecalculated(transaction._id.toString());
520
520
  await this.postponedTransactionsService.createPostponedTransaction(transaction);
521
521
  currentFloatedBalance = new Decimal(currentFloatedBalance).add(totalPostponed).toNumber();
522
522
  break;
523
- case ELoanTransactionTypes.DISBURSEMENT:
524
- currentFloatedBalance = new Decimal(currentFloatedBalance).add(transaction.amount).add(totalPostponed).toNumber();
525
- break;
526
- case ELoanTransactionTypes.ADJUSTMENT:
523
+ }
524
+ default: {
527
525
  currentFloatedBalance = new Decimal(currentFloatedBalance).add(transaction.amount).add(totalPostponed).toNumber();
528
- break;
526
+ }
529
527
  }
530
528
  await LoanTransaction.findByIdAndUpdate(transaction._id, { floatedBalance: currentFloatedBalance });
531
529
  }
@@ -601,15 +599,15 @@ export class LoanTransactionsService {
601
599
  // floatedBalance recalculation
602
600
  const totalPostponed = await getPostponedTransactions(tr.date, tr.productId.toString(), true);
603
601
  switch (tr.transactionType) {
604
- case ELoanTransactionTypes.COLLECTION:
602
+ case ELoanTransactionTypes.COLLECTION: {
605
603
  await this.postponedTransactionsService.cleanRecalculated(tr._id.toString());
606
604
  await this.postponedTransactionsService.createPostponedTransaction(tr);
607
605
  floatedBalance = new Decimal(floatedBalance).add(totalPostponed).toNumber();
608
606
  break;
609
- case ELoanTransactionTypes.DISBURSEMENT:
610
- case ELoanTransactionTypes.ADJUSTMENT:
607
+ }
608
+ default: {
611
609
  floatedBalance = new Decimal(floatedBalance).add(tr.amount).add(totalPostponed).toNumber();
612
- break;
610
+ }
613
611
  }
614
612
 
615
613
  await LoanTransaction.updateOne(