From b56550c0715d71bfad7500e1b80fad1a702cf6a4 Mon Sep 17 00:00:00 2001 From: Mark Polak Date: Mon, 16 Mar 2015 16:28:30 +0100 Subject: [PATCH] Add one quarter from next year if the current is the last quarter of the year --- src/main/period/period-service.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/period/period-service.js b/src/main/period/period-service.js index 315f0e6..52f7b49 100644 --- a/src/main/period/period-service.js +++ b/src/main/period/period-service.js @@ -83,16 +83,21 @@ function periodService(d2Api) { //Show this years and last years quarters if (/^Quarterly$/.test(currentPeriodType)) { + var futureYear = []; var thisYear = dhis2.period.generator.generateReversedPeriods(currentPeriodType, 0); var currentQuarter = dhis2.period.generator.filterFuturePeriodsExceptCurrent(thisYear); thisYear = thisYear.slice((3 - currentQuarter.length >= 0) ? 3 - currentQuarter.length : 0); + if (currentQuarter.length === 4) { + futureYear = dhis2.period.generator.generateReversedPeriods(currentPeriodType, 1)[3]; + } + var oneYearAgo = dhis2.period.generator.generateReversedPeriods(currentPeriodType, -1); var twoYearsAgo = dhis2.period.generator.generateReversedPeriods(currentPeriodType, -2); var threeYearsAgo = dhis2.period.generator.generateReversedPeriods(currentPeriodType, -3); - generatedPeriods = thisYear.concat(oneYearAgo).concat(twoYearsAgo).concat(threeYearsAgo); + generatedPeriods = futureYear.concat(thisYear).concat(oneYearAgo).concat(twoYearsAgo).concat(threeYearsAgo); return; }