dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29698
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15041: support for financial year calenders in js generator
------------------------------------------------------------
revno: 15041
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-28 13:26:24 +0545
message:
support for financial year calenders in js generator
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js 2014-04-28 06:15:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js 2014-04-28 07:41:24 +0000
@@ -26,6 +26,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+
dhis2.util.namespace('dhis2.period');
dhis2.period.DEFAULT_DATE_FORMAT = "yyyy-mm-dd";
@@ -44,9 +48,9 @@
"SixMonthly": dhis2.period.makeSixMonthlyPeriodGenerator(calendar),
"SixMonthlyApril": dhis2.period.makeSixMonthlyAprilPeriodGenerator(calendar),
"Yearly": dhis2.period.makeYearlyPeriodGenerator(calendar),
- "FinancialOct": dhis2.period.makeMonthlyPeriodGenerator(calendar),
- "FinancialJuly": dhis2.period.makeMonthlyPeriodGenerator(calendar),
- "FinancialApril": dhis2.period.makeMonthlyPeriodGenerator(calendar)
+ "FinancialApril": dhis2.period.makeFinancialAprilPeriodGenerator(calendar),
+ "FinancialJuly": dhis2.period.makeFinancialJulyPeriodGenerator(calendar),
+ "FinancialOct": dhis2.period.makeFinancialOctoberPeriodGenerator(calendar)
};
this.getAll = function() {
@@ -171,7 +175,6 @@
}
var year = cal.today().year() - offset;
-
var periods = [];
var startDate = cal.newDate(year, 1, 1);
@@ -217,7 +220,6 @@
}
var year = cal.today().year() - offset;
-
var periods = [];
for( var month = 1; month <= cal.monthsInYear(year); month++ ) {
@@ -442,3 +444,51 @@
return self;
};
+
+dhis2.period.makeFinancialAprilPeriodGenerator = function( cal ) {
+ return dhis2.period.makeYearlyPeriodGeneratorWithMonthOffset(cal, 4, 'April');
+};
+
+dhis2.period.makeFinancialJulyPeriodGenerator = function( cal ) {
+ return dhis2.period.makeYearlyPeriodGeneratorWithMonthOffset(cal, 7, 'July');
+};
+
+dhis2.period.makeFinancialOctoberPeriodGenerator = function( cal ) {
+ return dhis2.period.makeYearlyPeriodGeneratorWithMonthOffset(cal, 10, 'Oct');
+};
+
+dhis2.period.makeYearlyPeriodGeneratorWithMonthOffset = function( cal, monthStart, monthShortName ) {
+ var self = {};
+ self.generatePeriods = function( offset ) {
+ if( typeof offset === 'undefined' ) {
+ offset = 0;
+ }
+
+ var year = cal.today().year() - offset;
+ var periods = [];
+
+ var startDate = cal.newDate(year - 5, monthStart, 1);
+
+ // generate 11 years, thisYear +/- 5 years
+ for( var i = 1; i < 12; i++ ) {
+ var endDate = cal.newDate(startDate).add(1, 'y').add(-1, 'd');
+
+ var period = {};
+ period['startDate'] = startDate.formatDate(dhis2.period.DEFAULT_DATE_FORMAT);
+ period['endDate'] = endDate.formatDate(dhis2.period.DEFAULT_DATE_FORMAT);
+ period['name'] = startDate.formatDate("MM yyyy") + ' - ' + endDate.formatDate("MM yyyy");
+ period['id'] = 'Financial' + monthShortName + '_' + period['startDate'];
+ period['iso'] = startDate.formatDate("yyyy") + monthShortName;
+
+ period['_startDate'] = startDate;
+ period['_endDate'] = endDate;
+
+ periods.push(period);
+ startDate.add(1, 'y');
+ }
+
+ return periods;
+ };
+
+ return self;
+};