Author: sichen
Date: Mon Jun 25 17:06:25 2007
New Revision: 550640

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

Modified:
    
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

Modified: 
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?view=diff&rev=550640&r1=550639&r2=550640
==============================================================================
--- 
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
 (original)
+++ 
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
 Mon Jun 25 17:06:25 2007
@@ -1283,7 +1283,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();
@@ -1305,6 +1305,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");
@@ -1313,6 +1321,8 @@
                 }
             }
         }
+
+        // return either a positive amount or positive zero
         return Math.max(total - openAmount, 0);
     }
 


Reply via email to