svn commit: r433424 - /incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

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

svn commit: r433424 - /incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

sichen
Author: sichen
Date: Mon Aug 21 16:23:17 2006
New Revision: 433424

URL: http://svn.apache.org/viewvc?rev=433424&view=rev
Log:
New methods for figuring out amount of order paid and refunded to each payment method

Modified:
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?rev=433424&r1=433423&r2=433424&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Mon Aug 21 16:23:17 2006
@@ -182,6 +182,74 @@
         return paymentPrefs;
     }
 
+    /**
+     * Returns a Map of paymentMethodId -> amount charged (Double) based on PaymentGatewayResponse.  
+     * @return
+     */
+ public Map getReceivedPaymentTotalsByPaymentMethod() {
+ Map paymentMethodAmounts = new HashMap();
+ List paymentPrefs = getPaymentPreferences();
+ Iterator ppit = paymentPrefs.iterator();
+ while (ppit.hasNext()) {
+ GenericValue paymentPref = (GenericValue) ppit.next();
+ List paymentGatewayResponses = new ArrayList();
+ try {
+ paymentGatewayResponses = paymentPref.getRelatedByAnd("PaymentGatewayResponse", UtilMisc.toMap("paymentServiceTypeEnumId","PRDS_PAY_CAPTURE"));
+ } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+ }
+            
+ BigDecimal chargedToPaymentPref = ZERO;
+ Iterator pgrit = paymentGatewayResponses.iterator();
+            while(pgrit.hasNext()) {
+ GenericValue paymentGatewayResponse = (GenericValue) pgrit.next();
+             if (paymentGatewayResponse.get("amount") != null) {
+        chargedToPaymentPref = chargedToPaymentPref.add(paymentGatewayResponse.getBigDecimal("amount")).setScale(scale+1, rounding);
+ }
+            }
+            
+            // if chargedToPaymentPref > 0
+            if (chargedToPaymentPref.compareTo(ZERO) == 1) {
+                // key of the resulting map is paymentMethodId or paymentMethodTypeId if the paymentMethodId is not available
+                String paymentMethodKey = paymentPref.getString("paymentMethodId") != null ? paymentPref.getString("paymentMethodId") : paymentPref.getString("paymentMethodTypeId");
+                paymentMethodAmounts.put(paymentMethodKey, new Double(chargedToPaymentPref.setScale(scale, rounding).doubleValue()));
+            }
+ }
+        return paymentMethodAmounts;
+ }
+
+    /**
+     * Returns a Map of paymentMethodId -> amount refunded
+     * @return
+     */
+    public Map getReturnedTotalsByPaymentMethod() {
+        Map paymentMethodAmounts = new HashMap();
+ List paymentPrefs = getPaymentPreferences();
+ Iterator ppit = paymentPrefs.iterator();
+ while (ppit.hasNext()) {
+ GenericValue paymentPref = (GenericValue) ppit.next();
+            List returnItemResponses = new ArrayList();
+            try {
+                returnItemResponses = orderHeader.getDelegator().findByAnd("ReturnItemResponse", UtilMisc.toMap("orderPaymentPreferenceId", paymentPref.getString("orderPaymentPreferenceId")));
+            } catch(GenericEntityException e) {
+                Debug.logError(e, module);
+            }
+            BigDecimal refundedToPaymentPref = ZERO;
+            Iterator ririt = returnItemResponses.iterator();
+            while (ririt.hasNext()) {
+                GenericValue returnItemResponse = (GenericValue) ririt.next();
+                refundedToPaymentPref = refundedToPaymentPref.add(returnItemResponse.getBigDecimal("responseAmount")).setScale(scale+1, rounding);
+            }
+            
+            // if refundedToPaymentPref > 0
+            if (refundedToPaymentPref.compareTo(ZERO) == 1) {
+                String paymentMethodId = paymentPref.getString("paymentMethodId") != null ? paymentPref.getString("paymentMethodId") : paymentPref.getString("paymentMethodTypeId");
+                paymentMethodAmounts.put(paymentMethodId, new Double(refundedToPaymentPref.setScale(scale, rounding).doubleValue()));
+            }
+        }
+        return paymentMethodAmounts;
+    }
+    
     public List getOrderPayments() {
         return getOrderPayments(null);
     }