diff --git a/src/main/java/org/sigmah/client/ui/view/pivot/LayoutComposer.java b/src/main/java/org/sigmah/client/ui/view/pivot/LayoutComposer.java index a4c82d569..e50405151 100644 --- a/src/main/java/org/sigmah/client/ui/view/pivot/LayoutComposer.java +++ b/src/main/java/org/sigmah/client/ui/view/pivot/LayoutComposer.java @@ -90,7 +90,21 @@ public PivotTableElement fixIndicator(int indicatorId) { pivot.setFilter(filter); return pivot; } - + public PivotTableElement YearExcel(int indicatorId) { + PivotTableElement pivot = new PivotTableElement(); + pivot.setShowEmptyCells(true); + pivot.addRowDimensions(adminDimensions); + pivot.addRowDimension(new Dimension(DimensionType.Site)); + pivot.addColDimension(new DateDimension(DateUnit.MONTH)); + pivot.addColDimension(new DateDimension(DateUnit.YEAR)); + Filter filter = new Filter(); + filter.addRestriction(DimensionType.Database, databaseId); + filter.addRestriction(DimensionType.Indicator, indicatorId); + filter.setDateRange(projectDateRange); + pivot.setFilter(filter); + return pivot; + } + public PivotTableElement fixSite(int siteId) { PivotTableElement pivot = new PivotTableElement(); pivot.setShowEmptyCells(true); diff --git a/src/main/java/org/sigmah/server/servlet/exporter/data/SpreadsheetDataUtil.java b/src/main/java/org/sigmah/server/servlet/exporter/data/SpreadsheetDataUtil.java index feeb4bb6e..3ffc65385 100644 --- a/src/main/java/org/sigmah/server/servlet/exporter/data/SpreadsheetDataUtil.java +++ b/src/main/java/org/sigmah/server/servlet/exporter/data/SpreadsheetDataUtil.java @@ -22,73 +22,76 @@ * #L% */ - -import javax.validation.constraints.NotNull; -import org.sigmah.client.ui.view.pivot.LayoutComposer; -import org.sigmah.server.domain.Project; -import org.sigmah.server.servlet.exporter.base.Exporter; -import org.sigmah.server.util.CalendarDates; -import org.sigmah.shared.command.GenerateElement; -import org.sigmah.shared.command.GetIndicators; -import org.sigmah.shared.command.GetProject; -import org.sigmah.shared.command.result.IndicatorListResult; -import org.sigmah.shared.dto.IndicatorDTO; -import org.sigmah.shared.dto.IndicatorGroup; -import org.sigmah.shared.dto.ProjectDTO; -import org.sigmah.shared.dto.pivot.content.PivotContent; -import org.sigmah.shared.dto.pivot.model.PivotTableElement; - -public final class SpreadsheetDataUtil { - - private SpreadsheetDataUtil() { - // Only provides static methods. - } - - @NotNull - public static LogFrameExportData prepareLogFrameData(final Project project, final Exporter exporter) throws Throwable { - // TODO [INDICATORS] A major redesign of the indicators is in progress... - - final LogFrameExportData data = new LogFrameExportData(project, exporter); - - // Get indicators from CommandHanler (only for the purpose to get aggregated(current) values of indicators). - final IndicatorListResult indicators = exporter.execute(new GetIndicators(project.getId())); - for (final IndicatorDTO dto : indicators.getData()) { - data.getIndMap().put(dto.getId(), dto); - } - return data; - } - - @NotNull - public static IndicatorEntryData prepareIndicatorsData(Integer projectId, final Exporter exporter) throws Throwable { - // TODO [INDICATORS] A major redesign of the indicators is in progress... - - // Get project - final ProjectDTO project = exporter.execute(new GetProject(projectId, null)); - final LayoutComposer composer = new LayoutComposer(new CalendarDates(), project); - - // Get indicators - final IndicatorListResult indicators = exporter.execute(new GetIndicators(project)); - - // Create spreadsheet data - final IndicatorEntryData data = new IndicatorEntryData(exporter, indicators, project.getName()); - - // Set indicator groups - for(final IndicatorGroup group:indicators.getGroups()) { - data.getGroupMap().put(group.getId(), group.getName()); - } - - // Put indicator entry - for (final IndicatorDTO indicator : indicators.getData()) { - final PivotTableElement pivot = composer.fixIndicator(indicator.getId()); - final PivotContent content = exporter.execute(new GenerateElement(pivot)); - data.getEntryMap().put(indicator.getId(), content.getData()); - } - - // Put ungrouped indicators - final IndicatorGroup nonGroup = new IndicatorGroup(exporter.localize("unGrouped")); - nonGroup.getIndicators().addAll(indicators.getUngroupedIndicators()); - data.getIndicators().getGroups().add(nonGroup); - - return data; - } -} + +import javax.validation.constraints.NotNull; +import org.sigmah.client.ui.view.pivot.LayoutComposer; +import org.sigmah.server.domain.Project; +import org.sigmah.server.servlet.exporter.base.Exporter; +import org.sigmah.server.util.CalendarDates; +import org.sigmah.shared.command.GenerateElement; +import org.sigmah.shared.command.GetIndicators; +import org.sigmah.shared.command.GetProject; +import org.sigmah.shared.command.result.IndicatorListResult; +import org.sigmah.shared.dto.IndicatorDTO; +import org.sigmah.shared.dto.IndicatorGroup; +import org.sigmah.shared.dto.ProjectDTO; +import org.sigmah.shared.dto.pivot.content.PivotContent; +import org.sigmah.shared.dto.pivot.model.PivotTableElement; + +public final class SpreadsheetDataUtil { + + private SpreadsheetDataUtil() { + // Only provides static methods. + } + + @NotNull + public static LogFrameExportData prepareLogFrameData(final Project project, final Exporter exporter) throws Throwable { + // TODO [INDICATORS] A major redesign of the indicators is in progress... + + final LogFrameExportData data = new LogFrameExportData(project, exporter); + + // Get indicators from CommandHanler (only for the purpose to get aggregated(current) values of indicators). + final IndicatorListResult indicators = exporter.execute(new GetIndicators(project.getId())); + for (final IndicatorDTO dto : indicators.getData()) { + data.getIndMap().put(dto.getId(), dto); + } + return data; + } + + @NotNull + public static IndicatorEntryData prepareIndicatorsData(Integer projectId, final Exporter exporter) throws Throwable { + // TODO [INDICATORS] A major redesign of the indicators is in progress... + + // Get project + final ProjectDTO project = exporter.execute(new GetProject(projectId, null)); + final LayoutComposer composer = new LayoutComposer(new CalendarDates(), project); + + // Get indicators + final IndicatorListResult indicators = exporter.execute(new GetIndicators(project)); + + // Create spreadsheet data + final IndicatorEntryData data = new IndicatorEntryData(exporter, indicators, project.getName()); + + // Set indicator groups + for(final IndicatorGroup group:indicators.getGroups()) { + data.getGroupMap().put(group.getId(), group.getName()); + } + + // Put indicator entry + for (final IndicatorDTO indicator : indicators.getData()) { + final PivotTableElement pivot = composer.fixIndicator(indicator.getId()); + final PivotContent content = exporter.execute(new GenerateElement(pivot)); + data.getEntryMap().put(indicator.getId(), content.getData()); + final PivotTableElement pivotyear = composer.YearExcel(indicator.getId()); + final PivotContent contentyear = exporter.execute(new GenerateElement(pivotyear)); + data.getEntryMap().put(indicator.getId()+1, contentyear.getData()); + } + + // Put ungrouped indicators + final IndicatorGroup nonGroup = new IndicatorGroup(exporter.localize("unGrouped")); + nonGroup.getIndicators().addAll(indicators.getUngroupedIndicators()); + data.getIndicators().getGroups().add(nonGroup); + + return data; + } +} diff --git a/src/main/java/org/sigmah/server/servlet/exporter/template/IndicatorEntryCalcTemplate.java b/src/main/java/org/sigmah/server/servlet/exporter/template/IndicatorEntryCalcTemplate.java index e41adfd18..19c94d545 100644 --- a/src/main/java/org/sigmah/server/servlet/exporter/template/IndicatorEntryCalcTemplate.java +++ b/src/main/java/org/sigmah/server/servlet/exporter/template/IndicatorEntryCalcTemplate.java @@ -128,6 +128,8 @@ private void createDetailSheet(final IndicatorDTO indicator) throws Throwable { int rowIndex = -1; List leaves = data.getEntryMap().get(indicator.getId()).getRootColumn().getLeaves(); + final List leavesyear + = data.getEntryMap().get(indicator.getId() + 1).getRootColumn().getLeaves(); int numbOfLeaves = leaves.size(); int numbOfCols = 4; @@ -211,16 +213,76 @@ private void createDetailSheet(final IndicatorDTO indicator) throws Throwable { row.getCellByIndex(4).setCellStyleName(null); // data entry + //for year row in sheet + String merge = "hello"; + row = tableEx.getRowByIndex(++rowIndex); + int cellIndex = 0; + CalcUtils.putHeader(row, ++cellIndex, "Year"); + Map columnIndexMapyr = new HashMap(); + for (PivotTableData.Axis axis : leavesyear) { + CalcUtils.putHeader(row, ++cellIndex, axis.getLabel()); + columnIndexMapyr.put(axis.getLabel(), cellIndex); + if (merge.equals(axis.getLabel()) && cellIndex > 2) { + CalcUtils.mergeCell(tableEx, cellIndex - 1, rowIndex, cellIndex, rowIndex); + } else { + } + merge = axis.getLabel(); + + } + int month = 0; + String completedate = "hello"; // header row = tableEx.getRowByIndex(++rowIndex); - int cellIndex = 0; - CalcUtils.putHeader(row, ++cellIndex, data.getLocalizedVersion("sideAndMonth")); + cellIndex = 0; + CalcUtils.putHeader(row, ++cellIndex, "Month"); Map columnIndexMap = new HashMap(); for (PivotTableData.Axis axis : leaves) { CalcUtils.putHeader(row, ++cellIndex, axis.getLabel()); columnIndexMap.put(axis.getLabel(), cellIndex); + if (cellIndex == 2) { + completedate = axis.getLabel(); + } } - +//for date value + if (completedate.equals("Jan")) { + month = 1; + } else if (completedate.equals("Feb")) { + month = 2; + } else if (completedate.equals("Mar")) { + month = 3; + } else if (completedate.equals("Apr")) { + month = 4; + } else if (completedate.equals("May")) { + month = 5; + } else if (completedate.equals("Jun")) { + month = 6; + } else if (completedate.equals("Jul")) { + month = 7; + } else if (completedate.equals("Aug")) { + month = 8; + } else if (completedate.equals("Sep")) { + month = 9; + } else if (completedate.equals("Oct")) { + month = 10; + } else if (completedate.equals("Nov")) { + month = 11; + } else { + month = 12; + } + //for year row in sheet + row = tableEx.getRowByIndex(++rowIndex); + cellIndex = 0; + CalcUtils.putHeader(row, ++cellIndex, "Site"); + Map columnIndexMapcompletedate = new HashMap(); + for (PivotTableData.Axis axis : leavesyear) { + CalcUtils.putHeader(row, ++cellIndex, month + "." + axis.getLabel()); + columnIndexMapcompletedate.put(axis.getLabel(), cellIndex); + if (month == 12) { + month = 1; + } else { + month++; + } + } // rows for (PivotTableData.Axis axis : data.getEntryMap().get(indicator.getId()).getRootRow().getChildren()) { row = tableEx.getRowByIndex(++rowIndex); diff --git a/src/main/java/org/sigmah/server/servlet/exporter/template/IndicatorEntryExcelTemplate.java b/src/main/java/org/sigmah/server/servlet/exporter/template/IndicatorEntryExcelTemplate.java index 704a68ae5..fa99d8d8d 100644 --- a/src/main/java/org/sigmah/server/servlet/exporter/template/IndicatorEntryExcelTemplate.java +++ b/src/main/java/org/sigmah/server/servlet/exporter/template/IndicatorEntryExcelTemplate.java @@ -126,6 +126,8 @@ private void createDetailSheet(final IndicatorDTO indicator) { int rowIndex = -1; final List leaves = data.getEntryMap().get(indicator.getId()).getRootColumn().getLeaves(); + final List leavesyear = data.getEntryMap().get(indicator.getId() + 1).getRootColumn().getLeaves(); + int numbOfLeaves = leaves.size(); int numbOfCols = 4; @@ -207,17 +209,88 @@ private void createDetailSheet(final IndicatorDTO indicator) { sheetEx.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 1, numbOfCols)); // data entry + //for year above months in indicators + int startval = 2; + int endval = 0; + String merge = "hello"; + row = sheetEx.createRow(++rowIndex); + row.setHeightInPoints(defHeight); + int cellIndex = 0; + utils.putHeader(row, ++cellIndex, "Year"); + Map columnIndexMapyr = new HashMap(); + for (PivotTableData.Axis axis : leavesyear) { + utils.putHeader(row, ++cellIndex, axis.getLabel()); + columnIndexMapyr.put(axis.getLabel(), cellIndex); + if (cellIndex > 3) { + if (merge.equals(axis.getLabel())) { + + } else { + endval = cellIndex - 1; + sheetEx.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, startval, endval)); + startval = cellIndex; + } + } + sheetEx.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, startval, cellIndex)); + merge = axis.getLabel(); + + } // header + int month = 0; + String completedate = "hello"; row = sheetEx.createRow(++rowIndex); row.setHeightInPoints(defHeight); - int cellIndex = 0; - utils.putHeader(row, ++cellIndex, data.getLocalizedVersion("sideAndMonth")); + cellIndex = 0; + utils.putHeader(row, ++cellIndex, "month"); Map columnIndexMap = new HashMap(); for (PivotTableData.Axis axis : leaves) { utils.putHeader(row, ++cellIndex, axis.getLabel()); columnIndexMap.put(axis.getLabel(), cellIndex); + if (cellIndex == 2) { + completedate = axis.getLabel(); + } } - + + if (completedate.equals("Jan")) { + month = 1; + } else if (completedate.equals("Feb")) { + month = 2; + } else if (completedate.equals("Mar")) { + month = 3; + } else if (completedate.equals("Apr")) { + month = 4; + } else if (completedate.equals("May")) { + month = 5; + } else if (completedate.equals("Jun")) { + month = 6; + } else if (completedate.equals("Jul")) { + month = 7; + } else if (completedate.equals("Aug")) { + month = 8; + } else if (completedate.equals("Sep")) { + month = 9; + } else if (completedate.equals("Oct")) { + month = 10; + } else if (completedate.equals("Nov")) { + month = 11; + } else { + month = 12; + } + + //for year row in sheet + row = sheetEx.createRow(++rowIndex); + row.setHeightInPoints(defHeight); + cellIndex = 0; + utils.putHeader(row, ++cellIndex, "Site"); + Map columnIndexMapcompletedate = new HashMap(); + for (PivotTableData.Axis axis : leavesyear) { + utils.putHeader(row, ++cellIndex, month + "." + axis.getLabel()); + columnIndexMapcompletedate.put(axis.getLabel(), cellIndex); + if (month == 12) { + month = 1; + } else { + month++; + } + } // rows for (PivotTableData.Axis axis : data.getEntryMap().get(indicator.getId()).getRootRow().getChildren()) { row = sheetEx.createRow(++rowIndex);