Fix criteria filtering discounting children with invalidated criteria
If any child has the filtering criteria invalidated, it's not taken into account in order to calculate the values in the parent task that is part of the report. FEA: ItEr77S09WBSReport
This commit is contained in:
parent
242cfa8e35
commit
535d2e3423
3 changed files with 109 additions and 4 deletions
|
|
@ -945,7 +945,7 @@ public abstract class OrderElement extends IntegrationEntity implements
|
||||||
newRequirement);
|
newRequirement);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<IndirectCriterionRequirement> getIndirectCriterionRequirement() {
|
public Set<IndirectCriterionRequirement> getIndirectCriterionRequirement() {
|
||||||
return criterionRequirementHandler.getIndirectCriterionRequirement(criterionRequirements);
|
return criterionRequirementHandler.getIndirectCriterionRequirement(criterionRequirements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,16 @@ public class ProjectStatusReportDTO {
|
||||||
this.totalCost = totalCost;
|
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) {
|
public ProjectStatusReportDTO(OrderElement orderElement) {
|
||||||
code = orderElement.getCode();
|
code = orderElement.getCode();
|
||||||
name = Util.getPrefixSpacesDependingOnDepth(orderElement)
|
name = Util.getPrefixSpacesDependingOnDepth(orderElement)
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import org.libreplan.business.orders.entities.Order;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
import org.libreplan.business.planner.entities.IMoneyCostCalculator;
|
import org.libreplan.business.planner.entities.IMoneyCostCalculator;
|
||||||
import org.libreplan.business.reports.dtos.ProjectStatusReportDTO;
|
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.daos.ICriterionDAO;
|
||||||
import org.libreplan.business.resources.entities.Criterion;
|
import org.libreplan.business.resources.entities.Criterion;
|
||||||
import org.libreplan.business.scenarios.IScenarioManager;
|
import org.libreplan.business.scenarios.IScenarioManager;
|
||||||
|
|
@ -114,9 +115,80 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
|
||||||
dto.setExpensesCost(moneyCostCalculator
|
dto.setExpensesCost(moneyCostCalculator
|
||||||
.getExpensesMoneyCost(orderElement));
|
.getExpensesMoneyCost(orderElement));
|
||||||
dto.setTotalCost(moneyCostCalculator.getTotalMoneyCost(orderElement));
|
dto.setTotalCost(moneyCostCalculator.getTotalMoneyCost(orderElement));
|
||||||
|
|
||||||
|
if (!isNotFilteringByCriteria()) {
|
||||||
|
dto = discountChildrenWithInvalidatedCriteria(orderElement, dto);
|
||||||
|
}
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProjectStatusReportDTO discountChildrenWithInvalidatedCriteria(
|
||||||
|
OrderElement orderElement, ProjectStatusReportDTO dto) {
|
||||||
|
List<ProjectStatusReportDTO> dtosToDiscount = new ArrayList<ProjectStatusReportDTO>();
|
||||||
|
|
||||||
|
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<ProjectStatusReportDTO> 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,
|
private void calculateTotalDTO(Order order,
|
||||||
List<ProjectStatusReportDTO> dtos) {
|
List<ProjectStatusReportDTO> dtos) {
|
||||||
if (isNotFiltering()) {
|
if (isNotFiltering()) {
|
||||||
|
|
@ -151,12 +223,20 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNotFiltering() {
|
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<OrderElement> filterBySelectedLabels(
|
private List<OrderElement> filterBySelectedLabels(
|
||||||
List<OrderElement> orderElements) {
|
List<OrderElement> orderElements) {
|
||||||
if (selectedLabels.isEmpty()) {
|
if (isNotFilteringByLabels()) {
|
||||||
return orderElements;
|
return orderElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,7 +251,7 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
|
||||||
|
|
||||||
private List<OrderElement> filterBySelectedCriteria(
|
private List<OrderElement> filterBySelectedCriteria(
|
||||||
List<OrderElement> orderElements) {
|
List<OrderElement> orderElements) {
|
||||||
if (selectedCriteria.isEmpty()) {
|
if (isNotFilteringByCriteria()) {
|
||||||
return orderElements;
|
return orderElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,6 +272,14 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
|
||||||
return total.plus(other);
|
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) {
|
private BigDecimal addIfNotNull(BigDecimal total, BigDecimal other) {
|
||||||
if (other == null) {
|
if (other == null) {
|
||||||
return total;
|
return total;
|
||||||
|
|
@ -199,6 +287,13 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
|
||||||
return total.add(other);
|
return total.add(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BigDecimal subtractIfNotNull(BigDecimal total, BigDecimal other) {
|
||||||
|
if (other == null) {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
return total.subtract(other);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public BigDecimal getHoursCost(Order order) {
|
public BigDecimal getHoursCost(Order order) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue