📄 mrpservices.java
字号:
try { InventoryEventPlannedServices.createOrUpdateInventoryEventPlanned(parameters, eventQuantityTmp, delegator); } catch (GenericEntityException e) { return ServiceUtil.returnError("Problem initializing the InventoryEventPlanned entity (PUR_ORDER_RECP)"); } } // ---------------------------------------- // PRODUCTION Run: components // ---------------------------------------- resultList = null; iteratorResult = null; parameters = UtilMisc.toMap("workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED", "statusId", "WEGS_CREATED"); try { resultList = delegator.findByAnd("WorkEffortAndGoods", parameters); } catch(GenericEntityException e) { Debug.logError(e, "Error : delegator.findByAnd(\"OrderItem\", parameters\")", module); Debug.logError(e, "Error : parameters = "+parameters,module); return ServiceUtil.returnError("Problem, we can not find the order items, for more detail look at the log"); } iteratorResult = resultList.iterator(); while(iteratorResult.hasNext()){ genericResult = (GenericValue) iteratorResult.next(); String productId = genericResult.getString("productId"); Double eventQuantityTmp = new Double(-1.0 * genericResult.getDouble("estimatedQuantity").doubleValue()); Timestamp estimatedShipDate = genericResult.getTimestamp("estimatedStartDate"); if (estimatedShipDate == null) { estimatedShipDate = now; } parameters = UtilMisc.toMap("productId", productId, "eventDate", estimatedShipDate, "inventoryEventPlanTypeId", "MANUF_ORDER_REQ"); try { InventoryEventPlannedServices.createOrUpdateInventoryEventPlanned(parameters, eventQuantityTmp, delegator); } catch (GenericEntityException e) { return ServiceUtil.returnError("Problem initializing the InventoryEventPlanned entity (MRP_REQUIREMENT)"); } } // ---------------------------------------- // PRODUCTION Run: product produced // ---------------------------------------- resultList = null; iteratorResult = null; parameters = UtilMisc.toMap("workEffortGoodStdTypeId", "PRUN_PROD_DELIV", "statusId", "WEGS_CREATED", "workEffortTypeId", "PROD_ORDER_HEADER"); try { resultList = delegator.findByAnd("WorkEffortAndGoods", parameters); } catch(GenericEntityException e) { Debug.logError(e, "Error : delegator.findByAnd(\"OrderItem\", parameters\")", module); Debug.logError(e, "Error : parameters = "+parameters,module); return ServiceUtil.returnError("Problem, we can not find the order items, for more detail look at the log"); } iteratorResult = resultList.iterator(); while(iteratorResult.hasNext()){ genericResult = (GenericValue) iteratorResult.next(); if ("PRUN_CLOSED".equals(genericResult.getString("currentStatusId"))) { continue; } Double qtyToProduce = genericResult.getDouble("quantityToProduce"); if (qtyToProduce == null) { qtyToProduce = new Double(0); } Double qtyProduced = genericResult.getDouble("quantityProduced"); if (qtyProduced == null) { qtyProduced = new Double(0); } if (qtyProduced.compareTo(qtyToProduce) >= 0) { continue; } double qtyDiff = qtyToProduce.doubleValue() - qtyProduced.doubleValue(); String productId = genericResult.getString("productId"); Double eventQuantityTmp = new Double(qtyDiff); Timestamp estimatedShipDate = genericResult.getTimestamp("estimatedCompletionDate"); if (estimatedShipDate == null) { estimatedShipDate = now; } parameters = UtilMisc.toMap("productId", productId, "eventDate", estimatedShipDate, "inventoryEventPlanTypeId", "MANUF_ORDER_RECP"); try { InventoryEventPlannedServices.createOrUpdateInventoryEventPlanned(parameters, eventQuantityTmp, delegator); } catch (GenericEntityException e) { return ServiceUtil.returnError("Problem initializing the InventoryEventPlanned entity (MANUF_ORDER_RECP)"); } } Map result = new HashMap(); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); Debug.logInfo("return from initInventoryEventPlanned", module); return result; } /** * Create a List with all the event of InventotyEventPlanned for one billOfMaterialLevel, sorted by productId and eventDate. * * <li>INPUT : Parameter to get from the context : </li><ul> * <li>Integer billOfMaterialLevel : 0 for root for more detail see BomHelper.getMaxDepth</li></ul> * * <li>OUTPUT : Result to put in the map :</li><ul> * <li>List listInventoryEventForMRP : all the event of InventotyEventPlanned for one billOfMaterialLevel, sorted by productId and eventDate<br/> * @param ctx The DispatchContext that this service is operating in. * @param context Map containing the input parameters. * @return Map with the result of the service, the output parameters. */ public static Map listProductForMrp(DispatchContext ctx, Map context) { Debug.logInfo("listProductForMrp called", module); // read parameters from context GenericDelegator delegator = ctx.getDelegator(); Security security = ctx.getSecurity(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); Long billOfMaterialLevel = (Long) context.get("billOfMaterialLevel"); // Find all products in MrpInventoryEventPlanned, ordered by bom and eventDate List listResult = null; // If billOfMaterialLevel == 0 the search must be done with (billOfMaterialLevel == 0 || billOfMaterialLevel == null) EntityCondition parameters = null; if (billOfMaterialLevel.intValue() == 0) { parameters = new EntityExpr(new EntityExpr("billOfMaterialLevel", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("billOfMaterialLevel", EntityOperator.EQUALS, billOfMaterialLevel)); } else { parameters = new EntityExpr("billOfMaterialLevel", EntityOperator.EQUALS, billOfMaterialLevel); } List orderBy = UtilMisc.toList("productId", "eventDate"); try{ //listResult = delegator.findByAnd("MrpInventoryEventPlanned", parameters, orderBy); listResult = delegator.findByCondition("MrpInventoryEventPlanned", parameters, null, orderBy); } catch(GenericEntityException e) { Debug.logError(e, "Error : delegator.findByCondition(\"MrpInventoryEventPlanned\", parameters, null, orderBy)", module); Debug.logError(e, "Error : parameters = "+parameters,module); Debug.logError(e, "Error : orderBy = "+orderBy,module); return ServiceUtil.returnError("Problem, we can not find the products, for more detail look at the log"); } Map result = new HashMap(); result.put("listInventoryEventForMrp",listResult); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); Debug.logInfo("return from listProductForMrp "+billOfMaterialLevel, module); return result; } /** * Find the quantity on hand of products for MRP. * <li>PreConditions : none</li> * <li>Result : We get the quantity of product available in the stocks.</li> * * @param product the product for which the Quantity Available is required * @return the sum of all the totalAvailableToPromise of the inventoryItem related to the product, if the related facility is Mrp available (not yet implemented!!) */ public static double findProductMrpQoh(GenericValue product, LocalDispatcher dispatcher) { List orderBy = UtilMisc.toList("facilityId", "-receivedDate", "-inventoryItemId"); Map resultMap = null; try{ resultMap = dispatcher.runSync("getProductInventoryAvailable", UtilMisc.toMap("productId", product.getString("productId"))); // TODO: aggiungere facilityId come argomento ed usare il seguente //resultMap = dispatcher.runSync("getProductInventoryAvailableByFacility", UtilMisc.toMap("productId", product.getString("productId"), "facilityId", facilityId)); } catch (GenericServiceException e) { Debug.logError(e, "Error calling getProductInventoryAvailableByFacility service", module); return 0; } return ((Double)resultMap.get("quantityOnHandTotal")).doubleValue(); } /** * Process the bill of material (bom) of the product to insert components in the InventoryEventPlanned table. * Before inserting in the entity, test if there is the record already existing to add quantity rather to create a new one. * * @param product * @param eventQuantity the product quantity needed * @param startDate the startDate of the productionRun which will used to produce the product * @param routingTaskStartDate Map with all the routingTask as keys and startDate of each of them * @return None */ public static void processBomComponent(GenericValue product, double eventQuantity, Timestamp startDate, Map routingTaskStartDate, List listComponent) { // TODO : change the return type to boolean to be able to test if all is ok or if it have had a exception GenericDelegator delegator = product.getDelegator(); if (listComponent != null && listComponent.size() >0) { Iterator listComponentIter = listComponent.iterator(); while (listComponentIter.hasNext()) { BOMNode node = (BOMNode) listComponentIter.next(); GenericValue productComponent = node.getProductAssoc(); // read the startDate for the component String routingTask = node.getProductAssoc().getString("routingWorkEffortId"); Timestamp eventDate = (routingTask == null || !routingTaskStartDate.containsKey(routingTask)) ? startDate : (Timestamp) routingTaskStartDate.get(routingTask); // if the components is valid at the event Date create the Mrp requirement in the InventoryEventPlanned entity if (EntityUtil.isValueActive(productComponent, eventDate)) { //Map parameters = UtilMisc.toMap("productId", productComponent.getString("productIdTo")); Map parameters = UtilMisc.toMap("productId", node.getProduct().getString("productId")); parameters.put("eventDate", eventDate); parameters.put("inventoryEventPlanTypeId", "MRP_REQUIREMENT"); double componentEventQuantity = node.getQuantity(); try { InventoryEventPlannedServices.createOrUpdateInventoryEventPlanned(parameters, new Double(-1.0 * componentEventQuantity), delegator); } catch (GenericEntityException e) { Debug.logError("Error : delegator.findByPrimaryKey(\"InventoryEventPlanned\", parameters) ="+parameters+"--"+e.getMessage(), module); } } } } return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -