diff --git a/libreplan-business/src/main/java/org/libreplan/business/workreports/daos/IWorkReportDAO.java b/libreplan-business/src/main/java/org/libreplan/business/workreports/daos/IWorkReportDAO.java index 4beec4916..9add69c28 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/workreports/daos/IWorkReportDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/workreports/daos/IWorkReportDAO.java @@ -48,7 +48,9 @@ public interface IWorkReportDAO extends IIntegrationEntityDAO { /** * Returns the {@link WorkReport} of the predefined type monthly timesheet - * for the given resource in the specified date. + * for the given resource in the specified date.
+ * + * If there isn't any, it returns null. */ WorkReport getMonthlyTimesheetWorkReport(Resource resource, LocalDate date); 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 6e8037c0e..efbe400b1 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 @@ -55,6 +55,10 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer { Util.appendLabel(row, monthlyTimesheet.getDate().toString("MMMM y")); + WorkReport workReport = monthlyTimesheet.getWorkReport(); + Util.appendLabel(row, workReport.getTotalEffortDuration() + .toFormattedString()); + Util.appendOperationsAndOnClickEvent(row, new EventListener() { @Override @@ -90,17 +94,30 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer { * {@link WorkReport}. */ class MonthlyTimesheet { + private LocalDate date; + private WorkReport workReport; + /** - * 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 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. */ - MonthlyTimesheet(LocalDate date) { - this.date = new LocalDate(date.getYear(), date.getMonthOfYear(), 1); + MonthlyTimesheet(LocalDate date, WorkReport workReport) { + this.date = date.dayOfMonth().withMaximumValue(); + this.workReport = workReport; } public LocalDate getDate() { return date; } + + public WorkReport getWorkReport() { + return workReport; + } + } 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 3c38f9b6d..7641e9a64 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 @@ -25,9 +25,14 @@ import java.util.List; import org.joda.time.LocalDate; import org.joda.time.Months; +import org.libreplan.business.resources.entities.Resource; import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.users.entities.User; +import org.libreplan.business.workreports.daos.IWorkReportDAO; +import org.libreplan.business.workreports.entities.WorkReport; +import org.libreplan.business.workreports.entities.WorkReportType; import org.libreplan.web.UserUtil; +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; @@ -42,6 +47,9 @@ import org.springframework.transaction.annotation.Transactional; @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel { + @Autowired + private IWorkReportDAO workReportDAO; + @Override @Transactional(readOnly = true) public List getMonthlyTimesheets() { @@ -52,10 +60,11 @@ public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel { LocalDate activationDate = getActivationDate(user.getWorker()); LocalDate currentDate = new LocalDate(); - return getMonthlyTimesheets(activationDate, currentDate.plusMonths(1)); + return getMonthlyTimesheets(user.getWorker(), activationDate, + currentDate.plusMonths(1)); } - private List getMonthlyTimesheets( + private List getMonthlyTimesheets(Resource resource, LocalDate start, LocalDate end) { int months = Months.monthsBetween(start, end).getMonths(); @@ -64,12 +73,25 @@ public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel { // In decreasing order to provide a list sorted with the more recent // monthly timesheets at the beginning for (int i = months; i >= 0; i--) { - result.add(new MonthlyTimesheet(start.plusMonths(i))); + LocalDate date = start.plusMonths(i); + WorkReport workReport = workReportDAO + .getMonthlyTimesheetWorkReport(resource, date); + forceLoad(workReport); + result.add(new MonthlyTimesheet(date, workReport)); } return result; } + private void forceLoad(WorkReport workReport) { + if (workReport != null) { + WorkReportType workReportType = workReport.getWorkReportType(); + workReportType.getLineFields().size(); + workReportType.getWorkReportLabelTypeAssigments().size(); + workReportType.getHeadingFields().size(); + } + } + private LocalDate getActivationDate(Worker worker) { return worker.getCalendar().getFistCalendarAvailability() .getStartDate(); diff --git a/libreplan-webapp/src/main/webapp/myaccount/_monthlyTimesheetsArea.zul b/libreplan-webapp/src/main/webapp/myaccount/_monthlyTimesheetsArea.zul index 439bb137e..5c7c79e3a 100644 --- a/libreplan-webapp/src/main/webapp/myaccount/_monthlyTimesheetsArea.zul +++ b/libreplan-webapp/src/main/webapp/myaccount/_monthlyTimesheetsArea.zul @@ -25,6 +25,7 @@ pageSize="10" rowRenderer="@{controller.monthlyTimesheetsRenderer}"> +