From 4da11d0f1973f8ac180bfa89e00db81cf6708080 Mon Sep 17 00:00:00 2001 From: Susana Montes Pedreira Date: Mon, 7 May 2012 08:08:59 +0100 Subject: [PATCH] Modify the Project cost report to include a new area called Expenses, per OrderElement. FEA: ItEr76S24AdapatingProjectsToExpenses --- .../business/orders/daos/IOrderDAO.java | 4 + .../business/orders/daos/OrderDAO.java | 55 ++++ .../reports/dtos/CostExpenseSheetDTO.java | 114 +++++++ .../reports/dtos/CostWorkReportLineDTO.java | 245 +++++++++++++++ .../reports/dtos/OrderCostMasterDTO.java | 131 ++++++++ .../dtos/OrderCostsPerResourceDTO.java | 40 ++- .../dtos/ReportPerOrderElementDTO.java | 45 +++ .../src/main/jasper/Bundle.properties | 3 + .../jasper/costExpenseSheetLinesReport.jrxml | 149 +++++++++ .../jasper/costWorkReportLinesReport.jrxml | 238 ++++++++++++++ .../jasper/orderCostsPerResourceReport.jrxml | 295 +++++------------- .../orderCostsPerResource.properties | 11 + .../orderCostsPerResource_es.properties | 11 + .../web/common/CustomMenuController.java | 2 +- .../web/expensesheet/ExpenseSheetModel.java | 4 - .../reports/IOrderCostsPerResourceModel.java | 1 + .../OrderCostsPerResourceController.java | 3 +- .../reports/OrderCostsPerResourceModel.java | 191 +++++++++--- 18 files changed, 1259 insertions(+), 283 deletions(-) create mode 100644 libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CostExpenseSheetDTO.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CostWorkReportLineDTO.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/reports/dtos/OrderCostMasterDTO.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/reports/dtos/ReportPerOrderElementDTO.java create mode 100644 libreplan-webapp/src/main/jasper/Bundle.properties create mode 100644 libreplan-webapp/src/main/jasper/costExpenseSheetLinesReport.jrxml create mode 100644 libreplan-webapp/src/main/jasper/costWorkReportLinesReport.jrxml diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/daos/IOrderDAO.java b/libreplan-business/src/main/java/org/libreplan/business/orders/daos/IOrderDAO.java index 5aad81fb4..2c13f19cf 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/daos/IOrderDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/daos/IOrderDAO.java @@ -29,6 +29,7 @@ import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.orders.entities.Order; import org.libreplan.business.orders.entities.OrderElement; import org.libreplan.business.planner.entities.Task; +import org.libreplan.business.reports.dtos.CostExpenseSheetDTO; import org.libreplan.business.reports.dtos.OrderCostsPerResourceDTO; import org.libreplan.business.resources.entities.Criterion; import org.libreplan.business.scenarios.entities.Scenario; @@ -101,4 +102,7 @@ public interface IOrderDAO extends IIntegrationEntityDAO { boolean existsByNameAnotherTransaction(String name); List getActiveOrders(); + + List getCostExpenseSheet(List orders, Date startingDate, + Date endingDate, List criterions); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/daos/OrderDAO.java b/libreplan-business/src/main/java/org/libreplan/business/orders/daos/OrderDAO.java index ef9b23688..8fe22ce53 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/daos/OrderDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/daos/OrderDAO.java @@ -43,6 +43,7 @@ import org.libreplan.business.orders.entities.OrderElement; import org.libreplan.business.orders.entities.OrderStatusEnum; import org.libreplan.business.planner.daos.ITaskSourceDAO; import org.libreplan.business.planner.entities.Task; +import org.libreplan.business.reports.dtos.CostExpenseSheetDTO; import org.libreplan.business.reports.dtos.OrderCostsPerResourceDTO; import org.libreplan.business.resources.entities.Criterion; import org.libreplan.business.scenarios.entities.Scenario; @@ -57,6 +58,7 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; + /** * Dao for {@link Order} * @@ -161,6 +163,7 @@ public class OrderDAO extends IntegrationEntityDAO implements // Attach ordername value each.setOrderName(order.getName()); + each.setOrderCode(order.getCode()); // Attach calculated pricePerHour BigDecimal pricePerHour = CostCategoryDAO .getPriceByResourceDateAndHourType(each.getWorker(), @@ -423,4 +426,56 @@ public class OrderDAO extends IntegrationEntityDAO implements return criteria.list(); } + @Override + public List getCostExpenseSheet(List orders, Date startingDate, + Date endingDate, List criterions) { + + String strQuery = "SELECT new org.libreplan.business.reports.dtos.CostExpenseSheetDTO(expense) " + + "FROM OrderElement orderElement, ExpenseSheetLine expense " + + "LEFT OUTER JOIN expense.orderElement exp_ord " + + "WHERE orderElement.id = exp_ord.id "; + + if (!orders.isEmpty()) { + strQuery += "AND orderElement.parent IN (:orders) "; + } + 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 "; + } + + // Order by date + strQuery += "ORDER BY expense.date"; + + Query query = getSession().createQuery(strQuery); + + // Set parameters + if (!orders.isEmpty()) { + query.setParameterList("orders", orders); + } + if (startingDate != null) { + query.setParameter("startingDate", startingDate); + } + if (endingDate != null) { + query.setParameter("endingDate", endingDate); + } + + List list = query.list(); + + List filteredList = new ArrayList(); + for (CostExpenseSheetDTO each : list) { + Order order = loadOrderAvoidingProxyFor(each.getOrderElement()); + // Apply filtering + if (matchFilterCriterion(each.getOrderElement(), criterions)) { + each.setOrder(order); + filteredList.add(each); + } + } + return filteredList; + } + } diff --git a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CostExpenseSheetDTO.java b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CostExpenseSheetDTO.java new file mode 100644 index 000000000..133b1391c --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CostExpenseSheetDTO.java @@ -0,0 +1,114 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 WirelessGalcia 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 . + */ + +package org.libreplan.business.reports.dtos; + +import java.math.BigDecimal; +import java.util.Date; + +import org.libreplan.business.expensesheet.entities.ExpenseSheetLine; +import org.libreplan.business.orders.entities.Order; + +/** + * Note: this class has a natural ordering that is inconsistent with equals. + */ + +/** + * @author Susana Montes Pedreira + */ +public class CostExpenseSheetDTO extends ReportPerOrderElementDTO implements + Comparable { + + private Date date; + private String concept; + private String resource; + private BigDecimal value; + private String orderElementCode; + private Order order; + + public CostExpenseSheetDTO(ExpenseSheetLine bean) { + super(bean.getOrderElement()); + this.date = bean.getDate().toDateTimeAtStartOfDay().toDate(); + this.concept = bean.getConcept(); + if (bean.getResource() != null) { + this.resource = bean.getResource().getShortDescription(); + } + this.value = bean.getValue(); + this.setOrderElementCode(bean.getOrderElement().getCode()); + } + + public void setConcept(String concept) { + this.concept = concept; + } + + public String getConcept() { + return concept; + } + + public void setResource(String resource) { + this.resource = resource; + } + + public String getResource() { + return resource; + } + + public void setDate(Date date) { + this.date = date; + } + + public Date getDate() { + return date; + } + + public void setValue(BigDecimal value) { + this.value = value; + } + + public BigDecimal getValue() { + return value; + } + + @Override + public int compareTo(CostExpenseSheetDTO o) { + if (date == null) { + return -1; + } + if (o.getDate() == null) { + return 1; + } + return date.compareTo(o.getDate()); + } + + public void setOrder(Order order) { + this.order = order; + } + + public Order getOrder() { + return order; + } + + public void setOrderElementCode(String orderElementCode) { + this.orderElementCode = orderElementCode; + } + + public String getOrderElementCode() { + return orderElementCode; + } +} \ No newline at end of file diff --git a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CostWorkReportLineDTO.java b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CostWorkReportLineDTO.java new file mode 100644 index 000000000..033d9ec5a --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CostWorkReportLineDTO.java @@ -0,0 +1,245 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 WirelessGalcia 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 . + */ + +package org.libreplan.business.reports.dtos; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.Set; + +import org.joda.time.LocalTime; +import org.libreplan.business.labels.entities.Label; +import org.libreplan.business.orders.entities.OrderElement; +import org.libreplan.business.resources.entities.Worker; +import org.libreplan.business.workreports.entities.WorkReportLine; +import org.libreplan.business.workreports.valueobjects.DescriptionValue; + +/** + * Note: this class has a natural ordering that is inconsistent with equals. + */ + +/** + * @author Susana Montes Pedreira + */ +public class CostWorkReportLineDTO implements Comparable { + + private OrderElement orderElement; + + private String workerName; + + private Date date; + + private LocalTime clockStart; + + private LocalTime clockFinish; + + private BigDecimal numHours; + + private String descriptionValues; + + private String labels; + + private String hoursType; + + private String hoursTypeCode; + + // Attached outside the DTO + private BigDecimal cost; + + // Attached outside the DTO + private BigDecimal costPerHour; + + private Worker worker; + + private Boolean costTypeHours = Boolean.TRUE; + + public CostWorkReportLineDTO(Worker worker, WorkReportLine workReportLine) { + + this.workerName = worker.getName(); + if (workReportLine.getLocalDate() != null) { + this.date = workReportLine.getLocalDate().toDateTimeAtStartOfDay().toDate(); + } + this.clockStart = workReportLine.getClockStart(); + this.clockFinish = workReportLine.getClockFinish(); + this.numHours = workReportLine.getEffort().toHoursAsDecimalWithScale(2); + this.descriptionValues = descriptionValuesAsString(workReportLine.getDescriptionValues()); + this.labels = labelsAsString(workReportLine.getLabels()); + this.hoursType = workReportLine.getTypeOfWorkHours().getName(); + this.hoursTypeCode = workReportLine.getTypeOfWorkHours().getCode(); + this.worker = worker; + } + + public CostWorkReportLineDTO(OrderCostsPerResourceDTO dto) { + this.workerName = dto.getWorkerName(); + this.date = dto.getDate(); + this.clockStart = dto.getClockStart(); + this.clockFinish = dto.getClockFinish(); + this.numHours = dto.getNumHours(); + this.descriptionValues = dto.getDescriptionValues(); + this.labels = dto.getLabels(); + this.hoursType = dto.getHoursType(); + this.hoursTypeCode = dto.getHoursTypeCode(); + this.worker = dto.getWorker(); + } + + private String labelsAsString(Set