← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3054: Implemented subtotals and totals in dataset section report

 

------------------------------------------------------------
revno: 3054
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-03-16 22:25:24 +0100
message:
  Implemented subtotals and totals in dataset section report
modified:
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateSectionDataSetReportAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderSectionDataSetReportForm.vm


--
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-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateSectionDataSetReportAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateSectionDataSetReportAction.java	2011-03-16 16:26:53 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateSectionDataSetReportAction.java	2011-03-16 21:25:24 +0000
@@ -41,6 +41,8 @@
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.Section;
@@ -66,6 +68,7 @@
     implements Action
 {
     private static final String DEFAULT_HEADER = "Value";
+    private static final String TOTAL_HEADER = "Total";
     
     // -------------------------------------------------------------------------
     // Dependencies
@@ -193,7 +196,8 @@
         throws Exception
     {
         String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY );
-
+        boolean realTime = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME );
+        
         List<Section> sections = new ArrayList<Section>( selectedDataSet.getSections() );
         Collections.sort( sections, new SectionOrderComparator() );
 
@@ -205,17 +209,32 @@
         {
             Grid grid = new ListGrid().setTitle( section.getName() );
 
+            DataElementCategoryCombo categoryCombo = section.getCategoryCombo();
+            
             // -----------------------------------------------------------------
             // Grid headers
             // -----------------------------------------------------------------
 
             grid.addHeader( new GridHeader( i18n.getString( "dataelement" ), false, true ) ); // Data element header
 
-            for ( DataElementCategoryOptionCombo optionCombo : section.getCategoryCombo().getOptionCombos() ) // Value headers
+            for ( DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos() ) // Value headers
             {
                 grid.addHeader( new GridHeader( optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false ) );
             }
 
+            if ( categoryCombo.doSubTotals() && !selectedUnitOnly ) // Sub-total headers
+            {
+                for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() )
+                {
+                    grid.addHeader( new GridHeader( categoryOption.getName(), false, false ) );
+                }
+            }
+            
+            if ( categoryCombo.doTotal() && !selectedUnitOnly ) // Total header
+            {
+                grid.addHeader( new GridHeader( TOTAL_HEADER, false, false ) );
+            }
+            
             // -----------------------------------------------------------------
             // Grid values
             // -----------------------------------------------------------------
@@ -229,7 +248,7 @@
                 grid.addRow();
                 grid.addValue( dataElement.getName() ); // Data element name
 
-                for ( DataElementCategoryOptionCombo optionCombo : section.getCategoryCombo().getOptionCombos() ) // Values
+                for ( DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos() ) // Values
                 {
                     String value = null;
 
@@ -240,15 +259,36 @@
                     }
                     else
                     {
-                        Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService
-                            .getAggregatedDataValue( dataElement, optionCombo, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedOrgunit )
-                            : aggregatedDataValueService.getAggregatedValue( dataElement, optionCombo, selectedPeriod, selectedOrgunit );
+                        Double aggregatedValue = realTime ? 
+                            aggregationService.getAggregatedDataValue( dataElement, optionCombo, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedOrgunit ) : 
+                            aggregatedDataValueService.getAggregatedValue( dataElement, optionCombo, selectedPeriod, selectedOrgunit );
 
-                        value = ( aggregatedValue != null ) ? String.valueOf( MathUtils.getRounded( aggregatedValue, 0 ) ) : null;
+                        value = aggregatedValue != null ? String.valueOf( MathUtils.getRounded( aggregatedValue, 0 ) ) : null;
                     }
                     
                     grid.addValue( value );
                 }
+                
+                if ( categoryCombo.doSubTotals() && !selectedUnitOnly ) // Sub-total values
+                {
+                    for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() )
+                    {
+                        Double value = realTime ? 
+                            aggregationService.getAggregatedDataValue( dataElement, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedOrgunit, categoryOption ) : 
+                            aggregatedDataValueService.getAggregatedValue( dataElement, categoryOption, selectedPeriod, selectedOrgunit );
+
+                        grid.addValue( value != null ? String.valueOf( MathUtils.getRounded( value, 0 ) ) : null );
+                    }
+                }
+                
+                if ( categoryCombo.doTotal() && !selectedUnitOnly ) // Total value
+                {
+                    Double value = realTime ?
+                        aggregationService.getAggregatedDataValue( dataElement, null, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedOrgunit ) :
+                        aggregatedDataValueService.getAggregatedValue( dataElement, selectedPeriod, selectedOrgunit );
+                        
+                    grid.addValue( value != null ? String.valueOf( MathUtils.getRounded( value, 0 ) ) : null );
+                }
             }
 
             grids.add( grid );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderSectionDataSetReportForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderSectionDataSetReportForm.vm	2011-03-16 16:26:53 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderSectionDataSetReportForm.vm	2011-03-16 21:25:24 +0000
@@ -1,34 +1,36 @@
 <h3>$i18n.getString('reporting_unit'): $reportingUnit &nbsp; $i18n.getString('reporting_period'): $reportingPeriod</h3>
 <p><input type="button" value="$i18n.getString( 'back' )" style="width:100px" onclick="javascript:window.location.href='showDataSetReportForm.action'"/></p>
 
-<div id="printDateSetPreviewDiv" style="margin-bottom:20px">
+<div id="printDateSetPreviewDiv">
 #foreach( $grid in $grids )
 
 <h3>$!encoder.htmlEncode( $grid.title )</h3>
 <h5>$!encoder.htmlEncode( $grid.subtitle )</h5>
 
-	<table class="listTable gridTable">
-	<thead>
-		<tr>
-			#foreach( $header in $grid.getVisibleHeaders() )
-				<th #if( $header.meta )style="text-align:left"#end>$!encoder.htmlEncode( $header.name )</th>
-			#end
-		</tr>
-	</thead>
-
-	<tbody>
-	#set( $mark = false )       
-	#foreach( $row in $grid.getVisibleRows() )
-		<tr #alternate( $mark )>
-			#foreach( $col in $row )
-				#set( $index = ( $velocityCount - 1 ) )
-				<td #if( $grid.getVisibleHeaders().get( $index ).meta )style="text-align:left"#end>$!encoder.htmlEncode( $col )</td>
-			#end
-		</tr>
-		 #set( $mark = !$mark )
-	#end
-	</tbody>
-	</table>
+<table class="listTable gridTable">
+<thead>
+	<tr>
+		#foreach( $header in $grid.getVisibleHeaders() )
+			<th #if( !$header.meta )style="text-align:center;"#end>$!encoder.htmlEncode( $header.name )</th>
+		#end
+	</tr>
+</thead>
+
+<tbody>
+#set( $mark = false )       
+#foreach( $row in $grid.getVisibleRows() )
+	<tr #alternate( $mark )>
+		#foreach( $col in $row )
+			#set( $index = ( $velocityCount - 1 ) )
+			<td #if( !$grid.getVisibleHeaders().get( $index ).meta )style="text-align:center;"#end>$!encoder.htmlEncode( $col )</td>
+		#end
+	</tr>
+	 #set( $mark = !$mark )
+#end
+</tbody>
+</table>
+
+<br>
 #end
 </div>