← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4911: Improved generation of relative periods. The available periods for reporting period in report tab...

 

------------------------------------------------------------
revno: 4911
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-10-12 19:32:39 +0200
message:
  Improved generation of relative periods. The available periods for reporting period in report tables and reports are presented more intelligently.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/CalendarPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/BiMonthlyPeriodTypeTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/QuarterlyPeriodTypeTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableInternalProcess.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
  dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableGridTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dashboard/action/GetReportAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dashboard/action/GetReportParamsAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/inputReportParamsForm.vm
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectDataSet.vm
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectOrganisationUnit.vm
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectPeriod.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/EditDataSetFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/PeriodTypeListAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/CreateTableAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetReportParamsAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm
  dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedDataValuesAction.java
  dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedIndicatorValuesAction.java


--
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-api/src/main/java/org/hisp/dhis/period/CalendarPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/CalendarPeriodType.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/CalendarPeriodType.java	2011-10-12 17:32:39 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
@@ -92,9 +94,31 @@
      * generates for a year, all months in 2007 should be generated and returned
      * in order.
      * 
-     * @param date the date which touches the time span to generate Periods
-     *        for.
+     * @param date the date which touches the time span to generate Periods for.
      * @return a list of Periods for a defined time span.
      */
     public abstract List<Period> generatePeriods( Date date );
+    
+    /**
+     * Generates a list of Periods for the last 5 years. Must be overridden by
+     * CalendarPeriodTypes which do not generate periods for the current year
+     * only in their implementation of generatePeriods( Date ).
+     * 
+     * @param date the date which touches the time span to generate Periods for.
+     * @return a list of Periods for a defined time span.
+     */
+    public List<Period> generateLast5Years( Date date )
+    {
+        ArrayList<Period> periods = new ArrayList<Period>();
+        Calendar cal = createCalendarInstance( date );
+        cal.add( Calendar.YEAR, -4 );
+        
+        for ( int i = 0; i < 5; i++ )
+        {
+            periods.addAll( generatePeriods( cal.getTime() ) );
+            cal.add( Calendar.YEAR, 1 );
+        }
+        
+        return periods;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java	2011-10-12 17:32:39 +0000
@@ -135,6 +135,28 @@
     }
 
     @Override
+    public List<Period> generateLast5Years( Date date )
+    {
+        Calendar cal = createCalendarInstance( date );
+        
+        boolean past = cal.get( Calendar.MONTH ) >= getBaseMonth();
+        
+        cal.add( Calendar.YEAR, past ? -5 : -6 );
+        cal.set( Calendar.MONTH, getBaseMonth() );
+        cal.set( Calendar.DATE, 1 );
+
+        ArrayList<Period> periods = new ArrayList<Period>();
+
+        for ( int i = 0; i < 5; ++i )
+        {
+            periods.add( createPeriod( cal ) );
+            cal.add( Calendar.YEAR, 1 );
+        }
+
+        return periods;
+    }
+
+    @Override
     public String getIsoDate( Period period )
     {
         throw new UnsupportedOperationException( "Not supported yet." );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2011-10-12 10:32:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2011-10-12 17:32:39 +0000
@@ -155,6 +155,16 @@
     {
         return frequencyOrder() + 15;
     }
+    
+    /**
+     * Returns start date formatted as string.
+     * 
+     * @return start date formatted as string.
+     */
+    public String getStartDateString()
+    {
+        return getMediumDateString( startDate );
+    }
 
     /**
      * Formats a Date to the format YYYY-MM-DD.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2011-10-11 11:27:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2011-10-12 17:32:39 +0000
@@ -162,6 +162,9 @@
     // Logic
     // -------------------------------------------------------------------------
     
+    /**
+     * Sets all options to false.
+     */
     public RelativePeriods clear()
     {
         this.reportingMonth = false;
@@ -176,17 +179,56 @@
         this.last5Years = false;
         return this;
     }
+
+    /**
+     * Returns the period type for the option with the lowest frequency.
+     * 
+     * @return the period type.
+     */
+    public PeriodType getPeriodType()
+    {
+        if ( isReportingMonth() )
+        {
+            return PeriodType.getPeriodTypeByName( MonthlyPeriodType.NAME );
+        }
+        
+        if ( isReportingBimonth() )
+        {
+            return PeriodType.getPeriodTypeByName( BiMonthlyPeriodType.NAME );
+        }
+        
+        if ( isReportingQuarter() )
+        {
+            return PeriodType.getPeriodTypeByName( QuarterlyPeriodType.NAME );
+        }
+        
+        return PeriodType.getPeriodTypeByName( YearlyPeriodType.NAME );
+    }
     
     /**
-     * Returns the name of the reporting month.
-     * 
-     * @param months the number of months back in time representing the current month.
-     * @param format the i18n format.
-     * @return the name of the reporting month.
-     */
-    public String getReportingMonthName( int months, I18nFormat format )
-    {
-        Period period = new MonthlyPeriodType().createPeriod( getDate( months, null ) );
+     * Return the name of the reporting period.
+     * 
+     * @param date the start date of the reporting period.
+     * @param format the i18n format.
+     * @return the name of the reporting period.
+     */
+    public String getReportingPeriodName( Date date, I18nFormat format )
+    {
+        Period period = getPeriodType().createPeriod( date );
+        return format.formatPeriod( period );
+    }
+
+    /**
+     * Return the name of the reporting period. The current date is set to 
+     * todays date minus one month.
+     * 
+     * @param date the start date of the reporting period.
+     * @param format the i18n format.
+     * @return the name of the reporting period.
+     */
+    public String getReportingPeriodName( I18nFormat format )
+    {
+        Period period = getPeriodType().createPeriod( getDate( 1, new Date() ) );
         return format.formatPeriod( period );
     }
     
@@ -195,85 +237,83 @@
      */
     public List<Period> getRelativePeriods()
     {
-        return getRelativePeriods( 1, null, null, false );
+        return getRelativePeriods( getDate( 1, new Date() ), null, false );
     }
-    
+
     /**
-     * Gets a list of Periods based on the given input and the state of this RelativePeriods.
+     * Gets a list of Periods based on the given input and the state of this 
+     * RelativePeriods. The current date is set to todays date minus one month.
      * 
-     * @param months the number of months back in time representing the current month.
      * @param format the i18n format.
      * @return a list of relative Periods.
      */
-    public List<Period> getRelativePeriods( int months, I18nFormat format, boolean dynamicNames )
+    public List<Period> getRelativePeriods( I18nFormat format, boolean dynamicNames )
     {
-        return getRelativePeriods( months, null, format, dynamicNames );
+        return getRelativePeriods( getDate( 1, new Date() ), format, dynamicNames );
     }
     
     /**
-     * Gets a list of Periods based on the given input and the state of this RelativePeriods.
+     * Gets a list of Periods based on the given input and the state of this 
+     * RelativePeriods.
      * 
-     * @param months the number of months back in time representing the current reporting month.
-     * @param date the date representing now (for testing purposes).
+     * @param date the date representing now.
      * @param format the i18n format.
      * @return a list of relative Periods.
      */
-    protected List<Period> getRelativePeriods( int months, Date date, I18nFormat format, boolean dynamicNames )
+    public List<Period> getRelativePeriods( Date date, I18nFormat format, boolean dynamicNames )
     {
         List<Period> periods = new ArrayList<Period>();
         
-        Date current = getDate( months, date );
-        
         if ( isReportingMonth() )
         {
-            periods.add( getRelativePeriod( new MonthlyPeriodType(), REPORTING_MONTH, current, dynamicNames, format ) );
+            periods.add( getRelativePeriod( new MonthlyPeriodType(), REPORTING_MONTH, date, dynamicNames, format ) );
         }
         
         if ( isReportingBimonth() )
         {
-            periods.add( getRelativePeriod( new BiMonthlyPeriodType(), REPORTING_BIMONTH, current, dynamicNames, format ) );
+            periods.add( getRelativePeriod( new BiMonthlyPeriodType(), REPORTING_BIMONTH, date, dynamicNames, format ) );
         }
         
         if ( isReportingQuarter() )
         {
-            periods.add( getRelativePeriod( new QuarterlyPeriodType(), REPORTING_QUARTER, current, dynamicNames, format ) );
+            periods.add( getRelativePeriod( new QuarterlyPeriodType(), REPORTING_QUARTER, date, dynamicNames, format ) );
         }
         
         if ( isMonthsThisYear() )
         {
-            periods.addAll( getRelativePeriodList( new MonthlyPeriodType(), MONTHS_THIS_YEAR, current, dynamicNames, format ) );
+            periods.addAll( getRelativePeriodList( new MonthlyPeriodType(), MONTHS_THIS_YEAR, date, dynamicNames, format ) );
         }
         
         if ( isQuartersThisYear() )
         {
-            periods.addAll( getRelativePeriodList( new QuarterlyPeriodType(), QUARTERS_THIS_YEAR, current, dynamicNames, format ) );
+            periods.addAll( getRelativePeriodList( new QuarterlyPeriodType(), QUARTERS_THIS_YEAR, date, dynamicNames, format ) );
         }
         
         if ( isThisYear() )
         {
-            periods.add( getRelativePeriod( new YearlyPeriodType(), THIS_YEAR, current, dynamicNames, format ) );
+            periods.add( getRelativePeriod( new YearlyPeriodType(), THIS_YEAR, date, dynamicNames, format ) );
         }
 
         if ( isLast5Years() )
         {
-            periods.addAll( getRelativePeriodList( new YearlyPeriodType().generateLast5Years( current ), LAST_5_YEARS, dynamicNames, format ) );
+            periods.addAll( getRelativePeriodList( new YearlyPeriodType().generateLast5Years( date ), LAST_5_YEARS, dynamicNames, format ) );
         }
         
-        current = getDate( MONTHS_IN_YEAR, current );
+        date = getDate( MONTHS_IN_YEAR, date );
         
         if ( isMonthsLastYear() )
         {
-            periods.addAll( getRelativePeriodList( new MonthlyPeriodType(), MONTHS_LAST_YEAR, current, dynamicNames, format ) );
+            periods.addAll( getRelativePeriodList( new MonthlyPeriodType(), MONTHS_LAST_YEAR, date, dynamicNames, format ) );
         }
         
         if ( isQuartersLastYear() )
         {
-            periods.addAll( getRelativePeriodList( new QuarterlyPeriodType(), QUARTERS_LAST_YEAR, current, dynamicNames, format ) );
+            periods.addAll( getRelativePeriodList( new QuarterlyPeriodType(), QUARTERS_LAST_YEAR, date, dynamicNames, format ) );
         }
         
         if ( isLastYear() )
         {
-            periods.add( getRelativePeriod( new YearlyPeriodType(), LAST_YEAR, current, dynamicNames, format ) );
+            periods.add( getRelativePeriod( new YearlyPeriodType(), LAST_YEAR, date, dynamicNames, format ) );
         }
         
         return periods;
@@ -285,14 +325,14 @@
      * 
      * @param periodType the period type.
      * @param periodNames the array of period names.
-     * @param current the current date.
+     * @param date the current date.
      * @param dynamicNames indication of whether dynamic names should be used.
      * @param format the I18nFormat.
      * @return a list of periods.
      */
-    private List<Period> getRelativePeriodList( CalendarPeriodType periodType, String[] periodNames, Date current, boolean dynamicNames, I18nFormat format )
+    private List<Period> getRelativePeriodList( CalendarPeriodType periodType, String[] periodNames, Date date, boolean dynamicNames, I18nFormat format )
     {
-        return getRelativePeriodList( periodType.generatePeriods( current ), periodNames, dynamicNames, format );
+        return getRelativePeriodList( periodType.generatePeriods( date ), periodNames, dynamicNames, format );
     }
 
     /**
@@ -325,14 +365,14 @@
      * 
      * @param periodType the period type.
      * @param periodName the period name.
-     * @param current the current date.
+     * @param date the current date.
      * @param dynamicNames indication of whether dynamic names should be used.
      * @param format the I18nFormat.
      * @return a list of periods.
      */
-    private Period getRelativePeriod( CalendarPeriodType periodType, String periodName, Date current, boolean dynamicNames, I18nFormat format )
+    private Period getRelativePeriod( CalendarPeriodType periodType, String periodName, Date date, boolean dynamicNames, I18nFormat format )
     {
-        return setName( periodType.createPeriod( current ), periodName, dynamicNames, format );
+        return setName( periodType.createPeriod( date ), periodName, dynamicNames, format );
     }
     
     /**
@@ -355,16 +395,16 @@
      * Returns a date.
      * 
      * @param months the number of months to subtract from the current date.
-     * @param now the date representing now, ignored if null.
+     * @param date the date representing now, ignored if null.
      * @return a date.
      */
-    private Date getDate( int months, Date now )
+    public Date getDate( int months, Date date )
     {
         Calendar cal = PeriodType.createCalendarInstance();
         
-        if ( now != null ) // For testing purposes
+        if ( date != null ) // For testing purposes
         {
-            cal.setTime( now );
+            cal.setTime( date );
         }
         
         cal.add( Calendar.MONTH, ( months * -1 ) );        

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java	2011-10-12 17:32:39 +0000
@@ -155,6 +155,27 @@
     }
 
     @Override
+    public List<Period> generateLast5Years( Date date )
+    {
+        Calendar cal = createCalendarInstance( date );
+        cal.add( Calendar.YEAR, cal.get( Calendar.YEAR ) % 2 == 0 ? -10 : -9 );
+        cal.set( Calendar.DAY_OF_YEAR, 1 );
+
+        ArrayList<Period> twoYears = new ArrayList<Period>();
+
+        for ( int i = 0; i < 5; ++i )
+        {
+            Date startDate = cal.getTime();
+            cal.add( Calendar.YEAR, 1 );
+            cal.set( Calendar.DAY_OF_YEAR, cal.getActualMaximum( Calendar.DAY_OF_YEAR ) );
+            twoYears.add( new Period( this, startDate, cal.getTime() ) );
+            cal.add( Calendar.DAY_OF_YEAR, 1 );
+        }
+
+        return twoYears;
+    }
+
+    @Override
     public String getIsoDate( Period period )
     {
         throw new UnsupportedOperationException( "Not supported yet." );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2011-10-11 11:27:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2011-10-12 17:32:39 +0000
@@ -132,9 +132,7 @@
         return periods;
     }
 
-    /**
-     * Generates YearlyPeriods for the last 5 years including the current.
-     */
+    @Override
     public List<Period> generateLast5Years( Date date )
     {
         Calendar cal = createCalendarInstance( date );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java	2011-09-18 14:36:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java	2011-10-12 17:32:39 +0000
@@ -29,6 +29,7 @@
 
 import java.io.OutputStream;
 import java.util.Collection;
+import java.util.Date;
 
 import org.hisp.dhis.i18n.I18nFormat;
 
@@ -43,7 +44,7 @@
     final String REPORTTYPE_PDF = "pdf";
     final String REPORTTYPE_XLS = "xls";
 
-    public void renderReport( OutputStream out, Report report, Integer reportingPeriod, 
+    public void renderReport( OutputStream out, Report report, Date reportingPeriod, 
         Integer organisationUnitId, String type, I18nFormat format );
     
     /**

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2011-07-21 03:29:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2011-10-12 17:32:39 +0000
@@ -28,6 +28,7 @@
  */
 
 import java.util.Collection;
+import java.util.Date;
 
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.i18n.I18nFormat;
@@ -54,7 +55,7 @@
      *        report parameter, bot parent organisation unit and organisation unit.
      * @param format the I18nFormat to use.
      */
-    void populateReportTableDataMart( int id, String mode, Integer reportingPeriod, 
+    void populateReportTableDataMart( int id, String mode, Date reportingPeriod, 
         Integer organisationUnitId, I18nFormat format );
     
     /**
@@ -120,7 +121,7 @@
      * @param organisationUnitId the organisation unit number. 
      * @return a Grid.
      */
-    Grid getReportTableGrid( int id, I18nFormat format, Integer reportingPeriod, Integer organisationUnitId );
+    Grid getReportTableGrid( int id, I18nFormat format, Date reportingPeriod, Integer organisationUnitId );
     
     /**
      * If report table mode, this method will return the report table with the
@@ -140,7 +141,7 @@
     
     int getReportTableCountByName( String name );
     
- // -------------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     // ReportTableGroup
     // -------------------------------------------------------------------------
 

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/BiMonthlyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/BiMonthlyPeriodTypeTest.java	2011-09-16 07:53:59 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/BiMonthlyPeriodTypeTest.java	2011-10-12 17:32:39 +0000
@@ -124,4 +124,20 @@
         assertEquals( periodType.createPeriod( new Cal( 2009, 9, 1 ).time() ), periods.get( 4 ) );
         assertEquals( periodType.createPeriod( new Cal( 2009, 11, 1 ).time() ), periods.get( 5 ) );
     }
+    
+    @Test
+    public void testGenerateLast5Years()
+    {
+        testCal.set( 2009, 8, 15 );
+        
+        List<Period> periods = periodType.generateLast5Years( testCal.time() );
+        
+        assertEquals( 30, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 1, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 3, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 5, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 7, 1 ).time() ), periods.get( 3 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 9, 1 ).time() ), periods.get( 4 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 11, 1 ).time() ), periods.get( 5 ) );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java	2011-02-24 21:01:47 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java	2011-10-12 17:32:39 +0000
@@ -130,4 +130,26 @@
         assertEquals( periodType.createPeriod( new Cal( 2009, 11, 1 ).time() ), periods.get( 10 ) );
         assertEquals( periodType.createPeriod( new Cal( 2009, 12, 1 ).time() ), periods.get( 11 ) );
     }
+    
+    @Test
+    public void testGenerateLast5Years()
+    {
+        testCal.set( 2009, 8, 15 );
+        
+        List<Period> periods = periodType.generateLast5Years( testCal.time() );
+        
+        assertEquals( 60, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 1, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 2, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 3, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 4, 1 ).time() ), periods.get( 3 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 5, 1 ).time() ), periods.get( 4 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 6, 1 ).time() ), periods.get( 5 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 7, 1 ).time() ), periods.get( 6 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 8, 1 ).time() ), periods.get( 7 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 9, 1 ).time() ), periods.get( 8 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 10, 1 ).time() ), periods.get( 9 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 11, 1 ).time() ), periods.get( 10 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 12, 1 ).time() ), periods.get( 11 ) );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/QuarterlyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/QuarterlyPeriodTypeTest.java	2011-02-24 21:01:47 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/QuarterlyPeriodTypeTest.java	2011-10-12 17:32:39 +0000
@@ -123,4 +123,18 @@
         assertEquals( periodType.createPeriod( new Cal( 2009, 7, 1 ).time() ), periods.get( 2 ) );
         assertEquals( periodType.createPeriod( new Cal( 2009, 10, 1 ).time() ), periods.get( 3 ) );
     }
+
+    @Test
+    public void testGenerateLast5Years()
+    {
+        testCal.set( 2009, 8, 15 );
+        
+        List<Period> periods = periodType.generateLast5Years( testCal.time() );
+        
+        assertEquals( 20, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 1, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 4, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 7, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 10, 1 ).time() ), periods.get( 3 ) );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java	2011-10-11 11:27:38 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java	2011-10-12 17:32:39 +0000
@@ -60,7 +60,7 @@
     {        
         RelativePeriods periods = new RelativePeriods( true, true, true, true, true, true, true, true, true, true );
         
-        Collection<Period> relatives = periods.getRelativePeriods( 1, getDate( 2002, 1, 1 ), i18nFormat, false );
+        Collection<Period> relatives = periods.getRelativePeriods( getDate( 2001, 1, 1 ), i18nFormat, false );
         
         assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 1, 1 ), getDate( 2001, 1, 31 ) ) ) );
         assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 2, 1 ), getDate( 2001, 2, 28 ) ) ) );

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java	2011-02-24 21:01:47 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java	2011-10-12 17:32:39 +0000
@@ -122,4 +122,16 @@
         assertEquals( periodType.createPeriod( new Cal( 2009, 1, 1 ).time() ), periods.get( 0 ) );
         assertEquals( periodType.createPeriod( new Cal( 2009, 7, 1 ).time() ), periods.get( 1 ) );
     }
+    
+    @Test
+    public void testGenerateLast5Years()
+    {
+        testCal.set( 2009, 8, 15 );
+        
+        List<Period> periods = periodType.generateLast5Years( testCal.time() );
+        
+        assertEquals( 10, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 1, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 7, 1 ).time() ), periods.get( 1 ) );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2011-08-13 10:41:20 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2011-10-12 17:32:39 +0000
@@ -120,7 +120,7 @@
     {
         if ( relatives != null )
         {
-            periodIds.addAll( getIdentifiers( Period.class, periodService.reloadPeriods( relatives.getRelativePeriods( 1, null, false ) ) ) );
+            periodIds.addAll( getIdentifiers( Period.class, periodService.reloadPeriods( relatives.getRelativePeriods() ) ) );
         }
         
         dataMartEngine.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, completeExport, new OutputHolderState() );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-09-22 14:26:27 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-10-12 17:32:39 +0000
@@ -218,8 +218,7 @@
 
         if ( chart.getRelatives() != null )
         {
-            chart.setRelativePeriods( periodService.reloadPeriods( chart.getRelatives().getRelativePeriods( 1, null,
-                false ) ) );
+            chart.setRelativePeriods( periodService.reloadPeriods( chart.getRelatives().getRelativePeriods( format, true ) ) );
         }
 
         User user = currentUserService.getCurrentUser();
@@ -239,7 +238,7 @@
     {
         RelativePeriods relatives = new RelativePeriods();
         relatives.setMonthsThisYear( true );
-        List<Period> periods = periodService.reloadPeriods( relatives.getRelativePeriods( 1, format, true ) );
+        List<Period> periods = periodService.reloadPeriods( relatives.getRelativePeriods( format, true ) );
 
         Chart chart = new Chart();
 
@@ -267,7 +266,7 @@
     {
         RelativePeriods relatives = new RelativePeriods();
         relatives.setThisYear( true );
-        List<Period> periods = periodService.reloadPeriods( relatives.getRelativePeriods( 1, format, true ) );
+        List<Period> periods = periodService.reloadPeriods( relatives.getRelativePeriods( format, true ) );
 
         Chart chart = new Chart();
 

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java	2011-09-02 13:11:12 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java	2011-10-12 17:32:39 +0000
@@ -142,7 +142,7 @@
     {
         if ( relatives != null )
         {
-            Collection<Integer> periodIds = ConversionUtils.getIdentifiers( Period.class, periodService.reloadPeriods( relatives.getRelativePeriods( 1, null, false ) ) );
+            Collection<Integer> periodIds = ConversionUtils.getIdentifiers( Period.class, periodService.reloadPeriods( relatives.getRelativePeriods() ) );
             
             exportDataSetCompleteness( dataSetIds, periodIds, organisationUnitIds );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2011-09-19 13:34:58 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2011-10-12 17:32:39 +0000
@@ -30,6 +30,7 @@
 import java.io.OutputStream;
 import java.sql.Connection;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -114,7 +115,7 @@
     // ReportService implementation
     // -------------------------------------------------------------------------
 
-    public void renderReport( OutputStream out, Report report, Integer reportingPeriod, 
+    public void renderReport( OutputStream out, Report report, Date reportingPeriod, 
         Integer organisationUnitId, String type, I18nFormat format )
     {
         Map<String, Object> params = new HashMap<String, Object>();

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableInternalProcess.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableInternalProcess.java	2011-02-23 21:08:31 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableInternalProcess.java	2011-10-12 17:32:39 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Date;
+
 import org.amplecode.cave.process.SerialToGroup;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.system.process.AbstractStatementInternalProcess;
@@ -71,9 +73,9 @@
         this.mode = mode;
     }
 
-    private Integer reportingPeriod;
+    private Date reportingPeriod;
 
-    public void setReportingPeriod( Integer reportingPeriod )
+    public void setReportingPeriod( Date reportingPeriod )
     {
         this.reportingPeriod = reportingPeriod;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2011-10-12 11:48:47 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2011-10-12 17:32:39 +0000
@@ -42,6 +42,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -153,7 +154,7 @@
     // ReportTableService implementation
     // -------------------------------------------------------------------------
 
-    public void populateReportTableDataMart( int id, String mode, Integer reportingPeriod, Integer organisationUnitId,
+    public void populateReportTableDataMart( int id, String mode, Date reportingPeriod, Integer organisationUnitId,
         I18nFormat format )
     {
         ReportTable reportTable = getReportTable( id, mode );
@@ -175,7 +176,7 @@
         }
     }
 
-    public Grid getReportTableGrid( int id, I18nFormat format, Integer reportingPeriod, Integer organisationUnitId )
+    public Grid getReportTableGrid( int id, I18nFormat format, Date reportingPeriod, Integer organisationUnitId )
     {
         ReportTable reportTable = getReportTable( id );
 
@@ -365,7 +366,7 @@
      * @param format the I18n format.
      * @return a report table.
      */
-    private ReportTable initDynamicMetaObjects( ReportTable reportTable, Integer reportingPeriod,
+    private ReportTable initDynamicMetaObjects( ReportTable reportTable, Date reportingPeriod,
         Integer organisationUnitId, I18nFormat format )
     {
         // ---------------------------------------------------------------------
@@ -376,7 +377,7 @@
         {
             reportTable.setRelativePeriods( periodService.reloadPeriods( reportTable.getRelatives().getRelativePeriods(
                 reportingPeriod, format, !reportTable.isDoPeriods() ) ) );
-            reportTable.setReportingPeriodName( reportTable.getRelatives().getReportingMonthName( reportingPeriod,
+            reportTable.setReportingPeriodName( reportTable.getRelatives().getReportingPeriodName( reportingPeriod,
                 format ) );
 
             log.info( "Reporting period date from report param: " + reportTable.getReportingPeriodName() );
@@ -384,8 +385,8 @@
         else
         {
             reportTable.setRelativePeriods( periodService.reloadPeriods( reportTable.getRelatives().getRelativePeriods(
-                1, format, !reportTable.isDoPeriods() ) ) );
-            reportTable.setReportingPeriodName( reportTable.getRelatives().getReportingMonthName( 1, format ) );
+                format, !reportTable.isDoPeriods() ) ) );
+            reportTable.setReportingPeriodName( reportTable.getRelatives().getReportingPeriodName( format ) );
 
             log.info( "Reporting period date default: " + reportTable.getReportingPeriodName() );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableGridTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableGridTest.java	2011-10-10 13:26:01 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableGridTest.java	2011-10-12 17:32:39 +0000
@@ -29,6 +29,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -135,6 +136,8 @@
     private int unitIdB;
         
     private I18nFormat i18nFormat;
+    
+    private Date date = new Date();
 
     // -------------------------------------------------------------------------
     // Fixture
@@ -338,7 +341,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, null, 0 );
         
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 13.0, grid.getRow( 0 ).get( 7 ) );
@@ -360,7 +363,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 9 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 10 ) );
@@ -384,7 +387,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 7 ) );
@@ -406,7 +409,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 13.0, grid.getRow( 0 ).get( 7 ) );
@@ -428,7 +431,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
         
         assertEquals( 11.0, grid.getRow( 0 ).get( 9 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 10 ) );
@@ -452,7 +455,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
         
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 7 ) );
@@ -474,7 +477,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
         
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 13.0, grid.getRow( 0 ).get( 7 ) );
@@ -496,7 +499,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 9 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 10 ) );
@@ -520,7 +523,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 7 ) );
@@ -555,7 +558,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
         
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 11.0, grid.getRow( 0 ).get( 7 ) );
@@ -598,7 +601,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
         
         assertEquals( 11.0, grid.getRow( 0 ).get( 9 ) );
         assertEquals( 11.0, grid.getRow( 0 ).get( 10 ) );
@@ -643,7 +646,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
                 
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 11.0, grid.getRow( 0 ).get( 7 ) );
@@ -686,7 +689,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 12 ) );
         assertEquals( 11.0, grid.getRow( 0 ).get( 13 ) );
@@ -730,7 +733,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 13.0, grid.getRow( 0 ).get( 7 ) );
@@ -768,7 +771,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
         
         assertEquals( 11.0, grid.getRow( 0 ).get( 9 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 10 ) );
@@ -816,7 +819,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 7 ) );
@@ -854,7 +857,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 3 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 4 ) );
@@ -875,7 +878,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 11.0, grid.getRow( 0 ).get( 12 ) );
         assertEquals( 12.0, grid.getRow( 1 ).get( 12 ) );
@@ -897,7 +900,7 @@
         
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 2, grid.getHeight() );
         
@@ -918,7 +921,7 @@
         
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
 
         assertEquals( 17.0, grid.getRow( 0 ).get( 9 ) );
         assertEquals( 18.0, grid.getRow( 0 ).get( 10 ) );
@@ -942,7 +945,7 @@
 
         int id = reportTableService.saveReportTable( reportTable );
 
-        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, 0, 0 );
+        Grid grid = reportTableService.getReportTableGrid( id, i18nFormat, date, 0 );
         
         assertEquals( 11.0, grid.getRow( 0 ).get( 6 ) );
         assertEquals( 12.0, grid.getRow( 0 ).get( 7 ) );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java	2011-09-22 14:26:27 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java	2011-10-12 17:32:39 +0000
@@ -2,6 +2,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Date;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -71,7 +72,7 @@
             public void write( OutputStream out )
                 throws IOException, WebApplicationException
             {
-                reportService.renderReport( out, report, 1, organisationUnitId, ReportService.REPORTTYPE_PDF, format );
+                reportService.renderReport( out, report, new Date(), organisationUnitId, ReportService.REPORTTYPE_PDF, format );
             }
         } ).build();
     }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dashboard/action/GetReportAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dashboard/action/GetReportAction.java	2011-09-28 10:34:08 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dashboard/action/GetReportAction.java	2011-10-12 17:32:39 +0000
@@ -27,9 +27,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Date;
+
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.reporttable.ReportTableService;
+import org.hisp.dhis.system.util.DateUtils;
 
 import com.opensymphony.xwork2.Action;
 
@@ -65,9 +68,9 @@
         this.id = id;
     }
 
-    private Integer reportingPeriod;
+    private String reportingPeriod;
 
-    public void setReportingPeriod( Integer reportingPeriod )
+    public void setReportingPeriod( String reportingPeriod )
     {
         this.reportingPeriod = reportingPeriod;
     }
@@ -98,7 +101,9 @@
     public String execute()
         throws Exception
     {
-        grid = reportTableService.getReportTableGrid( id, format, reportingPeriod, organisationUnitId );
+        Date date = reportingPeriod != null ? DateUtils.getMediumDate( reportingPeriod ) : new Date();
+        
+        grid = reportTableService.getReportTableGrid( id, format, date, organisationUnitId );
         
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dashboard/action/GetReportParamsAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dashboard/action/GetReportParamsAction.java	2011-09-28 10:34:08 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dashboard/action/GetReportParamsAction.java	2011-10-12 17:32:39 +0000
@@ -27,19 +27,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Calendar;
-import java.util.SortedMap;
-import java.util.TreeMap;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
 
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
-import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.CalendarPeriodType;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportParams;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
+import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter;
+import org.hisp.dhis.system.util.FilterUtils;
 
 import com.opensymphony.xwork2.Action;
 
@@ -49,8 +49,6 @@
 public class GetReportParamsAction
     implements Action
 {
-    private static final int AVAILABLE_REPORTING_MONTHS = 24;
-    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -102,19 +100,12 @@
     {
         return reportParams;
     }
-        
-    private SortedMap<Integer, String> reportingPeriods = new TreeMap<Integer, String>();
-
-    public SortedMap<Integer, String> getReportingPeriods()
-    {
-        return reportingPeriods;
-    }
-    
-    private Report report;
-
-    public Report getReport()
-    {
-        return report;
+
+    private List<Period> periods;
+
+    public List<Period> getPeriods()
+    {
+        return periods;
     }
 
     // -------------------------------------------------------------------------
@@ -128,26 +119,22 @@
         if ( id != null )
         {
             ReportTable reportTable = reportTableService.getReportTable( id, ReportTableService.MODE_REPORT_TABLE );
-            
+
             if ( reportTable != null )
             {
                 reportParams = reportTable.getReportParams();
                                 
-                if ( reportParams.isParamReportingMonth() )
+                if ( reportParams.isParamReportingMonth() && reportTable.getRelatives() != null )
                 {
-                    MonthlyPeriodType periodType = new MonthlyPeriodType();
-                    
-                    Calendar cal = PeriodType.createCalendarInstance();
-                    
-                    for ( int i = 0; i < AVAILABLE_REPORTING_MONTHS; i++ )
+                    CalendarPeriodType periodType = (CalendarPeriodType) reportTable.getRelatives().getPeriodType();
+                    periods = periodType.generateLast5Years( new Date() );
+                    Collections.reverse( periods );
+                    FilterUtils.filter( periods, new PastAndCurrentPeriodFilter() );
+                    
+                    for ( Period period : periods )
                     {
-                        int month = i + 1;    
-                        cal.add( Calendar.MONTH, -1 );                    
-                        Period period = periodType.createPeriod( cal.getTime() );                    
-                        String periodName = format.formatPeriod( period );
-                        
-                        reportingPeriods.put( month, periodName );
-                    }                
+                        period.setName( format.formatPeriod( period ) );
+                    }
                 }
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java	2011-10-11 17:30:01 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java	2011-10-12 17:32:39 +0000
@@ -28,10 +28,11 @@
 
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -44,14 +45,9 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.CalendarPeriodType;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter;
-import org.hisp.dhis.system.util.FilterUtils;
+import org.hisp.dhis.period.PeriodService;
 
 import com.opensymphony.xwork2.Action;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import org.hisp.dhis.period.DefaultPeriodService;
-import org.hisp.dhis.period.PeriodService;
 
 /**
  * @author mortenoh
@@ -94,6 +90,7 @@
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
+    
     private Integer organisationUnitId;
 
     public void setOrganisationUnitId( Integer organisationUnitId )
@@ -142,6 +139,7 @@
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
+    
     @Override
     public String execute()
     {
@@ -156,7 +154,6 @@
             cal.add( Calendar.MONTH, -12 );
             Date dateStart = cal.getTime();
 
-            //      System.out.println(">>>>"+dateEnd.toString()+"\n||||"+dateStart.toString());
             //FilterUtils.filter( periods, new PastAndCurrentPeriodFilter() );
             Collection<Period> periodsBetweenDates = periodService.getPeriodsBetweenDates( periodType, dateStart, dateEnd );
             periods = (List<Period>) periodsBetweenDates;

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2011-10-11 17:30:01 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2011-10-12 17:32:39 +0000
@@ -1,14 +1,13 @@
 report_table_parameters = Report parameters
-reporting_month = Reporting month
 get_report = Get report
 select_organisation_unit = Please select organisation unit
-#test
 DHIS_2=DHIS 2
-data_entry=Data Entry
-dashboard=Dashboard
-available_datasets=Available Datasets
-available_organisation_units= Available organization Units
-logout=Logout
-available_periods=Available_Periods
-menu=Menu
-save=Save
+data_entry = Data Entry
+dashboard = Dashboard
+available_datasets = Available data sets
+available_organisation_units = Available organisation Units
+logout = Logout
+available_periods = Available periods
+menu = Menu
+save = Save
+reporting_period = Report period

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/inputReportParamsForm.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/inputReportParamsForm.vm	2011-04-07 12:42:11 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/inputReportParamsForm.vm	2011-10-12 17:32:39 +0000
@@ -19,12 +19,12 @@
 
 #if ( $!reportParams.isParamReportingMonth() )
 
-<div class="labelDiv">$i18n.getString( "reporting_month" )</div>
+<div class="labelDiv">$i18n.getString( "reporting_period" )</div>
 
 <div class="pageDiv">
 <select id="reportingPeriod" name="reportingPeriod" style="width:300px">               
-#foreach ( $key in $reportingPeriods.keySet() )
-<option value="$key">$reportingPeriods.get( $key )</option>
+#foreach ( $period in $periods )
+<option value="${period.startDateString}">${period.name}</option>
 #end
 </select>
 </div>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectDataSet.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectDataSet.vm	2011-10-11 17:30:01 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectDataSet.vm	2011-10-12 17:32:39 +0000
@@ -1,12 +1,11 @@
 
-<h2>$i18n.getString("available_datasets")</h2>
-
+<h2>$i18n.getString( "available_datasets" )</h2>
 <p>
-	<ul>
-		#foreach( $dataSet in $dataSets )
-		<li><a href="selectPeriod.action?organisationUnitId=$organisationUnitId&dataSetId=$dataSet.id">$!encoder.jsonEncode( ${dataSet.name} )</a></li>
-		#end
-	</ul>
+<ul>
+	#foreach( $dataSet in $dataSets )
+	<li><a href="selectPeriod.action?organisationUnitId=$organisationUnitId&dataSetId=$dataSet.id">$!encoder.jsonEncode( ${dataSet.name} )</a></li>
+	#end
+</ul>
 </p>
 
 <div id="footer">

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectOrganisationUnit.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectOrganisationUnit.vm	2011-10-11 17:30:01 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectOrganisationUnit.vm	2011-10-12 17:32:39 +0000
@@ -1,14 +1,14 @@
 
-<h2>$i18n.getString("available_oganisation_units")</h2>
-
+<h2>$i18n.getString( "available_organisation_units" )</h2>
 
 <p>
-	<ul>
-	#foreach( $organisationUnit in $organisationUnits )
-		<li><a href="selectDataSet.action?organisationUnitId=$organisationUnit.id">$!encoder.jsonEncode( ${organisationUnit.name} )</a></li>
-	#end
-	</ul>
+<ul>
+#foreach( $organisationUnit in $organisationUnits )
+	<li><a href="selectDataSet.action?organisationUnitId=$organisationUnit.id">$!encoder.jsonEncode( ${organisationUnit.name} )</a></li>
+#end
+</ul>
 </p>
+
 <div id="footer">
 <ul><li>
 <a href="index.action">$i18n.getString("menu")</a></li>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectPeriod.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectPeriod.vm	2011-10-12 13:13:14 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectPeriod.vm	2011-10-12 17:32:39 +0000
@@ -1,5 +1,5 @@
 
-<h2>$i18n.getString("available_periods")</h2>
+<h2>$i18n.getString( "available_periods" )</h2>
 
 <p>
 	<ul>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/EditDataSetFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/EditDataSetFormAction.java	2011-05-19 17:07:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/EditDataSetFormAction.java	2011-10-12 17:32:39 +0000
@@ -30,7 +30,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Iterator;
 import java.util.List;
 
 import org.hisp.dhis.dataelement.DataElement;
@@ -38,7 +37,6 @@
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
-import org.hisp.dhis.period.OnChangePeriodType;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 
@@ -142,16 +140,6 @@
     {
         periodTypes = periodService.getAllPeriodTypes();
 
-        Iterator<PeriodType> iterator = periodTypes.iterator();
-
-        while ( iterator.hasNext() )
-        {
-            if ( iterator.next().getName().equalsIgnoreCase( OnChangePeriodType.NAME ) )
-            {
-                iterator.remove();
-            }
-        }
-
         if ( dataSetId != null )
         {
             dataSet = dataSetService.getDataSet( dataSetId );
@@ -160,11 +148,9 @@
         }
 
         Collections.sort( dataElements, dataElementComparator );
-
         Collections.sort( indicators, indicatorComparator );
 
         displayPropertyHandler.handle( dataElements );
-
         displayPropertyHandler.handle( indicators );
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/PeriodTypeListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/PeriodTypeListAction.java	2011-05-27 10:24:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/PeriodTypeListAction.java	2011-10-12 17:32:39 +0000
@@ -28,9 +28,7 @@
  */
 
 import java.util.Collection;
-import java.util.Iterator;
 
-import org.hisp.dhis.period.OnChangePeriodType;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 
@@ -78,16 +76,6 @@
     {   	
         periodTypes = periodService.getAllPeriodTypes();
         
-        Iterator<PeriodType> iterator = periodTypes.iterator();
-        
-        while( iterator.hasNext() )
-        {
-        	if( iterator.next().getName().equalsIgnoreCase( OnChangePeriodType.NAME ) )
-        	{
-        		iterator.remove();
-        	}
-        }  	
-    	
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java	2011-09-18 14:36:11 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java	2011-10-12 17:32:39 +0000
@@ -30,6 +30,7 @@
 import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
 
 import java.io.OutputStream;
+import java.util.Date;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -37,6 +38,7 @@
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.report.ReportService;
 import org.hisp.dhis.system.util.CodecUtils;
+import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.util.ContextUtils;
 import org.hisp.dhis.util.StreamActionSupport;
 
@@ -78,9 +80,9 @@
         this.id = id;
     }
 
-    private Integer reportingPeriod;
+    private String reportingPeriod;
 
-    public void setReportingPeriod( Integer reportingPeriod )
+    public void setReportingPeriod( String reportingPeriod )
     {
         this.reportingPeriod = reportingPeriod;
     }
@@ -110,8 +112,10 @@
         type = defaultIfEmpty( type, DEFAULT_TYPE );
         
         Report report = reportService.getReport( id );
+
+        Date date = reportingPeriod != null ? DateUtils.getMediumDate( reportingPeriod ) : new Date();
         
-        reportService.renderReport( out, report, reportingPeriod, organisationUnitId, type, format );
+        reportService.renderReport( out, report, date, organisationUnitId, type, format );
         
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/CreateTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/CreateTableAction.java	2011-02-23 21:08:31 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/CreateTableAction.java	2011-10-12 17:32:39 +0000
@@ -31,10 +31,13 @@
 import static org.hisp.dhis.util.InternalProcessUtil.PROCESS_KEY_REPORT;
 import static org.hisp.dhis.util.InternalProcessUtil.setCurrentRunningProcess;
 
+import java.util.Date;
+
 import org.amplecode.cave.process.ProcessCoordinator;
 import org.amplecode.cave.process.ProcessExecutor;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.reporttable.ReportTableInternalProcess;
+import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.user.CurrentUserService;
 
 import com.opensymphony.xwork2.Action;
@@ -89,9 +92,9 @@
         this.mode = mode;
     }
 
-    private Integer reportingPeriod;
+    private String reportingPeriod;
 
-    public void setReportingPeriod( Integer reportingPeriod )
+    public void setReportingPeriod( String reportingPeriod )
     {
         this.reportingPeriod = reportingPeriod;
     }
@@ -116,9 +119,11 @@
         
         ReportTableInternalProcess process = (ReportTableInternalProcess) executor.getProcess();
 
+        Date date = reportingPeriod != null ? DateUtils.getMediumDate( reportingPeriod ) : new Date();
+        
         process.setId( id );
         process.setMode( mode );
-        process.setReportingPeriod( reportingPeriod );
+        process.setReportingPeriod( date );
         process.setOrganisationUnitId( organisationUnitId );
         process.setFormat( format );
 

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java	2011-09-14 12:46:13 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java	2011-10-12 17:32:39 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -36,6 +37,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
+import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.util.SessionUtils;
 
 import com.opensymphony.xwork2.Action;
@@ -80,9 +82,9 @@
         this.format = format;
     }
     
-    private Integer reportingPeriod;
+    private String reportingPeriod;
 
-    public void setReportingPeriod( Integer reportingPeriod )
+    public void setReportingPeriod( String reportingPeriod )
     {
         this.reportingPeriod = reportingPeriod;
     }
@@ -154,8 +156,10 @@
         else
         {
             ReportTable reportTable = reportTableService.getReportTable( id );
+
+            Date date = reportingPeriod != null ? DateUtils.getMediumDate( reportingPeriod ) : new Date();
             
-            grid = reportTableService.getReportTableGrid( id, format, reportingPeriod, organisationUnitId );
+            grid = reportTableService.getReportTableGrid( id, format, date, organisationUnitId );
             
             params.putAll( constantService.getConstantParameterMap() );
             params.putAll( reportTable.getOrganisationUnitGroupMap( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() ) );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetReportParamsAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetReportParamsAction.java	2011-03-29 20:06:47 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetReportParamsAction.java	2011-10-12 17:32:39 +0000
@@ -27,18 +27,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Calendar;
-import java.util.SortedMap;
-import java.util.TreeMap;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
 
 import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.CalendarPeriodType;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportParams;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
+import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter;
+import org.hisp.dhis.system.util.FilterUtils;
 
 import com.opensymphony.xwork2.Action;
 
@@ -49,8 +49,6 @@
 public class GetReportParamsAction
     implements Action
 {
-    private static final int AVAILABLE_REPORTING_MONTHS = 24;
-    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -107,19 +105,12 @@
     {
         return reportParams;
     }
-        
-    private SortedMap<Integer, String> reportingPeriods = new TreeMap<Integer, String>();
-
-    public SortedMap<Integer, String> getReportingPeriods()
-    {
-        return reportingPeriods;
-    }
     
-    private Report report;
+    private List<Period> periods;
 
-    public Report getReport()
+    public List<Period> getPeriods()
     {
-        return report;
+        return periods;
     }
 
     // -------------------------------------------------------------------------
@@ -136,21 +127,17 @@
             {
                 reportParams = reportTable.getReportParams();
                                 
-                if ( reportParams.isParamReportingMonth() )
+                if ( reportParams.isParamReportingMonth() && reportTable.getRelatives() != null )
                 {
-                    MonthlyPeriodType periodType = new MonthlyPeriodType();
-                    
-                    Calendar cal = PeriodType.createCalendarInstance();
-                    
-                    for ( int i = 0; i < AVAILABLE_REPORTING_MONTHS; i++ )
+                    CalendarPeriodType periodType = (CalendarPeriodType) reportTable.getRelatives().getPeriodType();
+                    periods = periodType.generateLast5Years( new Date() );
+                    Collections.reverse( periods );
+                    FilterUtils.filter( periods, new PastAndCurrentPeriodFilter() );
+                    
+                    for ( Period period : periods )
                     {
-                        int month = i + 1;    
-                        cal.add( Calendar.MONTH, -1 );                    
-                        Period period = periodType.createPeriod( cal.getTime() );                    
-                        String periodName = format.formatPeriod( period );
-                        
-                        reportingPeriods.put( month, periodName );
-                    }                
+                        period.setName( format.formatPeriod( period ) );
+                    }
                 }
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-10-11 14:15:32 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-10-12 17:32:39 +0000
@@ -389,4 +389,5 @@
 leaf_parent_organisation_unit = Leaf organisation units
 reporting_bimonth = Reporting bimonth
 reporting_quarter = Reporting quarter
-include_organisation_unit_group_sets = Include org unit group sets param
\ No newline at end of file
+include_organisation_unit_group_sets = Include org unit group sets param
+reporting_period = Reporting period
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm	2011-09-14 15:17:22 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm	2011-10-12 17:32:39 +0000
@@ -39,13 +39,13 @@
     #if ( $!reportParams.isParamReportingMonth() )
     
     <tr>
-        <th>$i18n.getString( "reporting_month" )</th>
+        <th>$i18n.getString( "reporting_period" )</th>
     </tr>
     <tr>
         <td>
             <select id="reportingPeriod" name="reportingPeriod" style="width:325px">               
-                #foreach ( $key in $reportingPeriods.keySet() )
-                    <option value="$key">$reportingPeriods.get( $key )</option>
+                #foreach ( $period in $periods )
+                    <option value="${period.startDateString}">${period.name}</option>
                 #end
             </select>
         </td>

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedDataValuesAction.java'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedDataValuesAction.java	2011-10-11 11:27:38 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedDataValuesAction.java	2011-10-12 17:32:39 +0000
@@ -178,7 +178,7 @@
                 thisYear, monthsLastYear, quartersLastYear, lastYear, lastFiveYears );
 
             Collection<Integer> relativePeriods = ConversionUtils.getIdentifiers( Period.class,
-                periodService.reloadPeriods( relativePeriod.getRelativePeriods( 1, format, true ) ) );
+                periodService.reloadPeriods( relativePeriod.getRelativePeriods( format, true ) ) );
 
             object = aggregatedDataValueService.getAggregatedDataValues( dataElementIds, relativePeriods,
                 organisationUnitIds );

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedIndicatorValuesAction.java'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedIndicatorValuesAction.java	2011-10-11 11:27:38 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedIndicatorValuesAction.java	2011-10-12 17:32:39 +0000
@@ -178,7 +178,7 @@
                 thisYear, monthsLastYear, quartersLastYear, lastYear, lastFiveYears );
 
             Collection<Integer> relativePeriods = ConversionUtils.getIdentifiers( Period.class,
-                periodService.reloadPeriods( relativePeriod.getRelativePeriods( 1, format, true ) ) );
+                periodService.reloadPeriods( relativePeriod.getRelativePeriods( format, true ) ) );
 
             object = aggregatedDataValueService.getAggregatedIndicatorValues( indicatorIds, relativePeriods,
                 organisationUnitIds );