findIncomingProductionRunsStatusConds.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "PRUN_DOC_PRINTED"));
findIncomingProductionRunsStatusConds.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "PRUN_RUNNING"));
findIncomingProductionRunsStatusConds.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "PRUN_COMPLETED"));
findIncomingProductionRunsConds.add(EntityCondition.makeCondition(findIncomingProductionRunsStatusConds, EntityOperator.OR));
EntityConditionList findIncomingProductionRunsCondition = EntityCondition.makeCondition(findIncomingProductionRunsConds, EntityOperator.AND);
List incomingProductionRuns = delegator.findList("WorkEffortAndGoods", findIncomingProductionRunsCondition, null, UtilMisc.toList("-estimatedCompletionDate"), null, false);
Iterator incomingProductionRunsIter = incomingProductionRuns.iterator();
while (incomingProductionRunsIter.hasNext()) {
GenericValue incomingProductionRun = (GenericValue)incomingProductionRunsIter.next();
double producedQtyTot = 0.0;
if (incomingProductionRun.getString("currentStatusId").equals("PRUN_COMPLETED")) {
List inventoryItems = delegator.findByAnd("WorkEffortAndInventoryProduced", UtilMisc.toMap("productId", productId, "workEffortId", incomingProductionRun.getString("workEffortId")));
Iterator inventoryItemsIter = inventoryItems.iterator();
while (inventoryItemsIter.hasNext()) {
GenericValue inventoryItem = (GenericValue)inventoryItemsIter.next();
GenericValue inventoryItemDetail = EntityUtil.getFirst(delegator.findByAnd("InventoryItemDetail", UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId")), UtilMisc.toList("inventoryItemDetailSeqId")));
if (inventoryItemDetail != null && inventoryItemDetail.get("quantityOnHandDiff") != null) {
Double inventoryItemQty = inventoryItemDetail.getDouble("quantityOnHandDiff");
producedQtyTot = producedQtyTot + inventoryItemQty.doubleValue();
}
}
}
double estimatedQuantity = 0.0;
if (incomingProductionRun.get("estimatedQuantity") != null) {
estimatedQuantity = incomingProductionRun.getDouble("estimatedQuantity").doubleValue();
}
double remainingQuantity = estimatedQuantity - producedQtyTot; // the qty that still needs to be produced
if (remainingQuantity > 0) {
incomingProductionRun.set("estimatedQuantity", new Double(remainingQuantity));
} else {
continue;
}
String weFacilityId = incomingProductionRun.getString("facilityId");
Map quantitySummary = (Map)summaryInByFacility.get(weFacilityId);
if (quantitySummary == null) {
quantitySummary = new HashMap();
quantitySummary.put("facilityId", weFacilityId);
summaryInByFacility.put(weFacilityId, quantitySummary);
}
Double remainingQuantityTot = (Double)quantitySummary.get("estimatedQuantityTotal");
if (remainingQuantityTot == null) {
quantitySummary.put("estimatedQuantityTotal", new Double(remainingQuantity));
} else {
quantitySummary.put("estimatedQuantityTotal", new Double(remainingQuantity + remainingQuantityTot.doubleValue()));
}
List incomingProductionRunList = (List)quantitySummary.get("incomingProductionRunList");
if (incomingProductionRunList == null) {
incomingProductionRunList = new LinkedList();
quantitySummary.put("incomingProductionRunList", incomingProductionRunList);
}
incomingProductionRunList.add(incomingProductionRun);
}
//
// Information about the running production runs that are going
// to consume units of productId by facility.
//
List findOutgoingProductionRunsConds = new LinkedList();
findOutgoingProductionRunsConds.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId));
findOutgoingProductionRunsConds.add(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "WEGS_CREATED"));
findOutgoingProductionRunsConds.add(EntityCondition.makeCondition("workEffortGoodStdTypeId", EntityOperator.EQUALS, "PRUNT_PROD_NEEDED"));
if (facilityId != null) {
findOutgoingProductionRunsConds.add(EntityCondition.makeCondition("facilityId", EntityOperator.EQUALS, facilityId));
}
List findOutgoingProductionRunsStatusConds = new LinkedList();
findOutgoingProductionRunsStatusConds.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "PRUN_CREATED"));
findOutgoingProductionRunsStatusConds.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "PRUN_SCHEDULED"));
findOutgoingProductionRunsStatusConds.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "PRUN_DOC_PRINTED"));
findOutgoingProductionRunsStatusConds.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "PRUN_RUNNING"));
findOutgoingProductionRunsConds.add(EntityCondition.makeCondition(findOutgoingProductionRunsStatusConds, EntityOperator.OR));
EntityConditionList findOutgoingProductionRunsCondition = EntityCondition.makeCondition(findOutgoingProductionRunsConds, EntityOperator.AND);
List outgoingProductionRuns = delegator.findList("WorkEffortAndGoods", findOutgoingProductionRunsCondition, null, UtilMisc.toList("-estimatedStartDate"), null, false);
Iterator outgoingProductionRunsIter = outgoingProductionRuns.iterator();
while (outgoingProductionRunsIter.hasNext()) {
GenericValue outgoingProductionRun = (GenericValue)outgoingProductionRunsIter.next();