Search in sources :

Example 6 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class PackingSession method findOrderItemSeqId.

protected String findOrderItemSeqId(String productId, String orderId, String shipGroupSeqId, BigDecimal quantity) throws GeneralException {
    Map<String, Object> lookupMap = new HashMap<String, Object>();
    lookupMap.put("orderId", orderId);
    lookupMap.put("productId", productId);
    lookupMap.put("statusId", "ITEM_APPROVED");
    lookupMap.put("shipGroupSeqId", shipGroupSeqId);
    List<String> sort = UtilMisc.toList("-quantity");
    List<GenericValue> orderItems = this.getDelegator().findByAnd("OrderItemAndShipGroupAssoc", lookupMap, sort, false);
    String orderItemSeqId = null;
    if (orderItems != null) {
        for (GenericValue item : orderItems) {
            // get the reservations for the item
            Map<String, Object> invLookup = new HashMap<String, Object>();
            invLookup.put("orderId", orderId);
            invLookup.put("orderItemSeqId", item.getString("orderItemSeqId"));
            invLookup.put("shipGroupSeqId", shipGroupSeqId);
            List<GenericValue> reservations = this.getDelegator().findByAnd("OrderItemShipGrpInvRes", invLookup, null, false);
            for (GenericValue res : reservations) {
                BigDecimal qty = res.getBigDecimal("quantity");
                if (quantity.compareTo(qty) <= 0) {
                    orderItemSeqId = item.getString("orderItemSeqId");
                    break;
                }
            }
        }
    }
    if (orderItemSeqId != null) {
        return orderItemSeqId;
    } else {
        throw new GeneralException("No valid order item found for product [" + productId + "] with quantity: " + quantity);
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal)

Example 7 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class PackingSession method checkReservations.

protected void checkReservations(boolean ignore) throws GeneralException {
    List<String> errors = new LinkedList<String>();
    for (PackingSessionLine line : this.getLines()) {
        BigDecimal reservedQty = this.getCurrentReservedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId());
        BigDecimal packedQty = this.getPackedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId());
        if (packedQty.compareTo(reservedQty) != 0) {
            errors.add("Packed amount does not match reserved amount for item (" + line.getProductId() + ") [" + packedQty + " / " + reservedQty + "]");
        }
    }
    if (errors.size() > 0) {
        if (!ignore) {
            throw new GeneralException("Attempt to pack order failed.", errors);
        } else {
            Debug.logWarning("Packing warnings: " + errors, module);
        }
    }
}
Also used : GeneralException(org.apache.ofbiz.base.util.GeneralException) LinkedList(java.util.LinkedList) BigDecimal(java.math.BigDecimal)

Example 8 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class PackingSession method addOrIncreaseLine.

public void addOrIncreaseLine(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, BigDecimal quantity, int packageSeqId, BigDecimal weight, boolean update) throws GeneralException {
    // reset the session if we just completed
    if (status == 0) {
        throw new GeneralException("Packing session has been completed; be sure to CLEAR before packing a new order! [000]");
    }
    // do nothing if we are trying to add a quantity of 0
    if (!update && quantity.compareTo(BigDecimal.ZERO) == 0) {
        return;
    }
    // find the actual product ID
    productId = ProductWorker.findProductId(this.getDelegator(), productId);
    // set the default null values - primary is the assumed first item
    if (orderId == null) {
        orderId = primaryOrderId;
    }
    if (shipGroupSeqId == null) {
        shipGroupSeqId = primaryShipGrp;
    }
    if (orderItemSeqId == null && productId != null) {
        orderItemSeqId = this.findOrderItemSeqId(productId, orderId, shipGroupSeqId, quantity);
    }
    // get the reservations for the item
    Map<String, Object> invLookup = new HashMap<String, Object>();
    invLookup.put("orderId", orderId);
    invLookup.put("orderItemSeqId", orderItemSeqId);
    invLookup.put("shipGroupSeqId", shipGroupSeqId);
    List<GenericValue> reservations = this.getDelegator().findByAnd("OrderItemShipGrpInvRes", invLookup, UtilMisc.toList("quantity DESC"), false);
    // no reservations we cannot add this item
    if (UtilValidate.isEmpty(reservations)) {
        throw new GeneralException("No inventory reservations available; cannot pack this item! [101]");
    }
    // find the inventoryItemId to use
    if (reservations.size() == 1) {
        GenericValue res = EntityUtil.getFirst(reservations);
        int checkCode = this.checkLineForAdd(res, orderId, orderItemSeqId, shipGroupSeqId, productId, quantity, packageSeqId, update);
        this.createPackLineItem(checkCode, res, orderId, orderItemSeqId, shipGroupSeqId, productId, quantity, weight, packageSeqId);
    } else {
        // more than one reservation found
        Map<GenericValue, BigDecimal> toCreateMap = new HashMap<GenericValue, BigDecimal>();
        Iterator<GenericValue> i = reservations.iterator();
        BigDecimal qtyRemain = quantity;
        while (i.hasNext() && qtyRemain.compareTo(BigDecimal.ZERO) > 0) {
            GenericValue res = i.next();
            // Check that the inventory item product match with the current product to pack
            if (!productId.equals(res.getRelatedOne("InventoryItem", false).getString("productId"))) {
                continue;
            }
            BigDecimal resQty = res.getBigDecimal("quantity");
            BigDecimal resPackedQty = this.getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId, res.getString("inventoryItemId"), -1);
            if (resPackedQty.compareTo(resQty) >= 0) {
                continue;
            } else if (!update) {
                resQty = resQty.subtract(resPackedQty);
            }
            BigDecimal thisQty = resQty.compareTo(qtyRemain) > 0 ? qtyRemain : resQty;
            int thisCheck = this.checkLineForAdd(res, orderId, orderItemSeqId, shipGroupSeqId, productId, thisQty, packageSeqId, update);
            switch(thisCheck) {
                case 2:
                    Debug.logInfo("Packing check returned '2' - new pack line will be created!", module);
                    toCreateMap.put(res, thisQty);
                    qtyRemain = qtyRemain.subtract(thisQty);
                    break;
                case 1:
                    Debug.logInfo("Packing check returned '1' - existing pack line has been updated!", module);
                    qtyRemain = qtyRemain.subtract(thisQty);
                    break;
                case 0:
                    Debug.logInfo("Packing check returned '0' - doing nothing.", module);
                    break;
                default:
                    Debug.logInfo("Packing check returned '> 2' or '< 0'", module);
                    break;
            }
        }
        if (qtyRemain.compareTo(BigDecimal.ZERO) == 0) {
            for (Map.Entry<GenericValue, BigDecimal> entry : toCreateMap.entrySet()) {
                GenericValue res = entry.getKey();
                BigDecimal qty = entry.getValue();
                this.createPackLineItem(2, res, orderId, orderItemSeqId, shipGroupSeqId, productId, qty, weight, packageSeqId);
            }
        } else {
            throw new GeneralException("Not enough inventory reservation available; cannot pack the item! [103]");
        }
    }
    // run the add events
    this.runEvents(PackingEvent.EVENT_CODE_ADD);
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 9 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class PackingSessionLine method issueItemToShipment.

protected void issueItemToShipment(String shipmentId, String picklistBinId, GenericValue userLogin, BigDecimal quantity, LocalDispatcher dispatcher) throws GeneralException {
    if (quantity == null) {
        quantity = this.getQuantity();
    }
    Map<String, Object> issueMap = new HashMap<String, Object>();
    issueMap.put("shipmentId", shipmentId);
    issueMap.put("orderId", this.getOrderId());
    issueMap.put("orderItemSeqId", this.getOrderItemSeqId());
    issueMap.put("shipGroupSeqId", this.getShipGroupSeqId());
    issueMap.put("inventoryItemId", this.getInventoryItemId());
    issueMap.put("quantity", quantity);
    issueMap.put("userLogin", userLogin);
    Map<String, Object> issueResp = dispatcher.runSync("issueOrderItemShipGrpInvResToShipment", issueMap);
    if (ServiceUtil.isError(issueResp)) {
        throw new GeneralException(ServiceUtil.getErrorMessage(issueResp));
    }
    String shipmentItemSeqId = (String) issueResp.get("shipmentItemSeqId");
    if (shipmentItemSeqId == null) {
        throw new GeneralException("Issue item did not return a valid shipmentItemSeqId!");
    } else {
        this.setShipmentItemSeqId(shipmentItemSeqId);
    }
    if (picklistBinId != null) {
        // find the pick list item
        Debug.logInfo("Looking up picklist item for bin ID #" + picklistBinId, module);
        Delegator delegator = dispatcher.getDelegator();
        Map<String, Object> itemLookup = new HashMap<String, Object>();
        itemLookup.put("picklistBinId", picklistBinId);
        itemLookup.put("orderId", this.getOrderId());
        itemLookup.put("orderItemSeqId", this.getOrderItemSeqId());
        itemLookup.put("shipGroupSeqId", this.getShipGroupSeqId());
        itemLookup.put("inventoryItemId", this.getInventoryItemId());
        GenericValue plItem = EntityQuery.use(delegator).from("PicklistItem").where(itemLookup).queryOne();
        if (plItem != null) {
            Debug.logInfo("Found picklist bin: " + plItem, module);
            BigDecimal itemQty = plItem.getBigDecimal("quantity");
            if (itemQty.compareTo(quantity) == 0) {
                // set to complete
                itemLookup.put("itemStatusId", "PICKITEM_COMPLETED");
            } else {
                itemLookup.put("itemStatusId", "PICKITEM_CANCELLED");
            }
            itemLookup.put("userLogin", userLogin);
            Map<String, Object> itemUpdateResp = dispatcher.runSync("updatePicklistItem", itemLookup);
            if (ServiceUtil.isError(itemUpdateResp)) {
                throw new GeneralException(ServiceUtil.getErrorMessage(issueResp));
            }
        } else {
            Debug.logInfo("No item was found for lookup: " + itemLookup, module);
        }
    } else {
        Debug.logWarning("*** NO Picklist Bin ID set; cannot update picklist status!", module);
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal)

Example 10 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class VerifyPickSession method checkVerifiedQty.

protected void checkVerifiedQty(String orderId, Locale locale) throws GeneralException {
    BigDecimal verifiedQty = BigDecimal.ZERO;
    BigDecimal orderedQty = BigDecimal.ZERO;
    List<GenericValue> orderItems = this.getDelegator().findByAnd("OrderItem", UtilMisc.toMap("orderId", orderId, "statusId", "ITEM_APPROVED"), null, false);
    for (GenericValue orderItem : orderItems) {
        orderedQty = orderedQty.add(orderItem.getBigDecimal("quantity"));
    }
    for (VerifyPickSessionRow pickRow : this.getPickRows(orderId)) {
        verifiedQty = verifiedQty.add(pickRow.getReadyToVerifyQty());
    }
    if (orderedQty.compareTo(verifiedQty) != 0) {
        throw new GeneralException(UtilProperties.getMessage("ProductErrorUiLabels", "ProductErrorAllOrderItemsAreNotVerified", locale));
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) BigDecimal(java.math.BigDecimal)

Aggregations

GeneralException (org.apache.ofbiz.base.util.GeneralException)216 GenericValue (org.apache.ofbiz.entity.GenericValue)133 Delegator (org.apache.ofbiz.entity.Delegator)101 Locale (java.util.Locale)81 HashMap (java.util.HashMap)71 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)68 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)68 IOException (java.io.IOException)65 BigDecimal (java.math.BigDecimal)55 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)54 Writer (java.io.Writer)29 LinkedList (java.util.LinkedList)29 Map (java.util.Map)29 Timestamp (java.sql.Timestamp)26 StringWriter (java.io.StringWriter)19 Environment (freemarker.core.Environment)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 ShoppingCart (org.apache.ofbiz.order.shoppingcart.ShoppingCart)14 HttpSession (javax.servlet.http.HttpSession)13 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)13