Add possibility to create monthly timesheets from work reports list

A pop-up asking for date and worker will be shown.

If the timesheet doesn't exist it will be created, if it already exists it will
be edited.

FEA: ItEr76S28UserDashboard
This commit is contained in:
Manuel Rego Casasnovas 2012-06-01 13:16:20 +02:00
parent 5f2d97e0b1
commit 72610b07f2
7 changed files with 201 additions and 12 deletions

View file

@ -27,6 +27,7 @@ import java.util.List;
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.resources.entities.Worker;
import org.libreplan.business.users.entities.User;
import org.springframework.transaction.annotation.Transactional;
/**
@ -121,4 +122,9 @@ public interface IWorkerDAO extends IIntegrationEntityDAO<Worker> {
public List<Worker> findByFirstNameSecondNameAnotherTransaction(
String firstname, String secondname);
/**
* Return the list of {@link Worker Workers} bound to any {@link User}.
*/
List<Worker> getBound();
}

View file

@ -191,4 +191,12 @@ public class WorkerDAO extends IntegrationEntityDAO<Worker>
return query.list();
}
@Override
@SuppressWarnings("unchecked")
public List<Worker> getBound() {
Criteria criteria = getSession().createCriteria(Worker.class);
criteria.add(Restrictions.isNotNull("user"));
return criteria.list();
}
}

View file

@ -0,0 +1,97 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.libreplan.web.common.components.finders;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.libreplan.business.resources.daos.IResourceDAO;
import org.libreplan.business.resources.entities.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.zkoss.zul.Bandbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
/**
* This is a finder for {@link Resource Resources} in a {@link Bandbox}
*
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
@Repository
public class ResourceBandboxFinder extends BandboxFinder implements IBandboxFinder {
@Autowired
private IResourceDAO resourceDAO;
private final String headers[] = { _("Resource") };
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
@Override
@Transactional(readOnly = true)
public List<Resource> getAll() {
return resourceDAO.findAll();
}
@Override
public boolean entryMatchesText(Object obj, String text) {
Resource resource = (Resource) obj;
text = StringUtils.trim(text.toLowerCase());
return checkContainsText(resource.getShortDescription(), text);
}
private boolean checkContainsText(String original, String text) {
return original.toLowerCase().contains(text);
}
@Override
public String objectToString(Object obj) {
Resource resource = (Resource) obj;
return resource.getShortDescription();
}
@Override
public String[] getHeaders() {
return headers.clone();
}
@Override
public ListitemRenderer getItemRenderer() {
return resourcesRenderer;
}
private final ListitemRenderer resourcesRenderer = new ListitemRenderer() {
@Override
public void render(Listitem item, Object data) {
Resource resource = (Resource) data;
item.setValue(data);
item.appendChild(new Listcell(resource.getShortDescription()));
}
};
}

View file

@ -32,6 +32,7 @@ import org.libreplan.business.labels.entities.LabelType;
import org.libreplan.business.orders.entities.OrderElement;
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.entities.WorkReport;
import org.libreplan.business.workreports.entities.WorkReportLine;
import org.libreplan.business.workreports.entities.WorkReportType;
@ -245,4 +246,9 @@ public interface IWorkReportModel extends IIntegrationEntityModel {
void generateWorkReportLinesIfIsNecessary();
List<TypeOfWorkHours> getAllHoursType();
/**
* Returns the list of {@link Worker Workers} bound to any {@link User}.
*/
List<Worker> getBoundWorkers();
}

View file

@ -41,6 +41,7 @@ import org.libreplan.business.labels.entities.Label;
import org.libreplan.business.labels.entities.LabelType;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.resources.entities.Resource;
import org.libreplan.business.resources.entities.Worker;
import org.libreplan.business.workingday.EffortDuration;
import org.libreplan.business.workreports.entities.HoursManagementEnum;
import org.libreplan.business.workreports.entities.WorkReport;
@ -85,6 +86,7 @@ import org.zkoss.zul.ListModel;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Popup;
import org.zkoss.zul.Row;
import org.zkoss.zul.RowRenderer;
import org.zkoss.zul.SimpleListModel;
@ -182,6 +184,12 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
@javax.annotation.Resource
private IMonthlyTimesheetController monthlyTimesheetController;
private Popup monthlyTimesheetsPopup;
private Datebox monthlyTimesheetsDatebox;
private BandboxSearch monthlyTimesheetsBandboxSearch;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
@ -642,13 +650,17 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
@Override
public void goToCreateForm(WorkReportType workReportType) {
cameBackList = false;
workReportModel.initCreate(workReportType);
prepareWorkReportList();
createWindow.setTitle(_("Create Work Report"));
getVisibility().showOnly(createWindow);
loadComponents(createWindow);
Util.reloadBindings(createWindow);
if (workReportType.isMonthlyTimesheetsType()) {
monthlyTimesheetsPopup.open(listTypeToAssign);
} else {
cameBackList = false;
workReportModel.initCreate(workReportType);
prepareWorkReportList();
createWindow.setTitle(_("Create Work Report"));
getVisibility().showOnly(createWindow);
loadComponents(createWindow);
Util.reloadBindings(createWindow);
}
}
@Override
@ -660,11 +672,7 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
@Override
public void goToEditForm(WorkReport workReport) {
if (workReport.getWorkReportType().isMonthlyTimesheetsType()) {
Date date = workReport.getWorkReportLines().iterator().next()
.getDate();
Resource resource = workReport.getResource();
monthlyTimesheetController.goToCreateOrEditForm(
LocalDate.fromDateFields(date), resource);
goToEditMonthlyTimeSheet(workReport);
} else {
workReportModel.initEdit(workReport);
createWindow.setTitle(_("Edit Work Report"));
@ -675,6 +683,13 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
}
}
private void goToEditMonthlyTimeSheet(WorkReport workReport) {
Date date = workReport.getWorkReportLines().iterator().next().getDate();
Resource resource = workReport.getResource();
monthlyTimesheetController.goToCreateOrEditForm(
LocalDate.fromDateFields(date), resource);
}
private void loadComponents(Component window) {
listWorkReportLines = (NewDataSortableGrid) window
.getFellow("listWorkReportLines");
@ -720,6 +735,12 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
listTypeToAssign = (Listbox) window.getFellow("listTypeToAssign");
filterStartDate = (Datebox) window.getFellow("filterStartDate");
filterFinishDate = (Datebox) window.getFellow("filterFinishDate");
monthlyTimesheetsPopup = (Popup) window
.getFellow("monthlyTimesheetsPopup");
monthlyTimesheetsDatebox = (Datebox) window
.getFellow("monthlyTimesheetsDatebox");
monthlyTimesheetsBandboxSearch = (BandboxSearch) window
.getFellow("monthlyTimesheetsBandboxSearch");
clearFilterDates();
}
@ -1932,4 +1953,25 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
}
public List<Worker> getBoundWorkers() {
return workReportModel.getBoundWorkers();
}
public void createOrEditMonthlyTimesheet() {
Date date = monthlyTimesheetsDatebox.getValue();
if (date == null) {
throw new WrongValueException(monthlyTimesheetsDatebox,
_("Please set a date"));
}
Resource resource = (Resource) monthlyTimesheetsBandboxSearch
.getSelectedElement();
if (resource == null) {
throw new WrongValueException(monthlyTimesheetsBandboxSearch,
_("Please select a worker"));
}
monthlyTimesheetController.goToCreateOrEditForm(
LocalDate.fromDateFields(date), resource);
}
}

View file

@ -632,4 +632,10 @@ public class WorkReportModel extends IntegrationEntityModel implements
return typeOfWorkHoursDAO.hoursTypeByNameAsc();
}
@Override
@Transactional(readOnly = true)
public List<Worker> getBoundWorkers() {
return workerDAO.getBound();
}
}

View file

@ -105,6 +105,30 @@
onClick="controller.onCreateNewWorkReport()"/>
</hbox>
</div>
<popup id="monthlyTimesheetsPopup" width="300px">
<grid>
<columns>
<column width="50px"/>
<column />
</columns>
<rows>
<row>
<label value="${i18n:_('Date')}" />
<datebox id="monthlyTimesheetsDatebox" />
</row>
<row>
<label value="${i18n:_('Worker')}" />
<bandboxSearch id="monthlyTimesheetsBandboxSearch"
finder="ResourceBandboxFinder"
model="@{controller.boundWorkers}"
widthBandbox="200px"
widthListbox="400px" />
</row>
</rows>
</grid>
<button onClick="controller.createOrEditMonthlyTimesheet();"
label="${i18n:_('Go to monthly timesheet')}" />
</popup>
</window>
<window id="createWindow">