@zeniai/client-epic-state 5.0.57 → 5.0.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.
@@ -63,8 +63,16 @@ function getSummationBalance(summationType, resultSlice, allMonthlyBalancesOrder
63
63
  console.error('Invalid option passed!!');
64
64
  return undefined;
65
65
  }
66
- case 'rolling_12_months_average':
67
- return getRolling12MonthsAverageBalance(allMonthlyBalancesOrderedAsc, thisPeriod, summationType);
66
+ case 'rolling_12_months_average': {
67
+ let sumDivisor = 12;
68
+ const thisPeriodIsTotal = isBalanceSheetBalances === true || isCashFlowCashAndEquivalents != null;
69
+ if (thisPeriodIsTotal === false &&
70
+ thisPeriod.balanceTimeFrame === 'quarter') {
71
+ // For quarterly view, show the average per quarter where it is relevant.
72
+ sumDivisor = 4;
73
+ }
74
+ return getRolling12MonthsAverageBalance(allMonthlyBalancesOrderedAsc, thisPeriod, summationType, sumDivisor);
75
+ }
68
76
  }
69
77
  }
70
78
  exports.getSummationBalance = getSummationBalance;
@@ -150,15 +158,13 @@ function getRolling12MonthsTotalBalance(allMonthlyBalancesOrderedAsc, thisPeriod
150
158
  return undefined;
151
159
  }
152
160
  }
153
- function getRolling12MonthsAverageBalance(allMonthlyBalancesOrderedAsc, thisPeriod, type) {
161
+ function getRolling12MonthsAverageBalance(allMonthlyBalancesOrderedAsc, thisPeriod, type, sumDivisor) {
154
162
  const thisMonthIndex = lodash_findlastindex_1.default(allMonthlyBalancesOrderedAsc, (value) => thisPeriod.endDate.set('date', 1).isSame(value.startDate) &&
155
163
  thisPeriod.endDate.isSame(value.endDate));
156
164
  if (thisMonthIndex != -1) {
157
165
  const rolling12Months = allMonthlyBalancesOrderedAsc.slice(-12, thisMonthIndex + 1);
158
166
  const sumAmount = rolling12Months.reduce((sum, value) => sum + value.balance.amount, 0);
159
- // For Quarter show quarterly average. For month & year, show rolling 12 months monthly average
160
- const averageDivisor = thisPeriod.balanceTimeFrame === 'quarter' ? 4 : 12;
161
- const average = rolling12Months.length > 0 ? sumAmount / averageDivisor : 0;
167
+ const average = rolling12Months.length > 0 ? sumAmount / sumDivisor : 0;
162
168
  const resultBalance = Object.assign({}, thisPeriod, {
163
169
  type: type,
164
170
  balanceTimeFrame: 'free_range',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.57",
3
+ "version": "5.0.58",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",