Author: sichen
Date: Fri Nov 14 15:10:13 2008
New Revision: 714185

URL: http://svn.apache.org/viewvc?rev=714185&view=rev
Log:
fix bug where payments are not applied to invoices generated by subsequent ship 
groups that are packed

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=714185&r1=714184&r2=714185&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
 Fri Nov 14 15:10:13 2008
@@ -774,19 +774,17 @@
                 currentPayments.addAll(payments);
             }
             if (currentPayments.size() > 0) {
-                // apply these payments to the invoice; only if they haven't 
already been applied
+                // apply these payments to the invoice if they have any 
remaining amount to apply
                 Iterator cpi = currentPayments.iterator();
                 while (cpi.hasNext()) {
                     GenericValue payment = (GenericValue) cpi.next();
-                    List currentApplications = null;
-                    currentApplications = 
payment.getRelated("PaymentApplication");
-                    if (currentApplications == null || 
currentApplications.size() == 0) {
-                        // no applications; okay to apply
+                    BigDecimal notApplied = 
PaymentWorker.getPaymentNotAppliedBd(payment);
+                    if (notApplied.signum() > 0) {
                         Map appl = new HashMap();
                         appl.put("paymentId", payment.get("paymentId"));
                         appl.put("invoiceId", invoiceId);
                         appl.put("billingAccountId", billingAccountId);
-                        appl.put("amountApplied", payment.get("amount"));
+                        appl.put("amountApplied", new 
Double(notApplied.doubleValue()));
                         appl.put("userLogin", userLogin);
                         Map createPayApplResult = 
dispatcher.runSync("createPaymentApplication", appl); 
                         if (ServiceUtil.isError(createPayApplResult)) {


Reply via email to