1 25 package org.ofbiz.workeffort.workeffort; 26 27 import java.sql.Timestamp ; 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.HashMap ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.LinkedList ; 34 import java.util.List ; 35 import java.util.Map ; 36 import java.util.Set ; 37 38 import org.ofbiz.base.util.Debug; 39 import org.ofbiz.base.util.UtilDateTime; 40 import org.ofbiz.base.util.UtilMisc; 41 import org.ofbiz.base.util.UtilValidate; 42 import org.ofbiz.entity.GenericDelegator; 43 import org.ofbiz.entity.GenericEntityException; 44 import org.ofbiz.entity.GenericValue; 45 import org.ofbiz.entity.condition.EntityExpr; 46 import org.ofbiz.entity.condition.EntityCondition; 47 import org.ofbiz.entity.condition.EntityConditionList; 48 import org.ofbiz.entity.condition.EntityJoinOperator; 49 import org.ofbiz.entity.condition.EntityOperator; 50 import org.ofbiz.entity.util.EntityUtil; 51 import org.ofbiz.security.Security; 52 import org.ofbiz.service.DispatchContext; 53 import org.ofbiz.service.ServiceUtil; 54 55 63 public class WorkEffortServices { 64 65 public static final String module = WorkEffortServices.class.getName(); 66 67 public static Map getWorkEffortAssignedTasks(DispatchContext ctx, Map context) { 68 GenericDelegator delegator = ctx.getDelegator(); 69 GenericValue userLogin = (GenericValue) context.get("userLogin"); 70 71 List validWorkEfforts = null; 72 73 if (userLogin != null && userLogin.get("partyId") != null) { 74 try { 75 validWorkEfforts = delegator.findByAnd("WorkEffortAndPartyAssign", 76 UtilMisc.toList(new EntityExpr("partyId", EntityOperator.EQUALS, userLogin.get("partyId")), 77 new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "TASK"), 78 new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"), 79 new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"), 80 new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"), 81 new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED")), 82 UtilMisc.toList("priority")); 83 } catch (GenericEntityException e) { 84 Debug.logWarning(e, module); 85 return ServiceUtil.returnError("Error finding desired WorkEffort records: " + e.toString()); 86 } 87 } 88 89 Map result = new HashMap (); 90 if (validWorkEfforts == null) validWorkEfforts = new LinkedList (); 91 result.put("tasks", validWorkEfforts); 92 return result; 93 } 94 95 public static Map getWorkEffortAssignedActivities(DispatchContext ctx, Map context) { 96 GenericDelegator delegator = ctx.getDelegator(); 97 GenericValue userLogin = (GenericValue) context.get("userLogin"); 98 99 List validWorkEfforts = null; 100 101 if (userLogin != null && userLogin.get("partyId") != null) { 102 try { 103 List constraints = new LinkedList (); 104 105 constraints.add(new EntityExpr("partyId", EntityOperator.EQUALS, userLogin.get("partyId"))); 106 constraints.add(new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "ACTIVITY")); 107 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED")); 108 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED")); 109 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED")); 110 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED")); 111 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_COMPLETED")); 112 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_TERMINATED")); 113 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_ABORTED")); 114 validWorkEfforts = delegator.findByAnd("WorkEffortAndPartyAssign", constraints, UtilMisc.toList("priority")); 115 } catch (GenericEntityException e) { 116 Debug.logWarning(e, module); 117 return ServiceUtil.returnError("Error finding desired WorkEffort records: " + e.toString()); 118 } 119 } 120 121 Map result = new HashMap (); 122 if (validWorkEfforts == null) validWorkEfforts = new LinkedList (); 123 result.put("activities", validWorkEfforts); 124 return result; 125 } 126 127 public static Map getWorkEffortAssignedActivitiesByRole(DispatchContext ctx, Map context) { 128 GenericDelegator delegator = ctx.getDelegator(); 129 GenericValue userLogin = (GenericValue) context.get("userLogin"); 130 131 List roleWorkEfforts = null; 132 133 if (userLogin != null && userLogin.get("partyId") != null) { 134 try { 135 List constraints = new LinkedList (); 136 137 constraints.add(new EntityExpr("partyId", EntityOperator.EQUALS, userLogin.get("partyId"))); 138 constraints.add(new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "ACTIVITY")); 139 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED")); 140 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED")); 141 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED")); 142 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED")); 143 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_COMPLETED")); 144 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_TERMINATED")); 145 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_ABORTED")); 146 roleWorkEfforts = delegator.findByAnd("WorkEffortPartyAssignByRole", constraints, UtilMisc.toList("priority")); 147 } catch (GenericEntityException e) { 148 Debug.logWarning(e, module); 149 return ServiceUtil.returnError("Error finding desired WorkEffort records: " + e.toString()); 150 } 151 } 152 153 Map result = new HashMap (); 154 if (roleWorkEfforts == null) roleWorkEfforts = new LinkedList (); 155 result.put("roleActivities", roleWorkEfforts); 156 return result; 157 } 158 159 public static Map getWorkEffortAssignedActivitiesByGroup(DispatchContext ctx, Map context) { 160 GenericDelegator delegator = ctx.getDelegator(); 161 GenericValue userLogin = (GenericValue) context.get("userLogin"); 162 163 List groupWorkEfforts = null; 164 165 if (userLogin != null && userLogin.get("partyId") != null) { 166 try { 167 List constraints = new LinkedList (); 168 169 constraints.add(new EntityExpr("partyId", EntityOperator.EQUALS, userLogin.get("partyId"))); 170 constraints.add(new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "ACTIVITY")); 171 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED")); 172 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED")); 173 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED")); 174 constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED")); 175 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_COMPLETED")); 176 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_TERMINATED")); 177 constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_ABORTED")); 178 groupWorkEfforts = delegator.findByAnd("WorkEffortPartyAssignByGroup", constraints, UtilMisc.toList("priority")); 179 } catch (GenericEntityException e) { 180 Debug.logWarning(e, module); 181 return ServiceUtil.returnError("Error finding desired WorkEffort records: " + e.toString()); 182 } 183 } 184 185 Map result = new HashMap (); 186 if (groupWorkEfforts == null) groupWorkEfforts = new LinkedList (); 187 result.put("groupActivities", groupWorkEfforts); 188 return result; 189 } 190 191 public static Map getWorkEffort(DispatchContext ctx, Map context) { 192 GenericDelegator delegator = ctx.getDelegator(); 193 GenericValue userLogin = (GenericValue) context.get("userLogin"); 194 Security security = ctx.getSecurity(); 195 Map resultMap = new HashMap (); 196 197 String workEffortId = (String ) context.get("workEffortId"); 198 GenericValue workEffort = null; 199 200 try { 201 workEffort = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId)); 202 } catch (GenericEntityException e) { 203 Debug.logWarning(e, module); 204 } 205 206 Boolean canView = null; 207 Collection workEffortPartyAssignments = null; 208 Boolean tryEntity = null; 209 GenericValue currentStatus = null; 210 211 if (workEffort == null) { 212 tryEntity = new Boolean (false); 213 canView = new Boolean (true); 214 215 String statusId = (String ) context.get("currentStatusId"); 216 217 if (statusId != null && statusId.length() > 0) { 218 try { 219 currentStatus = delegator.findByPrimaryKeyCache("StatusItem", UtilMisc.toMap("statusId", statusId)); 220 } catch (GenericEntityException e) { 221 Debug.logWarning(e, module); 222 } 223 } 224 } else { 225 if (userLogin != null && userLogin.get("partyId") != null && workEffortId != null) { 227 try { 228 workEffortPartyAssignments = delegator.findByAnd("WorkEffortPartyAssignment", UtilMisc.toMap("workEffortId", workEffortId, "partyId", userLogin.get("partyId"))); 229 } catch (GenericEntityException e) { 230 Debug.logWarning(e, module); 231 } 232 } 233 canView = (workEffortPartyAssignments != null && workEffortPartyAssignments.size() > 0) ? Boolean.TRUE : Boolean.FALSE; 234 if (!canView.booleanValue() && security.hasEntityPermission("WORKEFFORTMGR", "_VIEW", userLogin)) { 235 canView = new Boolean (true); 236 } 237 238 tryEntity = new Boolean (true); 239 240 if (workEffort.get("currentStatusId") != null) { 241 try { 242 currentStatus = delegator.findByPrimaryKeyCache("StatusItem", UtilMisc.toMap("statusId", workEffort.get("currentStatusId"))); 243 } catch (GenericEntityException e) { 244 Debug.logWarning(e, module); 245 } 246 } 247 } 248 249 if (workEffortId != null) resultMap.put("workEffortId", workEffortId); 250 if (workEffort != null) resultMap.put("workEffort", workEffort); 251 if (canView != null) resultMap.put("canView", canView); 252 if (workEffortPartyAssignments != null) resultMap.put("partyAssigns", workEffortPartyAssignments); 253 if (tryEntity != null) resultMap.put("tryEntity", tryEntity); 254 if (currentStatus != null) resultMap.put("currentStatusItem", currentStatus); 255 return resultMap; 256 } 257 258 private static List getWorkEffortEvents(DispatchContext ctx, Timestamp startStamp, Timestamp endStamp, String partyId, String facilityId, String fixedAssetId) { 259 GenericDelegator delegator = ctx.getDelegator(); 260 List validWorkEfforts = new ArrayList (); 261 try { 262 List entityExprList = UtilMisc.toList( 263 new EntityExpr("estimatedCompletionDate", EntityOperator.GREATER_THAN_EQUAL_TO, startStamp), 264 new EntityExpr("estimatedStartDate", EntityOperator.LESS_THAN, endStamp)); 265 List typesList = UtilMisc.toList(new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "EVENT")); 266 if (UtilValidate.isNotEmpty(partyId)) { 267 entityExprList.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId)); 268 } 269 if (UtilValidate.isNotEmpty(facilityId)) { 270 entityExprList.add(new EntityExpr("facilityId", EntityOperator.EQUALS, facilityId)); 271 typesList.add(new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "PROD_ORDER_HEADER")); 272 } 273 if (UtilValidate.isNotEmpty(fixedAssetId)) { 274 entityExprList.add(new EntityExpr("fixedAssetId", EntityOperator.EQUALS, fixedAssetId)); 275 typesList.add(new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "PROD_ORDER_TASK")); 276 } 277 EntityCondition typesCondition = null; 278 if (typesList.size() == 1) { 279 typesCondition = (EntityExpr)typesList.get(0); 280 } else { 281 typesCondition = new EntityConditionList(typesList, EntityJoinOperator.OR); 282 } 283 entityExprList.add(typesCondition); 284 285 List tempWorkEfforts = null; 286 if (UtilValidate.isNotEmpty(partyId)) { 287 tempWorkEfforts = delegator.findByAnd("WorkEffortAndPartyAssign", entityExprList, UtilMisc.toList("estimatedStartDate")); 288 } else { 289 tempWorkEfforts = delegator.findByAnd("WorkEffort", entityExprList, UtilMisc.toList("estimatedStartDate")); 290 } 291 292 Set tempWeKeys = new HashSet (); 298 Iterator tempWorkEffortIter = tempWorkEfforts.iterator(); 299 while (tempWorkEffortIter.hasNext()) { 300 GenericValue tempWorkEffort = (GenericValue) tempWorkEffortIter.next(); 301 String tempWorkEffortId = tempWorkEffort.getString("workEffortId"); 302 if (tempWeKeys.contains(tempWorkEffortId)) { 303 tempWorkEffortIter.remove(); 304 } else { 305 tempWeKeys.add(tempWorkEffortId); 306 } 307 } 308 309 validWorkEfforts = new ArrayList (tempWorkEfforts); 310 } catch (GenericEntityException e) { 311 Debug.logWarning(e, module); 312 } 313 return validWorkEfforts; 314 } 315 316 public static Map getWorkEffortEventsByPeriod(DispatchContext ctx, Map context) { 317 GenericDelegator delegator = ctx.getDelegator(); 318 Security security = ctx.getSecurity(); 319 GenericValue userLogin = (GenericValue) context.get("userLogin"); 320 Map resultMap = new HashMap (); 321 322 Timestamp startDay = (Timestamp ) context.get("start"); 323 Integer numPeriodsInteger = (Integer ) context.get("numPeriods"); 324 Integer periodInteger = (Integer ) context.get("periodSeconds"); 325 326 String partyId = (String ) context.get("partyId"); 327 String facilityId = (String ) context.get("facilityId"); 328 String fixedAssetId = (String ) context.get("fixedAssetId"); 329 Boolean filterOutCanceledEvents = (Boolean ) context.get("filterOutCanceledEvents"); 330 if (filterOutCanceledEvents == null) { 331 filterOutCanceledEvents = Boolean.FALSE; 332 } 333 334 int maxConcurrentEntries = 0; 336 337 long period = periodInteger.intValue()*1000; 338 339 int numPeriods = 0; 340 if(numPeriodsInteger != null) numPeriods = numPeriodsInteger.intValue(); 341 342 Timestamp startStamp = UtilDateTime.getDayStart(startDay); 344 Timestamp endStamp = new Timestamp (startStamp.getTime()+(period*(numPeriods+1))); 345 346 startStamp.setNanos(0); 347 List validWorkEfforts = null; 349 String partyIdToUse = null; 350 351 if (UtilValidate.isNotEmpty(partyId)) { 352 if (partyId.equals(userLogin.getString("partyId")) || security.hasEntityPermission("WORKEFFORTMGR", "_VIEW", userLogin)) { 353 partyIdToUse = partyId; 354 } else { 355 return ServiceUtil.returnError("You do not have permission to view information for party with ID [" + partyId + "], you must be logged in as a user associated with this party, or have the WORKEFFORTMGR_VIEW or WORKEFFORTMGR_ADMIN permissions."); 356 } 357 } else { 358 if (UtilValidate.isEmpty(facilityId) && UtilValidate.isEmpty(fixedAssetId)) { 360 partyIdToUse = userLogin.getString("partyId"); 361 } 362 } 363 364 if (UtilValidate.isNotEmpty(partyIdToUse) || UtilValidate.isNotEmpty(facilityId) || UtilValidate.isNotEmpty(fixedAssetId)) { 366 validWorkEfforts = getWorkEffortEvents(ctx, startStamp, endStamp, partyIdToUse, facilityId, fixedAssetId); 367 } 368 if (filterOutCanceledEvents.booleanValue()) { 369 validWorkEfforts = EntityUtil.filterOutByCondition(validWorkEfforts, new EntityExpr("currentStatusId", EntityOperator.EQUALS, "EVENT_CANCELLED")); 370 } 371 372 List periods = new ArrayList (); 374 if (validWorkEfforts != null) { 375 376 for (int i = 0; i < numPeriods; i++) { 378 Timestamp curPeriodStart = new Timestamp (startStamp.getTime()+(i*period)); 379 Timestamp curPeriodEnd = new Timestamp (curPeriodStart.getTime()+period); 380 List curWorkEfforts = new ArrayList (); 381 Map entry = new HashMap (); 382 for (int j = 0; j < validWorkEfforts.size(); j++) { 383 384 GenericValue workEffort = (GenericValue) validWorkEfforts.get(j); 385 387 Timestamp estimatedStartDate = workEffort.getTimestamp("estimatedStartDate"); 388 Timestamp estimatedCompletionDate = workEffort.getTimestamp("estimatedCompletionDate"); 389 390 if (estimatedStartDate == null || estimatedCompletionDate == null) continue; 391 392 if (estimatedStartDate.compareTo(curPeriodEnd) < 0 && estimatedCompletionDate.compareTo(curPeriodStart) > 0) { 393 395 Map calEntry = new HashMap (); 396 calEntry.put("workEffort",workEffort); 397 398 long length = ((estimatedCompletionDate.after(endStamp) ? endStamp.getTime() : estimatedCompletionDate.getTime()) - (estimatedStartDate.before(startStamp) ? startStamp.getTime() : estimatedStartDate.getTime())); 399 int periodSpan = (int) Math.ceil((double) length / period); 400 calEntry.put("periodSpan", new Integer (periodSpan)); 401 402 if(i == 0) calEntry.put("startOfPeriod",new Boolean (true)); else { 404 boolean startOfPeriod = ((estimatedStartDate.getTime() - curPeriodStart.getTime()) >= 0); 405 calEntry.put("startOfPeriod", new Boolean (startOfPeriod)); 406 } 407 curWorkEfforts.add(calEntry); 408 } 409 410 if (estimatedStartDate.after(curPeriodEnd)) break; 412 413 if (estimatedCompletionDate.before(curPeriodEnd)) { 415 validWorkEfforts.remove(j); 416 j--; 417 } 418 } 419 int numEntries = curWorkEfforts.size(); 422 if(numEntries > maxConcurrentEntries) maxConcurrentEntries = numEntries; 423 entry.put("start",curPeriodStart); 424 entry.put("end",curPeriodEnd); 425 entry.put("calendarEntries",curWorkEfforts); 426 periods.add(entry); 427 } 428 } 429 Map result = new HashMap (); 430 result.put("periods", periods); 431 result.put("maxConcurrentEntries", new Integer (maxConcurrentEntries)); 432 return result; 433 } 434 435 public static Map getProductManufacturingSummaryByFacility(DispatchContext ctx, Map context) { 436 GenericDelegator delegator = ctx.getDelegator(); 437 Security security = ctx.getSecurity(); 438 GenericValue userLogin = (GenericValue) context.get("userLogin"); 439 String productId = (String ) context.get("productId"); 440 String facilityId = (String ) context.get("facilityId"); 442 Map summaryInByFacility = new HashMap (); 443 Map summaryOutByFacility = new HashMap (); 444 try { 445 List findIncomingProductionRunsConds = new LinkedList (); 450 451 findIncomingProductionRunsConds.add(new EntityExpr("productId", EntityOperator.EQUALS, productId)); 452 findIncomingProductionRunsConds.add(new EntityExpr("statusId", EntityOperator.EQUALS, "WEGS_CREATED")); 453 findIncomingProductionRunsConds.add(new EntityExpr("workEffortGoodStdTypeId", EntityOperator.EQUALS, "PRUN_PROD_DELIV")); 454 if (facilityId != null) { 455 findIncomingProductionRunsConds.add(new EntityExpr("facilityId", EntityOperator.EQUALS, facilityId)); 456 } 457 458 List findIncomingProductionRunsStatusConds = new LinkedList (); 459 findIncomingProductionRunsStatusConds.add(new EntityExpr("currentStatusId", EntityOperator.EQUALS, "PRUN_CREATED")); 460 findIncomingProductionRunsStatusConds.add(new EntityExpr("currentStatusId", EntityOperator.EQUALS, "PRUN_DOC_PRINTED")); 461 findIncomingProductionRunsStatusConds.add(new EntityExpr("currentStatusId", EntityOperator.EQUALS, "PRUN_RUNNING")); 462 findIncomingProductionRunsStatusConds.add(new EntityExpr("currentStatusId", EntityOperator.EQUALS, "PRUN_COMPLETED")); 463 findIncomingProductionRunsConds.add(new EntityConditionList(findIncomingProductionRunsStatusConds, EntityOperator.OR)); 464 465 EntityConditionList findIncomingProductionRunsCondition = new EntityConditionList(findIncomingProductionRunsConds, EntityOperator.AND); 466 467 List incomingProductionRuns = delegator.findByCondition("WorkEffortAndGoods", findIncomingProductionRunsCondition, null, UtilMisc.toList("-estimatedCompletionDate")); 468 Iterator incomingProductionRunsIter = incomingProductionRuns.iterator(); 469 while (incomingProductionRunsIter.hasNext()) { 470 GenericValue incomingProductionRun = (GenericValue)incomingProductionRunsIter.next(); 471 472 double producedQtyTot = 0.0; 473 if (incomingProductionRun.getString("currentStatusId").equals("PRUN_COMPLETED")) { 474 List inventoryItems = delegator.findByAnd("WorkEffortAndInventoryProduced", UtilMisc.toMap("productId", productId, "workEffortId", incomingProductionRun.getString("workEffortId"))); 475 Iterator inventoryItemsIter = inventoryItems.iterator(); 476 while (inventoryItemsIter.hasNext()) { 477 GenericValue inventoryItem = (GenericValue)inventoryItemsIter.next(); 478 GenericValue inventoryItemDetail = EntityUtil.getFirst(delegator.findByAnd("InventoryItemDetail", UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId")), UtilMisc.toList("inventoryItemDetailSeqId"))); 479 if (inventoryItemDetail != null && inventoryItemDetail.get("quantityOnHandDiff") != null) { 480 Double inventoryItemQty = inventoryItemDetail.getDouble("quantityOnHandDiff"); 481 producedQtyTot = producedQtyTot + inventoryItemQty.doubleValue(); 482 } 483 } 484 } 485 double estimatedQuantity = 0.0; 486 if (incomingProductionRun.get("estimatedQuantity") != null) { 487 estimatedQuantity = incomingProductionRun.getDouble("estimatedQuantity").doubleValue(); 488 } 489 double remainingQuantity = estimatedQuantity - producedQtyTot; if (remainingQuantity > 0) { 491 incomingProductionRun.set("estimatedQuantity", new Double (remainingQuantity)); 492 } else { 493 continue; 494 } 495 String weFacilityId = incomingProductionRun.getString("facilityId"); 496 497 Map quantitySummary = (Map )summaryInByFacility.get(weFacilityId); 498 if (quantitySummary == null) { 499 quantitySummary = new HashMap (); 500 quantitySummary.put("facilityId", weFacilityId); 501 summaryInByFacility.put(weFacilityId, quantitySummary); 502 } 503 Double remainingQuantityTot = (Double )quantitySummary.get("estimatedQuantityTotal"); 504 if (remainingQuantityTot == null) { 505 quantitySummary.put("estimatedQuantityTotal", new Double (remainingQuantity)); 506 } else { 507 quantitySummary.put("estimatedQuantityTotal", new Double (remainingQuantity + remainingQuantityTot.doubleValue())); 508 } 509 510 List incomingProductionRunList = (List )quantitySummary.get("incomingProductionRunList"); 511 if (incomingProductionRunList == null) { 512 incomingProductionRunList = new LinkedList (); 513 quantitySummary.put("incomingProductionRunList", incomingProductionRunList); 514 } 515 incomingProductionRunList.add(incomingProductionRun); 516 } 517 List findOutgoingProductionRunsConds = new LinkedList (); 522 523 findOutgoingProductionRunsConds.add(new EntityExpr("productId", EntityOperator.EQUALS, productId)); 524 findOutgoingProductionRunsConds.add(new EntityExpr("statusId", EntityOperator.EQUALS, "WEGS_CREATED")); 525 findOutgoingProductionRunsConds.add(new EntityExpr("workEffortGoodStdTypeId", EntityOperator.EQUALS, "PRUNT_PROD_NEEDED")); 526 if (facilityId != null) { 527 findOutgoingProductionRunsConds.add(new EntityExpr("facilityId", EntityOperator.EQUALS, facilityId)); 528 } 529 530 List findOutgoingProductionRunsStatusConds = new LinkedList (); 531 findOutgoingProductionRunsStatusConds.add(new EntityExpr("currentStatusId", EntityOperator.EQUALS, "PRUN_CREATED")); 532 findOutgoingProductionRunsStatusConds.add(new EntityExpr("currentStatusId", EntityOperator.EQUALS, "PRUN_DOC_PRINTED")); 533 findOutgoingProductionRunsStatusConds.add(new EntityExpr("currentStatusId", EntityOperator.EQUALS, "PRUN_RUNNING")); 534 findOutgoingProductionRunsConds.add(new EntityConditionList(findOutgoingProductionRunsStatusConds, EntityOperator.OR)); 535 536 EntityConditionList findOutgoingProductionRunsCondition = new EntityConditionList(findOutgoingProductionRunsConds, EntityOperator.AND); 537 List outgoingProductionRuns = delegator.findByCondition("WorkEffortAndGoods", findOutgoingProductionRunsCondition, null, UtilMisc.toList("-estimatedStartDate")); 538 Iterator outgoingProductionRunsIter = outgoingProductionRuns.iterator(); 539 while (outgoingProductionRunsIter.hasNext()) { 540 GenericValue outgoingProductionRun = (GenericValue)outgoingProductionRunsIter.next(); 541 542 String weFacilityId = outgoingProductionRun.getString("facilityId"); 543 Double neededQuantity = outgoingProductionRun.getDouble("estimatedQuantity"); 544 if (neededQuantity == null) { 545 neededQuantity = new Double (0); 546 } 547 548 Map quantitySummary = (Map )summaryOutByFacility.get(weFacilityId); 549 if (quantitySummary == null) { 550 quantitySummary = new HashMap (); 551 quantitySummary.put("facilityId", weFacilityId); 552 summaryOutByFacility.put(weFacilityId, quantitySummary); 553 } 554 Double remainingQuantityTot = (Double )quantitySummary.get("estimatedQuantityTotal"); 555 if (remainingQuantityTot == null) { 556 quantitySummary.put("estimatedQuantityTotal", neededQuantity); 557 } else { 558 quantitySummary.put("estimatedQuantityTotal", new Double (neededQuantity.doubleValue() + remainingQuantityTot.doubleValue())); 559 } 560 561 List outgoingProductionRunList = (List )quantitySummary.get("outgoingProductionRunList"); 562 if (outgoingProductionRunList == null) { 563 outgoingProductionRunList = new LinkedList (); 564 quantitySummary.put("outgoingProductionRunList", outgoingProductionRunList); 565 } 566 outgoingProductionRunList.add(outgoingProductionRun); 567 } 568 569 } catch(GenericEntityException gee) { 570 return ServiceUtil.returnError("Error retrieving manufacturing data for productId [" + productId + "]: " + gee.getMessage()); 571 } 572 Map resultMap = ServiceUtil.returnSuccess(); 573 resultMap.put("summaryInByFacility", summaryInByFacility); 574 resultMap.put("summaryOutByFacility", summaryOutByFacility); 575 return resultMap; 576 } 577 } 578 | Popular Tags |