public static Map<String, Object> productionRunDeclareAndProduce(DispatchContext ctx, Map<String, ? extends Object> context) {
Map<String, Object> result = FastMap.newInstance();
Delegator delegator = ctx.getDelegator();
LocalDispatcher dispatcher = ctx.getDispatcher();
Locale locale = (Locale) context.get("locale");
GenericValue userLogin = (GenericValue) context.get("userLogin");
// Mandatory input fields
String productionRunId = (String)context.get("workEffortId");
// Optional input fields
BigDecimal quantity = (BigDecimal)context.get("quantity");
Map<GenericPK, Object> componentsLocationMap = UtilGenerics.checkMap(context.get("componentsLocationMap"));
// The production run is loaded
ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher);
BigDecimal quantityProduced = productionRun.getGenericValue().getBigDecimal("quantityProduced");
BigDecimal quantityToProduce = productionRun.getGenericValue().getBigDecimal("quantityToProduce");
if (quantityProduced == null) {
quantityProduced = BigDecimal.ZERO;
}
if (quantityToProduce == null) {
quantityToProduce = BigDecimal.ZERO;
}
BigDecimal minimumQuantityProducedByTask = quantityProduced.add(quantity);
if (minimumQuantityProducedByTask.compareTo(quantityToProduce) > 0) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingQuantityProducedIsHigherThanQuantityDeclared", locale));
}
List<GenericValue> tasks = productionRun.getProductionRunRoutingTasks();
for (int i = 0; i < tasks.size(); i++) {
GenericValue oneTask = tasks.get(i);
String taskId = oneTask.getString("workEffortId");
if ("PRUN_RUNNING".equals(oneTask.getString("currentStatusId"))) {
BigDecimal quantityDeclared = oneTask.getBigDecimal("quantityProduced");
if (quantityDeclared == null) {
quantityDeclared = BigDecimal.ZERO;
}
if (minimumQuantityProducedByTask.compareTo(quantityDeclared) > 0) {
try {