Author: sichen
Date: Thu Mar 15 10:36:49 2007 New Revision: 518702 URL: http://svn.apache.org/viewvc?view=rev&rev=518702 Log: Improvements to add/remove payment methods in order view. The payment amount field defaults to the open order amount, which is a new method in Order Read Helper. Replaced minilang service updateOrderPaymentPreference with an improved java version. Changed the requests to request-redirect to avoid adding the payment method again if user hits refresh. Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml ofbiz/trunk/applications/order/servicedef/services.xml ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml ofbiz/trunk/applications/order/webapp/ordermgr/order/orderpaymentinfo.ftl Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml?view=diff&rev=518702&r1=518701&r2=518702 ============================================================================== --- ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml (original) +++ ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml Thu Mar 15 10:36:49 2007 @@ -491,54 +491,6 @@ <set-nonpk-fields value-name="orderHeader" map-name="parameters"/> <store-value value-name="orderHeader"/> </simple-method> - <simple-method method-name="updateOrderPaymentPreference" short-description="Update an order payment preference record"> - <check-permission permission="ORDERMGR" action="_UPDATE"> - <fail-message message="ERROR: Not enough permissions to update this record."/> - </check-permission> - <check-errors/> - - <entity-one entity-name="OrderPaymentPreference" value-name="opp"> - <field-map field-name="orderPaymentPreferenceId" env-name="parameters.orderPaymentPreferenceId"/> - </entity-one> - - <log level="always" message="Parameters - ${parameters}"/> - <if-not-empty field-name="checkOutPaymentId" map-name="parameters"> - <if-regexp map-name="parameters" field-name="checkOutPaymentId" expr="\d+"> - <log level="info" message="PaymentMethod found: ${parameters.checkOutPaymentId}"/> - <set field="parameters.paymentMethodId" from-field="parameters.checkOutPaymentId"/> - <entity-one entity-name="PaymentMethod" value-name="paymentMethod"> - <field-map field-name="paymentMethodId" env-name="parameters.checkOutPaymentId"/> - </entity-one> - <set field="parameters.paymentMethodTypeId" from-field="paymentMethod.paymentMethodTypeId"/> - <else> - <log level="info" message="PaymentMethodType found: ${parameters.checkOutPaymentId}"/> - <set field="parameters.paymentMethodTypeId" from-field="parameters.checkOutPaymentId"/> - </else> - </if-regexp> - </if-not-empty> - - <if-compare field-name="parameters.cancelThis" operator="not-equals" value="true"> - <log level="always" message="Cancel not set; updating..."/> - <clone-value value-name="opp" new-value-name="newOpp"/> - <set field="opp.statusId" value="PAYMENT_CANCELLED"/> - <store-value value-name="opp"/> - - <sequenced-id-to-env sequence-name="OrderPaymentPreference" env-name="payPrefId"/> - <set field="newOpp.orderPaymentPreferenceId" from-field="payPrefId"/> - <set field="newOpp.paymentMethodTypeId" set-if-null="true"/> - <set field="newOpp.paymentMethodId" set-if-null="true"/> - <set field="newOpp.createdByUserLogin" from-field="userLogin.userLoginId"/> - <set-nonpk-fields value-name="newOpp" map-name="parameters"/> - <create-value value-name="newOpp"/> - <field-to-result field-name="orderPaymentPreferenceId" map-name="newOpp" result-name="orderPaymentPreferenceId"/> - <else> - <log level="always" message="Cancel set; not updating..."/> - <set field="opp.statusId" value="PAYMENT_CANCELLED"/> - <store-value value-name="opp"/> - <field-to-result field-name="orderPaymentPreferenceId" map-name="opp" result-name="orderPaymentPreferenceId"/> - </else> - </if-compare> - </simple-method> <simple-method method-name="recreateOrderAdjustments" short-description="Auto create OrderAdjustments"> <check-permission permission="ORDERMGR" action="_CREATE"> Modified: ofbiz/trunk/applications/order/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?view=diff&rev=518702&r1=518701&r2=518702 ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services.xml Thu Mar 15 10:36:49 2007 @@ -294,8 +294,8 @@ <attribute name="orderId" type="String" mode="IN" optional="false"/> </service> - <service name="updateOrderPaymentPreference" engine="simple" auth="true" default-entity-name="OrderPaymentPreference" - location="org/ofbiz/order/order/OrderServices.xml" invoke="updateOrderPaymentPreference"> + <service name="updateOrderPaymentPreference" engine="java" auth="true" default-entity-name="OrderPaymentPreference" + location="org.ofbiz.order.order.OrderServices" invoke="updateOrderPaymentPreference"> <auto-attributes mode="INOUT" include="pk" optional="false"/> <auto-attributes mode="IN" include="nonpk" optional="true"/> <attribute name="checkOutPaymentId" type="String" mode="IN" optional="true"/> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?view=diff&rev=518702&r1=518701&r2=518702 ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Thu Mar 15 10:36:49 2007 @@ -1280,6 +1280,42 @@ return getOrderGrandTotalBd().doubleValue(); } + /** + * Gets the amount open on the order that is not covered by the relevant OrderPaymentPreferences. + * This works by adding up the amount allocated to each unprocessed OrderPaymentPreference and the + * amounts received as payments for the settled ones. + */ + public double getOrderOpenAmount() throws GenericEntityException { + GenericDelegator delegator = orderHeader.getDelegator(); + double total = getOrderGrandTotal(); + double openAmount = 0; + List prefs = getPaymentPreferences(); + + // add up the covered amount, but skip preferences which are declined or cancelled + for (Iterator iter = prefs.iterator(); iter.hasNext(); ) { + GenericValue pref = (GenericValue) iter.next(); + if ("PAYMENT_CANCELLED".equals(pref.get("statusId")) || "PAYMENT_DECLINED".equals(pref.get("statusId"))) { + continue; + } else if ("PAYMENT_SETTLED".equals(pref.get("statusId"))) { + List responses = pref.getRelatedByAnd("PaymentGatewayResponse", UtilMisc.toMap("transCodeEnumId", "PGT_CAPTURE")); + for (Iterator respIter = responses.iterator(); respIter.hasNext(); ) { + GenericValue response = (GenericValue) respIter.next(); + Double amount = response.getDouble("amount"); + if (amount != null) { + openAmount += amount.doubleValue(); + } + } + } else { + // all others are currently "unprocessed" payment preferences + Double maxAmount = pref.getDouble("maxAmount"); + if (maxAmount != null) { + openAmount += maxAmount.doubleValue(); + } + } + } + return total - openAmount; + } + public List getOrderHeaderAdjustments() { return getOrderHeaderAdjustments(getAdjustments(), null); } Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?view=diff&rev=518702&r1=518701&r2=518702 ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Thu Mar 15 10:36:49 2007 @@ -3706,4 +3706,60 @@ return ServiceUtil.returnSuccess(); } + public static Map updateOrderPaymentPreference(DispatchContext dctx, Map context) { + GenericDelegator delegator = dctx.getDelegator(); + LocalDispatcher dispatcher = dctx.getDispatcher(); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + + String orderPaymentPreferenceId = (String) context.get("orderPaymentPreferenceId"); + String checkOutPaymentId = (String) context.get("checkOutPaymentId"); + boolean cancelThis = ("true".equals((String) context.get("cancelThis"))); + try { + GenericValue opp = delegator.findByPrimaryKey("OrderPaymentPreference", UtilMisc.toMap("orderPaymentPreferenceId", orderPaymentPreferenceId)); + String paymentMethodId = null; + String paymentMethodTypeId = null; + + // The checkOutPaymentId is either a paymentMethodId or paymentMethodTypeId + // the original method did a "\d+" regexp to decide which is the case, this version is more explicit with its lookup of PaymentMethodType + if (checkOutPaymentId != null) { + List paymentMethodTypes = delegator.findAllCache("PaymentMethodType"); + for (Iterator iter = paymentMethodTypes.iterator(); iter.hasNext(); ) { + GenericValue type = (GenericValue) iter.next(); + if (type.get("paymentMethodTypeId").equals(checkOutPaymentId)) { + paymentMethodTypeId = (String) type.get("paymentMethodTypeId"); + break; + } + } + if (paymentMethodTypeId == null) { + GenericValue method = delegator.findByPrimaryKey("PaymentMethod", UtilMisc.toMap("paymentMethodTypeId", paymentMethodTypeId)); + paymentMethodId = checkOutPaymentId; + paymentMethodTypeId = (String) method.get("paymentMethodTypeId"); + } + } + + Map results = ServiceUtil.returnSuccess(); + if (cancelThis) { + opp.set("statusId", "PAYMENT_CANCELLED"); + opp.store(); + results.put("orderPaymentPreferenceId", opp.get("orderPaymentPreferenceId")); + } else { + GenericValue newOpp = (GenericValue) opp.clone(); + opp.set("statusId", "PAYMENT_CANCELLED"); + opp.store(); + + newOpp.set("orderPaymentPreferenceId", delegator.getNextSeqId("OrderPaymentPreference")); + newOpp.set("paymentMethodId", paymentMethodId); + newOpp.set("paymentMethodTypeId", paymentMethodTypeId); + newOpp.setNonPKFields(context); + newOpp.create(); + results.put("orderPaymentPreferenceId", newOpp.get("orderPaymentPreferenceId")); + } + + return results; + } catch (GenericEntityException e) { + Debug.logError(e, module); + return ServiceUtil.returnError(e.getMessage()); + } + } + } Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml?view=diff&rev=518702&r1=518701&r2=518702 ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml Thu Mar 15 10:36:49 2007 @@ -1401,14 +1401,14 @@ <request-map uri="authOrderPayment"> <security https="true" auth="true"/> <event type="service" path="" invoke="authOrderPaymentPreference"/> - <response name="success" type="view" value="orderview"/> + <response name="success" type="request-redirect" value="orderview"/> </request-map> <request-map uri="updateOrderPaymentPreference"> <security https="true" auth="true"/> <event type="service" invoke="updateOrderPaymentPreference"/> - <response name="success" type="view" value="orderview"/> - <response name="error" type="view" value="orderview"/> + <response name="success" type="request-redirect" value="orderview"/> + <response name="error" type="request-redirect" value="orderview"/> </request-map> <!-- Lookup request mappings --> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/order/orderpaymentinfo.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/orderpaymentinfo.ftl?view=diff&rev=518702&r1=518701&r2=518702 ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/order/orderpaymentinfo.ftl (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/order/orderpaymentinfo.ftl Thu Mar 15 10:36:49 2007 @@ -340,11 +340,12 @@ </select> </td> </tr> + <#assign openAmount = orderReadHelper.getOrderOpenAmount()> <tr> <td width="20%" align="right"><div class="tableheadtext">${uiLabelMap.AccountingAmount} </div></td> <td width="2%"> </td> <td nowrap> - <input type="text" class="inputBox" name="maxAmount"/> + <input type="text" class="inputBox" name="maxAmount" value="${openAmount}"/> </td> </tr> <tr> |
Free forum by Nabble | Edit this page |