Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
I'm looking at MInvoice.getOpenAmt method and it looks like it's not fully implemented.The paymentDate parameter has no functionality. I think that what it's supposed to do is to consider if any discounts should be applied in regard to the payment term and timestamp. I need this to work in a different project and I wonder if below would be a solution. And I'd be very pleased for any kind of input.
One more thing about getOpenAmt that caused me trouble earlier is that if you call the method getOpenAmt once it doesn't update the value any more (" if (m_openAmt == null)" )
This is kind of dangerous if you call the method twice and in between the two calls you e.g. have allocated a payment. Then you won't get the correct value. I think the line should be removed or the method should have one more parameter "boolean reload". What do you think?
Back to the first change I was talking about. (Maybe it shouldn't be applied on credit memos?) This should be added in getOpenAmt
if (paymentDate != null)
{
if (getC_PaymentTerm_ID()>0) {
BigDecimal discount = getDiscountAmt(paymentDate);
if (discount!=null)
m_openAmt = m_openAmt.subtract(discount);
}
}
the "getDiscountAmt" method would be something like this:
Nils proposed here:
https://groups.google.com/d/msg/idempiere/y3QMLFjHUJg/qoRo87-TTZ8J
if (paymentDate != null) { if (getC_PaymentTerm_ID()>0) { BigDecimal discount = getDiscountAmt(paymentDate); if (discount!=null) m_openAmt = m_openAmt.subtract(discount); } }
* Get discount amt depending on payment term and timestamp * @return pos/neg amount or null */ public BigDecimal getDiscountAmt (Timestamp paymentDate) { BigDecimal retValue = null; String sql = "SELECT " + " invoiceDiscount(?,?,?) "; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_Invoice_ID()); pstmt.setTimestamp(2, paymentDate); pstmt.setInt(3, getC_PaymentTerm_ID()); rs = pstmt.executeQuery(); if (rs.next()) { retValue = rs.getBigDecimal(1); } rs.close(); pstmt.close(); pstmt = null; } catch (SQLException e) { throw new DBException(e, sql); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } return retValue; } // getDiscountAmt