[Bug #927] Improve the imputed hours tab in the order element view.

- Sort the imputed hours rows by date.
  - Add a column with the hours type.
  - Group in a row all the hours of the tuple (Resource, Date, Hours type) so
that the hours of a row can be an addition.
  - Fix the height of the area for the hours with a scroll to avoid layout
problems.

FEA : ItEr72S04BugFixing
This commit is contained in:
Susana Montes Pedreira 2011-03-14 12:48:40 +01:00
parent 1552ba8784
commit 936a8c7766
8 changed files with 168 additions and 18 deletions

View file

@ -0,0 +1,87 @@
/*
* This file is part of NavalPlan
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* 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.navalplanner.business.reports.dtos;
import java.util.Date;
import org.joda.time.LocalDate;
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.workreports.entities.WorkReportLine;
/**
* DTO for {@link WorkReportLine} entity.
* @author Susana Montes Pedreira <smonts@wirelessgalicia.com>
*/
public class WorkReportLineDTO {
private Integer sumHours;
private Date date;
private Resource resource;
private TypeOfWorkHours typeOfWorkHours;
public WorkReportLineDTO() {
}
public WorkReportLineDTO(Resource resource,
TypeOfWorkHours typeOfWorkHours, Date date, Long numHours) {
this.setDate(date);
this.setResource(resource);
this.setTypeOfWorkHours(typeOfWorkHours);
this.setSumHours(new Integer(numHours.intValue()));
}
public void setSumHours(Integer numHours) {
this.sumHours = numHours;
}
public Integer getSumHours() {
return sumHours;
}
public void setDate(Date date) {
this.date = date;
}
public Date getDate() {
return date;
}
public void setResource(Resource resource) {
this.resource = resource;
}
public Resource getResource() {
return resource;
}
public void setTypeOfWorkHours(TypeOfWorkHours typeOfWorkHours) {
this.typeOfWorkHours = typeOfWorkHours;
}
public TypeOfWorkHours getTypeOfWorkHours() {
return typeOfWorkHours;
}
public LocalDate getLocalDate() {
return LocalDate.fromDateFields(getDate());
}
}

View file

@ -26,6 +26,7 @@ import java.util.List;
import org.navalplanner.business.common.daos.IIntegrationEntityDAO;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.business.reports.dtos.WorkReportLineDTO;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.workreports.entities.WorkReportLine;
@ -48,4 +49,7 @@ public interface IWorkReportLineDAO extends
List<WorkReportLine> findByResources(List<Resource> resourcesList);
List<WorkReportLineDTO> findByOrderElementGroupByResourceAndHourTypeAndDate(
OrderElement orderElement);
}

View file

@ -27,22 +27,24 @@ import java.util.Date;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;
import org.navalplanner.business.common.daos.IntegrationEntityDAO;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.business.reports.dtos.WorkReportLineDTO;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.workreports.entities.WorkReportLine;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
/**
* Dao for {@link WorkReportLineDAO}
*
* @author Diego Pino García <dpino@igalia.com>
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class WorkReportLineDAO extends IntegrationEntityDAO<WorkReportLine>
@ -56,6 +58,25 @@ public class WorkReportLineDAO extends IntegrationEntityDAO<WorkReportLine>
return (List<WorkReportLine>) c.list();
}
@SuppressWarnings("unchecked")
@Override
public List<WorkReportLineDTO> findByOrderElementGroupByResourceAndHourTypeAndDate(
OrderElement orderElement) {
String strQuery = "SELECT new org.navalplanner.business.reports.dtos.WorkReportLineDTO(wrl.resource, wrl.typeOfWorkHours, wrl.date, SUM(wrl.numHours)) "
+ "FROM WorkReportLine wrl "
+ "LEFT OUTER JOIN wrl.orderElement orderElement "
+ "WHERE orderElement = :orderElement "
+ "GROUP BY wrl.resource, wrl.typeOfWorkHours, wrl.date "
+ "ORDER BY to_char(wrl.date, 'yyyy-mm-dd') , wrl.resource, wrl.typeOfWorkHours";
// Set parameters
Query query = getSession().createQuery(strQuery);
query.setParameter("orderElement", orderElement);
return (List<WorkReportLineDTO>) query.list();
}
@Override
public List<WorkReportLine> findByOrderElementAndChildren(
OrderElement orderElement) {

View file

@ -24,7 +24,7 @@ package org.navalplanner.web.orders;
import java.util.List;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.business.workreports.entities.WorkReportLine;
import org.navalplanner.business.reports.dtos.WorkReportLineDTO;
import org.navalplanner.web.common.Util;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
@ -48,7 +48,7 @@ public class AssignedHoursToOrderElementController extends
comp.setVariable("assignedHoursToOrderElementController", this, true);
}
public List<WorkReportLine> getWorkReportLines() {
public List<WorkReportLineDTO> getWorkReportLines() {
return assignedHoursToOrderElementModel.getWorkReportLines();
}

View file

@ -27,10 +27,11 @@ import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.joda.time.LocalDate;
import org.navalplanner.business.orders.daos.IOrderElementDAO;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.business.reports.dtos.WorkReportLineDTO;
import org.navalplanner.business.workreports.daos.IWorkReportLineDAO;
import org.navalplanner.business.workreports.entities.WorkReportLine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
@ -57,7 +58,7 @@ public class AssignedHoursToOrderElementModel implements
private OrderElement orderElement;
private List<WorkReportLine> listWRL;
private List<WorkReportLineDTO> listWRL;
@Autowired
public AssignedHoursToOrderElementModel(IWorkReportLineDAO workReportLineDAO) {
@ -68,23 +69,58 @@ public class AssignedHoursToOrderElementModel implements
@Override
@Transactional(readOnly = true)
public List<WorkReportLine> getWorkReportLines() {
public List<WorkReportLineDTO> getWorkReportLines() {
if (orderElement == null) {
return new ArrayList<WorkReportLine>();
return new ArrayList<WorkReportLineDTO>();
}
this.assignedDirectHours = 0;
this.listWRL = workReportLineDAO.findByOrderElement(orderElement);
Iterator<WorkReportLine> iterador = listWRL.iterator();
this.listWRL = workReportLineDAO
.findByOrderElementGroupByResourceAndHourTypeAndDate(orderElement);
this.listWRL = groupByDate(listWRL);
Iterator<WorkReportLineDTO> iterador = listWRL.iterator();
while (iterador.hasNext()) {
WorkReportLine w = iterador.next();
WorkReportLineDTO w = iterador.next();
w.getResource().getShortDescription();
w.getOrderElement().getWorkHours();
w.getWorkReport().getDate();
this.assignedDirectHours = this.assignedDirectHours + w.getNumHours();
w.getTypeOfWorkHours().getName();
this.assignedDirectHours = this.assignedDirectHours
+ w.getSumHours();
}
return listWRL;
}
private List<WorkReportLineDTO> groupByDate(
List<WorkReportLineDTO> listWRL) {
List<WorkReportLineDTO> groupedByDateList = new ArrayList<WorkReportLineDTO>();
if (!listWRL.isEmpty()) {
Iterator<WorkReportLineDTO> iterador = listWRL.iterator();
WorkReportLineDTO currentWRL = iterador.next();
groupedByDateList.add(currentWRL);
while (iterador.hasNext()) {
WorkReportLineDTO nextWRL = iterador.next();
LocalDate currentDate = currentWRL.getLocalDate();
LocalDate nextDate = nextWRL.getLocalDate();
if ((currentWRL.getResource().getId().equals(nextWRL
.getResource().getId()))
&& (currentWRL.getTypeOfWorkHours().getId()
.equals(nextWRL.getTypeOfWorkHours().getId()))
&& (currentDate.compareTo(nextDate) == 0)) {
// sum the number of hours to the next WorkReportLineDTO
currentWRL.setSumHours(currentWRL.getSumHours()
+ nextWRL.getSumHours());
} else {
groupedByDateList.add(nextWRL);
currentWRL = nextWRL;
}
}
}
return groupedByDateList;
}
@Override
public int getAssignedDirectHours() {
if (orderElement == null) {

View file

@ -24,13 +24,13 @@ package org.navalplanner.web.orders;
import java.util.List;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.business.workreports.entities.WorkReportLine;
import org.navalplanner.business.reports.dtos.WorkReportLineDTO;
/**
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
public interface IAssignedHoursToOrderElementModel{
public List<WorkReportLine> getWorkReportLines();
public List<WorkReportLineDTO> getWorkReportLines();
public int getAssignedDirectHours();
public int getTotalAssignedHours();
public int getAssignedDirectHoursChildren();

View file

@ -62,7 +62,7 @@
<tabpanel id="tabPanelDetails">
<orderElementDetails id="orderElementDetails" />
</tabpanel>
<tabpanel>
<tabpanel style="overflow:auto">
<listOrderElementHours id="orderElementHours" fulfill="tabAssignedHours.onSelect"/>
</tabpanel>
<tabpanel>

View file

@ -27,10 +27,11 @@
<panelchildren>
<grid
model="@{assignedHoursToOrderElementController.workReportLines}"
mold="paging" pageSize="10">
mold="paging" pageSize="10" fixedLayout="true">
<columns>
<column label="${i18n:_('Date')}" width="120px" />
<column label="${i18n:_('Resource')}" />
<column label="${i18n:_('Hours type')}" />
<column label="${i18n:_('Hours')}" width="100px" />
</columns>
<rows>
@ -39,7 +40,8 @@
value="@{workReportLine.date, converter='org.navalplanner.web.common.typeconverters.DateConverter'}" />
<label
value="@{workReportLine.resource.shortDescription}" />
<label value="@{workReportLine.numHours}" />
<label value="@{workReportLine.typeOfWorkHours.name}" />
<label value="@{workReportLine.sumHours}" />
</row>
</rows>
</grid>