svn commit: r598491 - in /ofbiz/trunk/applications/order: servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r598491 - in /ofbiz/trunk/applications/order: servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

apatel-2
Author: apatel
Date: Mon Nov 26 18:01:18 2007
New Revision: 598491

URL: http://svn.apache.org/viewvc?rev=598491&view=rev
Log:
Adding service for setting OrderPaymentStatus.

Modified:
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?rev=598491&r1=598490&r2=598491&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Mon Nov 26 18:01:18 2007
@@ -865,4 +865,11 @@
         <attribute name="numberOfProductsPerOrder" type="Integer" mode="IN" optional="true" default-value="5"/>
         <attribute name="salesChannel" type="String" mode="IN" optional="true"/>
     </service>
+    
+    <service name="changeOrderPaymentStatus" engine="java" auth="true"
+            location="org.ofbiz.order.order.OrderServices" invoke="setOrderPaymentStatus">
+        <description>Change the payment status of an existing order</description>
+        <attribute name="orderPaymentPreferenceId" type="String" mode="IN" optional="false"/>
+        <attribute name="changeReason" type="String" mode="IN" optional="true"/>
+    </service>    
 </services>

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?rev=598491&r1=598490&r2=598491&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Mon Nov 26 18:01:18 2007
@@ -4515,4 +4515,41 @@
         result.put("invoicedQuantity", invoicedQuantity.setScale(orderDecimals, orderRounding));
         return result;
     }
+    
+    public static Map setOrderPaymentStatus(DispatchContext ctx, Map context) {
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        GenericDelegator delegator = ctx.getDelegator();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        String orderPaymentPreferenceId = (String) context.get("orderPaymentPreferenceId");
+        String changeReason = (String) context.get("changeReason");
+        Map successResult = ServiceUtil.returnSuccess();
+        Locale locale = (Locale) context.get("locale");
+        try {
+            GenericValue orderPaymentPreference = delegator.findByPrimaryKey("OrderPaymentPreference", UtilMisc.toMap("orderPaymentPreferenceId", orderPaymentPreferenceId));
+            String orderId = orderPaymentPreference.getString("orderId");
+            GenericValue orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
+            if (orderHeader == null) {
+                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCouldNotChangeOrderStatusOrderCannotBeFound", locale));
+            }
+            String statusId = orderPaymentPreference.getString("statusId");
+            if (Debug.verboseOn()) Debug.logVerbose("[OrderServices.setOrderPaymentStatus] : Setting Order Payment Status to : " + statusId, module);
+            // create a order payment status
+            GenericValue orderStatus = delegator.makeValue("OrderStatus");
+            orderStatus.put("orderStatusId", delegator.getNextSeqId("OrderStatus"));
+            orderStatus.put("statusId", statusId);
+            orderStatus.put("orderId", orderId);
+            orderStatus.put("orderPaymentPreferenceId", orderPaymentPreferenceId);
+            orderStatus.put("statusDatetime", UtilDateTime.nowTimestamp());
+            orderStatus.put("statusUserLogin", userLogin.getString("userLoginId"));
+            orderStatus.put("changeReason", changeReason);
+
+            orderStatus.create();
+
+        } catch (GenericEntityException e) {
+            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCouldNotChangeOrderStatus", locale) + e.getMessage() + ").");
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
+
 }