Add capcity row to monthly timesheets

FEA: ItEr76S28UserDashboard
This commit is contained in:
Manuel Rego Casasnovas 2012-05-29 12:35:08 +02:00
parent 346214c2ce
commit 6b01da1240
3 changed files with 45 additions and 5 deletions

View file

@ -95,4 +95,10 @@ public interface IMonthlyTimesheetModel {
*/
EffortDuration getTotalEffortDuration();
/**
* Returns the capacity of the current resource for the specified
* <code>date</code>.
*/
EffortDuration getResourceCapacity(LocalDate date);
}

View file

@ -82,7 +82,7 @@ public class MonthlyTimesheetController extends GenericForwardComposer
monthlyTimesheetRow.getOrderElemement());
break;
case CAPACITY:
// TODO
renderCapacityRow(row);
break;
case TOTAL:
renderTotalRow(row);
@ -175,16 +175,15 @@ public class MonthlyTimesheetController extends GenericForwardComposer
}
private void renderTotalRow(Row row) {
appendTotalLabel(row);
appendLabelSpaningTwoColumns(row, _("Total"));
appendTotalForDays(row);
appendTotalColumn(row);
}
private void appendTotalLabel(Row row) {
Label label = new Label(_("Total"));
private void appendLabelSpaningTwoColumns(Row row, String label) {
Cell cell = new Cell();
cell.setColspan(2);
cell.appendChild(label);
cell.appendChild(new Label(label));
row.appendChild(cell);
}
@ -233,6 +232,26 @@ public class MonthlyTimesheetController extends GenericForwardComposer
.toFormattedString());
}
private void renderCapacityRow(Row row) {
appendLabelSpaningTwoColumns(row, _("Capacity"));
appendCapcityForDaysAndTotal(row);
}
private void appendCapcityForDaysAndTotal(Row row) {
EffortDuration totalCapacity = EffortDuration.zero();
for (LocalDate day = start; day.compareTo(end) <= 0; day = day
.plusDays(1)) {
EffortDuration capacity = monthlyTimesheetModel
.getResourceCapacity(day);
Util.appendLabel(row, capacity.toFormattedString());
totalCapacity = totalCapacity.plus(capacity);
}
Util.appendLabel(row, totalCapacity.toFormattedString());
}
};
@Override
@ -310,6 +329,7 @@ public class MonthlyTimesheetController extends GenericForwardComposer
List<MonthlyTimesheetRow> result = MonthlyTimesheetRow
.wrap(monthlyTimesheetModel
.getOrderElements());
result.add(MonthlyTimesheetRow.createCapacityRow());
result.add(MonthlyTimesheetRow.createTotalRow());
return result;
}

View file

@ -24,6 +24,7 @@ import java.util.List;
import org.hibernate.NonUniqueResultException;
import org.joda.time.LocalDate;
import org.libreplan.business.calendars.entities.ResourceCalendar;
import org.libreplan.business.common.daos.IConfigurationDAO;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
@ -35,6 +36,7 @@ import org.libreplan.business.resources.entities.Worker;
import org.libreplan.business.scenarios.IScenarioManager;
import org.libreplan.business.users.entities.User;
import org.libreplan.business.workingday.EffortDuration;
import org.libreplan.business.workingday.IntraDayDate.PartialDay;
import org.libreplan.business.workreports.daos.IWorkReportDAO;
import org.libreplan.business.workreports.daos.IWorkReportTypeDAO;
import org.libreplan.business.workreports.entities.PredefinedWorkReportTypes;
@ -42,6 +44,7 @@ import org.libreplan.business.workreports.entities.WorkReport;
import org.libreplan.business.workreports.entities.WorkReportLine;
import org.libreplan.business.workreports.entities.WorkReportType;
import org.libreplan.web.UserUtil;
import org.libreplan.web.calendars.BaseCalendarModel;
import org.libreplan.web.common.concurrentdetection.OnConcurrentModification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
@ -93,6 +96,7 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
throw new RuntimeException(
"This page only can be used by users bound to a resource");
}
forceLoad(getWorker().getCalendar());
this.date = date;
@ -100,6 +104,10 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
initWorkReport();
}
private void forceLoad(ResourceCalendar calendar) {
BaseCalendarModel.forceLoadBaseCalendar(calendar);
}
private void initWorkReport() {
// Get work report representing this monthly timesheet
workReport = workReportDAO.getMonthlyTimesheetWorkReport(
@ -260,4 +268,10 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
return workReport.getTotalEffortDuration();
}
@Override
public EffortDuration getResourceCapacity(LocalDate date) {
return getWorker().getCalendar().getCapacityOn(
PartialDay.wholeDay(date));
}
}