svn commit: r528770 - in /ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment: PaymentGatewayServices.java PaymentWorker.java

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

svn commit: r528770 - in /ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment: PaymentGatewayServices.java PaymentWorker.java

jacopoc
Author: jacopoc
Date: Fri Apr 13 22:47:46 2007
New Revision: 528770

URL: http://svn.apache.org/viewvc?view=rev&rev=528770
Log:
Partially converted to BigDecimal (to fix some approx issues) part of the process order payment service.

Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.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?view=diff&rev=528770&r1=528769&r2=528770
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Fri Apr 13 22:47:46 2007
@@ -1053,9 +1053,9 @@
                     // it from other methods, otherwise return
                     if (billingAccountCaptureAmount.compareTo(captureAmountBd) == -1) {
                         BigDecimal outstandingAmount = captureAmountBd.subtract(billingAccountCaptureAmount).setScale(decimals, rounding);
-                        captureAmount = new Double(outstandingAmount.doubleValue());
+                        captureAmountBd = outstandingAmount;
                     } else {
-                        Debug.logInfo("Amount to capture [" + captureAmount + "] was fully captured in Payment [" + tmpResult.get("paymentId") + "].", module);
+                        Debug.logInfo("Amount to capture [" + captureAmountBd + "] was fully captured in Payment [" + tmpResult.get("paymentId") + "].", module);
                         Map result = ServiceUtil.returnSuccess();
                         result.put("processResult", "COMPLETE");
                         return result;
@@ -1076,31 +1076,18 @@
 
         BigDecimal orderGrandTotal = orh.getOrderGrandTotalBd();
         orderGrandTotal = orderGrandTotal.setScale(2, BigDecimal.ROUND_HALF_UP);
-        double orderTotal = orderGrandTotal.doubleValue();
 
-        double totalPayments = PaymentWorker.getPaymentsTotal(orh.getOrderPayments());
-        double remainingTotal = orderTotal - totalPayments;
-        if (Debug.infoOn()) Debug.logInfo("Capture Remaining Total: " + remainingTotal, module);
-
-        // re-format the remaining total
-        String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");
-        DecimalFormat formatter = new DecimalFormat(currencyFormat);
-        String remainingTotalString = formatter.format(remainingTotal);
-        try {
-            Number remaining = formatter.parse(remainingTotalString);
-            if (remaining != null) {
-                remainingTotal = remaining.doubleValue();
-            }
-        } catch (ParseException e) {
-            Debug.logError(e, "Problem getting parsed remaining total", module);
-            return ServiceUtil.returnError("ERROR: Cannot parse grand total from formatted string; see logs");
-        }
-        //Debug.logInfo("Formatted Remaining total : " + remainingTotal, module);
-
-        if (captureAmount == null) {
-            captureAmount = new Double(remainingTotal);
+        BigDecimal totalPayments = PaymentWorker.getPaymentsTotal(orh.getOrderPayments());
+        totalPayments = totalPayments.setScale(2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal remainingTotalBd = orderGrandTotal.subtract(totalPayments);
+        if (Debug.infoOn()) Debug.logInfo("Capture Remaining Total: " + remainingTotalBd, module);
+
+        double amountToCapture = 0.0;
+        if (captureAmountBd == null) {
+            amountToCapture = remainingTotalBd.doubleValue();
+        } else {
+            amountToCapture = captureAmountBd.doubleValue();
         }
-        double amountToCapture = captureAmount.doubleValue();
         if (Debug.infoOn()) Debug.logInfo("Actual Expected Capture Amount : " + amountToCapture, module);
 
         // iterate over the prefs and capture each one until we meet our total
@@ -1124,8 +1111,8 @@
             //Debug.log("Actual Auth amount : " + authAmount, module);
 
             // if the authAmount is more then the remaining total; just use remaining total
-            if (authAmount.doubleValue() > remainingTotal) {
-                authAmount = new Double(remainingTotal);
+            if (authAmount.doubleValue() > remainingTotalBd.doubleValue()) {
+                authAmount = new Double(remainingTotalBd.doubleValue());
             }
 
             // if we have a billing account; total up auth + account available

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java?view=diff&rev=528770&r1=528769&r2=528770
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java Fri Apr 13 22:47:46 2007
@@ -207,21 +207,22 @@
      * Returns the total from a list of Payment entities
      *
      * @param payments List of Payment GenericValue items
-     * @return total payments as double
+     * @return total payments as BigDecimal
      */
-    public static double getPaymentsTotal(List payments) {
+
+    public static BigDecimal getPaymentsTotal(List payments) {
         if (payments == null) {
             throw new IllegalArgumentException("Payment list cannot be null");            
         }
-        
-        double paymentsTotal = 0.00;
+
+        BigDecimal paymentsTotal = new BigDecimal("0");
         Iterator i = payments.iterator();
         while (i.hasNext()) {
             GenericValue payment = (GenericValue) i.next();
-            paymentsTotal += payment.getDouble("amount").doubleValue();
+            paymentsTotal = paymentsTotal.add(payment.getBigDecimal("amount")).setScale(decimals, rounding);
         }
         return paymentsTotal;
-    }          
+    }
 
     /**
      * Method to return the total amount of an payment which is applied to a payment