ItEr39S13RFIntegracionSistemaXeracionInformesItEr38S19: Set up infrastructure for supporting reports (JasperReports) and add report for worked hours per worker.

This commit is contained in:
Javier Moran Rua 2009-12-17 18:21:52 +01:00
parent 4f85c573db
commit df91f31f60
17 changed files with 1016 additions and 1 deletions

View file

@ -0,0 +1,143 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 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 java.util.Set;
import org.navalplanner.business.labels.entities.Label;
import org.navalplanner.business.resources.entities.Worker;
import org.navalplanner.business.workreports.entities.WorkReportLine;
import org.navalplanner.business.workreports.valueobjects.DescriptionValue;
public class HoursWorkedPerWorkerDTO {
private String workerName;
private Date date;
private Date clockStart;
private Date clockFinish;
private Integer numHours;
private String orderElementCode;
private String descriptionValues;
private String labels;
public HoursWorkedPerWorkerDTO(
Worker worker,
WorkReportLine workReportLine) {
this.workerName = worker.getName();
this.date = workReportLine.getDate();
this.clockStart = workReportLine.getClockStart();
this.clockFinish = workReportLine.getClockFinish();
this.numHours = workReportLine.getNumHours();
this.orderElementCode = workReportLine.getOrderElement().getCode();
this.descriptionValues = descriptionValuesAsString(workReportLine.getDescriptionValues());
this.labels = labelsAsString(workReportLine.getLabels());
}
private String labelsAsString(Set<Label> labels) {
String result = "";
for (Label label: labels) {
result = label.getType().getName() + ": " + label.getName() + ", ";
}
return (result.length() > 0) ? result.substring(0, result.length() - 2) : result;
}
private String descriptionValuesAsString(Set<DescriptionValue> descriptionValues) {
String result = "";
for (DescriptionValue descriptionValue: descriptionValues) {
result = descriptionValue.getFieldName() + ": " + descriptionValue.getValue() + ", ";
}
return (result.length() > 0) ? result.substring(0, result.length() - 2) : result;
}
public Integer getNumHours() {
return numHours;
}
public void setNumHours(Integer numHours) {
this.numHours = numHours;
}
public Date getClockStart() {
return clockStart;
}
public void setClockStart(Date clockStart) {
this.clockStart = clockStart;
}
public Date getClockFinish() {
return clockFinish;
}
public void setClockFinish(Date clockFinish) {
this.clockFinish = clockFinish;
}
public String getWorkerName() {
return workerName;
}
public void setWorkerName(String workerName) {
this.workerName = workerName;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getOrderElementCode() {
return orderElementCode;
}
public void setOrderElementCode(String orderElementCode) {
this.orderElementCode = orderElementCode;
}
public String getDescriptionValues() {
return descriptionValues;
}
public void setDescriptionValues(String descriptionValues) {
this.descriptionValues = descriptionValues;
}
public String getLabels() {
return labels;
}
public void setLabels(String labels) {
this.labels = labels;
}
}

View file

@ -20,10 +20,12 @@
package org.navalplanner.business.resources.daos;
import java.util.Date;
import java.util.List;
import org.navalplanner.business.common.daos.IGenericDAO;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.reports.dtos.HoursWorkedPerWorkerDTO;
import org.navalplanner.business.resources.entities.Worker;
import org.springframework.transaction.annotation.Transactional;
@ -66,4 +68,10 @@ public interface IWorkerDAO extends IGenericDAO<Worker, Long> {
*/
@Transactional(readOnly = true)
List<Worker> getWorkers();
/**
*
*/
List<HoursWorkedPerWorkerDTO> getWorkingHoursPerWorker(List<Worker> workers, Date startingDate, Date endingDate);
}

View file

@ -20,16 +20,20 @@
package org.navalplanner.business.resources.daos;
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.GenericDAOHibernate;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.reports.dtos.HoursWorkedPerWorkerDTO;
import org.navalplanner.business.resources.entities.Worker;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
/**
* Hibernate DAO for the <code>Worker</code> entity.
@ -74,4 +78,48 @@ public class WorkerDAO extends GenericDAOHibernate<Worker, Long>
"nif", containsName))).list();
}
@Override
@Transactional(readOnly = true)
public List<HoursWorkedPerWorkerDTO> getWorkingHoursPerWorker(List<Worker> workers, Date startingDate, Date endingDate) {
String strQuery =
"SELECT new org.navalplanner.business.reports.dtos.HoursWorkedPerWorkerDTO(worker, wrl) " +
"FROM Worker worker, WorkReportLine wrl " +
"LEFT OUTER JOIN wrl.resource resource " +
"WHERE resource.id = worker.id ";
// Set date range
if (startingDate != null && endingDate != null) {
strQuery += "AND wrl.date BETWEEN :startingDate AND :endingDate ";
}
if (startingDate != null && endingDate == null) {
strQuery += "AND wrl.date >= :startingDate ";
}
if (startingDate == null && endingDate != null) {
strQuery += "AND wrl.date <= :endingDate ";
}
// Set workers
if (workers != null && !workers.isEmpty()) {
strQuery += "AND worker IN (:workers) ";
}
// Order by
strQuery += "ORDER BY worker.id, wrl.date";
// Set parameters
Query query = getSession().createQuery(strQuery);
if (startingDate != null) {
query.setParameter("startingDate", startingDate);
}
if (endingDate != null) {
query.setParameter("endingDate", endingDate);
}
if (workers != null && !workers.isEmpty()) {
query.setParameterList("workers", workers);
}
// Get result
return query.list();
}
}

View file

@ -37,9 +37,44 @@
</execution>
</executions>
</plugin>
<!-- =========================================================== -->
<!-- Jasper reports configuration -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<configuration>
<sourceDirectory>${project.build.sourceDirectory}/../jasper</sourceDirectory>
<outputDirectory>${project.build.sourceDirectory}/../../../target/classes</outputDirectory>
<xmlValidation>true</xmlValidation>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<dependencies>
<!--note this must be repeated here to pick up correct xml validation -->
<dependency>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>3.7.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Jasper Reports -->
<dependency>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
</dependency>
<!-- Gettext commons -->
<dependency>
<groupId>org.xnap.commons</groupId>

View file

@ -0,0 +1,269 @@
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<style name="Title" isDefault="false" fontName="Arial" fontSize="26" isBold="true" pdfFontName="Helvetica-Bold"/>
<style name="SubTitle" isDefault="false" forecolor="#666666" fontName="Arial" fontSize="18"/>
<style name="Column header" isDefault="false" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
<style name="Detail" isDefault="false" fontName="Arial" fontSize="12"/>
<parameter name="startingDate" class="java.util.Date"/>
<parameter name="endingDate" class="java.util.Date"/>
<field name="workerName" class="java.lang.String"/>
<field name="date" class="java.util.Date"/>
<field name="clockStart" class="java.util.Date"/>
<field name="clockFinish" class="java.util.Date"/>
<field name="numHours" class="java.lang.Integer"/>
<field name="orderElementCode" class="java.lang.String"/>
<field name="descriptionValues" class="java.lang.String"/>
<field name="labels" class="java.lang.String"/>
<variable name="sumHoursPerDay" class="java.lang.Integer" resetType="Group" resetGroup="Data" incrementType="Group" incrementGroup="Data" calculation="Sum">
<variableExpression><![CDATA[$F{numHours}]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
</variable>
<variable name="sumHoursPerWorker" class="java.lang.Integer" resetType="Group" resetGroup="Worker" incrementType="Group" incrementGroup="Worker" calculation="Sum">
<variableExpression><![CDATA[$V{sumHoursPerDay}]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
</variable>
<group name="Group2">
<groupExpression><![CDATA[(int)($V{REPORT_COUNT}/5)]]></groupExpression>
</group>
<group name="Worker">
<groupExpression><![CDATA[$F{workerName}]]></groupExpression>
<groupHeader>
<band height="22">
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="143" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{workerName}]]></textFieldExpression>
</textField>
<line>
<reportElement x="2" y="20" width="553" height="2"/>
</line>
</band>
</groupHeader>
<groupFooter>
<band height="27">
<textField>
<reportElement x="153" y="1" width="30" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{sumHoursPerWorker}]]></textFieldExpression>
</textField>
<line>
<reportElement x="0" y="21" width="553" height="1"/>
</line>
<staticText>
<reportElement x="27" y="1" width="124" height="20"/>
<textElement verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Total hours per worker:]]></text>
</staticText>
</band>
</groupFooter>
</group>
<group name="Data">
<groupExpression><![CDATA[$F{date}]]></groupExpression>
<groupHeader>
<band height="42">
<rectangle>
<reportElement mode="Opaque" x="19" y="21" width="536" height="20" forecolor="#000000" backcolor="#E0E4FB"/>
</rectangle>
<textField pattern="dd/MM/yy" isBlankWhenNull="true">
<reportElement x="16" y="0" width="86" height="20"/>
<textElement>
<font size="11"/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[$F{date}]]></textFieldExpression>
</textField>
<staticText>
<reportElement style="Column header" x="87" y="26" width="66" height="15"/>
<textElement verticalAlignment="Top">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Hora fin]]></text>
</staticText>
<staticText>
<reportElement style="Column header" x="191" y="26" width="85" height="15"/>
<textElement verticalAlignment="Top">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Código pedido]]></text>
</staticText>
<staticText>
<reportElement style="Column header" x="276" y="26" width="135" height="15"/>
<textElement verticalAlignment="Top">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Campos de texto]]></text>
</staticText>
<staticText>
<reportElement style="Column header" x="411" y="26" width="56" height="15"/>
<textElement verticalAlignment="Top">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Etiquetas]]></text>
</staticText>
<staticText>
<reportElement style="Column header" x="22" y="26" width="62" height="15"/>
<textElement verticalAlignment="Top">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Hora inicio]]></text>
</staticText>
<staticText>
<reportElement style="Column header" x="153" y="26" width="30" height="15"/>
<textElement verticalAlignment="Top">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Horas]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band height="26">
<textField>
<reportElement x="153" y="4" width="30" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{sumHoursPerDay}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="45" y="4" width="106" height="20"/>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Total hours per day:]]></text>
</staticText>
<line>
<reportElement x="153" y="3" width="30" height="1"/>
</line>
</band>
</groupFooter>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="120" splitType="Stretch">
<staticText>
<reportElement style="Title" x="0" y="13" width="263" height="33"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Worker report]]></text>
</staticText>
<staticText>
<reportElement style="SubTitle" x="34" y="46" width="240" height="22"/>
<textElement/>
<text><![CDATA[Worked hours per worker]]></text>
</staticText>
<image scaleImage="RealHeight">
<reportElement x="316" y="3" width="237" height="65"/>
<imageExpression class="java.lang.String"><![CDATA["logos/navalpro_logo.gif"]]></imageExpression>
</image>
<staticText>
<reportElement x="0" y="76" width="78" height="20">
<printWhenExpression><![CDATA[new java.lang.Boolean($P{startingDate} != null)]]></printWhenExpression>
</reportElement>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Data comezo:]]></text>
</staticText>
<textField pattern="dd/MM/yyyy" isBlankWhenNull="true">
<reportElement x="78" y="76" width="92" height="20"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression class="java.util.Date"><![CDATA[$P{startingDate}]]></textFieldExpression>
</textField>
<textField pattern="dd/MM/yyyy" isBlankWhenNull="true">
<reportElement x="248" y="76" width="100" height="20"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression class="java.util.Date"><![CDATA[$P{endingDate}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="170" y="76" width="78" height="20">
<printWhenExpression><![CDATA[new java.lang.Boolean($P{endingDate} != null)]]></printWhenExpression>
</reportElement>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Data fin:]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="22" splitType="Stretch">
<textField pattern="h.mm a" isBlankWhenNull="true">
<reportElement x="19" y="0" width="66" height="20"/>
<textElement/>
<textFieldExpression class="java.util.Date"><![CDATA[$F{clockStart}]]></textFieldExpression>
</textField>
<textField pattern="h.mm a" isBlankWhenNull="true">
<reportElement x="84" y="0" width="69" height="20"/>
<textElement/>
<textFieldExpression class="java.util.Date"><![CDATA[$F{clockFinish}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="192" y="0" width="85" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{orderElementCode}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="277" y="0" width="135" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{descriptionValues}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="412" y="0" width="143" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{labels}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="153" y="0" width="30" height="20"/>
<textElement textAlignment="Center"/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{numHours}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="16" splitType="Stretch">
<line>
<reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1"/>
<graphicElement>
<pen lineWidth="0.5" lineColor="#999999"/>
</graphicElement>
</line>
</band>
</columnFooter>
<pageFooter>
<band height="20" splitType="Stretch">
<textField>
<reportElement style="Column header" x="433" y="0" width="80" height="20"/>
<textElement textAlignment="Right">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement style="Column header" x="513" y="0" width="40" height="20"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement style="Column header" x="0" y="0" width="197" height="20"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>

View file

@ -241,7 +241,9 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
"02-criterios.html#id1"));
}
topItem(_("Quality management"), "/", "", true);
topItem(_("Reports"), "", "",
subItem(_("Worker report"),
"/reports/worker_report.zul", ""));
}
private Vbox getRegisteredItemsInsertionPoint() {

View file

@ -0,0 +1,48 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 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.web.reports;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;
public class ComboboxOutputFormat extends HtmlMacroComponent {
private static final long serialVersionUID = 1L;
public String getOutputFormat() {
return getSelectedItem().getLabel().toLowerCase();
}
private Comboitem getSelectedItem() {
final Comboitem item = getCombobox().getSelectedItem();
return (item != null) ? item : getDefaultItem();
}
private Combobox getCombobox() {
return (Combobox) this.getFellowIfAny("combobox");
}
private Comboitem getDefaultItem() {
return getCombobox().getItemAtIndex(0);
}
}

View file

@ -0,0 +1,109 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 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.web.reports;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.sf.jasperreports.engine.JRDataSource;
import org.navalplanner.business.resources.entities.Worker;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkex.zul.Jasperreport;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
/**
*
* @author Diego Pino Garcia <dpino@igalia.com>
*
*/
public class HoursWorkedPerWorkerController extends GenericForwardComposer {
private IHoursWorkedPerWorkerModel hoursWorkedPerWorkerModel;
private HoursWorkedPerWorkerReport workerReport;
private Listbox lbWorkers;
private Datebox startingDate;
private Datebox endingDate;
private ComboboxOutputFormat outputFormat;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
comp.setVariable("controller", this, true);
}
public List<Worker> getWorkers() {
return hoursWorkedPerWorkerModel.getWorkers();
}
public void showReport(Jasperreport report) {
final String type = outputFormat.getOutputFormat();
workerReport = new HoursWorkedPerWorkerReport(report);
workerReport.setDatasource(getDataSource());
workerReport.setParameters(getParameters());
workerReport.show(type);
}
private JRDataSource getDataSource() {
return hoursWorkedPerWorkerModel.getWorkerReport(getSelectedWorkers(), getStartingDate(), getEndingDate());
}
private Map<String, Object> getParameters() {
Map<String, Object> result = new HashMap<String, Object>();
result.put("startingDate", getStartingDate());
result.put("endingDate", getEndingDate());
return result;
}
private List<Worker> getSelectedWorkers() {
List<Worker> result = new ArrayList<Worker>();
final Set<Listitem> listItems = lbWorkers.getSelectedItems();
for (Listitem each: listItems) {
result.add((Worker) each.getValue());
}
return result;
}
private Date getStartingDate() {
return startingDate.getValue();
}
private Date getEndingDate() {
return endingDate.getValue();
}
}

View file

@ -0,0 +1,67 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 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.web.reports;
import java.util.Date;
import java.util.List;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.navalplanner.business.reports.dtos.HoursWorkedPerWorkerDTO;
import org.navalplanner.business.resources.daos.IWorkerDAO;
import org.navalplanner.business.resources.entities.Worker;
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;
import org.springframework.transaction.annotation.Transactional;
/**
* Diego Pino Garcia <dpino@igalia.com>
*
*/
@Service
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class HoursWorkedPerWorkerModel implements IHoursWorkedPerWorkerModel {
@Autowired
private IWorkerDAO workerDAO;
@Transactional(readOnly = true)
public JRDataSource getWorkerReport(List<Worker> workers, Date startingDate, Date endingDate) {
final List<HoursWorkedPerWorkerDTO> workingHoursPerWorkerList = workerDAO.getWorkingHoursPerWorker(workers, startingDate, endingDate);
if (workingHoursPerWorkerList != null && !workingHoursPerWorkerList.isEmpty()) {
return new JRBeanCollectionDataSource(workingHoursPerWorkerList);
} else {
return new JREmptyDataSource();
}
}
@Override
@Transactional(readOnly = true)
public List<Worker> getWorkers() {
return workerDAO.getWorkers();
}
}

View file

@ -0,0 +1,33 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 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.web.reports;
import org.zkoss.zkex.zul.Jasperreport;
public class HoursWorkedPerWorkerReport extends NavalplannerReport {
public HoursWorkedPerWorkerReport(Jasperreport report) {
report.setSrc("worker_report.jasper");
setReport(report);
}
}

View file

@ -0,0 +1,21 @@
package org.navalplanner.web.reports;
import java.util.Date;
import java.util.List;
import net.sf.jasperreports.engine.JRDataSource;
import org.navalplanner.business.resources.entities.Worker;
/**
*
* @author Diego Pino Garcia <dpino@igalia.com>
*
*/
public interface IHoursWorkedPerWorkerModel {
JRDataSource getWorkerReport(List<Worker> workers, Date startingDate, Date endingDate);
List<Worker> getWorkers();
}

View file

@ -0,0 +1,28 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 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.web.reports;
public interface INavalplannerReport {
void show(String type);
}

View file

@ -0,0 +1,54 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 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.web.reports;
import java.util.Map;
import net.sf.jasperreports.engine.JRDataSource;
import org.zkoss.zkex.zul.Jasperreport;
public abstract class NavalplannerReport implements INavalplannerReport {
private Jasperreport report;
public Jasperreport getReport() {
return report;
}
public void setReport(Jasperreport report) {
this.report = report;
}
@Override
public void show(String type) {
this.report.setType(type);
}
public void setParameters(Map parameters) {
report.setParameters(parameters);
}
public void setDatasource(JRDataSource dataSource) {
report.setDatasource(dataSource);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View file

@ -0,0 +1,32 @@
<!--
This file is part of ###PROJECT_NAME###
Copyright (C) 2009 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/>.
-->
<vbox>
<combobox id="combobox"
value="HTML"
autocomplete="true"
autodrop="true" >
<comboitem label="HTML"/>
<comboitem label="ODT"/>
<comboitem label="PDF"/>
</combobox>
</vbox>

View file

@ -0,0 +1,112 @@
<!--
This file is part of ###PROJECT_NAME###
Copyright (C) 2009 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/>.
-->
<?page id="reports"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?init class="org.zkoss.zk.ui.util.Composition" arg0="/common/layout/template.zul"?>
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_v01.css"?>
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_zk.css"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?component name="combobox_output_format" macroURI="combobox_output_format.zul"
class="org.navalplanner.web.reports.ComboboxOutputFormat" ?>
<zk>
<window self="@{define(content)}"
apply="org.navalplanner.web.reports.HoursWorkedPerWorkerController"
title="Hours worked per worker"
border="normal" >
<!-- Select output format -->
<panel title="${i18n:_('Dates')}" border="normal"
style="overflow:auto">
<panelchildren>
<grid width="600px">
<columns>
<column width="200px" />
<column />
</columns>
<rows>
<row>
<label value="${i18n:_('Start date:')}" />
<datebox id="startingDate" />
</row>
<row>
<label value="${i18n:_('End date:')}" />
<datebox id="endingDate" />
</row>
</rows>
</grid>
</panelchildren>
</panel>
<!-- Select output format -->
<panel title="${i18n:_('Workers')}"
border="normal"
style="overflow:auto">
<panelchildren>
<listbox id="lbWorkers"
width="600px"
multiple="true"
model="@{controller.workers}">
<listhead>
<listheader label="${i18n:_('NIF')}" sort="auto(nif)" />
<listheader label="${i18n:_('Name')}" sort="auto(name)" />
</listhead>
<listitem self="@{each='worker'}" value="@{worker}">
<listcell label="@{worker.nif}" />
<listcell label="@{worker.name}" />
</listitem>
</listbox>
</panelchildren>
</panel>
<!-- Select output format -->
<panel title="${i18n:_('Format')}" border="normal"
style="overflow:auto">
<panelchildren>
<grid width="600px">
<columns>
<column width="200px" />
<column />
</columns>
<rows>
<row>
<label value="${i18n:_('Output format:')}" />
<combobox_output_format id="outputFormat" />
</row>
</rows>
</grid>
</panelchildren>
</panel>
<separator spacing="10px" orient="horizontal"/>
<button label="Show" onClick="controller.showReport(report)" />
<jasperreport id="report" />
</window>
</zk>

View file

@ -194,6 +194,12 @@
<!-- Dependency management -->
<dependencyManagement>
<dependencies>
<!-- Jasper Reports -->
<dependency>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>3.7.0</version>
</dependency>
<!-- Gettext commons -->
<dependency>
<groupId>org.xnap.commons</groupId>