Modify project status report to include new data

Add parameters in the controller and data for each colum in the DTOs.

Create a new Util class with utilities for report DTOs.

FEA: ItEr77S09WBSReport
This commit is contained in:
Manuel Rego Casasnovas 2012-10-16 11:34:23 +02:00
parent 12011733a3
commit da3a60e7cf
5 changed files with 184 additions and 11 deletions

View file

@ -19,7 +19,8 @@
package org.libreplan.business.reports.dtos;
import org.apache.commons.lang.StringUtils;
import java.math.BigDecimal;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.orders.entities.SumChargedEffort;
import org.libreplan.business.orders.entities.TaskSource;
@ -44,9 +45,18 @@ public class ProjectStatusReportDTO {
private EffortDuration imputedHours;
private BigDecimal budget;
private BigDecimal hoursCost;
private BigDecimal expensesCost;
private BigDecimal totalCost;
public ProjectStatusReportDTO(OrderElement orderElement) {
code = orderElement.getCode();
name = orderElement.getName();
name = Util.getPrefixSpacesDependingOnDepth(orderElement)
+ orderElement.getName();
Integer estimatedHours = orderElement.getWorkHours();
this.estimatedHours = estimatedHours != null ? EffortDuration
@ -62,7 +72,7 @@ public class ProjectStatusReportDTO {
imputedHours = sumChargedEffort.getTotalChargedEffort();
}
appendPrefixSpacesDependingOnDepth(orderElement);
setBudget(orderElement.getBudget());
}
public String getCode() {
@ -92,14 +102,68 @@ public class ProjectStatusReportDTO {
return effortDuration.toFormattedString();
}
private void appendPrefixSpacesDependingOnDepth(OrderElement orderElement) {
int depth = 0;
while (!orderElement.getParent().isOrder()) {
depth++;
orderElement = orderElement.getParent();
}
public BigDecimal getBudget() {
return budget;
}
name = StringUtils.repeat(INDENT_PREFIX, depth) + name;
public void setBudget(BigDecimal budget) {
this.budget = budget;
}
public BigDecimal getHoursCost() {
return hoursCost;
}
public void setHoursCost(BigDecimal hoursCost) {
this.hoursCost = hoursCost;
}
public BigDecimal getExpensesCost() {
return expensesCost;
}
public void setExpensesCost(BigDecimal expensesCost) {
this.expensesCost = expensesCost;
}
public BigDecimal getTotalCost() {
return totalCost;
}
public void setTotalCost(BigDecimal totalCost) {
this.totalCost = totalCost;
}
public BigDecimal getBudgetIntegerPart() {
return Util.getIntegerPart(budget);
}
public BigDecimal getBudgetFractionalPart() {
return Util.getFractionalPart(budget);
}
public BigDecimal getHoursCostIntegerPart() {
return Util.getIntegerPart(hoursCost);
}
public BigDecimal getHoursCostFractionalPart() {
return Util.getFractionalPart(hoursCost);
}
public BigDecimal getExpensesCostIntegerPart() {
return Util.getIntegerPart(expensesCost);
}
public BigDecimal getExpensesCostFractionalPart() {
return Util.getFractionalPart(expensesCost);
}
public BigDecimal getTotalCostIntegerPart() {
return Util.getIntegerPart(totalCost);
}
public BigDecimal getTotalCostFractionalPart() {
return Util.getFractionalPart(totalCost);
}
}

View file

@ -0,0 +1,64 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.libreplan.business.reports.dtos;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.apache.commons.lang.StringUtils;
import org.libreplan.business.trees.ITreeNode;
/**
* Utilities methods for report DTOs.
*
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public class Util {
public static final String INDENT_PREFIX = " ";
public static BigDecimal getIntegerPart(BigDecimal value) {
if (value == null) {
return value;
}
return value.setScale(2, RoundingMode.DOWN);
}
public static BigDecimal getFractionalPart(BigDecimal value) {
if (value == null) {
return value;
}
BigDecimal fractionalPart = value.subtract(value.setScale(0,
RoundingMode.FLOOR));
return (fractionalPart.compareTo(BigDecimal.ZERO) != 0) ? fractionalPart
: null;
}
public static String getPrefixSpacesDependingOnDepth(ITreeNode<?> node) {
int depth = 0;
while (node.getParent() != null && node.getParent().getParent() != null) {
depth++;
node = node.getParent();
}
return StringUtils.repeat(INDENT_PREFIX, depth);
}
}

View file

@ -19,6 +19,7 @@
package org.libreplan.web.reports;
import java.math.BigDecimal;
import java.util.List;
import org.libreplan.business.orders.entities.Order;
@ -35,4 +36,10 @@ public interface IProjectStatusReportModel {
List<ProjectStatusReportDTO> getProjectStatusReportDTOs(Order order);
BigDecimal getHoursCost(Order order);
BigDecimal getExpensesCost(Order order);
BigDecimal getTotalCost(Order order);
}

View file

@ -33,6 +33,7 @@ import org.libreplan.business.orders.entities.SumChargedEffort;
import org.libreplan.business.orders.entities.TaskSource;
import org.libreplan.business.reports.dtos.ProjectStatusReportDTO;
import org.libreplan.business.workingday.EffortDuration;
import org.libreplan.web.common.Util;
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
@ -122,6 +123,15 @@ public class ProjectStatusReportController extends LibrePlanReportController {
result.put("imputedHours",
ProjectStatusReportDTO.toString(imputedHours));
result.put("budget", Util.addCurrencySymbol(order.getBudget()));
result.put("hoursCost", Util.addCurrencySymbol(projectStatusReportModel
.getHoursCost(order)));
result.put("expensesCost", Util
.addCurrencySymbol(projectStatusReportModel
.getExpensesCost(order)));
result.put("totalCost", Util.addCurrencySymbol(projectStatusReportModel
.getTotalCost(order)));
return result;
}
}

View file

@ -19,6 +19,7 @@
package org.libreplan.web.reports;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -26,6 +27,7 @@ import java.util.List;
import org.libreplan.business.orders.daos.IOrderDAO;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.planner.entities.IMoneyCostCalculator;
import org.libreplan.business.reports.dtos.ProjectStatusReportDTO;
import org.libreplan.business.scenarios.IScenarioManager;
import org.libreplan.web.security.SecurityUtils;
@ -51,6 +53,9 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
@Autowired
private IScenarioManager scenarioManager;
@Autowired
private IMoneyCostCalculator moneyCostCalculator;
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
@ -72,10 +77,33 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
List<ProjectStatusReportDTO> dtos = new ArrayList<ProjectStatusReportDTO>();
for (OrderElement child : order.getAllChildren()) {
dtos.add(new ProjectStatusReportDTO(child));
ProjectStatusReportDTO dto = new ProjectStatusReportDTO(child);
dto.setHoursCost(moneyCostCalculator.getHoursMoneyCost(child));
dto.setExpensesCost(moneyCostCalculator.getExpensesMoneyCost(child));
dto.setTotalCost(moneyCostCalculator.getTotalMoneyCost(child));
dtos.add(dto);
}
return dtos;
}
@Override
@Transactional(readOnly = true)
public BigDecimal getHoursCost(Order order) {
return moneyCostCalculator.getHoursMoneyCost(order);
}
@Override
@Transactional(readOnly = true)
public BigDecimal getExpensesCost(Order order) {
return moneyCostCalculator.getExpensesMoneyCost(order);
}
@Override
@Transactional(readOnly = true)
public BigDecimal getTotalCost(Order order) {
return moneyCostCalculator.getTotalMoneyCost(order);
}
}