From 24836a7c6c1d9328c3266cbb322f116eb464b443 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 15 Mar 2022 15:11:06 +0100 Subject: [PATCH] IDEMPIERE-5231 Create Payments from Bank Statement is not taking into account Discounts (#1248) * IDEMPIERE-5231 Create Payments from Bank Statement is not taking into account Discounts #resolve * - Remove misleading closing message --- .../org/compiere/process/BankStatementPayment.java | 5 ++++- .../src/org/compiere/model/MInvoice.java | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/org.adempiere.base.process/src/org/compiere/process/BankStatementPayment.java b/org.adempiere.base.process/src/org/compiere/process/BankStatementPayment.java index 7b7492cda8..82b4554909 100644 --- a/org.adempiere.base.process/src/org/compiere/process/BankStatementPayment.java +++ b/org.adempiere.base.process/src/org/compiere/process/BankStatementPayment.java @@ -220,7 +220,10 @@ public class BankStatementPayment extends SvrProcess payment.setPayAmt(PayAmt); else // payment is likely to be negative payment.setPayAmt(PayAmt.negate()); - payment.setOverUnderAmt(invoice.getOpenAmt().subtract(payment.getPayAmt())); + BigDecimal discountAmt = invoice.getDiscountAmt(payment.getDateTrx()); + payment.setDiscountAmt(discountAmt); + BigDecimal overUnderAmt = invoice.getOpenAmt().subtract(payment.getPayAmt()).subtract(discountAmt); + payment.setOverUnderAmt(overUnderAmt); } else // set Pay Amout from Invoice { diff --git a/org.adempiere.base/src/org/compiere/model/MInvoice.java b/org.adempiere.base/src/org/compiere/model/MInvoice.java index 601f9f63ef..2aee361e4d 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoice.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoice.java @@ -72,7 +72,7 @@ public class MInvoice extends X_C_Invoice implements DocAction, IDocsPostProcess /** * */ - private static final long serialVersionUID = -261338363319970683L; + private static final long serialVersionUID = -303676612533389278L; /** * Get Payments Of BPartner @@ -1404,6 +1404,18 @@ public class MInvoice extends X_C_Invoice implements DocAction, IDocsPostProcess return retValue; } // getOpenAmt + /* + * Get discount amt depending on payment date + * @return discount Amt + */ + public BigDecimal getDiscountAmt(Timestamp paymentDate) + { + BigDecimal retValue = DB.getSQLValueBDEx(get_TrxName(), + "SELECT invoiceDiscount(?,?,?) FROM DUAL", + getC_Invoice_ID(), paymentDate, 0); + return retValue; + } + /** * Get Document Status * @return Document Status Clear Text