Fixes Issue 24778, Fixes Issue 24768
authorVíctor Martínez Romanos <victor.martinez@openbravo.com>
Mon, 21 Oct 2013 12:26:36 +0530
changeset 21343 0c6559f88e5a
parent 21342 c4d4ca9a75dc
child 21344 bb980d7198e0
Fixes Issue 24778, Fixes Issue 24768

Payment Monitor doesn't udpate invoice status when voiding a payment
Payment Monitor NullPointer Exception in method calculateAmounts()
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentMonitorProcess.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentMonitorProcess.java	Mon Oct 21 17:37:49 2013 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentMonitorProcess.java	Mon Oct 21 12:26:36 2013 +0530
@@ -22,10 +22,11 @@
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
@@ -87,10 +88,11 @@
 
       StringBuilder whereClause = new StringBuilder();
       whereClause.append(" as i");
-      whereClause.append("   left join i.fINPaymentScheduleList fps");
+      whereClause.append("   left join i.fINPaymentScheduleList fps ");
       whereClause.append(" where i.processed=true");
-      whereClause.append(" and (i.paymentComplete=false");
-      whereClause.append(" or i.outstandingAmount <> 0");
+      whereClause.append(" and (i.paymentComplete=false ");
+      whereClause.append("      or fps.updated >= i.lastCalculatedOnDate ");
+      whereClause.append("      or i.outstandingAmount <> 0");
       if (migration != null) {
         whereClause.append("  or (i.finalSettlementDate is null");
         whereClause.append(" and fps.id is not null");
@@ -107,7 +109,7 @@
         obc.setFilterOnReadableClients(false);
         obc.setFilterOnReadableOrganization(false);
       }
-      final List<String> invoiceIds = new ArrayList<String>();
+      final Set<String> invoiceIds = new HashSet<String>();
       for (Invoice invoice : obc.list()) {
         invoiceIds.add(invoice.getId());
       }
@@ -179,6 +181,7 @@
 
       OBDal.getInstance().save(invoice);
       OBDal.getInstance().flush();
+    } catch (Exception e) {
     } finally {
       OBContext.restorePreviousMode();
     }
@@ -257,19 +260,23 @@
       }
 
       if (paymentSchedule.getPaidAmount().compareTo(paid) != 0) {
-        logger.log("ERROR Invoice " + invoice.getDocumentNo()
-            + ": wrong payment plan info, paid amount is "
-            + paymentSchedule.getPaidAmount().toPlainString() + " when it should be "
-            + paid.toPlainString());
+        if (logger != null) {
+          logger.log("ERROR Invoice " + invoice.getDocumentNo()
+              + ": wrong payment plan info, paid amount is "
+              + paymentSchedule.getPaidAmount().toPlainString() + " when it should be "
+              + paid.toPlainString());
+        }
         paymentSchedule.setPaidAmount(paid);
         OBDal.getInstance().save(paymentSchedule);
       }
       if (paymentSchedule.getOutstandingAmount().compareTo(
           paymentSchedule.getAmount().subtract(paid)) != 0) {
-        logger.log("ERROR Invoice " + invoice.getDocumentNo()
-            + ": wrong payment plan info, outstanding amount is "
-            + paymentSchedule.getOutstandingAmount().toPlainString() + " when it should be "
-            + paymentSchedule.getAmount().subtract(paid).toPlainString());
+        if (logger != null) {
+          logger.log("ERROR Invoice " + invoice.getDocumentNo()
+              + ": wrong payment plan info, outstanding amount is "
+              + paymentSchedule.getOutstandingAmount().toPlainString() + " when it should be "
+              + paymentSchedule.getAmount().subtract(paid).toPlainString());
+        }
         paymentSchedule.setOutstandingAmount(paymentSchedule.getAmount().subtract(paid));
         OBDal.getInstance().save(paymentSchedule);
       }