001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.shipment.packing;
019:
020: import java.util.Map;
021:
022: import javolution.util.FastMap;
023:
024: import org.ofbiz.base.util.GeneralException;
025: import org.ofbiz.base.util.UtilFormatOut;
026: import org.ofbiz.base.util.Debug;
027: import org.ofbiz.entity.GenericValue;
028: import org.ofbiz.entity.GenericDelegator;
029: import org.ofbiz.service.LocalDispatcher;
030: import org.ofbiz.service.ServiceUtil;
031:
032: public class PackingSessionLine implements java.io.Serializable {
033:
034: public final String module = PackingSessionLine.class.getName();
035:
036: protected String orderId = null;
037: protected String orderItemSeqId = null;
038: protected String shipGroupSeqId = null;
039: protected String productId = null;
040: protected String inventoryItemId = null;
041: protected String shipmentItemSeqId = null;
042: protected double quantity = 0;
043: protected double weight = 0;
044: protected int packageSeq = 0;
045:
046: public PackingSessionLine(String orderId, String orderItemSeqId,
047: String shipGroupSeqId, String productId,
048: String inventoryItemId, double quantity, double weight,
049: int packageSeq) {
050: this .orderId = orderId;
051: this .orderItemSeqId = orderItemSeqId;
052: this .shipGroupSeqId = shipGroupSeqId;
053: this .inventoryItemId = inventoryItemId;
054: this .productId = productId;
055: this .quantity = quantity;
056: this .weight = weight;
057: this .packageSeq = packageSeq;
058: }
059:
060: public String getOrderId() {
061: return this .orderId;
062: }
063:
064: public String getOrderItemSeqId() {
065: return this .orderItemSeqId;
066: }
067:
068: public String getShipGroupSeqId() {
069: return this .shipGroupSeqId;
070: }
071:
072: public String getInventoryItemId() {
073: return this .inventoryItemId;
074: }
075:
076: public String getProductId() {
077: return this .productId;
078: }
079:
080: public String getShipmentItemSeqId() {
081: return this .shipmentItemSeqId;
082: }
083:
084: public void setShipmentItemSeqId(String shipmentItemSeqId) {
085: this .shipmentItemSeqId = shipmentItemSeqId;
086: }
087:
088: public double getQuantity() {
089: return this .quantity;
090: }
091:
092: public void setQuantity(double quantity) {
093: this .quantity = quantity;
094: }
095:
096: public void addQuantity(double quantity) {
097: this .quantity += quantity;
098: }
099:
100: public double getWeight() {
101: return weight;
102: }
103:
104: public void setWeight(double weight) {
105: this .weight = weight;
106: }
107:
108: public void addWeight(double weight) {
109: this .weight += weight;
110: }
111:
112: public int getPackageSeq() {
113: return this .packageSeq;
114: }
115:
116: public boolean isSameItem(PackingSessionLine line) {
117: if (this .getInventoryItemId().equals(line.getInventoryItemId())) {
118: if (this .getOrderItemSeqId().equals(
119: line.getOrderItemSeqId())) {
120: if (this .getOrderId().equals(line.getOrderId())) {
121: if (this .getShipGroupSeqId().equals(
122: line.getShipGroupSeqId())) {
123: return true;
124: }
125: }
126: }
127: }
128: return false;
129: }
130:
131: protected void issueItemToShipment(String shipmentId,
132: String picklistBinId, GenericValue userLogin,
133: Double quantity, LocalDispatcher dispatcher)
134: throws GeneralException {
135: if (quantity == null) {
136: quantity = new Double(this .getQuantity());
137: }
138:
139: Map issueMap = FastMap.newInstance();
140: issueMap.put("shipmentId", shipmentId);
141: issueMap.put("orderId", this .getOrderId());
142: issueMap.put("orderItemSeqId", this .getOrderItemSeqId());
143: issueMap.put("shipGroupSeqId", this .getShipGroupSeqId());
144: issueMap.put("inventoryItemId", this .getInventoryItemId());
145: issueMap.put("quantity", quantity);
146: issueMap.put("userLogin", userLogin);
147:
148: Map issueResp = dispatcher.runSync(
149: "issueOrderItemShipGrpInvResToShipment", issueMap);
150: if (ServiceUtil.isError(issueResp)) {
151: throw new GeneralException(ServiceUtil
152: .getErrorMessage(issueResp));
153: }
154:
155: String shipmentItemSeqId = (String) issueResp
156: .get("shipmentItemSeqId");
157: if (shipmentItemSeqId == null) {
158: throw new GeneralException(
159: "Issue item did not return a valid shipmentItemSeqId!");
160: } else {
161: this .setShipmentItemSeqId(shipmentItemSeqId);
162: }
163:
164: if (picklistBinId != null) {
165: // find the pick list item
166: Debug.log("Looking up picklist item for bin ID #"
167: + picklistBinId, module);
168: GenericDelegator delegator = dispatcher.getDelegator();
169: Map itemLookup = FastMap.newInstance();
170: itemLookup.put("picklistBinId", picklistBinId);
171: itemLookup.put("orderId", this .getOrderId());
172: itemLookup.put("orderItemSeqId", this .getOrderItemSeqId());
173: itemLookup.put("shipGroupSeqId", this .getShipGroupSeqId());
174: itemLookup
175: .put("inventoryItemId", this .getInventoryItemId());
176: GenericValue plItem = delegator.findByPrimaryKey(
177: "PicklistItem", itemLookup);
178: if (plItem != null) {
179: Debug.log("Found picklist bin: " + plItem, module);
180: Double itemQty = plItem.getDouble("quantity");
181: if (itemQty.doubleValue() == quantity.doubleValue()) {
182: // set to complete
183: itemLookup
184: .put("itemStatusId", "PICKITEM_COMPLETED");
185: } else {
186: itemLookup
187: .put("itemStatusId", "PICKITEM_CANCELLED");
188: }
189: itemLookup.put("userLogin", userLogin);
190:
191: Map itemUpdateResp = dispatcher.runSync(
192: "updatePicklistItem", itemLookup);
193: if (ServiceUtil.isError(itemUpdateResp)) {
194: throw new GeneralException(ServiceUtil
195: .getErrorMessage(issueResp));
196: }
197: } else {
198: Debug.log(
199: "No item was found for lookup: " + itemLookup,
200: module);
201: }
202: } else {
203: Debug
204: .logWarning(
205: "*** NO Picklist Bin ID set; cannot update picklist status!",
206: module);
207: }
208: }
209:
210: protected void applyLineToPackage(String shipmentId,
211: GenericValue userLogin, LocalDispatcher dispatcher)
212: throws GeneralException {
213: // assign item to package
214: String shipmentPackageSeqId = UtilFormatOut.formatPaddedNumber(
215: this .getPackageSeq(), 5);
216:
217: Map packageMap = FastMap.newInstance();
218: packageMap.put("shipmentId", shipmentId);
219: packageMap
220: .put("shipmentItemSeqId", this .getShipmentItemSeqId());
221: packageMap.put("quantity", new Double(this .getQuantity()));
222: packageMap.put("shipmentPackageSeqId", shipmentPackageSeqId);
223: packageMap.put("userLogin", userLogin);
224: Map packageResp = dispatcher.runSync(
225: "addShipmentContentToPackage", packageMap);
226:
227: if (ServiceUtil.isError(packageResp)) {
228: throw new GeneralException(ServiceUtil
229: .getErrorMessage(packageResp));
230: }
231: }
232: }
|