Search in sources :

Example 11 with GenericValue

use of org.apache.ofbiz.entity.GenericValue in project ofbiz-framework by apache.

the class PackingSession method getCurrentShippedQuantity.

public BigDecimal getCurrentShippedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId) {
    BigDecimal shipped = BigDecimal.ZERO;
    List<GenericValue> issues = this.getItemIssuances(orderId, orderItemSeqId, shipGroupSeqId);
    if (issues != null) {
        for (GenericValue v : issues) {
            BigDecimal qty = v.getBigDecimal("quantity");
            if (qty == null)
                qty = BigDecimal.ZERO;
            shipped = shipped.add(qty);
        }
    }
    return shipped;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) BigDecimal(java.math.BigDecimal)

Example 12 with GenericValue

use of org.apache.ofbiz.entity.GenericValue 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 13 with GenericValue

use of org.apache.ofbiz.entity.GenericValue in project ofbiz-framework by apache.

the class PackingSession method addItemInfo.

public void addItemInfo(List<GenericValue> infos) {
    for (GenericValue v : infos) {
        ItemDisplay newItem = new ItemDisplay(v);
        int currentIdx = itemInfos.indexOf(newItem);
        if (currentIdx != -1) {
            ItemDisplay existingItem = itemInfos.get(currentIdx);
            existingItem.quantity = existingItem.quantity.add(newItem.quantity);
        } else {
            itemInfos.add(newItem);
        }
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue)

Example 14 with GenericValue

use of org.apache.ofbiz.entity.GenericValue in project ofbiz-framework by apache.

the class PackingSession method updateShipmentRouteSegments.

protected void updateShipmentRouteSegments() throws GeneralException {
    BigDecimal shipmentWeight = getTotalWeight();
    if (shipmentWeight.compareTo(BigDecimal.ZERO) <= 0)
        return;
    List<GenericValue> shipmentRouteSegments = getDelegator().findByAnd("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", this.getShipmentId()), null, false);
    if (!UtilValidate.isEmpty(shipmentRouteSegments)) {
        for (GenericValue shipmentRouteSegment : shipmentRouteSegments) {
            shipmentRouteSegment.set("billingWeight", shipmentWeight);
            shipmentRouteSegment.set("billingWeightUomId", getWeightUomId());
        }
        getDelegator().storeAll(shipmentRouteSegments);
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) BigDecimal(java.math.BigDecimal)

Example 15 with GenericValue

use of org.apache.ofbiz.entity.GenericValue 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)

Aggregations

GenericValue (org.apache.ofbiz.entity.GenericValue)1422 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)871 Delegator (org.apache.ofbiz.entity.Delegator)721 Locale (java.util.Locale)505 HashMap (java.util.HashMap)463 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)370 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)356 BigDecimal (java.math.BigDecimal)338 LinkedList (java.util.LinkedList)312 Timestamp (java.sql.Timestamp)202 GeneralException (org.apache.ofbiz.base.util.GeneralException)168 Map (java.util.Map)155 IOException (java.io.IOException)116 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)97 HttpSession (javax.servlet.http.HttpSession)89 ArrayList (java.util.ArrayList)69 Security (org.apache.ofbiz.security.Security)69 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)59 List (java.util.List)56 EntityExpr (org.apache.ofbiz.entity.condition.EntityExpr)52