svn commit: r554148 - /ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

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

svn commit: r554148 - /ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

lektran
Author: lektran
Date: Sat Jul  7 00:07:32 2007
New Revision: 554148

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

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

Modified: ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?view=diff&rev=554148&r1=554147&r2=554148
==============================================================================
--- ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Sat Jul  7 00:07:32 2007
@@ -3325,14 +3325,17 @@
     }
 
     /** make a list of all OrderPaymentPreferences and Billing info including all payment methods and types */
-    public List makeAllOrderPaymentInfos() {
+    public List makeAllOrderPaymentInfos(LocalDispatcher dispatcher) {
         List allOpPrefs = new LinkedList();
-        Iterator i = paymentInfo.iterator();
-        while (i.hasNext()) {
-            CartPaymentInfo inf = (CartPaymentInfo) i.next();
-            allOpPrefs.addAll(inf.makeOrderPaymentInfos(this.getDelegator()));
-        }
+        double remainingAmount = this.getGrandTotal() - this.getPaymentTotal();
         if (getBillingAccountId() != null) {
+            double billingAccountAvailableAmount = billingAccountAvailableAmount = CheckOutHelper.availableAccountBalance(getBillingAccountId(), dispatcher);
+            if (remainingAmount < getBillingAccountAmount()) {
+                this.billingAccountAmt = remainingAmount;
+            }
+            if (billingAccountAvailableAmount < getBillingAccountAmount()) {
+                this.billingAccountAmt = billingAccountAvailableAmount;
+            }
             GenericValue opp = delegator.makeValue("OrderPaymentPreference", new HashMap());
             opp.set("paymentMethodTypeId", "EXT_BILLACT");
             opp.set("presentFlag", "N");
@@ -3340,6 +3343,19 @@
             opp.set("maxAmount", new Double(getBillingAccountAmount()));
             opp.set("statusId", "PAYMENT_NOT_RECEIVED");
             allOpPrefs.add(opp);
+            remainingAmount = remainingAmount - getBillingAccountAmount();
+            if (remainingAmount < 0) {
+                remainingAmount = 0;
+            }
+        }
+        Iterator i = paymentInfo.iterator();
+        while (i.hasNext()) {
+            CartPaymentInfo inf = (CartPaymentInfo) i.next();
+            if (inf.amount == null) {
+                inf.amount = new Double(remainingAmount);
+                remainingAmount = 0;
+            }
+            allOpPrefs.addAll(inf.makeOrderPaymentInfos(this.getDelegator()));
         }
         return allOpPrefs;
     }
@@ -3576,7 +3592,7 @@
         result.put("orderItemAttributes", this.makeAllOrderItemAttributes());
         result.put("orderContactMechs", this.makeAllOrderContactMechs());
         result.put("orderItemContactMechs", this.makeAllOrderItemContactMechs());
-        result.put("orderPaymentInfo", this.makeAllOrderPaymentInfos());
+        result.put("orderPaymentInfo", this.makeAllOrderPaymentInfos(dispatcher));
         result.put("orderItemShipGroupInfo", this.makeAllShipGroupInfos());
         result.put("orderItemSurveyResponses", this.makeAllOrderItemSurveyResponses());
         result.put("orderAdditionalPartyRoleMap", this.getAdditionalPartyRoleMap());