Related to BUG-43380:Remittance of a payment out using
authorAtul Gaware <atul.gaware@openbravo.com>
Wed, 11 Mar 2020 14:11:54 +0530
changeset 37206 5214fb3a858d
parent 37205 77322000dc90
child 37207 c65f62b9ff01
Related to BUG 43380:Remittance of a payment out using
credit gets unbalance and posts on Suspense Balancing
account

**Add field to store AmountExcludingCredit used in payment
**Add getter and setter method for AmountExcludingCredit
**Calculate the AmountExcludingCredit for each payment detail
linked with payment, proportionate used credit per
payment detail is separated from each payment detail
amount, in the last payment detail rounding amount
is adjusted.
src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java
src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java	Thu Mar 12 10:06:25 2020 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java	Wed Mar 11 14:11:54 2020 +0530
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2019 Openbravo SLU
+ * All portions are Copyright (C) 2010-2020 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -95,7 +95,12 @@
       return null;
     }
 
-    FieldProviderFactory[] data = new FieldProviderFactory[paymentDetails.size()];
+    int noOfPaymentDetails = paymentDetails.size();
+    BigDecimal usedCredit = payment.getUsedCredit();
+    BigDecimal creditAmtToAdjust = usedCredit.divide(new BigDecimal(noOfPaymentDetails),
+        payment.getCurrency().getPricePrecision().intValue(), RoundingMode.HALF_UP);
+    BigDecimal totalCreditAdjusted = BigDecimal.ZERO;
+    FieldProviderFactory[] data = new FieldProviderFactory[noOfPaymentDetails];
     String psId = null;
     String pdId = null;
     BigDecimal totalAmount = BigDecimal.ZERO;
@@ -155,6 +160,14 @@
             totalAmount = amount;
           }
           FieldProviderFactory.setField(data[i], "Amount", totalAmount.toString());
+          BigDecimal amountExcludingCredit = totalAmount.subtract(creditAmtToAdjust);
+          totalCreditAdjusted = totalCreditAdjusted.add(creditAmtToAdjust);
+          if (i == noOfPaymentDetails - 1) {
+            amountExcludingCredit = amountExcludingCredit
+                .subtract(usedCredit.subtract(totalCreditAdjusted));
+          }
+          FieldProviderFactory.setField(data[i], "AmountExcludingCredit",
+              amountExcludingCredit.toString());
         }
         psId = psi != null ? psi.getId() : null;
 
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java	Thu Mar 12 10:06:25 2020 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java	Wed Mar 11 14:11:54 2020 +0530
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2016 Openbravo SLU
+ * All portions are Copyright (C) 2010-2020 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -36,6 +36,7 @@
   String isPrepayment = "";
   boolean isPrepaymentAgainstInvoice = false;
   BigDecimal doubtFulDebtAmount = BigDecimal.ZERO;
+  String AmountExcludingCredit = "";
 
   @Deprecated
   Invoice invoice = null;
@@ -148,6 +149,13 @@
   }
 
   /**
+   * @return the amountExcludingCredit
+   */
+  public String getAmountExcludingCredit() {
+    return AmountExcludingCredit;
+  }
+
+  /**
    * @return the line_ID
    */
   public String getLine_ID() {
@@ -201,6 +209,14 @@
     Amount = amount;
   }
 
+  /**
+   * @param amountExcludingCredit
+   *          the amountExcludingCredit to set
+   */
+  public void setAmountExcludingCredit(String amountExcludingCredit) {
+    AmountExcludingCredit = amountExcludingCredit;
+  }
+
   public BigDecimal getDoubtFulDebtAmount() {
     return doubtFulDebtAmount;
   }