=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java 2011-09-08 15:47:47 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java 2011-11-22 09:03:42 +0000 @@ -65,6 +65,7 @@ private static final String TITLE_SEP = " - "; private static final String FIRST_COLUMN_TEXT = "Organisation unit"; + private static final String HEADER_NONE = "None"; private static final String HEADER_TOTAL = "Total"; // ------------------------------------------------------------------------- @@ -135,23 +136,46 @@ grid.addHeader( new GridHeader( group.getName(), false, false ) ); } + grid.addHeader( new GridHeader( HEADER_NONE, false, false ) ); grid.addHeader( new GridHeader( HEADER_TOTAL, false, false ) ); + boolean hasNone = false; + for ( OrganisationUnit unit : units ) { grid.addRow(); grid.addValue( unit.getName() ); + int totalGroup = 0; + Collection subTree = organisationUnitService.getOrganisationUnitWithChildren( unit.getId() ); for ( OrganisationUnitGroup group : groups ) { Collection result = CollectionUtils.intersection( subTree, group.getMembers() ); - grid.addValue( result != null ? result.size() : 0 ); - } - - grid.addValue( subTree != null ? subTree.size() : 0 ); + int count = result != null ? result.size() : 0; + + grid.addValue( count ); + + totalGroup += count; + } + + int total = subTree != null ? subTree.size() : 0; + int none = total - totalGroup; + + grid.addValue( none ); + grid.addValue( total ); + + if ( none > 0 ) + { + hasNone = true; + } + } + + if ( !hasNone ) + { + grid.removeColumn( grid.getWidth() - 2 ); // None column } return grid;