details:   https://code.openbravo.com/erp/devel/pi/rev/490fcc05cd42
changeset: 21247:490fcc05cd42
user:      David Miguelez <david.miguelez <at> openbravo.com>
date:      Wed Oct 09 10:33:50 2013 +0200
summary:   Fixes Issue 24555. Fixes Issue with duplicated lines in Accounting.

diffstat:

 src/org/openbravo/erpCommon/ad_forms/AcctServer.java              |  88 
++++++++-
 src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java |  18 +-
 src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java           |  19 +-
 src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java    |  18 +-
 4 files changed, 124 insertions(+), 19 deletions(-)

diffs (266 lines):

diff -r 097ff53c20f1 -r 490fcc05cd42 
src/org/openbravo/erpCommon/ad_forms/AcctServer.java
--- a/src/org/openbravo/erpCommon/ad_forms/AcctServer.java      Tue Oct 08 
23:52:19 2013 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java      Wed Oct 09 
10:33:50 2013 +0200
@@ -2815,21 +2815,25 @@
    *          Invoice Payment Schedule of actual Payment Detail
    * @param pso
    *          Order Payment Schedule of actual Payment Detail
-   * @param i
+   * @param currentPaymentDetailIndex
    *          Index
    */
+  @Deprecated
   public BigDecimal getPaymentDetailAmount(List<FIN_PaymentDetail> 
paymentDetails,
-      FIN_PaymentSchedule ps, FIN_PaymentSchedule psi, FIN_PaymentSchedule 
pso, int i) {
+      FIN_PaymentSchedule ps, FIN_PaymentSchedule psi, FIN_PaymentSchedule pso,
+      int currentPaymentDetailIndex) {
     if (psi == null && pso == null) {
-      return paymentDetails.get(i).getAmount();
+      return paymentDetails.get(currentPaymentDetailIndex).getAmount();
     }
     // If the actual Payment Detail belongs to the same Invoice Payment 
Schedule as the previous
     // record, or it has no Order related.
     if ((psi != null && psi.equals(ps)) || pso == null) {
-      FIN_PaymentScheduleDetail psdNext = (i == paymentDetails.size() - 1) ? 
null : paymentDetails
-          .get(i + 1).getFINPaymentScheduleDetailList().get(0);
-      FIN_PaymentScheduleDetail psdPrevious = (i == 0) ? null : 
paymentDetails.get(i - 1)
-          .getFINPaymentScheduleDetailList().get(0);
+      FIN_PaymentScheduleDetail psdNext = (currentPaymentDetailIndex == 
paymentDetails.size() - 1) ? null
+          : paymentDetails.get(currentPaymentDetailIndex + 
1).getFINPaymentScheduleDetailList()
+              .get(0);
+      FIN_PaymentScheduleDetail psdPrevious = (currentPaymentDetailIndex == 0) 
? null
+          : paymentDetails.get(currentPaymentDetailIndex - 
1).getFINPaymentScheduleDetailList()
+              .get(0);
       // If it has no Order related, and the next record belongs to the same 
Invoice Payment
       // Schedule and the next record has an Order related.
       if (pso == null && psdNext != null && 
psdNext.getInvoicePaymentSchedule() == psi
@@ -2839,13 +2843,77 @@
         // record has no Order related.
       } else if (psdPrevious != null && 
psdPrevious.getInvoicePaymentSchedule() == psi
           && psdPrevious.getOrderPaymentSchedule() == null) {
-        return paymentDetails.get(i).getAmount().add(paymentDetails.get(i - 
1).getAmount());
+        return paymentDetails.get(currentPaymentDetailIndex).getAmount()
+            .add(paymentDetails.get(currentPaymentDetailIndex - 
1).getAmount());
       } else {
-        return paymentDetails.get(i).getAmount();
+        return paymentDetails.get(currentPaymentDetailIndex).getAmount();
       }
     } else {
-      return paymentDetails.get(i).getAmount();
+      return paymentDetails.get(currentPaymentDetailIndex).getAmount();
     }
   }
 
+  /**
+   * Returns the writeoff and the amount of a Payment Detail. In case the 
related Payment Schedule
+   * Detail was generated for compensate the difference between an Order and a 
related Invoice, it
+   * merges it's amount with the next Payment Schedule Detail. Issue 19567:
+   * https://issues.openbravo.com/view.php?id=19567
+   * 
+   * @param paymentDetails
+   *          List of payment Details
+   * @param ps
+   *          Previous Payment Schedule
+   * @param psi
+   *          Invoice Payment Schedule of actual Payment Detail
+   * @param pso
+   *          Order Payment Schedule of actual Payment Detail
+   * @param currentPaymentDetailIndex
+   *          Index
+   */
+  public HashMap<String, BigDecimal> getPaymentDetailWriteOffAndAmount(
+      List<FIN_PaymentDetail> paymentDetails, FIN_PaymentSchedule ps, 
FIN_PaymentSchedule psi,
+      FIN_PaymentSchedule pso, int currentPaymentDetailIndex) {
+
+    HashMap<String, BigDecimal> amountAndWriteOff = new HashMap<String, 
BigDecimal>();
+
+    // If the Payment Detail has either an Invoice or an Order associated to it
+    if (psi != null || pso != null) {
+      // If the Payment Detail has no Order associated to it, or it has an 
Invoice associated and is
+      // the same one as the previous Payment Detail
+      if ((psi != null && psi.equals(ps)) || pso == null) {
+        FIN_PaymentScheduleDetail psdNext = (currentPaymentDetailIndex == 
paymentDetails.size() - 1) ? null
+            : paymentDetails.get(currentPaymentDetailIndex + 
1).getFINPaymentScheduleDetailList()
+                .get(0);
+        FIN_PaymentScheduleDetail psdPrevious = (currentPaymentDetailIndex == 
0) ? null
+            : paymentDetails.get(currentPaymentDetailIndex - 
1).getFINPaymentScheduleDetailList()
+                .get(0);
+        // If the Payment Detail has no Order associated, and the next Payment 
Detail belongs to the
+        // same Invoice and it has an Order related, then return null
+        if (pso == null && psdNext != null && 
psdNext.getInvoicePaymentSchedule() == psi
+            && psdNext.getOrderPaymentSchedule() != null) {
+          amountAndWriteOff.put("amount", null);
+          amountAndWriteOff.put("writeoff", null);
+          // If there is a previous Payment Detail that belongs to the same 
Invoice and has no Order
+          // related to it, return the sum of amounts.
+        } else if (psdPrevious != null && 
psdPrevious.getInvoicePaymentSchedule() == psi
+            && psdPrevious.getOrderPaymentSchedule() == null) {
+          amountAndWriteOff.put("amount", 
paymentDetails.get(currentPaymentDetailIndex).getAmount()
+              .add(paymentDetails.get(currentPaymentDetailIndex - 
1).getAmount()));
+          amountAndWriteOff.put(
+              "writeoff",
+              paymentDetails.get(currentPaymentDetailIndex).getWriteoffAmount()
+                  .add(paymentDetails.get(currentPaymentDetailIndex - 
1).getWriteoffAmount()));
+        }
+      }
+    }
+
+    // In any other case
+    amountAndWriteOff.put("amount", 
paymentDetails.get(currentPaymentDetailIndex).getAmount());
+    amountAndWriteOff.put("writeoff", 
paymentDetails.get(currentPaymentDetailIndex)
+        .getWriteoffAmount());
+
+    return amountAndWriteOff;
+
+  }
+
 }
diff -r 097ff53c20f1 -r 490fcc05cd42 
src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java Tue Oct 
08 23:52:19 2013 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java Wed Oct 
09 10:33:50 2013 +0200
@@ -117,6 +117,7 @@
     List<FIN_PaymentDetail> paymentDetails = 
FIN_Utility.getOrderedPaymentDetailList(payment);
     FieldProviderFactory[] data = new 
FieldProviderFactory[paymentDetails.size()];
     FIN_PaymentSchedule ps = null;
+    FIN_PaymentDetail pd = null;
     OBContext.setAdminMode();
     try {
       for (int i = 0; i < data.length; i++) {
@@ -129,12 +130,24 @@
           continue;
         }
 
+        // If the Payment Detail has already been processed, skip it
+        if (paymentDetails.get(i).equals(pd)) {
+          continue;
+        }
+        pd = paymentDetails.get(i);
+
         data[i] = new FieldProviderFactory(null);
         FIN_PaymentSchedule psi = 
paymentDetails.get(i).getFINPaymentScheduleDetailList().get(0)
             .getInvoicePaymentSchedule();
         FIN_PaymentSchedule pso = 
paymentDetails.get(i).getFINPaymentScheduleDetailList().get(0)
             .getOrderPaymentSchedule();
-        BigDecimal amount = getPaymentDetailAmount(paymentDetails, ps, psi, 
pso, i);
+        // Related to Issue Issue 19567. Some Payment Detail's amount and 
writeoff amount are merged
+        // into one.
+        // https://issues.openbravo.com/view.php?id=19567
+        HashMap<String, BigDecimal> amountAndWriteOff = 
getPaymentDetailWriteOffAndAmount(
+            paymentDetails, ps, psi, pso, i);
+        BigDecimal amount = amountAndWriteOff.get("amount");
+        BigDecimal writeOff = amountAndWriteOff.get("writeoff");
         if (amount == null) {
           data[i] = null;
           ps = psi;
@@ -165,8 +178,7 @@
             .get(i));
         FieldProviderFactory.setField(data[i], 
"isPaymentDatePriorToInvoiceDate",
             isPaymentDatePriorToInvoiceDate && 
!paymentDetails.get(i).isPrepayment() ? "Y" : "N");
-        FieldProviderFactory.setField(data[i], "WriteOffAmt", 
paymentDetails.get(i)
-            .getWriteoffAmount().toString());
+        FieldProviderFactory.setField(data[i], "WriteOffAmt", 
writeOff.toString());
         FieldProviderFactory.setField(data[i], "cGlItemId",
             paymentDetails.get(i).getGLItem() != null ? 
paymentDetails.get(i).getGLItem().getId()
                 : "");
diff -r 097ff53c20f1 -r 490fcc05cd42 
src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java   Tue Oct 08 
23:52:19 2013 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java   Wed Oct 09 
10:33:50 2013 +0200
@@ -22,6 +22,7 @@
 import java.sql.Connection;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
 import javax.servlet.ServletException;
@@ -90,6 +91,7 @@
 
     FieldProviderFactory[] data = new 
FieldProviderFactory[paymentDetails.size()];
     FIN_PaymentSchedule ps = null;
+    FIN_PaymentDetail pd = null;
     OBContext.setAdminMode();
     try {
       for (int i = 0; i < data.length; i++) {
@@ -99,12 +101,24 @@
           continue;
         }
 
+        // If the Payment Detail has already been processed, skip it
+        if (paymentDetails.get(i).equals(pd)) {
+          continue;
+        }
+        pd = paymentDetails.get(i);
+
         data[i] = new FieldProviderFactory(null);
         FIN_PaymentSchedule psi = 
paymentDetails.get(i).getFINPaymentScheduleDetailList().get(0)
             .getInvoicePaymentSchedule();
         FIN_PaymentSchedule pso = 
paymentDetails.get(i).getFINPaymentScheduleDetailList().get(0)
             .getOrderPaymentSchedule();
-        BigDecimal amount = getPaymentDetailAmount(paymentDetails, ps, psi, 
pso, i);
+        // Related to Issue Issue 19567. Some Payment Detail's amount and 
writeoff amount are merged
+        // into one.
+        // https://issues.openbravo.com/view.php?id=19567
+        HashMap<String, BigDecimal> amountAndWriteOff = 
getPaymentDetailWriteOffAndAmount(
+            paymentDetails, ps, psi, pso, i);
+        BigDecimal amount = amountAndWriteOff.get("amount");
+        BigDecimal writeOff = amountAndWriteOff.get("writeoff");
         if (amount == null) {
           data[i] = null;
           ps = psi;
@@ -135,8 +149,7 @@
             : "");
         FieldProviderFactory.setField(data[i], "DoubtFulDebtAmount", 
paymentDetails.get(i)
             
.getFINPaymentScheduleDetailList().get(0).getDoubtfulDebtAmount().toString());
-        FieldProviderFactory.setField(data[i], "WriteOffAmt", 
paymentDetails.get(i)
-            .getWriteoffAmount().toString());
+        FieldProviderFactory.setField(data[i], "WriteOffAmt", 
writeOff.toString());
         FieldProviderFactory.setField(data[i], "C_GLItem_ID",
             paymentDetails.get(i).getGLItem() != null ? 
paymentDetails.get(i).getGLItem().getId()
                 : "");
diff -r 097ff53c20f1 -r 490fcc05cd42 
src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java    Tue Oct 
08 23:52:19 2013 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java    Wed Oct 
09 10:33:50 2013 +0200
@@ -166,6 +166,7 @@
     List<FIN_PaymentDetail> paymentDetails = 
FIN_Utility.getOrderedPaymentDetailList(payment);
     FieldProviderFactory[] data = new 
FieldProviderFactory[paymentDetails.size()];
     FIN_PaymentSchedule ps = null;
+    FIN_PaymentDetail pd = null;
     OBContext.setAdminMode();
     try {
       for (int i = 0; i < data.length; i++) {
@@ -175,12 +176,24 @@
           continue;
         }
 
+        // If the Payment Detail has already been processed, skip it
+        if (paymentDetails.get(i).equals(pd)) {
+          continue;
+        }
+        pd = paymentDetails.get(i);
+
         data[i] = new FieldProviderFactory(null);
         FIN_PaymentSchedule psi = 
paymentDetails.get(i).getFINPaymentScheduleDetailList().get(0)
             .getInvoicePaymentSchedule();
         FIN_PaymentSchedule pso = 
paymentDetails.get(i).getFINPaymentScheduleDetailList().get(0)
             .getOrderPaymentSchedule();
-        BigDecimal amount = getPaymentDetailAmount(paymentDetails, ps, psi, 
pso, i);
+        // Related to Issue Issue 19567. Some Payment Detail's amount and 
writeoff amount are merged
+        // into one.
+        // https://issues.openbravo.com/view.php?id=19567
+        HashMap<String, BigDecimal> amountAndWriteOff = 
getPaymentDetailWriteOffAndAmount(
+            paymentDetails, ps, psi, pso, i);
+        BigDecimal amount = amountAndWriteOff.get("amount");
+        BigDecimal writeOff = amountAndWriteOff.get("writeoff");
         if (amount == null) {
           data[i] = null;
           ps = psi;
@@ -218,8 +231,7 @@
             .get(i));
         FieldProviderFactory.setField(data[i], 
"isPaymentDatePriorToInvoiceDate",
             isPaymentDatePriorToInvoiceDate && 
!paymentDetails.get(i).isPrepayment() ? "Y" : "N");
-        FieldProviderFactory.setField(data[i], "WriteOffAmt", 
paymentDetails.get(i)
-            .getWriteoffAmount().toString());
+        FieldProviderFactory.setField(data[i], "WriteOffAmt", 
writeOff.toString());
         FieldProviderFactory.setField(data[i], "cGlItemId",
             paymentDetails.get(i).getGLItem() != null ? 
paymentDetails.get(i).getGLItem().getId()
                 : "");

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to