ItEr34S13CUAsignacionRecursosEspecificosAPlanificacionItEr33S15: Added dedication chart to stretches function configuration.

This commit is contained in:
Manuel Rego Casasnovas 2009-11-16 11:44:24 +01:00 committed by Javier Moran Rua
parent 536a4f6664
commit f577f7a794
4 changed files with 101 additions and 6 deletions

View file

@ -24,6 +24,7 @@ import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.joda.time.LocalDate;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.planner.entities.AssignmentFunction;
import org.navalplanner.business.planner.entities.Stretch;
@ -64,6 +65,10 @@ public interface IStretchesFunctionModel {
void setStretchLengthPercentage(Stretch stretch, BigDecimal lengthPercentage)
throws IllegalArgumentException;
LocalDate getTaskStartDate();
Integer getTaskHours();
/*
* Final conversation steps
*/

View file

@ -27,6 +27,8 @@ import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.planner.entities.AssignmentFunction;
import org.navalplanner.business.planner.entities.ResourceAllocation;
@ -48,6 +50,8 @@ import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.SimpleXYModel;
import org.zkoss.zul.XYModel;
import org.zkoss.zul.api.Window;
public class StretchesFunctionController extends GenericForwardComposer {
@ -82,7 +86,7 @@ public class StretchesFunctionController extends GenericForwardComposer {
stretchesFunctionModel.initCreate(task);
}
}
reloadStretchesList();
reloadStretchesListAndCharts();
}
public void showWindow() throws SuspendNotAllowedException,
@ -155,7 +159,7 @@ public class StretchesFunctionController extends GenericForwardComposer {
public void set(Date value) {
try {
stretchesFunctionModel.setStretchDate(stretch, value);
reloadStretchesList();
reloadStretchesListAndCharts();
} catch (IllegalArgumentException e) {
throw new WrongValueException(tempDatebox, e
.getMessage());
@ -183,7 +187,7 @@ public class StretchesFunctionController extends GenericForwardComposer {
stretchesFunctionModel
.setStretchLengthPercentage(stretch,
value);
reloadStretchesList();
reloadStretchesListAndCharts();
} catch (IllegalArgumentException e) {
throw new WrongValueException(tempDecimalbox, e
.getMessage());
@ -210,6 +214,7 @@ public class StretchesFunctionController extends GenericForwardComposer {
new BigDecimal(100), RoundingMode.DOWN);
try {
stretch.setAmountWorkPercentage(value);
reloadStretchesListAndCharts();
} catch (IllegalArgumentException e) {
throw new WrongValueException(tempDecimalbox,
_("Amount work percentage should be between 0 and 100"));
@ -229,7 +234,7 @@ public class StretchesFunctionController extends GenericForwardComposer {
@Override
public void onEvent(Event event) throws Exception {
stretchesFunctionModel.removeStretch(stretch);
reloadStretchesList();
reloadStretchesListAndCharts();
}
});
@ -240,11 +245,59 @@ public class StretchesFunctionController extends GenericForwardComposer {
public void addStretch() {
stretchesFunctionModel.addStretch();
reloadStretchesList();
reloadStretchesListAndCharts();
}
private void reloadStretchesList() {
private void reloadStretchesListAndCharts() {
Util.reloadBindings(window.getFellow("stretchesList"));
Util.reloadBindings(window.getFellow("dedicationChart"));
}
public XYModel getDedicationChartData() {
XYModel xymodel = new SimpleXYModel();
List<Stretch> stretches = stretchesFunctionModel.getStretches();
if (stretches.isEmpty()) {
return xymodel;
}
String title = "hours";
LocalDate previousDate = stretchesFunctionModel.getTaskStartDate();
BigDecimal previousPercentage = BigDecimal.ZERO;
BigDecimal taskHours = new BigDecimal(stretchesFunctionModel
.getTaskHours());
xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
.getMillis(), 0);
for (Stretch stretch : stretches) {
BigDecimal amountWork = stretch.getAmountWorkPercentage().subtract(
previousPercentage).multiply(taskHours);
Integer days = Days.daysBetween(previousDate, stretch.getDate())
.getDays();
// TODO subtract bank holidays
int hoursPerDay = 0;
if (days > 0) {
hoursPerDay = amountWork.divide(new BigDecimal(days),
RoundingMode.DOWN).intValue();
}
xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
.getMillis() + 1, hoursPerDay);
xymodel.addValue(title, stretch.getDate().toDateTimeAtStartOfDay()
.getMillis(), hoursPerDay);
previousDate = stretch.getDate();
previousPercentage = stretch.getAmountWorkPercentage();
}
xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
.getMillis() + 1, 0);
return xymodel;
}
}

View file

@ -30,13 +30,16 @@ import java.util.List;
import org.joda.time.LocalDate;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.planner.daos.ITaskElementDAO;
import org.navalplanner.business.planner.entities.AssignmentFunction;
import org.navalplanner.business.planner.entities.Stretch;
import org.navalplanner.business.planner.entities.StretchesFunction;
import org.navalplanner.business.planner.entities.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Model for UI operations related to {@link StretchesFunction} configuration.
@ -51,10 +54,14 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
* Conversation state
*/
private StretchesFunction stretchesFunction;
private Task task;
private StretchesFunction originalStretchesFunction;
@Autowired
private ITaskElementDAO taskElementDAO;
@Override
public void initCreate(Task task) {
stretchesFunction = StretchesFunction.create();
@ -191,4 +198,23 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
stretch.setDate(new LocalDate(stretchDate));
}
@Override
public LocalDate getTaskStartDate() {
if (task == null) {
return null;
}
return new LocalDate(task.getStartDate());
}
@Transactional(readOnly = true)
@Override
public Integer getTaskHours() {
if (task == null) {
return null;
}
taskElementDAO.reattach(task);
return task.getHoursSpecifiedAtOrder();
}
}

View file

@ -30,6 +30,7 @@
<window border="normal" title="${i18n:_('Stretches function configuration')}"
apply="${stretchesFunctionController}">
<hbox>
<vbox>
<label>${i18n:_('Stretches')}</label>
@ -57,6 +58,16 @@
</hbox>
</vbox>
<vbox>
<chart id="dedicationChart" title="${i18n:_('Dedication chart')}"
type="time_series" threeD="false"
model="@{stretchesFunctionController.getDedicationChartData}"
yAxis= "${i18n:_('Hours')}" paneColor="#FFFFFF"
showLegend="false" />
</vbox>
</hbox>
</window>
</zk>