Author: bibryam
Date: Tue Aug  2 09:04:02 2011
New Revision: 1153073

URL: http://svn.apache.org/viewvc?rev=1153073&view=rev
Log:
A slightly modified patch from Martin Kreidenweis - voided payments are 
auto-applied to new order invoices
https://issues.apache.org/jira/browse/OFBIZ-4345

Modified:
    
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java

Modified: 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?rev=1153073&r1=1153072&r2=1153073&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
 (original)
+++ 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
 Tue Aug  2 09:04:02 2011
@@ -747,7 +747,10 @@ public class InvoiceServices {
             }
 
             // check for previous order payments
-            List<GenericValue> orderPaymentPrefs = 
delegator.findByAnd("OrderPaymentPreference", UtilMisc.toMap("orderId", 
orderId));
+            List<EntityExpr> paymentPrefConds = UtilMisc.toList(
+                    EntityCondition.makeCondition("orderId", 
EntityOperator.EQUALS, orderId),
+                    EntityCondition.makeCondition("statusId", 
EntityOperator.NOT_EQUAL, "PAYMENT_CANCELLED"));
+            List<GenericValue> orderPaymentPrefs = 
delegator.findList("OrderPaymentPreference", 
EntityCondition.makeCondition(paymentPrefConds, EntityOperator.AND), null, 
null, null, false);
             List<GenericValue> currentPayments = FastList.newInstance();
             for (GenericValue paymentPref : orderPaymentPrefs) {
                 List<GenericValue> payments = 
paymentPref.getRelated("Payment");
@@ -755,6 +758,9 @@ public class InvoiceServices {
             }
             // apply these payments to the invoice if they have any remaining 
amount to apply
             for (GenericValue payment : currentPayments) {
+                if ("PMNT_VOID".equals(payment.getString("statusId")) || 
"PMNT_CANCELLED".equals(payment.getString("statusId"))) {
+                    continue;
+                }
                 BigDecimal notApplied = 
PaymentWorker.getPaymentNotApplied(payment);
                 if (notApplied.signum() > 0) {
                     Map<String, Object> appl = FastMap.newInstance();


Reply via email to