Fixes issue 15884: CurrentDSO and Overdue columns are being calculated wrong.
authorIoritz Cia <ioritz.cia@openbravo.com>
Thu, 05 May 2011 20:29:37 +0200
changeset 12063 305530340709
parent 12062 e317dcf60d8d
child 12064 65e926b95433
Fixes issue 15884: CurrentDSO and Overdue columns are being calculated wrong.
modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Thu May 05 19:46:37 2011 +0200
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Thu May 05 20:29:37 2011 +0200
@@ -515,31 +515,23 @@
               FIN_PaymentScheduleDetail[i].getInvoicePaymentSchedule().getDueDate()).toString());
           // plannedDSO
           plannedDSO = (FIN_PaymentScheduleDetail[i].getInvoicePaymentSchedule().getDueDate()
-              .getTime() - FIN_PaymentScheduleDetail[i].getInvoicePaymentSchedule().getInvoice()
-              .getInvoiceDate().getTime());
+              .getTime() - invoicedDate.getTime());
           FieldProviderFactory.setField(data[i], "PLANNED_DSO", String.valueOf(plannedDSO
               / (1000 * 60 * 60 * 24)));
           // currentDSO
-          currentTime = System.currentTimeMillis();
-          if (currentTime < invoicedDate.getTime())
-            FieldProviderFactory.setField(data[i], "CURRENT_DSO", String.valueOf(plannedDSO
-                / (1000 * 60 * 60 * 24)));
-          else {
-            currentDSO = currentTime
-                - FIN_PaymentScheduleDetail[i].getInvoicePaymentSchedule().getInvoice()
-                    .getInvoiceDate().getTime();
-            FieldProviderFactory.setField(data[i], "CURRENT_DSO", String.valueOf((currentDSO)
-                / (1000 * 60 * 60 * 24)));
+          if (FIN_PaymentScheduleDetail[i].getPaymentDetails() != null) {
+            currentDSO = FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment()
+                .getPaymentDate().getTime()
+                - invoicedDate.getTime();
+          } else {
+            currentTime = System.currentTimeMillis();
+            currentDSO = currentTime - invoicedDate.getTime();
           }
+          FieldProviderFactory.setField(data[i], "CURRENT_DSO", String.valueOf((currentDSO)
+              / (1000 * 60 * 60 * 24)));
           // daysOverdue
-          if (currentTime < FIN_PaymentScheduleDetail[i].getInvoicePaymentSchedule().getDueDate()
-              .getTime())
-            FieldProviderFactory.setField(data[i], "OVERDUE", "0");
-          else
-            FieldProviderFactory.setField(data[i], "OVERDUE", String
-                .valueOf((currentTime - FIN_PaymentScheduleDetail[i].getInvoicePaymentSchedule()
-                    .getDueDate().getTime())
-                    / (1000 * 60 * 60 * 24)));
+          FieldProviderFactory.setField(data[i], "OVERDUE", String
+              .valueOf((currentDSO - plannedDSO) / (1000 * 60 * 60 * 24)));
         } else {
           // project
           FieldProviderFactory.setField(data[i], "PROJECT", "");