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

📄 orderreturnservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                GenericValue returnStatus = delegator.makeValue("ReturnStatus", UtilMisc.toMap("returnStatusId", returnStatusId));                returnStatus.set("statusId", "RETURN_COMPLETED");                returnStatus.set("returnId", returnId);                returnStatus.set("statusDatetime", now);                toStore.add(returnStatus);                try {                    delegator.storeAll(toStore);                } catch (GenericEntityException e) {                    Debug.logError(e, module);                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToCreateReturnStatusHistory", locale));                }            }        }        Map result = ServiceUtil.returnSuccess();        result.put("statusId", returnHeader.get("statusId"));        return result;    }    // credit (billingAccount) return    public static Map processCreditReturn(DispatchContext dctx, Map context) {        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericDelegator delegator = dctx.getDelegator();        String returnId = (String) context.get("returnId");        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        GenericValue returnHeader = null;        List returnItems = null;        try {            returnHeader = delegator.findByPrimaryKey("ReturnHeader", UtilMisc.toMap("returnId", returnId));            if (returnHeader != null) {                returnItems = returnHeader.getRelatedByAnd("ReturnItem", UtilMisc.toMap("returnTypeId", "RTN_CREDIT"));            }        } catch (GenericEntityException e) {            Debug.logError(e, "Problems looking up return information", module);            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorGettingReturnHeaderItemInformation", locale));        }        if (returnHeader != null && returnItems != null && returnItems.size() > 0) {            String billingAccountId = returnHeader.getString("billingAccountId");            String fromPartyId = returnHeader.getString("fromPartyId");            String toPartyId = returnHeader.getString("toPartyId");                        // make sure total refunds on a return don't exceed amount of returned orders            Map serviceResult = null;            try {                serviceResult = dispatcher.runSync("checkPaymentAmountForRefund", UtilMisc.toMap("returnId", returnId));            } catch (GenericServiceException e) {                Debug.logError(e, "Problem running the checkPaymentAmountForRefund service", module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemsWithCheckPaymentAmountForRefund", locale));                            }            if (ServiceUtil.isError(serviceResult)) {                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));            }                                    if (billingAccountId == null) {                // create new BillingAccount w/ 0 balance                try {                    // Note that accountLimit must be 0.0 for store credits, because the available balance of BillingAccounts is calculated as accountLimit + sum of Payments - sum of Invoices                    Map newBa = dispatcher.runSync("createBillingAccount", UtilMisc.toMap("accountLimit", new Double(0.00), "description", "Credit Account", "userLogin", userLogin, "accountCurrencyUomId", returnHeader.get("currencyUomId")));                    if (!newBa.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR)) {                        billingAccountId = (String) newBa.get("billingAccountId");                        if (billingAccountId != null) {                            // set the role on the account                            Map newBaR = dispatcher.runSync("createBillingAccountRole", UtilMisc.toMap("billingAccountId", billingAccountId, "partyId", fromPartyId, "roleTypeId", "BILL_TO_CUSTOMER", "userLogin", userLogin));                            if (newBaR.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR)) {                                Debug.logError("Error with createBillingAccountRole: " + newBaR.get(ModelService.ERROR_MESSAGE), module);                                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWithCreateBillingAccountRole", locale) + newBaR.get(ModelService.ERROR_MESSAGE));                            }                        }                    } else {                        Debug.logError("Error with createBillingAccount: " + newBa.get(ModelService.ERROR_MESSAGE), module);                        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWithCreateBillingAccount", locale) + newBa.get(ModelService.ERROR_MESSAGE));                    }                } catch (GenericServiceException e) {                    Debug.logError(e, "Problems creating BillingAccount", module);                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemsCreatingBillingAccount", locale));                }            }            // double check; make sure we have a billingAccount            if (billingAccountId == null) {                Debug.logError("No available billing account, none was created", module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderNoAvailableBillingAccount", locale));            }            // now; to be used for all timestamps            Timestamp now = UtilDateTime.nowTimestamp();            // first, compute the total credit from the return items            BigDecimal creditTotal = ZERO;            for (Iterator itemsIter = returnItems.iterator(); itemsIter.hasNext(); ) {                GenericValue item = (GenericValue) itemsIter.next();                BigDecimal quantity = item.getBigDecimal("returnQuantity");                BigDecimal price = item.getBigDecimal("returnPrice");                if (quantity == null) quantity = ZERO;                if (price == null) price = ZERO;                creditTotal = creditTotal.add(price.multiply(quantity).setScale(decimals, rounding));            }            // add the adjustments to the total            BigDecimal adjustments = new BigDecimal(getReturnAdjustmentTotal(delegator, UtilMisc.toMap("returnId", returnId)));            creditTotal = creditTotal.add(adjustments.setScale(decimals, rounding));            // create a Payment record for this credit; will look just like a normal payment            // However, since this payment is not a DISBURSEMENT or RECEIPT but really a matter of internal record            // it is of type "Other (Non-posting)"            String paymentId = delegator.getNextSeqId("Payment").toString();            GenericValue payment = delegator.makeValue("Payment", UtilMisc.toMap("paymentId", paymentId));            payment.set("paymentTypeId", "CUSTOMER_REFUND");            payment.set("paymentMethodTypeId", "EXT_BILLACT");            payment.set("partyIdFrom", toPartyId);  // if you receive a return FROM someone, then you'd have to give a return TO that person            payment.set("partyIdTo", fromPartyId);            payment.set("effectiveDate", now);            payment.set("amount", creditTotal);            payment.set("comments", "Return Credit");            payment.set("statusId", "PMNT_CONFIRMED");  // set the status to confirmed so nothing else can happen to the payment            try {                delegator.create(payment);            } catch (GenericEntityException e) {                Debug.logError(e, "Problem creating Payment record", module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemCreatingPaymentRecord", locale));            }            // create a return item response             Map itemResponse = UtilMisc.toMap("paymentId", paymentId);            itemResponse.put("billingAccountId", billingAccountId);            itemResponse.put("responseAmount", new Double(creditTotal.doubleValue()));            itemResponse.put("responseDate", now);            itemResponse.put("userLogin", userLogin);            Map serviceResults = null;            try {                serviceResults = dispatcher.runSync("createReturnItemResponse", itemResponse);                if (ServiceUtil.isError(serviceResults)) {                    return ServiceUtil.returnError("Could not create ReturnItemResponse record", null, null, serviceResults);                }            } catch (GenericServiceException e) {                Debug.logError(e, "Problem creating ReturnItemResponse record", module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemCreatingReturnItemResponseRecord", locale));            }            // the resulting response ID will be associated with the return items            String itemResponseId = (String) serviceResults.get("returnItemResponseId");            // loop through the items again to update them and store a status change history            List toBeStored = new ArrayList();            for (Iterator itemsIter = returnItems.iterator(); itemsIter.hasNext(); ) {                GenericValue item = (GenericValue) itemsIter.next();                // set the response on the item and flag the item to be stored                item.set("returnItemResponseId", itemResponseId);                item.set("statusId", "RETURN_COMPLETED");                toBeStored.add(item);                // create the status change history and set it to be stored                String returnStatusId = delegator.getNextSeqId("ReturnStatus").toString();                GenericValue returnStatus = delegator.makeValue("ReturnStatus", UtilMisc.toMap("returnStatusId", returnStatusId));                returnStatus.set("statusId", item.get("statusId"));                returnStatus.set("returnId", item.get("returnId"));                returnStatus.set("returnItemSeqId", item.get("returnItemSeqId"));                returnStatus.set("statusDatetime", now);                toBeStored.add(returnStatus);            }            // store the item changes (attached responseId)            try {                delegator.storeAll(toBeStored);            } catch (GenericEntityException e) {                Debug.logError(e, "Problem storing ReturnItem updates", module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemStoringReturnItemUpdates", locale));            }            // create the PaymentApplication for the billing account            String paId = delegator.getNextSeqId("PaymentApplication").toString();            GenericValue pa = delegator.makeValue("PaymentApplication", UtilMisc.toMap("paymentApplicationId", paId));            pa.set("paymentId", paymentId);            pa.set("billingAccountId", billingAccountId);            pa.set("amountApplied", creditTotal);            try {                delegator.create(pa);            } catch (GenericEntityException e) {                Debug.logError(e, "Problem creating PaymentApplication record for billing account", module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemCreatingPaymentApplicationRecord", locale));            }            // create the payment applications for the return invoice            try {                serviceResults = dispatcher.runSync("createPaymentApplicationsFromReturnItemResponse",                         UtilMisc.toMap("returnItemResponseId", itemResponseId, "userLogin", userLogin));                if (ServiceUtil.isError(serviceResults)) {                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemCreatingPaymentApplicationRecord", locale), null, null, serviceResults);                }            } catch (GenericServiceException e) {                Debug.logError(e, "Problem creating PaymentApplication records for return invoice", module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemCreatingPaymentApplicationRecord", locale));            }        }        return ServiceUtil.returnSuccess();    }    // refund (cash/charge) return    //TODO add adjustment total    public static Map processRefundReturn(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        String returnId = (String) context.get("returnId");        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        GenericValue returnHeader = null;        List returnItems = null;        try {            returnHeader = delegator.findByPrimaryKey("ReturnHeader", UtilMisc.toMap("returnId", returnId));            if (returnHeader != null) {                returnItems = returnHeader.getRelatedByAnd("ReturnItem", UtilMisc.toMap("returnTypeId", "RTN_REFUND"));            }        } catch (GenericEntityException e) {            Debug.logError(e, "Problems looking up return information", module);            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorGettingReturnHeaderItemInformation", locale));        }        if (returnHeader != null && returnItems != null && returnItems.size() > 0) {            Map itemsByOrder = new HashMap();            Map totalByOrder = new HashMap();                        // make sure total refunds on a return don't exceed amount of returned orders            Map serviceResult = null;            try {                serviceResult = dispatcher.runSync("checkPaymentAmountForRefund", UtilMisc.toMap("returnId", returnId));            } catch (GenericServiceException e){                Debug.logError(e, "Problem running the checkPaymentAmountForRefund service", module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemsWithCheckPaymentAmountForRefund", locale));                            }            if (ServiceUtil.isError(serviceResult)) {                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));            }                                                            groupReturnItemsByOrder(returnItems, itemsByOrder, totalByOrder, delegator, returnId);            // process each one by order            Set itemSet = itemsByOrder.entrySet();

⌨️ 快捷键说明

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