svn commit: r550639 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

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

svn commit: r550639 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

sichen
Author: sichen
Date: Mon Jun 25 17:05:50 2007
New Revision: 550639

URL: http://svn.apache.org/viewvc?view=rev&rev=550639
Log:
Fix problem were order open amount does not subtract refunds from settled payments.

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

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=550639&r1=550638&r2=550639
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Mon Jun 25 17:05:50 2007
@@ -1284,7 +1284,7 @@
     /**
      * 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.
+     * amounts received and refunded as payments for the settled ones.
      */
     public double getOrderOpenAmount() throws GenericEntityException {
         GenericDelegator delegator = orderHeader.getDelegator();
@@ -1306,6 +1306,14 @@
                         openAmount += amount.doubleValue();
                     }
                 }
+                responses = pref.getRelatedByAnd("PaymentGatewayResponse", UtilMisc.toMap("transCodeEnumId", "PGT_REFUND"));
+                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");
@@ -1314,6 +1322,8 @@
                 }
             }
         }
+
+        // return either a positive amount or positive zero
         return Math.max(total - openAmount, 0);
     }