ItEr42S17CUGravacionModelosUnidadesTraballoItEr41S20: Implementing controller and component for material assignment for templates

This commit is contained in:
Óscar González Fernández 2010-01-08 00:18:18 +01:00
parent 0b4f727d86
commit 581150c167
4 changed files with 182 additions and 0 deletions

View file

@ -30,6 +30,14 @@ import org.navalplanner.business.templates.entities.OrderElementTemplate;
*/
public class MaterialAssignmentTemplate extends BaseEntity {
public static MaterialAssignmentTemplate copyFrom(
MaterialAssignmentTemplate assignment) {
MaterialAssignmentTemplate result = new MaterialAssignmentTemplate();
result.materialInfo = assignment.getMaterialInfo().copy();
result.orderElementTemplate = assignment.getOrderElementTemplate();
return BaseEntity.create(result);
}
public static MaterialAssignmentTemplate create() {
return BaseEntity.create(new MaterialAssignmentTemplate());
}

View file

@ -19,6 +19,7 @@
*/
package org.navalplanner.business.templates.entities;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@ -196,4 +197,22 @@ public abstract class OrderElementTemplate extends BaseEntity implements
MaterialAssignmentTemplate materialAssignment) {
materialAssignments.remove(materialAssignment);
}
public BigDecimal getTotalMaterialAssigmentPrice() {
BigDecimal result = BigDecimal.ZERO;
for (MaterialAssignmentTemplate each : materialAssignments) {
result = result.add(each.getTotalPrice());
}
return result;
}
public double getTotalMaterialAssigmentUnits() {
double result = 0;
for (MaterialAssignmentTemplate each : materialAssignments) {
if (each.getUnits() != null) {
result += each.getUnits();
}
}
return result;
}
}

View file

@ -0,0 +1,38 @@
/*
* 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.templates.materials;
import org.navalplanner.web.orders.materials.MaterialAssignmentsComponent;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
*
*/
public class MaterialAssignmentTemplateComponent extends
MaterialAssignmentsComponent {
private TemplateMaterialsController controller = new TemplateMaterialsController();
@Override
public TemplateMaterialsController getController() {
return controller;
}
}

View file

@ -0,0 +1,117 @@
/*
* 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.templates.materials;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialAssignmentTemplate;
import org.navalplanner.business.templates.entities.OrderElementTemplate;
import org.navalplanner.web.orders.materials.AssignedMaterialsController;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.TreeModel;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
*
*/
public class TemplateMaterialsController extends
AssignedMaterialsController<OrderElementTemplate, MaterialAssignmentTemplate> {
private IAssignedMaterialsToOrderElementTemplateModel assignedMaterialsToOrderElementTemplateModel;
@Override
protected MaterialAssignmentTemplate copyFrom(
MaterialAssignmentTemplate assignment) {
return MaterialAssignmentTemplate.copyFrom(assignment);
}
@Override
protected void createAssignmentsBoxComponent(Component parent) {
}
@Override
public TreeModel getAllMaterialCategories() {
return assignedMaterialsToOrderElementTemplateModel
.getAllMaterialCategories();
}
@Override
protected Material getMaterial(MaterialAssignmentTemplate materialAssignment) {
return materialAssignment.getMaterial();
}
@Override
public TreeModel getMaterialCategories() {
return assignedMaterialsToOrderElementTemplateModel
.getMaterialCategories();
}
@Override
protected IAssignedMaterialsToOrderElementTemplateModel getModel() {
return assignedMaterialsToOrderElementTemplateModel;
}
@Override
public BigDecimal getTotalPrice() {
OrderElementTemplate template = assignedMaterialsToOrderElementTemplateModel
.getTemplate();
if (template == null) {
return BigDecimal.ZERO;
}
return template.getTotalMaterialAssigmentPrice().setScale(2,
RoundingMode.HALF_UP);
}
@Override
protected Double getTotalPrice(MaterialAssignmentTemplate materialAssignment) {
return materialAssignment.getTotalPrice().doubleValue();
}
@Override
public double getTotalUnits() {
OrderElementTemplate template = assignedMaterialsToOrderElementTemplateModel
.getTemplate();
if (template == null) {
return 0;
}
return template.getTotalMaterialAssigmentUnits();
}
@Override
protected double getUnits(MaterialAssignmentTemplate assignment) {
if (assignment.getUnits() == null) {
return 0;
}
return assignment.getUnits();
}
@Override
protected void initializeEdition(OrderElementTemplate template) {
assignedMaterialsToOrderElementTemplateModel.initEdit(template);
}
@Override
protected void setUnits(MaterialAssignmentTemplate assignment, double units) {
assignment.setUnits(units);
}
}