svn commit: r571361 - in /ofbiz/trunk/applications: accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java

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

svn commit: r571361 - in /ofbiz/trunk/applications: accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java

jonesde
Author: jonesde
Date: Thu Aug 30 20:29:32 2007
New Revision: 571361

URL: http://svn.apache.org/viewvc?rev=571361&view=rev
Log:
A couple of changes to do rounding at sensitive spots

Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=571361&r1=571360&r2=571361&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Thu Aug 30 20:29:32 2007
@@ -66,8 +66,8 @@
     public static final String CREDIT_SERVICE_TYPE = "PRDS_PAY_CREDIT";
     private static final int TX_TIME = 300;
     private static BigDecimal ZERO = BigDecimal.ZERO;
-    private static int decimals = -1;
-    private static int rounding = -1;
+    private static int decimals;
+    private static int rounding;
     static {
         decimals = UtilNumber.getBigDecimalScale("order.decimals");
         rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding");
@@ -143,7 +143,9 @@
         } else {
             transAmount = orderPaymentPreference.getDouble("maxAmount");
         }
-
+        
+        // round this before moving on just in case a funny number made it this far
+        transAmount = (new BigDecimal(transAmount)).setScale(decimals, rounding).doubleValue();
 
         // if our transaction amount exists and is zero, there's nothing to process, so return
         if ((transAmount != null) && (transAmount.doubleValue() <= 0)) {

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java?rev=571361&r1=571360&r2=571361&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java Thu Aug 30 20:29:32 2007
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.order.shoppingcart.product;
 
+import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -37,6 +38,7 @@
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilNumber;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.GenericDelegator;
@@ -66,6 +68,9 @@
     public static final String module = ProductPromoWorker.class.getName();
     public static final String resource_error = "OrderErrorUiLabels";
 
+    public static final int decimals = UtilNumber.getBigDecimalScale("order.decimals");
+    public static final int rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding");
+
     public static List getStoreProductPromos(GenericDelegator delegator, LocalDispatcher dispatcher, ServletRequest request) {
         List productPromos = FastList.newInstance();
         Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
@@ -1467,8 +1472,10 @@
     }
 
     public static void doOrderItemPromoAction(GenericValue productPromoAction, ShoppingCartItem cartItem, double amount, String amountField, GenericDelegator delegator) {
+        // round the amount before setting to make sure we don't get funny numbers in there
+        BigDecimal amountBd = (new BigDecimal(amount)).setScale(decimals, rounding);
         GenericValue orderAdjustment = delegator.makeValue("OrderAdjustment",
-                UtilMisc.toMap("orderAdjustmentTypeId", "PROMOTION_ADJUSTMENT", amountField, new Double(amount),
+                UtilMisc.toMap("orderAdjustmentTypeId", "PROMOTION_ADJUSTMENT", amountField, amountBd,
                     "productPromoId", productPromoAction.get("productPromoId"),
                     "productPromoRuleId", productPromoAction.get("productPromoRuleId"),
                     "productPromoActionSeqId", productPromoAction.get("productPromoActionSeqId")));
@@ -1482,8 +1489,10 @@
     }
 
     public static void doOrderPromoAction(GenericValue productPromoAction, ShoppingCart cart, double amount, String amountField, GenericDelegator delegator) {
+        // round the amount before setting to make sure we don't get funny numbers in there
+        BigDecimal amountBd = (new BigDecimal(amount)).setScale(decimals, rounding);
         GenericValue orderAdjustment = delegator.makeValue("OrderAdjustment",
-                UtilMisc.toMap("orderAdjustmentTypeId", "PROMOTION_ADJUSTMENT", amountField, new Double(amount),
+                UtilMisc.toMap("orderAdjustmentTypeId", "PROMOTION_ADJUSTMENT", amountField, amountBd,
                     "productPromoId", productPromoAction.get("productPromoId"),
                     "productPromoRuleId", productPromoAction.get("productPromoRuleId"),
                     "productPromoActionSeqId", productPromoAction.get("productPromoActionSeqId")));