diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java index 4c29db997..6c397a3ab 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java @@ -945,7 +945,7 @@ public abstract class OrderElement extends IntegrationEntity implements newRequirement); } - protected Set getIndirectCriterionRequirement() { + public Set getIndirectCriterionRequirement() { return criterionRequirementHandler.getIndirectCriterionRequirement(criterionRequirements); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/ProjectStatusReportDTO.java b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/ProjectStatusReportDTO.java index e4397e358..a84a4fe5a 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/ProjectStatusReportDTO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/ProjectStatusReportDTO.java @@ -66,6 +66,16 @@ public class ProjectStatusReportDTO { this.totalCost = totalCost; } + public ProjectStatusReportDTO(String code, String name, + EffortDuration estimatedHours, EffortDuration plannedHours, + EffortDuration imputedHours, BigDecimal budget, + BigDecimal hoursCost, BigDecimal expensesCost, BigDecimal totalCost) { + this(estimatedHours, plannedHours, imputedHours, budget, hoursCost, + expensesCost, totalCost); + this.code = code; + this.name = name; + } + public ProjectStatusReportDTO(OrderElement orderElement) { code = orderElement.getCode(); name = Util.getPrefixSpacesDependingOnDepth(orderElement) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportModel.java index ef199cfc4..9e7b816c3 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportModel.java @@ -33,6 +33,7 @@ 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.requirements.entities.IndirectCriterionRequirement; import org.libreplan.business.resources.daos.ICriterionDAO; import org.libreplan.business.resources.entities.Criterion; import org.libreplan.business.scenarios.IScenarioManager; @@ -114,9 +115,80 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel { dto.setExpensesCost(moneyCostCalculator .getExpensesMoneyCost(orderElement)); dto.setTotalCost(moneyCostCalculator.getTotalMoneyCost(orderElement)); + + if (!isNotFilteringByCriteria()) { + dto = discountChildrenWithInvalidatedCriteria(orderElement, dto); + } + return dto; } + private ProjectStatusReportDTO discountChildrenWithInvalidatedCriteria( + OrderElement orderElement, ProjectStatusReportDTO dto) { + List dtosToDiscount = new ArrayList(); + + for (OrderElement child : orderElement.getChildren()) { + for (IndirectCriterionRequirement criterionRequirement : child + .getIndirectCriterionRequirement()) { + if (isCriterionSelected(criterionRequirement.getCriterion() + .getCode())) { + if (!criterionRequirement.isValid()) { + dtosToDiscount.add(calculateDTO(child)); + } + } + } + } + + return discount(dto, dtosToDiscount); + } + + private ProjectStatusReportDTO discount(ProjectStatusReportDTO originalDto, + List toDiscount) { + if (toDiscount.isEmpty()) { + return originalDto; + } + + EffortDuration estimatedHours = originalDto.getEstimatedHoursAsEffortDuration(); + EffortDuration plannedHours = originalDto.getPlannedHoursAsEffortDuration(); + EffortDuration imputedHours = originalDto.getImputedHoursAsEffortDuration(); + + BigDecimal budget = originalDto.getBudget(); + BigDecimal hoursCost = originalDto.getHoursCost(); + BigDecimal expensesCost = originalDto.getExpensesCost(); + BigDecimal totalCost = originalDto.getTotalCost(); + + for (ProjectStatusReportDTO each : toDiscount) { + estimatedHours = subtractIfNotNull(estimatedHours, + each.getEstimatedHoursAsEffortDuration()); + plannedHours = subtractIfNotNull(plannedHours, + each.getPlannedHoursAsEffortDuration()); + imputedHours = subtractIfNotNull(imputedHours, + each.getImputedHoursAsEffortDuration()); + + budget = subtractIfNotNull(budget, each.getBudget()); + hoursCost = subtractIfNotNull(hoursCost, each.getHoursCost()); + expensesCost = subtractIfNotNull(expensesCost, + each.getExpensesCost()); + totalCost = subtractIfNotNull(totalCost, each.getTotalCost()); + } + + ProjectStatusReportDTO projectStatusReportDTO = new ProjectStatusReportDTO( + originalDto.getCode(), originalDto.getName(), estimatedHours, + plannedHours, imputedHours, budget, hoursCost, expensesCost, + totalCost); + return projectStatusReportDTO; + } + + public boolean isCriterionSelected(String code) { + for (Criterion criterion : selectedCriteria) { + if (criterion.getCode().equals(code)) { + return true; + } + } + + return false; + } + private void calculateTotalDTO(Order order, List dtos) { if (isNotFiltering()) { @@ -151,12 +223,20 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel { } private boolean isNotFiltering() { - return selectedLabels.isEmpty() && selectedCriteria.isEmpty(); + return isNotFilteringByLabels() && isNotFilteringByCriteria(); + } + + private boolean isNotFilteringByLabels() { + return selectedLabels.isEmpty(); + } + + private boolean isNotFilteringByCriteria() { + return selectedCriteria.isEmpty(); } private List filterBySelectedLabels( List orderElements) { - if (selectedLabels.isEmpty()) { + if (isNotFilteringByLabels()) { return orderElements; } @@ -171,7 +251,7 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel { private List filterBySelectedCriteria( List orderElements) { - if (selectedCriteria.isEmpty()) { + if (isNotFilteringByCriteria()) { return orderElements; } @@ -192,6 +272,14 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel { return total.plus(other); } + private EffortDuration subtractIfNotNull(EffortDuration total, + EffortDuration other) { + if (other == null) { + return total; + } + return total.minus(other); + } + private BigDecimal addIfNotNull(BigDecimal total, BigDecimal other) { if (other == null) { return total; @@ -199,6 +287,13 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel { return total.add(other); } + private BigDecimal subtractIfNotNull(BigDecimal total, BigDecimal other) { + if (other == null) { + return total; + } + return total.subtract(other); + } + @Override @Transactional(readOnly = true) public BigDecimal getHoursCost(Order order) {