result.put("productionRunId", productionRunId);
Iterator<ConfigOption> options = config.getSelectedOptions().iterator();
Map<String, BigDecimal> components = FastMap.newInstance();
while (options.hasNext()) {
ConfigOption co = options.next();
//components.addAll(co.getComponents());
Iterator<GenericValue> selComponents = co.getComponents().iterator();
while (selComponents.hasNext()) {
BigDecimal componentQuantity = null;
GenericValue selComponent = selComponents.next();
if (selComponent.get("quantity") != null) {
componentQuantity = selComponent.getBigDecimal("quantity");
}
if (componentQuantity == null) {
componentQuantity = BigDecimal.ONE;
}
String componentProductId = selComponent.getString("productId");
if (co.isVirtualComponent(selComponent)) {
Map<String, String> componentOptions = co.getComponentOptions();
if (UtilValidate.isNotEmpty(componentOptions) && UtilValidate.isNotEmpty(componentOptions.get(componentProductId))) {
componentProductId = componentOptions.get(componentProductId);
}
}
componentQuantity = quantity.multiply(componentQuantity);
if (components.containsKey(componentProductId)) {
BigDecimal totalQuantity = components.get(componentProductId);
componentQuantity = totalQuantity.add(componentQuantity);
}
// check if a bom exists
List<GenericValue> bomList = null;
try {
bomList = delegator.findByAnd("ProductAssoc",
UtilMisc.toMap("productId", componentProductId, "productAssocTypeId", "MANUF_COMPONENT"));
bomList = EntityUtil.filterByDate(bomList, UtilDateTime.nowTimestamp());
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTryToGetBomListError", locale));
}
// if so create a mandatory predecessor to this production run
if (UtilValidate.isNotEmpty(bomList)) {
serviceContext.clear();
serviceContext.put("productId", componentProductId);
serviceContext.put("quantity", componentQuantity);
serviceContext.put("startDate", UtilDateTime.nowTimestamp());
serviceContext.put("facilityId", facilityId);
serviceContext.put("userLogin", userLogin);
resultService = null;
try {
resultService = dispatcher.runSync("createProductionRunsForProductBom", serviceContext);
GenericValue workEffortPreDecessor = delegator.makeValue("WorkEffortAssoc", UtilMisc.toMap(
"workEffortIdTo", productionRunId, "workEffortIdFrom", resultService.get("productionRunId"),
"workEffortAssocTypeId", "WORK_EFF_PRECEDENCY", "fromDate", UtilDateTime.nowTimestamp()));
workEffortPreDecessor.create();
} catch (GenericServiceException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale));
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTryToCreateWorkEffortAssoc", locale));
}
} else {
components.put(componentProductId, componentQuantity);
}
// create production run notes from comments
String comments = co.getComments();
if (UtilValidate.isNotEmpty(comments)) {
resultService.clear();
serviceContext.clear();
serviceContext.put("workEffortId", productionRunId);
serviceContext.put("internalNote", "Y");
serviceContext.put("noteInfo", comments);
serviceContext.put("noteName", co.getDescription());
serviceContext.put("userLogin", userLogin);
serviceContext.put("noteParty", userLogin.getString("partyId"));
try {
resultService = dispatcher.runSync("createWorkEffortNote", serviceContext);
} catch (GenericServiceException e) {