svn commit: r757093 [3/5] - in /ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting: ./ agreement/ finaccount/ invoice/ payment/ tax/ test/ thirdparty/authorizedotnet/ thirdparty/clearcommerce/ thirdparty/cybersource/ thirdparty/gosoftware/ th...

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

svn commit: r757093 [3/5] - in /ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting: ./ agreement/ finaccount/ invoice/ payment/ tax/ test/ thirdparty/authorizedotnet/ thirdparty/clearcommerce/ thirdparty/cybersource/ thirdparty/gosoftware/ th...

doogie-3
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java?rev=757093&r1=757092&r2=757093&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java Sat Mar 21 23:44:59 2009
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -45,7 +45,7 @@
  * InvoiceWorker - Worker methods of invoices
  */
 public class InvoiceWorker {
-    
+
     public static String module = InvoiceWorker.class.getName();
     private static BigDecimal ZERO = BigDecimal.ZERO;
     private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
@@ -66,18 +66,18 @@
         if (delegator == null) {
             throw new IllegalArgumentException("Null delegator is not allowed in this method");
         }
-        
+
         GenericValue invoice = null;
         try {
-            invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));    
+            invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));
         } catch (GenericEntityException e) {
             Debug.logError(e, "Problem getting Invoice", module);
         }
-        
+
         if (invoice == null) {
             throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice");
         }
-        
+
         return getInvoiceTotal(invoice, actualCurrency);
     }
 
@@ -110,7 +110,7 @@
         BigDecimal ONE = BigDecimal.ONE;
 
         if (invoice == null)
-           throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice");
+           throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice");
         List invoiceTaxItems = null;
         try {
             GenericDelegator delegator = invoice.getDelegator();
@@ -120,7 +120,7 @@
                     ), EntityOperator.AND);
             invoiceTaxItems = delegator.findList("InvoiceItem", condition, null, null, null, false);
         } catch (GenericEntityException e) {
-            Debug.logError(e, "Trouble getting InvoiceItem list", module);            
+            Debug.logError(e, "Trouble getting InvoiceItem list", module);
         }
         if (UtilValidate.isNotEmpty(invoiceTaxItems)) {
             Iterator invoiceItemsIter = invoiceTaxItems.iterator();
@@ -138,11 +138,11 @@
         return invoiceTaxTotal.setScale(decimals, rounding);
 
     }
-    
+
     public static BigDecimal getInvoiceNoTaxTotal(GenericValue invoice) {
         return getInvoiceTotal(invoice, Boolean.TRUE).subtract(getInvoiceTaxTotal(invoice));
     }
-    
+
     /**
      * Method to return the total amount of an invoice
      * @param invoice GenericValue object of the Invoice
@@ -151,7 +151,7 @@
      public static BigDecimal getInvoiceTotal(GenericValue invoice) {
         return getInvoiceTotal(invoice, Boolean.TRUE);
     }
-        
+
     public static BigDecimal getInvoiceTotal(GenericValue invoice, Boolean actualCurrency) {
         BigDecimal invoiceTotal = ZERO;
         BigDecimal invoiceTaxTotal = ZERO;
@@ -159,7 +159,7 @@
         try {
             invoiceItems = invoice.getRelated("InvoiceItem");
         } catch (GenericEntityException e) {
-            Debug.logError(e, "Trouble getting InvoiceItem list", module);            
+            Debug.logError(e, "Trouble getting InvoiceItem list", module);
         }
         if (UtilValidate.isNotEmpty(invoiceItems)) {
             Iterator invoiceItemsIter = invoiceItems.iterator();
@@ -203,13 +203,13 @@
         // remaining code is the old method, which we leave here for compatibility purposes
         List billToRoles = null;
         try {
-            billToRoles = invoice.getRelated("InvoiceRole", UtilMisc.toMap("roleTypeId", "BILL_TO_CUSTOMER"),
+            billToRoles = invoice.getRelated("InvoiceRole", UtilMisc.toMap("roleTypeId", "BILL_TO_CUSTOMER"),
                 UtilMisc.toList("-datetimePerformed"));
         } catch (GenericEntityException e) {
-            Debug.logError(e, "Trouble getting InvoiceRole list", module);            
+            Debug.logError(e, "Trouble getting InvoiceRole list", module);
         }
-        
-        if (billToRoles != null) {        
+
+        if (billToRoles != null) {
             GenericValue role = EntityUtil.getFirst(billToRoles);
             GenericValue party = null;
             try {
@@ -219,8 +219,8 @@
             }
             if (party != null)
                 return party;
-        }            
-        return null;        
+        }
+        return null;
     }
 
     /** Convenience method to obtain the bill from party for an invoice. Note that invoice.partyIdFrom is the bill from party. */
@@ -232,12 +232,12 @@
         }
         return null;
     }
-    
+
     /**
       * Method to obtain the send from party for an invoice
       * @param invoice GenericValue object of the Invoice
       * @return GenericValue object of the Party
-      */    
+      */
     public static GenericValue getSendFromParty(GenericValue invoice) {
         GenericValue billFromParty = getBillFromParty(invoice);
         if (billFromParty != null) {
@@ -247,13 +247,13 @@
         // remaining code is the old method, which we leave here for compatibility purposes
         List sendFromRoles = null;
         try {
-            sendFromRoles = invoice.getRelated("InvoiceRole", UtilMisc.toMap("roleTypeId", "BILL_FROM_VENDOR"),
+            sendFromRoles = invoice.getRelated("InvoiceRole", UtilMisc.toMap("roleTypeId", "BILL_FROM_VENDOR"),
                 UtilMisc.toList("-datetimePerformed"));
         } catch (GenericEntityException e) {
-            Debug.logError(e, "Trouble getting InvoiceRole list", module);            
+            Debug.logError(e, "Trouble getting InvoiceRole list", module);
         }
-        
-        if (sendFromRoles != null) {        
+
+        if (sendFromRoles != null) {
             GenericValue role = EntityUtil.getFirst(sendFromRoles);
             GenericValue party = null;
             try {
@@ -263,28 +263,28 @@
             }
             if (party != null)
                 return party;
-        }            
-        return null;        
+        }
+        return null;
     }
-    
+
     /**
       * Method to obtain the billing address for an invoice
       * @param invoice GenericValue object of the Invoice
       * @return GenericValue object of the PostalAddress
-      */        
+      */
     public static GenericValue getBillToAddress(GenericValue invoice) {
-        return getInvoiceAddressByType(invoice, "BILLING_LOCATION");        
+        return getInvoiceAddressByType(invoice, "BILLING_LOCATION");
     }
-    
+
     /**
       * Method to obtain the sending address for an invoice
       * @param invoice GenericValue object of the Invoice
       * @return GenericValue object of the PostalAddress
-      */        
+      */
     public static GenericValue getSendFromAddress(GenericValue invoice) {
-        return getInvoiceAddressByType(invoice, "PAYMENT_LOCATION");                
+        return getInvoiceAddressByType(invoice, "PAYMENT_LOCATION");
     }
-    
+
     public static GenericValue getInvoiceAddressByType(GenericValue invoice, String contactMechPurposeTypeId) {
         GenericDelegator delegator = invoice.getDelegator();
         List locations = null;
@@ -292,7 +292,7 @@
         try {
             locations = invoice.getRelated("InvoiceContactMech", UtilMisc.toMap("contactMechPurposeTypeId", contactMechPurposeTypeId), null);
         } catch (GenericEntityException e) {
-            Debug.logError("Touble getting InvoiceContactMech entity list", module);          
+            Debug.logError("Touble getting InvoiceContactMech entity list", module);
         }
 
         if (locations == null || locations.size() == 0)    {
@@ -303,22 +303,22 @@
             if (invoice.getString("invoiceTypeId").equals("PURCHASE_INVOICE"))
                 destinationPartyId = "partyFrom";
             try {
-                locations = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",
+                locations = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",
                         UtilMisc.toMap("partyId", destinationPartyId, "contactMechPurposeTypeId", contactMechPurposeTypeId)));
             } catch (GenericEntityException e) {
-                Debug.logError("Trouble getting contact party purpose list", module);          
+                Debug.logError("Trouble getting contact party purpose list", module);
             }
             //if still not found get it from the general location
             if (locations == null || locations.size() == 0)    {
                 try {
-                    locations = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",
+                    locations = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",
                             UtilMisc.toMap("partyId", destinationPartyId, "contactMechPurposeTypeId", "GENERAL_LOCATION")));
                 } catch (GenericEntityException e) {
-                    Debug.logError("Trouble getting contact party purpose list", module);          
+                    Debug.logError("Trouble getting contact party purpose list", module);
                 }
             }
-        }        
-        
+        }
+
         // now return the first PostalAddress from the locations
         GenericValue postalAddress = null;
         GenericValue contactMech = null;
@@ -328,7 +328,7 @@
             } catch (GenericEntityException e) {
                 Debug.logError(e, "Trouble getting Contact for contactMechId: " + contactMech.getString("contactMechId"), module);
             }
-            
+
             if (contactMech.getString("contactMechTypeId").equals("POSTAL_ADDRESS"))    {
                 try {
                     postalAddress = contactMech.getRelatedOne("PostalAddress");
@@ -340,16 +340,16 @@
         }
         return contactMech;
     }
-        
+
     private static GenericValue getAddressFromParty(GenericValue party, String purposeTypeId) {
         if (party == null) return null;
-        
+
         GenericValue contactMech = null;
         GenericValue postalAddress = null;
         try {
-            List mecs = party.getRelated("PartyContactMechPurpose",
+            List mecs = party.getRelated("PartyContactMechPurpose",
                 UtilMisc.toMap("contactMechPurposeTypeId", purposeTypeId), null);
-            if (mecs != null) {            
+            if (mecs != null) {
                 List filteredMecs = EntityUtil.filterByDate(mecs);
                 GenericValue mecPurpose = EntityUtil.getFirst(filteredMecs);
                 if (mecPurpose != null)
@@ -358,22 +358,22 @@
         } catch (GenericEntityException e) {
             Debug.logError(e, "Trouble getting current ContactMech for Party/Purpose", module);
         }
-        
+
         if (contactMech != null) {
             if (contactMech.getString("contactMechTypeId").equals("POSTAL_ADDRESS")) {
                 try {
-                    postalAddress = contactMech.getRelatedOne("PostalAddress");                              
+                    postalAddress = contactMech.getRelatedOne("PostalAddress");
                 } catch (GenericEntityException e) {
                     Debug.logError(e, "Trouble getting PostalAddress from ContactMech", module);
                 }
             }
         }
-        
+
         if (postalAddress != null)
             return postalAddress;
-        return null;        
+        return null;
     }
-    
+
     /**
      * Method to return the total amount of an invoice which is not yet applied to a payment
      * @param invoice GenericValue object of the Invoice
@@ -393,7 +393,7 @@
     }
     /**
      * Returns amount not applied (ie, still outstanding) of an invoice at an asOfDate, based on Payment.effectiveDate <= asOfDateTime
-     *
+     *
      * @param invoice
      * @param asOfDateTime
      * @return
@@ -402,7 +402,7 @@
         return InvoiceWorker.getInvoiceTotal(invoice, Boolean.TRUE).subtract(getInvoiceApplied(invoice, asOfDateTime));
     }
 
-    
+
     /**
      * Method to return the total amount of an invoice which is applied to a payment
      * @param invoice GenericValue object of the Invoice
@@ -411,10 +411,10 @@
     public static BigDecimal getInvoiceApplied(GenericDelegator delegator, String invoiceId) {
         return getInvoiceApplied(delegator, invoiceId, UtilDateTime.nowTimestamp(), Boolean.TRUE);
     }
-    
+
     /**
      * Returns amount applied to invoice before an asOfDateTime, based on Payment.effectiveDate <= asOfDateTime
-     *
+     *
      * @param delegator
      * @param invoiceId
      * @param asOfDateTime - a Timestamp
@@ -424,10 +424,10 @@
         if (delegator == null) {
             throw new IllegalArgumentException("Null delegator is not allowed in this method");
         }
-        
+
         BigDecimal invoiceApplied = ZERO;
         List paymentApplications = null;
-        
+
         // lookup payment applications which took place before the asOfDateTime for this invoice
         EntityConditionList dateCondition = EntityCondition.makeCondition(UtilMisc.toList(
                 EntityCondition.makeCondition("effectiveDate", EntityOperator.EQUALS, null),
@@ -435,12 +435,12 @@
         EntityConditionList conditions = EntityCondition.makeCondition(UtilMisc.toList(
                 dateCondition,
                 EntityCondition.makeCondition("invoiceId", EntityOperator.EQUALS, invoiceId)),
-                EntityOperator.AND);
+                EntityOperator.AND);
 
         try {
             paymentApplications = delegator.findList("PaymentAndApplication", conditions, null, UtilMisc.toList("effectiveDate"), null, false);
         } catch (GenericEntityException e) {
-            Debug.logError(e, "Trouble getting paymentApplicationlist", module);            
+            Debug.logError(e, "Trouble getting paymentApplicationlist", module);
         }
         if (UtilValidate.isNotEmpty(paymentApplications)) {
             Iterator p = paymentApplications.iterator();
@@ -462,7 +462,7 @@
     public static BigDecimal getInvoiceApplied(GenericValue invoice) {
         return getInvoiceApplied(invoice, UtilDateTime.nowTimestamp());
     }
-    
+
     /**
      * @param delegator
      * @param invoiceId
@@ -484,21 +484,21 @@
         if (delegator == null) {
             throw new IllegalArgumentException("Null delegator is not allowed in this method");
         }
-        
+
         GenericValue invoiceItem = null;
         try {
-            invoiceItem = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId,"invoiceItemSeqId", invoiceItemSeqId));    
+            invoiceItem = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId,"invoiceItemSeqId", invoiceItemSeqId));
         } catch (GenericEntityException e) {
             Debug.logError(e, "Problem getting InvoiceItem", module);
         }
-        
+
         if (invoiceItem == null) {
             throw new IllegalArgumentException("The invoiceId/itemSeqId passed does not match an existing invoiceItem");
         }
-        
+
         return getInvoiceItemApplied(invoiceItem);
     }
-    
+
     /**
      * Method to return the total amount of an invoiceItem which is applied to a payment
      * @param invoice GenericValue object of the Invoice
@@ -510,7 +510,7 @@
         try {
             paymentApplications = invoiceItem.getRelated("PaymentApplication");
         } catch (GenericEntityException e) {
-            Debug.logError(e, "Trouble getting paymentApplicationlist", module);            
+            Debug.logError(e, "Trouble getting paymentApplicationlist", module);
         }
         if (UtilValidate.isNotEmpty(paymentApplications)) {
             Iterator p = paymentApplications.iterator();
@@ -519,7 +519,7 @@
                 invoiceItemApplied = invoiceItemApplied.add(paymentApplication.getBigDecimal("amountApplied")).setScale(decimals,rounding);
             }
         }
-        return invoiceItemApplied;        
+        return invoiceItemApplied;
     }
     public static BigDecimal getInvoiceCurrencyConversionRate(GenericValue invoice) {
         BigDecimal conversionRate = null;
@@ -540,12 +540,12 @@
                 otherCurrencyUomId = "USD"; // final default
             }
         } catch (GenericEntityException e) {
-            Debug.logError(e, "Trouble getting database records....", module);            
+            Debug.logError(e, "Trouble getting database records....", module);
         }
         if (invoice.getString("currencyUomId").equals(otherCurrencyUomId)) {
             return BigDecimal.ONE;  // organization party has the same currency so conversion not required.
         }
-        
+
         try {
             // check if the invoice is posted and get the conversion from there
             List acctgTransEntries = invoice.getRelated("AcctgTrans");
@@ -571,7 +571,7 @@
             }
             // use the dated conversion entity
             if (UtilValidate.isEmpty(conversionRate)) {
-                List rates = EntityUtil.filterByDate(delegator.findByAnd("UomConversionDated", UtilMisc.toMap("uomIdTo", invoice.getString("currencyUomId"), "uomId", otherCurrencyUomId)), invoice.getTimestamp("invoiceDate"));
+                List rates = EntityUtil.filterByDate(delegator.findByAnd("UomConversionDated", UtilMisc.toMap("uomIdTo", invoice.getString("currencyUomId"), "uomId", otherCurrencyUomId)), invoice.getTimestamp("invoiceDate"));
                 if (UtilValidate.isNotEmpty(rates)) {
                     conversionRate = (BigDecimal.ONE).divide(((GenericValue) rates.get(0)).getBigDecimal("conversionFactor"), new MathContext(100)).setScale(decimals,rounding);
                 } else {
@@ -581,7 +581,7 @@
             }
 
         } catch (GenericEntityException e) {
-            Debug.logError(e, "Trouble getting database records....", module);            
+            Debug.logError(e, "Trouble getting database records....", module);
         }
         return(conversionRate);
     }
@@ -590,19 +590,19 @@
         if (delegator == null) {
             throw new IllegalArgumentException("Null delegator is not allowed in this method");
         }
-        
+
         GenericValue invoice = null;
         try {
-            invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));    
+            invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));
         } catch (GenericEntityException e) {
             Debug.logError(e, "Problem getting Invoice", module);
         }
-        
+
         if (invoice == null) {
             throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice");
         }
-        
+
         return getInvoiceCurrencyConversionRate(invoice);
     }
-  
+
 }

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java?rev=757093&r1=757092&r2=757093&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java Sat Mar 21 23:44:59 2009
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -53,7 +53,7 @@
  * Worker methods for BillingAccounts
  */
 public class BillingAccountWorker {
-    
+
     public static final String module = BillingAccountWorker.class.getName();
     private static BigDecimal ZERO = BigDecimal.ZERO;
     private static int decimals = -1;
@@ -69,7 +69,7 @@
     public static List makePartyBillingAccountList(GenericValue userLogin, String currencyUomId, String partyId, GenericDelegator delegator, LocalDispatcher dispatcher) throws GeneralException {
         List billingAccountList = FastList.newInstance();
 
-        Map agentResult = dispatcher.runSync("getRelatedParties", UtilMisc.<String, Object>toMap("userLogin", userLogin, "partyIdFrom", partyId,
+        Map agentResult = dispatcher.runSync("getRelatedParties", UtilMisc.<String, Object>toMap("userLogin", userLogin, "partyIdFrom", partyId,
                 "roleTypeIdFrom", "AGENT", "roleTypeIdTo", "CUSTOMER", "partyRelationshipTypeId", "AGENT", "includeFromToSwitched", "Y"));
         if (ServiceUtil.isError(agentResult)) {
             throw new GeneralException("Error while finding party BillingAccounts when getting Customers that this party is an agent of: " + ServiceUtil.getErrorMessage(agentResult));
@@ -95,11 +95,11 @@
 
                 if (currencyUomId.equals(billingAccountVO.getString("accountCurrencyUomId"))) {
                     BigDecimal accountBalance = BillingAccountWorker.getBillingAccountBalance(billingAccountVO);
-                
+
                     Map billingAccount = new HashMap(billingAccountVO);
                     BigDecimal accountLimit = getAccountLimit(billingAccountVO);
-                
-                    billingAccount.put("accountBalance", accountBalance);
+
+                    billingAccount.put("accountBalance", accountBalance);
                     BigDecimal accountAvailable = accountLimit.subtract(accountBalance);
                     totalAvailable = totalAvailable.add(accountAvailable);
                     billingAccountList.add(billingAccount);
@@ -109,7 +109,7 @@
         }
         return billingAccountList;
     }
-    
+
     /**
      * Returns the accountLimit of the BillingAccount or BigDecimal ZERO if it is null
      * @param billingAccount
@@ -123,10 +123,10 @@
             return ZERO;
         }
     }
-    
+
     /**
      * Calculates the "available" balance of a billing account, which is the
-     * net balance minus amount of pending (not cancelled, rejected, or received) order payments.  
+     * net balance minus amount of pending (not cancelled, rejected, or received) order payments.
      * When looking at using a billing account for a new order, you should use this method.
      * @param billingAccountId
      * @param delegator
@@ -139,7 +139,7 @@
     }
 
     public static BigDecimal getBillingAccountBalance(GenericValue billingAccount) throws GenericEntityException {
-        
+
         GenericDelegator delegator = billingAccount.getDelegator();
         String billingAccountId = billingAccount.getString("billingAccountId");
 
@@ -152,7 +152,7 @@
                 EntityCondition.makeCondition("paymentMethodTypeId", EntityOperator.EQUALS, "EXT_BILLACT"),
                 EntityCondition.makeCondition("statusId", EntityOperator.NOT_IN, UtilMisc.toList("ORDER_CANCELLED", "ORDER_REJECTED")),
                 EntityCondition.makeCondition("preferenceStatusId", EntityOperator.NOT_IN, UtilMisc.toList("PAYMENT_SETTLED", "PAYMENT_RECEIVED", "PAYMENT_DECLINED", "PAYMENT_CANCELLED")) // PAYMENT_NOT_AUTH
-            ), EntityOperator.AND);
+            ), EntityOperator.AND);
 
         List orderPaymentPreferenceSums = delegator.findList("OrderPurchasePaymentSummary", whereConditions, UtilMisc.toSet("maxAmount"), null, null, false);
         for (Iterator oppsi = orderPaymentPreferenceSums.iterator(); oppsi.hasNext(); ) {
@@ -176,12 +176,12 @@
         /*
         GenericDelegator delegator = billingAccount.getDelegator();
         String billingAccountId = billingAccount.getString("billingAccountId");
-        
+
         // first get the net balance of invoices - payments
         BigDecimal balance = getBillingAccountNetBalance(delegator, billingAccountId);
-        
+
         // now the amounts of all the pending orders (not cancelled, rejected or completed)
-        List orderHeaders = getBillingAccountOpenOrders(delegator, billingAccountId);
+        List orderHeaders = getBillingAccountOpenOrders(delegator, billingAccountId);
 
         if (orderHeaders != null) {
             Iterator ohi = orderHeaders.iterator();
@@ -199,25 +199,25 @@
         if (balance.compareTo(accountLimit) > 0) {
             balance = accountLimit;
         } else {
-            balance = balance.setScale(decimals, rounding);    
+            balance = balance.setScale(decimals, rounding);
         }
         return balance;
          */
     }
-    
+
     /**
      * Returns list of orders which are currently open against a billing account
-     */
+     */
     public static List getBillingAccountOpenOrders(GenericDelegator delegator, String billingAccountId) throws GenericEntityException {
-        EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(UtilMisc.toList(
+        EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(UtilMisc.toList(
                 EntityCondition.makeCondition("billingAccountId", EntityOperator.EQUALS, billingAccountId),
                 EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"),
                 EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED"),
-                EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_COMPLETED")),
+                EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_COMPLETED")),
                 EntityJoinOperator.AND);
         return delegator.findList("OrderHeader", ecl, null, null, null, false);
-    }
-    
+    }
+
     /**
      * Returns the amount which could be charged to a billing account, which is defined as the accountLimit minus account balance and minus the balance of outstanding orders
      * When trying to figure out how much of a billing account can be used to pay for an outstanding order, use this method
@@ -235,7 +235,7 @@
             return ZERO;
         }
     }
-    
+
     public static BigDecimal getBillingAccountAvailableBalance(GenericDelegator delegator, String billingAccountId) throws GenericEntityException {
         GenericValue billingAccount = delegator.findByPrimaryKey("BillingAccount", UtilMisc.toMap("billingAccountId", billingAccountId));
         return getBillingAccountAvailableBalance(billingAccount);
@@ -251,7 +251,7 @@
      */
     public static BigDecimal getBillingAccountNetBalance(GenericDelegator delegator, String billingAccountId) throws GenericEntityException {
         BigDecimal balance = ZERO;
-    
+
         // search through all PaymentApplications and add the amount that was applied to invoice and subtract the amount applied from payments
         List paymentAppls = delegator.findByAnd("PaymentApplication", UtilMisc.toMap("billingAccountId", billingAccountId));
         for (Iterator pAi = paymentAppls.iterator(); pAi.hasNext(); ) {
@@ -261,17 +261,17 @@
             if (invoice != null) {
                 // make sure the invoice has not been canceled and it is not a "Customer return invoice"
                 if (!"CUST_RTN_INVOICE".equals(invoice.getString("invoiceTypeId")) && !"INVOICE_CANCELLED".equals(invoice.getString("statusId"))) {
-                    balance = balance.add(amountApplied);    
+                    balance = balance.add(amountApplied);
                 }
             } else {
                 balance = balance.subtract(amountApplied);
             }
         }
-    
+
         balance = balance.setScale(decimals, rounding);
         return balance;
     }
-    
+
     /**
      * Returns the amount of the billing account which could be captured, which is BillingAccount.accountLimit - net balance
      * @param billingAccount
@@ -281,28 +281,28 @@
     public static BigDecimal availableToCapture(GenericValue billingAccount) throws GenericEntityException {
         BigDecimal netBalance = getBillingAccountNetBalance(billingAccount.getDelegator(), billingAccount.getString("billingAccountId"));
         BigDecimal accountLimit = billingAccount.getBigDecimal("accountLimit");
-        
+
         return accountLimit.subtract(netBalance).setScale(decimals, rounding);
     }
-    
+
     public static Map calcBillingAccountBalance(DispatchContext dctx, Map context) {
         GenericDelegator delegator = dctx.getDelegator();
         String billingAccountId = (String) context.get("billingAccountId");
         Map result = ServiceUtil.returnSuccess();
-        
+
         try {
             GenericValue billingAccount = delegator.findByPrimaryKey("BillingAccount", UtilMisc.toMap("billingAccountId", billingAccountId));
             if (billingAccount == null) {
                 return ServiceUtil.returnError("Unable to locate billing account #" + billingAccountId);
             }
-            
+
             result.put("billingAccount", billingAccount);
             result.put("accountBalance",  getBillingAccountBalance(delegator, billingAccountId));
             result.put("netAccountBalance", getBillingAccountNetBalance(delegator, billingAccountId));
             result.put("availableBalance", getBillingAccountAvailableBalance(billingAccount));
             result.put("availableToCapture", availableToCapture(billingAccount));
-        
-            return result;  
+
+            return result;
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
             return ServiceUtil.returnError("Error getting billing account or calculating balance for billing account #" + billingAccountId);

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java?rev=757093&r1=757092&r2=757093&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java Sat Mar 21 23:44:59 2009
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -55,7 +55,7 @@
     public static final int PIN_NUMBER_LENGTH = 6;
 
     public static BigDecimal ZERO = BigDecimal.ZERO;
-    
+
     // Base Gift Certificate Services
     public static Map createGiftCertificate(DispatchContext dctx, Map context) {
         LocalDispatcher dispatcher = dctx.getDispatcher();
@@ -84,7 +84,7 @@
 
             GenericValue giftCertSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId));
             Map acctResult = null;
-            
+
             if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
                 // TODO: move this code to createFinAccountForStore as well
                 int cardNumberLength = CARD_NUMBER_LENGTH;
@@ -100,7 +100,7 @@
 
                 // in this case, the card number is the finAccountId
                 finAccountId = cardNumber;
-                
+
                 // create the FinAccount
                 Map acctCtx = UtilMisc.toMap("finAccountId", finAccountId);
                 acctCtx.put("finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId);
@@ -109,7 +109,7 @@
                 acctCtx.put("userLogin", userLogin);
                 acctResult = dispatcher.runSync("createFinAccount", acctCtx);
             } else {
-                acctResult = dispatcher.runSync("createFinAccountForStore", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId, "userLogin", userLogin));  
+                acctResult = dispatcher.runSync("createFinAccountForStore", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId, "userLogin", userLogin));
                 if (acctResult.get("finAccountId") != null) {
                     finAccountId = cardNumber = (String) acctResult.get("finAccountId");
                 }
@@ -117,14 +117,14 @@
                     cardNumber = (String) acctResult.get("finAccountCode");
                 }
             }
-            
+
             if (ServiceUtil.isError(acctResult)) {
                 String error = ServiceUtil.getErrorMessage(acctResult);
                 return ServiceUtil.returnError(error);
             }
-            
+
             // create the initial (deposit) transaction
-            // do something tricky here: run as the "system" user
+            // do something tricky here: run as the "system" user
             // that can actually create a financial account transaction
             GenericValue permUserLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "system"));
             refNum = createTransaction(delegator, dispatcher, permUserLogin, initialAmount,
@@ -195,7 +195,7 @@
         if (finAccountId == null) {
             return ServiceUtil.returnError("Cannot get fin account for adding to balance");
         }
-        
+
         if (finAccount == null) {
             try {
                 finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", finAccountId));
@@ -276,7 +276,7 @@
         } catch (GenericEntityException e) {
             return ServiceUtil.returnError("Cannot get financial account settings " + e.getMessage());
         }
-        
+
         // check the actual balance (excluding authorized amounts) and create the transaction if it is sufficient
         BigDecimal previousBalance = finAccount.get("actualBalance") == null ? BigDecimal.ZERO : finAccount.getBigDecimal("actualBalance");
 
@@ -327,7 +327,7 @@
         } catch (GenericEntityException e) {
             return ServiceUtil.returnError("Cannot get financial account settings " + e.getMessage());
         }
-        
+
         // TODO: get the real currency from context
         //String currencyUom = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");
         // get the balance
@@ -353,7 +353,7 @@
         }
 
         // get the authorizations
-        GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");        
+        GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
         GenericValue authTransaction = (GenericValue) context.get("authTrans");
         if (authTransaction == null) {
             authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
@@ -361,25 +361,25 @@
         if (authTransaction == null) {
             return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot capture");
         }
-      
+
         // get the gift certificate and its authorization from the authorization
         String finAccountAuthId = authTransaction.getString("referenceNum");
         try {
             GenericValue finAccountAuth = delegator.findByPrimaryKey("FinAccountAuth", UtilMisc.toMap("finAccountAuthId", finAccountAuthId));
-            GenericValue giftCard = finAccountAuth.getRelatedOne("FinAccount");  
+            GenericValue giftCard = finAccountAuth.getRelatedOne("FinAccount");
             // make sure authorization has not expired
             Timestamp authExpiration = finAccountAuth.getTimestamp("thruDate");
             if ((authExpiration != null) && (authExpiration.before(UtilDateTime.nowTimestamp()))) {
                 return ServiceUtil.returnError("Authorization transaction [" + authTransaction.getString("paymentGatewayResponseId") + "] has expired as of " + authExpiration);
             }
-            // make sure the fin account itself has not expired
+            // make sure the fin account itself has not expired
             if ((giftCard.getTimestamp("thruDate") != null) && (giftCard.getTimestamp("thruDate").before(UtilDateTime.nowTimestamp()))) {
                 return ServiceUtil.returnError("Gift certificate has expired as of " + giftCard.getTimestamp("thruDate"));
             }
-            
+
             // obtain the order information
             OrderReadHelper orh = new OrderReadHelper(delegator, orderPaymentPreference.getString("orderId"));
-            
+
             Map redeemCtx = new HashMap();
             redeemCtx.put("userLogin", userLogin);
             redeemCtx.put("productStoreId", orh.getProductStoreId());
@@ -387,7 +387,7 @@
             redeemCtx.put("pinNumber", giftCard.get("finAccountCode"));
             redeemCtx.put("currency", currency);
             if (orh.getBillToParty() != null) {
-                redeemCtx.put("partyId", orh.getBillToParty().get("partyId"));    
+                redeemCtx.put("partyId", orh.getBillToParty().get("partyId"));
             }
             redeemCtx.put("amount", amount);
 
@@ -397,13 +397,13 @@
             if (ServiceUtil.isError(redeemResult)) {
                 return redeemResult;
             }
-            
+
             // now release the authorization should this use the gift card release service?
             Map releaseResult = dispatcher.runSync("expireFinAccountAuth", UtilMisc.<String, Object>toMap("userLogin", userLogin, "finAccountAuthId", finAccountAuthId));
             if (ServiceUtil.isError(releaseResult)) {
                 return releaseResult;
             }
-            
+
             Map result = ServiceUtil.returnSuccess();
             if (redeemResult != null) {
                 Boolean processResult = (Boolean) redeemResult.get("processResult");
@@ -422,7 +422,7 @@
         }
 }
 
-    
+
     public static Map giftCertificateAuthorize(DispatchContext dctx, Map context) {
         LocalDispatcher dispatcher = dctx.getDispatcher();
         GenericDelegator delegator = dctx.getDelegator();
@@ -452,7 +452,7 @@
                     if (validatePin(delegator, giftCard.getString("cardNumber"), giftCard.getString("pinNumber"))) {
                         finAccountId = giftCard.getString("cardNumber");
                         finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", finAccountId));
-                    }
+                    }
                 } else {
                         finAccount = FinAccountHelper.getFinAccountFromCode(giftCard.getString("cardNumber"), delegator);
                         if (finAccount == null) {
@@ -463,16 +463,16 @@
             } else {
                 return ServiceUtil.returnError("No product store financial account settings available");
             }
-            
+
             if (finAccountId == null) {
                 return ServiceUtil.returnError("Gift certificate pin number is invalid");
             }
-            
+
             // check for expiration date
             if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime.nowTimestamp()))) {
                 return ServiceUtil.returnError("Gift certificate has expired as of " + finAccount.getTimestamp("thruDate"));
             }
-            
+
             // check the amount to authorize against the available balance of fin account, which includes active authorizations as well as transactions
             BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
             Boolean processResult = null;
@@ -491,17 +491,17 @@
                 Map tmpResult = dispatcher.runSync("createFinAccountAuth", UtilMisc.<String, Object>toMap("finAccountId", finAccountId, "amount", amount, "currencyUomId", currency,
                         "thruDate", thruDate, "userLogin", userLogin));
                 if (ServiceUtil.isError(tmpResult)) {
-                    return tmpResult;
+                    return tmpResult;
                 } else {
                     refNum = (String) tmpResult.get("finAccountAuthId");
-                    processResult = Boolean.TRUE;  
+                    processResult = Boolean.TRUE;
                 }
             } else {
                 Debug.logError("Attempted to authorize [" + amount + "] against a balance of only [" + availableBalance + "]", module);
                 refNum = "N/A";      // a refNum is always required from authorization
                 processResult = Boolean.FALSE;
             }
-            
+
             result.put("processAmount", amount);
             result.put("authResult", processResult);
             result.put("processAmount", amount);
@@ -509,7 +509,7 @@
             result.put("authCode", "A");
             result.put("captureCode", "C");
             result.put("authRefNum", refNum);
-            
+
             return result;
         } catch (GenericEntityException ex) {
             Debug.logError(ex, "Cannot authorize gift certificate", module);
@@ -519,7 +519,7 @@
             return ServiceUtil.returnError("Cannot authorize gift certificate due to " + ex.getMessage());
         }
     }
-    
+
     public static Map giftCertificateRefund(DispatchContext dctx, Map context) {
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
@@ -694,12 +694,12 @@
         // Gift certificate settings are per store in this entity
         GenericValue giftCertSettings = null;
         try {
-            giftCertSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId));    
+            giftCertSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId));
         } catch (GenericEntityException e) {
             Debug.logError(e, "Unable to get Product Store FinAccount settings for " + FinAccountHelper.giftCertFinAccountTypeId, module);
             ServiceUtil.returnError("Unable to get Product Store FinAccount settings for " + FinAccountHelper.giftCertFinAccountTypeId + ": " + e.getMessage());
         }
-      
+
         // survey information
         String surveyId = giftCertSettings.getString("purchaseSurveyId");
 
@@ -824,7 +824,7 @@
                 uiLabelMap.addBottomResourceBundle("CommonUiLabels");
                 answerMap.put("uiLabelMap", uiLabelMap);
                 answerMap.put("locale", locale);
-                
+
                 // set the bcc address(s)
                 String bcc = productStoreEmail.getString("bccAddress");
                 if (copyMe) {
@@ -851,7 +851,7 @@
                 emailCtx.put("userLogin", userLogin);
 
                 // send off the email async so we will retry on failed attempts
-                // SC 20060405: Changed to runSync because runAsync kept getting an error:
+                // SC 20060405: Changed to runSync because runAsync kept getting an error:
                 // Problem serializing service attributes (Cannot serialize object of class java.util.PropertyResourceBundle)
                 try {
                     dispatcher.runSync("sendMailFromScreen", emailCtx);

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=757093&r1=757092&r2=757093&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 Sat Mar 21 23:44:59 2009
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -89,13 +89,13 @@
         // set zero to the proper scale
         if (decimals != -1) ZERO = ZERO.setScale(decimals);
     }
-    
+
     /**
      * Authorizes a single order preference with an option to specify an amount. The result map has the Booleans
      * "errors" and "finished" which notify the user if there were any errors and if the authorizatoin was finished.
-     * There is also a List "messages" for the authorization response messages and a BigDecimal, "processAmount" as the
-     * amount processed.
-     *
+     * There is also a List "messages" for the authorization response messages and a BigDecimal, "processAmount" as the
+     * amount processed.
+     *
      * TODO: it might be nice to return the paymentGatewayResponseId
      */
     public static Map authOrderPaymentPreference(DispatchContext dctx, Map context) {
@@ -155,7 +155,7 @@
         } else {
             transAmount = orderPaymentPreference.getBigDecimal("maxAmount");
         }
-        
+
         // round this before moving on just in case a funny number made it this far
         transAmount = transAmount.setScale(decimals, rounding);
 
@@ -194,7 +194,7 @@
                             // TODO: what do we do with this? we need to fail the auth but still allow the order through so it can be fixed later
                             // NOTE: this is called through a different path for auto re-orders, so it should be good to go... will leave this comment here just in case...
                         }
-                        
+
                         // if we have a failure at this point and no NSF retry is needed, then try other credit cards on file, if the user has any
                         if (!needsNsfRetry) {
                             // is this an auto-order?
@@ -204,16 +204,16 @@
                                 if ("Y".equals(productStore.getString("autoOrderCcTryOtherCards"))) {
                                     // get other credit cards for the bill to party
                                     List otherPaymentMethodAndCreditCardList = null;
-                                    String billToPartyId = null;
+                                    String billToPartyId = null;
                                     GenericValue billToParty = orh.getBillToParty();
                                     if (billToParty != null) {
                                         billToPartyId = billToParty.getString("partyId");
                                     } else {
                                         // TODO optional: any other ways to find the bill to party? perhaps look at info from OrderPaymentPreference, ie search back from other PaymentMethod...
                                     }
-                                    
+
                                     if (UtilValidate.isNotEmpty(billToPartyId)) {
-                                        otherPaymentMethodAndCreditCardList = delegator.findByAnd("PaymentMethodAndCreditCard",
+                                        otherPaymentMethodAndCreditCardList = delegator.findByAnd("PaymentMethodAndCreditCard",
                                                 UtilMisc.toMap("partyId", billToPartyId, "paymentMethodTypeId", "CREDIT_CARD"));
                                         otherPaymentMethodAndCreditCardList = EntityUtil.filterByDate(otherPaymentMethodAndCreditCardList, true);
                                     }
@@ -222,18 +222,18 @@
                                         Iterator otherPaymentMethodAndCreditCardIter = otherPaymentMethodAndCreditCardList.iterator();
                                         while (otherPaymentMethodAndCreditCardIter.hasNext()) {
                                             GenericValue otherPaymentMethodAndCreditCard = (GenericValue) otherPaymentMethodAndCreditCardIter.next();
-                                            
+
                                             // change OrderPaymentPreference in memory only and call auth service
                                             orderPaymentPreference.set("paymentMethodId", otherPaymentMethodAndCreditCard.getString("paymentMethodId"));
                                             Map authRetryResult = authPayment(dispatcher, userLogin, orh, orderPaymentPreference, totalRemaining, reAuth, transAmount);
                                             try {
                                                 boolean processRetryResult = processResult(dctx, authPaymentResult, userLogin, orderPaymentPreference);
-                                                
+
                                                 if (processRetryResult) {
                                                     // wow, we got here that means the other card was successful...
                                                     // on success save the OrderPaymentPreference, and then return finished (which will break from loop)
                                                     orderPaymentPreference.store();
-                                                    
+
                                                     Map results = ServiceUtil.returnSuccess();
                                                     results.put("messages", authRetryResult.get("customerRespMsgs"));
                                                     results.put("processAmount", thisAmount);
@@ -250,7 +250,7 @@
                                                 results.put("errors", Boolean.TRUE);
                                                 return results;
                                             }
-                                            
+
                                             // if no sucess, fall through to return not finished
                                         }
                                     }
@@ -382,7 +382,7 @@
 
             if (ServiceUtil.isError(results)) {
                 hadError += 1;
-                messages.add("Could not authorize OrderPaymentPreference [" + paymentPref.getString("orderPaymentPreferenceId") + "] for order [" + orderId + "]: " + results.get(ModelService.ERROR_MESSAGE));
+                messages.add("Could not authorize OrderPaymentPreference [" + paymentPref.getString("orderPaymentPreferenceId") + "] for order [" + orderId + "]: " + results.get(ModelService.ERROR_MESSAGE));
                 continue;
             }
 
@@ -472,7 +472,7 @@
         if (paymentPreference.get("securityCode") != null) {
             processContext.put("cardSecurityCode", paymentPreference.get("securityCode"));
         }
-        
+
         // get the billing information
         getBillingInformation(orh, paymentPreference, processContext);
 
@@ -501,9 +501,9 @@
         Map processorResult = null;
         try {
             // invoke the payment processor; allow 5 minute transaction timeout and require a new tx; we'll capture the error and pass back nicely
-            
+
             GenericValue creditCard = (GenericValue) processContext.get("creditCard");
-            
+
             // only try other exp dates if orderHeader.autoOrderShoppingListId is not empty, productStore.autoOrderCcTryExp=Y and this payment is a creditCard
             boolean tryOtherExpDates = "Y".equals(productStore.getString("autoOrderCcTryExp")) && creditCard != null && UtilValidate.isNotEmpty(orderHeader.getString("autoOrderShoppingListId"));
 
@@ -511,15 +511,15 @@
             if (!tryOtherExpDates || UtilValidate.isDateAfterToday(creditCard.getString("expireDate"))) {
                 processorResult = dispatcher.runSync(serviceName, processContext, TX_TIME, true);
             }
-            
-            // try other expire dates if the expireDate is not after today, or if we called the auth service and resultBadExpire = true
+
+            // try other expire dates if the expireDate is not after today, or if we called the auth service and resultBadExpire = true
             if (tryOtherExpDates && (!UtilValidate.isDateAfterToday(creditCard.getString("expireDate")) || (processorResult != null && Boolean.TRUE.equals((Boolean) processorResult.get("resultBadExpire"))))) {
                 // try adding 2, 3, 4 years later with the same month
                 String expireDate = creditCard.getString("expireDate");
                 int dateSlash1 = expireDate.indexOf("/");
                 String month = expireDate.substring(0, dateSlash1);
                 String year = expireDate.substring(dateSlash1 + 1);
-                
+
                 // start adding 2 years, if comes back with resultBadExpire try again up to twice incrementing one year
                 year = StringUtil.addToNumberString(year, 2);
                 // note that this is set in memory only for now, not saved to the database unless successful
@@ -534,14 +534,14 @@
                     creditCard.set("expireDate", month + "/" + year);
                     processorResult = dispatcher.runSync(serviceName, processContext, TX_TIME, true);
                 }
-                
+
                 if (!ServiceUtil.isError(processorResult) && Boolean.TRUE.equals((Boolean) processorResult.get("resultBadExpire"))) {
                     // okay, try one more year... and this is the last try
                     year = StringUtil.addToNumberString(year, 1);
                     creditCard.set("expireDate", month + "/" + year);
                     processorResult = dispatcher.runSync(serviceName, processContext, TX_TIME, true);
                 }
-                
+
                 // at this point if we have a successful result, let's save the new creditCard expireDate
                 if (!ServiceUtil.isError(processorResult) && Boolean.TRUE.equals((Boolean) processorResult.get("authResult"))) {
                     // TODO: this is bad; we should be expiring the old card and creating a new one instead of editing it
@@ -722,7 +722,7 @@
                 Debug.logError(ServiceUtil.getErrorMessage(releaseResult), module);
                 return ServiceUtil.returnError(ServiceUtil.getErrorMessage(releaseResult));
             } else if (! ServiceUtil.isFailure(releaseResult)) {
-                finished.add(paymentPref);                
+                finished.add(paymentPref);
             }
         }
         result = ServiceUtil.returnSuccess();
@@ -736,7 +736,7 @@
     }
 
     /**
-     *
+     *
      * Releases authorization for a single OrderPaymentPreference through service calls to the defined processing service for the ProductStore/PaymentMethodType
      * @return SUCCESS|FAILED|ERROR for complete processing of payment.
      */
@@ -753,14 +753,14 @@
         try {
             paymentPref = delegator.findByPrimaryKey("OrderPaymentPreference", UtilMisc.toMap("orderPaymentPreferenceId", orderPaymentPreferenceId));
         } catch ( GenericEntityException e ) {
-            String errMsg = "Problem getting OrderPaymentPreference for orderPaymentPreferenceId " + orderPaymentPreferenceId;
+            String errMsg = "Problem getting OrderPaymentPreference for orderPaymentPreferenceId " + orderPaymentPreferenceId;
             Debug.logWarning(e, errMsg, module);
             return ServiceUtil.returnError(errMsg);
         }
 
         // Error if no OrderPaymentPreference was found
         if (paymentPref == null) {
-            String errMsg = "Could not find OrderPaymentPreference with orderPaymentPreferenceId: " + orderPaymentPreferenceId;
+            String errMsg = "Could not find OrderPaymentPreference with orderPaymentPreferenceId: " + orderPaymentPreferenceId;
             Debug.logWarning(errMsg, module);
             return ServiceUtil.returnError(errMsg);
         }
@@ -770,14 +770,14 @@
         try {
             orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", paymentPref.getString("orderId")));
         } catch ( GenericEntityException e ) {
-            String errMsg = "Problem getting OrderHeader for orderId " + paymentPref.getString("orderId");
+            String errMsg = "Problem getting OrderHeader for orderId " + paymentPref.getString("orderId");
             Debug.logWarning(e, errMsg, module);
             return ServiceUtil.returnError(errMsg);
         }
 
         // Error if no OrderHeader was found
         if (orderHeader == null) {
-            String errMsg = "Could not find OrderHeader with orderId: " + paymentPref.getString("orderId") + "; not processing payments.";
+            String errMsg = "Could not find OrderHeader with orderId: " + paymentPref.getString("orderId") + "; not processing payments.";
             Debug.logWarning(errMsg, module);
             return ServiceUtil.returnError(errMsg);
         }
@@ -795,12 +795,12 @@
             paymentConfig = paymentSettings.getString("paymentPropertiesPath");
             serviceName = paymentSettings.getString("paymentService");
             if (serviceName == null) {
-                String errMsg = "No payment release service for - " + paymentPref.getString("paymentMethodTypeId");
+                String errMsg = "No payment release service for - " + paymentPref.getString("paymentMethodTypeId");
                 Debug.logWarning(errMsg, module);
                 return ServiceUtil.returnError(errMsg);
             }
         } else {
-            String errMsg = "No payment release settings found for - " + paymentPref.getString("paymentMethodTypeId");
+            String errMsg = "No payment release settings found for - " + paymentPref.getString("paymentMethodTypeId");
             Debug.logWarning(errMsg, module);
             return ServiceUtil.returnError(errMsg);
         }
@@ -1106,7 +1106,7 @@
                         return ServiceUtil.returnError(ex.getMessage());
                     }
                     if (captureResult != null) {
-                        
+
                         BigDecimal amountCaptured = (BigDecimal) captureResult.get("captureAmount");
                         Debug.logInfo("Amount captured for order [" + orderId + "] from unapplied payments associated to billing account [" + billingAccountId + "] is: " + amountCaptured, module);
 
@@ -1208,7 +1208,7 @@
                     amountCaptured = amountCaptured.setScale(decimals, rounding);
 
                     // decrease amount of next payment preference to capture
-                    amountToCapture = amountToCapture.subtract(amountCaptured);                
+                    amountToCapture = amountToCapture.subtract(amountCaptured);
 
                     // add the invoiceId to the result for processing
                     captureResult.put("invoiceId", invoiceId);
@@ -1323,12 +1323,12 @@
         BigDecimal captureAmount = (BigDecimal) context.get("captureAmount");
         String orderId = (String) context.get("orderId");
         Map results = ServiceUtil.returnSuccess();
-        
+
         try {
             // Note that the partyIdFrom of the Payment should be the partyIdTo of the invoice, since you're receiving a payment from the party you billed
             GenericValue invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));
-            Map paymentParams = UtilMisc.toMap("paymentTypeId", "CUSTOMER_PAYMENT", "paymentMethodTypeId", "EXT_BILLACT",
-                    "partyIdFrom", invoice.getString("partyId"), "partyIdTo", invoice.getString("partyIdFrom"),
+            Map paymentParams = UtilMisc.toMap("paymentTypeId", "CUSTOMER_PAYMENT", "paymentMethodTypeId", "EXT_BILLACT",
+                    "partyIdFrom", invoice.getString("partyId"), "partyIdTo", invoice.getString("partyIdFrom"),
                     "statusId", "PMNT_RECEIVED", "effectiveDate", UtilDateTime.nowTimestamp());
             paymentParams.put("amount", captureAmount);
             paymentParams.put("currencyUomId", invoice.getString("currencyUomId"));
@@ -1336,10 +1336,10 @@
             Map tmpResult = dispatcher.runSync("createPayment", paymentParams);
             if (ServiceUtil.isError(tmpResult)) {
                 return tmpResult;
-            }
-            
+            }
+
             String paymentId = (String) tmpResult.get("paymentId");
-            tmpResult = dispatcher.runSync("createPaymentApplication", UtilMisc.<String, Object>toMap("paymentId", paymentId, "invoiceId", invoiceId, "billingAccountId", billingAccountId,
+            tmpResult = dispatcher.runSync("createPaymentApplication", UtilMisc.<String, Object>toMap("paymentId", paymentId, "invoiceId", invoiceId, "billingAccountId", billingAccountId,
                     "amountApplied", captureAmount, "userLogin", userLogin));
             if (ServiceUtil.isError(tmpResult)) {
                 return tmpResult;
@@ -1348,7 +1348,7 @@
                 return ServiceUtil.returnError("No payment created for invoice [" + invoiceId + "] and billing account [" + billingAccountId + "]");
             }
             results.put("paymentId", paymentId);
-            
+
             if (orderId != null && captureAmount.compareTo(BigDecimal.ZERO) > 0) {
                 // Create a paymentGatewayResponse, if necessary
                 GenericValue order = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
@@ -1359,10 +1359,10 @@
                 List orderPaymentPreferences = delegator.findByAnd("OrderPaymentPreference", UtilMisc.toMap("orderId", orderId, "paymentMethodTypeId", "EXT_BILLACT"));
                 if (orderPaymentPreferences.size() > 0) {
                     GenericValue orderPaymentPreference = EntityUtil.getFirst(orderPaymentPreferences);
-                    
+
                     // Check the productStore setting to see if we need to do this explicitly
                     GenericValue productStore = order.getRelatedOne("ProductStore");
-                    if (productStore.getString("manualAuthIsCapture") == null || (! productStore.getString("manualAuthIsCapture").equalsIgnoreCase("Y"))) {        
+                    if (productStore.getString("manualAuthIsCapture") == null || (! productStore.getString("manualAuthIsCapture").equalsIgnoreCase("Y"))) {
                         String responseId = delegator.getNextSeqId("PaymentGatewayResponse");
                         GenericValue pgResponse = delegator.makeValue("PaymentGatewayResponse");
                         pgResponse.set("paymentGatewayResponseId", responseId);
@@ -1383,7 +1383,7 @@
                         // Update the orderPaymentPreference
                         orderPaymentPreference.set("statusId", "PAYMENT_SETTLED");
                         orderPaymentPreference.store();
-                        
+
                         results.put("paymentGatewayResponseId", responseId);
                     }
                 }
@@ -1407,7 +1407,7 @@
         captureAmount = captureAmount.setScale(decimals, rounding);
         String orderId = (String) context.get("orderId");
         BigDecimal capturedAmount = BigDecimal.ZERO;
-        
+
         try {
             // Select all the unapplied payment applications associated to the billing account
             List conditionList = UtilMisc.toList(EntityCondition.makeCondition("billingAccountId", EntityOperator.EQUALS, billingAccountId),
@@ -1460,7 +1460,7 @@
         results.put("captureAmount", capturedAmount);
         return results;
     }
-    
+
     private static Map capturePayment(DispatchContext dctx, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPref, BigDecimal amount) {
         return capturePayment(dctx, userLogin, orh, paymentPref, amount, null);
     }
@@ -1536,17 +1536,17 @@
             ModelService captureService = dctx.getModelService(serviceName);
             Set inParams = captureService.getInParamNames();
             if (inParams.contains("captureAmount")) {
-                captureContext.put("captureAmount", amount);    
+                captureContext.put("captureAmount", amount);
             } else if (inParams.contains("processAmount")) {
-                captureContext.put("processAmount", amount);    
+                captureContext.put("processAmount", amount);
             } else {
                 return ServiceUtil.returnError("Service [" + serviceName + "] does not have a captureAmount or processAmount.  Its parameters are: " + inParams);
             }
         } catch (GenericServiceException ex) {
             return ServiceUtil.returnError("Cannot get model service for " + serviceName);
         }
-        
-        
+
+
         if (authTrans != null) {
             captureContext.put("authTrans", authTrans);
         }
@@ -1665,7 +1665,7 @@
         // in case we rollback make sure this service gets called
         dispatcher.addRollbackService(model.name, context, true);
 
-        // invoke the service
+        // invoke the service
         Map resResp;
         try {
             resResp = dispatcher.runSync(model.name, context);
@@ -1675,7 +1675,7 @@
         }
         if (ServiceUtil.isError(resResp)) {
             throw new GeneralException(ServiceUtil.getErrorMessage(resResp));
-        }        
+        }
     }
 
     public static Map processAuthResult(DispatchContext dctx, Map context) {
@@ -1717,7 +1717,7 @@
             response.set("paymentMethodId", orderPaymentPreference.get("paymentMethodId"));
             response.set("transCodeEnumId", "PGT_AUTHORIZE");
             response.set("currencyUomId", currencyUomId);
-    
+
             // set the avs/fraud result
             response.set("gatewayAvsResult", context.get("avsCode"));
             response.set("gatewayCvResult", context.get("cvCode"));
@@ -1732,7 +1732,7 @@
             response.set("gatewayFlag", context.get("authFlag"));
             response.set("gatewayMessage", context.get("authMessage"));
             response.set("transactionDate", UtilDateTime.nowTimestamp());
-            
+
             if (Boolean.TRUE.equals((Boolean) context.get("resultDeclined"))) response.set("resultDeclined", "Y");
             if (Boolean.TRUE.equals((Boolean) context.get("resultNsf"))) response.set("resultNsf", "Y");
             if (Boolean.TRUE.equals((Boolean) context.get("resultBadExpire"))) response.set("resultBadExpire", "Y");
@@ -1740,7 +1740,7 @@
 
             // save the response
             savePgr(dctx, response);
-    
+
             // create the internal messages
             List messages = (List) context.get("internalRespMsgs");
             if (UtilValidate.isNotEmpty(messages)) {
@@ -1755,11 +1755,11 @@
                     savePgr(dctx, respMsg);
                 }
             }
-    
+
             if (response.getBigDecimal("amount").compareTo((BigDecimal)context.get("processAmount")) != 0) {
                 Debug.logWarning("The authorized amount does not match the max amount : Response - " + response + " : result - " + context, module);
             }
-    
+
             // set the status of the OrderPaymentPreference
             if (context != null && authResult.booleanValue()) {
                 orderPaymentPreference.set("statusId", "PAYMENT_AUTHORIZED");
@@ -1768,11 +1768,11 @@
             } else {
                 orderPaymentPreference.set("statusId", "PAYMENT_ERROR");
             }
-            
+
             // remove sensitive credit card data regardless of outcome
             orderPaymentPreference.set("securityCode", null);
-            orderPaymentPreference.set("track2", null);    
-                
+            orderPaymentPreference.set("track2", null);
+
             boolean needsNsfRetry = needsNsfRetry(orderPaymentPreference, context, delegator);
             if (needsNsfRetry) {
                 orderPaymentPreference.set("needsNsfRetry", "Y");
@@ -1792,7 +1792,7 @@
                         creditCard.set("consecutiveFailedAuths", new Long(consecutiveFailedAuths.longValue() + 1));
                     }
                     creditCard.set("lastFailedAuthDate", nowTimestamp);
-                    
+
                     if (Boolean.TRUE.equals((Boolean) context.get("resultNsf"))) {
                         Long consecutiveFailedNsf = creditCard.getLong("consecutiveFailedNsf");
                         if (consecutiveFailedNsf == null) {
@@ -1805,7 +1805,7 @@
                     creditCard.store();
                 }
             }
-            
+
             // auth was successful, to clear out any failed auth or nsf info
             if (authResult.booleanValue()) {
                 if ((creditCard != null) && (creditCard.get("lastFailedAuthDate") != null)) {
@@ -1824,7 +1824,7 @@
 
         return ServiceUtil.returnSuccess();
     }
-    
+
     private static boolean needsNsfRetry(GenericValue orderPaymentPreference, Map processContext, GenericDelegator delegator) throws GenericEntityException {
         boolean needsNsfRetry = false;
         if (Boolean.TRUE.equals((Boolean) processContext.get("resultNsf"))) {
@@ -1833,16 +1833,16 @@
             if (UtilValidate.isNotEmpty(orderHeader.getString("autoOrderShoppingListId"))) {
                 GenericValue productStore = orderHeader.getRelatedOne("ProductStore");
                 if ("Y".equals(productStore.getString("autoOrderCcTryLaterNsf"))) {
-                    // one last condition: make sure there have been less than ProductStore.autoOrderCcTryLaterMax
+                    // one last condition: make sure there have been less than ProductStore.autoOrderCcTryLaterMax
                     //   PaymentGatewayResponse records with the same orderPaymentPreferenceId and paymentMethodId (just in case it has changed)
                     //   and that have resultNsf = Y, ie only consider other NSF responses
                     Long autoOrderCcTryLaterMax = productStore.getLong("autoOrderCcTryLaterMax");
                     if (autoOrderCcTryLaterMax != null) {
-                        long failedTries = delegator.findCountByCondition("PaymentGatewayResponse",
+                        long failedTries = delegator.findCountByCondition("PaymentGatewayResponse",
                                 EntityCondition.makeCondition(UtilMisc.toMap(
-                                        "orderPaymentPreferenceId", orderPaymentPreference.get("orderPaymentPreferenceId"),
+                                        "orderPaymentPreferenceId", orderPaymentPreference.get("orderPaymentPreferenceId"),
                                         "paymentMethodId", orderPaymentPreference.get("paymentMethodId"),
-                                        "resultNsf", "Y"),
+                                        "resultNsf", "Y"),
                                     EntityOperator.AND),
                                 null, null);
                         if (failedTries < autoOrderCcTryLaterMax.longValue()) {
@@ -2077,7 +2077,7 @@
                     Debug.logError(e, message, module);
                     return ServiceUtil.returnError(message );
                 }
-            }
+            }
 
             // determine the partyIdFrom for the payment, which is who made the payment
             String partyIdFrom = null;
@@ -2110,7 +2110,7 @@
             } else {
                 // otherwise default to Company and print a big warning about this
                 partyIdTo = "Company";
-                Debug.logWarning("Using default value of [" + partyIdTo + "] for payTo on invoice [" + invoiceId + "] and orderPaymentPreference [" +
+                Debug.logWarning("Using default value of [" + partyIdTo + "] for payTo on invoice [" + invoiceId + "] and orderPaymentPreference [" +
                         paymentPreference.getString("orderPaymentPreferenceId") + "]", module);
             }
 
@@ -2468,12 +2468,12 @@
 
         return ServiceUtil.returnSuccess();
     }
-    
+
     public static Map retryFailedAuthNsfs(DispatchContext dctx, Map context) {
         GenericDelegator delegator = dctx.getDelegator();
         LocalDispatcher dispatcher = dctx.getDispatcher();
         GenericValue userLogin = (GenericValue) context.get("userLogin");
-        
+
         // get the date/time for one week before now since we'll only retry once a week for NSFs
         Calendar calcCal = Calendar.getInstance();
         calcCal.setTimeInMillis(System.currentTimeMillis());
@@ -2483,7 +2483,7 @@
         EntityListIterator eli = null;
         try {
             eli = delegator.find("OrderPaymentPreference",
-                    EntityCondition.makeCondition(EntityCondition.makeCondition("needsNsfRetry", EntityOperator.EQUALS, "Y"), EntityOperator.AND, EntityCondition.makeCondition(ModelEntity.STAMP_FIELD, EntityOperator.LESS_THAN_EQUAL_TO, oneWeekAgo)),
+                    EntityCondition.makeCondition(EntityCondition.makeCondition("needsNsfRetry", EntityOperator.EQUALS, "Y"), EntityOperator.AND, EntityCondition.makeCondition(ModelEntity.STAMP_FIELD, EntityOperator.LESS_THAN_EQUAL_TO, oneWeekAgo)),
                     null, null, UtilMisc.toList("orderId"), null);
 
             List processList = FastList.newInstance();
@@ -2517,7 +2517,7 @@
 
         return ServiceUtil.returnSuccess();
     }
-    
+
     public static GenericValue getCaptureTransaction(GenericValue orderPaymentPreference) {
         GenericValue capTrans = null;
         try {
@@ -2537,7 +2537,7 @@
 
     /**
      * Gets the chronologically latest PaymentGatewayResponse from an OrderPaymentPreference which is either a PRDS_PAY_AUTH
-     * or PRDS_PAY_REAUTH.  Used for capturing.  
+     * or PRDS_PAY_REAUTH.  Used for capturing.
      * @param orderPaymentPreference
      * @return
      */
@@ -2630,7 +2630,7 @@
     }
 
     // safe payment gateway store
-    private static void savePgr(DispatchContext dctx, GenericValue pgr) {        
+    private static void savePgr(DispatchContext dctx, GenericValue pgr) {
         Map context = UtilMisc.toMap("paymentGatewayResponse", pgr);
         LocalDispatcher dispatcher = dctx.getDispatcher();
         GenericDelegator delegator = dctx.getDelegator();
@@ -2940,7 +2940,7 @@
                 }
             }
         }
-        
+
         return ServiceUtil.returnSuccess();
     }
 
@@ -3027,7 +3027,7 @@
         result.put("processAmount", context.get("processAmount"));
         result.put("authRefNum", refNum);
         result.put("authAltRefNum", refNum);
-        result.put("authCode", "100");        
+        result.put("authCode", "100");
         result.put("authMessage", "This is a test processor; no payments were captured or authorized.");
 
         return result;
@@ -3139,7 +3139,7 @@
         String expireDate = creditCard.getString("expireDate");
         String lastNumberStr = expireDate.substring(expireDate.length() - 1);
         int lastNumber = Integer.parseInt(lastNumberStr);
-        
+
         if ((float) lastNumber / 2.0 == 0.0) {
             return alwaysBadExpireProcessor(dctx, context);
         } else {

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java?rev=757093&r1=757092&r2=757093&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java Sat Mar 21 23:44:59 2009
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -40,7 +40,7 @@
  * Services for Payment maintenance
  */
 public class PaymentMethodServices {
-    
+
     public final static String module = PaymentMethodServices.class.getName();
 
     /**
@@ -91,12 +91,12 @@
         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
         return result;
     }
-    
+
     public static Map makeExpireDate(DispatchContext ctx, Map context) {
         Map result = new HashMap();
         String expMonth = (String) context.get("expMonth");
         String expYear = (String) context.get("expYear");
-        
+
         StringBuffer expDate = new StringBuffer();
         expDate.append(expMonth);
         expDate.append("/");
@@ -265,11 +265,11 @@
         if (!paymentMethod.getString("partyId").equals(partyId) && !security.hasEntityPermission("PAY_INFO", "_UPDATE", userLogin)) {
             return ServiceUtil.returnError("Party Id [" + partyId + "] is not the owner of payment method [" + paymentMethodId + "] and does not have permission to change it.");
         }
-        
+
         // do some more complicated/critical validation...
         List messages = new LinkedList();
-        
-        // first remove all spaces from the credit card number      
+
+        // first remove all spaces from the credit card number
         String updatedCardNumber = StringUtil.removeSpaces((String) context.get("cardNumber"));
         if (updatedCardNumber.startsWith("*")) {
             // get the masked card number from the db
@@ -282,14 +282,14 @@
             }
             origMaskedNumber = origMaskedNumber + origCardNumber.substring(cardLength);
             Debug.log(origMaskedNumber);
-            
+
             // compare the two masked numbers
             if (updatedCardNumber.equals(origMaskedNumber)) {
                 updatedCardNumber = origCardNumber;
-            }            
+            }
         }
         context.put("cardNumber", updatedCardNumber);
-        
+
         if (!UtilValidate.isCardMatch((String) context.get("cardType"), (String) context.get("cardNumber")))
             messages.add((String) context.get("cardNumber")
                     + UtilValidate.isCreditCardPrefixMsg + (String) context.get("cardType") + UtilValidate.isCreditCardSuffixMsg
@@ -298,7 +298,7 @@
             messages.add("The expiration date " + (String) context.get("expireDate") + " is before today.");
         if (messages.size() > 0) {
             return ServiceUtil.returnError(messages);
-        }        
+        }
 
         newPm = GenericValue.create(paymentMethod);
         toBeStored.add(newPm);
@@ -310,7 +310,7 @@
             newPmId = delegator.getNextSeqId("PaymentMethod");
         } catch (IllegalArgumentException e) {
             return ServiceUtil.returnError("ERROR: Could not update credit card info (id generation failure)");
-            
+
         }
 
         newPm.set("partyId", partyId);
@@ -688,7 +688,7 @@
 
             if (tempVal == null) {
                 // no value found, create a new one
-                newPartyContactMechPurpose = delegator.makeValue("PartyContactMechPurpose",
+                newPartyContactMechPurpose = delegator.makeValue("PartyContactMechPurpose",
                     UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId, "fromDate", now));
             }
         }
@@ -794,7 +794,7 @@
             GenericValue tempVal = null;
 
             try {
-                List allPCMPs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",
+                List allPCMPs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",
                             UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId",contactMechPurposeTypeId), null), true);
                 tempVal = EntityUtil.getFirst(allPCMPs);
             } catch (GenericEntityException e) {