svn commit: r554547 - /ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java

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

svn commit: r554547 - /ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java

lektran
Author: lektran
Date: Mon Jul  9 00:34:59 2007
New Revision: 554547

URL: http://svn.apache.org/viewvc?view=rev&rev=554547
Log:
Applied fix from trunk for revision: 552487

Modified:
    ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java

Modified: ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java?view=diff&rev=554547&r1=554546&r2=554547
==============================================================================
--- ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java (original)
+++ ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java Mon Jul  9 00:34:59 2007
@@ -23,6 +23,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.Collections;
+import java.util.Comparator;
 import java.math.BigDecimal;
 
 import javolution.util.FastList;
@@ -81,10 +83,9 @@
 
         if (billingAccountRoleList != null && billingAccountRoleList.size() > 0) {
             double totalAvailable = 0.0;
-            TreeMap sortedAccounts = new TreeMap();
             Iterator billingAcctIter = billingAccountRoleList.iterator();
             while (billingAcctIter.hasNext()) {
-                GenericValue billingAccountRole = (GenericValue) billingAcctIter.next();        
+                GenericValue billingAccountRole = (GenericValue) billingAcctIter.next();
                 GenericValue billingAccountVO = billingAccountRole.getRelatedOne("BillingAccount");
 
                 // skip accounts that have thruDate < nowTimestamp
@@ -99,12 +100,11 @@
                 
                     billingAccount.put("accountBalance", new Double(accountBalance));
                     double accountAvailable = accountLimit - accountBalance;
-                    totalAvailable += accountAvailable;    
-                    sortedAccounts.put(new Double(accountAvailable), billingAccount);
+                    totalAvailable += accountAvailable;
+                    billingAccountList.add(billingAccount);
                 }
             }
-            
-            billingAccountList.addAll(sortedAccounts.values());
+            Collections.sort(billingAccountList, new BillingAccountComparator());
         }
         return billingAccountList;
     }
@@ -310,7 +310,11 @@
             Debug.logError(e, module);
             return ServiceUtil.returnError("Error getting billing account or calculating balance for billing account #" + billingAccountId);
         }
-        
-        
+    }
+
+    private static class BillingAccountComparator implements Comparator {
+        public int compare(Object billingAccount1, Object billingAccount2) {
+            return ((Double)((Map)billingAccount1).get("accountBalance")).compareTo((Double)((Map)billingAccount2).get("accountBalance"));
+        }
     }
 }