1 25 package org.ofbiz.manufacturing.mrp; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 import org.ofbiz.base.util.Debug; 31 import org.ofbiz.base.util.UtilMisc; 32 import org.ofbiz.entity.GenericDelegator; 33 import org.ofbiz.entity.GenericEntityException; 34 import org.ofbiz.entity.GenericValue; 35 import org.ofbiz.service.DispatchContext; 36 import org.ofbiz.service.ServiceUtil; 37 38 43 public class InventoryEventPlannedServices { 44 45 public static final String module = InventoryEventPlannedServices.class.getName(); 46 47 56 public static Map createInventoryEventPlanned(DispatchContext ctx, Map context) { 57 GenericDelegator delegator = ctx.getDelegator(); 58 Map parameters = UtilMisc.toMap("productId", context.get("productId"), 60 "eventDate", context.get("eventDate"), 61 "inventoryEventPlanTypeId",context.get("inventoryEventPlanTypeId")); 62 Double quantity = (Double )context.get("eventQuantity"); 63 GenericValue inventoryEventPlanned = null; 64 try { 65 createOrUpdateInventoryEventPlanned(parameters, quantity, delegator); 66 } catch (GenericEntityException e) { 67 Debug.logError(e,"Error : delegator.findByPrimaryKey(\"InventoryEventPlanned\", parameters =)"+parameters, module); 68 return ServiceUtil.returnError("Problem, on database access, for more detail look at the log"); 69 } 70 return ServiceUtil.returnSuccess(); 71 } 72 73 public static void createOrUpdateInventoryEventPlanned(Map inventoryEventPlannedKeyMap, Double newQuantity, GenericDelegator delegator) throws GenericEntityException { 74 GenericValue inventoryEventPlanned = null; 75 inventoryEventPlanned = delegator.findByPrimaryKey("InventoryEventPlanned", inventoryEventPlannedKeyMap); 76 if (inventoryEventPlanned == null) { 77 inventoryEventPlanned = delegator.makeValue("InventoryEventPlanned", inventoryEventPlannedKeyMap); 78 inventoryEventPlanned.put("eventQuantity", newQuantity); 79 inventoryEventPlanned.create(); 80 } else { 81 double qties = newQuantity.doubleValue() + ((Double )inventoryEventPlanned.get("eventQuantity")).doubleValue(); 82 inventoryEventPlanned.put("eventQuantity", new Double (qties)); 83 inventoryEventPlanned.store(); 84 } 85 } 86 87 } 88 | Popular Tags |