1 25 package org.ofbiz.shipment.packing; 26 27 import java.util.Iterator ; 28 import java.util.Map ; 29 30 import org.ofbiz.base.util.Debug; 31 import org.ofbiz.base.util.GeneralException; 32 import org.ofbiz.base.util.UtilValidate; 33 import org.ofbiz.service.DispatchContext; 34 import org.ofbiz.service.ServiceUtil; 35 36 42 public class PackingServices { 43 44 public static final String module = PackingServices.class.getName(); 45 46 public static Map addPackLine(DispatchContext dctx, Map context) { 47 PackingSession session = (PackingSession) context.get("packingSession"); 48 String shipGroupSeqId = (String ) context.get("shipGroupSeqId"); 49 String orderId = (String ) context.get("orderId"); 50 String productId = (String ) context.get("productId"); 51 Double quantity = (Double ) context.get("quantity"); 52 Integer packageSeq = (Integer ) context.get("packageSeq"); 53 54 String instructions = (String ) context.get("handlingInstructions"); 56 session.setHandlingInstructions(instructions); 57 58 if (quantity == null) { 59 quantity = new Double (1); 60 } 61 62 Debug.log("Pack input [" + productId + "] @ [" + quantity + "]", module); 63 64 try { 65 session.addOrIncreaseLine(orderId, null, shipGroupSeqId, productId, quantity.doubleValue(), packageSeq.intValue()); 66 } catch (GeneralException e) { 67 Debug.logError(e, module); 68 return ServiceUtil.returnError(e.getMessage()); 69 } 70 71 return ServiceUtil.returnSuccess(); 72 } 73 74 public static Map packBulk(DispatchContext dctx, Map context) { 75 PackingSession session = (PackingSession) context.get("packingSession"); 76 String orderId = (String ) context.get("orderId"); 77 String shipGroupSeqId = (String ) context.get("shipGroupSeqId"); 78 79 String instructions = (String ) context.get("handlingInstructions"); 81 session.setHandlingInstructions(instructions); 82 83 Map prdInfo = (Map ) context.get("prdInfo"); 84 Map qtyInfo = (Map ) context.get("qtyInfo"); 85 Map pkgInfo = (Map ) context.get("pkgInfo"); 86 Map selInfo = (Map ) context.get("selInfo"); 87 if (selInfo != null) { 88 Iterator i = selInfo.keySet().iterator(); 89 while (i.hasNext()) { 90 String orderItemSeqId = (String ) i.next(); 91 String qtyStr = (String ) qtyInfo.get(orderItemSeqId); 92 String pkgStr = (String ) pkgInfo.get(orderItemSeqId); 93 String prdStr = (String ) prdInfo.get(orderItemSeqId); 94 if (UtilValidate.isEmpty(prdStr)) { 95 prdStr = null; 97 } 98 Debug.log("Item: " + orderItemSeqId + " / Product: " + prdStr + " / Quantity: " + qtyStr + " / Package: " + pkgStr, module); 99 100 double quantity = 0; 101 int packageSeq = 0; 102 try { 103 quantity = Double.parseDouble(qtyStr); 104 packageSeq = Integer.parseInt(pkgStr); 105 } catch (Exception e) { 106 return ServiceUtil.returnError(e.getMessage()); 107 } 108 109 try { 110 session.addOrIncreaseLine(orderId, orderItemSeqId, shipGroupSeqId, prdStr, quantity, packageSeq); 111 } catch (GeneralException e) { 112 Debug.logError(e, module); 113 return ServiceUtil.returnError(e.getMessage()); 114 } 115 } 116 } 117 118 return ServiceUtil.returnSuccess(); 119 } 120 121 public static Map incrementPackageSeq(DispatchContext dctx, Map context) { 122 PackingSession session = (PackingSession) context.get("packingSession"); 123 int nextSeq = session.nextPackageSeq(); 124 Map result = ServiceUtil.returnSuccess(); 125 result.put("nextPackageSeq", new Integer (nextSeq)); 126 return result; 127 } 128 129 public static Map clearPackLine(DispatchContext dctx, Map context) { 130 PackingSession session = (PackingSession) context.get("packingSession"); 131 String orderId = (String ) context.get("orderId"); 132 String orderItemSeqId = (String ) context.get("orderItemSeqId"); 133 String shipGroupSeqId = (String ) context.get("shipGroupSeqId"); 134 String inventoryItemId = (String ) context.get("inventoryItemId"); 135 Integer packageSeqId = (Integer ) context.get("packageSeqId"); 136 137 PackingSessionLine line = session.findLine(orderId, orderItemSeqId, shipGroupSeqId, 138 inventoryItemId, packageSeqId.intValue()); 139 140 if (line != null) { 142 session.clearLine(line); 143 } else { 144 return ServiceUtil.returnError("Packing line item not found; cannot clear."); 145 } 146 147 return ServiceUtil.returnSuccess(); 148 } 149 150 public static Map clearPackAll(DispatchContext dctx, Map context) { 151 PackingSession session = (PackingSession) context.get("packingSession"); 152 session.clear(); 153 154 return ServiceUtil.returnSuccess(); 155 } 156 157 158 public static Map completePack(DispatchContext dctx, Map context) { 159 PackingSession session = (PackingSession) context.get("packingSession"); 160 161 String instructions = (String ) context.get("handlingInstructions"); 163 session.setHandlingInstructions(instructions); 164 165 Boolean force = (Boolean ) context.get("forceComplete"); 166 if (force == null) { 167 force = Boolean.FALSE; 168 } 169 170 String shipmentId = null; 171 try { 172 shipmentId = session.complete(force.booleanValue()); 173 } catch (GeneralException e) { 174 Debug.logError(e, module); 175 return ServiceUtil.returnError(e.getMessage(), e.getMessageList()); 176 } 177 178 Map resp; 179 if ("EMPTY".equals(shipmentId)) { 180 resp = ServiceUtil.returnError("No items currently set to be shipped. Cannot complete!"); 181 } else { 182 resp = ServiceUtil.returnSuccess("Shipment #" + shipmentId + " created and marked as PACKED."); 183 } 184 185 resp.put("shipmentId", shipmentId); 186 return resp; 187 } 188 } 189 | Popular Tags |