Using the new MoneyCostCalculator to print the new Money Cost bar
FEA: ItEr76S17MoneyCostMonitoringSystem
This commit is contained in:
parent
213e68c36e
commit
ac430aba6a
9 changed files with 111 additions and 36 deletions
|
|
@ -520,9 +520,8 @@ public class TaskComponent extends Div implements AfterCompose {
|
|||
public void updateCompletionMoneyCostBar() {
|
||||
if (task.isShowingMoneyCostBar()) {
|
||||
int startPixels = this.task.getBeginDate().toPixels(getMapper());
|
||||
// TODO change method, for the moment using getHoursAdvanceEndDate()
|
||||
String widthMoneyCostBar = pixelsFromStartUntil(
|
||||
startPixels, this.task.getHoursAdvanceEndDate()) + "px";
|
||||
String widthMoneyCostBar = pixelsFromStartUntil(startPixels,
|
||||
this.task.getMoneyCostBarEndDate()) + "px";
|
||||
response(null, new AuInvoke(this, "resizeCompletionMoneyCostBar",
|
||||
widthMoneyCostBar));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
* Copyright (C) 2010-2011 Igalia, S.L.
|
||||
* Copyright (C) 2010-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
|
||||
|
|
@ -34,6 +34,7 @@ import org.zkoss.ganttz.data.constraint.Constraint;
|
|||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public class DefaultFundamentalProperties implements ITaskFundamentalProperties {
|
||||
|
||||
|
|
@ -47,10 +48,14 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
|
|||
|
||||
private long hoursAdvanceEndDate;
|
||||
|
||||
private long moneyCostBarEndDate;
|
||||
|
||||
private Date advanceEndDate;
|
||||
|
||||
private BigDecimal hoursAdvancePercentage;
|
||||
|
||||
private BigDecimal moneyCostBarPercentage;
|
||||
|
||||
private BigDecimal advancePercentage;
|
||||
|
||||
private String tooltipText;
|
||||
|
|
@ -65,15 +70,19 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
|
|||
public DefaultFundamentalProperties(String name, Date beginDate,
|
||||
long lengthMilliseconds, String notes,
|
||||
Date hoursAdvanceEndDate,
|
||||
Date moneyCostBarEndDate,
|
||||
Date advanceEndDate,
|
||||
BigDecimal hoursAdvancePercentage, BigDecimal advancePercentage) {
|
||||
BigDecimal hoursAdvancePercentage,
|
||||
BigDecimal moneyCostBarPercentage, BigDecimal advancePercentage) {
|
||||
this.name = name;
|
||||
this.beginDate = beginDate.getTime();
|
||||
this.lengthMilliseconds = lengthMilliseconds;
|
||||
this.notes = notes;
|
||||
this.hoursAdvanceEndDate = hoursAdvanceEndDate.getTime();
|
||||
this.moneyCostBarEndDate = moneyCostBarEndDate.getTime();
|
||||
this.advanceEndDate = advanceEndDate;
|
||||
this.hoursAdvancePercentage = hoursAdvancePercentage;
|
||||
this.moneyCostBarPercentage = moneyCostBarPercentage;
|
||||
this.advancePercentage = advancePercentage;
|
||||
this.tooltipText = "Default tooltip";
|
||||
this.labelsText = "";
|
||||
|
|
@ -152,6 +161,11 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
|
|||
return GanttDate.createFrom(new Date(hoursAdvanceEndDate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GanttDate getMoneyCostBarEndDate() {
|
||||
return GanttDate.createFrom(new Date(moneyCostBarEndDate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GanttDate getAdvanceEndDate() {
|
||||
return advanceEndDate != null ? GanttDate.createFrom(new Date(
|
||||
|
|
@ -163,6 +177,11 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
|
|||
return hoursAdvancePercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getMoneyCostBarPercentage() {
|
||||
return moneyCostBarPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAdvancePercentage() {
|
||||
return advancePercentage;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
* Copyright (C) 2010-2011 Igalia, S.L.
|
||||
* Copyright (C) 2010-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
|
||||
|
|
@ -29,6 +29,7 @@ import org.zkoss.ganttz.data.constraint.Constraint;
|
|||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public interface ITaskFundamentalProperties {
|
||||
|
||||
|
|
@ -65,10 +66,14 @@ public interface ITaskFundamentalProperties {
|
|||
|
||||
public GanttDate getHoursAdvanceEndDate();
|
||||
|
||||
public GanttDate getMoneyCostBarEndDate();
|
||||
|
||||
public GanttDate getAdvanceEndDate();
|
||||
|
||||
public BigDecimal getHoursAdvancePercentage();
|
||||
|
||||
public BigDecimal getMoneyCostBarPercentage();
|
||||
|
||||
public BigDecimal getAdvancePercentage();
|
||||
|
||||
public String getTooltipText();
|
||||
|
|
|
|||
|
|
@ -342,6 +342,11 @@ public abstract class Task implements ITaskFundamentalProperties {
|
|||
return fundamentalProperties.getHoursAdvancePercentage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getMoneyCostBarPercentage() {
|
||||
return fundamentalProperties.getMoneyCostBarPercentage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAdvancePercentage() {
|
||||
return fundamentalProperties.getAdvancePercentage();
|
||||
|
|
@ -352,6 +357,11 @@ public abstract class Task implements ITaskFundamentalProperties {
|
|||
return fundamentalProperties.getHoursAdvanceEndDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GanttDate getMoneyCostBarEndDate() {
|
||||
return fundamentalProperties.getMoneyCostBarEndDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GanttDate getAdvanceEndDate() {
|
||||
return fundamentalProperties.getAdvanceEndDate();
|
||||
|
|
|
|||
|
|
@ -31,19 +31,19 @@ import org.libreplan.business.orders.entities.OrderElement;
|
|||
public interface IMoneyCostCalculator {
|
||||
|
||||
/**
|
||||
* Returns the money cost of a {@link TaskElement}.<br />
|
||||
* Returns the money cost of a {@link OrderElement} taking into account all
|
||||
* its children.<br />
|
||||
*
|
||||
* It uses the {@link OrderElement} (or OrderElements) associated to the
|
||||
* {@link TaskElement} in order to calculate the cost using the following
|
||||
* formula:<br />
|
||||
* It uses the {@link OrderElement} in order to calculate the cost using the
|
||||
* following formula:<br />
|
||||
* <tt>Sum of all the hours devoted to a task multiplied by the cost of
|
||||
* each hour according to these parameters (type of hour, cost category of
|
||||
* the resource, date of the work report)</tt>
|
||||
*
|
||||
* @param The
|
||||
* {@link TaskElement} to calculate the money cost
|
||||
* @return Money cost of the task
|
||||
* {@link OrderElement} to calculate the money cost
|
||||
* @return Money cost of the order element and all its children
|
||||
*/
|
||||
BigDecimal getMoneyCost(TaskElement taskElement);
|
||||
BigDecimal getMoneyCost(OrderElement orderElement);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ import org.springframework.stereotype.Component;
|
|||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
/**
|
||||
* @author mrego
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class MoneyCostCalculator implements IMoneyCostCalculator {
|
||||
|
|
@ -51,9 +55,7 @@ public class MoneyCostCalculator implements IMoneyCostCalculator {
|
|||
private IHourCostDAO hourCostDAO;
|
||||
|
||||
@Override
|
||||
public BigDecimal getMoneyCost(TaskElement taskElement) {
|
||||
OrderElement orderElement = taskElement.getOrderElement();
|
||||
|
||||
public BigDecimal getMoneyCost(OrderElement orderElement) {
|
||||
List<WorkReportLine> workReportLines = workReportLineDAO
|
||||
.findByOrderElementAndChildren(orderElement, false);
|
||||
|
||||
|
|
@ -72,4 +74,20 @@ public class MoneyCostCalculator implements IMoneyCostCalculator {
|
|||
return result.setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divides {@code moneyCost} by {@code budget} if {@code budget} is
|
||||
* different from 0. Otherwise, returns 0.
|
||||
*
|
||||
* @param moneyCost
|
||||
* @param budget
|
||||
* @return A BigDecimal from 0 to 1 with the proportion
|
||||
*/
|
||||
public static BigDecimal getMoneyCostProportion(BigDecimal moneyCost,
|
||||
BigDecimal budget) {
|
||||
if (budget.compareTo(BigDecimal.ZERO) == 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return moneyCost.divide(budget);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,6 @@
|
|||
*/
|
||||
package org.libreplan.business.test.planner.entities;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.libreplan.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
|
|
@ -44,7 +41,6 @@ import org.libreplan.business.orders.entities.OrderElement;
|
|||
import org.libreplan.business.orders.entities.OrderLine;
|
||||
import org.libreplan.business.planner.entities.IMoneyCostCalculator;
|
||||
import org.libreplan.business.planner.entities.MoneyCostCalculator;
|
||||
import org.libreplan.business.planner.entities.TaskElement;
|
||||
import org.libreplan.business.resources.daos.IResourceDAO;
|
||||
import org.libreplan.business.resources.entities.Resource;
|
||||
import org.libreplan.business.resources.entities.Worker;
|
||||
|
|
@ -97,7 +93,6 @@ public class MoneyCostCalculatorTest {
|
|||
private OrderElement orderElement;
|
||||
private WorkReportType workReportType;
|
||||
private WorkReport workReport;
|
||||
private TaskElement taskElement;
|
||||
|
||||
private void givenTypeOfWorkHours() {
|
||||
typeOfWorkHours = TypeOfWorkHours.createUnvalidated(
|
||||
|
|
@ -162,13 +157,6 @@ public class MoneyCostCalculatorTest {
|
|||
workReportDAO.save(workReport);
|
||||
}
|
||||
|
||||
private void givenTask() {
|
||||
taskElement = createNiceMock(TaskElement.class);
|
||||
expect(taskElement.getOrderElement()).andReturn(orderElement)
|
||||
.anyTimes();
|
||||
replay(taskElement);
|
||||
}
|
||||
|
||||
private void givenBasicExample() {
|
||||
givenTypeOfWorkHours();
|
||||
givenCostCategory();
|
||||
|
|
@ -176,13 +164,12 @@ public class MoneyCostCalculatorTest {
|
|||
givenOrderElement();
|
||||
giveWorkReportType();
|
||||
givenWorkReport();
|
||||
givenTask();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicTest() throws InstanceNotFoundException {
|
||||
givenBasicExample();
|
||||
assertThat(moneyCostCalculator.getMoneyCost(taskElement),
|
||||
assertThat(moneyCostCalculator.getMoneyCost(orderElement),
|
||||
equalTo(new BigDecimal(500).setScale(2)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ import org.libreplan.business.orders.entities.HoursGroup;
|
|||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.orders.entities.OrderElement;
|
||||
import org.libreplan.business.orders.entities.OrderLineGroup;
|
||||
import org.libreplan.business.planner.entities.IMoneyCostCalculator;
|
||||
import org.libreplan.business.planner.entities.MoneyCostCalculator;
|
||||
import org.libreplan.business.qualityforms.daos.IQualityFormDAO;
|
||||
import org.libreplan.business.qualityforms.entities.QualityForm;
|
||||
import org.libreplan.business.requirements.entities.DirectCriterionRequirement;
|
||||
|
|
@ -167,6 +169,9 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
@Autowired
|
||||
private IOrderVersionDAO orderVersionDAO;
|
||||
|
||||
@Autowired
|
||||
private IMoneyCostCalculator moneyCostCalculator;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Label> getLabels() {
|
||||
|
|
@ -680,10 +685,8 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
result.append(_("Progress") + ": ").append(getEstimatedAdvance(order)).append("% , ");
|
||||
result.append(_("Hours invested") + ": ").append(
|
||||
getHoursAdvancePercentage(order)).append("% , ");
|
||||
// TODO change method and message, for the moment using
|
||||
// getHoursAdvancePercentage(order)
|
||||
result.append(_("Cost") + ": ")
|
||||
.append(getHoursAdvancePercentage(order)).append("% \n");
|
||||
.append(getMoneyCostBarPercentage(order)).append("% \n");
|
||||
|
||||
if (!getDescription(order).equals("")) {
|
||||
result.append(" , " + _("Description") + ": "
|
||||
|
|
@ -719,6 +722,12 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
return result.multiply(new BigDecimal(100));
|
||||
}
|
||||
|
||||
private BigDecimal getMoneyCostBarPercentage(Order order) {
|
||||
return MoneyCostCalculator.getMoneyCostProportion(
|
||||
moneyCostCalculator.getMoneyCost(order), order.getBudget());
|
||||
|
||||
}
|
||||
|
||||
private String buildLabelsText(Order order) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Set<Label> labels = order.getLabels();
|
||||
|
|
|
|||
|
|
@ -67,7 +67,9 @@ import org.libreplan.business.planner.daos.ITaskElementDAO;
|
|||
import org.libreplan.business.planner.entities.Dependency;
|
||||
import org.libreplan.business.planner.entities.Dependency.Type;
|
||||
import org.libreplan.business.planner.entities.GenericResourceAllocation;
|
||||
import org.libreplan.business.planner.entities.IMoneyCostCalculator;
|
||||
import org.libreplan.business.planner.entities.ITaskPositionConstrained;
|
||||
import org.libreplan.business.planner.entities.MoneyCostCalculator;
|
||||
import org.libreplan.business.planner.entities.PositionConstraintType;
|
||||
import org.libreplan.business.planner.entities.ResourceAllocation;
|
||||
import org.libreplan.business.planner.entities.ResourceAllocation.Direction;
|
||||
|
|
@ -276,6 +278,9 @@ public class TaskElementAdapter {
|
|||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
@Autowired
|
||||
private IMoneyCostCalculator moneyCostCalculator;
|
||||
|
||||
static class GanttDateAdapter extends CustomDate {
|
||||
|
||||
private static final int DAY_MILLISECONDS = (int) Days.days(1)
|
||||
|
|
@ -593,6 +598,31 @@ public class TaskElementAdapter {
|
|||
RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GanttDate getMoneyCostBarEndDate() {
|
||||
return calculateLimitDateByPercentage(getMoneyCostBarPercentage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getMoneyCostBarPercentage() {
|
||||
return MoneyCostCalculator.getMoneyCostProportion(
|
||||
getMoneyCost(), taskElement.getOrderElement()
|
||||
.getBudget());
|
||||
}
|
||||
|
||||
private BigDecimal getMoneyCost() {
|
||||
return transactionService
|
||||
.runOnReadOnlyTransaction(new IOnTransaction<BigDecimal>() {
|
||||
|
||||
@Override
|
||||
public BigDecimal execute() {
|
||||
return moneyCostCalculator
|
||||
.getMoneyCost(taskElement
|
||||
.getOrderElement());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public GanttDate getAdvanceEndDate(String progressType) {
|
||||
return getAdvanceEndDate(ProgressType.asEnum(progressType));
|
||||
|
|
@ -953,10 +983,8 @@ public class TaskElementAdapter {
|
|||
.append(getHoursAdvancePercentage().multiply(
|
||||
new BigDecimal(100))).append("% <br/>");
|
||||
|
||||
// TODO change method and message, for the moment using
|
||||
// getHoursAdvancePercentage()
|
||||
result.append(_("Cost") + ": ")
|
||||
.append(getHoursAdvancePercentage().multiply(
|
||||
.append(getMoneyCostBarPercentage().multiply(
|
||||
new BigDecimal(100))).append("% <br/>");
|
||||
|
||||
if (taskElement.getOrderElement() instanceof Order) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue