← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 871: Added Previewing function into Advanced Report Excel function ...

 

------------------------------------------------------------
revno: 871
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2009-10-16 14:19:35 +0700
message:
  Added Previewing function into Advanced Report Excel function ...
added:
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedCategoryAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedNormalAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedOrgGroupListingAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedPeriodColumnListingAction.java
modified:
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/viewReportPreview.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.
=== added directory 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance'
=== added directory 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action'
=== added file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedCategoryAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedCategoryAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedCategoryAction.java	2009-10-16 07:19:35 +0000
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.hisp.dhis.reportexcel.preview.advance.action;
+
+import java.util.Collection;
+import java.util.Set;
+
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.reportexcel.DataElementGroupOrder;
+import org.hisp.dhis.reportexcel.ReportExcelCategory;
+import org.hisp.dhis.reportexcel.ReportExcelItem;
+import org.hisp.dhis.reportexcel.preview.action.GeneratePreviewReportExcelSupport;
+import org.hisp.dhis.reportexcel.utils.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @author Chau Thu Tran
+ * @author Tran Thanh Tri
+ * @version $Id$
+ * @since 2009-10-08
+ */
+public class GeneratePreviewAdvancedCategoryAction
+    extends GeneratePreviewReportExcelSupport
+{
+    // ---------------------------------------------------------------------
+    // Dependency
+    // ---------------------------------------------------------------------
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    // ---------------------------------------------------------------------
+    // Input && Output
+    // ---------------------------------------------------------------------
+
+    private Integer orgunitGroupId;
+
+    // ---------------------------------------------------------------------
+    // Getters && Setters
+    // ---------------------------------------------------------------------
+
+    public void setOrgunitGroupId( Integer orgunitGroupId )
+    {
+        this.orgunitGroupId = orgunitGroupId;
+    }
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
+    // ---------------------------------------------------------------------
+    // Action implementation
+    // ---------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        statementManager.initialise();
+
+        OrganisationUnitGroup organisationUnitGroup = organisationUnitGroupService
+            .getOrganisationUnitGroup( orgunitGroupId.intValue() );
+        
+        Period period = selectionManager.getSelectedPeriod();
+        this.installPeriod( period );
+        
+        ReportExcelCategory reportExcel = (ReportExcelCategory) reportService.getReportExcel( selectionManager
+            .getSelectedReportExcelId() );
+
+        this.installReadTemplateFile( reportExcel, period, organisationUnitGroup );
+
+        if ( this.sheetId > 0 )
+        {
+            HSSFSheet sheet = this.templateWorkbook.getSheetAt( this.sheetId - 1 );
+
+            Collection<ReportExcelItem> reportExcelItems = reportService.getReportExcelItem( this.sheetId,
+                selectionManager.getSelectedReportExcelId() );
+
+            this.generateOutPutFile( organisationUnitGroup.getMembers(), reportExcelItems, reportExcel, sheet );
+        }
+        else
+        {
+            for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportExcelId() ) )
+            {
+                HSSFSheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 );
+
+                Collection<ReportExcelItem> reportExcelItems = reportService.getReportExcelItem( this.sheetId,
+                    selectionManager.getSelectedReportExcelId() );
+
+                this.generateOutPutFile( organisationUnitGroup.getMembers(), reportExcelItems, reportExcel, sheet );
+            }
+        }
+
+        this.complete();
+
+        statementManager.destroy();
+
+        return SUCCESS;
+    }
+
+    private void generateOutPutFile( Set<OrganisationUnit> organisationUnits,
+        Collection<ReportExcelItem> reportExcelItems, ReportExcelCategory reportExcel, HSSFSheet sheet )
+        throws RowsExceededException, WriteException
+    {
+        for ( ReportExcelItem reportItem : reportExcelItems )
+        {
+            int rowBegin = reportItem.getRow();
+
+            for ( DataElementGroupOrder dataElementGroup : reportExcel.getDataElementOrders() )
+            {
+                int beginChapter = rowBegin;
+                if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT_NAME ) )
+                {
+                    ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), dataElementGroup.getName(),
+                        ExcelUtils.TEXT, sheet, this.csTextChapterLeft );
+                }
+                else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT_CODE ) )
+                {
+                    ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), dataElementGroup.getCode(),
+                        ExcelUtils.TEXT, sheet, this.csTextICDJustify );
+                }
+
+                rowBegin++;
+                int serial = 1;
+                for ( DataElement dataElement : dataElementGroup.getDataElements() )
+                {
+                    if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT_NAME ) )
+                    {
+                        ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), dataElement.getName(),
+                            ExcelUtils.TEXT, sheet, this.csTextLeft );
+                    }
+                    else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT_CODE ) )
+                    {
+                        ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), dataElement.getCode(),
+                            ExcelUtils.TEXT, sheet, this.csTextLeft );
+                    }
+                    else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.SERIAL ) )
+                    {
+                        ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( serial ),
+                            ExcelUtils.NUMBER, sheet, this.csNumber );
+                    }
+                    else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.FORMULA_EXCEL ) )
+                    {
+                        ExcelUtils.writeFormulaByPOI( rowBegin, reportItem.getColumn(), reportItem.getExpression(),
+                            sheet, this.csNumber );
+                    }
+                    else
+                    {
+                        ReportExcelItem newReportItem = new ReportExcelItem();
+                        newReportItem.setColumn( reportItem.getColumn() );
+                        newReportItem.setRow( reportItem.getRow() );
+                        newReportItem.setPeriodType( reportItem.getPeriodType() );
+                        newReportItem.setName( reportItem.getName() );
+                        newReportItem.setSheetNo( reportItem.getSheetNo() );
+                        newReportItem.setItemType( reportItem.getItemType() );
+
+                        String expression = reportItem.getExpression();
+                        expression = expression.replace( "*", String.valueOf( dataElement.getId() ) );
+                        newReportItem.setExpression( expression );
+
+                        double value = 0.0;
+                        for ( OrganisationUnit organisationUnit : organisationUnits )
+                        {
+                            value += this.getDataValue( newReportItem, organisationUnit );
+                            System.out.println( "\n\n\n value : " + value );
+                        }
+                        ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( value ),
+                            ExcelUtils.NUMBER, sheet, this.csNumber );
+                    }
+                    rowBegin++;
+                    serial++;
+                }
+
+                if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) )
+                {
+                    String columnName = ExcelUtils.convertColNumberToColName( reportItem.getColumn() );
+                    String formula = "SUM(" + columnName + (beginChapter + 1) + ":" + columnName + (rowBegin - 1) + ")";
+                    ExcelUtils.writeFormulaByPOI( beginChapter, reportItem.getColumn(), formula, sheet, this.csNumber );
+                }
+            }
+        }
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedNormalAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedNormalAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedNormalAction.java	2009-10-16 07:19:35 +0000
@@ -0,0 +1,152 @@
+package org.hisp.dhis.reportexcel.preview.advance.action;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.reportexcel.ReportExcelItem;
+import org.hisp.dhis.reportexcel.ReportExcelNormal;
+import org.hisp.dhis.reportexcel.preview.action.GeneratePreviewReportExcelSupport;
+import org.hisp.dhis.reportexcel.utils.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @author Chau Thu Tran
+ * @version $Id$
+ * @since 2009-10-08
+ */
+public class GeneratePreviewAdvancedNormalAction
+    extends GeneratePreviewReportExcelSupport
+{
+
+    // ---------------------------------------------------------------------
+    // Dependency
+    // ---------------------------------------------------------------------
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    // ---------------------------------------------------------------------
+    // Input && Output
+    // ---------------------------------------------------------------------
+
+    private Integer orgunitGroupId;
+
+    // ---------------------------------------------------------------------
+    // Getters && Setters
+    // ---------------------------------------------------------------------
+
+    public void setOrgunitGroupId( Integer orgunitGroupId )
+    {
+        this.orgunitGroupId = orgunitGroupId;
+    }
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
+    // ---------------------------------------------------------------------
+    // Action implementation
+    // ---------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {        
+        this.statementManager.initialise();
+
+        Period period = this.selectionManager.getSelectedPeriod();
+        this.installPeriod( period );
+
+        OrganisationUnitGroup organisationUnitGroup = organisationUnitGroupService
+            .getOrganisationUnitGroup( orgunitGroupId );
+
+        Set<OrganisationUnit> organisationUnits = organisationUnitGroup.getMembers();
+
+        ReportExcelNormal reportExcel = (ReportExcelNormal) reportService.getReportExcel( this.selectionManager
+            .getSelectedReportExcelId() );
+
+        this.installReadTemplateFile( reportExcel, period, organisationUnitGroup );
+
+        if ( this.sheetId > 0 )
+        {
+            HSSFSheet sheet = this.templateWorkbook.getSheetAt( this.sheetId - 1 );
+
+            Collection<ReportExcelItem> reportExcelItems = reportService.getReportExcelItem( this.sheetId,
+                this.selectionManager.getSelectedReportExcelId() );
+
+            this.generateOutPutFile( organisationUnits, reportExcelItems, sheet );
+        }
+        else
+        {
+            for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportExcelId() ) )
+            {
+                HSSFSheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 );
+
+                Collection<ReportExcelItem> reportExcelItems = reportService.getReportExcelItem( sheetNo,
+                    this.selectionManager.getSelectedReportExcelId() );
+
+                this.generateOutPutFile( organisationUnits, reportExcelItems, sheet );
+            }
+        }
+
+        this.complete();
+
+        this.statementManager.destroy();
+
+        return SUCCESS;
+
+    }
+
+    private void generateOutPutFile( Set<OrganisationUnit> organisationList,
+        Collection<ReportExcelItem> reportExcelItems, HSSFSheet sheet )
+    {
+        for ( ReportExcelItem reportItem : reportExcelItems )
+        {
+            double value = 0;
+
+            Iterator<OrganisationUnit> iter = organisationList.iterator();
+
+            while ( iter.hasNext() )
+            {
+                OrganisationUnit organisationUnit = iter.next();
+
+                value += getDataValue( reportItem, organisationUnit );
+            }
+
+            ExcelUtils.writeValueByPOI( reportItem.getRow(), reportItem.getColumn(), String.valueOf( value ),
+                ExcelUtils.NUMBER, sheet, this.csNumber );
+        }
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedOrgGroupListingAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedOrgGroupListingAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedOrgGroupListingAction.java	2009-10-16 07:19:35 +0000
@@ -0,0 +1,193 @@
+package org.hisp.dhis.reportexcel.preview.advance.action;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Set;
+
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.reportexcel.ReportExcel;
+import org.hisp.dhis.reportexcel.ReportExcelItem;
+import org.hisp.dhis.reportexcel.ReportExcelOganiztionGroupListing;
+import org.hisp.dhis.reportexcel.preview.action.GeneratePreviewReportExcelSupport;
+import org.hisp.dhis.reportexcel.utils.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @author Chau Thu Tran
+ * @author Tran Thanh Tri
+ * @version $Id$
+ * @since 2009-10-08
+ */
+public class GeneratePreviewAdvancedOrgGroupListingAction
+    extends GeneratePreviewReportExcelSupport
+{
+
+    // ---------------------------------------------------------------------
+    // Dependency
+    // ---------------------------------------------------------------------
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    // ---------------------------------------------------------------------
+    // Input && Output
+    // ---------------------------------------------------------------------
+
+    private Integer orgunitGroupId;
+
+    // ---------------------------------------------------------------------
+    // Getters && Setters
+    // ---------------------------------------------------------------------
+
+    public void setOrgunitGroupId( Integer orgunitGroupId )
+    {
+        this.orgunitGroupId = orgunitGroupId;
+    }
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
+    // ---------------------------------------------------------------------
+    // Action implementation
+    // ---------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        this.statementManager.initialise();
+
+        Period period = selectionManager.getSelectedPeriod();
+        this.installPeriod( period );
+
+        OrganisationUnitGroup organisationUnitGroup = organisationUnitGroupService
+            .getOrganisationUnitGroup( orgunitGroupId.intValue() );
+
+        ReportExcelOganiztionGroupListing reportExcel = (ReportExcelOganiztionGroupListing) reportService
+            .getReportExcel( selectionManager.getSelectedReportExcelId() );
+
+        this.installReadTemplateFile( reportExcel, period, organisationUnitGroup );
+
+        if ( this.sheetId > 0 )
+        {
+            HSSFSheet sheet = this.templateWorkbook.getSheetAt( this.sheetId - 1 );
+
+            Collection<ReportExcelItem> reportExcelItems = reportService.getReportExcelItem( this.sheetId,
+                this.selectionManager.getSelectedReportExcelId() );
+
+            this.generateOutPutFile( reportExcel, reportExcelItems, organisationUnitGroup.getMembers(), sheet );
+        }
+        else
+        {
+            for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportExcelId() ) )
+            {
+                HSSFSheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 );
+
+                Collection<ReportExcelItem> reportExcelItems = reportService.getReportExcelItem( sheetNo,
+                    selectionManager.getSelectedReportExcelId() );
+
+                this.generateOutPutFile( reportExcel, reportExcelItems, organisationUnitGroup.getMembers(), sheet );
+            }
+        }
+
+        this.complete();
+
+        this.statementManager.destroy();
+
+        return SUCCESS;
+    }
+
+    private void generateOutPutFile( ReportExcel reportExcel, Collection<ReportExcelItem> reportExcelItems,
+        Set<OrganisationUnit> organisationUnits, HSSFSheet sheet )
+        throws RowsExceededException, WriteException
+    {
+        for ( ReportExcelItem reportItem : reportExcelItems )
+        {
+            int rowBegin = reportItem.getRow();
+            int chapperNo = 0;
+
+            int beginChapter = rowBegin;
+
+            chapperNo++;
+            rowBegin++;
+            int serial = 1;
+
+            for ( OrganisationUnit o : organisationUnits )
+            {
+                if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.ORGANISATION ) )
+                {
+                    ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), o.getName(), ExcelUtils.TEXT, sheet,
+                        this.csTextLeft );
+                }
+                else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.SERIAL ) )
+                {
+                    ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( serial ),
+                        ExcelUtils.NUMBER, sheet, this.csNumber );
+                }
+                else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) )
+                {
+                    double value = this.getDataValue( reportItem, o );
+
+                    ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( value ),
+                        ExcelUtils.NUMBER, sheet, this.csNumber );
+                }
+                else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.INDICATOR ) )
+                {
+                    double value = this.getIndicatorValue( reportItem, o );
+
+                    ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( value ),
+                        ExcelUtils.NUMBER, sheet, this.csNumber );
+                }
+                else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.FORMULA_EXCEL ) )
+                {
+                    ExcelUtils.writeFormulaByPOI( rowBegin, reportItem.getColumn(), reportItem.getExpression(), sheet,
+                        this.csNumber );
+                }
+
+                rowBegin++;
+                serial++;
+            }
+
+            if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT )
+                && (!organisationUnits.isEmpty()) )
+            {
+                String columnName = ExcelUtils.convertColNumberToColName( reportItem.getColumn() );
+                String formula = "SUM(" + columnName + (beginChapter + 1) + ":" + columnName + (rowBegin - 1) + ")";
+                ExcelUtils.writeFormulaByPOI( beginChapter, reportItem.getColumn(), formula, sheet, this.csNumber );
+            }
+        }
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedPeriodColumnListingAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedPeriodColumnListingAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/advance/action/GeneratePreviewAdvancedPeriodColumnListingAction.java	2009-10-16 07:19:35 +0000
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.reportexcel.preview.advance.action;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.comparator.AscendingPeriodComparator;
+import org.hisp.dhis.reportexcel.ReportExcelItem;
+import org.hisp.dhis.reportexcel.ReportExcelPeriodColumnListing;
+import org.hisp.dhis.reportexcel.preview.action.GeneratePreviewReportExcelSupport;
+import org.hisp.dhis.reportexcel.utils.DateUtils;
+import org.hisp.dhis.reportexcel.utils.ExcelUtils;
+import org.hisp.dhis.system.util.MathUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @author Chau Thu Tran
+ * @author Tran Thanh Tri
+ * @version $Id$
+ * @since 2009-10-08
+ */
+
+public class GeneratePreviewAdvancedPeriodColumnListingAction
+    extends GeneratePreviewReportExcelSupport
+{
+
+    // ---------------------------------------------------------------------
+    // Dependency
+    // ---------------------------------------------------------------------
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    // ---------------------------------------------------------------------
+    // Input && Output
+    // ---------------------------------------------------------------------
+
+    private Integer orgunitGroupId;
+
+    // ---------------------------------------------------------------------
+    // Getters && Setters
+    // ---------------------------------------------------------------------
+
+    public void setOrgunitGroupId( Integer orgunitGroupId )
+    {
+        this.orgunitGroupId = orgunitGroupId;
+    }
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
+    // ---------------------------------------------------------------------
+    // Action implementation
+    // ---------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {       
+        this.statementManager.initialise();
+
+        OrganisationUnitGroup organisationUnitGroup = organisationUnitGroupService
+            .getOrganisationUnitGroup( orgunitGroupId.intValue() );
+
+        Period period = this.selectionManager.getSelectedPeriod();
+        this.installPeriod( period );
+
+        Calendar calendar = Calendar.getInstance();
+
+        PeriodType periodType = periodService.getPeriodTypeByClass( MonthlyPeriodType.class );
+
+        Date firstDateOfThisYear = DateUtils.getFirstDayOfYear( calendar.get( Calendar.YEAR ) );
+
+        List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriodsByPeriodType( periodType,
+            firstDateOfThisYear, endDate ) );
+
+        Collections.sort( periodList, new AscendingPeriodComparator() );
+
+        ReportExcelPeriodColumnListing reportExcel = (ReportExcelPeriodColumnListing) reportService
+            .getReportExcel( selectionManager.getSelectedReportExcelId() );
+
+        this.installReadTemplateFile( reportExcel, period, organisationUnitGroup );
+
+        if ( this.sheetId > 0 )
+        {
+            HSSFSheet sheet = this.templateWorkbook.getSheetAt( this.sheetId - 1 );
+
+            Collection<ReportExcelItem> reportExcelItems = reportService.getReportExcelItem( this.sheetId,
+                this.selectionManager.getSelectedReportExcelId() );
+
+            this.generateOutPutFile( periodList, reportExcelItems, organisationUnitGroup.getMembers(), sheet );
+        }
+        else
+        {
+            for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportExcelId() ) )
+            {
+                HSSFSheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 );
+
+                Collection<ReportExcelItem> reportExcelItems = reportService.getReportExcelItem( sheetNo,
+                    selectionManager.getSelectedReportExcelId() );
+
+                this.generateOutPutFile( periodList, reportExcelItems, organisationUnitGroup.getMembers(), sheet );
+            }
+        }
+
+        this.complete();
+
+        this.statementManager.destroy();
+
+        return SUCCESS;
+    }
+
+    private void generateOutPutFile( List<Period> periods, Collection<ReportExcelItem> reportExcelItems,
+        Set<OrganisationUnit> organisationUnits, HSSFSheet sheet )
+        throws RowsExceededException, WriteException
+    {
+        for ( ReportExcelItem reportItem : reportExcelItems )
+        {
+            int i = 0;
+            for ( Period p : periods )
+            {
+                double value = 0.0;
+
+                for ( OrganisationUnit organisationUnit : organisationUnits )
+                {
+                    if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) )
+                    {
+                        value += MathUtils.calculateExpression( generateExpression( reportItem, p.getStartDate(), p
+                            .getEndDate(), organisationUnit ) );
+                    }
+                    else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.INDICATOR ) )
+                    {
+                        value += MathUtils.calculateExpression( generateExpression( reportItem, p.getStartDate(), p
+                            .getEndDate(), organisationUnit ) );
+                    }
+                }// end of showing the orgunit
+
+                ExcelUtils.writeValueByPOI( reportItem.getRow(), reportItem.getColumn() + i, String.valueOf( value ),
+                    ExcelUtils.NUMBER, sheet, this.csNumber );
+                
+                i++;
+            }
+        }
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-10-15 09:50:00 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-10-16 07:19:35 +0000
@@ -845,7 +845,7 @@
 
 	
 	<!-- PREVIEW ADVANCED REPORT -->
-	<!--
+	
 	<bean
 		id="org.hisp.dhis.reportexcel.preview.advance.action.GeneratePreviewAdvancedNormalAction"
 		class="org.hisp.dhis.reportexcel.preview.advance.action.GeneratePreviewAdvancedNormalAction"
@@ -973,7 +973,7 @@
 		<property name="initPOIStylesManager"
 			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>	
-	-->
+	
 	
 	<!-- Selection State -->
 	

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2009-10-15 09:50:00 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2009-10-16 07:19:35 +0000
@@ -703,7 +703,7 @@
         </action>
 		
 		<!-- PREVIEW ADVANCED REPORT -->
-		<!--
+		
 		<action name="previewAdvancedReportExcel"
 			class="org.hisp.dhis.reportexcel.export.action.GenerateReportExcelFlowAction">
 			<result name="CATEGORY" type="chain">
@@ -743,7 +743,7 @@
 			<result name="success" type="chain">exportXMLChain
 			</result>
 		</action>
-		-->
+		
 				
 		<!-- PROCESSED FOR PERIOD IN INDIVIDUAL REPORT -->
 		

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/viewReportPreview.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/viewReportPreview.vm	2009-10-12 09:32:38 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/viewReportPreview.vm	2009-10-16 07:19:35 +0000
@@ -1,14 +1,8 @@
 
 <div id="showSheetDiv">
-	<table>
-		<tr>
-			<td><label class='formatLabel'>$i18n.getString('sheet_of_excel_file')</label></td>
-			<td>
-				<select id="sheetNoExcelFile" name="sheetNoExcelFile" onchange="javascript: previewReport('$!reportId', '$!periodId', this.value, '$!orgunitGroupId', '$!i18n.getString("working_in_progress")');">
-				</select>
-			</td>
-		</tr>
-	</table>
+	<label class='formatLabel'>$i18n.getString('sheet_of_excel_file')</label>
+	<select id="sheetNoExcelFile" name="sheetNoExcelFile" onchange="javascript: previewReport('$!reportId', '$!periodId', this.value, '$!orgunitGroupId', '$!i18n.getString("working_in_progress")');">
+	</select>
 </div>
 <br/>
 <div id="previewContentDiv">