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

📄 paymentmethodservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            return ServiceUtil.returnError("ERROR: Could not update GiftCard info (id generation failure)");        }        newPm.set("partyId", partyId);        newPm.set("fromDate", context.get("fromDate"), false);        newPm.set("thruDate", context.get("thruDate"));        newPm.set("description",context.get("description"));        newGc.set("cardNumber", context.get("cardNumber"));        newGc.set("pinNumber", context.get("pinNumber"));        newGc.set("expireDate", context.get("expireDate"));        if (!newGc.equals(giftCard) || !newPm.equals(paymentMethod)) {            newPm.set("paymentMethodId", newPmId);            newGc.set("paymentMethodId", newPmId);            newPm.set("fromDate", (context.get("fromDate") != null ? context.get("fromDate") : now));            isModified = true;        }        if (isModified) {            // set thru date on old paymentMethod            paymentMethod.set("thruDate", now);            toBeStored.add(paymentMethod);            try {                delegator.storeAll(toBeStored);            } catch (GenericEntityException e) {                Debug.logWarning(e.getMessage(), module);                return ServiceUtil.returnError(                    "ERROR: Could not update EFT Account (write failure): " + e.getMessage());            }        } else {            result.put("newPaymentMethodId", paymentMethodId);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);            result.put(ModelService.SUCCESS_MESSAGE, "No changes made, not updating EFT Account");            return result;        }        result.put("newPaymentMethodId", newGc.getString("paymentMethodId"));        result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        return result;    }    /**     * Creates EftAccount and PaymentMethod entities according to the parameters passed in the context     * <b>security check</b>: userLogin partyId must equal partyId, or must have PAY_INFO_CREATE permission     * @param ctx The DispatchContext that this service is operating in     * @param context Map containing the input parameters     * @return Map with the result of the service, the output parameters     */    public static Map createEftAccount(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Timestamp now = UtilDateTime.nowTimestamp();        String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PAY_INFO", "_CREATE");        if (result.size() > 0) return result;        List toBeStored = new LinkedList();        GenericValue newPm = delegator.makeValue("PaymentMethod", null);        toBeStored.add(newPm);        GenericValue newEa = delegator.makeValue("EftAccount", null);        toBeStored.add(newEa);        String newPmId = null;        try {            newPmId = delegator.getNextSeqId("PaymentMethod");        } catch (IllegalArgumentException e) {            return ServiceUtil.returnError("ERROR: Could not create credit card (id generation failure)");        }        newPm.set("partyId", partyId);        newPm.set("fromDate", (context.get("fromDate") != null ? context.get("fromDate") : now));        newPm.set("thruDate", context.get("thruDate"));        newPm.set("description",context.get("description"));        newEa.set("bankName", context.get("bankName"));        newEa.set("routingNumber", context.get("routingNumber"));        newEa.set("accountType", context.get("accountType"));        newEa.set("accountNumber", context.get("accountNumber"));        newEa.set("nameOnAccount", context.get("nameOnAccount"));        newEa.set("companyNameOnAccount", context.get("companyNameOnAccount"));        newEa.set("contactMechId", context.get("contactMechId"));        newPm.set("paymentMethodId", newPmId);        newPm.set("paymentMethodTypeId", "EFT_ACCOUNT");        newEa.set("paymentMethodId", newPmId);        GenericValue newPartyContactMechPurpose = null;        String contactMechId = (String) context.get("contactMechId");        if (contactMechId != null && contactMechId.length() > 0) {            // add a PartyContactMechPurpose of BILLING_LOCATION if necessary            String contactMechPurposeTypeId = "BILLING_LOCATION";            GenericValue tempVal = null;            try {                List allPCMPs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",                        UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId), null), true);                tempVal = EntityUtil.getFirst(allPCMPs);            } catch (GenericEntityException e) {                Debug.logWarning(e.getMessage(), module);                tempVal = null;            }            if (tempVal == null) {                // no value found, create a new one                newPartyContactMechPurpose = delegator.makeValue("PartyContactMechPurpose",                 		UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId, "fromDate", now));            }        }        if (newPartyContactMechPurpose != null)            toBeStored.add(newPartyContactMechPurpose);        try {            delegator.storeAll(toBeStored);        } catch (GenericEntityException e) {            Debug.logWarning(e.getMessage(), module);            return ServiceUtil.returnError("ERROR: Could not create credit card (write failure): " + e.getMessage());        }        result.put("paymentMethodId", newEa.getString("paymentMethodId"));        result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        return result;    }    /**     * Updates EftAccount and PaymentMethod entities according to the parameters passed in the context     * <b>security check</b>: userLogin partyId must equal partyId, or must have PAY_INFO_UPDATE permission     * @param ctx The DispatchContext that this service is operating in     * @param context Map containing the input parameters     * @return Map with the result of the service, the output parameters     */    public static Map updateEftAccount(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Timestamp now = UtilDateTime.nowTimestamp();        String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PAY_INFO", "_UPDATE");        if (result.size() > 0) return result;        List toBeStored = new LinkedList();        boolean isModified = false;        GenericValue paymentMethod = null;        GenericValue newPm = null;        GenericValue eftAccount = null;        GenericValue newEa = null;        String paymentMethodId = (String) context.get("paymentMethodId");        try {            eftAccount = delegator.findByPrimaryKey("EftAccount", UtilMisc.toMap("paymentMethodId", paymentMethodId));            paymentMethod =                delegator.findByPrimaryKey("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId));        } catch (GenericEntityException e) {            Debug.logWarning(e.getMessage(), module);            return ServiceUtil.returnError(                "ERROR: Could not get EFT Account to update (read error): " + e.getMessage());        }        if (eftAccount == null || paymentMethod == null) {            return ServiceUtil.returnError("ERROR: Could not find EFT Account to update with id " + paymentMethodId);        }        if (!paymentMethod.getString("partyId").equals(partyId) && !security.hasEntityPermission("PAY_INFO", "_UPDATE", userLogin)) {            return ServiceUtil.returnError("Party Id [" + partyId + "] is not the owner of payment method [" + paymentMethodId + "] and does not have permission to change it.");        }         newPm = GenericValue.create(paymentMethod);        toBeStored.add(newPm);        newEa = GenericValue.create(eftAccount);        toBeStored.add(newEa);        String newPmId = null;        try {            newPmId = delegator.getNextSeqId("PaymentMethod");        } catch (IllegalArgumentException e) {            return ServiceUtil.returnError("ERROR: Could not update EFT Account info (id generation failure)");        }        newPm.set("partyId", partyId);        newPm.set("fromDate", context.get("fromDate"), false);        newPm.set("thruDate", context.get("thruDate"));        newPm.set("description",context.get("description"));        newEa.set("bankName", context.get("bankName"));        newEa.set("routingNumber", context.get("routingNumber"));        newEa.set("accountType", context.get("accountType"));        newEa.set("accountNumber", context.get("accountNumber"));        newEa.set("nameOnAccount", context.get("nameOnAccount"));        newEa.set("companyNameOnAccount", context.get("companyNameOnAccount"));        newEa.set("contactMechId", context.get("contactMechId"));        if (!newEa.equals(eftAccount) || !newPm.equals(paymentMethod)) {            newPm.set("paymentMethodId", newPmId);            newEa.set("paymentMethodId", newPmId);            newPm.set("fromDate", (context.get("fromDate") != null ? context.get("fromDate") : now));            isModified = true;        }        GenericValue newPartyContactMechPurpose = null;        String contactMechId = (String) context.get("contactMechId");        if (contactMechId != null && contactMechId.length() > 0) {            // add a PartyContactMechPurpose of BILLING_LOCATION if necessary            String contactMechPurposeTypeId = "BILLING_LOCATION";            GenericValue tempVal = null;            try {                List allPCMPs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",                     		UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId",contactMechPurposeTypeId), null), true);                tempVal = EntityUtil.getFirst(allPCMPs);            } catch (GenericEntityException e) {                Debug.logWarning(e.getMessage(), module);                tempVal = null;            }            if (tempVal == null) {                // no value found, create a new one                newPartyContactMechPurpose = delegator.makeValue("PartyContactMechPurpose",                        UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId, "fromDate", now));            }        }        if (isModified) {            // Debug.logInfo("yes, is modified", module);            if (newPartyContactMechPurpose != null)                toBeStored.add(newPartyContactMechPurpose);            // set thru date on old paymentMethod            paymentMethod.set("thruDate", now);            toBeStored.add(paymentMethod);            try {                delegator.storeAll(toBeStored);            } catch (GenericEntityException e) {                Debug.logWarning(e.getMessage(), module);                return ServiceUtil.returnError(                    "ERROR: Could not update EFT Account (write failure): " + e.getMessage());            }        } else {            result.put("newPaymentMethodId", paymentMethodId);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);            result.put(ModelService.SUCCESS_MESSAGE, "No changes made, not updating EFT Account");            return result;        }        result.put("newPaymentMethodId", newEa.getString("paymentMethodId"));        result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        return result;    }}

⌨️ 快捷键说明

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