ItEr45S14CUActualizarTraballoExportadoPorSubcontrataItEr44S20: Created a list on the interface to report advances of different subcontracted projects to the customer.

This commit is contained in:
Manuel Rego Casasnovas 2010-01-25 17:23:28 +01:00 committed by Javier Moran Rua
parent 55d8734ec7
commit 4a337e0223
11 changed files with 460 additions and 10 deletions

View file

@ -94,4 +94,6 @@ public interface IOrderElementDAO extends IGenericDAO<OrderElement, Long> {
List<OrderElement> getAll();
public List<OrderElement> findOrderElementsWithExternalCode();
}

View file

@ -232,4 +232,11 @@ public class OrderElementDAO extends GenericDAOHibernate<OrderElement, Long>
return list(OrderElement.class);
}
}
@Override
public List<OrderElement> findOrderElementsWithExternalCode() {
Criteria c = getSession().createCriteria(OrderElement.class);
c.add(Restrictions.isNotNull("externalCode"));
return c.list();
}
}

View file

@ -354,7 +354,7 @@ public abstract class OrderElement extends BaseEntity implements
protected abstract Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments();
protected abstract Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments(
public abstract Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments(
AdvanceType advanceType);
protected abstract Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignmentsReportGlobal();

View file

@ -429,7 +429,7 @@ public class OrderLine extends OrderElement {
return BigDecimal.ZERO;
}
protected Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments(
public Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments(
AdvanceType advanceType) {
Set<DirectAdvanceAssignment> result = new HashSet<DirectAdvanceAssignment>();
for (DirectAdvanceAssignment directAdvanceAssignment : directAdvanceAssignments) {

View file

@ -604,7 +604,7 @@ public class OrderLineGroup extends OrderElement implements
}
@Override
protected Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments(
public Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments(
AdvanceType advanceType) {
Set<DirectAdvanceAssignment> result = new HashSet<DirectAdvanceAssignment>();

View file

@ -198,7 +198,8 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
subItem(_("General resource allocation"),"/planner/index.zul;company_load","01-introducion.html#id1"),
subItem(_("Orders list"), "/planner/index.zul;orders_list","01-introducion.html#id2"),
subItem(_("Templates list"), "/templates/templates.zul", ""),
subItem(_("Subcontracted tasks list"),"/subcontract/subcontractedTasks.zul", ""));
subItem(_("Subcontracted tasks list"), "/subcontract/subcontractedTasks.zul", ""),
subItem(_("Report advances"), "/subcontract/reportAdvances.zul", ""));
topItem(_("Resources"), "/resources/worker/worker.zul", "",
subItem(_("Workers List"), "/resources/worker/worker.zul","05-recursos.html#xesti-n-de-traballadores"),

View file

@ -263,11 +263,7 @@ public class ManageOrderElementAdvancesController extends
.getPossibleAdvanceTypes(advance);
for(AdvanceType advanceType : listAdvanceType){
if (!advanceType.getUnitName().equals(
PredefinedAdvancedTypes.CHILDREN.getTypeName())
&& !advanceType.getUnitName()
.equals(
PredefinedAdvancedTypes.SUBCONTRACTOR
.getTypeName())) {
PredefinedAdvancedTypes.CHILDREN.getTypeName())) {
Comboitem comboItem = new Comboitem();
comboItem.setValue(advanceType);
comboItem.setLabel(advanceType.getUnitName());

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.subcontract;
import java.util.List;
import java.util.Set;
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
import org.navalplanner.business.advance.entities.DirectAdvanceAssignment;
import org.navalplanner.business.orders.entities.Order;
/**
* Contract for {@link ReportAdvancesController}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public interface IReportAdvancesModel {
List<Order> getOrdersWithExternalCodeInAnyOrderElement();
AdvanceMeasurement getLastAdvanceMeasurement(
Set<DirectAdvanceAssignment> allDirectAdvanceAssignments);
AdvanceMeasurement getLastAdvanceMeasurementReported(
Set<DirectAdvanceAssignment> allDirectAdvanceAssignments);
boolean isAnyAdvanceMeasurementNotReported(
Set<DirectAdvanceAssignment> allDirectAdvanceAssignments);
}

View file

@ -0,0 +1,172 @@
/*
* 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.subcontract;
import static org.navalplanner.web.I18nHelper._;
import java.util.List;
import java.util.Set;
import org.navalplanner.business.advance.bootstrap.PredefinedAdvancedTypes;
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
import org.navalplanner.business.advance.entities.DirectAdvanceAssignment;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.orders.entities.Order;
import org.navalplanner.web.common.IMessagesForUser;
import org.navalplanner.web.common.MessagesForUser;
import org.navalplanner.web.common.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Label;
import org.zkoss.zul.Row;
import org.zkoss.zul.RowRenderer;
import org.zkoss.zul.api.Window;
/**
* Controller for operations related with report advances.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@org.springframework.stereotype.Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ReportAdvancesController extends GenericForwardComposer {
private Window window;
private Component messagesContainer;
private IMessagesForUser messagesForUser;
@Autowired
private IReportAdvancesModel reportAdvancesModel;
private ReportAdvancesOrderRenderer reportAdvancesOrderRenderer = new ReportAdvancesOrderRenderer();
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
window = (Window) comp;
window.setVariable("controller", this, true);
messagesForUser = new MessagesForUser(messagesContainer);
}
public List<Order> getOrdersWithExternalCodeInAnyOrderElement() {
return reportAdvancesModel.getOrdersWithExternalCodeInAnyOrderElement();
}
public ReportAdvancesOrderRenderer getReportAdvancesOrderRenderer() {
return reportAdvancesOrderRenderer;
}
private class ReportAdvancesOrderRenderer implements RowRenderer {
@Override
public void render(Row row, Object data) throws Exception {
Order order = (Order) data;
row.setValue(order);
appendLabel(row, order.getCode());
appendLabel(row, toString(order.getCustomerReference()));
appendLabel(row, order.getName());
Set<DirectAdvanceAssignment> allDirectAdvanceAssignments = order
.getAllDirectAdvanceAssignments(PredefinedAdvancedTypes.SUBCONTRACTOR
.getType());
AdvanceMeasurement lastAdvanceMeasurementReported = reportAdvancesModel
.getLastAdvanceMeasurementReported(allDirectAdvanceAssignments);
if (lastAdvanceMeasurementReported != null) {
appendLabel(row, toString(lastAdvanceMeasurementReported.getDate()));
appendLabel(row, toString(lastAdvanceMeasurementReported.getValue()));
} else {
appendLabel(row, "");
appendLabel(row, "");
}
AdvanceMeasurement lastAdvanceMeasurement = reportAdvancesModel
.getLastAdvanceMeasurement(allDirectAdvanceAssignments);
if (lastAdvanceMeasurement != null) {
appendLabel(row, toString(lastAdvanceMeasurement.getDate()));
appendLabel(row, toString(lastAdvanceMeasurement.getValue()));
} else {
appendLabel(row, "");
appendLabel(row, "");
}
if (reportAdvancesModel
.isAnyAdvanceMeasurementNotReported(allDirectAdvanceAssignments)) {
appendLabel(row, _("Pending update"));
appendOperations(row, order, false);
} else {
appendLabel(row, _("Updated"));
appendOperations(row, order, true);
}
}
private String toString(Object object) {
if (object == null) {
return "";
}
return object.toString();
}
private void appendLabel(Row row, String label) {
row.appendChild(new Label(label));
}
private void appendOperations(Row row, Order order,
boolean sendButtonDisabled) {
row.appendChild(getSendButton(order, sendButtonDisabled));
}
private Button getSendButton(final Order order,
boolean sendButtonDisabled) {
Button sendButton = new Button(_("Send"));
sendButton.addEventListener(Events.ON_CLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
try {
// TODO reportAdvancesModel.sendAdvances(order);
} catch (ValidationException e) {
messagesForUser.showInvalidValues(e);
}
Util.reloadBindings(window);
}
});
sendButton.setDisabled(sendButtonDisabled);
return sendButton;
}
}
}

View file

@ -0,0 +1,167 @@
/*
* 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.subcontract;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.navalplanner.business.advance.bootstrap.PredefinedAdvancedTypes;
import org.navalplanner.business.advance.daos.IAdvanceAssignmentDAO;
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
import org.navalplanner.business.advance.entities.DirectAdvanceAssignment;
import org.navalplanner.business.orders.daos.IOrderElementDAO;
import org.navalplanner.business.orders.entities.Order;
import org.navalplanner.business.orders.entities.OrderElement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* Model for operations related with report advances.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ReportAdvancesModel implements IReportAdvancesModel {
private static Log LOG = LogFactory.getLog(ReportAdvancesModel.class);
@Autowired
private IOrderElementDAO orderElementDAO;
@Autowired
private IAdvanceAssignmentDAO advanceAssignmentDAO;
@Override
@Transactional(readOnly = true)
public List<Order> getOrdersWithExternalCodeInAnyOrderElement() {
List<OrderElement> orderElements = orderElementDAO
.findOrderElementsWithExternalCode();
Map<Long, Order> ordersMap = new HashMap<Long, Order>();
for (OrderElement orderElement : orderElements) {
Order order = orderElementDAO
.loadOrderAvoidingProxyFor(orderElement);
if (ordersMap.get(order.getId()) == null) {
ordersMap.put(order.getId(), order);
forceLoadDirectAdvanceAssignments(order);
}
}
return new ArrayList<Order>(ordersMap.values());
}
private void forceLoadDirectAdvanceAssignments(Order order) {
order.getAllDirectAdvanceAssignments(
PredefinedAdvancedTypes.SUBCONTRACTOR.getType()).size();
}
@Override
@Transactional(readOnly = true)
public AdvanceMeasurement getLastAdvanceMeasurement(
Set<DirectAdvanceAssignment> allDirectAdvanceAssignments) {
if (allDirectAdvanceAssignments.isEmpty()) {
return null;
}
Iterator<DirectAdvanceAssignment> iterator = allDirectAdvanceAssignments
.iterator();
DirectAdvanceAssignment advanceAssignment = iterator.next();
advanceAssignmentDAO.reattachUnmodifiedEntity(advanceAssignment);
AdvanceMeasurement lastAdvanceMeasurement = advanceAssignment
.getLastAdvanceMeasurement();
while (iterator.hasNext()) {
advanceAssignment = iterator.next();
advanceAssignmentDAO.reattachUnmodifiedEntity(advanceAssignment);
AdvanceMeasurement advanceMeasurement = advanceAssignment
.getLastAdvanceMeasurement();
if (advanceMeasurement.getDate().compareTo(
lastAdvanceMeasurement.getDate()) > 0) {
lastAdvanceMeasurement = advanceMeasurement;
}
}
return lastAdvanceMeasurement;
}
@Override
@Transactional(readOnly = true)
public AdvanceMeasurement getLastAdvanceMeasurementReported(
Set<DirectAdvanceAssignment> allDirectAdvanceAssignments) {
if (allDirectAdvanceAssignments.isEmpty()) {
return null;
}
AdvanceMeasurement lastAdvanceMeasurementReported = null;
for (DirectAdvanceAssignment advanceAssignment : allDirectAdvanceAssignments) {
advanceAssignmentDAO.reattachUnmodifiedEntity(advanceAssignment);
for (AdvanceMeasurement advanceMeasurement : advanceAssignment.getAdvanceMeasurements()) {
if (advanceMeasurement.getCommunicationDate() != null) {
if (lastAdvanceMeasurementReported == null) {
lastAdvanceMeasurementReported = advanceMeasurement;
} else {
if (advanceMeasurement.getCommunicationDate()
.compareTo(
lastAdvanceMeasurementReported
.getCommunicationDate()) > 0) {
lastAdvanceMeasurementReported = advanceMeasurement;
}
}
}
}
}
return lastAdvanceMeasurementReported;
}
@Override
@Transactional(readOnly = true)
public boolean isAnyAdvanceMeasurementNotReported(
Set<DirectAdvanceAssignment> allDirectAdvanceAssignments) {
if (allDirectAdvanceAssignments.isEmpty()) {
return false;
}
for (DirectAdvanceAssignment advanceAssignment : allDirectAdvanceAssignments) {
advanceAssignmentDAO.reattachUnmodifiedEntity(advanceAssignment);
for (AdvanceMeasurement advanceMeasurement : advanceAssignment.getAdvanceMeasurements()) {
if (advanceMeasurement.getCommunicationDate() == null) {
return true;
}
}
}
return false;
}
}

View file

@ -0,0 +1,57 @@
<!--
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 title="${i18n:_('Subcontracted tasks')}"?>
<?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"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?taglib uri="/WEB-INF/tld/i18n.tld" prefix="i18n"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<div self="@{define(content)}">
<window apply="${reportAdvancesController}"
title="${i18n:_('Report advances')}">
<vbox id="messagesContainer" />
<grid id="listing"
model="@{controller.ordersWithExternalCodeInAnyOrderElement}"
rowRenderer="@{controller.reportAdvancesOrderRenderer}"
mold="paging" pageSize="10" fixedLayout="true">
<columns>
<column label="${i18n:_('Order code')}"/>
<column label="${i18n:_('Customer reference code')}"/>
<column label="${i18n:_('Name')}"/>
<column label="${i18n:_('Date last advance reported')}"/>
<column label="${i18n:_('Value last advance reported')}"/>
<column label="${i18n:_('Date last advance measurement')}"/>
<column label="${i18n:_('Value last advance measurement')}"/>
<column label="${i18n:_('State')}"/>
<column label="${i18n:_('Operations')}" />
</columns>
</grid>
</window>
</div>
</zk>