=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportOrganizationGroupListingAction.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportOrganizationGroupListingAction.java 2010-11-25 22:22:10 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportOrganizationGroupListingAction.java 2010-12-20 08:25:07 +0000 @@ -53,6 +53,7 @@ public class GenerateReportOrganizationGroupListingAction extends GenerateReportSupport { + private static final String PREFIX_FORMULA_SUM = "SUM("; // ------------------------------------------- // Dependency @@ -72,9 +73,9 @@ statementManager.initialise(); OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - + Period period = periodGenericManager.getSelectedPeriod(); - + this.installPeriod( period ); ReportExcelOganiztionGroupListing reportExcel = (ReportExcelOganiztionGroupListing) reportService @@ -88,7 +89,7 @@ for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportId() ) ) { Sheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 ); - + Collection reportExcelItems = reportExcel.getReportItemBySheet( sheetNo ); this.generateOutPutFile( reportExcel, orgUniGroupAtLevels, reportExcelItems, organisationUnit, sheet ); @@ -121,12 +122,11 @@ int chapperNo = 0; int firstRow = reportItem.getRow(); int rowBegin = firstRow + 1; - - String totalFormula = "SUM("; - + + String totalFormula = PREFIX_FORMULA_SUM; + for ( OrganisationUnitGroup organisationUnitGroup : reportExcel.getOrganisationUnitGroups() ) { - OrganisationUnitLevel organisationUnitLevel = orgUniGroupAtLevels.get( organisationUnitGroup ); List organisationUnitsAtLevel = new ArrayList(); @@ -143,7 +143,6 @@ .getOrganisationUnitsAtLevel( organisationUnitLevel.getLevel(), organisationUnit ) ); organisationUnits.retainAll( organisationUnitsAtLevel ); - } else { @@ -166,8 +165,8 @@ ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), chappter[chapperNo], ExcelUtils.TEXT, sheet, this.csText12BoldCenter ); chapperNo++; - } - + } + rowBegin++; int serial = 1; @@ -212,22 +211,22 @@ && (!organisationUnits.isEmpty()) ) { String columnName = ExcelUtils.convertColNumberToColName( reportItem.getColumn() ); - String formula = "SUM(" + columnName + (beginChapter + 1) + ":" + columnName + (rowBegin - 1) + ")"; + String formula = "SUM(" + columnName + (beginChapter + 1) + ":" + columnName + (rowBegin - 1) + ")"; + ExcelUtils.writeFormulaByPOI( beginChapter, reportItem.getColumn(), formula, sheet, this.csFormula ); - totalFormula += columnName + beginChapter + ","; + totalFormula += columnName + beginChapter + ","; } } - - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT )) + + if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) + && !totalFormula.equals( PREFIX_FORMULA_SUM ) ) { totalFormula = totalFormula.substring( 0, totalFormula.length() - 1 ) + ")"; - - ExcelUtils.writeFormulaByPOI( firstRow, reportItem.getColumn(), totalFormula, sheet, this.csFormula ); + ExcelUtils.writeFormulaByPOI( firstRow, reportItem.getColumn(), totalFormula, sheet, this.csFormula ); } - } } } === modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportSupport.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportSupport.java 2010-12-16 08:48:12 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportSupport.java 2010-12-20 08:25:07 +0000 @@ -576,8 +576,7 @@ if ( reportItem.getPeriodType().equalsIgnoreCase( ReportExcelItem.PERIODTYPE.SELECTED_MONTH ) ) { - value = MathUtils - .calculateExpression( generateExpression( reportItem, startDate, endDate, organisationUnit ) ); + value = MathUtils.calculateExpression( generateExpression( reportItem, startDate, endDate, organisationUnit ) ); } else if ( reportItem.getPeriodType().equalsIgnoreCase( ReportExcelItem.PERIODTYPE.LAST_3_MONTH ) ) { @@ -609,7 +608,7 @@ value = MathUtils.calculateExpression( generateExpression( reportItem, startSixMonthly, endSixMonthly, organisationUnit ) ); } - + return value; } @@ -634,34 +633,23 @@ while ( matcher.find() ) { String replaceString = matcher.group(); - + replaceString = replaceString.replaceAll( "[\\[\\]]", "" ); String dataElementIdString = replaceString.substring( 0, replaceString.indexOf( SEPARATOR ) ); - String optionComboIdString = replaceString.substring( replaceString.indexOf( SEPARATOR ) + 1, - replaceString.length() ); + String optionComboIdString = replaceString.substring( replaceString.indexOf( SEPARATOR ) + 1, replaceString.length() ); int dataElementId = Integer.parseInt( dataElementIdString ); int optionComboId = Integer.parseInt( optionComboIdString ); DataElement dataElement = dataElementService.getDataElement( dataElementId ); - + DataElementCategoryOptionCombo optionCombo = categoryService .getDataElementCategoryOptionCombo( optionComboId ); - - if ( !(dataElement instanceof CalculatedDataElement) ) - { - - replaceString = getValue( dataElement, optionCombo, organisationUnit, startDate, endDate ) + ""; - - matcher.appendReplacement( buffer, replaceString ); - - matcher.appendTail( buffer ); - - } - - else if ( dataElement instanceof CalculatedDataElement ) - { + + // CalculatedDataElement + if ( dataElement instanceof CalculatedDataElement ) + { CalculatedDataElement calculatedDataElement = (CalculatedDataElement) dataElement; int factor = 0; @@ -680,23 +668,28 @@ optionComboIdString = operandId.substring( operandId.indexOf( SEPARATOR ) + 1, operandId .length() ); - DataElement element = dataElementService - .getDataElement( Integer.parseInt( dataElementIdString ) ); - optionCombo = categoryService.getDataElementCategoryOptionCombo( Integer - .parseInt( optionComboIdString ) ); + DataElement element = dataElementService.getDataElement( Integer.parseInt( dataElementIdString ) ); + optionCombo = categoryService.getDataElementCategoryOptionCombo( Integer.parseInt( optionComboIdString ) ); double dataValue = getValue( element, optionCombo, organisationUnit, startDate, endDate ); - value += dataValue * factor; - + value += (dataValue * factor); } - buffer.append( value ); + matcher.appendReplacement( buffer, value + "" ); + } + // Normal + else + { + replaceString = getValue( dataElement, optionCombo, organisationUnit, startDate, endDate ) + ""; - break; + matcher.appendReplacement( buffer, replaceString ); } } - + + // Finally + matcher.appendTail( buffer ); + return buffer.toString(); } catch ( NumberFormatException ex )