📄 mrpservices.java
字号:
/* * $Id: MrpServices.java 7238 2006-04-08 07:30:54Z jacopo $ * Copyright (c) 2003, 2004 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.manufacturing.mrp;import java.sql.Timestamp;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.ListIterator;import java.util.Locale;import java.util.Map;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.manufacturing.bom.BOMNode;import org.ofbiz.security.Security;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;// TODO: // Verificare il metodo: ProductHelper.isBuild(product)// Verificare il metodo ProposedOrder.calculateQuantityToSupply()// il metodo findProductMrpQoh() deve richiamare internamente un servizio// /** * Services for running MRP * * @author <a href=mailto:thierry.grauss@etu.univ-tours.fr">Thierry GRAUSS</a> */public class MrpServices { public static final String module = MrpServices.class.getName(); public static final String resource = "ManufacturingUiLabels"; /** * Initialize the InventoryEventPlanned table. * <li>PreConditions : none</li> * <li>Result : The table InventoryEventPlannedForMRP is initialized</li> * <li>INPUT : Parameter to get from the context :</li><ul> * <li>Boolean reInitialize<br/> * if true : we must reinitialize the table, else we synchronize the table (not for the moment)</li></ul> * * <li>OUTPUT : Result to put in the map :</li><ul> * <li>none</li></ul> * * @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 initInventoryEventPlanned(DispatchContext ctx, Map context) { GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); Security security = ctx.getSecurity(); Timestamp now = UtilDateTime.nowTimestamp(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); //Erases the old table for the moment and initializes it with the new orders, //Does not modify the old one now. Debug.logInfo("initInventoryEventPlanned called", module); List listResult = null; try{ listResult = delegator.findAll("InventoryEventPlanned"); } catch(GenericEntityException e) { Debug.logError(e,"Error : delegator.findAll(\"InventoryEventPlanned\")", module); return ServiceUtil.returnError("Problem, we can not find all the items of InventoryEventPlanned, for more detail look at the log"); } if(listResult != null){ try{ delegator.removeAll(listResult); } catch(GenericEntityException e) { Debug.logError(e,"Error : delegator.removeAll(listResult), listResult ="+listResult, module); return ServiceUtil.returnError("Problem, we can not remove the InventoryEventPlanned items, for more detail look at the log"); } } // MRP proposed requirements are deleted // TODO: is it correct? listResult = null; try{ listResult = delegator.findByAnd("Requirement", UtilMisc.toMap("requirementTypeId", "MRP_PRO_PURCH_ORDER", "statusId", "REQ_CREATED")); } catch(GenericEntityException e) { return ServiceUtil.returnError("Problem, we can not find all the items of InventoryEventPlanned, for more detail look at the log"); } if(listResult != null){ try{ delegator.removeAll(listResult); } catch(GenericEntityException e) { return ServiceUtil.returnError("Problem, we can not remove the InventoryEventPlanned items, for more detail look at the log"); } } listResult = null; try{ listResult = delegator.findByAnd("Requirement", UtilMisc.toMap("requirementTypeId", "MRP_PRO_PROD_ORDER", "statusId", "REQ_CREATED")); } catch(GenericEntityException e) { return ServiceUtil.returnError("Problem, we can not find all the items of InventoryEventPlanned, for more detail look at the log"); } if(listResult != null){ try{ delegator.removeAll(listResult); } catch(GenericEntityException e) { return ServiceUtil.returnError("Problem, we can not remove the InventoryEventPlanned items, for more detail look at the log"); } } GenericValue genericResult = null; Map parameters = null; List resultList = null; Iterator iteratorResult = null; // ---------------------------------------- // Loads all the approved sales order items and purchase order items // ---------------------------------------- resultList = null; iteratorResult = null; parameters = UtilMisc.toMap("orderTypeId", "SALES_ORDER", "itemStatusId", "ITEM_APPROVED"); try { resultList = delegator.findByAnd("OrderHeaderAndItems", 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("quantity").doubleValue()); Timestamp estimatedShipDate = genericResult.getTimestamp("estimatedDeliveryDate"); if (estimatedShipDate == null) { estimatedShipDate = now; } parameters = UtilMisc.toMap("productId", productId, "eventDate", estimatedShipDate, "inventoryEventPlanTypeId", "SALE_ORDER_SHIP"); try { InventoryEventPlannedServices.createOrUpdateInventoryEventPlanned(parameters, eventQuantityTmp, delegator); } catch (GenericEntityException e) { return ServiceUtil.returnError("Problem initializing the InventoryEventPlanned entity (SALE_ORDER_SHIP)"); } } // ---------------------------------------- // Loads all the approved purchase order items // ---------------------------------------- resultList = null; iteratorResult = null; parameters = UtilMisc.toMap("orderTypeId", "PURCHASE_ORDER", "itemStatusId", "ITEM_APPROVED"); try { resultList = delegator.findByAnd("OrderHeaderAndItems", 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(genericResult.getDouble("quantity").doubleValue()); Timestamp estimatedShipDate = genericResult.getTimestamp("estimatedShipDate"); if (estimatedShipDate == null) { estimatedShipDate = now; } parameters = UtilMisc.toMap("productId", productId, "eventDate", estimatedShipDate, "inventoryEventPlanTypeId", "PUR_ORDER_RECP");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -