diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IMonthlyTimesheetModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IMonthlyTimesheetModel.java
index 2cebb15ad..46b887c4f 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IMonthlyTimesheetModel.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IMonthlyTimesheetModel.java
@@ -77,7 +77,9 @@ public interface IMonthlyTimesheetModel {
/**
* Sets the {@link EffortDuration} in the current monthly timesheet for the
- * specified orderElement and date.
+ * specified orderElement and date.
+ *
+ * Marks the current monthly timesheet as modified.
*/
void setEffortDuration(OrderElement orderElement, LocalDate date,
EffortDuration effortDuration);
@@ -128,4 +130,22 @@ public interface IMonthlyTimesheetModel {
*/
Order getOrder(OrderElement orderElement);
-}
\ No newline at end of file
+ /**
+ * Returns true if current monthly timesheet has been modified
+ * by the user.
+ */
+ boolean isModified();
+
+ /**
+ * Checks if current monthly timesheet is the first month, that means the
+ * first activation period of the resource.
+ */
+ boolean isFirstMonth();
+
+ /**
+ * Checks if current monthly timesheet is the last month, that means the
+ * next month of current date.
+ */
+ boolean isLastMonth();
+
+}
diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetController.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetController.java
index 194642b2b..57824423f 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetController.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetController.java
@@ -25,12 +25,16 @@ import static org.libreplan.web.planner.tabs.MultipleTabsPlannerController.BREAD
import java.util.ArrayList;
import java.util.List;
+import javax.annotation.Resource;
+
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.workingday.EffortDuration;
import org.libreplan.web.common.Util;
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
+import org.libreplan.web.common.entrypoints.EntryPointsHandler;
+import org.libreplan.web.common.entrypoints.EntryPointsHandler.ICapture;
import org.libreplan.web.common.entrypoints.IURLHandlerRegistry;
import org.libreplan.web.users.services.CustomTargetUrlResolver;
import org.springframework.util.Assert;
@@ -38,6 +42,7 @@ import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.util.GenericForwardComposer;
+import org.zkoss.zul.Button;
import org.zkoss.zul.Cell;
import org.zkoss.zul.Column;
import org.zkoss.zul.Columns;
@@ -69,6 +74,13 @@ public class MonthlyTimesheetController extends GenericForwardComposer
private BandboxSearch orderElementBandboxSearch;
+ private Button previousMonth;
+
+ private Button nextMonth;
+
+ @Resource
+ private IMonthlyTimesheetController monthlyTimesheetController;
+
private RowRenderer rowRenderer = new RowRenderer() {
private LocalDate first;
@@ -412,6 +424,43 @@ public class MonthlyTimesheetController extends GenericForwardComposer
}
}
+ public boolean isFirstMonth() {
+ return monthlyTimesheetModel.isFirstMonth();
+ }
+
+ public boolean isLastMonth() {
+ return monthlyTimesheetModel.isLastMonth();
+ }
+
+ public void previousMonth() {
+ if (monthlyTimesheetModel.isModified()) {
+ throw new WrongValueException(
+ previousMonth,
+ _("There are unsaved changes in the current monthly timesheet, please save before moving"));
+ }
+ sendToMonthlyTimesheet(monthlyTimesheetModel.getDate().minusMonths(1));
+ }
+
+ public void nextMonth() {
+ if (monthlyTimesheetModel.isModified()) {
+ throw new WrongValueException(
+ nextMonth,
+ _("There are unsaved changes in the current monthly timesheet, please save before moving"));
+ }
+
+ sendToMonthlyTimesheet(monthlyTimesheetModel.getDate().plusMonths(1));
+ }
+
+ private void sendToMonthlyTimesheet(final LocalDate date) {
+ String capturePath = EntryPointsHandler.capturePath(new ICapture() {
+ @Override
+ public void capture() {
+ monthlyTimesheetController.goToCreateOrEditForm(date);
+ }
+ });
+ Executions.getCurrent().sendRedirect(capturePath);
+ }
+
}
/**
diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetModel.java
index 0b6dd1712..bf8a28927 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetModel.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MonthlyTimesheetModel.java
@@ -101,6 +101,8 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
@Autowired
private IOrderDAO orderDAO;
+ private boolean modified;
+
@Override
@Transactional(readOnly = true)
public void initCreateOrEdit(LocalDate date) {
@@ -117,6 +119,8 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
initWorkReport();
initOrderElements();
+
+ modified = false;
}
private void initDates() {
@@ -266,6 +270,7 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
workReport.addWorkReportLine(workReportLine);
}
workReportLine.setEffort(effortDuration);
+ modified = true;
}
private WorkReportLine createWorkReportLine(OrderElement orderElement,
@@ -298,6 +303,7 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
.getWorkReportLines());
workReportDAO.save(workReport);
}
+ modified = false;
}
@Override
@@ -306,6 +312,7 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
date = null;
orderElements = null;
workReport = null;
+ modified = false;
}
@Override
@@ -353,4 +360,22 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
return orderDAO.loadOrderAvoidingProxyFor(orderElement);
}
+ @Override
+ public boolean isModified() {
+ return modified;
+ }
+
+ @Override
+ public boolean isFirstMonth() {
+ LocalDate activationDate = getWorker().getCalendar()
+ .getFistCalendarAvailability().getStartDate();
+ return firstDay.equals(activationDate.dayOfMonth().withMinimumValue());
+ }
+
+ @Override
+ public boolean isLastMonth() {
+ return firstDay.equals(new LocalDate().plusMonths(1).dayOfMonth()
+ .withMinimumValue());
+ }
+
}
diff --git a/libreplan-webapp/src/main/webapp/myaccount/monthlyTimesheet.zul b/libreplan-webapp/src/main/webapp/myaccount/monthlyTimesheet.zul
index bb0db9ae3..cb3f126d4 100644
--- a/libreplan-webapp/src/main/webapp/myaccount/monthlyTimesheet.zul
+++ b/libreplan-webapp/src/main/webapp/myaccount/monthlyTimesheet.zul
@@ -30,6 +30,15 @@
+
+
+