diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IMonthlyTimesheetsAreaModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IMonthlyTimesheetsAreaModel.java index d1852ba50..d1fe00664 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IMonthlyTimesheetsAreaModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IMonthlyTimesheetsAreaModel.java @@ -34,18 +34,18 @@ import org.libreplan.business.workreports.entities.WorkReport; public interface IMonthlyTimesheetsAreaModel { /** - * Returns the list of {@link MonthlyTimesheet MonthlyTimesheets} for the + * Returns the list of {@link MonthlyTimesheetDTO MonthlyTimesheets} for the * resource bound to current {@link User}.
* * There's no need that a {@link WorkReport} is saved in order to a - * {@link MonthlyTimesheet} exists for a month.
+ * {@link MonthlyTimesheetDTO} exists for a month.
* - * The list of {@link MonthlyTimesheet MonthlyTimesheets} will be since the + * The list of {@link MonthlyTimesheetDTO MonthlyTimesheets} will be since the * date the resource is activated in the system (checking * {@link CalendarAvailability} for the resource) to next month of current * date. */ - List getMonthlyTimesheets(); + List getMonthlyTimesheets(); /** * Returns the number of different {@link OrderElement OrderElements} with diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetDTO.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetDTO.java new file mode 100644 index 000000000..87b6b141a --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetDTO.java @@ -0,0 +1,92 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.libreplan.web.users.dashboard; + +import org.joda.time.LocalDate; +import org.libreplan.business.workingday.EffortDuration; +import org.libreplan.business.workreports.entities.WorkReport; + +/** + * Simple class to represent the monthly timesheets to be shown in the list.
+ * + * This is only a utility class for the UI, everything will be saved using + * {@link WorkReport} class. + * + * @author Manuel Rego Casasnovas + */ +public class MonthlyTimesheetDTO { + + private LocalDate date; + + private WorkReport workReport; + + private EffortDuration resourceCapacity; + + private EffortDuration totalHours; + + private int tasksNumber; + + /** + * @param date + * Only the year and month are used, the day is reseted to first + * day of the month. As there's only one timesheet per month. + * @param workReport + * The work report of the monthly timesheet, it could be + * null if it doesn't exist yet. + * @param resourceCapacity + * The capacity of the resource bound to current user in the + * month of this timesheet. + * @param totalHours + * Total hours worked by the resource bound to the current user + * in the monthly timesheet + * @param tasksNumber + * Number of tasks in the monthly timesheet + */ + MonthlyTimesheetDTO(LocalDate date, WorkReport workReport, + EffortDuration resourceCapacity, EffortDuration totalHours, + int tasksNumber) { + this.date = date.dayOfMonth().withMaximumValue(); + this.workReport = workReport; + this.resourceCapacity = resourceCapacity; + this.totalHours = totalHours; + this.tasksNumber = tasksNumber; + } + + public LocalDate getDate() { + return date; + } + + public WorkReport getWorkReport() { + return workReport; + } + + public EffortDuration getResourceCapacity() { + return resourceCapacity; + } + + public EffortDuration getTotalHours() { + return totalHours; + } + + public int getTasksNumber() { + return tasksNumber; + } + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetsAreaController.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetsAreaController.java index 8fa5a5edf..66e98ed71 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetsAreaController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetsAreaController.java @@ -23,9 +23,6 @@ import java.util.List; import javax.annotation.Resource; -import org.joda.time.LocalDate; -import org.libreplan.business.workingday.EffortDuration; -import org.libreplan.business.workreports.entities.WorkReport; import org.libreplan.web.common.Util; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; @@ -51,23 +48,15 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer { @Override public void render(Row row, Object data) throws Exception { - final MonthlyTimesheet monthlyTimesheet = (MonthlyTimesheet) data; + final MonthlyTimesheetDTO monthlyTimesheet = (MonthlyTimesheetDTO) data; row.setValue(monthlyTimesheet); Util.appendLabel(row, monthlyTimesheet.getDate().toString("MMMM y")); Util.appendLabel(row, monthlyTimesheet.getResourceCapacity() .toFormattedString()); - - WorkReport workReport = monthlyTimesheet.getWorkReport(); - EffortDuration hours = EffortDuration.zero(); - int tasksNumber = 0; - if (workReport != null) { - hours = workReport.getTotalEffortDuration(); - tasksNumber = monthlyTimesheetsAreaModel - .getNumberOfOrderElementsWithTrackedTime(workReport); - } - Util.appendLabel(row, hours.toFormattedString()); - Util.appendLabel(row, tasksNumber + ""); + Util.appendLabel(row, monthlyTimesheet.getTotalHours() + .toFormattedString()); + Util.appendLabel(row, monthlyTimesheet.getTasksNumber() + ""); Util.appendOperationsAndOnClickEvent(row, new EventListener() { @@ -87,7 +76,7 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer { comp.setAttribute("controller", this); } - public List getMonthlyTimesheets() { + public List getMonthlyTimesheets() { return monthlyTimesheetsAreaModel.getMonthlyTimesheets(); } @@ -95,50 +84,4 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer { return monthlyTimesheetsRenderer; } -} - -/** - * Simple class to represent the monthly timesheets to be shown in the list.
- * - * This is only a simple class for the UI, everything will be saved using - * {@link WorkReport}. - */ -class MonthlyTimesheet { - - private LocalDate date; - - private WorkReport workReport; - - private EffortDuration resourceCapacity; - - /** - * @param date - * Only the year and month are used, the day is reseted to first - * day of the month. As there's only one timesheet per month. - * @param workReport - * The work report of the monthly timesheet, it could be - * null if it doesn't exist yet. - * @param resourceCapacity - * The capacity of the resource bound to current user in the - * month of this timesheet. - */ - MonthlyTimesheet(LocalDate date, WorkReport workReport, - EffortDuration resourceCapacity) { - this.date = date.dayOfMonth().withMaximumValue(); - this.workReport = workReport; - this.resourceCapacity = resourceCapacity; - } - - public LocalDate getDate() { - return date; - } - - public WorkReport getWorkReport() { - return workReport; - } - - public EffortDuration getResourceCapacity() { - return resourceCapacity; - } - -} +} \ No newline at end of file diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetsAreaModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetsAreaModel.java index 6f64914fb..fa28d7ddf 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetsAreaModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetsAreaModel.java @@ -58,7 +58,7 @@ public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel { @Override @Transactional(readOnly = true) - public List getMonthlyTimesheets() { + public List getMonthlyTimesheets() { User user = UserUtil.getUserFromSession(); if (!user.isBound()) { return Collections.emptyList(); @@ -72,19 +72,28 @@ public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel { currentDate.plusMonths(1)); } - private List getMonthlyTimesheets(Resource resource, + private List getMonthlyTimesheets(Resource resource, LocalDate start, LocalDate end) { int months = Months.monthsBetween(start, end).getMonths(); - List result = new ArrayList(); + List result = new ArrayList(); // In decreasing order to provide a list sorted with the more recent // monthly timesheets at the beginning for (int i = months; i >= 0; i--) { LocalDate date = start.plusMonths(i); - result.add(new MonthlyTimesheet(date, - getWorkReport(resource, date), getResourceCapcity(resource, - date))); + + WorkReport workReport = getWorkReport(resource, date); + + EffortDuration hours = EffortDuration.zero(); + int tasksNumber = 0; + if (workReport != null) { + hours = workReport.getTotalEffortDuration(); + tasksNumber = getNumberOfOrderElementsWithTrackedTime(workReport); + } + + result.add(new MonthlyTimesheetDTO(date, workReport, + getResourceCapcity(resource, date), hours, tasksNumber)); } return result; diff --git a/libreplan-webapp/src/main/webapp/myaccount/_monthlyTimesheetsArea.zul b/libreplan-webapp/src/main/webapp/myaccount/_monthlyTimesheetsArea.zul index 381a2a215..110eb2667 100644 --- a/libreplan-webapp/src/main/webapp/myaccount/_monthlyTimesheetsArea.zul +++ b/libreplan-webapp/src/main/webapp/myaccount/_monthlyTimesheetsArea.zul @@ -25,10 +25,15 @@ pageSize="10" rowRenderer="@{controller.monthlyTimesheetsRenderer}" sclass="clickable-rows"> - - - - + + + +