📄 packingsession.java
字号:
PackingSessionLine line = this.findLine(orderId, orderItemSeqId, shipGroupSeqId, invItemId, packageSeqId); if (line == null) { Debug.log("No current line found testing [" + invItemId + "] R: " + resQty + " / Q: " + quantity, module); if (resQty < quantity) { return 0; } else { return 2; } } else { double newQty = line.getQuantity() + quantity; Debug.log("Existing line found testing [" + invItemId + "] R: " + resQty + " / Q: " + newQty, module); if (resQty < newQty) { return 0; } else { line.setQuantity(newQty); return 1; } } } public String getShipmentId() { return this.shipmentId; } public List getLines() { return this.packLines; } public int nextPackageSeq() { return ++packageSeq; } public int getCurrentPackageSeq() { return packageSeq; } public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId) { double total = 0.0; List lines = this.getLines(); Iterator i = lines.iterator(); while (i.hasNext()) { PackingSessionLine line = (PackingSessionLine) i.next(); if (orderId.equals(line.getOrderId()) && orderItemSeqId.equals(line.getOrderItemSeqId()) && shipGroupSeqId.equals(line.getShipGroupSeqId())) { total += line.getQuantity(); } } return total; } public void registerEvent(PackingEvent event) { this.packEvents.add(event); this.runEvents(PackingEvent.EVENT_CODE_EREG); } public LocalDispatcher getDispatcher() { if (_dispatcher == null) { try { _dispatcher = GenericDispatcher.getLocalDispatcher(dispatcherName, this.getDelegator()); } catch (GenericServiceException e) { throw new RuntimeException(e); } } return _dispatcher; } public GenericDelegator getDelegator() { if (_delegator == null) { _delegator = GenericDelegator.getGenericDelegator(delegatorName); } return _delegator; } public GenericValue getUserLogin() { return this.userLogin; } public int getStatus() { return this.status; } public String getFacilityId() { return this.facilityId; } public void setFacilityId(String facilityId) { this.facilityId = facilityId; } public String getPrimaryOrderId() { return this.primaryOrderId; } public void setPrimaryOrderId(String orderId) { this.primaryOrderId = orderId; } public String getPrimaryShipGroupSeqId() { return this.primaryShipGrp; } public void setPrimaryShipGroupSeqId(String shipGroupSeqId) { this.primaryShipGrp = shipGroupSeqId; } public String getHandlingInstructions() { return this.instructions; } public void setHandlingInstructions(String instructions) { this.instructions = instructions; } public void clearLine(PackingSessionLine line) { this.packLines.remove(line); } public void clear() { this.packLines.clear(); this.instructions = null; this.primaryOrderId = null; this.primaryShipGrp = null; this.packageSeq = 1; this.status = 1; this.runEvents(PackingEvent.EVENT_CODE_CLEAR); } public String complete(boolean force) throws GeneralException { if (this.getLines().size() == 0) { return "EMPTY"; } // check for errors this.checkReservations(force); // set the status to 0 this.status = 0; // create the shipment this.createShipment(); // create the packages this.createPackages(); // issue the items this.issueItemsToShipment(); // assign items to packages this.applyItemsToPackages(); // set the shipment to packed this.setShipmentToPacked(); // run the complete events this.runEvents(PackingEvent.EVENT_CODE_COMPLETE); return this.shipmentId; } protected void checkReservations(boolean ignore) throws GeneralException { List errors = FastList.newInstance(); Iterator i = this.getLines().iterator(); while (i.hasNext()) { PackingSessionLine line = (PackingSessionLine) i.next(); Map invLookup = FastMap.newInstance(); invLookup.put("orderId", line.getOrderId()); invLookup.put("orderItemSeqId", line.getOrderItemSeqId()); invLookup.put("shipGroupSeqId", line.getShipGroupSeqId()); invLookup.put("inventoryItemId", line.getInventoryItemId()); GenericValue res = this.getDelegator().findByPrimaryKey("OrderItemShipGrpInvRes", invLookup); Double qty = res.getDouble("quantity"); if (qty == null) qty = new Double(0); double resQty = qty.doubleValue(); double lineQty = line.getQuantity(); if (lineQty != resQty) { errors.add("Packed amount does not match reserved amount for item (" + line.getProductId() + ") [" + lineQty + " / " + resQty + "]"); } } if (errors.size() > 0) { if (!ignore) { throw new GeneralException("Attempt to pack order failed. Click COMPLETE again to force.", errors); } else { Debug.logWarning("Packing warnings: " + errors, module); } } } protected void runEvents(int eventCode) { if (this.packEvents.size() > 0) { Iterator i = this.packEvents.iterator(); while (i.hasNext()) { PackingEvent event = (PackingEvent) i.next(); event.runEvent(this, eventCode); } } } protected void createShipment() throws GeneralException { // first create the shipment Map newShipment = FastMap.newInstance(); newShipment.put("originFacilityId", this.facilityId); newShipment.put("primaryShipGroupSeqId", primaryShipGrp); newShipment.put("primaryOrderId", primaryOrderId); newShipment.put("shipmentTypeId", "OUTGOING_SHIPMENT"); newShipment.put("statusId", "SHIPMENT_INPUT"); newShipment.put("handlingInstructions", instructions); newShipment.put("userLogin", userLogin); Debug.log("Creating new shipment with context: " + newShipment, module); Map newShipResp = this.getDispatcher().runSync("createShipment", newShipment); if (ServiceUtil.isError(newShipResp)) { throw new GeneralException(ServiceUtil.getErrorMessage(newShipResp)); } this.shipmentId = (String) newShipResp.get("shipmentId"); } protected void issueItemsToShipment() throws GeneralException { List lines = this.getLines(); Iterator i = lines.iterator(); while (i.hasNext()) { PackingSessionLine line = (PackingSessionLine) i.next(); line.issueItemToShipment(shipmentId, userLogin, getDispatcher()); } } protected void createPackages() throws GeneralException { for (int i = 0; i < packageSeq; i++) { String shipmentPackageSeqId = UtilFormatOut.formatPaddedNumber(i+1, 5); Map pkgCtx = FastMap.newInstance(); pkgCtx.put("shipmentId", shipmentId); pkgCtx.put("shipmentPackageSeqId", shipmentPackageSeqId); //pkgCtx.put("shipmentBoxTypeId", ""); pkgCtx.put("userLogin", userLogin); Map newPkgResp = this.getDispatcher().runSync("createShipmentPackage", pkgCtx); if (ServiceUtil.isError(newPkgResp)) { throw new GeneralException(ServiceUtil.getErrorMessage(newPkgResp)); } } } protected void applyItemsToPackages() throws GeneralException { List lines = this.getLines(); Iterator i = lines.iterator(); while (i.hasNext()) { PackingSessionLine line = (PackingSessionLine) i.next(); line.applyLineToPackage(shipmentId, userLogin, getDispatcher()); } } protected void setShipmentToPacked() throws GeneralException { Map packedCtx = UtilMisc.toMap("shipmentId", shipmentId, "statusId", "SHIPMENT_PACKED", "userLogin", userLogin); Map packedResp = this.getDispatcher().runSync("updateShipment", packedCtx); if (packedResp != null && ServiceUtil.isError(packedResp)) { throw new GeneralException(ServiceUtil.getErrorMessage(packedResp)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -