gemcap-be-common 1.3.15 → 1.3.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.
package/db/new-summary.js CHANGED
@@ -16,6 +16,7 @@ const LoanStatementTransaction_model_1 = require("../models/LoanStatementTransac
16
16
  const bbcDates_db_1 = require("./bbcDates.db");
17
17
  const reserve_types_enum_1 = require("../enums/reserve-types.enum");
18
18
  const ComplianceItem_model_1 = require("../models/ComplianceItem.model");
19
+ const excel_helper_1 = require("../helpers/excel.helper");
19
20
  const LoanCharges_model_1 = require("../models/LoanCharges.model");
20
21
  const BorrowerCompliance_model_1 = require("../models/BorrowerCompliance.model");
21
22
  const LoanTransaction_model_1 = require("../models/LoanTransaction.model");
@@ -79,15 +80,6 @@ const styles = {
79
80
  },
80
81
  },
81
82
  };
82
- const numberFormat = {
83
- fullNumber: '#,##0.00',
84
- shortNumber: '#,##0',
85
- xNumber: '0.00"x"',
86
- xNumber1DP: '0.0"x"',
87
- thousands: '0.0,',
88
- percent: '0.00%',
89
- percent1DP: '0.0%',
90
- };
91
83
  const borrowerTitleLength = 12;
92
84
  const dateFormat = 'MM-DD-YYYY';
93
85
  const productsDataMap = new Map();
@@ -98,39 +90,39 @@ const complianceBorrowersMap = new Map();
98
90
  const allBorrowerSummaryRowFields = {
99
91
  commitmentAmount: {
100
92
  t: 'n',
101
- z: numberFormat.thousands,
93
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
102
94
  },
103
95
  endingBalance: {
104
96
  t: 'n',
105
- z: numberFormat.thousands,
97
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
106
98
  },
107
99
  endingParticipationBalance: {
108
100
  t: 'n',
109
- z: numberFormat.thousands,
101
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
110
102
  },
111
103
  netExposure: {
112
104
  t: 'n',
113
- z: numberFormat.thousands,
105
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
114
106
  },
115
107
  averageBalanceSinceInception: {
116
108
  t: 'n',
117
- z: numberFormat.thousands,
109
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
118
110
  },
119
111
  totalIncomeReceived: {
120
112
  t: 'n',
121
- z: numberFormat.thousands,
113
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
122
114
  },
123
115
  loanLifeIRR: {
124
116
  t: 'n',
125
- z: numberFormat.percent,
117
+ z: excel_helper_1.NUMBER_FORMATS.percent,
126
118
  },
127
119
  MOIC: {
128
120
  t: 'n',
129
- z: numberFormat.xNumber,
121
+ z: excel_helper_1.NUMBER_FORMATS.xNumber,
130
122
  },
131
123
  participantBalance: {
132
124
  t: 'n',
133
- z: numberFormat.thousands,
125
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
134
126
  },
135
127
  };
136
128
  const borrowerSummaryRowFields = {
@@ -139,23 +131,23 @@ const borrowerSummaryRowFields = {
139
131
  },
140
132
  'grossValue': {
141
133
  t: 'n',
142
- z: numberFormat.thousands,
134
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
143
135
  },
144
136
  'ineligible': {
145
137
  t: 'n',
146
- z: numberFormat.thousands,
138
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
147
139
  },
148
140
  'netValue': {
149
141
  t: 'n',
150
- z: numberFormat.thousands,
142
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
151
143
  },
152
144
  'advanceRate': {
153
145
  t: 'n',
154
- z: numberFormat.percent1DP,
146
+ z: excel_helper_1.NUMBER_FORMATS.percent1DP,
155
147
  },
156
148
  'availability': {
157
149
  t: 'n',
158
- z: numberFormat.thousands,
150
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
159
151
  },
160
152
  };
161
153
  const emptyRow = [{ v: '', t: 's' }];
@@ -555,7 +547,7 @@ class NewSummaryExcel {
555
547
  return Object.values(dataRow).map((v) => ({
556
548
  v: v != null ? v : '',
557
549
  t: typeof v === 'number' ? 'n' : 's',
558
- z: v != null ? numberFormat.thousands : undefined,
550
+ z: v != null ? excel_helper_1.NUMBER_FORMATS.thousands : undefined,
559
551
  ...(totalRows.includes(dataRow.title) ? { s: styles.blackOnWhiteWithTopBorder } : {}),
560
552
  }));
561
553
  });
@@ -577,9 +569,9 @@ class NewSummaryExcel {
577
569
  Object.entries(equipmentOrder).forEach(([key, desc]) => {
578
570
  const newRow = [
579
571
  { v: desc.title, s: desc.s },
580
- { v: availability.equipment[key].amount ?? 0, t: 'n', z: numberFormat.thousands, s: desc.s },
581
- { v: availability.equipment[key].advanceRate ?? 0, t: 'n', z: numberFormat.percent, s: desc.s },
582
- { v: availability.equipment[key].availability ?? 0, t: 'n', z: numberFormat.thousands, s: desc.s },
572
+ { v: availability.equipment[key].amount ?? 0, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands, s: desc.s },
573
+ { v: availability.equipment[key].advanceRate ?? 0, t: 'n', z: excel_helper_1.NUMBER_FORMATS.percent, s: desc.s },
574
+ { v: availability.equipment[key].availability ?? 0, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands, s: desc.s },
583
575
  ];
584
576
  rows.push(newRow);
585
577
  });
@@ -587,21 +579,21 @@ class NewSummaryExcel {
587
579
  rows.push([{ v: '' }, { v: 'Gross Amount' }, { v: 'Availability' }]);
588
580
  rows.push([
589
581
  { v: 'Term Reserve' },
590
- { v: availability.equipment[equipment_types_enum_1.EEquipmentTypes.EQUIPMENT].amount, t: 'n', z: numberFormat.thousands },
591
- { v: availability.equipment[equipment_types_enum_1.EEquipmentTypes.EQUIPMENT].availability, t: 'n', z: numberFormat.thousands },
582
+ { v: availability.equipment[equipment_types_enum_1.EEquipmentTypes.EQUIPMENT].amount, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands },
583
+ { v: availability.equipment[equipment_types_enum_1.EEquipmentTypes.EQUIPMENT].availability, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands },
592
584
  ]);
593
585
  rows.push([
594
586
  { v: 'Loan Balance' },
595
587
  { v: 0, t: 'n' },
596
- { v: availability.loanBalances.TERM, t: 'n', z: numberFormat.thousands },
588
+ { v: availability.loanBalances.TERM, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands },
597
589
  ]);
598
590
  rows.push([
599
591
  { v: 'Net Availability' },
600
- { v: availability.equipment[equipment_types_enum_1.EEquipmentTypes.EQUIPMENT].amount, t: 'n', z: numberFormat.thousands },
592
+ { v: availability.equipment[equipment_types_enum_1.EEquipmentTypes.EQUIPMENT].amount, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands },
601
593
  {
602
594
  v: new decimal_js_1.default(availability.equipment['netTotal'].availability).sub(availability.loanBalances.TERM).toNumber(),
603
595
  t: 'n',
604
- z: numberFormat.thousands,
596
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
605
597
  },
606
598
  ]);
607
599
  return [
@@ -629,22 +621,22 @@ class NewSummaryExcel {
629
621
  loanEconomicsData.push([{ v: 'Average Balance Since Inception' }, {
630
622
  v: productData.averageBalanceSinceInception,
631
623
  t: 'n',
632
- z: numberFormat.thousands,
624
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
633
625
  }]);
634
626
  loanEconomicsData.push([{ v: 'Total Income Received' }, {
635
627
  v: productData.totalIncomeReceived,
636
628
  t: 'n',
637
- z: numberFormat.thousands,
629
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
638
630
  }]);
639
631
  loanEconomicsData.push([{ v: 'Loan Life IRR' }, {
640
632
  v: productData.loanLifeIRR,
641
633
  t: 'n',
642
- z: numberFormat.percent,
634
+ z: excel_helper_1.NUMBER_FORMATS.percent,
643
635
  }]);
644
636
  loanEconomicsData.push([{ v: 'MOIC' }, {
645
637
  v: productData.MOIC,
646
638
  t: 'n',
647
- z: numberFormat.xNumber,
639
+ z: excel_helper_1.NUMBER_FORMATS.xNumber,
648
640
  }]);
649
641
  }
650
642
  const dataDeep = 5;
@@ -691,10 +683,10 @@ class NewSummaryExcel {
691
683
  const collections = txs.filter((t) => t.transactionType === LoanTransaction_model_1.ELoanTransactionTypes.COLLECTION);
692
684
  const totalDisbursements = lodash_1.default.sumBy(disbursements, 'amount');
693
685
  const totalCollections = Math.abs(lodash_1.default.sumBy(collections, 'amount'));
694
- totalDisbursementRow.push({ v: totalDisbursements, t: 'n', z: numberFormat.thousands });
695
- countDisbursementRow.push({ v: disbursements.length, t: 'n', z: numberFormat.shortNumber });
696
- totalCollectionRow.push({ v: totalCollections, t: 'n', z: numberFormat.thousands });
697
- countCollectionRow.push({ v: collections.length, t: 'n', z: numberFormat.shortNumber });
686
+ totalDisbursementRow.push({ v: totalDisbursements, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands });
687
+ countDisbursementRow.push({ v: disbursements.length, t: 'n', z: excel_helper_1.NUMBER_FORMATS.shortNumber });
688
+ totalCollectionRow.push({ v: totalCollections, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands });
689
+ countCollectionRow.push({ v: collections.length, t: 'n', z: excel_helper_1.NUMBER_FORMATS.shortNumber });
698
690
  }
699
691
  charges.forEach((charge) => {
700
692
  const chargeYieldData = yieldDataSorted.filter((yieldDataDoc) => {
@@ -703,7 +695,7 @@ class NewSummaryExcel {
703
695
  const chargeData = chargeYieldData.reduce((acc, chargeYieldDataDoc) => {
704
696
  const newRow = chargeYieldDataDoc.valuePercent < 0
705
697
  ? negativeCell
706
- : { v: chargeYieldDataDoc.valuePercent, t: 'n', z: numberFormat.percent };
698
+ : { v: chargeYieldDataDoc.valuePercent, t: 'n', z: excel_helper_1.NUMBER_FORMATS.percent };
707
699
  return [...acc, newRow];
708
700
  }, [{ v: charge.name, t: 's' }]);
709
701
  chargesData.push(chargeData);
@@ -730,7 +722,7 @@ class NewSummaryExcel {
730
722
  const newRow = {
731
723
  v: totalCollections === 0 ? 0 : new decimal_js_1.default(yieldDataDoc.value).div(Math.abs(totalCollections)).mul(daysInMonth).round().toNumber(),
732
724
  t: 'n',
733
- z: numberFormat.thousands,
725
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
734
726
  };
735
727
  return [...acc, newRow];
736
728
  }, []);
@@ -743,8 +735,8 @@ class NewSummaryExcel {
743
735
  return [...acc, negativeCell];
744
736
  }
745
737
  const newRow = isPercent
746
- ? { v: yieldDataDoc.valuePercent, t: 'n', z: numberFormat.percent }
747
- : { v: yieldDataDoc.value, t: 'n', z: numberFormat.thousands };
738
+ ? { v: yieldDataDoc.valuePercent, t: 'n', z: excel_helper_1.NUMBER_FORMATS.percent }
739
+ : { v: yieldDataDoc.value, t: 'n', z: excel_helper_1.NUMBER_FORMATS.thousands };
748
740
  return [...acc, newRow];
749
741
  }, [{ v: total.title, t: 's' }]);
750
742
  chargesData.push(chargeData);
@@ -799,7 +791,7 @@ class NewSummaryExcel {
799
791
  const createFinancialIndexes = (enumObj, keys, overrides = {}) => keys.reduce((acc, key) => {
800
792
  const enumValue = enumObj[key];
801
793
  acc[enumValue] = {
802
- format: overrides[key]?.format ?? numberFormat.thousands,
794
+ format: overrides[key]?.format ?? excel_helper_1.NUMBER_FORMATS.thousands,
803
795
  title: overrides[key]?.title ?? FinancialSpreadingSheet_model_1.financialSpreadingTotalDictionary[enumValue],
804
796
  addEmptyRow: overrides[key]?.addEmptyRow ?? false,
805
797
  style: overrides[key]?.style ?? {},
@@ -822,18 +814,18 @@ class NewSummaryExcel {
822
814
  FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.NET_INCOME,
823
815
  ], {
824
816
  [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.GROSS_MARGIN]: {
825
- format: numberFormat.percent,
817
+ format: excel_helper_1.NUMBER_FORMATS.percent,
826
818
  addEmptyRow: true,
827
819
  style: { font: { italic: true, name: 'Calibri' } },
828
820
  },
829
821
  [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.OPERATING_MARGIN]: {
830
- format: numberFormat.percent,
822
+ format: excel_helper_1.NUMBER_FORMATS.percent,
831
823
  addEmptyRow: true,
832
824
  style: { font: { italic: true, name: 'Calibri' } },
833
825
  },
834
826
  [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS]: {
835
827
  title: 'EBITDA',
836
- format: numberFormat.thousands,
828
+ format: excel_helper_1.NUMBER_FORMATS.thousands,
837
829
  style: { font: { bold: true, name: 'Calibri' } },
838
830
  },
839
831
  [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.NON_OPERATING_EXPENSES]: {
@@ -903,7 +895,7 @@ class NewSummaryExcel {
903
895
  {
904
896
  label: 'Fixed Charge Coverage Ratio',
905
897
  dependencies: [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.FINANCING_COSTS, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.DEPRECIATION_AMORTIZATION, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS],
906
- format: numberFormat.xNumber1DP,
898
+ format: excel_helper_1.NUMBER_FORMATS.xNumber1DP,
907
899
  formula: (base, i) => {
908
900
  const EBITDA = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS);
909
901
  const DepreciationAmortization = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.DEPRECIATION_AMORTIZATION);
@@ -921,7 +913,7 @@ class NewSummaryExcel {
921
913
  {
922
914
  label: 'Interest Coverage Ratio',
923
915
  dependencies: [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.FINANCING_COSTS, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.DEPRECIATION_AMORTIZATION, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS],
924
- format: numberFormat.xNumber1DP,
916
+ format: excel_helper_1.NUMBER_FORMATS.xNumber1DP,
925
917
  formula: (base, i) => {
926
918
  const EBITDA = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS);
927
919
  const DepreciationAmortization = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.DEPRECIATION_AMORTIZATION);
@@ -939,7 +931,7 @@ class NewSummaryExcel {
939
931
  {
940
932
  label: 'Total Debt / EBITDA',
941
933
  dependencies: [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.COMPANY_DEBT, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.OTHER_DEBT],
942
- format: numberFormat.xNumber1DP,
934
+ format: excel_helper_1.NUMBER_FORMATS.xNumber1DP,
943
935
  formula: (base, i) => {
944
936
  const EBITDA = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS);
945
937
  const CompanyDebt = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.COMPANY_DEBT);
@@ -957,7 +949,7 @@ class NewSummaryExcel {
957
949
  {
958
950
  label: 'Senior Debt / EBITDA',
959
951
  dependencies: [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.COMPANY_DEBT],
960
- format: numberFormat.xNumber1DP,
952
+ format: excel_helper_1.NUMBER_FORMATS.xNumber1DP,
961
953
  formula: (base, i) => {
962
954
  const EBITDA = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.INCOME_FROM_OPERATIONS);
963
955
  const CompanyDebt = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.COMPANY_DEBT);
@@ -974,7 +966,7 @@ class NewSummaryExcel {
974
966
  {
975
967
  label: 'AR Turnover Days',
976
968
  dependencies: [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.SALES, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.TRADE_RECEIVABLES],
977
- format: numberFormat.fullNumber,
969
+ format: excel_helper_1.NUMBER_FORMATS.fullNumber,
978
970
  formula: (base, i) => {
979
971
  const Sales = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.SALES);
980
972
  const TradeReceivables = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.TRADE_RECEIVABLES);
@@ -991,7 +983,7 @@ class NewSummaryExcel {
991
983
  {
992
984
  label: 'AP Turnover Days',
993
985
  dependencies: [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.COST_OF_SALES, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.ACCOUNTS_PAYABLE],
994
- format: numberFormat.fullNumber,
986
+ format: excel_helper_1.NUMBER_FORMATS.fullNumber,
995
987
  formula: (base, i) => {
996
988
  const CostOfSales = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.COST_OF_SALES);
997
989
  const AccountsPayable = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.ACCOUNTS_PAYABLE);
@@ -1008,7 +1000,7 @@ class NewSummaryExcel {
1008
1000
  {
1009
1001
  label: 'Inventory Turnover Days',
1010
1002
  dependencies: [FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.COST_OF_SALES, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.INVENTORY],
1011
- format: numberFormat.fullNumber,
1003
+ format: excel_helper_1.NUMBER_FORMATS.fullNumber,
1012
1004
  formula: (base, i) => {
1013
1005
  const CostOfSales = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal.COST_OF_SALES);
1014
1006
  const Inventory = get(base, i, FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal.INVENTORY);
@@ -1036,7 +1028,7 @@ class NewSummaryExcel {
1036
1028
  for (let i = 0; i <= monthDeep; i++) {
1037
1029
  const result = formula(financialRatiosBase, i);
1038
1030
  if (result) {
1039
- row.push({ v: result, t: 'n', z: format ?? numberFormat.thousands });
1031
+ row.push({ v: result, t: 'n', z: format ?? excel_helper_1.NUMBER_FORMATS.thousands });
1040
1032
  }
1041
1033
  else {
1042
1034
  row.push(negativeCell);
@@ -1082,12 +1074,12 @@ class NewSummaryExcel {
1082
1074
  const totalRevolverWithStyle = totalRevolver.map((v) => ({
1083
1075
  v,
1084
1076
  t: 'n',
1085
- z: numberFormat.thousands,
1077
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
1086
1078
  }));
1087
1079
  const totalRevolverBalanceWithStyle = totalRevolverBalance.map((v) => ({
1088
1080
  v,
1089
1081
  t: 'n',
1090
- z: numberFormat.thousands,
1082
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
1091
1083
  }));
1092
1084
  const headRoomWithStyle = headRoom.map((v) => ({ v, t: 'n', z: '0.00%' }));
1093
1085
  const headRoomRows = [
@@ -1129,12 +1121,12 @@ class NewSummaryExcel {
1129
1121
  {
1130
1122
  v: row.totalAmount,
1131
1123
  t: 'n',
1132
- z: numberFormat.thousands,
1124
+ z: excel_helper_1.NUMBER_FORMATS.thousands,
1133
1125
  },
1134
1126
  {
1135
1127
  v: new decimal_js_1.default(row.totalAmount).div(total).toDP(4).toNumber(),
1136
1128
  t: 'n',
1137
- z: numberFormat.percent,
1129
+ z: excel_helper_1.NUMBER_FORMATS.percent,
1138
1130
  },
1139
1131
  ]));
1140
1132
  }