1 26 27 package org.ofbiz.manufacturing.techdata; 28 29 import java.sql.Timestamp ; 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 import java.util.LinkedList ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.TreeMap ; 36 37 import org.ofbiz.base.util.Debug; 38 import org.ofbiz.base.util.UtilMisc; 39 import org.ofbiz.entity.GenericEntityException; 40 import org.ofbiz.entity.GenericValue; 41 import org.ofbiz.entity.util.EntityUtil; 42 import org.ofbiz.manufacturing.mrp.MrpServices; 43 import org.ofbiz.service.GenericServiceException; 44 import org.ofbiz.service.LocalDispatcher; 45 46 47 54 public class ProductHelper { 55 56 public static final String module = ProductHelper.class.getName(); 57 public static final String resource = "ManufacturingUiLabels"; 58 59 60 67 public static GenericValue getRouting(GenericValue product, double quantity, Timestamp eventDate, LocalDispatcher dispatcher){ 69 Debug.logInfo("getRouting called", module); 70 71 List listRouting = null; 73 try{ 74 listRouting = product.getRelated("WorkEffortGoodStandard", UtilMisc.toMap("workEffortGoodStdTypeId", "ROU_PROD_TEMPLATE"),UtilMisc.toList("estimatedQuantity DESC")); 75 if (listRouting.size()>0) listRouting = EntityUtil.filterByDate(listRouting,eventDate); 76 } catch (GenericEntityException e) { 77 Debug.logError(e,"Error : product.getRelated routing... productId="+product.getString("productId"), module); 78 return null; 79 } 80 if (listRouting == null || listRouting.size()==0) { 81 Map serviceResponse = null; 83 try { 84 serviceResponse = dispatcher.runSync("getManufacturingComponents", UtilMisc.toMap("productId", product.getString("productId"), "quantity", new Double (quantity))); 85 } catch (GenericServiceException e) { 86 Debug.logError("Error : getManufacturingComponents for productId ="+product.getString("productId")+"--"+e.getMessage(), module); 87 return null; 88 } 89 String routingId = (String )serviceResponse.get("workEffortId"); 90 try{ 91 return product.getDelegator().findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", routingId)); 92 } catch (GenericEntityException e) { 93 return null; 94 } 95 } 96 Iterator listRoutingIter = listRouting.iterator(); 97 boolean found = false; 98 GenericValue routingProduct = null; 99 while (listRoutingIter.hasNext() && !found) { 101 routingProduct = (GenericValue) listRoutingIter.next(); 102 if (routingProduct.getDouble("estimatedQuantity")==null || 103 routingProduct.getDouble("estimatedQuantity").doubleValue() < quantity) found = true; 104 } 105 try{ 106 return routingProduct.getRelatedOneCache("WorkEffort"); 107 } catch (GenericEntityException e) { 108 Debug.logError(e,"Error : routingProduct.getRelated routing... workEffortId="+routingProduct.getString("workEffortId")+" productId="+routingProduct.getString("productId"), module); 109 return null; 110 } 111 } 112 113 118 public static List getVariationProduct(List inventoryList, LocalDispatcher dispatcher){ 119 120 Debug.logInfo("coucou de la methode", module); 121 ArrayList inventoryProductList; 122 Map inventoryProductMap = new TreeMap (); 123 Map cumulativeAtpByEventMap = new TreeMap (); 124 GenericValue inventoryTmp; 125 boolean firstOfList = true; 126 127 Iterator iter = inventoryList.iterator(); 129 while( iter.hasNext() ){ 130 inventoryTmp = (GenericValue) iter.next(); 131 inventoryProductList = (ArrayList )inventoryProductMap.get( inventoryTmp.getString("productId") ); 132 if( inventoryProductList == null ){ 133 inventoryProductList = new ArrayList (); 134 inventoryProductMap.put( inventoryTmp.getString("productId"), inventoryProductList); 135 } 136 inventoryProductList.add( inventoryTmp ); 137 } 138 139 ArrayList keys = new ArrayList ( inventoryProductMap.keySet() ); 141 for (Iterator iterMap = keys.iterator(); iterMap.hasNext(); ){ 142 String productId = (String ) iterMap.next(); 143 inventoryProductList = (ArrayList ) inventoryProductMap.get(productId); 144 double productAtp = 0; 145 for (iter = inventoryProductList.iterator();iter.hasNext();){ 146 inventoryTmp = (GenericValue)iter.next(); 148 if (firstOfList){ 149 try { 151 GenericValue product = inventoryTmp.getRelatedOneCache("Product"); 152 productAtp = MrpServices.findProductMrpQoh(product, dispatcher); 153 } catch (Exception e) { 154 Debug.logError("Error : getRelatedOneCache Produc with productId="+inventoryTmp.getString("productId")+"--"+e.getMessage(), module); 155 return null; 156 } 157 firstOfList = false; 158 } 159 Double doubleTmp = (Double )inventoryTmp.getDouble("eventQuantity"); 160 productAtp += doubleTmp.doubleValue(); 161 cumulativeAtpByEventMap.put( inventoryTmp, new Double (productAtp) ); 162 } 163 firstOfList = true; 164 } 165 166 List eventPlannedAndCumulativeAtp = new LinkedList (); 168 iter = inventoryList.iterator(); 169 while( iter.hasNext() ){ 170 inventoryTmp = (GenericValue)iter.next(); 171 Double productAtp = (Double ) cumulativeAtpByEventMap.get(inventoryTmp); 172 eventPlannedAndCumulativeAtp.add( productAtp ); 173 } 174 return eventPlannedAndCumulativeAtp; 175 176 } 177 } 178 | Popular Tags |