⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        }        if (productStore != null) {            isImmediatelyFulfilled = "Y".equals(productStore.getString("isImmediatelyFulfilled"));        }        boolean reserveInventory = ("SALES_ORDER".equals(orderTypeId));        if (reserveInventory && isImmediatelyFulfilled) {            // don't reserve inventory if the product store has isImmediatelyFulfilled set, ie don't if in this store things are immediately fulfilled            reserveInventory = false;        }        if (reserveInventory) {            // START inventory reservation            // decrement inventory available for each OrderItemShipGroupAssoc, within the same transaction            if (orderItemShipGroupInfo != null && orderItemShipGroupInfo.size() > 0) {                Iterator osiInfos = orderItemShipGroupInfo.iterator();                while (osiInfos.hasNext()) {                    GenericValue orderItemShipGroupAssoc = (GenericValue) osiInfos.next();                    if ("OrderItemShipGroupAssoc".equals(orderItemShipGroupAssoc.getEntityName())) {                        GenericValue orderItem = (GenericValue) itemValuesBySeqId.get(orderItemShipGroupAssoc.get("orderItemSeqId"));                        String itemStatus = orderItem.getString("statusId");                        if ("ITEM_REJECTED".equals(itemStatus) || "ITEM_CANCELLED".equals(itemStatus) || "ITEM_COMPLETED".equals(itemStatus)) {                            Debug.logInfo("Order item [" + orderItem.getString("orderId") + " / " + orderItem.getString("orderItemSeqId") + "] is not in a proper status for reservation", module);                            continue;                        }                        if (UtilValidate.isNotEmpty(orderItem.getString("productId")) && !"RENTAL_ORDER_ITEM".equals(orderItem.getString("orderItemTypeId")))                        { // ignore for rental                            // only reserve product items; ignore non-product items                            try {                                Map reserveInput = new HashMap();                                reserveInput.put("productStoreId", productStoreId);                                reserveInput.put("productId", orderItem.getString("productId"));                                reserveInput.put("orderId", orderItem.getString("orderId"));                                reserveInput.put("orderItemSeqId", orderItem.getString("orderItemSeqId"));                                reserveInput.put("shipGroupSeqId", orderItemShipGroupAssoc.getString("shipGroupSeqId"));                                // use the quantity from the orderItemShipGroupAssoc, NOT the orderItem, these are reserved by item-group assoc                                reserveInput.put("quantity", orderItemShipGroupAssoc.getDouble("quantity"));                                reserveInput.put("userLogin", userLogin);                                Map reserveResult = dispatcher.runSync("reserveStoreInventory", reserveInput);                                if (ServiceUtil.isError(reserveResult)) {                                    GenericValue product = null;                                    try {                                        product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", orderItem.getString("productId")));                                    } catch (GenericEntityException e) {                                        Debug.logError(e, "Error when looking up product in createOrder service, product failed inventory reservation", module);                                    }                                    String invErrMsg = "The product ";                                    if (product != null) {                                        invErrMsg += getProductName(product, orderItem);                                    }                                    invErrMsg += " with ID " + orderItem.getString("productId") + " is no longer in stock. Please try reducing the quantity or removing the product from this order.";                                    resErrorMessages.add(invErrMsg);                                }                            } catch (GenericServiceException e) {                                String errMsg = "Fatal error calling reserveStoreInventory service: " + e.toString();                                Debug.logError(e, errMsg, module);                                resErrorMessages.add(errMsg);                            }                        }                    }                }            }        }    }    public static String getProductName(GenericValue product, GenericValue orderItem) {        if (UtilValidate.isNotEmpty(product.getString("productName"))) {            return product.getString("productName");        } else {            return orderItem.getString("itemDescription");        }    }    public static String getProductName(GenericValue product, String orderItemName) {        if (UtilValidate.isNotEmpty(product.getString("productName"))) {            return product.getString("productName");        } else {            return orderItemName;        }    }    public static String determineSingleFacilityFromOrder(GenericValue orderHeader) {        if (orderHeader != null) {            String productStoreId = orderHeader.getString("productStoreId");            if (productStoreId != null) {                return ProductStoreWorker.determineSingleFacilityForStore(orderHeader.getDelegator(), productStoreId);            }        }        return null;    }    /** Service for resetting the OrderHeader grandTotal */    public static Map resetGrandTotal(DispatchContext ctx, Map context) {        GenericDelegator delegator = ctx.getDelegator();        //appears to not be used: GenericValue userLogin = (GenericValue) context.get("userLogin");        String orderId = (String) context.get("orderId");        GenericValue orderHeader = null;        try {            orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));        } catch (GenericEntityException e) {            String errMsg = "ERROR: Could not set grantTotal on OrderHeader entity: " + e.toString();            Debug.logError(e, errMsg, module);            return ServiceUtil.returnError(errMsg);        }        if (orderHeader != null) {            OrderReadHelper orh = new OrderReadHelper(orderHeader);            Double currentTotal = orderHeader.getDouble("grandTotal");            Double currentSubTotal = orderHeader.getDouble("remainingSubTotal");            // get the new grand total            double updatedTotal = orh.getOrderGrandTotal();            // calculate subTotal as grandTotal - returnsTotal - (tax + shipping of items not returned)            double remainingSubTotal = updatedTotal - orh.getOrderReturnedTotal() - orh.getOrderNonReturnedTaxAndShipping();            if (currentTotal == null || currentSubTotal == null || updatedTotal != currentTotal.doubleValue() ||                    remainingSubTotal != currentSubTotal.doubleValue()) {                orderHeader.set("grandTotal", UtilFormatOut.formatPriceNumber(updatedTotal));                orderHeader.set("remainingSubTotal", UtilFormatOut.formatPriceNumber(remainingSubTotal));                try {                    orderHeader.store();                } catch (GenericEntityException e) {                    String errMsg = "ERROR: Could not set grandTotal on OrderHeader entity: " + e.toString();                    Debug.logError(e, errMsg, module);                    return ServiceUtil.returnError(errMsg);                }            }        }        return ServiceUtil.returnSuccess();    }    /** Service for setting the OrderHeader grandTotal for all OrderHeaders with no grandTotal */    public static Map setEmptyGrandTotals(DispatchContext ctx, Map context) {        GenericDelegator delegator = ctx.getDelegator();        LocalDispatcher dispatcher = ctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Boolean forceAll = (Boolean) context.get("forceAll");        Locale locale = (Locale) context.get("locale");        if (forceAll == null) {            forceAll = new Boolean(false);        }        EntityCondition cond = null;        if (!forceAll.booleanValue()) {            List exprs = UtilMisc.toList(new EntityExpr("grandTotal", EntityOperator.EQUALS, null),                    new EntityExpr("remainingSubTotal", EntityOperator.EQUALS, null));            cond = new EntityConditionList(exprs, EntityOperator.OR);        }        List fields = UtilMisc.toList("orderId");        EntityListIterator eli = null;        try {            eli = delegator.findListIteratorByCondition("OrderHeader", cond, fields, null);        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        if (eli != null) {            // reset each order            GenericValue orderHeader = null;            while ((orderHeader = (GenericValue) eli.next()) != null) {                String orderId = orderHeader.getString("orderId");                Map resetResult = null;                try {                    resetResult = dispatcher.runSync("resetGrandTotal", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));                } catch (GenericServiceException e) {                    Debug.logError(e, "ERROR: Cannot reset order totals - " + orderId, module);                }                if (resetResult != null && ServiceUtil.isError(resetResult)) {                    Debug.logWarning(UtilProperties.getMessage(resource_error,"OrderErrorCannotResetOrderTotals", UtilMisc.toMap("orderId",orderId,"resetResult",ServiceUtil.getErrorMessage(resetResult)), locale), module);                }            }            // close the ELI            try {                eli.close();            } catch (GenericEntityException e) {                Debug.logError(e, module);            }        } else {            Debug.logInfo("No orders found for reset processing", module);        }        return ServiceUtil.returnSuccess();    }    /** Service for checking and re-clac the tax amount */    public static Map recalcOrderTax(DispatchContext ctx, Map context) {        LocalDispatcher dispatcher = ctx.getDispatcher();        GenericDelegator delegator = ctx.getDelegator();        String orderId = (String) context.get("orderId");        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        // check and make sure we have permission to change the order        Security security = ctx.getSecurity();        if (!security.hasEntityPermission("ORDERMGR", "_UPDATE", userLogin)) {            GenericValue placingCustomer = null;            try {                Map placingCustomerFields = UtilMisc.toMap("orderId", orderId, "partyId", userLogin.getString("partyId"), "roleTypeId", "PLACING_CUSTOMER");                placingCustomer = delegator.findByPrimaryKey("OrderRole", placingCustomerFields);            } catch (GenericEntityException e) {                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCannotGetOrderRoleEntity ",locale) + e.getMessage());            }            if (placingCustomer == null)                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderYouDoNotHavePermissionToChangeThisOrdersStatus",locale));        }        // get the order header        GenericValue orderHeader = null;        try {            orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));        } catch (GenericEntityException e) {            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCannotGetOrderHeaderEntity",locale) + e.getMessage());        }        if (orderHeader == null) {            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorNoValidOrderHeaderFoundForOrderId", UtilMisc.toMap("orderId",orderId), locale));        }        // don't charge tax on purchase orders        if ("PURCHASE_ORDER".equals(orderHeader.getString("orderTypeId"))) {            return ServiceUtil.returnSuccess();        }        // remove the tax adjustments        int removed = 0;        try {           

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -