@dhis2/analytics 21.8.2 → 21.9.1
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/CHANGELOG.md +14 -0
- package/build/cjs/components/PeriodDimension/PeriodDimension.js +32 -1
- package/build/cjs/components/PeriodDimension/PeriodTransfer.js +20 -6
- package/build/cjs/components/PeriodDimension/__tests__/PeriodDimension.spec.js +13 -0
- package/build/cjs/components/PeriodDimension/__tests__/__snapshots__/PeriodDimension.spec.js.snap +6 -0
- package/build/cjs/components/PeriodDimension/utils/fixedPeriods.js +206 -478
- package/build/cjs/locales/en/translations.json +0 -14
- package/build/cjs/modules/pivotTable/PivotTableEngine.js +9 -28
- package/build/cjs/modules/pivotTable/__tests__/addToTotalIfNumber.js +72 -0
- package/build/cjs/modules/pivotTable/addToTotalIfNumber.js +10 -0
- package/build/es/components/PeriodDimension/PeriodDimension.js +30 -1
- package/build/es/components/PeriodDimension/PeriodTransfer.js +19 -6
- package/build/es/components/PeriodDimension/__tests__/PeriodDimension.spec.js +13 -0
- package/build/es/components/PeriodDimension/__tests__/__snapshots__/PeriodDimension.spec.js.snap +6 -0
- package/build/es/components/PeriodDimension/utils/fixedPeriods.js +204 -477
- package/build/es/locales/en/translations.json +0 -14
- package/build/es/modules/pivotTable/PivotTableEngine.js +8 -28
- package/build/es/modules/pivotTable/__tests__/addToTotalIfNumber.js +69 -0
- package/build/es/modules/pivotTable/addToTotalIfNumber.js +1 -0
- package/package.json +2 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { generateFixedPeriods, getNowInCalendar } from '@dhis2/multi-calendar-dates';
|
|
1
2
|
import i18n from '../../../locales/index.js';
|
|
2
3
|
import { DAILY, WEEKLY, WEEKLYWED, WEEKLYTHU, WEEKLYSAT, WEEKLYSUN, BIWEEKLY, MONTHLY, BIMONTHLY, QUARTERLY, SIXMONTHLY, SIXMONTHLYAPR, YEARLY, FYNOV, FYOCT, FYJUL, FYAPR } from './index.js';
|
|
3
4
|
const PERIOD_TYPE_REGEX = {
|
|
@@ -38,452 +39,179 @@ const PERIOD_TYPE_REGEX = {
|
|
|
38
39
|
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const getPeriods = ({
|
|
43
|
+
periodType,
|
|
44
|
+
config,
|
|
45
|
+
fnFilter,
|
|
46
|
+
periodSettings = {}
|
|
47
|
+
}) => {
|
|
48
|
+
const offset = parseInt(config.offset, 10);
|
|
49
|
+
const isFilter = config.filterFuturePeriods;
|
|
50
|
+
const isReverse = periodType.match(/^FY|YEARLY/) ? true : config.reversePeriods;
|
|
51
|
+
const {
|
|
52
|
+
calendar = 'gregory',
|
|
53
|
+
locale = 'en'
|
|
54
|
+
} = periodSettings;
|
|
55
|
+
const now = getNowInCalendar(calendar);
|
|
56
|
+
const year = (now.eraYear || now.year) + offset;
|
|
57
|
+
const params = {
|
|
58
|
+
periodType,
|
|
59
|
+
year,
|
|
60
|
+
calendar,
|
|
61
|
+
locale,
|
|
62
|
+
startingDay: config.startDay
|
|
63
|
+
};
|
|
64
|
+
let periods = generateFixedPeriods(params);
|
|
65
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
66
|
+
periods = !isReverse ? periods : periods.reverse();
|
|
67
|
+
return periods;
|
|
44
68
|
};
|
|
45
69
|
|
|
46
|
-
const getDailyPeriodType = (
|
|
70
|
+
const getDailyPeriodType = (fnFilter, periodSettings) => {
|
|
47
71
|
return config => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
while (date.getFullYear() === year) {
|
|
56
|
-
const period = {};
|
|
57
|
-
period.startDate = formatYyyyMmDd(date);
|
|
58
|
-
period.endDate = period.startDate;
|
|
59
|
-
period.name = period.startDate;
|
|
60
|
-
period.iso = period.startDate.replace(/-/g, '');
|
|
61
|
-
period.id = period.iso;
|
|
62
|
-
periods.push(period);
|
|
63
|
-
date.setDate(date.getDate() + 1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
67
|
-
periods = isReverse ? periods.reverse() : periods;
|
|
68
|
-
return periods;
|
|
72
|
+
return getPeriods({
|
|
73
|
+
periodType: 'DAILY',
|
|
74
|
+
config,
|
|
75
|
+
fnFilter,
|
|
76
|
+
periodSettings
|
|
77
|
+
});
|
|
69
78
|
};
|
|
70
79
|
};
|
|
71
80
|
|
|
72
|
-
const getWeeklyPeriodType = (
|
|
73
|
-
// Calculate the first date of an EPI year base on ISO standard ( first week always contains 4th Jan )
|
|
74
|
-
const getEpiWeekStartDay = (year, startDayOfWeek) => {
|
|
75
|
-
const jan4 = new Date(year, 0, 4);
|
|
76
|
-
const jan4DayOfWeek = jan4.getDay();
|
|
77
|
-
const startDate = jan4;
|
|
78
|
-
const dayDiff = jan4DayOfWeek - startDayOfWeek;
|
|
79
|
-
|
|
80
|
-
if (dayDiff > 0) {
|
|
81
|
-
startDate.setDate(jan4.getDate() - dayDiff);
|
|
82
|
-
} else if (dayDiff < 0) {
|
|
83
|
-
startDate.setDate(jan4.getDate() - dayDiff);
|
|
84
|
-
startDate.setDate(startDate.getDate() - 7);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return startDate;
|
|
88
|
-
};
|
|
89
|
-
|
|
81
|
+
const getWeeklyPeriodType = (weekObj, fnFilter, periodSettings) => {
|
|
90
82
|
return config => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
while (date.getFullYear() <= year) {
|
|
100
|
-
const period = {};
|
|
101
|
-
period.startDate = formatYyyyMmDd(date);
|
|
102
|
-
period.iso = "".concat(year).concat(weekObj.shortName, "W").concat(week);
|
|
103
|
-
period.id = period.iso;
|
|
104
|
-
date.setDate(date.getDate() + 6);
|
|
105
|
-
period.endDate = formatYyyyMmDd(date);
|
|
106
|
-
const weekNumber = week;
|
|
107
|
-
period.name = "".concat(i18n.t('Week {{weekNumber}}', {
|
|
108
|
-
weekNumber
|
|
109
|
-
}), " - ").concat(period.startDate, " - ").concat(period.endDate); // if end date is Jan 4th or later, week belongs to next year
|
|
110
|
-
|
|
111
|
-
if (date.getFullYear() > year && date.getDate() >= 4) {
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
periods.push(period);
|
|
116
|
-
date.setDate(date.getDate() + 1);
|
|
117
|
-
week += 1;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
121
|
-
periods = isReverse ? periods.reverse() : periods;
|
|
122
|
-
return periods;
|
|
83
|
+
return getPeriods({
|
|
84
|
+
periodType: 'WEEKLY',
|
|
85
|
+
config: { ...config,
|
|
86
|
+
startDay: weekObj.startDay
|
|
87
|
+
},
|
|
88
|
+
fnFilter,
|
|
89
|
+
periodSettings
|
|
90
|
+
});
|
|
123
91
|
};
|
|
124
92
|
};
|
|
125
93
|
|
|
126
|
-
const getBiWeeklyPeriodType = (
|
|
94
|
+
const getBiWeeklyPeriodType = (fnFilter, periodSettings) => {
|
|
127
95
|
return config => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const day = date.getDay();
|
|
135
|
-
let biWeek = 1;
|
|
136
|
-
|
|
137
|
-
if (day <= 4) {
|
|
138
|
-
date.setDate(date.getDate() - (day - 1));
|
|
139
|
-
} else {
|
|
140
|
-
date.setDate(date.getDate() + (8 - day));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
while (date.getFullYear() <= year) {
|
|
144
|
-
const period = {};
|
|
145
|
-
period.iso = "".concat(year, "BiW").concat(biWeek);
|
|
146
|
-
period.id = period.iso;
|
|
147
|
-
period.startDate = formatYyyyMmDd(date);
|
|
148
|
-
date.setDate(date.getDate() + 13);
|
|
149
|
-
period.endDate = formatYyyyMmDd(date);
|
|
150
|
-
const biWeekNumber = biWeek;
|
|
151
|
-
period.name = "".concat(i18n.t('Bi-Week {{biWeekNumber}}', {
|
|
152
|
-
biWeekNumber
|
|
153
|
-
}), " - ").concat(period.startDate, " - ").concat(period.endDate); // if end date is Jan 4th or later, biweek belongs to next year
|
|
154
|
-
|
|
155
|
-
if (date.getFullYear() > year && date.getDate() >= 4) {
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
periods.push(period);
|
|
160
|
-
date.setDate(date.getDate() + 1);
|
|
161
|
-
biWeek += 1;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
165
|
-
periods = isReverse ? periods.reverse() : periods;
|
|
166
|
-
return periods;
|
|
96
|
+
return getPeriods({
|
|
97
|
+
periodType: 'BIWEEKLY',
|
|
98
|
+
config,
|
|
99
|
+
fnFilter,
|
|
100
|
+
periodSettings
|
|
101
|
+
});
|
|
167
102
|
};
|
|
168
103
|
};
|
|
169
104
|
|
|
170
|
-
const getMonthlyPeriodType = (
|
|
171
|
-
const formatIso = date => {
|
|
172
|
-
const y = date.getFullYear();
|
|
173
|
-
let m = String(date.getMonth() + 1);
|
|
174
|
-
m = m.length < 2 ? "0".concat(m) : m;
|
|
175
|
-
return y + m;
|
|
176
|
-
};
|
|
177
|
-
|
|
105
|
+
const getMonthlyPeriodType = (fnFilter, periodSettings) => {
|
|
178
106
|
return config => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
while (date.getFullYear() === year) {
|
|
187
|
-
const period = {};
|
|
188
|
-
period.endDate = formatYyyyMmDd(date);
|
|
189
|
-
date.setDate(1);
|
|
190
|
-
period.startDate = formatYyyyMmDd(date);
|
|
191
|
-
const monthName = getMonthName(date.getMonth());
|
|
192
|
-
period.name = "".concat(monthName, " ").concat(year);
|
|
193
|
-
period.iso = formatIso(date);
|
|
194
|
-
period.id = period.iso;
|
|
195
|
-
periods.push(period);
|
|
196
|
-
date.setDate(0);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
200
|
-
periods = isReverse ? periods : periods.reverse(); // Months are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
201
|
-
|
|
202
|
-
return periods;
|
|
107
|
+
return getPeriods({
|
|
108
|
+
periodType: 'MONTHLY',
|
|
109
|
+
config,
|
|
110
|
+
fnFilter,
|
|
111
|
+
periodSettings
|
|
112
|
+
});
|
|
203
113
|
};
|
|
204
114
|
};
|
|
205
115
|
|
|
206
|
-
const getBiMonthlyPeriodType = (
|
|
116
|
+
const getBiMonthlyPeriodType = (fnFilter, periodSettings) => {
|
|
207
117
|
return config => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
let index = 6;
|
|
215
|
-
|
|
216
|
-
while (date.getFullYear() === year) {
|
|
217
|
-
const period = {};
|
|
218
|
-
period.endDate = formatYyyyMmDd(date);
|
|
219
|
-
date.setDate(0);
|
|
220
|
-
date.setDate(1);
|
|
221
|
-
period.startDate = formatYyyyMmDd(date);
|
|
222
|
-
const monthStart = getMonthName(date.getMonth());
|
|
223
|
-
const monthEnd = getMonthName(date.getMonth() + 1);
|
|
224
|
-
const fullYear = date.getFullYear();
|
|
225
|
-
period.name = "".concat(monthStart, " - ").concat(monthEnd, " ").concat(fullYear);
|
|
226
|
-
period.iso = "".concat(year, "0").concat(index, "B");
|
|
227
|
-
period.id = period.iso;
|
|
228
|
-
periods.push(period);
|
|
229
|
-
date.setDate(0);
|
|
230
|
-
index--;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
234
|
-
periods = isReverse ? periods : periods.reverse(); // Bi-months are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
235
|
-
|
|
236
|
-
return periods;
|
|
118
|
+
return getPeriods({
|
|
119
|
+
periodType: 'BIMONTHLY',
|
|
120
|
+
config,
|
|
121
|
+
fnFilter,
|
|
122
|
+
periodSettings
|
|
123
|
+
});
|
|
237
124
|
};
|
|
238
125
|
};
|
|
239
126
|
|
|
240
|
-
const getQuarterlyPeriodType = (
|
|
127
|
+
const getQuarterlyPeriodType = (fnFilter, periodSettings) => {
|
|
241
128
|
return config => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
let quarter = 4;
|
|
249
|
-
|
|
250
|
-
while (date.getFullYear() === year) {
|
|
251
|
-
const period = {};
|
|
252
|
-
period.endDate = formatYyyyMmDd(date);
|
|
253
|
-
date.setDate(0);
|
|
254
|
-
date.setDate(0);
|
|
255
|
-
date.setDate(1);
|
|
256
|
-
period.startDate = formatYyyyMmDd(date);
|
|
257
|
-
const monthStart = getMonthName(date.getMonth());
|
|
258
|
-
const monthEnd = getMonthName(date.getMonth() + 2);
|
|
259
|
-
const fullYear = date.getFullYear();
|
|
260
|
-
period.name = "".concat(monthStart, " - ").concat(monthEnd, " ").concat(fullYear);
|
|
261
|
-
period.iso = "".concat(year, "Q").concat(quarter);
|
|
262
|
-
period.id = period.iso;
|
|
263
|
-
periods.push(period);
|
|
264
|
-
date.setDate(0);
|
|
265
|
-
quarter -= 1;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
269
|
-
periods = isReverse ? periods : periods.reverse(); // Quarters are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
270
|
-
|
|
271
|
-
return periods;
|
|
129
|
+
return getPeriods({
|
|
130
|
+
periodType: 'QUARTERLY',
|
|
131
|
+
config,
|
|
132
|
+
fnFilter,
|
|
133
|
+
periodSettings
|
|
134
|
+
});
|
|
272
135
|
};
|
|
273
136
|
};
|
|
274
137
|
|
|
275
|
-
const getSixMonthlyPeriodType = fnFilter => {
|
|
138
|
+
const getSixMonthlyPeriodType = (fnFilter, periodSettings) => {
|
|
276
139
|
return config => {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
period.startDate = "".concat(year, "-01-01");
|
|
284
|
-
period.endDate = "".concat(year, "-06-30");
|
|
285
|
-
period.name = "".concat(getMonthName(0), " - ").concat(getMonthName(5), " ").concat(year);
|
|
286
|
-
period.iso = "".concat(year, "S1");
|
|
287
|
-
period.id = period.iso;
|
|
288
|
-
periods.push(period);
|
|
289
|
-
period = {};
|
|
290
|
-
period.startDate = "".concat(year, "-07-01");
|
|
291
|
-
period.endDate = "".concat(year, "-12-31");
|
|
292
|
-
period.name = "".concat(getMonthName(6), " - ").concat(getMonthName(11), " ").concat(year);
|
|
293
|
-
period.iso = "".concat(year, "S2");
|
|
294
|
-
period.id = period.iso;
|
|
295
|
-
periods.push(period);
|
|
296
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
297
|
-
periods = isReverse ? periods.reverse() : periods;
|
|
298
|
-
return periods;
|
|
140
|
+
return getPeriods({
|
|
141
|
+
periodType: 'SIXMONTHLY',
|
|
142
|
+
config,
|
|
143
|
+
fnFilter,
|
|
144
|
+
periodSettings
|
|
145
|
+
});
|
|
299
146
|
};
|
|
300
147
|
};
|
|
301
148
|
|
|
302
|
-
const getSixMonthlyAprilPeriodType = fnFilter => {
|
|
149
|
+
const getSixMonthlyAprilPeriodType = (fnFilter, periodSettings) => {
|
|
303
150
|
return config => {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
period.startDate = "".concat(year, "-04-01");
|
|
311
|
-
period.endDate = "".concat(year, "-09-30");
|
|
312
|
-
period.name = "".concat(getMonthName(3), " - ").concat(getMonthName(8), " ").concat(year);
|
|
313
|
-
period.iso = "".concat(year, "AprilS1");
|
|
314
|
-
period.id = period.iso;
|
|
315
|
-
periods.push(period);
|
|
316
|
-
period = {};
|
|
317
|
-
period.startDate = "".concat(year, "-10-01");
|
|
318
|
-
period.endDate = "".concat(year + 1, "-03-31");
|
|
319
|
-
period.name = "".concat(getMonthName(9), " ").concat(year, " - ").concat(getMonthName(2), " ").concat(year + 1);
|
|
320
|
-
period.iso = "".concat(year, "AprilS2");
|
|
321
|
-
period.id = period.iso;
|
|
322
|
-
periods.push(period);
|
|
323
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
324
|
-
periods = isReverse ? periods.reverse() : periods;
|
|
325
|
-
return periods;
|
|
151
|
+
return getPeriods({
|
|
152
|
+
periodType: 'SIXMONTHLYAPR',
|
|
153
|
+
config,
|
|
154
|
+
fnFilter,
|
|
155
|
+
periodSettings
|
|
156
|
+
});
|
|
326
157
|
};
|
|
327
158
|
};
|
|
328
159
|
|
|
329
|
-
const getYearlyPeriodType = (
|
|
160
|
+
const getYearlyPeriodType = (fnFilter, periodSettings) => {
|
|
330
161
|
return config => {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
while (year - date.getFullYear() < 10) {
|
|
339
|
-
const period = {};
|
|
340
|
-
period.endDate = formatYyyyMmDd(date);
|
|
341
|
-
date.setMonth(0, 1);
|
|
342
|
-
period.startDate = formatYyyyMmDd(date);
|
|
343
|
-
const dateString = date.getFullYear().toString();
|
|
344
|
-
period.name = dateString;
|
|
345
|
-
period.iso = date.getFullYear().toString();
|
|
346
|
-
period.id = period.iso.toString();
|
|
347
|
-
periods.push(period);
|
|
348
|
-
date.setDate(0);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
352
|
-
periods = isReverse ? periods : periods.reverse(); // Years are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
353
|
-
|
|
354
|
-
return periods;
|
|
162
|
+
return getPeriods({
|
|
163
|
+
periodType: 'YEARLY',
|
|
164
|
+
config,
|
|
165
|
+
fnFilter,
|
|
166
|
+
periodSettings
|
|
167
|
+
});
|
|
355
168
|
};
|
|
356
169
|
};
|
|
357
170
|
|
|
358
|
-
const getFinancialOctoberPeriodType = (
|
|
171
|
+
const getFinancialOctoberPeriodType = (fnFilter, periodSettings) => {
|
|
359
172
|
return config => {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
for (let i = 0; i < 10; i++) {
|
|
368
|
-
const period = {};
|
|
369
|
-
period.endDate = formatYyyyMmDd(date);
|
|
370
|
-
date.setYear(date.getFullYear() - 1);
|
|
371
|
-
date.setDate(date.getDate() + 1);
|
|
372
|
-
period.startDate = formatYyyyMmDd(date);
|
|
373
|
-
const yearStart = date.getFullYear();
|
|
374
|
-
const yearEnd = date.getFullYear() + 1;
|
|
375
|
-
period.name = "".concat(getMonthName(9), " ").concat(yearStart, " - ").concat(getMonthName(8), " ").concat(yearEnd);
|
|
376
|
-
period.id = "".concat(date.getFullYear(), "Oct");
|
|
377
|
-
periods.push(period);
|
|
378
|
-
date.setDate(date.getDate() - 1);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
382
|
-
periods = isReverse ? periods : periods.reverse(); // FinancialOctober periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
383
|
-
|
|
384
|
-
return periods;
|
|
173
|
+
return getPeriods({
|
|
174
|
+
periodType: 'FYOCT',
|
|
175
|
+
config,
|
|
176
|
+
fnFilter,
|
|
177
|
+
periodSettings
|
|
178
|
+
});
|
|
385
179
|
};
|
|
386
180
|
};
|
|
387
181
|
|
|
388
|
-
const getFinancialNovemberPeriodType = (
|
|
182
|
+
const getFinancialNovemberPeriodType = (fnFilter, periodSettings) => {
|
|
389
183
|
return config => {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
for (let i = 0; i < 10; i++) {
|
|
398
|
-
const period = {};
|
|
399
|
-
period.endDate = formatYyyyMmDd(date);
|
|
400
|
-
date.setYear(date.getFullYear() - 1);
|
|
401
|
-
date.setDate(date.getDate() + 1);
|
|
402
|
-
period.startDate = formatYyyyMmDd(date);
|
|
403
|
-
const yearStart = date.getFullYear();
|
|
404
|
-
const yearEnd = date.getFullYear() + 1;
|
|
405
|
-
period.name = "".concat(getMonthName(10), " ").concat(yearStart, " - ").concat(getMonthName(9), " ").concat(yearEnd);
|
|
406
|
-
period.id = "".concat(date.getFullYear(), "Nov");
|
|
407
|
-
periods.push(period);
|
|
408
|
-
date.setDate(date.getDate() - 1);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
412
|
-
periods = isReverse ? periods : periods.reverse(); // FinancialNovember periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
413
|
-
|
|
414
|
-
return periods;
|
|
184
|
+
return getPeriods({
|
|
185
|
+
periodType: 'FYNOV',
|
|
186
|
+
config,
|
|
187
|
+
fnFilter,
|
|
188
|
+
periodSettings
|
|
189
|
+
});
|
|
415
190
|
};
|
|
416
191
|
};
|
|
417
192
|
|
|
418
|
-
const getFinancialJulyPeriodType = (
|
|
193
|
+
const getFinancialJulyPeriodType = (fnFilter, periodSettings) => {
|
|
419
194
|
return config => {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
for (let i = 0; i < 10; i++) {
|
|
428
|
-
const period = {};
|
|
429
|
-
period.endDate = formatYyyyMmDd(date);
|
|
430
|
-
date.setYear(date.getFullYear() - 1);
|
|
431
|
-
date.setDate(date.getDate() + 1);
|
|
432
|
-
period.startDate = formatYyyyMmDd(date);
|
|
433
|
-
const yearStart = date.getFullYear();
|
|
434
|
-
const yearEnd = date.getFullYear() + 1;
|
|
435
|
-
period.name = "".concat(getMonthName(6), " ").concat(yearStart, " - ").concat(getMonthName(5), " ").concat(yearEnd);
|
|
436
|
-
period.id = "".concat(date.getFullYear(), "July");
|
|
437
|
-
periods.push(period);
|
|
438
|
-
date.setDate(date.getDate() - 1);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
442
|
-
periods = isReverse ? periods : periods.reverse(); // FinancialJuly periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
443
|
-
|
|
444
|
-
return periods;
|
|
195
|
+
return getPeriods({
|
|
196
|
+
periodType: 'FYJUL',
|
|
197
|
+
config,
|
|
198
|
+
fnFilter,
|
|
199
|
+
periodSettings
|
|
200
|
+
});
|
|
445
201
|
};
|
|
446
202
|
};
|
|
447
203
|
|
|
448
|
-
const getFinancialAprilPeriodType = (
|
|
204
|
+
const getFinancialAprilPeriodType = (fnFilter, periodSettings) => {
|
|
449
205
|
return config => {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
for (let i = 0; i < 10; i++) {
|
|
458
|
-
const period = {};
|
|
459
|
-
period.endDate = formatYyyyMmDd(date);
|
|
460
|
-
date.setYear(date.getFullYear() - 1);
|
|
461
|
-
date.setDate(date.getDate() + 1);
|
|
462
|
-
period.startDate = formatYyyyMmDd(date);
|
|
463
|
-
const yearStart = date.getFullYear();
|
|
464
|
-
const yearEnd = date.getFullYear() + 1;
|
|
465
|
-
period.name = "".concat(getMonthName(3), " ").concat(yearStart, " - ").concat(getMonthName(2), " ").concat(yearEnd);
|
|
466
|
-
period.id = "".concat(date.getFullYear(), "April");
|
|
467
|
-
periods.push(period);
|
|
468
|
-
date.setDate(date.getDate() - 1);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
472
|
-
periods = isReverse ? periods : periods.reverse(); // FinancialApril periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
473
|
-
|
|
474
|
-
return periods;
|
|
206
|
+
return getPeriods({
|
|
207
|
+
periodType: 'FYAPR',
|
|
208
|
+
config,
|
|
209
|
+
fnFilter,
|
|
210
|
+
periodSettings
|
|
211
|
+
});
|
|
475
212
|
};
|
|
476
213
|
};
|
|
477
214
|
|
|
478
|
-
const formatYyyyMmDd = date => {
|
|
479
|
-
const y = date.getFullYear();
|
|
480
|
-
let m = String(date.getMonth() + 1);
|
|
481
|
-
let d = String(date.getDate());
|
|
482
|
-
m = m.length < 2 ? "0".concat(m) : m;
|
|
483
|
-
d = d.length < 2 ? "0".concat(d) : d;
|
|
484
|
-
return "".concat(y, "-").concat(m, "-").concat(d);
|
|
485
|
-
};
|
|
486
|
-
|
|
487
215
|
const filterFuturePeriods = periods => {
|
|
488
216
|
const array = [];
|
|
489
217
|
const now = new Date(Date.now());
|
|
@@ -497,92 +225,91 @@ const filterFuturePeriods = periods => {
|
|
|
497
225
|
return array;
|
|
498
226
|
};
|
|
499
227
|
|
|
500
|
-
const getOptions =
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}, {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
},
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}, {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}, {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}, {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}, {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}, {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
}, {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}, {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}, {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}, {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}, {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
getPeriods: getFinancialAprilPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
582
|
-
name: i18n.t('Financial year (Start April)')
|
|
583
|
-
}];
|
|
228
|
+
const getOptions = periodSettings => {
|
|
229
|
+
return [{
|
|
230
|
+
id: DAILY,
|
|
231
|
+
getPeriods: getDailyPeriodType(filterFuturePeriods, periodSettings),
|
|
232
|
+
name: i18n.t('Daily')
|
|
233
|
+
}, {
|
|
234
|
+
id: WEEKLY,
|
|
235
|
+
getPeriods: getWeeklyPeriodType({
|
|
236
|
+
startDay: 1
|
|
237
|
+
}, filterFuturePeriods, periodSettings),
|
|
238
|
+
name: i18n.t('Weekly')
|
|
239
|
+
}, {
|
|
240
|
+
id: WEEKLYWED,
|
|
241
|
+
getPeriods: getWeeklyPeriodType({
|
|
242
|
+
startDay: 3
|
|
243
|
+
}, filterFuturePeriods, periodSettings),
|
|
244
|
+
name: i18n.t('Weekly (Start Wednesday)')
|
|
245
|
+
}, {
|
|
246
|
+
id: WEEKLYTHU,
|
|
247
|
+
getPeriods: getWeeklyPeriodType({
|
|
248
|
+
startDay: 4
|
|
249
|
+
}, filterFuturePeriods, periodSettings),
|
|
250
|
+
name: i18n.t('Weekly (Start Thursday)')
|
|
251
|
+
}, {
|
|
252
|
+
id: WEEKLYSAT,
|
|
253
|
+
getPeriods: getWeeklyPeriodType({
|
|
254
|
+
startDay: 6
|
|
255
|
+
}, filterFuturePeriods, periodSettings),
|
|
256
|
+
name: i18n.t('Weekly (Start Saturday)')
|
|
257
|
+
}, {
|
|
258
|
+
id: WEEKLYSUN,
|
|
259
|
+
getPeriods: getWeeklyPeriodType({
|
|
260
|
+
startDay: 7
|
|
261
|
+
}, filterFuturePeriods, periodSettings),
|
|
262
|
+
name: i18n.t('Weekly (Start Sunday)')
|
|
263
|
+
}, {
|
|
264
|
+
id: BIWEEKLY,
|
|
265
|
+
getPeriods: getBiWeeklyPeriodType(filterFuturePeriods, periodSettings),
|
|
266
|
+
name: i18n.t('Bi-weekly')
|
|
267
|
+
}, {
|
|
268
|
+
id: MONTHLY,
|
|
269
|
+
getPeriods: getMonthlyPeriodType(filterFuturePeriods, periodSettings),
|
|
270
|
+
name: i18n.t('Monthly')
|
|
271
|
+
}, {
|
|
272
|
+
id: BIMONTHLY,
|
|
273
|
+
getPeriods: getBiMonthlyPeriodType(filterFuturePeriods, periodSettings),
|
|
274
|
+
name: i18n.t('Bi-monthly')
|
|
275
|
+
}, {
|
|
276
|
+
id: QUARTERLY,
|
|
277
|
+
getPeriods: getQuarterlyPeriodType(filterFuturePeriods, periodSettings),
|
|
278
|
+
name: i18n.t('Quarterly')
|
|
279
|
+
}, {
|
|
280
|
+
id: SIXMONTHLY,
|
|
281
|
+
getPeriods: getSixMonthlyPeriodType(filterFuturePeriods, periodSettings),
|
|
282
|
+
name: i18n.t('Six-monthly')
|
|
283
|
+
}, {
|
|
284
|
+
id: SIXMONTHLYAPR,
|
|
285
|
+
getPeriods: getSixMonthlyAprilPeriodType(filterFuturePeriods, periodSettings),
|
|
286
|
+
name: i18n.t('Six-monthly April')
|
|
287
|
+
}, {
|
|
288
|
+
id: YEARLY,
|
|
289
|
+
getPeriods: getYearlyPeriodType(filterFuturePeriods, periodSettings),
|
|
290
|
+
name: i18n.t('Yearly')
|
|
291
|
+
}, {
|
|
292
|
+
id: FYNOV,
|
|
293
|
+
getPeriods: getFinancialNovemberPeriodType(filterFuturePeriods, periodSettings),
|
|
294
|
+
name: i18n.t('Financial year (Start November)')
|
|
295
|
+
}, {
|
|
296
|
+
id: FYOCT,
|
|
297
|
+
getPeriods: getFinancialOctoberPeriodType(filterFuturePeriods, periodSettings),
|
|
298
|
+
name: i18n.t('Financial year (Start October)')
|
|
299
|
+
}, {
|
|
300
|
+
id: FYJUL,
|
|
301
|
+
getPeriods: getFinancialJulyPeriodType(filterFuturePeriods, periodSettings),
|
|
302
|
+
name: i18n.t('Financial year (Start July)')
|
|
303
|
+
}, {
|
|
304
|
+
id: FYAPR,
|
|
305
|
+
getPeriods: getFinancialAprilPeriodType(filterFuturePeriods, periodSettings),
|
|
306
|
+
name: i18n.t('Financial year (Start April)')
|
|
307
|
+
}];
|
|
308
|
+
};
|
|
584
309
|
|
|
585
|
-
export const getFixedPeriodsOptionsById = id
|
|
310
|
+
export const getFixedPeriodsOptionsById = (id, periodSettings) => {
|
|
311
|
+
return getOptions(periodSettings).find(option => option.id === id);
|
|
312
|
+
};
|
|
586
313
|
export const getFixedPeriodsOptions = () => getOptions();
|
|
587
314
|
export const getYearOffsetFromNow = yearStr => parseInt(yearStr) - new Date(Date.now()).getFullYear();
|
|
588
315
|
export const parsePeriodCode = (code, allowedTypes) => {
|